# # start Tcl/Tk stuff # source [file join [pwd] plotchart plotchart.tcl] wm withdraw . toplevel .main wm title .main "Quickfield : Relay dynamics simulation" wm protocol .main WM_DELETE_WINDOW {destroy .} canvas .main.c -background white -width 500 -height 400 pack .main.c -fill both -side top set s [::Plotchart::createXYPlot .main.c {0.0 6.0e-2 1.0e-2} {5.5e-3 10.0e-3 0.5e-3}] $s dotconfig data -colour "red" $s yconfig -format %2.2e $s xconfig -format %4.3f # # end Tcl/Tk stuff # exec QLMCall.exe ClearResults #It is presumed that QuickField is already started, the problem coil.pbm is opened. #The plunger is placed in x=0 position #relay parameters set x_out 0.010; #pull out position. m set x_in 0.006; #pull in position, m set m_mass 0.0045; #plunger weight, kg set k 4; #spring constant, N/m set x_spring_free 0.015; #spring free would be position, m #initial conditions set t_time 0; #time, s set x_position $x_out; #plunger position, m set v_speed 0; #plunger speed, m/s #integration time step, s set dt_time_step 0.005 #maximal integration time, s set max_time 0.2 $s dot data 0 $x_out 5 while { $t_time < $max_time && $x_position > $x_in } { #electromagnetic force # theForce = getQfForceX(x_position) set results [exec QLMCall [expr 1.0 * $x_position]] set theForce [lindex $results 1] #add spring force set theForce [expr $theForce + ($x_spring_free - $x_position) * $k] #calculate acceleration and speed set v_speed [expr $v_speed + ($theForce / $m_mass) * $dt_time_step] #calculate plunger position set x_position [expr $x_position + $v_speed * $dt_time_step] set t_time [expr $t_time + $dt_time_step] #plot x-position $s dot data $t_time $x_position 5 } #add axis labels and title to the plot # xlabel('Time t, sec.'); # ylabel('Position x, m'); # title('Plunger position vs. time'); $s title "Plunger position vs. time" $s xtext "Time t, sec." $s ytext "Position x, m"