loop over element nodes with conditions

Moderator: GiD Team

Post Reply
lbenedetti
Posts: 6
Joined: Thu Dec 04, 2014 1:48 pm

loop over element nodes with conditions

Post by lbenedetti »

Hello,
I have a loop over the elements to get nodes conditions. For example, I have a face condition over a line and I get it from the .bas file with this:

Code: Select all

*Set Cond Face-Load    *elems  *CanRepeat
*loop elems *OnlyInCond
      ELEM=*elemsnum() NODES=*globalnodes
*if(QUADRAT==1)
      GLOBAL:     FX=*cond(2) FY=*cond(3) /
                  FX=*cond(2) FY=*cond(3) / 
                  FX=*cond(2) FY=*cond(3)
*else
      GLOBAL:     FX=*cond(2) FY=*cond(3) /
                  FX=*cond(2) FY=*cond(3) 
*endif
*end
Now, I would like to get the single information on the nodes that have that condition, in order to have a non constant force field (depending for example on the position).

Can I write a loop over *GlobalNodes (or *localnodes) and recall them in the loop as in the following?

Code: Select all

*loop globalnodes
        FX=*Operation(cond(2)*NodesCoord(globalnode,1))     FY=*Operation(cond(3)*NodesCoord(globalnode,2))
*end globalnodes
Also, is the use of NodesCoord in this case correct with globalnode or localnode? And how can I extract the counter in the loop?

Thank you very much!
User avatar
escolano
Posts: 1922
Joined: Sun Sep 05, 1982 10:51 pm

Re: loop over element nodes with conditions

Post by escolano »

If do you want that the condition named 'Face-Load' is applied on mesh to nodes instead as elements, you must declare it properly in its CONDMESHTYPE field of the .cnd
e.g.

Code: Select all

CONDITION: Face-Load
CONDTYPE: over lines
CONDMESHTYPE: over nodes
QUESTION: FX
VALUE: 0.0
QUESTION: FY
VALUE: 0.0
END CONDITION
and then you can do a loop on the nodes with this condition (to use its FX, FY fields)

Code: Select all

*Set Cond Face-Load  *nodes
*loop nodes *OnlyInCond
  FX=*Operation(cond(FX)*NodesCoord(1)) FY=*Operation(cond(FY)*NodesCoord(2))
*end nodes
About the loop counter, you can get it with the .bas command
*Loopvar
in case of nested loops it will return the counter of the inner loop
(or you can use your own .bas variable and *Operation to increment this variable inside the loop)
lbenedetti
Posts: 6
Joined: Thu Dec 04, 2014 1:48 pm

Re: loop over element nodes with conditions

Post by lbenedetti »

Hello Enrique,

thank you for your reply. However the situation is a little bit more complex than that. My condition is a pressure over face:

Code: Select all

