ActiveField™ Help    

Main QuickField Site  

Free Downloads  

Contacts  

ActiveField Technology
What's New
Objects Overview
Hierarchy Chart
How to Start: Application Object
How to work with Problems
How to work with Model
How to work with Data
How to Analyze Results

Objects

Properties

Methods

Parametric Simulation Samples

C-Shaped Magnet: Lesson 3

C-Shaped Magnet

Lesson 3: Using Parametric Workbench

[This is preliminary document and subject to change]

Here we will continue with C-Shaped magnet described in the Lesson 1 and Lesson 2. Now we rewrite our sample application with QuickField Parametric Workbech. The model will be fully parametric. Moreover, the customer might iterate each of geometric or physical parameter with a constant or random increment. You can download Lesson's 3 files here.

The two main parts of the QuickField Parametric Workbench are:

  • Workbench application  - a stand-alone program that provides a graphical user interface for displaying, editing and storing the model input parameters and viewing calculation results. The Workbench interact with the Exploring Object - a dynamic link library (DLL) executable file, which is written by a customer in Visual Basic or any other programming language supports creation of DLL. You can write and register any number of different Exploring Objects and drive them all with a single Workbench.
  • The second important Workbench component is the Exploring Object Wizard. It is integrated into Visual Basic 6.0 environment and assists the customer in creating a new exploring object DLL.

The discussion is divided into the following steps:

Step 1: Creating a Visual Basic project.

When started the Visual Basic usually asks what kind of new project you want to create. To use the Exploring Object Wizard please choose it from the list of project kinds:

Than the Exploring Object Wizard guides you through the steps needed to create a skeleton of the model. Next to the welcome screen the wizard asks the name and location of the project created. It is a good idea to choose a self-descriptive name because it will be used by Workbench to identify the  exploring object.

The next screen is dedicated to QuickField problem setting. You should choose a type of problem, class of symmetry (plane-parallel or axisymmetric), coordinate system and lengths units.

Another wizard's screen asks about some files needed for the modeling.

Defining the geometric model we can build it in our code from scratch or rely on an existing model, created by QuickField model editor. If later is the case, the file name should be printed in the "Basic model file" box. The file mentioned will be copied the the subfolder under project folder, and the wizard will generate code for copying the basic model in place of the working model file.

The same is true also for basic data file. If you do not need it - simply leave the box empty.

In our example we will use the basic data file Magn1.dms - the same we used in the Lesson 1 and do not use basic model file. Another input box is dedicated for the sketch file name. Most major picture formats (*.bmp, *.tif, *.gif, *.wmf) are assepted.

The next wizard screen is dedicated for defining input parameters.

We enter seven geometric parameters to the table and one - the magnet coercive force - physical one to the table. For each parameter we define the descriptive name, name of corresponding variable, unit, range and default value.

The next screen allows to choose the set of output parameters.

List of available quantities includes all the local and integral values. In addition you can define your own custom output parameter, give it a name and later write the code to calculate it. We chose here one local value (Flux density) and one integral parameter (the Maxwell force).

Finally we click the Finish button and the wizard generates Visual Basic project for us.

Step 2: Customizing the code generated by the Wizard:

Now let us review the code, generated by the wizard, in the file Magn1.cls. It implements two COM interfaces - ExploringObject and Asynchronous and contains several internal procedures that are used for implementing the interfaces. Fortunately, we have to modify only a few of them. The places where the customer most likely want to write some lines of code are marked by the special comment:

''' ----------------------------------------
''' TODO: Modify QuickField model (Mdl) here

''' ----------------------------------------

The subroutines  that you most likely want to modify are:

Sub ModifyModel ()

There we write the code that builds (modifies) the geometric model.
The ModifyModel procedure is called each time Workbench needs to rebuild the model.

Private Sub SetLabel
(ParamName As String)

The place for setting value to the data labels.
This procedure is called when a parameter marked as physical takes a new value.

Private Sub Calculations
(Pt As QFWB.ResultPoint)

This routine is responsible for calculation of all output parameters. It is called on each parametric step.

Private Function BuildContour() As QuickField.Contour

The BuildContour function build an integration contour for calculation of the integral output parameters (if any).

Modifying the geometric model.

We deal with the geometric model in the ModifyModel procedure. The only thing the wizard do for us is defining the geometrical parameters and setting their values. In our case this section looks like the following:

''' Local variables for all input parameters
Dim airGap As Double
airGap = theParameters("Air Gap").Value
Dim keeperHeight As Double
keeperHeight = theParameters("Keeper Height").Value
Dim KeeperWidth As Double
KeeperWidth = theParameters("Keeper Width").Value
Dim magnetHeight As Double
magnetHeight = theParameters("Magnet Height").Value
Dim magnetWidth As Double
magnetWidth = theParameters("Magnet Width").Value
Dim yokeHeight As Double
yokeHeight = theParameters("Yoke Height").Value
Dim yokeWidth As Double
yokeWidth = theParameters("Yoke Width").Value

''' ----------------------------------------
''' TODO: Modify QuickField model (Mdl) here

After the TODO comment we simply put the code from the Lesson 2 without any modifications. That code uses an auxiliary function fMin, so we also put it to the end of wizard generated file.

The Parametric Workbench will call this ModifyModel procedure each time when one of input parameters marked as Geometric is changed.

Altering label data.

The procedure intended for manipulating with model physical data is called SetLabel. It is called by the Parametric Workbench when one of the non-geometric (physical) variable is changed. The SetLabel procedure also receives the name of changing variable as an ParamName input parameter.

The wizard organizes the Select Case statement for choosing between physical variables:

