N2PModelContent#

class NaxToPy.Core.N2PModelContent.N2PModelContent(path, parallelprocessing, solver=None, dict_gen: dict = None, filter: Literal['ELEMENTS', 'PROPERTIES', 'PARTS', 'NODES'] = None, n2v: N2ModelContent = None, loadconnectors=True)[source]#

Bases: object

Main Class of the NaxToPy package. Keeps almost all the information contained in the output result.

The method that returns a N2PModelContent is load_model()

Example

>>> model1 = n2p.load_model(r"my_model1.op2")
>>> solver = model1.Solver  # Property of N2PModelContent
>>> nodes = model1.get_nodes()  # Method of N2PModelContent
>>> model2 = n2p.load_model(r"my_model2.h5")
>>> solver2 = model2.Solver  # Property of N2PModelContent
>>> nodes2 = model2.get_nodes()  # Method of N2PModelContent
clear_results_memory() None[source]#

Method that deletes the results data store at low level. It is useful when a lot of results are asked and kept in Python memory

create_free_body(name: str, loadcase: N2PLoadCase, increment: N2PIncrement = None, nodes: list[N2PNode] = None, elements: list[N2PElement] = None, outpoint: tuple[float, ...] = None, coordsysout: N2PCoord = None) N2PFreeBody[source]#

Method that creates a N2PFreeBody object, keeps in FreeBodiesDict() and returns it.

A N2PFreeBody contains the information of the cross-section defined by the user and the forces and moments calculated by NaxToPy durin the instance of the object.

Parameters:
  • name – str -> Must be unique. If a new FreeBody is name as an old one, the old FreeBody will be deleted.

  • loadcase – N2PLoadCase

  • increment – N2PIncrement

  • nodes – list[N2PNode]

  • elements – list[N2PElement]

  • outpoint – tuple[float]

  • coordsysout – N2PCoord

Returns:

freebody

Return type:

N2PFreeBody

Example

>>> model = load_model("model.op2")
>>> lc = model.get_load_case(5)
>>> incr = lc.ActiveN2PIncrement
>>> node_list = model.get_nodes([1000, 1001, 1002, 1003, 1004, 1005])
>>> elem_list = model.get_elements([1000, 1001, 1002, 1003, 1004])
elementnodal(elements: list[N2PElement] = None) dict[int, tuple][source]#

Method that generates the dictionary for the element-nodal mesh.

Use the internal id for unsew nodes as key and a tuple (ID_Part_Solver, ID_Node_Solver, ID_Element_Solver) as a value. If the dictionary has already created it is pointed instead.

Parameters:

elements – list[N2PElement] (optional) If a list of N2PElements is provided it returns a dict for the unsew nodes of those elements

Returns:

dict[internal_node_unsew] = (Part_Solver, ID_Node_Solver, ID_Element_Solver)

Example

>>> all_unsew_nodes = model.elementnodal()
>>> elements = model.get_elements([1001, 1002, 1003])
>>> some_unsew_nodes = model.elementnodal(elements)
get_connectors(ids=0) N2PConnector | list[N2PConnector][source]#

General method for obtain connectors.

If it has no argument or is 0: returns all the elements. If it has one id as argument: returns one N2PConnector. If it has a list as argument, it returns a list of N2PConnector. The ids should be a tuple (id, part_id). If not, part_id = 0 by default.

Parameters:

ids – int | list[int] | tuple[int, str] | list[tuple[int, str]]

Returns:

N2PConnector | list[N2PConnector]

Return type:

object

get_coords(ids=0) N2PCoord | list[N2PCoord][source]#

General method for obtain coordinate systems.

If it has no argument or is 0: returns all the coordinate systems If it has one id as argument: returns one N2PCoord If it has a list as argument, it returns a list of N2PCoord The ids should be a tuple (id, part_id). If not, part_id = 0 by default

Parameters:

ids – int | list[int] | tuple[int, str] | list[tuple[int, str]]

Returns:

N2PCoord | list[N2PCoord]

Return type:

object

get_elements(ids: int = 0) N2PElement[source]#
get_elements(ids: tuple[int, str] = 0) N2PElement
get_elements(ids: list[int] = 0) list[N2PElement]
get_elements(ids: list[tuple[int, str]] = 0) list[N2PElement]

General method for obtain elements.

If it has no argument or is 0: returns all the elements If it has one id as argument: returns one N2PElement If it has a list as argument, it returns a list of N2PElement The ids should be a tuple (id, part_id). If not, part_id = 0 by default

Parameters:

ids – int | list[int] | tuple[int, str] | list[tuple[int, str]]

Returns:

N2PElement | list[N2PElement]

Return type:

object

get_elements_adjacent(cells: list[N2PElement, N2PConnector], domain: list[N2PElement, N2PConnector] = None) list[N2PElement, N2PConnector][source]#

