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

You are not logged in.

#1 2021-04-14 21:42:14

kmmarquezf
Member
Registered: 2021-03-16
Posts: 14

Get the new coordinates of a deformed mesh

Hi,

I have managed to modify a mesh in order to obtain a deformed one. However, when I try to get the new node coordinates through MAYL_PY, I get an error. How can I fix this error?

This is the part of the code where I modify the mesh:


    DISPL=CREA_CHAMP(TYPE_CHAM='NOEU_DEPL_R',
                                            OPERATION='EXTR',
                                            RESULTAT=res,
                                            NOM_CHAM='DEPL',)

    MAIL_MEC=MODI_MAILLAGE(reuse =MAIL_MEC,
                                                         MAILLAGE=MAIL_MEC,
                                                         DEFORME=_F(OPTION='TRAN',
                                                         DEPL=DISPL,))
   
    ALLdat2 = MAIL_PY()
    ALLdat2.FromAster(MAIL_MEC)
    ALLCrd = ALLdat2.cn


And this is the error that I get:
           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! erreur non prevue et non traitee prevenir la maintenance                    !
   ! Traceback (most recent call last):                                          !
   !    File "/home/kale/salome_meca/V2019.0.3_universal/tools/                  !
   ! Code_aster_stable-v144_smeca/lib/aster/Noyau/N_JDC.py", line 225, in        !
   ! exec_compile                                                                !
   !     exec(self.proc_compile, self.g_context)                                 !
   !    File "fort.1", line 740, in <module>                                     !
   !     ALLdat2.FromAster(MAIL_MEC)                                             !
   !    File "/home/kale/salome_meca/V2019.0.3_universal/tools/                  !
   ! Code_aster_stable-v144_smeca/lib/aster/Utilitai/partition.py", line 238, in !
   ! FromAster                                                                   !
   !     nom_maillage = nom.nom                                                  !
   !  AttributeError: 'tuple' object has no attribute 'nom'                      !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Offline

#2 2021-04-15 12:49:21

kmmarquezf
Member
Registered: 2021-03-16
Posts: 14

Re: Get the new coordinates of a deformed mesh

UPDATE:
I managed to get the coordinates of the deformed mesh, but I think it should be an easier way (plus I'll end with like large number of mesh files).
This is what i did: I just printed the mesh and read it again O.o, but I don't think that this is a practical way and for some reason I get orphan nodes warnings.

BTW I need the coordinates because according to the new position of the nodes i'll have to apply a new displacement to some of them and update the mesh again and do the analysis to this new mesh until a stop criteria is reached. Similar as simulating growth of a tissue.

What I did was the following:

for i range  (1,grwstp)
    .
    .
    .
    #creation of the displacement field

    DISPL=CREA_CHAMP(TYPE_CHAM='NOEU_DEPL_R',
                                            OPERATION='EXTR',
                                            RESULTAT=res,
                                            NOM_CHAM='DEPL',)

    ##################################################
    #modification of the mesh based on the displacement field

    MAIL_MEC=MODI_MAILLAGE(reuse =MAIL_MEC,
                                                                     MAILLAGE=MAIL_MEC,
                                                                     DEFORME=_F(OPTION='TRAN',
                                                                     DEPL=DISPL,))

    #################################################
    #Deformed mesh in MED FILE printing

    outFileName=path_def_mesh+"/def_mesh"+str(i)+".med"
    outFile=open(outFileName, "w")

    DEFI_FICHIER(ACTION='ASSOCIER',
                                              FICHIER=path_def_mesh+'/def_mesh'+str(i)+'.med',
                                              UNITE=i+100)

    IMPR_RESU(FORMAT='MED',
                          UNITE=i+100,
                          RESU=_F(MAILLAGE=MAIL_MEC))

    #################################################
    #Reading the deformed mesh

    DEFI_FICHIER(ACTION='LIBERER',
                              UNITE=i+100)

    DEFI_FICHIER(ACTION='ASSOCIER',
                              FICHIER=path_def_mesh+'/def_mesh'+str(i)+'.med',
                              UNITE=i+200)

    MAILMEC2 = LIRE_MAILLAGE(FORMAT='MED',
                                                         UNITE=i+200)

    #################################################
    #Manipulation of the mesh with python
  
    ALLdat2 = MAIL_PY() # Function to access mesh with python  
    ALLdat2.FromAster(MAILMEC2)
    ALLCrd2 = ALLdat2.cn  

    print('ESTE ES EL MAXIMOOO F',i,i,i, np.max(ALLCrd2[:,1], axis=0), ALLCrd2[1106,0]) #Eval of one node to check if dx is changing

I was just wondering why is it not possible to use MAIL_PY for a  mesh two times in the same analysis?? even more if the mesh have been modified with the MODI_MAILLAGE opeator. (at the beginning of my analysis I used  MAIL_PY to get some information of the pre-deformed mesh)

Anyway, I'm open to suggestions to improve this part of my code, because I truly don't thing this is an optimal way and I'm not very sure of why I got the error.

Thank you very much for taking the time to read this and have a good day!

Offline

#3 2021-04-23 05:49:06

konyaro
Member
From: Genève
Registered: 2016-04-02
Posts: 262

Re: Get the new coordinates of a deformed mesh

Hello,
your first solution should work, cf. attached file. Is it possible to share your comm file and mesh?

Konyaro


Attachments:
extr_mesh_2x.comm, Size: 1.76 KiB, Downloads: 97

失敗は成功のもと (L'échec est la base de la réussite)

Offline

#4 2021-05-08 23:40:35

MrSnail
Member
Registered: 2018-10-26
Posts: 35

Re: Get the new coordinates of a deformed mesh

kmmarquezf - not sure if that would help you but if you save out the deformed mesh in Aster format instead of med, you have all the node coordinates in a .mail file which is already a text.




Otherwise just for info, you can even scale a deformed mesh like that... maybe there is an in-built function for you too?
scale = 238

shape = CREA_CHAMP(identifier='1:3',
                   NOM_CHAM='DEPL',
                   NUME_ORDRE=1,
                   OPERATION='EXTR',
                   RESULTAT=modes,
                   TYPE_CHAM='NOEU_DEPL_R')

defmesh = CREA_CHAMP(identifier='2:3',
                     COMB=_F(CHAM_GD=shape,
                             COEF_R=scale),
                     OPERATION='COMB',
                     TYPE_CHAM='NOEU_DEPL_R')

mesh = MODI_MAILLAGE(identifier='3:3',
                     reuse=mesh,
                     DEFORME=_F(DEPL=defmesh,
                                OPTION='TRAN'),
                     MAILLAGE=mesh)

IMPR_RESU(identifier='4:3',
          RESU=_F(MAILLAGE=mesh),
          UNITE=13)

FIN()

Offline

#5 2021-05-11 07:38:01

kmmarquezf
Member
Registered: 2021-03-16
Posts: 14

Re: Get the new coordinates of a deformed mesh

Konyaro, I know it should work, but for me it was not maybe I had (or have) and error somewhere. I attached the meshes and comm files.

There are some path in the file that should be changed (it is a huge code).


MrSnail, I'll check if there is a function for the growth.

Thank you both for he information.


Attachments:
test.tar.xz, Size: 162.64 KiB, Downloads: 81

Offline