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

You are not logged in.

#1 2019-07-13 20:52:03

Anirudh
Member
Registered: 2017-09-11
Posts: 248

use python loop to parse values in ORIENTATION concept

Hi,
I am doing a study in which I have to assign values to mesh groups that can change every time. The list of values and list of mesh groups are identical in length and have one to one correspondence to each another. The groups with 'Spring_(i)' have to be assigned orientation under the concept:
ORIENTATION=(_F(CARA='ANGL_VRIL',
                                         GROUP_MA=('Spring_0'),
                                         VALE=-value[0]),
                            _F(CARA='ANGL_VRIL',
                                         GROUP_MA=('Spring_1'),
                                         VALE=value[1]),
                             _F(CARA='ANGL_VRIL',
                                         GROUP_MA=('Spring_2'),
                                         VALE=value[2]),
                             _F(CARA='ANGL_VRIL',
                                         GROUP_MA=('Spring_3'),
                                         VALE=value[3]),
                                .
                                .
                                .
)

Like that. The length of both lists group_spr and list_orien can change but is same always for both. These are imported from an external file as lists.
I tried using this kind of looping using zip function(ignore twice reading of meshes):

DEBUT(PAR_LOT='NON')
import sys
sys.path.insert(0,"/tmp/beam")
import lists
print lists.list_orien
print lists.group_spr
angle_cor={}
iter1=range(0,len(lists.list_orien))
print iter1
mesh_all = LIRE_MAILLAGE(FORMAT='MED',
                     UNITE=2)
mesh_pr = LIRE_MAILLAGE(FORMAT='MED',
                     UNITE=3)
model = AFFE_MODELE(AFFE=(_F(MODELISATION=('POU_D_E', ),
                             PHENOMENE='MECANIQUE',
                             TOUT='OUI'),
                          _F(GROUP_MA=('all_springs'),
                             MODELISATION=('DIS_T', ),
                             PHENOMENE='MECANIQUE')),
                    MAILLAGE=mesh_all)
                    
for it,edge,val in zip(iter1,lists.group_spr,lists.list_orien):
     angle_cor["key_{0}".format(it)]="_F(CARA='ANGL_VRIL',GROUP_MA=('{0}'),VALE={1}),".format(edge,val)
print angle_cor
x=tuple(angle_cor.values())
print x
elemprop = AFFE_CARA_ELEM(DISCRET=_F(CARA='K_T_D_L',
                                     GROUP_MA=('all_springs'),
                                     REPERE='LOCAL',
                                     VALE=(10.0, 10.0, 10.0)),
                          MODELE=model,
                          ORIENTATION=x
                                                                      ,
                          POUTRE=_F(CARA=('EP', 'H'),
                                    GROUP_MA=('all_beams', ),
                                    SECTION='RECTANGLE',
                                    VALE=(0.2, 1.0)))

FIN()

But it does not work. the best I get is substituted values correctly in strings in x like below:
("_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_5'),VALE=45.7433206854),", "_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_4'),VALE=45.7433206854),", "_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_7'),VALE=-19.5540855263),", "_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_6'),VALE=37.9421401286),", "_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_1'),VALE=-5.0),", "_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_0'),VALE=-5.0),", "_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_3'),VALE=-5.0),", "_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_2'),VALE=-5.0),", "_F(CARA='ANGL_VRIL',GROUP_MA=('Spring_8'),VALE=-31.8945021231),")

how do I assign the values?
Attaching message output file.

Thanks
Anirudh


Attachments:
message.mess, Size: 19.42 KiB, Downloads: 28

Offline

#2 2019-07-14 13:10:18

chenghui62000
Member
From: Norway
Registered: 2018-06-19
Posts: 83

Re: use python loop to parse values in ORIENTATION concept

Hi, your post is very interesting to me.

But, I think I did not understand your question very well.
As far as I know, you might need a python loop to assign the different values.

Best regards,
Hui Cheng

Offline

#3 2019-07-14 15:11:53

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 3,616

Re: use python loop to parse values in ORIENTATION concept

hello Anirudh

your handling of Python is too complicated for me
i am happy enough with the following way of doing things