Method of N2PModelContent that returns a list of N2PElement and N2PConnector that are adjacent to selected ones. If a domain is selected, the adjacent elements only will be searched in that domain.

Parameters:
  • cells – list[N2PElement, N2PConnector, …]

  • domain – list[N2PElement, N2PConnector, …] -> Optional. Set the domain where to look for the adjacent elements

Returns:

list[N2PElement, N2PConnector, …]

Example

>>> model = load_model("model.odb")
>>> domain_S4 = [e for e in model.get_elements() if e.TypeElement == "S4"]
>>> elems_adj = model.get_elements_adjacent(model.get_elements(17500), domain=domain_S4)
get_elements_attached(cells: list[N2PElement, N2PConnector], domain: list[N2PElement, N2PConnector] = None) list[N2PElement, N2PConnector][source]#

Method of N2PModelContent that returns a list of N2PElement and N2PConnector that are attached to selected ones. If a domain is selected, the attached elements only will be searched in that domain.

Parameters:
  • cells – list[N2PElement, N2PConnector, …]

  • domain – list[N2PElement, N2PConnector, …] -> Optional. Set the domain where to look for the adjacent elements

Returns:

list[N2PElement, N2PConnector, …]

Example

>>> model = load_model("model.h3d")
>>> domain_elems = model.get_elements()
>>> elems_att = model.get_elements_attached(model.get_elements(17500), domain=domain_elems)
get_elements_by_face(cells: list[N2PElement, N2PConnector], tolerance_angle: float = 30, one_element_adjacent: bool = True, domain: list[N2PElement, N2PConnector] = None) list[N2PElement, N2PConnector][source]#

Method of N2PModelContent that returns a list of N2PElement and N2PConnector that are in the same face as the selected ones. If a domain is selected, the face elements only will be searched in that domain. To be considered in the same face, the adjacent element must share an arist and the angle between the elements must be lower than the tolerance angle.

Parameters:
  • cells – list[N2PElement, N2PConnector, …]

  • tolerance_angle – float -> Optional (30º by default). Max angle[º] between two elements to be considered in the same face

  • one_element_adjacent – bool -> Optional (True by default). If true, two elements are connected to edge of a selected element they will not be considered.

  • domain – list[N2PElement, N2PConnector, …] -> Optional. Set the domain where to look for the adjacent elements

Returns:

list[N2PElement, N2PConnector, …]

Example

>>> model = load_model("model.op2")
>>> elems1 = model.get_elements_by_face(model.get_elements(17500))
>>> domain_cquad = [e for e in model.get_elements() if e.TypeElement == "CQUAD4"]
>>> elems2 = model.get_elements_by_face(model.get_elements([17500, 17501]), 25, domain=domain_cquad)
get_elements_filtered(materials: str | int | list[str | int] = None, properties: str | int | list[str | int] = None, parts: str | list[str] = None, elementType: str | list[str] = None) list[N2PElement][source]#

Filters and returns a list of N2PElement objects based on the specified criteria.

This function allows external users to retrieve model elements by applying different filters. Materials, properties, parts, and element types can be specified to refine the search.

If multiple filters are provided, the function returns only elements that meet all conditions (AND logic). If no filters are specified, an empty list is returned.

Parameters:
  • materials (list[str], optional) – List of material names to filter elements by material type.

  • properties (list[str], optional) – List of properties to filter elements based on attributes.

  • parts (list[str], optional) – List of part names to obtain elements belonging to specific parts.

  • elementType (list[str], optional) – List of element types to filter elements by type.

Returns:

List of elements that meet the applied filters.

Return type:

list[N2PElement]

Example

>>> model = n2p.load_model(r".\abaqus_model.odb")
>>> elements = model.get_elements_filtered(materials=['Steel'], properties=['Steel Shell'])
>>> model = n2p.load_model(r".\nastran_model.op2")
>>> elements = model.get_elements_filtered(materials=[10001])

Note

  • If both materials and parts are provided, elements from the specified materials within the given parts will be filtered.

  • It is recommended to use this function when a specific selection of model elements is needed.

  • This method is faster than making a comprehension list.

get_free_edges(domain: list[N2PElement, N2PConnector] = None) list[tuple[N2PElement, N2PNode, N2PNode]][source]#

Method of N2PModelContent that returns a list of tuples of a N2PElement and two N2PNode of that element. The two nodes define the edge of the element that is contained in the free edge of the mesh If a domain is selected, the tuple will only be searched in that domain. Notice that connectors, although they may be given in the domain, they are never included in the free edges.

Parameters:

domain – list[N2PElement, N2PConnector, …] -> Optional. Set the domain where to look for the free edges

Returns:

list[tuple[N2PElement, N2PNode, N2PNode], …]

