The Problem object provides you access to almost all
QuickField objects. When you are going to create a new model or modify an existing geometry
model, or you have to set some media properties, boundary conditions and field sources, solve a
problem and analyze the solution, the first thing that you have to obtain is the Problem
object.
Let's assume that you already have the Application
object. If not, please return to the How to Start topic. The
Application object maintains a separate documents collection for each document type. You
can get the collection of Problem objects by its Problems
property. As any Documents collection it contains all
Problem objects that are currently opened and provides a way to create a new problem or open an
existing one.
The following example opens an existing problem "Magn1.pbm" and then creates a new
problem, and saves it as "MyProblem.pbm":
Dim QF As QuickField.Application
Set QF = CreateObject("QuickField.Application")
QF.Problems.Close
QF.DefaultFilePath = "D:\QuickField\Examples"
Dim prb As QuickField.Problem
Set prb = QF.Problems.Open("Magn1.pbm")
Dim prbNew As QuickField.Problem
Set prbNew = QF.Problems.Add
prbNew.SaveAs "MyProblem.pbm"
The first line of code creates the Application object. Then, QuickField starts if it is
not currently running. Than we close all opened problems if any. This is useful because
QuickField automatically opens the last saved problem when started. Next we set the default
file folder to the D:\QuickField\Examples directory. Now we can refer to the files it
contains without full path qualification.
The Open method of Problems collection opens an existing problem
Magn1.pbm and adds it to the collection. To create a new problem we use an Add method that creates an empty Problem. Then we save it to the
file with the name "MyProblem.pbm" using the SaveAs
method of the Problem object.
Now if we try to open a newly created problem "MyProblem.pbm" we can see that it is an
electrostatic problem referring to the model file Problem.mod and the data file Problem.des. To
change these default settings we have to extend our example, say in the following way:
......
Set prbNew = QF.Problems.Add
With prbNew
' Here we set the problem
properties
' as we do it using the
screen dialog
.ProblemType = qfHeatTransfer
.ReferencedFile(qfModelFile) = "MyModel.mod"
.ReferencedFile(qfDataFile) = "MyData.dht"
.Class = qfPlaneParallel
.Coordinates = qfCartesian
.LengthUnits = qfMillimeters
End With
prbNew.SaveAs "MyProblem.pbm"
A special object Link is used to establish coupling link. Each Link
object represents one coupling link. The Link object provides such properties as LinkType and TargetName,
which completely describe the link to a coupled problem. All the Link objects are member
of the Links collection. The Links collection allows you
to define a new coupling link by the Add method and remove an
existing link by the Remove method.
The following code demonstrates some basic operation with Link
object and Links collection:
Dim prb As QuickField.Problem
Set prb = QF.Problems.Open("Coupl1SA.pbm")
' First remove all existing links
Dim i As Integer
For i = 1 To prb.Links.Count
prb.Links.Remove (1)
Next
' Then add links to magnetic forces
prb.Links.Add qfMagneticForces, "Coupl1MS.pbm"
' Solve linked problem
Dim linkedPrb As QuickField.Problem
Set linkedPrb = QF.Problems.Open(prb.Links(1).TargetName)
linkedPrb.SolveProblem
' And now solve the main problem
prb.Save
prb.SolveProblem
Now we are ready to manipulate problem's geometric and physical data. To obtain a geometric Model object we use the Model
property of the Problem object. If the file MyModel.mod already exists it will be
loaded, otherwise the system creates a new blank Model object for you. The data document is
accessible by the DataDoc property. For example, the
following code