#It is presumed that QuickField is already started, the problem coil.pbm is opened. #The plunger is placed in x=0 position #LabelMover file relay.qva is opened use Win32::OLE; sub getQfForceX { #calculate force in QuickField $x_position = $_[0]; # 0. hook LabelMover (QuickField tool) $qlm = Win32::OLE->new('qlm.SimpleInterface'); # 1. set plunger position $qlm->SetVariation(0, $x_position); # 2. get the force $qlm->Solve(); return $qlm->GetResult(0); # each step is stored in LabelMover } #relay physical parameters $x_out = 0.01; # pull out position. m $x_in = 0.006; # pull in position, m $m_mass = 0.0045; # plunger weight, kg $k = 4.0; # spring constant, N/m $x_spring_free = 0.015; # spring free would be position, m #initial conditions $t_time = 0.0; # time, s $x_position = $x_out; # plunger position, m $v_speed = 0.0; # plunger speed, m/s $dt_time_step = 0.005; #integration time step, s $max_time = 0.2; # maximal integration time print "Time [s] Position [m] Speed[m/s]\n"; while (($t_time < $max_time) and ($x_position > $x_in)) { $theForce = getQfForceX($x_position); # electromagnetic force $theForce += ($x_spring_free - $x_position) * $k; # add spring force $v_speed += $theForce / $m_mass * $dt_time_step; # calculate acceleration and speed $x_position += $v_speed * $dt_time_step; # calculate plunger position $t_time += $dt_time_step; #output results also stored in LabelMover print "$t_time $x_position $v_speed\n"; }