get_load_case(id: int) N2PLoadCase | None[source]#
get_load_case(name: str) N2PLoadCase | None
get_load_case(id: list[int]) list[N2PLoadCase] | None
get_load_case(name: list[str]) list[N2PLoadCase] | None

Returns a list of N2PLoadCase objects with all the load cases contained in the output result file.

Parameters:
  • id (int|list[int], optional) – ID of the load case. Defaults to None.

  • name (str|list[int], optional) – Name of the load case. Defaults to None.

Returns:

a load case list[N2PLoadCase]: load cases list

Return type:

N2PLoadCase

Example

>>> a_loadcase = model.get_load_case(10)
>>> a_loadcase = model.get_load_case("Mechanical")
>>> some_loadcases = model.get_load_case([10, 20])
>>> some_loadcases = model.get_load_case(["Mechanical", "Thermal"])
get_materials(ids: int = 0) N2PMaterial[source]#
get_materials(ids: tuple[int, str] = 0) N2PMaterial
get_materials(ids: list[int] = 0) list[N2PMaterial]
get_materials(ids: list[tuple[int, str]] = 0) list[N2PMaterial]
get_materials(ids: str = 0) N2PMaterial
get_materials(ids: list[tuple[str, str]] = 0) list[N2PMaterial]

General method for obtain materials.

If it has no argument or is 0: returns all the materials If it has one id as argument: returns one N2PMaterial If it has a list as argument, it returns a list of N2PMaterial The ids should be a tuple (id, part_id). If not, part_id = 0 by default

Parameters:

ids – int | str | list[int] | tuple[int, str] | list[tuple[int, str]]

Returns:

N2PMaterial | list[N2PMaterial]

Return type:

object

get_nodes(ids=0) N2PNode | list[N2PNode][source]#

General method for obtain nodes.

If it has no argument or is 0: returns all the nodes. If it has one id as argument: returns one N2PNode. If it has a list as argument, it returns a list of N2PNode. The ids should be a tuple (id, part_id). If not, part_id = 0 by default.

Parameters:

ids – int | list[int] | tuple[int, str] | list[tuple[int, str]]

Returns:

N2PNode | list[N2PNode]

Return type:

object

get_properties(ids: int = 0) N2PProperty[source]#
get_properties(ids: tuple[int, str] = 0) N2PProperty
get_properties(ids: list[int] = 0) list[N2PProperty]
get_properties(ids: list[tuple[int, str]] = 0) list[N2PProperty]
get_properties(ids: str = 0) N2PProperty
get_properties(ids: list[tuple[str, str]] = 0) list[N2PProperty]

General method for obtain properties.

If it has no argument or is 0: returns all the properties If it has one id as argument: returns one N2PProperty If it has a list as argument, it returns a list of N2PProperty The ids should be a tuple (id, part_id). If not, part_id = 0 by default

Parameters:

ids – int | str | list[int] | tuple[int, str] | list[tuple[int, str]]

Returns:

N2PProperty | list[N2PProperty]

Return type:

object

get_result_by_LCs_Incr(list_lc_incr: list[tuple[N2PLoadCase, N2PIncrement]] | list[tuple[int, int]], result: str, component: list[str], sections: list = None, aveSections: int = -1, cornerData: bool = False, aveNodes: int = -1, variation: int = 100, realPolar: int = 0, coordsys: int = -1000, v1: tuple = (1, 0, 0), v2: tuple = (0, 1, 0), filter_list: list[N2PElement | N2PNode] = None) dict[tuple[int, int, str], ndarray][source]#
get_result_by_LCs_Incr(list_lc_incr: list[tuple[N2PLoadCase, N2PIncrement]] | list[tuple[int, int]], result: str, component: str, sections: list = None, aveSections: int = -1, cornerData: bool = False, aveNodes: int = -1, variation: int = 100, realPolar: int = 0, coordsys: int = -1000, v1: tuple = (1, 0, 0), v2: tuple = (0, 1, 0), filter_list: list[N2PElement | N2PNode] = None) dict[tuple[int, int], ndarray]

Get results of a component for multiple loadcases and increments.

This method uses parallel subprocesses to speed up calculations and returns a dictionary with loadcase/increment tuples as keys and numpy arrays as values.

