#It is presumed that QuickField is already started, the problem coil.pbm is opened. #=============================================== #calculates force in QuickField #=============================================== function getQfForceX ($x_position) { #0. open model #1. check plunger position, move plunger #2. calculate force # 0. open model $QF = new-object -comobject 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 $theVertex = $mdl.Shapes.Vertices.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.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 (-Not($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 echo "Time [s] Position [m] Speed[m/s]" while (($t_time -lt $max_time) -and ($x_position -gt $x_in)) { $theForce = getQfForceX($x_position) # electromagnetic force #in PowerShell function return collects _all_ calculated values #if they are not assigned to variables #execution $theContour.AddBlock1 in function adds "TRUE" to the output, #so the output is an array and we have to use [-1] - to get the last value $theForceX = $theForce[-1] $theForceX = $theForceX + ($x_spring_free - $x_position) * $k # add spring force $v_speed += $theForceX / $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 echo "$t_time $x_position $v_speed" #output results }