OOF2: The Manual

8.3. Adding New Fields, Fluxes, and Equations

New Fields, Fluxes, and Equations can be added with just a few lines of Python code. The OOF2 Field, Flux, and Equation classes represent global objects — there is only one instance of the Temperature field, for example, although the field may be defined on more than one Mesh, or on none at all. Creating a Field, Flux, or Equation object makes it available for use in a Mesh, and records some information about it, such as its name and dimension.

When a new material Property is created, it indicates which Fields, Fluxes and Equations it uses. The Field, Flux, and Equation classes themselves are not explicitly tied to any particular Properties. See Section 8.6 for the details.

OOF2 predefines some Fields, Fluxes, and Equations in SRC/engine/problem.py. Refer to that file for examples.

The Field subclasses defined in ooflib.SWIG.engine.field are:

These classes actually define CompoundFields, which represent the in-plane part of a Field along with its out of plane components, and the time derivatives of its in-plane and out-of-plane components.

To create a Field, Flux, or Equation, simply call the derived class's Python constructor.[57] For example:

from ooflib.SWIG.engine import field
Temperature = field.ScalarField("Temperature") 

New Fields should only be created by calling CompoundField constructors in Python. This will create four new Python variables whose names are the name of the Field, the name of the field suffixed with _z for the out-of-plane field, and the name suffixed with _t and _tz for the time derivative and its out-of-plane part. These variables live in the main OOF2 namespace, which is the one in which text mode, scripts and Console Window commands are executed.

Code outside of the main OOF2 namespace can gain access to the new Fields with the getField function. Within the script that created the Field, the Field can of course be referred to via a local variable referring to the new object:

gee = field.TwoVectorField("gee")

It is acceptable for the local variable name to be the same as the global variable name.

The Flux subclasses defined in ooflib.SWIG.engine.flux are:

The Equation subclasses defined in ooflib.SWIG.engine.equation are:

The Equation constructors each take a name, a Flux, and a dimension. The Flux is the Flux that the Equation operates on, and the dimension is an integer specifying how many components the equation has. (The divergence of a vector Flux has one component, and the divergence of a tensor flux has three components. A PlaneFluxEquation has as many components as there are out-of-plane components of the associated Flux.)

Like the Field classes, Fluxes and Equations can be retrieved by name in the main OOF2 namespace. They can also be retrieved by the getFlux and getEquation functions in either C++ or Python. Unlike Fields, they have no auxiliary out-of-plane or time derivative parts.

As an example, the following code fully defines the quantities necessary to solve the static heat conductivity problem (except for the thermal conductivity Material Property, which is discussed later).

from ooflib.SWIG.engine.field import ScalarField
from ooflib.SWIG.engine.flux import VectorFlux
from ooflib.SWIG.engine.equation import DivergenceEquation, PlaneFluxEquation

Temperature = ScalarField('Temperature')
Heat_Flux = VectorFlux('Heat_Flux')
HeatBalanceEqn = DivergenceEquation('Heat_Eqn', Heat_Flux, 1)
HeatOutOfPlane = PlaneFluxEquation('Plane_Heat_Flux', Heat_Flux, 1) 

Note that all of these quantities are already defined in OOF2 (in SRC/engine/problem.py to be exact) so don't redefine them. This is just an example of how you might define new Fields and Equations.



[57] Fields, Fluxes, and Equations are C++ classes, but they should only be instantiated by calling their swigged Python constructors.