Parameters:
  • list_lc_incr (list[tuple[int]]) – List of tuples containing (loadcase_id, increment_id) pairs for which to extract results.

  • result (str) – Name of the result type to extract (e.g., “STRESSES”, “STRAINS”, “DISPLACEMENTS”, “FORCES”).

  • component (str | list[str]) – Component name(s) to extract. For stresses: “VON_MISES”, “XX”, “YY”, etc. If list is provided, results for all components are returned.

  • sections (list[str] | list[N2PSection]) – Optional. Sections on which to perform operations. If None (default), operations are performed on all sections.

  • aveSections (int, default -1) –

    Optional. Operation to perform among sections:

    • -1: Maximum (default)

    • -2: Minimum

    • -3: Average

    • -4: Extreme

    • -6: Difference

  • cornerData (bool, default False) –

    Optional. Flag to control result location:

    • True: Results at element nodes

    • False: Results at element centroid (default)

  • aveNodes (int, default -1) –

    Optional. Operation among nodes when cornerData=True:

    • 0: None

    • -1: Maximum (default)

    • -2: Minimum

    • -3: Average

    • -6: Difference

  • variation (int, default 100) –

    Optional. Averaging parameter between nodes (0-100):

    • 0: No averaging between nodes

    • 100: Total averaging between nodes (default)

  • realPolar (int, default 0) –

    Optional. Data type for complex results:

    • 1: Real/Imaginary

    • 2: Magnitude/Phase

  • coordsys (int, default -1000) –

    Optional. Coordinate system for result representation:

    • 0: Global coordinate system

    • -1: Material coordinate system

    • -10: User defined coordinate system

    • -20: Element/Node user defined coordinate system

    • -1000: Analysis coordinate system (default)

    • >0: Solver ID of predefined coordinate system

    Note

    By default, results are in the analysis coordinate system. This is usually the element system, but in OP2 from Nastran (version >= 2023.3), it could be the material system if PARAM,OMID,YES is used.

  • v1 (tuple[float], default (1, 0, 0)) – Optional. 3D vector defining the x-axis of the coordinate system.

  • v2 (tuple[float], default (0, 1, 0)) –

    Optional. 3D vector defining the xy-plane. The coordinate system axes are generated as:

    • x = v1

    • z = v1 ^ v2 (cross product)

    • y = z ^ x (cross product)

  • filter_list (list[N2PElement] | list[N2PNode]) –

    Optional. Elements or nodes to filter results for. If None, results for all elements/nodes are returned.

    Warning

    Filtering results can slow down extraction. If results are needed for multiple separate lists, extract all results first and filter afterward.

Returns:

Dictionary containing extracted results:

  • If component is str: {(lc_id, incr_id): numpy.ndarray}

  • If component is list: {(lc_id, incr_id, component_name): numpy.ndarray}

Return type:

dict

Examples

Basic usage with single component:

>>> vonmises = model.get_result_by_LCs_Incr(
...     [(1, 2), (2, 2)], "STRESSES", "VON_MISES"
... )
>>> vonmises_1_2 = vonmises[(1, 2)]  # Results for LC=1, Incr=2

Using loadcase and increment objects:

>>> XX = model.get_result_by_LCs_Incr(
...     [(loadcase1, increment2), (loadcase2, increment2)],
...     "STRAINS", "XX"
... )
>>> XX_1_2 = XX.get((loadcase2.ID, increment2.ID))

Filtering by sections:

>>> YY_Z1 = model.get_result_by_LCs_Incr(
...     [(1, 2), (2, 2), (3, 1)],
...     "STRESSES", "YY",
...     sections=["Z1"]
... )
>>> YY_Z1_3_1 = YY_Z1.get((3, 1), None)

Using custom coordinate system:

>>> XY_transformed = model.get_result_by_LCs_Incr(
...     [(2, 2), (3, 1)],
...     "STRESSES", "XY",
...     v1=(0, -2, 0),
...     v2=(0, 0, -3)
... )
>>> XY_transformed_2_2 = XY_transformed.get((2, 2))

Filtering by elements and nodes:

>>> elements_face = model.get_elements_by_face(model.get_elements(100))
>>> fx_inface = model.get_result_by_LCs_Incr(
...     [(1, 2), (3, 1)],
...     "FORCES", "FX",
...     filter_list=elements_face
... )
>>> nodes_face = list({
...     node for element in elements_face for node in element.Nodes
... })
>>> x_inface = model.get_result_by_LCs_Incr(
...     [(1, 2), (3, 1)],
...     "DISPLACEMENTS", "X",
...     filter_list=nodes_face
... )

Multiple components:

>>> stresses = model.get_result_by_LCs_Incr(
...     [(1, 2), (2, 2)],
...     "STRESSES",
...     ["VON_MISES", "MAXIMUM_PRINCIPAL"]
... )
>>> vonmises_1_2 = stresses[(1, 2, "VON_MISES")]
>>> maxp_2_2 = stresses[(2, 2, "MAXIMUM_PRINCIPAL")]
>>> strains = model.get_result_by_LCs_Incr(
...     [(loadcase1, increment2), (loadcase2, increment2)],
...     "STRAINS",
...     ["XX", "XY", "YY"]
... )
>>> XX_1_2 = strains.get((loadcase2.ID, increment2.ID, "XX"))
import_results_from_files(results_files: list[str]) None[source]#
Method of N2PModelContent that reads an output result file from Nastran, Abaqus, Optistruct or Ansys and

