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

You are not logged in.

#1 2008-05-02 10:46:58

BL
Member
Registered: 2008-03-13
Posts: 131

Using python with Aster

I am attempting to use python within my .comm file.  I understand that I must use DEBUT(PAR_LOT='NON').  I know my statements will run correctly in python, but I have questions about for it is parsed for use by Aster.  Below are two commands.  The first works, (unless I mistyped).  The second should be the same but when I try it the program fails.  Am I not allowed to used syntax of this sort in a command to be read by aster?

Pressure=AFFE_CHAR_MECA(MODELE=TestCase,
                                               FORCE_COQUE=(
                                       _F(MAILLE='M1',PRES=1013000,)
                                                                           ,),);

myString = "_F(MAILLE='M1',PRES=1013000,)"
Pressure=AFFE_CHAR_MECA(MODELE=TestCase,
                                               FORCE_COQUE=(
                                       myString
                                                                           ,),);

Offline

#2 2008-05-02 14:39:59

Archibald Archambaud
Member
From: Clamart, France
Registered: 2007-12-03
Posts: 322

Re: Using python with Aster

Hi BL,

Your second example *cannot* work since your are using a string. Code_Aster commands are not strings.
What you should do is :

myDict = {MAILLE:'M1', PRES:1013000}   #    <=   This is a Python dictionnary
Pressure=AFFE_CHAR_MECA(MODELE=TestCase,
                                               FORCE_COQUE=myDict
                                                                           );

You can also check several test cases : ssnd102a.comm, ssns108a.comm, ....

AA

Offline

#3 2008-05-02 16:20:29

BL
Member
Registered: 2008-03-13
Posts: 131

Re: Using python with Aster

Thank you, AA.

I would look at the examples but I do not have those particular files in my astest folder.


So Aster commands will accept dictionaries.  I understand how I can create a simple dictionary like the one you suggest which will appear properly in the command.

However I actually need to apply pressure to very many elements seperately.  How can a create a dictionary that can have multiple values for the keys of MAILLE and PRES.  I am currently using a loop and determining each line seperately.  However if I loop over the dictionary statement I will end with a redefined dictionary, not one with more values.

myDict = {MAILLE:'M2', PRES:1038000}
not
myDict = {MAILLE:'M1', PRES:1013000,MAILLE:'M2', PRES:1038000}

I am trying not to call the statement many time so it will have a single name instead of many when I need to use it/them in other commands.

Offline

#4 2008-05-02 20:50:23

Archibald Archambaud
Member
From: Clamart, France
Registered: 2007-12-03
Posts: 322

Re: Using python with Aster

You can really play with Python inside Code_Aster.

For instance (there are many other solutions...) :

myList=[]

for maille in list_maille:
  myList.append({MAILLE:maille.name, PRES:maille.press})

Pressure=AFFE_CHAR_MECA(MODELE=TestCase,
                        FORCE_COQUE=myList);

The above script supposes that you have previously defined maille.name and maille.press.

AA

Offline

#5 2008-05-05 12:48:27

BL
Member
Registered: 2008-03-13
Posts: 131

Re: Using python with Aster

Yes, I see that works quite well. Thank you, again AA.

If I want to loop over a section of Aster commands until a condition is met I need to be able to reuse the names of the objects created.  How can I get Aster to release these names?  I am not concerned about loosing data with this release, I just need to be able to reuse the code of the loop.

Offline

#6 2008-05-05 14:54:31

BL
Member
Registered: 2008-03-13
Posts: 131

Re: Using python with Aster

Nevermind, I found the command DETRUIRE.  That would have been easier if I could read French.

Offline

#7 2008-05-06 10:32:16

BL
Member
Registered: 2008-03-13
Posts: 131

Re: Using python with Aster

I am calculating  displacements in a loop.  I have a result called RSTAT with these and I could output the displacement with IMPR_RESU and DEPL, but the file is not written yet and is therefore unavailable. 

Instead I tried to use python to access the result directly.  U1.03.02b suggests using,
dictionary = EVOL.LIST_CHAMPS( )

