Function

Type:string
Range:[]
Default:-/-
Appearance:simple
Excludes:Expression
Requires:Module

Used in combination with Module to specify the python function containing the “thermal source density”- tensor field definition.

In the most simple case a Python module is a .py-file which contains one or several python function definition. In this case the name of the module is simply the file name without its .py suffix. The parameter Function is used to pick out the desired function.

The so specified Python function must return a Python tuple or, preferable, a NumPy array of the appropriate shape (thermal source density is a scalar) and must accept a single argument which is a dictionary containing the parameters as defined by the Parameter sections:

# import numpy package
from numpy import *

def your_function_name(parameter):
   x = parameter['X'] # retrieving the position

   # add your code here

   return value # returns a  scalar

Note

The position \pvec{x} and the time t are implicitly inserted into the parameter dictionary with keys X and t respectively. For time-harmonic electromagnetic problems the angular frequency \omega is inserted with key EMOmega, if uniquely defined (EM stands for “electromagnetic”).

As a practical example we want to define an inductive heat source as stimulated by the presence of an time-harmonic electric field \VField{E} in a lossy medium with electric conductivity tensor \sigma (c.f. ElectricConductivity):

\begin{eqnarray*}
\SField{q} & = & \frac{1}{2} \VField{E}^{\mathrm{H}} \cdot \sigma \cdot \VField{E}
\end{eqnarray*}

This tensor field has two field parameters, namely the electric field strength \VField{E} and the electric conductivity tensor \pvec{\sigma}. It may be defined as follows:

Assuming that the respective Python implementation is contained in module PythonTensorFieldLibrary with function name InductiveHeating, the JCM-syntax looks like this:

ThermalSourceDensity {
  Python {
    Module = "PythonTensorFieldLibrary"
    Function = "InductiveHeating"

    Parameter {
       Name = "E"
       FieldValue {
         FieldBagPath = ... # path to an electric field
         Quantity = ElectricFieldStrength
       }
     }
     Parameter {
       Name = "sigma"
       FieldValue {
         Quantity = ElectricConductivity
       }
     }
   }
 }

Since, the FieldBagPath tag is missing within the last parameter section, the default value "./" is used. This means that the definition of the electric conductivity is taken from the materials.jcm file located in the same directory.

Tip

It is easier to define this simple example as an inline Python expression as shown in Expression.

The used Python function may have the following form:

from numpy import *

def InductiveHeating(parameter):
  E = parameter['E'] # retrieving the E-field vector
  sigma = parameter['sigma'] # retrieving the electric conductivity
  return 0.5*dot(E.conj().T, dot(sigma, E))

expression as shown in Expression.

The used Python function may have the following form:

from numpy import *

def ThermoOpticalCorrection(parameter):
  T0 = parameter['T0'] # retrieving T0
  a = parameter['a'] # retrieving a
  w = parameter['EMOmega'] # retrieving omega
  return a*eye(3, 3)*(T-T0)