add the results to the N2PModelContent instance.

Supports .op2, .xdb, .odb, .h5, .h3d and .rst file extensions read from a local filesystem or URL.

Parameters:

results_files – list[str]

Example

>>> model1 = load_model("model1_lc1.odb")
>>> model1.import_results_from_files(["model1_lc2.odb", "mode1l_lc3.odb"])
>>> model2 = load_model("model2.dat", "InputFileNastran")
>>> model2.import_results_from_files(["model2_lc1.op2", "model2_lc2.op2"])
load_user_coord_sys_from_csv(path: str, where: Literal['NODES', 'ELEMENTS']) None[source]#

Method that loads a coordinate system for each node/element as a user coordinate system from a CSV file.

The user can define a different system for each element or node and ask for results in that system using the optional argument “coordsys=-20”

The structure of the csv must have the node/element identification, and the coordinates of the vectors v1 and v2 that generates the system: x = v1; z = v1^v2; y = z^v1. The structure for elements and nodes must be:

node_id_1,part_id_1,x11,y11,z11,x12,y12,z12

user_system_elements_example.csv:

1001,0,1,0,0,0,1,0

1002,0,0.3,0.2,0,0,1,0

1003,0,0,1,0,1,1,0

1004,0,2,0,1,0.4,1,3

Warning

If a CSV is loaded and the another is loaded, the previous information will be deleted.

Parameters:
  • path – path for a CSV.

  • where – “NODES”|”ELEMENTS”. The user coordinate systems are for the nodes or the elements.

Examples

>>> N2PModelContent.load_user_coord_sys_from_csv(path="user_system_elements_example.csv", where="ELEMENTS")
>>> N2PModelContent.load_user_coord_sys_from_csv("node_sys.csv", "NODES")
new_coordinate_system(name: str, origin: tuple, v1: tuple, v2: tuple, type_coord: Literal['RECTANGULAR', 'CILINDRICAL', 'SPHERICAL'] = 'RECTANGULAR') N2PCoord[source]#

Returns a N2PCoord and add it to the coordinate system list.

Note

The ID of the coordinate system will be set automatically to the last ID + 1 .

Parameters:
  • name – str Name of the coordinate system.

  • origin – tuple tuple with the origin coordinates.

  • v1 – tuple tuple with coordinates of the x vector.

  • v2 – tuple tuple with coordinates of the xy plane vector.

  • type_coord – str (optional) The posible types are “RECTANGULAR”, “CILINDRICAL” or “SPHERICAL”. Default is “RECTANGULAR”.

Example

>>> mycoord = new_coordinate_system(name="MyCoordinate", origin=(0,0,0), v1=(0.5,0.5,0), v2=(0,1,0))
>>> new_coordinate_system("MatCoord2", (1,0,-1), (0,0.5,0), (0,0,1), "CILINDRICAL")
>>> coord_mat = model.get_coords()[-1]
new_derived_loadcase(name: str, formula: str) N2PLoadCase[source]#

Generate a new loadcase by linear combination of existing loadcases and frames.

This method creates a N2PLoadCase by combining multiple loadcase/frame pairs using linear arithmetic operations. The derived loadcase will have a negative ID and contains only one frame/increment with ID 0.

Parameters:
  • name (str) – Name for the new derived loadcase.

  • formula (str) –

    String defining the linear combination using loadcase/frame pairs and arithmetic operations. Loadcase/frame pairs must follow the structure <LCXX:FRYY> where XX is the loadcase ID and YY is the frame ID. Examples:

    • "<LC1:FR1>+2*<LC2:FR1>+0.5*<LC5:FR3>"

    • "0.5*<LC1:FR2>"

    • "5*<LC2:FR3>-2*<LC3:FR3>"

Returns:

  • N2PLoadCase – Derived loadcase with negative ID containing the linear combination results.

  • .. note:: – The derived loadcase will have only one frame/increment with ID 0. When using a derived loadcase in formulas, reference it as <LC-X:FR0> where X is the absolute value of the negative ID.

Examples

>>> dev_lc1 = new_derived_loadcase(
...     "dev_lc1",
...     "<LC1:FR1>+2*<LC2:FR1>+0.5*<LC5:FR3>"
... )
>>> dev_lc2 = new_derived_loadcase("dev_lc2", "0.5*<LC1:FR2>")
>>> dev_lc3 = new_derived_loadcase(
...     "dev_lc3",
...     "5*<LC-1:FR0>+2*<LC3:FR3>"
... )
new_envelope_loadcase(name: str, formula: str, criteria: Literal['ExtremeMax', 'ExtremeMin', 'Max', 'Min', 'Range'] = 'ExtremeMax', envelgroup: Literal['ByContour', 'ByLoadCaseID', 'ByIncrement'] = 'ByContour') N2PLoadCase[source]#