However when I do this as, dictionary = RSTAT.LIST_CHAMPS( ), in my case I get an empty dictionary.  I am doing this is before I destroy the concept so that it may be called again.

How can I get the displacements (at the nodes) I calculate in a loop?

Offline

#8 2008-05-06 15:42:09

Thomas DE SOZA
Guru
From: EDF
Registered: 2007-11-23
Posts: 3,066

Re: Using python with Aster

This article in the wiki may help you : http://www.code-aster.org/wiki/doku.php … til:fields

Offline

#9 2008-05-07 14:04:48

BL
Member
Registered: 2008-03-13
Posts: 131

Re: Using python with Aster

The using the method suggested at the link, causes an Abnormal Abort.  So i am looking at oter options.  Since I am unable to access the result directly, I thought that writing it to a table might make it more accessable.  I believe tables are directly accessable via python.

The results I am trying read are from the MECA_STATIQUE command.  The command RECU_TABLE is capable of writing results to a table but I am not sure if it works for my result type.  Is there a wat of writing my results into a table?

Offline

#10 2009-11-05 09:26:30

arthurlr
Member
Registered: 2009-09-14
Posts: 26

Re: Using python with Aster

bonjour
Je travail aussi avec Python et Aster.
J'ai un group de noeud très nombreux et je veux appliquer un effort unitaire sur chaqu'un de ces groups. Alors dans la commande AFFE_CHAR_MECA je dois faire une boucle de dictionnaires afin de remplacer la partie _F(GROUP_NO= , FX= ,FY= ,FZ=). Les composants des effort sont égales, mais le GROUP_NO change.

J'obtiens un erreur que franchement je comprend pas
Quelqu'un a déjà eu ce problème et peux m'aider?
J'ai réalisé la commande hors d'une boucle et marche très bien. Le problème aparait quand la boucle est faite.
Merci pour l'attention

Arthur


Voici le programme .comm et l'erreur


import Utilitai.Table
import math

DEBUT(PAR_LOT='NON',);

ensemble=LIRE_MAILLAGE(FORMAT='MED',);

Modele=AFFE_MODELE(MAILLAGE=ensemble,
                   AFFE=_F(TOUT='OUI',
                           PHENOMENE='MECANIQUE',
                           MODELISATION='3D',),);

Acier=DEFI_MATERIAU(ELAS=_F(E=210000.0,
                            NU=0.3,),);

ChMat=AFFE_MATERIAU(MAILLAGE=ensemble,
                    AFFE=_F(TOUT='OUI',
                            MATER=Acier,),);

#Blocage des cotes gauche et droit

BlocFlex=AFFE_CHAR_MECA(MODELE=Modele,
                        DDL_IMPO=_F(GROUP_NO=('CDroite_','CGauche_',),
                                    LIAISON='ENCASTRE',),);


Ngroup=ensemble.LIST_GROUP_NO()    #< creation d'une list de group de noeud et un filtre pour selectioner     seulement les groups de noeud que je veux appliquer les efforts
Ncontact=[]
for i in range (len(Ngroup)):
    lNgroup=list(Ngroup[i])
    if lNgroup[1]==1:
        Ncontact.append(lNgroup[0])

Ntest=[Ncontact[0],Ncontact[1],Ncontact[2]]

listdict=[]                                        #< list de dictionnaires pour remplecer en FORCE_NODALE
for i in range (len(Ntest)):
    listdict.append({'GROUP_NO':Ncontact[i],'FX':0.9082,'FY':0.4183,'FZ':0.2})
    'Ch_'+Ncontact[i]+Ncontact[i]=AFFE_CHAR_MECA(MODELE=Modele,
                                          FORCE_NODALE=listdict[i]);

Et voici l'erreur


==========================================
==========================================
JDC.py : ERREUR DE COMPILATION DANS ACCAS - INTERRUPTION
>> JDC.py : DEBUT RAPPORT
CR phase d'initialisation
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! Compilation impossible :   File "fort.1", line 41 !
   !      FORCE_NODALE=listdict[i]);                   !
   !  SyntaxError: can't assign to operator            !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
fin CR phase d'initialisation

Offline