2. Mesh#

2.1 General Mesh Methods#

import NaxToPy as n2p

path = r"C:\Data\models\subcase\subcase_17500.op2"

model = n2p.load_model(path)

# NODES

# Retrieve all the nodes
all_nodes = model.get_nodes()
# Retrieve only this nodes
some_nodes = model.get_nodes([61, 62, 63, 64])
# Same as previous instruction but specifying the part or superelement
some_nodes_2 = model.get_nodes([(61, "0"), (62, "0"), (63, "0"), (64, "0")])
# The N2PNode class:
a_node = all_nodes[123]

connectivity = a_node.Connectivity
coordinates = a_node.GlobalCoords
internal_id = a_node.InternalID

# ELEMENTS

# Retrieve all the elements
all_elements = model.get_elements()
# Retrieve only this elements. Ids passed as a list[int]. No part -> part "0" in nastran
some_elements = model.get_elements([42700080, 42700081, 42700082, 42700083])
# Same as previous instruction but specifing the part or superelement
some_elements_2 = model.get_elements([(42700080, "0"), (42700081, "0"), (42700082, "0"), (42700083, "0")])
# Filtering the elements
cquad_elements = model.get_elements_filtered(elementType=["CQUAD4"])
prop_elements = model.get_elements_filtered(properties=[1, 3])
mat_elements = model.get_elements_filtered(materials=[1])
comb_elements = model.get_elements_filtered(elementType=["CBAR"], properties=[4], materials=[1])

# The N2PElement class
a_element = all_elements[234]
ele_nodes = a_element.Nodes
ele_type = a_element.TypeElement
ele_system = a_element.ElemSystemArray
ele_centroid = a_element.Centroid
ele_internal_id = a_element.InternalID

# Element functions according to their connectivity. A list of elements can be selected to begging the search
# The domain of search can be specify or not. Is equivalent a visible elements in an interface app
adjacent_elements = model.get_elements_adjacent(cells=[a_element], domain=cquad_elements)
face_elements = model.get_elements_by_face(a_element)
attached_elements = model.get_elements_attached(a_element)

# CONNECTORS

# In NaxToPy connectors are a different class from elements. Connectors in nastran are the RBE3, RBE2 and MPC
all_conn = model.get_connectors()
a_conn = model.get_connectors(53510014)
conn_type = a_conn.TypeConnector
conn_freenodes = a_conn.FreeNodes


# MATERIALS
materials = model.get_materials()
material_999 = model.get_materials(999)

mat_poisson = material_999.Poisson
mat_young = material_999.Young

# PROPERTIES
properties = model.get_properties()
prop_10 = model.get_properties(10)

mat_thickness = prop_10.Thickness

# if it is a PCOMP some useful properties are: EqBenProps, EqMemProps, EQMatrix, EqQBenMatrix...
if prop_10.PropertyType == "PCOMP":
    eq_ben_props = prop_10.EqBenProps # tuple containing (Ex, Ey, nu, G) in bending behavior.
    eq_mem_props = prop_10.EqMemProps # tuple containing (Ex, Ey, nu, G) in membrane behavior.
    eq_mem_matrix = prop_10.EQMatrix # Returns the lamina membrane stiffness matrix Qm
    eq_ben_matrix = prop_10.EqQBenMatrix # Returns the lamina bending stiffness matrix Qb

# COORDINATE SYSTEMS

# The coordinates of the model can be obtain using:
coords = model.get_coords()

# New coordinate systems may be created in NaxToPy. ID is set internally by NaxToPy with a negative integer
new_coord = model.new_coordinate_system("NewCoord", (0, 0, 0), (0.5, 0.5, 0), (0, 0, 1), "RECTANGULAR")

# Other option to set coordinates system is to specify a coordinate system to each node or element.
# This method set a system to the elements 39900000, 39900001, 39900002 and 39900003
model.set_user_coord_sys(
    [ [39900000,0,1,0,0,0,1,0], 
      [39900001,0,0.3,0.2,0,0,1,0], 
      [39900002,0,0,1,0,1,1,0], 
      [39900003,0,2,0,1,0.4,1,3] ], 
    "ELEMENTS")
# To ask results in these coordinates system, use coordsys=-20

# Other similar option is to introduce the systems by a csv file:
model.load_user_coord_sys_from_csv("some\\path\\file.csv", "NODES")

2.2 Input Data Methods (Nastran)#

When an input data file from nastran (.bdf, .dat) is loaded, it is possible to access each Card defined in the files. It also allows some preprocessing as it is possible to modify, create or delete the Nastran Cards.

"""
This methods allows to read the mesh directly from the Bulk Data Input File
but also MODIFY, CREATE AND DELETE some nastran cards. So some preprocessing
can be done with these methods.

These methods only works for input mesh files (bdf, dat, fem).
Abaqus function and classes are different from Nastran/Optistruct ones.
"""
import NaxToPy as n2p

# Import a model using the model input data file (bdf file in this case)
path = r"C:\Data\models\subcase\subcase_17500.dat"
model = n2p.load_model(path)

# The N2PNastranInputData object is the main object where the mesh information is saved
inputdata = model.ModelInputData

# Prints the tree of files that generates the model
inputdata.print_include_hierarchy()

# To find any card, use find_cards(). First, set the superelement, then the type of Card ("ELEMENT", "PROPERTY", "MATERIAL", ...)
# and finally the list of cards name. It retun a list of N2PCards
cbars = inputdata.find_cards(0, "ELEMENT", ["CQUAD4"], {"PID": 10})

# Selecting the fourth N2PCard of cbars
a_cbar = cbars[3]

# Its possible to introduce filters to narrow the search. The filter is introduced as a dictionary.
# Here, the first pshell is selected (using [0])
pshell = inputdata.find_cards(0, "PROPERTY", ["PSHELL"], {"PID": 10})[0]

# Prints the card definition in the console
pshell.print_field_definition_table()
# Prints the card in the console
pshell.print_fixed_format_table()

# The properties of the card can be modified
pshell.T = 3.0
pshell.print_fixed_format_table()

# New cards can be created. The name of the card and the path of the include are required arguments
new_pshell = inputdata.create_card("PSHELL", r"C:\Data\mesh")

# # Once is created the fields of the card are set using the N2PCard properties
new_pshell.MID1 = 1
new_pshell.PID = 999

# # Optional arguments are the superelement (0 by default)
other_pshell = inputdata.create_card("PSHELL", r"C:\Data\models\subcase\mesh")

# The tree of includes can be written in a directory with the same structure including the changes.
inputdata.rebuild_file(r"C:\Data\Examples\3_Mesh")

idaero-logo
© 2025 Idaero Solutions S.L.

All rights reserved. This document is licensed under the terms of the LICENSE of the NaxToPy package.