Method of N2PModelContent that generate a new N2PLoadCase that is the envelope of the load cases and increments selected.

The id is automatically generated. It will be negative, starting at -1. If the new load case use a derivated or envelope load case use LCD1 in the formula instead of LC-1:

Parameters:
  • name (str) – Name of the envelope load case. It mustn’t be repeated.

  • formula (str) – formula that define the loadcases and increments must have this structure: <LCXX:FRYY>. Example: “<LC1:FR1>,<LCD2:FR1>,<LC2:FR10>”

  • criteria (str) –

    Criteria for selecting the results to build the new derived load case. Possible values:
    • ’ExtremeMax’

    • ’ExtremeMin’

    • ’Max’

    • ’Min’

    • ’Range’

  • envelgroup (str) –

    Criteria to select the data asociated to the elements/nodes:
    • ’ByContour’: The data will be the actual value (XX stress for example)

    • ’ByLoadCaseID’: The data will be the id of the original load case that is critical (LC 6363 for example)

    • ’ByIncrement’: The data will be the id of the increment that is critical

Returns:

N2PLoadCase

Examples

>>> env_lc1 = new_envelope_loadcase("env_lc1", formula="<LC1:FR1>,<LC2:FR1>")
>>> env_lc2 = new_envelope_loadcase("env_lc2", formula="<LC1:FR1>,<LC2:FR8>,<LC-3:FR0>", criteria="Min", envelgroup="ByLoadCaseID")
new_report(lc_incr: str, allincr: bool, result: str, componentssections: str, ifenvelope: bool, selection: list[N2PNode, N2PElement], sortby: str, aveSections=-1, cornerData=False, aveNodes=-1, variation=100, realPolar=0, coordsys: int = -1000, v1: tuple | ndarray = (1, 0, 0), v2: tuple | ndarray = (0, 1, 0)) N2PReport[source]#

Generate a report instance for extracting results from specified nodes or elements.

This method creates a N2PReport instance containing information about load cases, increments, components and sections for a specific result type. The report can calculate result arrays and export data to CSV format.

Parameters:
  • lc_incr (str) – Formula specifying the loadcase-increment pairs. Each pair must follow the structure <LCX:FRY> where X is the loadcase ID and Y is the increment/frame ID. Example: "<LC1:FR1>,<LC1:FR2>,<LC2:FR1>,<LC2:FR2>".

  • allincr (bool) – Flag to request all increments for the specified load cases.

  • result (str) – Name of the result type to extract (e.g., “DISPLACEMENTS”, “STRESSES”, “STRAINS”).

  • componentssections (str) –

    Formula specifying components and sections. Each component can have multiple sections following the structure <ComponentName:X#Y#Z#> where X, Y, Z are section names. Each section name must end with #. Examples:

    • With sections: "<VONMISES:Z1#Z2#>,<MAX_SHEAR:Z1#Z2#>"

    • Without sections: "<FX:NONE#>,<FY:NONE#>"

  • ifenvelope (bool) – Flag to extract only envelope results from the specified load cases.

  • selection (list[N2PNode] | list[N2PElement]) –

    List of nodes or elements where results are requested. Must match the result type:

    • Displacements: Use list of N2PNode

    • Stresses: Use list of N2PElement

  • sortby (str) –

    Sorting criterion for results:

    • ”LC”: Sort by load cases

    • ”IDS”: Sort by element/node IDs

  • aveSections (int, default -1) –

    Optional. Operation to perform among sections:

    • -1: Maximum (default)

    • -2: Minimum

    • -3: Average

    • -4: Extreme

    • -6: Difference

  • cornerData (bool, default False) –

    Optional. Flag to control result location:

    • True: Results at element nodes

    • False: Results at element centroid (default)

  • aveNodes (int, default -1) –

    Optional. Operation among nodes when cornerData=True:

    • 0: None

    • -1: Maximum (default)

    • -2: Minimum

    • -3: Average

    • -5: Average with variation parameter

    • -6: Difference

  • variation (int, default 100) –

    Optional. Averaging parameter between nodes (0-100):

    • 0: No averaging between nodes

    • 100: Total averaging between nodes (default)

  • realPolar (int, default 0) –

    Optional. Data type for complex results:

    • 1: Real/Imaginary

    • 2: Magnitude/Phase

  • coordsys (int, default -1000) –

    Optional. Coordinate system for result representation:

    • 0: Global coordinate system

    • -1: Material coordinate system

    • -10: User defined coordinate system

    • -20: Element/Node user defined coordinate system

    • -1000: Analysis coordinate system (default)

    • >0: Solver ID of predefined coordinate system

  • v1 (tuple[float] | numpy.ndarray, default (1, 0, 0)) – Optional. 3D vector defining the x-axis of the coordinate system.

  • v2 (tuple[float] | numpy.ndarray, default (0, 1, 0)) –

    Optional. 3D vector defining the xy-plane. The coordinate system axes are generated as:

    • x = v1

    • z = v1 ^ v2 (cross product)

    • y = z ^ x (cross product)

