
# a list of all monitor and custom function actors to be called by the MonitorFunction
set all_custom_functions {}
set all_monitor_actors {}

# the main custom function caller that will call all actors in $all_monitor_actors and in $all_custom_functions list
proc CustomFunctionCaller {step_id dt T n_iter norm perc process_id is_parallel} {
	global all_monitor_actors
	global all_custom_functions
	# Call monitors: we pass the parameters needed
	foreach p $all_monitor_actors {
		$p $step_id $dt $T $n_iter $norm $perc $process_id $is_parallel
	}
	# Call all other custom functions
	foreach p $all_custom_functions {
		$p
	}
}

recorder mpco "steel_connection.mpco" \
-N "displacement"

# Constraints.sp fix
	fix 1 1 1 1 0 0 0
	fix 3 1 1 1 0 0 0
	fix 5 1 1 1 0 0 0
	fix 7 1 1 1 0 0 0
	fix 9 1 1 1 0 0 0
	fix 11 1 1 1 0 0 0
	fix 144 1 1 1 0 0 0
	fix 145 1 1 1 0 0 0
	fix 169 1 1 1 0 0 0
	fix 170 1 1 1 0 0 0
	fix 55 1 1 1 0 0 0
	fix 56 1 1 1 0 0 0
	fix 80 1 1 1 0 0 0
	fix 81 1 1 1 0 0 0
	fix 82 1 1 1 0 0 0
	fix 83 1 1 1 0 0 0
	fix 84 1 1 1 0 0 0
	fix 85 1 1 1 0 0 0
	fix 86 1 1 1 0 0 0
	fix 87 1 1 1 0 0 0
	fix 88 1 1 1 0 0 0
	fix 119 1 1 1 0 0 0
	fix 120 1 1 1 0 0 0

# element ASDEmbeddedNodeElement $Tag  $Cnode   $Rnode1 $Rnode2 $Rnode3 <$Rnode4>   <-K $K> <-rot>
element ASDEmbeddedNodeElement 943  530   19 20 180   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 944  532   200 201 41   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 945  534   26 418 27   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 946  536   431 105 432   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 947  538   207 208 48   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 948  540   438 112 439   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 949  564   179 180 201   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 950  577   25 26 186   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 951  578   24 25 185   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 952  579   23 24 184   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 953  580   22 23 183   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 954  581   21 413 22   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 955  582   20 21 181   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 956  600   410 432 411   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 957  613   186 187 208   -K 2100000000.0 -rot
element ASDEmbeddedNodeElement 958  626   417 439 418   -K 2100000000.0 -rot

# Patterns.addPattern loadPattern
pattern Plain 3 1 {

# Loads.Force EdgeForce
	load 535 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 583 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 583 0.0 0.0 -1999.9999999999973 0.0 0.0 0.0
	load 584 0.0 0.0 -1999.9999999999973 0.0 0.0 0.0
	load 584 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 585 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 585 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 586 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 586 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 587 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 587 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 588 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 588 0.0 0.0 -2000.0 0.0 0.0 0.0
	load 531 0.0 0.0 -2000.0 0.0 0.0 0.0
}

# analyses command
domainChange
constraints Plain
numberer RCM
system UmfPack
test NormDispIncr 1e-06 10  
algorithm Newton
integrator LoadControl 0.0
analysis Static
# ======================================================================================
# NON-ADAPTIVE LOAD CONTROL ANALYSIS
# ======================================================================================

# ======================================================================================
# USER INPUT DATA 
# ======================================================================================

# duration and initial time step
set total_time 1.0
set initial_num_incr 10

set time 0.0
set time_increment [expr $total_time / $initial_num_incr]
integrator LoadControl $time_increment 
for {set increment_counter 1} {$increment_counter <= $initial_num_incr} {incr increment_counter} {
	if {$process_id == 0} {
		puts "Increment: $increment_counter. time_increment = $time_increment. Current time = $time"
	}
	
	set ok [analyze 1 ]
	#barrier
	
	if {$ok == 0} {
		set num_iter [testIter]
		set time [expr $time + $time_increment]
		# print statistics
		set norms [testNorms]
		if {$num_iter > 0} {set last_norm [lindex $norms [expr $num_iter-1]]} else {set last_norm 0.0}
		if {$process_id == 0} {
			puts "Increment: $increment_counter - Iterations: $num_iter - Norm: $last_norm ( [expr $time/$total_time*100.0] % )"
		}
		
		# Call Custom Functions
		set perc [expr $time/$total_time]
		CustomFunctionCaller $increment_counter $time_increment $time $num_iter $last_norm $perc $process_id $is_parallel

	} else {
		error "ERROR: the analysis did not converge"
	}
}

if {$process_id == 0} {
	puts "Target time has been reached. Current time = $time"
	puts "SUCCESS."
}
wipeAnalysis

# Done!
puts "ANALYSIS SUCCESSFULLY FINISHED"