NUMBER: 7 CONDITION: Surface-Load
CONDTYPE: over surfaces
CONDMESHTYPE: over face elems
QUESTION: Components:#CB#(GLOBAL,LOCAL)
VALUE: GLOBAL
DEPENDENCIES: (GLOBAL,HIDE,N_pressure,#CURRENT#, \
                      RESTORE,X_pressure,#CURRENT#, \
                      RESTORE,Y_pressure,#CURRENT#, \
                      RESTORE,Z_pressure,#CURRENT#, \
                      HIDE,Radial_pressure,#CURRENT#, \
                      HIDE,Theta_pressure,#CURRENT#)
DEPENDENCIES: (LOCAL,RESTORE,N_pressure,#CURRENT#, \
                      HIDE,X_pressure,#CURRENT#, \
                      HIDE,Y_pressure,#CURRENT#, \
                      HIDE,Z_pressure,#CURRENT#, \
                      HIDE,Radial_pressure,#CURRENT#, \
                      HIDE,Theta_pressure,#CURRENT#)
DEPENDENCIES: (LOCAL,HIDE,N_pressure,#CURRENT#, \
                      HIDE,X_pressure,#CURRENT#, \
                      HIDE,Y_pressure,#CURRENT#, \
                      RESTORE,Z_pressure,#CURRENT#, \
                      RESTORE,Radial_pressure,#CURRENT#, \
                      RESTORE,Theta_pressure,#CURRENT#)
QUESTION: X_pressure
VALUE: 0.0
QUESTION: Y_pressure
VALUE: 0.0
QUESTION: Radial_pressure
VALUE: 0.0
QUESTION: Theta_pressure
VALUE: 0.0
QUESTION: Z_pressure
VALUE: 0.0
QUESTION: N_pressure
VALUE: 0.0
END CONDITION
Then, in the "Global" and "Local" case the face of the element is required from the software point of view. Now I want to add a cylindrical force (to be transformed in FX and FY):

Code: Select all

*#---------------------------------------------------------------SURFACE-LOAD
*Set elems(all)
*if(ndime==2)
*Set Cond Face-Load    *elems  *CanRepeat
*else
*Set Cond SurFace-Load *elems *CanRepeat
*endif
*intformat "%8i"
*if(CondNumEntities>0)
    FACE_LOAD
*#
*if(ndime==2)
*#
*loop elems *OnlyInCond
      ELEM=*elemsnum() NODES=*globalnodes
*if(strcmp(cond(1),"GLOBAL")==0)
*if(QUADRAT==1)
      GLOBAL:     FX=*cond(2) FY=*cond(3) /
                  FX=*cond(2) FY=*cond(3) / 
                  FX=*cond(2) FY=*cond(3)
*else
      GLOBAL:     FX=*cond(2) FY=*cond(3) /
                  FX=*cond(2) FY=*cond(3) 
*endif
*elseif(strcmp(cond(1),"LOCAL")==0)
*if(QUADRAT==1)
      LOCAL:      FX=*cond(2) FY=*cond(4) /
                  FX=*cond(2) FY=*cond(4) / 
                  FX=*cond(2) FY=*cond(4)
*else
      LOCAL:      FX=*cond(2) FY=*cond(4) /
                  FX=*cond(2) FY=*cond(4) 
*endif
*elseif(strcmp(cond(1),"CYLINDRICAL")==0)
$ CYLINDRICAL
*Set var pi=4*atan(1.0)
*Set var myradius=Operation(sqrt(pow(NodesCoord(1),2)+pow(NodesCoord(2),2)))
*if(NodesCoord(1)==0.0)
*Set var theangle=Operation(pi/2.0)
*else
*Set var theangle=Operation(atan(NodesCoord(2)/NodesCoord(1)))
*endif
*if(sin(theangle)>=0.0)
*Set var mySin=Operation(1.0)
*else
*Set var mySin=Operation(-1.0)
*endif
*if(cos(theangle)>=0.0)
*Set var myCos=Operation(1.0)
*else
*Set var myCos=Operation(-1.0)
*endif
*Set var forcerad=Operation(cond(4,real))
*Set var forcetht=Operation(cond(5,real))
*Set var forcex1=Operation(forcerad*cos(theangle))
*Set var forcex2=Operation((-mySin*myradius*tan(forcetht)*sin(theangle)))
*Set var forcey1=Operation(forcerad*sin(theangle))
*Set var forcey2=Operation((+myCos*myradius*tan(forcetht)*cos(theangle)))
*if(QUADRAT==1)
      GLOBAL:     FX=*Operation(forcex1+forcex2) FY=*Operation(forcey1+forcey2) /
                  FX=*Operation(forcex1+forcex2) FY=*Operation(forcey1+forcey2) / 
                  FX=*Operation(forcex1+forcex2) FY=*Operation(forcey1+forcey2)
*else
      GLOBAL:     FX=*Operation(forcex1+forcex2) FY=*Operation(forcey1+forcey2) /
                  FX=*Operation(forcex1+forcex2) FY=*Operation(forcey1+forcey2) 
*endif
*endif
*end
The part of the script after $CILINDRICAL is changing from cylindrical to FX and FY. The final format of a loaded face is (in this case it was a square face):

Code: Select all

FACE_LOAD
      ELEM=      39 NODES=     3356    3359    3360    3357
      GLOBAL:    FX=0.0 FY=1.0 FZ=0.0 /
                 FX=0.0 FY=1.0 FZ=0.0 /
                 FX=0.0 FY=1.0 FZ=0.0 /
                 FX=0.0 FY=1.0 FZ=0.0
What I would like to do is to change the value in FX, FY, FZ to reflect the cylindrical force that is applied. Is it possible?
User avatar
escolano
Posts: 1922
Joined: Sun Sep 05, 1982 10:51 pm

Re: loop over element nodes with conditions

Post by escolano »

some errors that I have found (visually) in your code:

*Set var pi=4*atan(1.0)
*Set var myradius=Operation(sqrt(pow(NodesCoord(1),2)+pow(NodesCoord(2),2)))
*if(NodesCoord(1)==0.0)
*Set var theangle=Operation(pi/2.0)
*else
*Set var theangle=Operation(atan(NodesCoord(2)/NodesCoord(1)))
*endif[/color]

In set var pi must use Operation to do the math operation
and can't use NodesCoord because you are inside a loop elements (of the condition)
Maybe you can use the element center to represent its location: *ElemsCenter(1), *ElemsCenter(2), *ElemsCenter(3)

or maybe you could use the *ElemsNormal (for surface elements) that is a unitary vector pointing radially in this cilindric shape (with the same normal as the geometrical surface)

other advices:

For very complicated calculations or data reordering you can invoke from the .bas a *tcl procedure. This language is much powerful that the limitated .bas (from Tcl you could ask GiD to get more information)

You can also define for conditions special fields of 'local axes'. #LA# , and refer your data to these local axes attached to lines or surfaces (based on its tangent/normal on each location) and automatically calculated and attached to each element. Local axes could be also drawn from the conditions window.
Post Reply