Returns:

  • N2PReport – Report instance containing the specified result configuration. The report provides methods to:

    • Calculate result arrays returning headers and results as numpy.ndarray (dtype=str)

    • Export data to CSV format

  • .. note:: – Only one result type is available per report. For example, you can extract all DISPLACEMENTS components for all load cases, but cannot include STRESSES in the same report.

Examples

>>> report1 = model.new_report(
...     "<LC1:FR1>,<LC2:FR1>",
...     False,
...     "DISPLACEMENTS",
...     "<X:NONE#>,<Y:NONE#>",
...     False,
...     list_n2pnodes,
...     "LC"
... )
>>> report2 = model.new_report(
...     "<LC1:FR1>,<LC1:FR2>,<LC4:FR6>",
...     False,
...     "STRESSES",
...     "<VON_MISES:Z1#Z2#>,<MAX_SHEAR:Z1#Z2#>",
...     False,
...     list_n2pelements,
...     "IDS",
...     aveSections=-4,
...     coordsys=-1
... )
set_user_coord_sys(array2d: list | ndarray, where: Literal['NODES', 'ELEMENTS']) None[source]#

Method that sets a coordinate system for each node/element as a user coordinate system using an array defined by the user.

The user can define a different system for each element or node and ask for results in that system using the optional argument “coordsys=-20”

The structure of the array must have the node/element identification, and the coordinates of the vectors v1 and v2 that generates the system: x = v1; z = v1^v2; y = z^v1. The structure for elements and nodes must be:

[ [node_id_1,part_id_1,x11,y11,z11,x12,y12,z12], [node_id_2,part_id_2,x21,y21,z21,x22,y22,z22], … ]

user_system_elements_example.csv:

[ [1001,0,1,0,0,0,1,0], [1002,0,0.3,0.2,0,0,1,0], [1003,0,0,1,0,1,1,0], [1004,0,2,0,1,0.4,1,3] ]

Warning

If an array is passed to this method and the another is passed, the previous information will be deleted.

Parameters:
  • array2d – list|np.ndarray. The array can be a list of list or a two dimensional array of numpy with the type float

  • where – “NODES”|”ELEMENTS”. The user coordinate systems are for the nodes or the elements.

Examples

>>> array_ele = [ [1001,0,1,0,0,0,1,0], [1002,0,0.3,0.2,0,0,1,0], [1003,0,0,1,0,1,1,0],
>>> ...           [1004,0,2,0,1,0.4,1,3] ]
>>> array_node = np.array([ [2001,0,1,0,0,0,1,0], [2002,0,0.3,0.2,0,0,1,0], [2003,0,0,1,0,1,1,0],
>>> ...           [2004,0,2,0,1,0.4,1,3] ], dtype=float)
>>>
>>> N2PModelContent.set_user_coord_sys(array2d=array_ele, where="ELEMENTS")
>>> N2PModelContent.set_user_coord_sys(array_node, "NODES")
property AbaqusVersion: str#

Returns the Abaqus version used in the output result file if the solver is Abaqus

property ConnectorsDict: OrderedDict[tuple[int, int], N2PConnector]#

Returns a dictionary with the N2PConnector of the model as values. The key is the tuple (id, partid)

property ElementsDict: OrderedDict[tuple[int, int], N2PElement]#

Returns a dictionary with the N2PElement of the model as values. The key is the tuple (id, partid)

property FilePath: str#

Path (may be relative or absolute) file where the model was read from.

property LoadCases: list[N2PLoadCase]#

Returns a list with all the of N2PLoadCase

property MaterialDict: dict[tuple[int | str, str], N2PMaterial]#

Dictionary of materials. Key is a tuple that is ID (a int for Nastran/Optistruct or str for Abaqus) and the part (str), and value is a N2PMaterial

It is not initialized at first, only when it is needed.

Returns:

dict[(ID, Part)] = N2PMaterial

Example

>>> # For nastran the first item of the tuple is a int
>>> nastran_model = n2p.load_model(r".\nastran.op2")
>>> my_mat_10 = model.MaterialDict[(10, "0")]
>>> prop = model.PropertyDict(1000)
>>> my_mat = model.MaterialDict[(prop.MatID, prop.Part)]
>>> # For abaqus the first item of the tuple is a str
>>> abaqus_model = n2p.load_model("abaqus.odb")
>>> my_mat_Al = model.MaterialDict[("ALUMINIUM", "0")]
>>> prop = model.PropertyDict(1000)
>>> my_mat = model.MaterialDict[(prop.MatID, prop.Part)]
property ModelInputData: N2PNastranInputData | N2PAbaqusInputData#

