Package for postprocessing FEM results in Python
Project description
NaxToPy
NaxToPy is the NaxTo library designed for Python, allowing users to read and manipulate FEM analysis results files from the most common tools: Nastran (op2, xdb, h5), Abaqus (odb), Optistruct (h3d, op2), and Ansys (rst). It stores these results in a user-friendly Python structure. Additionally, it can read input files from Nastran (bdf/dat), Optistruct (fem) and Abaqus(inp) and modify their contents.
It can easily be combined with other Python packages, such as Matplotlib or Pandas, providing access to Python's full coding power for interpreting and processing results without the need to install additional software beyond NaxTo (see the Download and Homepage links on the left).
NaxToPy is a powerful tool for FEM analysis post-processing!
⚠️Warning: To use NaxToPy, NaxTo must be installed. This version is compatible with NaxTo 2025.2. Check in Programs and Features the NaxTo version that is installed.
📘Note: If a specific NaxTo version is installed, search the NaxToPy History to find which newer version is compatible with it.
Installation
If python is installed and pip is added to the PATH:
pip install NaxToPy
An alternative, if Python is callable from the command line:
python -m pip install NaxToPy
For Visual Studio users:
-
Open "Python Environments" window
-
Change the "general information" label to "Packages(Pypi)"
-
Write the name of the package and press enter:
-
NaxToPy+ enter
For Spyder users:
-
If pip is installed:
!pip install NaxToPy -
If pip is not installed, download and run
get-pip.pylocated in https://bootstrap.pypa.io/get-pip.py . Then, run the!pip ...command -
If no method worked, download the sorce ditribution of the package NaxToPy from Test PyPi and the source distribution of the packages from PyPi pythonnet, clr-loader, cffi, pycparser. Copy and paste the five folder in the same directory. When ever you want to use the NaxToPy package add the following lines to your script:
import sys sys.path.append("...\directory") import NaxToPy as n2p
Updating NaxToPy
If python is callable from the command line:
python -m pip install -U NaxToPy
For Visual Studio users:
-
Open "Python Environments" window
-
Change the "general information" label to "Packages(Pypi)"
-
Write the following command on the search bar and press enter:
-U NaxToPy+ enter
Version updates:
To see previous version see the pre-release versions in https://test.pypi.org/project/NaxToPy/
v.1.0.1
- Bug Fix: A new dependece is added to support python 3.12
- Bug Fix: N2PLog.set_directory now works correctly
- New download page for NaxTo and NaxToPy
v.1.1.0
- Bug Fix: PSOLID with material coordinate = -1 is now suppported
- Now, it is possible to modify the BDF data from Nastran and rewrite the files.
v.1.1.1
- New property for the class N2PLoadCase: Solver
- New fille that allows the user to call the N2P classes. Useful for typing
- N2PCoord don't have the property PartID any more, as it is considered that Coordinates systems don't have parts/superelements
- Method for the connectivity property of N2PNode have been optimized
v.1.2.0
- Bug Fix: Property IsTransformable of the N2PComponent class is now right.
- Bug Fix: When calling the methods .get_nodes(), get_elements(), etc from a Nastran Input File, the user don't have to specify the part.
v.1.2.1
- New method to create N2PLoadCase as envelope load case of the selected load cases.
- The name for derivated load cases is now checked to avoid a repeated name
v.1.3.0
- New class N2PReport. This class allow to create tables of data with the components, incremenets, load cases, etc to generate big reports.
- Improvement in typing
- Small changes in the core of the package related to libraries finding and loading.
v.1.4.0
- Bug correction for N2PReport. Now it sorts correctly by "LC" or "IDS"
- N2PLoadCase has a new property: PathFile.
v.1.5.0
- A bug is fixed that prevented requesting results on global axes.
- The typing of some functions is improved.
v.1.5.1
- Bug Fix. If the name for a derivated load case is repeated for a second time, the name is changed.
- Bug Fix. Now is possible to change the criteria for a new envelope load case.
v.1.5.2
- Bug fix: A bug has been resolved that previously prevented the generation of a .log file while executing the N2PtoEXE module.
- Bug fix: An internal error related to finding the libraries has been resolved.
- The option to include a splash image in an executable has been added.
v.1.5.3
- Bug fix for the EXE generation.
- Updates in the log messages.
v.1.5.4
- Bug Fix: After calling the method get_load_cases(), the new derived cases weren't found. Now they does.
- N2PLoadCase has now two properties for the ID: OriginalID, that was in the files readed and ID that is the one that is used in NaxToPy. Usually, they are the same.
- New method new_derived_component() in the class N2PResult that allows to create new N2PComponent based on the original components.
- New module N2PUpdateFastener. This module updates the stiffness of the CBUSH and CFAST acordint to their properties and shells properties.
v.1.5.5
- Bug Fix: Now is possible to call the module N2PUpdateFastener
v.1.5.6
- The method new_envelope_loadcase() now has the option to choose the envelope group. Which means the user can ask for the LoadCases that are critical or the Increment that is critical instead of the value.
v.2.0.0
- Changes made to align the library with updates in lower-level dependencies.
- New internal methods to look for the compatibility with low-level dependencies.
- The name of the .log is now NaxToPy_Year-Month-Day.log.
v.2.0.1
- The compatibility is extended to all NaxTo steps of the same version.
- The property N2PLoadCase.ActiveIncrement is subtitued by N2PLoadCase.ActiveN2PIncrement. It uses an object instaed of an int.
- Update of the examples of some docstrings.
v.2.1.0
- Reading a Natran Input File: SPC and SCP1 are now supported.
- Bug fix. The order in the components in new_report() does not affect now.
- Formula check in new_derived_loadcase(), new_enevelope_loadcase() and new_derived_component().
- New optional arguments if n2ptoexe() to add extra libaries, packages or files.
v.2.1.1
- Two new methods in N2PModelContent: load_user_coord_sys_from_csv() and set_user_coord_sys().
Also, there is a new property for N2PElement and N2PNode: UserSystemArray. This update allow the
user to define a different coordinate system for each element or node. To ask for the results
in this system, the optional argument
coordsysmust be equal to-20. - Bug fix: The checking for component and section in new_report() has been fixed. If a comma appeared in the component or section name, the method failed.
v.2.1.2
- Internal change for speeding up the read of NastranInputFiles. Now the Nastran Cards are loaded when they are asked and not all at once.
- Improvement in error handling and log writing.
- The function import_results_from_files() checks if the file exist. If not, it prints an error but the execution doesn't crash.
v.2.2.0
- Feat: New module for fastener analysis: N2PGetFasteners.
- Feat: New module for fastener analysis: N2PGetLoadFasteners. Calculates forces in joints and bypass forces.
- Bug fix: When a NaxToPy executable file is used on a machine where NaxTo is installed, the libraries are selected accordingly.
- Feat: Hidden imports are now allowed in n2ptoexe.
- Bug fix: Fixed the rotation of the FORCES tensor. Now the QX and QY components (transverse shears) are calculated correctly.
- Refactor: The dictionary and list for Cards have been replaced with a lazy dictionary and a lazy list, improving execution efficiency.
- Refactor: Reading the mesh from binary files is now executed in parallel by default, as this approach is more memory-safe.
v.2.2.1
- BugFix: The method set_increment() is fixed.
- BugFix: Several bugfix (not in the result accuracy) are fixed in modules N2PGetFastener and N2PGetLoadsFastener. Several optimizations are included.
- Feat: Now the method get_load_case() admits a list of int and a list of string and return a list of N2PLoadCase.
- Refactor: N2P classes use slots for security and optimization.
- Refactor: Complete refactor of the module that loads the NaxTo libraries.
- BugFix: in parallel mesh load with a small mesh and lot of results.
- BugFix: in sequential mesh load in op2.
v.2.2.2
- BugFix: Solved an issue in the Nastran Cards Dictionary
- BugFix: Solved the Prop atribute of an N2PElement in Abaqus
- Feat: Now is possible to create
N2PCoordby the user with thenew_coordinate_system()method. - Feat: Now is possible to add to
element_nodal()a list of N2PElement to unshew only the nodes of these elements. - Feat: Now is possible to ask for results in a list of elements or nodes using the optional argument
filter_list. - Feat: When the user provides a coordinate system and two vectors (v1, v2) to specify the output results, the information is redundant. The coordinate system will prevail.
- Feat: New properties supported: PBUSH, PFAST, PMASS, PELAS, PGAP, PWELD
- BugFix: The method get_elements_attached() is fixed so when there are MPC connectors with the same ID.
v.2.2.3
- Requirement: Now NaxToPy require the package h5py.
- Feat: N2PGetLoadFastener now can use PAG method and display format.
- BugFix: Some bugs are solved in N2PGetFastener and N2PGetLoadFastener.
- Feat: N2PGetLoadFastener can export results in HDF5 format.
- BugFix: The filtering in the method get_result_by_LCs_Incr() in elements when results are in Corner Data is fixed.
v.3.0.0
- Feat: Now it is supported more properties from Nastran: PBAR, PBARL, PBEAM, PBEAML, PBUSH, PWELD, PELAS, PFAST, PMASS, PGAP. They are kept as N2PBeam, N2PBeamL, N2PBush, N2PWeld, N2PElas, N2PFast, N2PMass, N2PGap.
- Feat: Now it is supported more properties from Abaqus: *BEAM SECTION and *BEAM GENERAL SECTION as N2PBeamL and N2PBeam.
- Feat: Overloaded
get_result_by_LCs_Incr()to accept a list of components. It load multiple components and load cases of the same result in parallel, improving efficiency. - Feat: New property N2PComp.EqQBenMatrix that returns the equivalent stifness matrix for bending.
- Feat: Added
N2PComp.EqMemPropsandN2PComp.EqBenPropsproperties to return equivalent engineering values (Ex, Ey, G, and ν) for membrane and bending behavior, respectively. - Feat: Added two new methods in
N2PModelContent:get_material()andget_property()to search easelly for materials and properties. - Feat: new method in
N2PModelContent:get_elements_filtered(). It returns a list ofN2PElementthat matches a material, property, part or type-element. - Feat: New checks in the results methods to avoid invalid parameters.
v.3.1.0
- Feat: New optional argument in
load_model()called loadconnectors. True by default. - Feat: New module N2PNeuber to obtain stresses using the Neuber method.
- Feat: New module N2PSandwich to calculate sandwich structures failure modes.
- Feat: New module N2PCompositeFailure for evaluating structural failure in laminates.
- Feat: New module N2PEdgeDelamination to obtain interlaminar stresses and RF from edge delamination.
- Feat: New module N2PCalculatorRFJoints manages the Reserve Factor (RF) calculation process of the joints obtained through the modules N2PGetFasteners and N2PGetLoadFasteners.
- Feat: New module N2PUpdateFastener provides methods to update rivet and bolt stiffness and generate a new FEM Input File (.bdf, .fem, .dat, etc.) file with the updated data.
- BugFix: Several bugs are fixed in N2PGetFastener and N2PGetLoadFastener modules.
- Feat: Extra information in the log when the NaxToPy is running from a executable.
- Feat:
N2PLoadModelContent.SetListis now an encapsulated property. - Refactor: the method
N2PLoadModelContent.get_result_by_LCs_Incr()is optimized.
v.3.1.1
- BugFix: Small error fixed in
N2PNeuber. - Feat: New Failure criteria in
N2PCompositeFailure-> Fiber Mode Concept - BugFix: The property
LevelListof the abstract classN2PLogis now an attribute to be compatible with Python 3.13. - Feat: New class
N2PropMiscfor properties that are not supported. - BugFix: Small errors in
N2PGetFasteners. - BugFix: Several errors are fixed for properties and materials when reading InputFileAbaqus (inp) and Abaqus (odb).
- Feat: Now, when a executable is created, if the version of NaxTo of the exe matches the instaled, it will use the installed NaxTo libraries. If the version doesn't match or NaxTo is not installed, exe NaxTo libraries will be used.
- BugFix: the keyword
THRUis now supported in the bulk data cardSPC1when reading from a Nastran Input File.
v.3.1.2
- BugFix: Changes to fix the Mat IDs attributes in N2Property from Abaqus files.
- Refactor: Updated vectorised method for N2PCompositeFailure module.
- Docs: Improved documentation in some methods.
v.3.2.0
- Refactor:
N2PGetFastenersandN2PGetLoadFasteners: Improvement in warning and error messages and documentation - Refactor:
N2PNastranInputData: The Nastran input file reading libraries (Bulk Data Files) have been updated, and this class has been adapted to the new changes, which improve memory management and file loading speed. - Refactor:
NaxToPy.load_model(): Improved file type selection (binary or text) and identification of which Solver type they belong to ("InputFileNastran","InputFileAbaqus"). - Refactor:
N2PModelContent.get_result_by_LCs_Incr(): Now, if the requested result or component does not exist in one of the load case-increment cases, the key-value pair is returned in the dictionary, but with the value set to a numpy array filled with "nan", instead of omitting the key from the dictionary. - Refactor:
N2PCompositeFailure: Improved module efficiency by vectorizing calculations and added a new failure criterion, FMC - Fiber Mode Concept, which is compatible with FirstPly and PlyByPly. - Feat:
N2PCoefficientsFinder: New NaxToPy module that detects and defines linear dependencies between rows of a given matrix. - Feat:
N2PNastranInputData.find_cards(): New method that replaces the oldget_cards_by_field(). Allows searching for cards with various filter types efficiently. - Feat:
N2PNastranInputData.get_failed_cards(): New method that allows retrieving cards that are poorly formatted or have reading errors when opening a Nastran input file (.bdf). - Feat:
N2PNastranInputData.create_card(): New method that allows creating Nastran cards completely from scratch, which will be added to the end of the Nastran input file once therebuild_file()command is executed.
v.3.2.1
- BugFix: Derived components are now founded right while using
get_result_by_LCs_Incr(). - BugFix: All sections are now founded right while using
get_result_by_LCs_Incr(). - BugFix: Now symbols like "" or "-" are supported as part of the name of Components and Load Cases while creating new derived Components and Derived Load Cases.
v.3.2.2
- BugFix: Logs message are not printed double when the buffer is called several times.
- BugFix:
get_load_case()now returns correctly the load cases if it is called before and after callingimport_results_from_files(). - Refactor: New structure for the h5 files generated by N2PNeuber module.
- BugFix: MCID in CQUAD4 and CTRIA3 are now correctly read from a bdf file.
v.3.2.3
- Refactor: lower minimum required versions of NumPy and HDF5.
- numpy >= 1.25.1
- h5py >= 3.8.0
- Feat: Now is possible to read Nastran and Optistruct SETs. They are loaded as
N2Set. - Refactor: Reorder in
N2PNastranInputData.find_cards()params making superElements optional.categoryis the first argument.superElementsis now optional (default=None) to allow searching across all superelements by default. - BugFix: Internal lazy dictionary for N2Cards (reading a Nastran or Optistruct input file) is fixed.
Documentation
NaxToPy is a package developed by Idaero Solutions© as a part of the NaxTo software.
NaxToPy only use four dependeces:
- NumPy: https://numpy.org/
- PythonNET: https://pythonnet.github.io/
- Setuptools: https://setuptools.pypa.io/en/latest/index.html
- HDF5: https://www.h5py.org/
Supported Files
Result files:
- Nastran: .op2, .h5, .xdb
- Optistruct: .op2, .h3d
- Abaqus: .odb
- Ansys: .rst, .rth(beta)
Input files:
- Nastran (.bdf)
- Optistruct (.fem)
- Abaqus (.inp)
Initialize your model
Load your model:
# results_fem.py
import NaxToPy as N2P
path = "results_fem.op2"
model = N2P.load_model(path)
Load mesh items
# results_fem.py
# Load a list with all the nodes (as N2PNode object) of the model
nodes = model.get_nodes()
# Load the nodes in the list [1, 2, 3] (as a list of N2PNode objects)
nodelist = model.get_nodes([1, 2, 3])
# Load the node with the id 1000 (as a N2PNode object)
node1000 = model.get_nodes(1000)
# Load a list with all the elements (as N2PElement object) of the model
element = model.get_elements()
# Load the elements in the list [10, 20, 30] (as a list of N2PElement objects)
elementlist = model.get_nodes([10, 20, 30])
# Load the connectors as N2PConnector:
connectorslist = model.get_connectors()
# Load the coordinate systems of the model:
coordslist = model.get_coords()
Add your own messages to the .log
# results_fem.py
N2P.N2PLog.Info.user("INFO-1000: Running results_fem.py")
Look for LoadCases, Results and Components
# results_fem.py
# Load the list of load cases as N2PLoadCase object
loadcaseslist = model.LoadCases
# Look for the Load Case with the name pressure
pressure_lc = model.get_load_case("pressure")
# Change the active increment (by default is the last one):
pressure_lc.ActiveN2PIncrement = pressure_lc.get_increment(10)
# Look for all results
all_results = pressure_lc.Results
# Look for the Result with the name DISPLACEMENT
displacement = pressure_lc.get_result("DISPLACEMENT")
# Load all the components of the result
all_components = displacement.Components
# Look for the component X:
x_coord = displacement.get_component("X")
Load the result data as a list
# results_fem.py
# Obtain the result array as a list for a component
x_list = x_coord.get_result_list()[0]
Load the result data as a NumPy array
# results_fem.py
# Call the get_result_ndarray method of a N2PComponent to obtain a numpy array
# with the results of the component.
x_df = x_coord.get_result_ndarray()
Create an executable file of your code
Using a different script:
# extra_script.py
import NaxToPy as N2P
path1 = "results_fem.py"
path2 = "results_fem_abaqus.py"
N2P.n2ptoexe(path1, console=True, solver="NASTRAN")
N2P.n2ptoexe(path2, console=True, solver="ABAQUS", abaqusversion=["2021", "2022"])
Create your own functions to work with other python packages:
Private function that generates the proper index for a data frame using the elemnts or nodes ids:
# results_fem.py
import pandas as pd
def _index_dataframe(model: "N2PModelContent", component: "N2PComponent", sections, aveSections, cornerData, aveNodes,
variation, realPolar, coordsys, v1, v2) -> pd.Index:
""" Function that returns the proper index for each component asked
"""
# It is look if there is one part or several's:
parts = len(model.Parts) - (model.Solver == "Abaqus")
# Then the result array and where there results are placed is obtained
on_items = component.get_result_ndarray(sections, aveSections, cornerData, aveNodes,
variation, realPolar, coordsys, v1, v2)[1]
# The ids and the index are selected. It takes into account where the results are and the number of parts
if on_items == "NODES":
nodes = model.get_nodes()
ids = [(nodo.PartID, nodo.ID) if parts > 1 else nodo.ID for nodo in nodes]
indexname = ["Part", "Grid"] if parts > 1 else ["Grid"]
elif on_items == "ELEMENTS":
elements = model.get_elements()
connectors = model.get_connectors()
ids = [(element.PartID, element.ID) if parts > 1 else element.ID for element in elements] + \
[(co.PartID, co.ID) if parts > 1 else co.ID for con in connectors for co in (con if isinstance(con, list) else [con])]
indexname = ["Part", "Element"] if parts > 1 else ["Element"]
elif on_items == "ELEMENT NODAL":
ids = model.elementnodal().values()
indexname = ["Part", "Grid", "Element"]
else:
return None
# If there are several parts, or it is corner data, MultiIndex is used:
if isinstance(ids[0], tuple):
index = pd.MultiIndex.from_tuples(ids, names=indexname)
else:
index = ids
return index
Function that generates a DataFrame with the results of a component
# results_fem.py
def dataframe_result(model: "N2PModelContent", component: "N2PComponent",sections=None, aveSections=-1, cornerData=False,
aveNodes=-1, variation=100, realPolar=0, coordsys: int = -1000,
v1: tuple = (1,0,0), v2: tuple = (0,1,0)) -> pd.DataFrame:
"""Function that returns as a dataframe of pandas the result array of a component
"""
# DataFrame generation
return pd.DataFrame(data={component.Name:
component.get_result_ndarray(sections, aveSections, cornerData, aveNodes, variation,
realPolar, coordsys, v1, v2)[0]},
index=_index_dataframe(model, component, sections, aveSections, cornerData, aveNodes, variation,
realPolar, coordsys, v1, v2),
columns=[component.Name])
Function that generates a DataFrame for all the components of a result
# results_fem.py
def dataframe_results(model: "N2PModelContent", result: "N2PResult", sections=None, aveSections=-1, cornerData=False,
aveNodes=-1, variation=100, realPolar=0, coordsys: int = -1000,
v1: tuple = (1,0,0), v2: tuple = (0,1,0)) -> pd.DataFrame:
"""Function that generates a DataFrame of pandas with all the components of a result. It uses dataframe_result.
It uses sequential computing.
"""
return pd.DataFrame(data={component.Name:
component.get_result_ndarray(sections, aveSections, cornerData, aveNodes, variation,
realPolar, coordsys, v1, v2)[0]
for component in result.Components.values()},
index=_index_dataframe(model, next(iter(result.Components.values())), sections, aveSections,
cornerData, aveNodes, variation, realPolar, coordsys, v1, v2),
columns=[component.Name for component in result.Components.values()])
For more documentation visit https://idaerosolutions.com/Home/NaxToPy
Complete NaxToPy documentation at: https://www.idaerosolutions.com/NaxToDocumentation/NaxToPy/3.1.0/index.html
License
See the license in Python\Lib\site-packages\NaxToPy-{version}.dist-info\LICENSE or executing the command python -m pip show NaxToPy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file naxtopy-3.2.3.tar.gz.
File metadata
- Download URL: naxtopy-3.2.3.tar.gz
- Upload date:
- Size: 471.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4732cdc4a0cb56cfb9f74f5ff056efd927b45e322b4d5591f7c1f86bd47354aa
|
|
| MD5 |
a4db9913aea2ca4b5fdc20f517367007
|
|
| BLAKE2b-256 |
6ff851d251300f9c0cdb8f7b9e85a617c940296270188fcf9f1539f7b5aeca4b
|
File details
Details for the file naxtopy-3.2.3-py3-none-any.whl.
File metadata
- Download URL: naxtopy-3.2.3-py3-none-any.whl
- Upload date:
- Size: 517.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b286ffa4324acb86c3f83ff2fa63bc4d1a7b26b54b1dd3c590a3e206bb66d78
|
|
| MD5 |
f8125ea66b299c96042ea64f403fbe18
|
|
| BLAKE2b-256 |
984e890a8a27103ee1c30d61fdecbd7398a0129f0fb4f4e473f46bf9213c779d
|