Select Case ParamName
Case "Coercive Force"
''' ----------------------------------------
Dim Hc As Double
Hc = theParameters("Coercive Force").Value

It also declares the variable called Hc that contains the actual value of the physical parameter. Below that the wizard put some commented out lines of code that show how to do modification of a data label. We almost follow these recommendations with only one difference: We should synchronously update two labels - ALNICO up and ALNICO Down with the same absolute value of the magnet coercive force.

So the code for updating the labels looks like this:

''' TODO: Edit here the LabCnt properties
Set Lbs = Prb.DataDoc.Labels(qfBlock) 'Select block labels collection
Set Lab = Lbs("ALNICO up") 'Get label
Set LabCnt = Lab.Content 'Get label content
LabCnt.Coercive = QF.PointRA(Hc, 3.1415926 / 2)
Lab.Content = LabCnt 'Update label content

Set Lbs = Prb.DataDoc.Labels(qfBlock) 'Select block labels collection
Set Lab = Lbs("ALNICO down") 'Get label
Set LabCnt = Lab.Content 'Get label content
LabCnt.Coercive = QF.PointRA(Hc, -3.1415926 / 2)
Lab.Content = LabCnt 'Update label content
''' ----------------------------------------

Evaluating the Output Parameters.

When creating the Visual Basic project with the wizard, we have defined two output parameters: Maxwell force acting on the steel keeper and the flux density value in the middle of the yoke. Because the former parameter is calculated as an integral value, we have to build an integration contour surrounding the keeper. The contour code should be written in the BuildContour procedure.

Our contour surrounds the steel keeper, so its size and position is dependant upon the values of geometric parameters. The first thing we do here is obtaining its values. To do it we simply copy here the wizard generated code concerning geometric parameters from the ModifyModel  procedure:

''' Local variables for all input parameters
Dim airGap As Double
airGap = theParameters("Air Gap").Value
Dim keeperHeight As Double
keeperHeight = theParameters("Keeper Height").Value
Dim KeeperWidth As Double
KeeperWidth = theParameters("Keeper Width").Value
Dim magnetHeight As Double
magnetHeight = theParameters("Magnet Height").Value
Dim magnetWidth As Double
magnetWidth = theParameters("Magnet Width").Value
Dim yokeHeight As Double
yokeHeight = theParameters("Yoke Height").Value
Dim yokeWidth As Double
yokeWidth = theParameters("Yoke Width").Value

Now we are ready to build the contour using the AddLineTo method. The wizard put here a commented out example of a round contour consisting of two semicircular arcs just for information. We replace it with the following code:

''' ----------------------------------------
''' TODO: Build Contour here

With Cnt
    .AddLineTo QF.PointXY(-KeeperWidth / 2 - magnetWidth, _
        yokeHeight + magnetHeight + airGap / 2)
    .AddLineTo QF.PointXY(KeeperWidth / 2 + magnetWidth, _
        yokeHeight + magnetHeight + airGap / 2)
    .AddLineTo QF.PointXY(KeeperWidth / 2 + magnetWidth, _
        yokeHeight + magnetHeight + airGap + keeperHeight * 1.5)
    .AddLineTo QF.PointXY(-KeeperWidth / 2 - magnetWidth, _
        yokeHeight + magnetHeight + airGap + keeperHeight * 1.5)
    .AddLineTo QF.PointXY(-KeeperWidth / 2 - magnetWidth, _
        yokeHeight + magnetHeight + airGap / 2)
End With
''' ----------------------------------------

Here we build a  closed rectangular contour oriented counter clockwise. The last AddLineTo closes the contour by connecting the ending point with the starting one. It could be done with AddLineTo method without parameters, but that approach does not works reliable on Windows 95/98 system.

While the BuildContour procedure is ready, it is very simple to do the rest calculations. The should be located in the Calculations porcedure. Almost all things needed are already written here by wizard:

''' ----------------------------------------
''' Start getting output parameter values
'Flux density
Pt.Value(1) = Locals.Grad.R
'Mechanical torque
Pt.Value(2) = Res.GetIntegral(qfInt_MaxwellTorque, Cnt).Abs
''' End getting output parameter values
''' ----------------------------------------

The only line we should change is the following:

Set Locals = Res.GetLocalValues(PointXY(0, yokeHeight / 2))

To obtain the actual value of the yokeHeight parameter we write here the code that you are already familiar with:

Dim yokeHeight As Double
yokeHeight = theParameters("Yoke Height").Value

Now we are ready to compile and use our exploring object. To compile the code choose the Make Magn1.dll command from the File menu. In the rest of this topic we discuss how to do calculation with our Magn1 exploring object.

Step 3: Using the Workbench Tool.

When started, the Parametric Workbench shows the General tab:

The first two things we should do are marked by red ellipse. First we should register our Magn1 exploring object to let the Workbench tool drive it. To do it please click the Register New ExploringObject button and locate the Magn1.dll.

The next step is creating a new modeling session. After clicking the New Session button you will be asked which of the registered Exploring Object you want to use. Please choose the Magn1 icon. After a few second's delay needed to start the QuickField server, the Workbench brings the All Parameters screen:

In the Value field for each quantity you see the default values that you have defined with Workbench wizard. You can enter any value for each parameter. In addition, you can declare one or two of parameters as varying ones. To do simply click the desired row in the Variable column.

When you have declared one or two parameters as variable, you can switch to the Variable Parameters tab, that lets to define the increment, lower and upper bound for each variable.

Then go to the Result tab and click the Solve to start calculations. While QuickField solves the problem, the workbench keeps you informed with the status line on the bottom of the Workbench window. You can also show and hide the QuickField window at any time you want. If the QuickField window is shown, the Workbench pauses iterating each time the solution is ready.

When the solving is finished, you can observe results in the table, show plot by clicking the Graphics button, or export the results to the Microsoft Excel workbook. To do the later, click Export button.