Returns a N2PNastranInputData or a N2PAbaqusInputData with the information of the input data file

property NodesDict: OrderedDict[tuple[int, int], N2PNode]#

Returns a dictionary with the N2PNode of the model as values. The key is the tuple (id, partid)

property NumberLoadCases: int#

Number of load cases of the model

property Parts: list[str]#

Returns the list of parts/superelements of the model

property PropertyDict: dict[int, N2PProperty]#

Dictionary of properties. Key is a tuple that is ID (a int for Nastran/Optistruct or str for Abaqus) and the part (str), and value is a N2PProperty

It is not initialized at first, only when it is needed.

Returns:

dict[(ID, Part)] = N2PProperty

Example

>>> # For nastran the first item of the tuple is a int
>>> nastran_model = n2p.load_model(r".\nastran.op2")
>>> my_prop_20 = model.PropertyDict[(20, "0")]
>>> my_prop = model.PropertyDict[(ele.Prop, prop.Part)]
>>> # For abaqus the first item of the tuple is a str
>>> abaqus_model = n2p.load_model("abaqus.odb")
>>> my_prop_shell = model.PropertyDict[("SHELL", "0")]
>>> my_prop = model.PropertyDict[(ele.Prop, prop.Part)]
property SetList: list[N2PSet]#

Returns a list of N2PSet kept in the model. It works for Abaqus, Optitruct (.h3d), Nastran (.op2, *.h5)

Note

The sets in *.op2 Nastran are not saved by default. To keep this information the command PARAM, POSTEXT, YES must be used in the Bulk Data Section before running the solution.

Warning

The type of sets it is not usually saved, so the IDs could be for Nodes or Elements. The user must know if the set was defined for Elements or Nodes.

property Solver: str#

Solver of the model

NaxToPy.Core.N2PModelContent.OpenFiletoN2P(n2v_instance: N2ModelContent) N2PModelContent[source]#

Read a N2ModelContent object and transform it into a N2PModelContent object.

Parameters:

n2v_instance – N2ModelContent. Mandatory.

NaxToPy.Core.N2PModelContent.initialize(path: str, parallelprocessing: bool = False) N2PModelContent[source]#

Deprecated function. This funtion has been substituted by load_model()

NaxToPy.Core.N2PModelContent.load_model(path: str, parallelprocessing: bool = True, file_type: Literal['InputFileNastran', 'InputFileAbaqus', 'Binary'] = None, dict_gen: dict = None, filter: Literal['ELEMENTS', 'PROPERTIES', 'PARTS', 'NODES'] = None, loadconnectors=True) N2PModelContent[source]#

Read an output result file in binary format from Nastran, Abaqus, Optistruct or Ansys and transform it into a N2PModelContent Object. It also can read models from input files in Nastran format.

Supports .op2, .xdb, .odb, .h5, .h3d and .rst file extensions read from a local filesystem or URL.

Supports Nastran Input Files (typically .bdf extension) and Abaqus Input File (typically .inp extension)

Parameters:
  • path – str. Mandatory.

  • parallelprocessing – bool. Optional. If true, the low libraries open the result files in several processes. It is slightly faster.

  • file_type – str. Optional. It specifies if it is Nastran input file (“InputFileNastran”), Abaqus input file (“InputFileAbaqus”) or binary result file (“Binary”).

  • filter – str. Optional. It specifies what to load in dict_gen (elements, properties, parts or nodes)

  • dict_gem – dict. Optional. Dictionary that represents what elements/properties/parts/nodes to load. For elements and nodes, the dictionary is in the form {Part ID (str): [Elements ID/Nodes ID]}. For parts or properties, the dictionary could simply be in the form {Part ID (str) / Property ID (str): []}.

Returns:

Instance with all the model data.

Return type:

N2PModelContent

Examples

>>> model1 = load_model(r"C:\MODELS\FEM\model1.dat")
>>> # file_type is not needed. It only helps the program and saves a checking
>>> model2 = load_model(r"C:\MODELS\FEM\model2.dat", file_type="InputFileNastran")
>>> # parallelprocessing is only aviable for Binary files. It is helpful in some big files.
>>> model3 = load_model(r"C:\MODELS\RESULTS\model1.op2", parallelprocessing=True)
>>> model4 = load_model(r"C:\MODELS\RESULTS\model2.xdb", file_type="Binary")
>>> model5 = load_model(r"C:\MODELS\RESULTS\model5.h3d")
>>> model6 = load_model(r"C:\MODELS\RESULTS\model6.odb", True, "Binary")