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

You are not logged in.

#1 2010-08-21 17:59:52

dbpatankar
Member
From: Roorkee, Uttarakhand, India
Registered: 2010-05-22
Posts: 172

[SOLVED]Extract value from a node and assign to a variable

Hello,

I am trying to extract displacement component (DZ) and assign a variable name to it so that I can use it in next iteration.
To make my point clear, say there is a node 'N35'. After applying load+bc, I am trying to get displacement component DZ and assign a variable say 'var' to it.
In algorithmic language :
var = DisplacementCompDZ('N35');

How can I achieve this?

Using POST_RELEVE_T, I can get it for group of nodes/node but it will be in table format and not a variable.
I want to assign the value to a variable.
Kindly help.

Last edited by dbpatankar (2010-08-21 20:39:40)

Offline

#2 2010-08-21 20:38:04

dbpatankar
Member
From: Roorkee, Uttarakhand, India
Registered: 2010-05-22
Posts: 172

Re: [SOLVED]Extract value from a node and assign to a variable

I found out the answer!

I didn't know much about Python and hence struggling to get that. But just after I read a little bit about dictionaries, lists in python, I got the solution.
Here is the answer for those who may be suffering from the same problem.

The table is something like :

NOEUD        X            Y            Z            DX           DY           DZ     
N64       1.19966E+00 -1.15865E-05 -1.63838E-03  1.81394E-03 -2.07795E-03  1.04842E-02
N113      1.49962E+00 -1.11233E-05 -2.36240E-03  2.05956E-03 -3.07869E-03  1.53553E-02
N159      9.11231E-23  1.27977E-22 -1.81301E-23  0.00000E+00  0.00000E+00  0.00000E+00
N270      2.69957E+00 -1.25319E-05 -5.68127E-03  2.48677E-03 -7.80872E-03  3.84270E-02
N346      1.79960E+00 -1.15171E-05 -3.14862E-03  2.24653E-03 -4.18034E-03  2.07363E-02
N372      2.09958E+00 -1.14958E-05 -3.97566E-03  2.37691E-03 -5.36016E-03  2.64737E-02
N425      8.99711E-01 -1.07778E-05 -1.00118E-03  1.51058E-03 -1.22664E-03  6.28355E-03
N461      2.99957E+00 -1.31310E-05 -6.54018E-03  2.50928E-03 -9.04506E-03  4.44634E-02
N500      2.39957E+00 -1.20486E-05 -4.82397E-03  2.44765E-03 -6.57507E-03  3.24065E-02
N770      5.99787E-01 -1.29910E-05 -4.84976E-04  1.07209E-03 -5.34566E-04  2.96552E-03
N851      2.99877E-01 -1.43431E-05 -1.34048E-04  6.04560E-04 -7.56027E-05  7.79659E-04


Say I want to extract every DZ separately and assign one variable to it.


1. Create a table using POST_RELEVE_T having required values(as shown above). Say that table is TBL
2. Now extract this table into a variable say VAR, by
       VAR = TBL.EXTR_TABLE();
