Welcome to the forums. Please post in English or French.

You are not logged in.

#1 2021-10-20 12:18:08

z-1616
Member
Registered: 2020-07-20
Posts: 10

[SOLVED] adding nodes using MAIL_PY()

Dear all,

I'm trying to add nodes to my mesh using the following commands in MAIL_PY():

|  # Le décalage de -1 est déjà fait sur les numéros des noeuds et des mailles
|  # Pour ajouter des Noeuds
|     #  Coordonnées
|           LesNoeudsEnPlus = NP.array([[xx,yy,zz]])
|           LesNoeudsEnPlus = NP.concatenate((LesNoeudsEnPlus,NP.array([[xx,yy,zz]])))
|     #  Noms
|           NomNoeudsEnPlus =     ['X%' % in]
|           NomNoeudsEnPlus.append('X%' % in)
|  # Ajout des noeuds au maillage : coordonnées , noms
|     mm.cn = NP.concatenate((mm.cn,LesNoeudsEnPlus))
|     mm.correspondance_noeuds = tuple(linomno + NomNoeudsEnPlus )

but I don't understand what the part ['X%' % in] is can someone give me an example of how should I successfully modify it.
I would really appreciate any help in this matter.

Thank you in advance,
Best Regards,
Zaki

Last edited by z-1616 (2021-11-27 01:54:27)

Offline

#2 2021-11-11 15:43:27

GuillermoBarraza
Member
Registered: 2016-05-24
Posts: 47

Re: [SOLVED] adding nodes using MAIL_PY()

Hi z-1616,

Here is a small script that add nodes to a mesh with MAIL_PY() :

# Creation of python mesh
mesh_py = MAIL_PY()
mesh_py.FromAster(MAILLAGE)  # read MED mesh and make it a python object

# Dictionary containing node's name as keys and node's coordinates as values
additional_nodes_dict = {
    "node_1": [x1, y1, z1],
    "node_2": [x2, y2, z2],
    ...
    "node_n": [xn, yn, zn]
} 

 # Node Names are given in mesh_py.correspondance_noeuds
list_of_node_names= list(mesh_py.correspondance_noeuds)
# Initial number of nodes
init_no_nodes = mesh_py.dime_maillage[0]

# Node coordinates to add:
node_coordinates = NP.zeros((len(additional_nodes_dict), 3)) # initialize a numpy array with size N rows and 3 columns (N is the number of nodes to add)
node_names = [] # initialize empty list of node names

for ii, node in enumerate(additional_nodes_dict.keys()):
        # 1. add node coordinates to numpy array
        node_coordinates[ii] = NP.array([additional_nodes_dict[node]])
        # node_names =     ['X%' %node] ->>>> THIS IS ONE OF THE THINGS YOU WERE WONDERING ABOUT
        node_names.append('%s' % node) # The '%s' is simply a string interpolation (%) of whatever the variable 'node' is storing, i.e. the node's name
        
        # Add node group to mesh
        group_name = node
        add_node_number = init_no_nodes + ii  # e.g. NUM_OF_NODES_IN_YOUR_MESH + 1
        mesh_py.gno[group_name] = NP.array([add_node_number])  # add node to mesh
        
# Add nodes to MESH : coord, name
mesh_py.cn = NP.concatenate((mesh_py.cn, node_coordinates))  # add node coordinates to mesh
mesh_py.correspondance_noeuds = tuple(list_of_node_names + node_names) # add node names

# Finally, update node count
number_of_nodes_to_add = len(additional_nodes_dict)
mesh_py.dime_maillage = list(mesh_py.dime_maillage)
mesh_py.dime_maillage[0] = init_no_nodes + number_of_nodes_to_add
mesh_py.dime_maillage = tuple(mesh_py.dime_maillage)

This is how you would add nodes to your mesh by assuming you have a map (dictionary) between your node names and their coordinates.


Hope you find it useful.

Cheers,
Guillermo

Offline

#3 2021-11-15 14:24:02

z-1616
Member
Registered: 2020-07-20
Posts: 10

Re: [SOLVED] adding nodes using MAIL_PY()

Dear Guillermo,

This helps a lot. I really appreciate your help.

Thank you so much.
Cheers,
Zaki

Offline

#4 2021-11-15 17:37:29

GuillermoBarraza
Member
Registered: 2016-05-24
Posts: 47

Re: [SOLVED] adding nodes using MAIL_PY()

You're welcome!

Don't forget to prepend [SOLVED] to the name of the thread in the case that you found the solution helped to solve your doubts smile

Offline