function theForce = getQfForce_X(x_position) %It is presumed that QuickField is already started, the QuickField problem is opened. %x_position is an absolute position of the plunger (vertex "anchor") %1. Move the plunger to proper position (x_position) %2. Calculate the force %3. Move the plunger back to zero position qf = actxserver('QuickField.Application'); %get link to QuickField pbm = qf.Problems.Item(1); %get link to the problem pbm.LoadModel(); %load model mdl = pbm.Model; %get link to the model %1. Move the plunger to proper position (x_position) %get current position of plunger (vertex "anchor") theShape = mdl.Shapes.LabeledAs('anchor','',''); %returns a collection of objects theVertex = theShape.Vertices.Item(1); %take first object in collection (normally there is only one vertex there) %displacement vector oldX = theVertex.Point.X; theVector = qf.PointXY(x_position - oldX, 0); %displacement vector between desired position and current position %select the object to move, i.e. "insulation" %(the plunger core is attached to plunger insulation and would be moved automatically) theShape = mdl.Shapes.LabeledAs('','','insulation'); %move the selected Shape theShape.Move(0, theVector); %QuickField constant qfShift = 0 mdl.Shapes.BuildMesh(); %build mesh in the model mdl.Save(); %save model file pbmState = pbm.SolveProblem(1); %1=NoWait, solve the problem asynchronously pause (2); %pause for 2 seconds to let the pbmState to be updated start_time = time(); do %wait till the problem is solved, but no more then 60 seconds v = pbmState.IsActive; p = time()-start_time; until ((!v) | (p>60)) %problem not solved - cannot continue if (!pbm.Solved) disp("cannot solve"); break; endif %check the state pbm.AnalyzeResults(); %load results res = pbm.Result; %get link to the result %to calculate the force we should build integration contour %we build the contour in the field window theFieldWindow = res.GetFieldWindow(1); %open the field window theContour = theFieldWindow.Contour; %get link to the contour theContour.AddBlock1('plunger_core'); %add "plunger" block to contour %calculate the magnetic force integral theMagneticForce = res.GetIntegral(15, theContour).Value; % QuickField constant 'qfInt_MaxwellForce' = 15 theForce = theMagneticForce.X; %plunger is moved by the X-component of the force endfunction