#Fixed elastic frame structure (static analysis for distributed load)
#unit system: force(N) - length(m) - mass(kg)
wipe
source utils_0.tcl

#..................................................................
#INITIAL CALCULATIONS

#square section
set b 	[expr 300.0*$mm]
set E 	[expr 2.e+04*$MPa]
set A 	[expr $b**2.]
set Iy 	[expr $b**4./12.]
set Iz 	[expr $b**4./12.]
set J 	[expr 0.141*($b**4.)]
set n 	0.25
set G 	[expr $E/(2.0*(1.0 + $n))]

#frame
set h 	3.0
set l 	4.0

#...............................................................
#MODEL BUILDER

#3D model, 6dof
#model BasicBuilder -ndm $ndm <-ndf $ndf> 
#(ndf and ndm are 1 based in OpenSees)
model BasicBuilder -ndm 3 -ndf 6

#create the nodes of the portal on the XZ plane
#node $nodeTag (ndm $coords) <-mass (ndf $massValues)>
node 1 0 0 0
node 2 0 0 $h 
node 3 $l 0 $h 
node 4 $l 0 0

#move from the basic CS to the global CS
#geomTransf Linear $transfTag $vecxzX $vecxzY $vecxzZ <-jntOffset $dXi $dYi $dZi $dXj $dYj $dZj>
#vecx coordinates is in practice the orientation of your local z axis in respect to the global system
#beams
geomTransf Linear 1 0.0 0.0 1.0
#columns
geomTransf Linear 2 1.0 0.0 0.0

#create elements for each column and the beam
#element elasticBeamColumn $eleTag $iNode $jNode $A $E $G $J $Iy $Iz $transfTag
element elasticBeamColumn 1 1 2 $A $E $G $J $Iy $Iz 2
element elasticBeamColumn 2 2 3 $A $E $G $J $Iy $Iz 1
element elasticBeamColumn 3 4 3 $A $E $G $J $Iy $Iz 2

#create a timeseries
# timeSeries Linear
timeSeries Linear 1

#assign bounday conditions
#fix $nodeTag (ndf $constrValues)   
fix 1 1 1 1 1 1 1 
fix 4 1 1 1 1 1 1

#assign loading conditions
#load
set p -1000.0
#pattern Plain $patternTag $tsTag <-fact $cFactor> {eleLoad -ele $eleTag1 <$eleTag2 ....> -type -beamUniform $Wy <$Wx>}
pattern Plain 1 1 {eleLoad -ele 2 -type -beamUniform 0.0 $p 0.0}


#...............................................................
#ANALYSIS

#make a directory to save your output
file mkdir "output"

#add the mpco recorder to compare the results with the STKO example (ex3.scd)
recorder mpco "output/ex2bis.mpco" \
-N "displacement" "reactionForce" \
-E "localForce"

#save your results in a specific folder
#recorder Node <-file $fileName> <-time> <-node $node1 $node2 ...> -dof ($dof1 $dof2 ...) $respType'
recorder  Node  -file "./output/out1_base_reactions.out" -time -node 1 4  -dof 1 2 3 4 5 6 reaction
#recorder Element <-file $fileName> <-time> <-eleRange $startEle $endEle> $arg1 $arg2 ...
recorder  Element  -file "./output/out2_forces.out"  -time -ele 2 localForce

#system systemType?
system FullGeneral

#constraints constraintType?
constraints Plain

#numberer numbererType?
numberer RCM

#test testType? (NormUnbalance $tol $iter)
test NormUnbalance 0.0001 10

#algorithm algorithmType? (Linear)
algorithm Linear

#integrator LoadControl $lambda
integrator LoadControl 1

#analysis analysisType?
analysis Static

#raise an error if the analysis does not work
#analyze $numIncr 
set ok [analyze    1]
if {$ok != 0} {
	error "Analysis failed!"
}

#print analysis done
puts "Static analysis done!"


#if you don't put this OpenSees will not save your data on the out put files until you exit it
wipe