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

You are not logged in.

#1 2019-03-18 12:06:59

nirmaljoshi
Member
From: Japan
Registered: 2018-10-12
Posts: 152

[solved] Error in python script- it says some parameters not defined

Hi,
I am using python inside code-aster for first time for a corrosion related analysis to plot fore-displacement diagram.

I get error saying
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! erreur de syntaxe,  Erreur de nom: name 'nl' is not defined ligne 98 !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I double checked my script it seems okay. I suppose i need a third eye to identify the error.

I checked the instruction in code-aster.org/forum2/viewtopic.php?id=24011.

May be I am doing something wrong?

mesh = LIRE_MAILLAGE(FORMAT='MED',
                     UNITE=20)

model = AFFE_MODELE(AFFE=_F(GROUP_MA=('Group_bar', ),
                            MODELISATION=('BARRE', ),
                            PHENOMENE='MECANIQUE'),
                    MAILLAGE=mesh)

elemprop = AFFE_CARA_ELEM(BARRE=_F(CARA='A',
                                   GROUP_MA=('Group_bar', ),
                                   SECTION='GENERALE',
                                   VALE=0.000113),
                          MODELE=model)

steelC = DEFI_MATERIAU(CORR_ACIER=_F(D_CORR=0.2,
                                     ECRO_K=500000000.0,
                                     ECRO_M=2.781,
                                     SY=500000000.0),
                       ELAS=_F(E=2e+11,
                               NU=0.3))

steel0 = DEFI_MATERIAU(ELAS=_F(E=2e+11,
                               NU=0.3))

fXArea = DEFI_FONCTION(INTERPOL=('LIN', ),
                       NOM_PARA='INST',
                       PROL_DROITE='LINEAIRE',
                       PROL_GAUCHE='LINEAIRE',
                       VALE=(0.0, 0.001, 0.001, 0.0001))

fload = DEFI_FONCTION(NOM_PARA='INST',
                      VALE=(0.0, 0.0, 1.0, 1.0))

listr = DEFI_LIST_REEL(DEBUT=0.0,
                       INTERVALLE=_F(JUSQU_A=0.001,
                                     NOMBRE=20))

support = AFFE_CHAR_MECA(DDL_IMPO=(_F(DX=0.0,
                                      DY=0.0,
                                      DZ=0.0,
                                      GROUP_NO=('Group_supportNode', )),
                                   _F(DY=0.0,
                                      DZ=0.0,
                                      GROUP_NO=('Group_supportInterme', ))),
                         MODELE=model)

load0 = AFFE_CHAR_MECA(DDL_IMPO=_F(DX=1.0,
                                   DY=0.0,
                                   DZ=0.0,
                                   GROUP_NO=('Group_loadingnode', )),
                       MODELE=model)
#variable for various degree of corrosion 0-90%
vCHCOR = range(0,95,20)
itr=len(vCHCOR)
CHCOR=[NONE]*itr
fieldmat=[NONE]*itr
resnonl=[NONE]*itr
rxn=[NONE]*itr
force=[NONE]*itr
depl=[NONE]*itr
printstr=''

for i in range(itr):
    corrlevel=vCHCOR[i]
    CHCOR = CREA_CHAMP(AFFE=_F(GROUP_MA=('Group_bar', ),
                            NOM_CMP=('CORR', ),
                            VALE=(corrlevel, )),
                    MAILLAGE=mesh,
                    OPERATION='AFFE',
                    TYPE_CHAM='CART_CORR_R')
    
    fmat = AFFE_MATERIAU(AFFE=_F(MATER=(steelC, ),
                                    TOUT='OUI'),
                            AFFE_VARC=_F(CHAM_GD=CHCOR,
                                        GROUP_MA=('Group_bar', ),
                                        NOM_VARC='CORR'),
                            MAILLAGE=mesh,
                            MODELE=model)
    
    nl[i] = STAT_NON_LINE(CARA_ELEM=elemprop,
                            CHAM_MATER=fmat,
                            COMPORTEMENT=_F(ITER_INTE_MAXI=20,
                                            ITER_INTE_PAS=200,
                                            RELATION='CORR_ACIER',
                                            RESI_CPLAN_RELA=1e-06),
                            CONVERGENCE=_F(ITER_GLOB_MAXI=200,
                                        RESI_GLOB_MAXI=0.001),
                            EXCIT=(_F(CHARGE=support),
                                _F(CHARGE=load0,
                                    FONC_MULT=fload)),
                            INCREMENT=_F(LIST_INST=listr),
                            METHODE='NEWTON',
                            MODELE=model,
                            NEWTON=_F(MATRICE='TANGENTE'))
    
    rxn[i] = CALC_CHAMP(FORCE=('REAC_NODA', ),
                    RESULTAT=nl[i])

    #IMPR_RESU(FORMAT='RESULTAT',
    #          RESU=_F(RESULTAT=resnonl),
    #          UNITE=3)
    
    #IMPR_RESU(FORMAT='RESULTAT',
    #          RESU=_F(RESULTAT=rxn),
    #          UNITE=80)

    force[i] = RECU_FONCTION(GROUP_NO=('Group_loadingnode', ),
                        NOM_CHAM='REAC_NODA',
                        NOM_CMP='DX',
                        RESULTAT=rxn[i])
    
    depl[i] = RECU_FONCTION(GROUP_NO=('Group_loadingnode', ),
                        NOM_CHAM='DEPL',
                        NOM_CMP='DX',
                        RESULTAT=nl[i])
#make result file
printstr=''
for i in range(itr):
   corrlevel=vCHCOR[i]
   printstr+= ' _F(FONC_X=depl['+str(i)+'],FONC_Y=force['+str(i)+'])'
   if i<itr-1:
        printstr+=','

IMPR_FONCTION(COURBE=(printstr),
              FORMAT='TABLEAU',
              SEPARATEUR=' ,',
              UNITE=8)

Last edited by nirmaljoshi (2019-03-27 07:41:10)


Attachments:
python.zip, Size: 3.35 KiB, Downloads: 60

Offline

#2 2019-03-18 12:44:23

mecour
Member
From: Ostrava (Czech)
Registered: 2011-04-04
Posts: 143

Re: [solved] Error in python script- it says some parameters not defined

Hello,

You did not define the nl concept before cycle.

maybe there is problem

Offline

#3 2019-03-18 12:56:51

nirmaljoshi
Member
From: Japan
Registered: 2018-10-12
Posts: 152

Re: [solved] Error in python script- it says some parameters not defined

Offcourse I understood the error message and there is problem. But the script seems correct to me.

The nl concept(variable?) is a list, so it has values such as nl[0],nl[1]etc and it stores the non-linear calculation results.


mecour wrote:

Hello,

You did not define the nl concept before cycle.

maybe there is problem

Offline

#4 2019-03-18 13:06:38

GPSalachs
Member
Registered: 2018-03-10
Posts: 177

Re: [solved] Error in python script- it says some parameters not defined

Is it possible that you have to cycle through the CHCOR and fmat parameters at each interaction?

Offline

#5 2019-03-18 14:52:21

mecour
Member
From: Ostrava (Czech)
Registered: 2011-04-04
Posts: 143

Re: [solved] Error in python script- it says some parameters not defined

here you define almost all parameters but no the 'nl'

vCHCOR = range(0,95,20)
itr=len(vCHCOR)
CHCOR=[NONE]*itr
fieldmat=[NONE]*itr
resnonl=[NONE]*itr
rxn=[NONE]*itr
force=[NONE]*itr
depl=[NONE]*itr

according to dynamic python language you dont need to define variable but in code-aster there are many non-standard workarounds.

Offline