3. This variable VAR will have many attributes, 'values' attribute is the one which is of our interest for this case.
    VAR.values() is actually a dictionary. For the above table, VAR.values() will look like :
    VAR.values() = {'NOEUD': ['N64     ', 'N113   ....],'X':[1.19......],'Y':[........],'Z':[.........],'DX':[........],'DY'[........],'DZ':[.........]}

   Now I will call 'NOEUD', 'X', 'Y', 'Z', 'DX', 'DY', 'DZ' as properties of the table.
4. Now if I want to access DZ component of node N425 then,
    (VAR.values().['DZ'])[6];
    This will give me value 6.28355E-03, which is what I want.
5. So
    myvar =  (VAR.values().['property'])[index];
   will do the necessary trick.
6. Now one can use for loop in python and assign every single DZ value to different variables.


Hope this helps.

(NOTE : My python knowledge is not even basic so please ignore if there are any python keywords mentioned wrongly. The above procedure just works. There may be other more efficient ways to do so. I highly appreciate if someone would like to point them out.)

Offline

#3 2016-07-28 13:48:32

emanu.gerb
Member
Registered: 2016-07-14
Posts: 20

Re: [SOLVED]Extract value from a node and assign to a variable

Hi, I know is a very old post but I'm trying to extract value using the POST_RELEVE_T command. After the point 4 I have the error below:

CR phase d'initialisation
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! Compilation impossible :   File "fort.1", line 648 !
   !      (VAR.values().['VALE'])[3];                   !
   !                    ^                               !
   !  SyntaxError: invalid syntax                       !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
fin CR phase d'initialisation

Could someone help me

Offline

#4 2016-07-29 13:36:14

dbpatankar
Member
From: Roorkee, Uttarakhand, India
Registered: 2010-05-22
Posts: 172

Re: [SOLVED]Extract value from a node and assign to a variable

Try removing the 'dot' in between values() and ['VALE']

So it should be

(VAR.values()['VALE'])[3];

Instead for clarity in expression, in the third step assign a new variable to VAR.values(). So its a python dictionary. Then access the dictionary elements.
For example :

a = VAR.values()
a['VALE'][3]

See if it works. And report it here so that it will be useful to someone else too.

Offline

#5 2016-10-18 10:07:44

Kevin-JS
Member
Registered: 2015-07-31
Posts: 19

Re: [SOLVED]Extract value from a node and assign to a variable

Hi dbpatankar,

Thank you for sharing your python codes. As you said, you are going to extract the DZ value and then used for your next iteration. I am wondering how you assign these variables to yours nodes. What is the command line you using for this task. I am trying to do pretty similar thing with you, namely, I am going to assign a list of forces to nodes or assign a list of  pressure to each shell element. Could you give me some clues and guidance?Thank you.

Kevin

Offline

#6 2016-10-18 10:51:50

dbpatankar
Member
From: Roorkee, Uttarakhand, India
Registered: 2010-05-22
Posts: 172

Re: [SOLVED]Extract value from a node and assign to a variable

Hi Kevin-JS,

For that I think you should look into command AFFE_CHAR_MECA. It has a subcommand FORCE_NODALE which can be used for the same purpose.

I hope I have understood your question correctly.

With regards,

Offline

#7 2016-10-19 05:06:15

Kevin-JS
Member
Registered: 2015-07-31
Posts: 19

Re: [SOLVED]Extract value from a node and assign to a variable

dbpatankar wrote:

Hi Kevin-JS,

For that I think you should look into command AFFE_CHAR_MECA. It has a subcommand FORCE_NODALE which can be used for the same purpose.

I hope I have understood your question correctly.

With regards,

Thank you for your quick reply. That is my question. I found a psot by Bracchesimo was quite useful. But I haven't try the command yet.
http://code-aster.org/forum2/viewtopic.php?id=14348. I have two questions about applying a list of forces on nodes.
1. An error arise when I try to use class MAIL_PY by importing partition module. Message shows that python can't find some modules used in paritition module. Do you have any experience in using python?
2. I am not sure if command AFFE_CHAR_MECA can define the loading with a force list like this 

CHAR=AFFE_CHAR_MECA(MODELE=MODE,
                    DDL_IMPO=(_F(GROUP_NO='fixed',DX=0.0,DY=0.0, DZ=0.0,),
                              _F(GROUP_NO='slidey',DY=0.0,),),     
            FORCE_NODALE=(forcelist),

Thank you for your time.

Kevin

Offline

#8 2016-10-19 07:11:42

dbpatankar
Member
From: Roorkee, Uttarakhand, India
Registered: 2010-05-22
Posts: 172

Re: [SOLVED]Extract value from a node and assign to a variable

Kevin-JS wrote:

1. An error arise when I try to use class MAIL_PY by importing partition module. Message shows that python can't find some modules used in paritition module. Do you have any experience in using python?
Kevin

I haven't used partition module before so cannot say anything about it with certainty. But as per the suggestion in url you posted, aster/STA<your aster version>/bibpyt/Utilitai should be in the search folder.

Kevin-JS wrote:

2. I am not sure if command AFFE_CHAR_MECA can define the loading with a force list like this 

CHAR=AFFE_CHAR_MECA(MODELE=MODE,
                    DDL_IMPO=(_F(GROUP_NO='fixed',DX=0.0,DY=0.0, DZ=0.0,),
                              _F(GROUP_NO='slidey',DY=0.0,),),     
            FORCE_NODALE=(forcelist),

Thank you for your time.
Kevin

As given in http://code-aster.org/forum2/viewtopic.php?id=14348, the application of force list on a node list is possible. If fact its a very nice use of python there to achieve it. Especially I liked the use of

forcelist.append(_F(NOEUD = 'N%d' % (i),FZ=F[c],),)

to create the force and node combination. So it will work properly if you have partition module working properly.

Moreover, if you post your query on a separate thread then probably you will have better chances of getting to the point answers. The current thread we are discussing on is very old and hence its visibility is very less.

Offline

#9 2016-10-19 22:35:27

Kevin-JS
Member
Registered: 2015-07-31
Posts: 19

Re: [SOLVED]Extract value from a node and assign to a variable

Hi dbpatankar,

Thank you for your suggestion. I am going to create another post on this issue.

Kevin

Last edited by Kevin-JS (2016-10-19 22:43:29)

Offline

Board footer