number format effect

Forum for OpenSees users to post questions, comments, etc. on the use of the OpenSees interpreter, OpenSees.exe

Moderators: silvia, selimgunay, Moderators

Post Reply
songwang
Posts: 16
Joined: Mon Feb 18, 2013 11:25 am
Location: Missouri University of Science and Technology

number format effect

Post by songwang »

Dear all:

I just encountered a problem about number format when I play with a one-bay one story frame. The script is as below:

###############################################################################
wipe

model BasicBuilder -ndm 2 -ndf 3

puts "model geometry"
node 1 0 0
node 2 1 0
node 3 0 1
node 4 1 1

puts "boundary condition"
fix 1 1 1 1
fix 2 1 1 1

puts "Geometry Transformation"
geomTransf Linear 1

set A 1
set E 1
set I [expr 1/12]

puts "element"
element elasticBeamColumn 1 1 3 $A $E $I 1
element elasticBeamColumn 2 3 4 $A $E $I 1
element elasticBeamColumn 3 4 2 $A $E $I 1

#######################################################################

If I apply a lateral load at node 3, the model doesn't work. However, if I change "set I [expr 1/12]" to "set I 0.083" or "set I [expr 13/12]" where value of []>=1, the model works. Also, if I assign variable I to only element 1 and let $I in element 2 and 3 to be a exact number like below:

###########################################################
set A 1
set E 1
set I [expr 1/12]

puts "element"
element elasticBeamColumn 1 1 3 $A $E $I 1
element elasticBeamColumn 2 3 4 $A $E 0.083 1
element elasticBeamColumn 3 4 2 $A $E 0.083 1
########################################################

The model works. Does anyone know why this happens?

Song
fmk
Site Admin
Posts: 5884
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: number format effect

Post by fmk »

your problem is a consequence of integer math
set I [expr 1/12]

1 and 12 are integers, the result is 0

whenever you divide by a value you know not to be an integer always include a dot so the interpreter knws it is not an integer,
i.e. set I [expr 1/12.]
Post Reply