#these can be read from a file
ori=(-5.0, -5.000000000000014, -5.000000000000014, -5.000000000000014, 45.743320685406246, 45.743320685406246, 37.94214012856506, -19.554085526329416, -31.89450212305018)
grp=('Spring_0', 'Spring_1', 'Spring_2', 'Spring_3', 'Spring_4', 'Spring_5', 'Spring_6', 'Spring_7', 'Spring_8')

orie=[];
for i in range (0,iter)
	orie.append( _F(GROUP_MA=grp[i],CARA='ANGL_VRIL',VALE=ori[i]),
);

elemprop = AFFE_CARA_ELEM(
	..........
	ORIENTATION=orie,

jean pierre aubry

Offline

#4 2019-07-16 00:22:16

Anirudh
Member
Registered: 2017-09-11
Posts: 248

Re: use python loop to parse values in ORIENTATION concept

Hi Jean Pierre,
Thanks a lot for the reply. It worked very well.
I have ran into another issue.
I want to post process displacements of beam elements in their local Coordinate systems. I attach an example for displacements in local Y of an element. Thus, I want displacements in the LOCAL CSYS of the element to which a node belongs. a node can belong to two elements, so there will be two values but thats ok.
All geometry lies in XOY plane
I tried with this but did not work:

table = POST_RELEVE_T(
                    ACTION=_F(
                        GROUP_NO=('all_beam_nodes', ), 
                        INTITULE='displacement', 
                        #MOYE_NOEUD='OUI',           #unsure what exactly is averaged
                        NOM_CHAM='DEPL', 
                        NOM_CMP=('DX', 'DY', 'DZ','DRX','DRY','DRZ'), 
                        OPERATION=('EXTRACTION', ), 
                        REPERE='LOCAL', 
                        RESULTAT=reslin,
                        VECT_Y=(0.0, 0.0, 1.0),        #Unsure if it works
                    )
)
IMPR_TABLE(FORMAT='TABLEAU', TABLE=table, UNITE=80)

The output file is created but its empty.

Thanks again.
Anirudh

Last edited by Anirudh (2019-07-16 00:35:35)


Attachments:
post_process_displacements.png, Size: 54.6 KiB, Downloads: 37

Offline

#5 2019-07-16 08:34:25

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 3,616

Re: use python loop to parse values in ORIENTATION concept

this works with an example of mine
VECT_Y looks like being the tricky bit

tablel = POST_RELEVE_T(
	ACTION=_F(
		RESULTAT=reslin
		INTITULE='displacement', 
		GROUP_NO=('all_beam_nodes',),
		NOM_CHAM='DEPL', 
		NOM_CMP=('DX', 'DY', 'DZ',),	
		REPERE='LOCAL', 
		VECT_Y=(0.0, 1.0, 0.0), #in agreement with the local Y of your model        
		OPERATION=('EXTRACTION', ), 
	),
);

i suggest yo run a first POST_RELEVE_T with  REPERE='GLOBAL', and a second one with REPERE='GLOBAL',
until you get the proper results
and look carefully at the .mess file if nothing is printed

Offline

#6 2019-07-16 09:32:49

Anirudh
Member
Registered: 2017-09-11
Posts: 248

Re: use python loop to parse values in ORIENTATION concept

Hello,
It works with GLOBAL but does not work with local.
This is my .comm file
Stage1

DEBUT(PAR_LOT='NON')
import sys
sys.path.insert(0,"/tmp/beam")
import lists
print lists.list_orien
print lists.group_spr
orie=[];


mesh_all = LIRE_MAILLAGE(FORMAT='MED',
                     UNITE=2)
model = AFFE_MODELE(AFFE=(_F(MODELISATION=('POU_D_E', ),
                             PHENOMENE='MECANIQUE',
                             TOUT='OUI'),
                          _F(GROUP_MA=('all_springs'),
                             MODELISATION=('DIS_T', ),
                             PHENOMENE='MECANIQUE')),
                    MAILLAGE=mesh_all)
                    
for i in range (0,len(lists.list_orien)):
	orie.append( _F(GROUP_MA=lists.group_spr[i],CARA='ANGL_VRIL',VALE=lists.list_orien[i]),);
print orie

elemprop = AFFE_CARA_ELEM(DISCRET=_F(CARA='K_T_D_L',
                                     GROUP_MA=('all_springs'),
                                     REPERE='LOCAL',
                                     VALE=(1.5e8, 1e9, 5000.0)),
                          MODELE=model,
                          ORIENTATION=orie,
                          POUTRE=_F(CARA=('EP', 'H'),
                                    GROUP_MA=('all_beams', ),
                                    SECTION='RECTANGLE',
                                    VALE=(0.04, 0.1)))
IMPR_RESU(CONCEPT=_F(CARA_ELEM=elemprop,
                     MODELE=model,
                     REPERE_LOCAL='ELNO'),
          UNITE=3)

FIN()

Stage2

mater = DEFI_MATERIAU(ELAS=_F(E=2e+11,
                              NU=0.33,
                              RHO=8000.0))

fieldmat = AFFE_MATERIAU(AFFE=_F(MATER=(mater, ),
                                 TOUT='OUI'),
                                 MODELE=model)

load0 = AFFE_CHAR_CINE(MECA_IMPO=(_F(DRX=0.0,
                                    DRY=0.0,
                                    DRZ=0.0,
                                    DX=0.0,
                                    DY=0.0,
                                    DZ=0.0,
                                    GROUP_NO=('start_vertex','end_vertex'),),
                                    _F(
                                    #DRX=0.0,
                                    #DRY=0.0,
                                    #DRZ=0.0,
                                    DX=0.0,
                                    DY=0.0,
                                    DZ=0.0,
                                    GROUP_NO=('all_bottom_fixed_points'),),),
                                MODELE=model)

load1 = AFFE_CHAR_MECA(PESANTEUR=_F(DIRECTION=(0.0, 0.0, -1.0),
                                    GRAVITE=9.81),
                                    MODELE=model)

reslin = MECA_STATIQUE(CHAM_MATER=fieldmat,
                        MODELE=model,
                        CARA_ELEM=elemprop,
                       
                       EXCIT=(_F(CHARGE=load0),
                              _F(CHARGE=load1)),
                       OPTION='SIEF_ELGA')
table = POST_RELEVE_T(
                    ACTION=_F(
                        GROUP_NO=('all_bm_nodes', ), 
                        INTITULE='displacement', 
                        #MOYE_NOEUD='OUI', 
                        NOM_CHAM='DEPL', 
                        NOM_CMP=('DX', 'DY', 'DZ',), 
                        OPERATION=('EXTRACTION', ), 
                        REPERE='LOCAL', 
                        RESULTAT=reslin,
                        MOYE_NOEUD='NON',
                        VECT_Y=(0.0, 1.0, 0.0),
                    )
)
IMPR_TABLE(
            FORMAT='TABLEAU', 
            TABLE=table, 
            UNITE=92
)  
IMPR_RESU(FORMAT='MED',RESU=_F(RESULTAT=reslin),UNITE=80)

Stage 1 is successful  but stage2 has errors.
Attaching all files.

Thanks
Anirudh


Attachments:
final_to_forum.tar.gz, Size: 10.53 KiB, Downloads: 30

Offline

#7 2019-07-16 15:29:37

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 3,616

Re: use python loop to parse values in ORIENTATION concept

please try the various options in 'tablel' in theattached file
and tell me your results

we may have to state that something is wrong in POST_RELEVE_T


Attachments:
test1.comm, Size: 4.8 KiB, Downloads: 23

Offline

#8 2019-07-16 20:01:46

Anirudh
Member
Registered: 2017-09-11
Posts: 248

Re: use python loop to parse values in ORIENTATION concept

Hi,
I again recieved the same error saying Node too far from the norm of the segment.
Then, I tried plugging directly the node numbers for nodes which did not have above error which I found to be N27 and N28
So, I tried this:

 table1 = POST_RELEVE_T(ACTION=_F(INTITULE='displacement',
                                   RESULTAT=RESU1,
                                   OPERATION=('EXTRACTION', ),
                                   NOEUD=('N27', 'N28'),
                                   VECT_Y=(0.0, 0.0, 1.0),
                                   NOM_CMP=('DX', 'DY', 'DZ'),
                                   MOYE_NOEUD='OUI',                       #averaged or not, same error
                                   REPERE='LOCAL',
                                   NOM_CHAM='DEPL',
                                   PRECISION=1.E-06,
                                   CRITERE='RELATIF',
                                   FORMAT_C='MODULE',),
                         INFO=1,)

The execution stopped with a red and I got this error:

 <I>_EXIT_CODE = 136

Attaching mess file.

Thanks
Anirudh


Attachments:
message2.mess, Size: 7.36 KiB, Downloads: 26

Offline

#9 2019-07-17 07:01:51

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 3,616

Re: use python loop to parse values in ORIENTATION concept

that is strange with NOEUD=('N27', 'N28'), and VECT_Y=(0.0, 0.0, 1.0),
i get a solutiion Y and Z inverted as it should
this on code_aster stand alone version 14.2 on Linux

Offline

#10 2019-07-17 13:06:12

Anirudh
Member
Registered: 2017-09-11
Posts: 248

Re: use python loop to parse values in ORIENTATION concept

Hi,
I tried various groups in many ways. But the results are random.
Sometimes it works, sometimes doesn't. Looks like it has more problems around curved geometry. Attaching a run mess file. I created a new group of nodes=g1, which is just a group of consecutive nodes near the beginning.
Group of nodes=post(which I believe is same as post_reduced in test1.comm) does not work either.
Comm file:

DEBUT(PAR_LOT='NON')


#i had to disable all that as i do not have the file /tmp/beam
# import sys
# sys.path.insert(0,"/tmp/beam")
# import lists
# print lists.list_orien
# print lists.group_spr
# orie=[];


mesh_all = LIRE_MAILLAGE(FORMAT='MED',UNITE=2)

mesh_all=DEFI_GROUP(
    reuse =mesh_all,
    MAILLAGE=mesh_all,
    #next we create some groups of node
    CREA_GROUP_NO=(
    	#in a ordered manner
		#_F(
		#	NOM='post',
		#	GROUP_MA='all_beams',
		#	OPTION='NOEUD_ORDO',
		#	NOEUD_ORIG='N27',
		#	NOEUD_EXTR='N31',
		#),
		#should be the same as 'post'
		_F(
			NOM='post',
			NOEUD=('N4','N6','N8','N10','N12','N14','N16','N18','N20','N22','N172','N174','N176','N178','N180','N182','N184','N440','N442','N444','N446','N448','N450','N452','N454','N456','N458','N716','N718','N720','N722','N724','N726','N728','N730','N734','N1144','N1145','N1146','N1147','N1148','N1149','N1150','N1151','N1152','N1153','N1154','N1155','N1156','N1157','N1158','N1159','N1160','N1161','N1162','N1163','N1164','N1165','N1166','N1167','N1168','N1169','N1170','N1171','N1172','N1173','N1174','N1175','N1176','N1177','N1178','N1179','N1180'),
		),
	),
);

model = AFFE_MODELE(AFFE=(_F(MODELISATION=('POU_D_E', ),
                             PHENOMENE='MECANIQUE',
                             TOUT='OUI'),
                          _F(GROUP_MA=('all_springs'),
                             MODELISATION=('DIS_T', ),
                             PHENOMENE='MECANIQUE')),
                    MAILLAGE=mesh_all)
                    
# for i in range (0,len(lists.list_orien)):
	# orie.append( _F(GROUP_MA=lists.group_spr[i],CARA='ANGL_VRIL',VALE=lists.list_orien[i]),);
# print orie

elemprop = AFFE_CARA_ELEM(
	MODELE=model,
	DISCRET=_F(
		CARA='K_T_D_L',
		GROUP_MA=('all_springs'),
		REPERE='LOCAL',
		VALE=(1.5e8, 1e9, 5000.0),
	       ),
        ORIENTATION=_F(GROUP_MA='all_beams',CARA='VECT_Y',VALE=(0.0,0.0,1.0),), 
	#and the discrete with local Y in global Y
	#ORIENTATION=orie,
	POUTRE=_F(
		CARA=('EP', 'H'),
		GROUP_MA=('all_beams', ),
		SECTION='RECTANGLE',
		VALE=(0.04, 0.1),
	),
);
IMPR_RESU(CONCEPT=_F(CARA_ELEM=elemprop,
                     MODELE=model,
                     REPERE_LOCAL='ELNO'),
          UNITE=3)

#FIN()


mater = DEFI_MATERIAU(ELAS=_F(E=2e+11,
                              NU=0.33,
                              RHO=8000.0))

fieldmat = AFFE_MATERIAU(AFFE=_F(MATER=(mater, ),
                                 TOUT='OUI'),
                                 MODELE=model)

load0 = AFFE_CHAR_CINE(MECA_IMPO=(_F(DRX=0.0,
                                    DRY=0.0,
                                    DRZ=0.0,
                                    DX=0.0,
                                    DY=0.0,
                                    DZ=0.0,
                                    GROUP_NO=('start_vertex','end_vertex'),),
                                    _F(
                                    #DRX=0.0,
                                    #DRY=0.0,
                                    #DRZ=0.0,
                                    DX=0.0,
                                    DY=0.0,
                                    DZ=0.0,
                                    GROUP_NO=('all_bottom_fixed_points'),),),
                                MODELE=model)

load1 = AFFE_CHAR_MECA(PESANTEUR=_F(DIRECTION=(0.0, 0.0, -1.0),
                                    GRAVITE=9.81),
                                    MODELE=model)

reslin = MECA_STATIQUE(CHAM_MATER=fieldmat,
                        MODELE=model,
                        CARA_ELEM=elemprop,
                       
                       EXCIT=(_F(CHARGE=load0),
                              _F(CHARGE=load1)),
                       OPTION='SIEF_ELGA')

#this table seems to write ok
tableg = POST_RELEVE_T(
	ACTION=_F(
		GROUP_NO=('g1', ),
          #NOEUD=('N4','N6','N8','N10','N12','N14','N16','N18','N20','N22','N172','N174','N176','N178','N180','N182','N184','N440','N442','N444','N446','N448','N450','N452','N454','N456','N458','N716','N718','N720','N722','N724','N726','N728','N730','N734','N1144','N1145','N1146','N1147','N1148','N1149','N1150','N1151','N1152','N1153','N1154','N1155','N1156','N1157','N1158','N1159','N1160','N1161','N1162','N1163','N1164','N1165','N1166','N1167','N1168','N1169','N1170','N1171','N1172','N1173','N1174','N1175','N1176','N1177','N1178','N1179','N1180'), 
		#NOEUD=('N27','N32','N33','N34','N20','N35','N36','N37','N18','N38',),  
		INTITULE='displacement', 
		#MOYE_NOEUD='OUI', 
		NOM_CHAM='DEPL', 
		NOM_CMP=('DX', 'DY', 'DZ',), 
		OPERATION=('EXTRACTION', ), 
		REPERE='LOCAL', 
		RESULTAT=reslin,
		#MOYE_NOEUD='NON',
          VECT_Y=(0.0, 0.0, 1.0),
	)
)
IMPR_TABLE(FORMAT='TABLEAU',TABLE=tableg,UNITE=92);
IMPR_RESU(FORMAT='MED',RESU=_F(RESULTAT=reslin),UNITE=80);
#try the various option in this
FIN()

Thanks
Anirudh

Last edited by Anirudh (2019-07-17 13:14:02)


Attachments:
latest_run.tar.gz, Size: 70.71 KiB, Downloads: 22

Offline

#11 2019-07-17 17:15:28

jeanpierreaubry
Guru
From: nantes (france)
Registered: 2009-03-12
Posts: 3,616

Re: use python loop to parse values in ORIENTATION concept

Anirudh wrote:

But the results are random.
Sometimes it works, sometimes doesn't. Looks like it has more problems around curved geometry.

that is exactly my conclusion!

Offline