ActiveField Technology

Properties 
Methods 
Userdefined function. Used as a parameter for GetCustomIntegral.
UserFunction object is the interface for calculation the custom userdefined function. In QuickField 6.2 userdefined function is used as integrand for calculation custom integrals with methods GetCustomIntegral and GetCustomIntegralTotal of the Result object.
QuickField has no implemented object with this interface. QuickField user should implement this interface in his/her program.
UserFunction interface has the only method:
Sub GetValue (point, bodyLabel, resValue)
with two input parameters point and bodyLabel an one
output parameter resValue. All three parameter have to be declared with
the ByVal keyword.
The calculated value resValue has the Quantity type, which is a container for physical quantities of different types (scalar, vector, complex etc.).
point as FieldPoint 
Coordinates of the point where the custom function should be calculated and local field values there. Parameter is an object of the FieldPoint type or derived types (FieldPointES, FieldPointCF, FieldPointTE, FieldPointTV, FieldPointHE, FieldPointSA, FieldPointEC) depending on the analysis type. 
bodyLabel as String 
This parameter contains the label of the current block, through which the integration contour goes through 
Calculated value resVal of the Quantity type 
Calculated value of the custom function should be put into the object of Quantity type, which includes information about the type and value. GetValue function should not create or delete the Quantity object. Its creation and removal should be performed in the calling program code. 
The following example showcases UserFunction, which implements the core loss calculation in the ferromagnetic material using Steinmetz equation
p = k_{loss}·B_{m}^{α}·f^{β},
where p  specific volume losses, B_{m}  flux density magnitude, f  frequency, k_{loss}, α, β  constants related to the material properties and magnetic field change mode.
First example is implemented in Visual Basic for Appliation (VBA) within MS Excel environment. This code should be placed into the separate Class Module, which is in our example named LossFunction. The class module should have the attribute Instancing = 2 (PublicNotCreatable) in the module property dialogue.
Option Explicit
Implements QuickField.UserFunction
Public pbm As QuickField.Application
Public Sub UserFunction_GetValue(ByVal Point As QuickField.FieldPoint, ByVal bodyLabel As String,
ByVal resVal As QuickField.Quantity)
' derive the Point parameter from the base type FieldPoint to the derived type FieldPointHE,
' which corresponds to the problem analysis type
Dim pointHE As QuickField.FieldPointHE
Set pointHE = Point
' Steinmetz loss equation coefficients
Const lossFactor As Double = 0.12345
Const alpha As Double = 2.05
Const beta As Double = 1.3
Const frequency As Double = 50
Dim B As Double
Dim lossDensity As Double
' to calculate the custom function we need the flux density magnitude:
B = pointHE.FluxDensity.Magnitude.R
lossDensity = lossFactor * WorksheetFunction.Power(frequency, beta) * WorksheetFunction.Power(B, alpha)
' store the calculated value to return the result
resVal.SetAsScalar lossDensity
End Sub
Following fragment calculates the custom userdefined volume integral using the redefined UserFunction:
Dim flag As Long ' flag is necessary to call the integrand function
Dim q As QuickField.Quantity ' integral calculation result
Dim res As Double '
flag = 0
Set myFunc = New VBAProject.LossFunction '
LossFunction here is the name of the Class Module, where our interface UserFunction is defined
Set q = res.GetCustomIntegral(myFunc, qfOverVolume, cnt)
' the call of the method for calculation of the user integral
over the volume inside the closed contour
Second variant is written in C#. Simple implementation of the UserFunction interface may look like:
class CoreLoss : QuickField.UserFunction
{
public void GetValue(QuickField.FieldPoint point, string blockLabel, ref QuickField.Quantity res)
{
const double lossFactor = 0.12345;
const double alpha = 2.05;
const double beta = 1.3;
const double frequency = 50;
var pointHE = point as FieldPointHE;
double B = pointHE.FluxDensity.Magnitude.R;
double val = lossFactor * Math.Pow(frequency, beta) * Math.Pow(B, alpha);
res.SetAsScalar(val);
}
}
To calculate the custom integral ober the volume, which is limited by the closed contour, it is required to create the new instance of the class, which implements the interface QuickField.UserFunction, and pass it as a parameter at the call of GetCustomIntegral method of the QuickField.Result class:
var myUserFunc = new CoreLoss(pbm);
double custom = res.GetCustomIntegral(myUserFunc,
qfOverVolume, cont).Abs;