#It is presumed that QuickField is already started, the problem coil.pbm is opened. use Win32::OLE; #=============================================== #calculates force in QuickField #=============================================== sub getQfForceX { $x_position = $_[0]; #input parameter #0. open model #1. check plunger position, move plunger #2. calculate force # 0. open model $QF = Win32::OLE->new("QuickField.Application"); #hook QuickField $pbm = $QF->Problems->Item(1); #get the first opened Problem $pbm->LoadModel(); #load Model $mdl = $pbm->Model; #hook the Model #1. check plunger x-position, the cooridate of vertex "R" on plunger #The Invoke() method allows to modify properties with arguments, which is not supported by the hash syntax $theVertex = $mdl->Shapes->Vertices->Invoke("LabeledAs","R","","")->Item(1); $theXposition = $theVertex->Point->X; #calculate x-coordinate of vertex "position" $theVector = $QF->PointXY($x_position - $theXposition, 0); #calculate displacement vector #plunger consists of 2 blocks: "insulation" (external), "plunger_core" (internal) #if we move the external block then the internal block will be moved too $theBlock = $mdl->Shapes->Blocks->Invoke("LabeledAs","","","insulation")->Item(1);#select "plunger" block $theBlock->Move(0, $theVector); #move plunger. 0=qfShift, displacement #2. Solve problem $mdl->Shapes->BuildMesh(True, False); #build mesh $mdl->Save(); #save model if (!($pbm->Solved())) #check if problem is solved { $pbm->SolveProblem(); #solve problem }; $pbm->AnalyzeResults(); #open results $res = $pbm->Result; #link to Result object $theFieldWindow = $res->GetFieldWindow(1); #hook Field window $theContour = $theFieldWindow->Contour; #build integration contour #plunger consists of 2 blocks: "insulation" (external), "plunger_core" (internal) $theContour->AddBlock1("insulation"); #add to contour block "insulation" $theContour->AddBlock1("plunger_core"); #add to contour block "plunger_core" #calculate magnetic force integral $theForce = $res->GetIntegral(15, $theContour)->Value; #15=qfInt_MaxwellForce return $theForce->X; #get x-component of force } #=============================================== # main programm starts here #=============================================== #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; #time increment print "$t_time $x_position $v_speed\n"; #output results }