program loop in opensees

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

Moderators: silvia, selimgunay, Moderators

Post Reply
yyleno
Posts: 33
Joined: Wed Sep 15, 2010 4:50 am
Location: Shanghai University

program loop in opensees

Post by yyleno »

Hi,

There is a big question in my code, i need calculate my code 100 times because it has a variable which has 100 value.
For example,
set Es 10000;
Es is a variable and Es ={10000 12000 14000 .........40000,50000} it is 100 value.
I want :?: write a loop :?: in opensees to calculate my code (source opensees.tcl) 100 times,and each times have each record (results).
What can i do ?

thanks !
vesna
Posts: 3033
Joined: Tue May 23, 2006 11:23 am
Location: UC Berkeley

Re: program loop in opensees

Post by vesna »

You can do it this way:

set j 0
foreach Es { 10000 12000 14000 .........40000 50000 } {

puts "Es: $Es"

model basic -ndm 2 -ndf 3
wipe
.....
incr j 1
set dataDir [format "Es%i" $j ]
file mkdir $dataDir; # create data directory
.....
recorder Node -file [format "$dataDir/DispEs%i.out" $j ] -time -node 3 -dof 1 disp; #records displacement

......

}
yyleno
Posts: 33
Joined: Wed Sep 15, 2010 4:50 am
Location: Shanghai University

Re: program loop in opensees

Post by yyleno »

Hi,vesna,
Thank you very much!
And in this question,if I have a file :!: *.txt or*.out :!: ,which consider Es value: 10000 12000 14000 .........40000 50000 ,how can i do call *.txt or *.out
in opensees? That is ,if i can call this file ,i can not input the numerical value of Es in opensees .
PLS tell me how can use it ?

Appreciation!
yyleno
Posts: 33
Joined: Wed Sep 15, 2010 4:50 am
Location: Shanghai University

Re: program loop in opensees

Post by yyleno »

PS:
:?: [format "Es%i" $j ] :?:
Can i use other chars instead of % which its have the same function ?
yyleno
Posts: 33
Joined: Wed Sep 15, 2010 4:50 am
Location: Shanghai University

Re: program loop in opensees

Post by yyleno »

Hi,vesna,
other question!

set T1 [expr 2.0*$pi/$w1]; # 1st mod
set T2 [expr 2.0*$pi/$w2]; # 2nd mod
set T3 [expr 2.0*$pi/$w3]; # 3nd mod
puts "T1 = $T1 s"; # display the
puts "T2 = $T2 s"; # display the
puts "T3 = $T3 s"

# write the output file cosisting of periods
:?: :?: HOW TO Write THIS PERIODS ? :?:
set period [format "Periods%i.txt" $k]
#set period "TRussData_beam_push_3D/Periods.txt"
set Periods [open $period "w"]
foreach t1 {$T1} t2 {$T2} t3 {$T3} {
puts $Periods " $t1 $t2 $t3 "
}
close $Periods
fmk
Site Admin
Posts: 5884
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Re: program loop in opensees

Post by fmk »

this is a basic tcl question on the use of foreach .. google tcl foreach .. e.g. http://www.astro.princeton.edu/~rhl/Tcl ... ach.n.html
jndlsmt
Posts: 18
Joined: Thu Nov 25, 2010 2:37 am
Location: IIT Kanpur

Re: program loop in opensees

Post by jndlsmt »

hi friends,
i have a same type problem in my code,i have a six random variables which have 100 values in matrix form
for example;
var-1 var-2 var-3 var-4 vAR-5 var-6
={40.2285 0.3088 16.1031 12.9999 5.1254 1.6663
40.8183 0.4883 15.6421 5.6726 2.6696 2.1183
37.7136 0.3961 11.8791 6.7538 4.0445 0.5526
40.3427 0.3681 18.1188 7.8508 4.8990 1.4542
39.3762 0.4104 17.0790 2.3890 0.7384 2.1817
..............................................} six variables have 100 values...
i want to write a loop in opensees for calculating this in my code, and each times have each record (results)
please help

thanks in advance
Sumit Jindal
IIT Kanpur (India)
vesna
Posts: 3033
Joined: Tue May 23, 2006 11:23 am
Location: UC Berkeley

Re: program loop in opensees

Post by vesna »

Here is an example about saving the periods into a file:
http://opensees.berkeley.edu/wiki/index ... e_analysis
yyleno
Posts: 33
Joined: Wed Sep 15, 2010 4:50 am
Location: Shanghai University

Re: program loop in opensees

Post by yyleno »

Hi,vesna,
Thank you very much!
vesna
Posts: 3033
Joined: Tue May 23, 2006 11:23 am
Location: UC Berkeley

Re: program loop in opensees

Post by vesna »

To read Es from file, at the beginning of your file write this:

set fileR [open Es.txt "r"]
set EsR [gets $fileR]
close $fileR

set j 0
foreach Es $EsR {

puts "Es: $Es"

model basic -ndm 2 -ndf 3
wipe
.....
incr j 1
set dataDir [format "Es%i" $j ]
file mkdir $dataDir; # create data directory
.....
recorder Node -file [format "$dataDir/DispEs%i.out" $j ] -time -node 3 -dof 1 disp; #records displacement

......

}
jndlsmt
Posts: 18
Joined: Thu Nov 25, 2010 2:37 am
Location: IIT Kanpur

Re: program loop in opensees

Post by jndlsmt »

hi vesna ,
please give me the solution of my problem with no of random variables..
i have a same type problem in my code,i have a six random variables which have 100 values in matrix form
for example;
var-1 var-2 var-3 var-4 vAR-5 var-6
={40.2285 0.3088 16.1031 12.9999 5.1254 1.6663
40.8183 0.4883 15.6421 5.6726 2.6696 2.1183
37.7136 0.3961 11.8791 6.7538 4.0445 0.5526
40.3427 0.3681 18.1188 7.8508 4.8990 1.4542
39.3762 0.4104 17.0790 2.3890 0.7384 2.1817
..............................................} six variables have 100 values...
i want to write a loop in opensees for calculating this in my code, and each times have each record (results)
please help
Sumit Jindal
IIT Kanpur (India)
Post Reply