Function

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

Used in combination with Module to specify the python function containing the “electric field strength”- 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 (electric field strength is a 3-vector) 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  3-vector

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 a plane wave with amplitude \VField{A} and wave vector \pvec{k}:

\begin{eqnarray*}
\VField{E} & = & \VField{A} \cdot e^{i \pvec{k}^{\mathrm{T}} \cdot \pvec{x}}
\end{eqnarray*}

This tensor field has the complex-valued vector parameters \VField{A} and \pvec{k}.

Tip

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

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

ElectricFieldStrength {
  Python {
     Module = "PythonTensorFieldLibrary"
     Function = "PlaneWave"
     Parameter {
       Name = "k"
       VectorValue = ... # set wave vector here
     }
     Parameter {
       Name = "A"
       VectorValue = ... # set amplitude vector here
     }
   }
 }

The used Python function may have the following form:

from numpy import *

def PlaneWave(parameter):
  x = parameter['X'] # retrieving the position
  k = parameter['k'] # retrieving the wave vector
  A = parameter['A'] # retrieving the amplitude

  return exp(1j*dot(k.T, x))*A;

We give more elaborated examples with field parameter dependencies in

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)