boutcore package

Module contents

class boutcore.Coordinates

Contains information about geometry, such as metric tensors

Bxy

boutcore.Field2D

Type

Bxy

G1

boutcore.Field2D

Type

G1

G1_11

boutcore.Field2D

Type

G1_11

G1_12

boutcore.Field2D

Type

G1_12

G1_13

boutcore.Field2D

Type

G1_13

G1_22

boutcore.Field2D

Type

G1_22

G1_23

boutcore.Field2D

Type

G1_23

G1_33

boutcore.Field2D

Type

G1_33

G2

boutcore.Field2D

Type

G2

G2_11

boutcore.Field2D

Type

G2_11

G2_12

boutcore.Field2D

Type

G2_12

G2_13

boutcore.Field2D

Type

G2_13

G2_22

boutcore.Field2D

Type

G2_22

G2_23

boutcore.Field2D

Type

G2_23

G2_33

boutcore.Field2D

Type

G2_33

G3

boutcore.Field2D

Type

G3

G3_11

boutcore.Field2D

Type

G3_11

G3_12

boutcore.Field2D

Type

G3_12

G3_13

boutcore.Field2D

Type

G3_13

G3_22

boutcore.Field2D

Type

G3_22

G3_23

boutcore.Field2D

Type

G3_23

G3_33

boutcore.Field2D

Type

G3_33

IntShiftTorsion

boutcore.Field2D

Type

IntShiftTorsion

J

boutcore.Field2D

Type

J

ShiftTorsion

boutcore.Field2D

Type

ShiftTorsion

dx

boutcore.Field2D

Type

dx

dy

boutcore.Field2D

Type

dy

dz

boutcore.Field2D

Type

dz

g11

boutcore.Field2D

Type

g11

g12

boutcore.Field2D

Type

g12

g13

boutcore.Field2D

Type

g13

g22

boutcore.Field2D

Type

g22

g23

boutcore.Field2D

Type

g23

g33

boutcore.Field2D

Type

g33

g_11

boutcore.Field2D

Type

g_11

g_12

boutcore.Field2D

Type

g_12

g_13

boutcore.Field2D

Type

g_13

g_22

boutcore.Field2D

Type

g_22

g_23

boutcore.Field2D

Type

g_23

g_33

boutcore.Field2D

Type

g_33

boutcore.D2DX2(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative D2DX2

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed D2DX2 derivative

Return type

Field3D

boutcore.D2DY2(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative D2DY2

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed D2DY2 derivative

Return type

Field3D

boutcore.D2DZ2(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative D2DZ2

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed D2DZ2 derivative

Return type

Field3D

boutcore.DDX(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative DDX

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed DDX derivative

Return type

Field3D

boutcore.DDY(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative DDY

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed DDY derivative

Return type

Field3D

boutcore.DDZ(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative DDZ

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed DDZ derivative

Return type

Field3D

class boutcore.Datafile
add(self, save_repeat=False, **kwargs)
write(self)
boutcore.Delp2(Field3D a)
boutcore.Div_par(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the derivative Div_par

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Div_par derivative

Return type

Field3D

boutcore.FDDX(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative FDDX

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed FDDX derivative

Return type

Field3D

boutcore.FDDY(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative FDDY

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed FDDY derivative

Return type

Field3D

boutcore.FDDZ(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative FDDZ

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed FDDZ derivative

Return type

Field3D

class boutcore.Field2D

The Field2D class

applyBoundary(self, boundary=None, time=None)

Set the boundaries of a Field2D. Only one of both arguments can be provided. If no value is provided, the default boundary is applied.

Parameters
  • boundary (string, optional) – The boundary to be set. Has to be a valid boundary type, e.g. “neumann”.

  • time (float, optional) – The time to be used by the boundary, if time dependent boundary conditions are used.

ddt(self, val=None)

Get or set the time derivative

Parameters

val (Field2D, optional) – If set, set the time derivative to val

Returns

The time derivative

Return type

Field2D

classmethod fromBoutOutputs(type cls, outputs, name, tind=-1, mesh=None, ignoreDataType=False)

Create a Field2D from reading in a datafile via collect.

Parameters
  • outputs (BoutOutputs) – object to read from

  • tind (int, optional) – time slice to read

  • mesh (Mesh, optional) – if not defined, use global mesh

  • ignoreDataType (bool, optional) – Do not fail if data is not float64

  • **kwargs – remaining arguments are passed to collect

classmethod fromCollect(type cls, name, tind=-1, mesh=None, ignoreDataType=False, **kwargs)

Create a Field2D from reading in a datafile via collect.

Parameters
  • tind (int, optional) – time slice to read

  • mesh (Mesh, optional) – if not defined, use global mesh

  • ignoreDataType (bool, optional) – Do not fail if data is not float64

  • **kwargs – remaining arguments are passed to collect

classmethod fromMesh(type cls, mesh=None)

Create a Field2D.

Parameters

mesh (Mesh, optional) – The mesh of the Field2D. If None, use global mesh

get(self)

Get all data of the Field2D

Returns

A 2D numpy array with the data of the Field2D

Return type

array

getAll(self)

Get all data of the Field2D

Returns

A 2D numpy array with the data of the Field2D

Return type

array

getLocation(self)

Get the location of the Field2D

Returns

Representation of the field’s location.

Return type

string

isAllocated(self)

Check if the Field2D has its own datablock allocated

Returns

whether the Field is allocated

Return type

bool

set(self, data, ignoreDataType=False)

Set all data of the Field2D

Parameters
  • data (array_like) – The data to be set

  • ignoreDataType (bool, optional) – Ignore if data is off different type to BoutReal

setAll(self, data, ignoreDataType=False)

Set all data of the Field2D

Parameters
  • data (array_like) – The data to be set

  • ignoreDataType (bool, optional) – Ignore if data is off different type to BoutRealxx

setLocation(self, location)

Set the location of the Field2D This does not do any modification of the data.

Parameters

location (string) – The location to be set, e.g. “YLOW” or “CELL_YLOW” are supported.

class boutcore.Field3D

The Field3D class

applyBoundary(self, boundary=None, time=None)

Set the boundaries of a Field3D. Only one of both arguments can be provided. If no value is provided, the default boundary is applied.

Parameters
  • boundary (string, optional) – The boundary to be set. Has to be a valid boundary type, e.g. “neumann”.

  • time (float, optional) – The time to be used by the boundary, if time dependent boundary conditions are used.

applyParallelBoundary(self, boundary=None, time=None)

Set the boundaries of a Field3D. Only one of both arguments can be provided. If no value is provided, the default boundary is applied.

Parameters
  • boundary (string, optional) – The boundary to be set. Has to be a valid boundary type, e.g. “neumann”.

  • time (float, optional) – The time to be used by the boundary, if time dependent boundary conditions are used.

ddt(self, val=None)

Get or set the time derivative

Parameters

val (Field3D, optional) – If set, set the time derivative to val

Returns

The time derivative

Return type

Field3D

classmethod fromBoutOutputs(type cls, outputs, name, tind=-1, mesh=None, ignoreDataType=False)

Create a Field3D from reading in a datafile via collect.

Parameters
  • outputs (BoutOutputs) – object to read from

  • tind (int, optional) – time slice to read

  • mesh (Mesh, optional) – if not defined, use global mesh

  • ignoreDataType (bool, optional) – Do not fail if data is not float64

  • **kwargs – remaining arguments are passed to collect

classmethod fromCollect(type cls, name, tind=-1, mesh=None, ignoreDataType=False, **kwargs)

Create a Field3D from reading in a datafile via collect.

Parameters
  • tind (int, optional) – time slice to read

  • mesh (Mesh, optional) – if not defined, use global mesh

  • ignoreDataType (bool, optional) – Do not fail if data is not float64

  • **kwargs – remaining arguments are passed to collect

classmethod fromMesh(type cls, mesh=None)

Create a Field3D.

Parameters

mesh (Mesh, optional) – The mesh of the Field3D. If None, use global mesh

get(self)

Get all data of the Field3D

Returns

A 3D numpy array with the data of the Field3D

Return type

array

getAll(self)

Get all data of the Field3D

Returns

A 3D numpy array with the data of the Field3D

Return type

array

getLocation(self)

Get the location of the Field3D

Returns

Representation of the field’s location.

Return type

string

isAllocated(self)

Check if the Field3D has its own datablock allocated

Returns

whether the Field is allocated

Return type

bool

set(self, data, ignoreDataType=False)

Set all data of the Field3D

Parameters
  • data (array_like) – The data to be set

  • ignoreDataType (bool, optional) – Ignore if data is off different type to BoutReal

setAll(self, data, ignoreDataType=False)

Set all data of the Field3D

Parameters
  • data (array_like) – The data to be set

  • ignoreDataType (bool, optional) – Ignore if data is off different type to BoutRealxx

setLocation(self, location)

Set the location of the Field3D This does not do any modification of the data.

Parameters

location (string) – The location to be set, e.g. “YLOW” or “CELL_YLOW” are supported.

class boutcore.FieldFactory
boutcore.Grad(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the derivative Grad

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Grad derivative

Return type

Vector3D

boutcore.Grad_par(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the derivative Grad_par

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Grad_par derivative

Return type

Field3D

boutcore.Grad_perp(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the derivative Grad_perp

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Grad_perp derivative

Return type

Vector3D

boutcore.Grad_perp_dot_Grad_perp(Field3D a, Field3D b)
Parameters
  • a (Field3D) – The left field of the multiplication

  • b (Field3D) – The right field of the multiplication

Returns

the scalar product of the perpendicular gradient contributions

Return type

Field3D

boutcore.Laplace(Field3D a)

Compute the full Laplacian nabla^2(a)

Parameters

a (Field3D) – The Field3D object of which to calculate the derivative

Returns

The computed Laplacian

Return type

Field3D

class boutcore.Laplacian(section=None)

Laplacian inversion solver

Compute the Laplacian inversion of objects.

Equation solved is: dnabla^2_perp x + (1/c1)nabla_perp c2cdotnabla_perp x + exnabla_x x + eznabla_z x + a x = b

setCoefA(self, Field3D A)

Set the “A” coefficient of the Laplacian solver

Parameters

A (Field3D) – Field to set as coefficient

setCoefC(self, Field3D C)

Set the “C” coefficient of the Laplacian solver

Parameters

C (Field3D) – Field to set as coefficient

setCoefC1(self, Field3D C1)

Set the “C1” coefficient of the Laplacian solver

Parameters

C1 (Field3D) – Field to set as coefficient

setCoefC2(self, Field3D C2)

Set the “C2” coefficient of the Laplacian solver

Parameters

C2 (Field3D) – Field to set as coefficient

setCoefD(self, Field3D D)

Set the “D” coefficient of the Laplacian solver

Parameters

D (Field3D) – Field to set as coefficient

setCoefEx(self, Field3D Ex)

Set the “Ex” coefficient of the Laplacian solver

Parameters

Ex (Field3D) – Field to set as coefficient

setCoefEz(self, Field3D Ez)

Set the “Ez” coefficient of the Laplacian solver

Parameters

Ez (Field3D) – Field to set as coefficient

setCoefs(self, **kwargs)

Set the coefficients for the Laplacian solver. The coefficients A, C, C1, C2, D, Ex and Ez can be passed as keyword arguments

solve(self, Field3D x, Field3D guess)

Calculate the Laplacian inversion

Parameters
  • x (Field3D) – Field to be inverted

  • guess (Field3D) – initial guess for the inversion

Returns

the inversion of x, where guess is a guess to start with

Return type

Field3D

class boutcore.Mesh(create=True, section=None, options=None)

Mesh class

Contains information about geometry. It contains also the coordinates and is responsible for taking deriavtives.

communicate(self, *args)

Communicate (MPI) the boundaries of the Field3Ds with neighbours

Parameters

args (Field3D) – Abitrary number of fields

coordinates

Get the Coordinates object of this mesh

classmethod getGlobal(type cls)

Get the global Mesh object

Returns

The global instance

Return type

Mesh

normalise(self, double norm)

Normalise the mesh.

Usefull if the Options are in SI units, but the simulation is written in Bohm units. Calling it multiple times will not change the mesh, if the normalisation is always the same.

It calls mesh->dx/=norm etc. followed by a call to geometry().

Parameters

norm (float) – The length with which to rescale

class boutcore.Options(name='')

The Options class

classmethod fromFile(type cls, file)

Create a new Options object by reading a file

Parameters

file (string) – The path of the file to read

Returns

The Options object

Return type

Options

get(self, name, default)

Get an option

Parameters
  • name (string) – the name of the value to get. Can be relative, e.g. “mesh:ddx:first”.

  • default (bool or string or float) – Depending on the type of the default, different things will be returned. Supported types are bool, string or float

Returns

See default for the type. The option that was read if available, otherwise default

Return type

bool or string or float

set(self, name, value, source='PyInterface', force=False)

Set an option

Parameters
  • name (string) – the name of the value to be set. Can be relative, e.g. “mesh:ddx:first”.

  • value (string) – the value to be set

  • source (string, optional) – The source of the change. Useful for keeping track of where what was set.

  • force (bool, optional) – If a value is overwritten, an exception is thrown. setting this to True avoids the exception.

class boutcore.PhysicsModel

The PhysicsModel base class for python

To implement your own PhysicsModel derive from this class and provide a rhs function which takes the self and the simulation time as input, and the init function which takes self and whether the simulation has been restarted as an argument.

A complete simulation could look something like this:

import boutcore as bc

bc.init(“mesh:n=48”) class MyModel(bc.PhysicsModel):

def init(self,restart):

self.dens = bc.create3D(“sin(x)”) self.solve_for(n=self.dens)

def rhs(self,time):

self.dens.ddt(bc.DDX(self.dens))

model = MyModel() model.solve()

init(self, restart)

This can be overwritten to do model specific initialization

solve(self)

Call the solver. This makes sure that self.init(restart) and self.rhs(time) are called from the solver.

solve_for(self, *args, **kwargs)

Add Field3D’s to be solved for. Need to pass as name=field - where name is the name that is used e.g. for the dump file and field is a Field3D

Parameters

kwargs (dictionary of Field2D or Field3D) – Keys must be strings, and value of dict must be the Field3D which should be evolved.

class boutcore.PhysicsModelBase

The PhysicsModelBase in python - better use the PhysicsModel class

setInit(self, init)

set the init function to be called

Parameters

init (function) – Must not be a method, and must accept an bool (restart) as argument

setRhs(self, rhs)

set the rhs function to be called

Parameters

rhs (function) – Must not be a method, and must accept an double (time) as argument

solve(self)
solve_for(self, **kwargs)
class boutcore.PythonModelCallback

Needed for callbacks from C++ to python

execute(self, parameter)void
boutcore.VDDX(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative VDDX

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed VDDX derivative

Return type

Field3D

boutcore.VDDY(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative VDDY

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed VDDY derivative

Return type

Field3D

boutcore.VDDZ(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative VDDZ

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed VDDZ derivative

Return type

Field3D

class boutcore.Vector2D

Vector2D class

A vector of Field2D

get(self)

Get all data of the Vector2D

Returns

A 3D numpy array with the data of the Vector2D

Return type

np.ndarray

x

The Field2D in x direction

y

The Field2D in y direction

z

The Field2D in z direction

class boutcore.Vector3D

Vector3D class

A vector of Field3D

get(self)

Get all data of the Vector3D

Returns

A 4D numpy array with the data of the Vector3D

Return type

np.ndarray

x

The Field3D in x direction

y

The Field3D in y direction

z

The Field3D in z direction

boutcore.Vpar_Grad_par(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the flux derivative Vpar_Grad_par

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Vpar_Grad_par derivative

Return type

Field3D

boutcore.abs(a)

Calculate abs of a

Parameters

a (Field3D or Field2D) – The field for which to calculate abs

Returns

abs of a

Return type

Field3D or Field2D

boutcore.bracket(Field3D a, Field3D b, method=u'BRACKET_STD', outloc=u'CELL_DEFAULT')

Calculate the poison bracket for Field3D a and Field3D b.

Parameters
  • a (Field3D) – The left field in the bracket

  • b (Field3D) – The right field in the bracket

  • method (string) – The method to be used

  • outloc (string) – The location of the calculated derivative

Returns

The bracket

Return type

Field3D

boutcore.checkInit()

Assert that boutcore has been initialized

boutcore.cos(a)

Calculate cos of a

Parameters

a (Field3D or Field2D) – The field for which to calculate cos

Returns

cos of a

Return type

Field3D or Field2D

boutcore.create3D(string, Mesh msh=None, outloc=u'CELL_DEFAULT', time=0)

Returns a Field3D from the fieldfactory :Parameters: * string (string) – Expression to create. This can contain references to the options

  • msh (Mesh) – the Mesh to use, defaults to the global mesh.

  • outloc (string) – the cell location of the returned field

  • time (float) – is the time

Returns

the Field from the expression

Return type

Field3D

boutcore.cross(Vector3D a, Vector3D b)

Compute the cross product of two vectors

Parameters

a, b (Vector3D) – The two Vector3D objects of which to calculate the cross product

Returns

The cross product

Return type

Vector3D

boutcore.exp(a)

Calculate exp of a

Parameters

a (Field3D or Field2D) – The field for which to calculate exp

Returns

exp of a

Return type

Field3D or Field2D

boutcore.finalise()

Finalize BOUT++ and also MPI. After this most objects and functions are not valid anymore.

Note that this deallocates the C++ objects, thus the python objects might not work any more.

boutcore.init(args=[])

Initialization function for the library.

Parameters

args (list of string or string, optional) – It accepts ether a list of strings, or a string that is split at the spaces. This is passed on to MPI and other libraries that BOUT++ initializes.

boutcore.interp_to(Field3D f3d, location)

Interpolate a Field3D to a given location

Parameters
  • f3d (Field3D) – The field to interpolate

  • location (string) – The location to which to interploate

Returns

the interpolated field

Return type

Field3D

boutcore.log(a)

Calculate log of a

Parameters

a (Field3D or Field2D) – The field for which to calculate log

Returns

log of a

Return type

Field3D or Field2D

boutcore.max(Field3D a)

Get the maximum

Parameters

a (Field3D) – The field

Returns

the maximum value of a

Return type

float

boutcore.min(Field3D a)

Get the minimum

Parameters

a (Field3D) – The field

Returns

the minimum value of a

Return type

float

boutcore.pow(Field3D a, exponent)

Returns a**e where a is a Field3D and e is a number

Parameters
  • a (Field3D) – The field for which to calculate the power

  • exponent (float) – The exponent

Returns

The a**exponent

Return type

Field3D

boutcore.print(*args, sep=' ', end='\n')
boutcore.setOption(name, value, source='PyInterface', force=False)

Set an option in the global Options tree. Prefer Options.set to avoid unexpected results if several Option roots are avalaible.

Parameters
  • name (string) – the name of the value to be set. Can be relative, e.g. “mesh:ddx:first”.

  • value (string) – the value to be set

  • source (string) – The source of the change. Useful for keeping track of where what was set.

  • force (bool) – If a value is overwritten, an exception is thrown. setting this to True avoids the exception.

boutcore.sin(a)

Calculate sin of a

Parameters

a (Field3D or Field2D) – The field for which to calculate sin

Returns

sin of a

Return type

Field3D or Field2D

boutcore.sqrt(a)

Calculate sqrt of a

Parameters

a (Field3D or Field2D) – The field for which to calculate sqrt

Returns

sqrt of a

Return type

Field3D or Field2D

Undocumented functions

Special and inherited functions

class boutcore.Coordinates

Contains information about geometry, such as metric tensors

Bxy

boutcore.Field2D

Type

Bxy

G1

boutcore.Field2D

Type

G1

G1_11

boutcore.Field2D

Type

G1_11

G1_12

boutcore.Field2D

Type

G1_12

G1_13

boutcore.Field2D

Type

G1_13

G1_22

boutcore.Field2D

Type

G1_22

G1_23

boutcore.Field2D

Type

G1_23

G1_33

boutcore.Field2D

Type

G1_33

G2

boutcore.Field2D

Type

G2

G2_11

boutcore.Field2D

Type

G2_11

G2_12

boutcore.Field2D

Type

G2_12

G2_13

boutcore.Field2D

Type

G2_13

G2_22

boutcore.Field2D

Type

G2_22

G2_23

boutcore.Field2D

Type

G2_23

G2_33

boutcore.Field2D

Type

G2_33

G3

boutcore.Field2D

Type

G3

G3_11

boutcore.Field2D

Type

G3_11

G3_12

boutcore.Field2D

Type

G3_12

G3_13

boutcore.Field2D

Type

G3_13

G3_22

boutcore.Field2D

Type

G3_22

G3_23

boutcore.Field2D

Type

G3_23

G3_33

boutcore.Field2D

Type

G3_33

IntShiftTorsion

boutcore.Field2D

Type

IntShiftTorsion

J

boutcore.Field2D

Type

J

ShiftTorsion

boutcore.Field2D

Type

ShiftTorsion

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

Coordinates.__reduce_cython__(self)

__setstate__()

Coordinates.__setstate_cython__(self, __pyx_state)

dx

boutcore.Field2D

Type

dx

dy

boutcore.Field2D

Type

dy

dz

boutcore.Field2D

Type

dz

g11

boutcore.Field2D

Type

g11

g12

boutcore.Field2D

Type

g12

g13

boutcore.Field2D

Type

g13

g22

boutcore.Field2D

Type

g22

g23

boutcore.Field2D

Type

g23

g33

boutcore.Field2D

Type

g33

g_11

boutcore.Field2D

Type

g_11

g_12

boutcore.Field2D

Type

g_12

g_13

boutcore.Field2D

Type

g_13

g_22

boutcore.Field2D

Type

g_22

g_23

boutcore.Field2D

Type

g_23

g_33

boutcore.Field2D

Type

g_33

boutcore.D2DX2(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative D2DX2

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed D2DX2 derivative

Return type

Field3D

boutcore.D2DY2(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative D2DY2

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed D2DY2 derivative

Return type

Field3D

boutcore.D2DZ2(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative D2DZ2

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed D2DZ2 derivative

Return type

Field3D

boutcore.DDX(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative DDX

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed DDX derivative

Return type

Field3D

boutcore.DDY(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative DDY

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed DDY derivative

Return type

Field3D

boutcore.DDZ(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the derivative DDZ

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed DDZ derivative

Return type

Field3D

class boutcore.Datafile
__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

Datafile.__reduce_cython__(self)

__setstate__()

Datafile.__setstate_cython__(self, __pyx_state)

add(self, save_repeat=False, **kwargs)
write(self)
boutcore.Delp2(Field3D a)
boutcore.Div_par(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the derivative Div_par

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Div_par derivative

Return type

Field3D

boutcore.FDDX(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative FDDX

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed FDDX derivative

Return type

Field3D

boutcore.FDDY(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative FDDY

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed FDDY derivative

Return type

Field3D

boutcore.FDDZ(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative FDDZ

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed FDDZ derivative

Return type

Field3D

class boutcore.Field2D

The Field2D class

__add__(value, /)

Return self+value.

__delitem__(key, /)

Delete self[key].

__getitem__()

Get data from the Field2D Supports full 2D slicing support. Partially slicing is currently not supported.

Parameters

slices (tuple_like of slice) – List of slice objects, which shall be returned. Must contain 2 slice objects

Returns

Numpy array of the requested data

Return type

array

__iadd__(value, /)

Return self+=value.

__imul__(value, /)

Return self*=value.

__isub__(value, /)

Return self-=value.

__itruediv__(value, /)

Return self/=value.

__mul__(value, /)

Return self*value.

__neg__()
Returns

negative of the Field

Return type

Field2D

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__pow__()

other must be None

Returns

exponential of the field to the power of the exponential

Return type

Field2D

__radd__(self, lhs)
__rdiv__(self, lhs)
__reduce__()

Field2D.__reduce_cython__(self)

__rmul__(self, lhs)
__rpow__(value, mod=None, /)

Return pow(value, self, mod).

__rsub__(self, lhs)
__rtruediv__(self, lhs)
__setitem__()
Parameters
  • slices (tuple_like, slice) – slice objects of the data to be set. Must contain 2 slice objects

  • data (array_like) – Values to be set. Must be 2D and match the size of the slicing object.

__setstate__()

Field2D.__setstate_cython__(self, __pyx_state)

__sub__(value, /)

Return self-value.

__truediv__(value, /)

Return self/value.

applyBoundary(self, boundary=None, time=None)

Set the boundaries of a Field2D. Only one of both arguments can be provided. If no value is provided, the default boundary is applied.

Parameters
  • boundary (string, optional) – The boundary to be set. Has to be a valid boundary type, e.g. “neumann”.

  • time (float, optional) – The time to be used by the boundary, if time dependent boundary conditions are used.

ddt(self, val=None)

Get or set the time derivative

Parameters

val (Field2D, optional) – If set, set the time derivative to val

Returns

The time derivative

Return type

Field2D

classmethod fromBoutOutputs(type cls, outputs, name, tind=-1, mesh=None, ignoreDataType=False)

Create a Field2D from reading in a datafile via collect.

Parameters
  • outputs (BoutOutputs) – object to read from

  • tind (int, optional) – time slice to read

  • mesh (Mesh, optional) – if not defined, use global mesh

  • ignoreDataType (bool, optional) – Do not fail if data is not float64

  • **kwargs – remaining arguments are passed to collect

classmethod fromCollect(type cls, name, tind=-1, mesh=None, ignoreDataType=False, **kwargs)

Create a Field2D from reading in a datafile via collect.

Parameters
  • tind (int, optional) – time slice to read

  • mesh (Mesh, optional) – if not defined, use global mesh

  • ignoreDataType (bool, optional) – Do not fail if data is not float64

  • **kwargs – remaining arguments are passed to collect

classmethod fromMesh(type cls, mesh=None)

Create a Field2D.

Parameters

mesh (Mesh, optional) – The mesh of the Field2D. If None, use global mesh

get(self)

Get all data of the Field2D

Returns

A 2D numpy array with the data of the Field2D

Return type

array

getAll(self)

Get all data of the Field2D

Returns

A 2D numpy array with the data of the Field2D

Return type

array

getLocation(self)

Get the location of the Field2D

Returns

Representation of the field’s location.

Return type

string

isAllocated(self)

Check if the Field2D has its own datablock allocated

Returns

whether the Field is allocated

Return type

bool

set(self, data, ignoreDataType=False)

Set all data of the Field2D

Parameters
  • data (array_like) – The data to be set

  • ignoreDataType (bool, optional) – Ignore if data is off different type to BoutReal

setAll(self, data, ignoreDataType=False)

Set all data of the Field2D

Parameters
  • data (array_like) – The data to be set

  • ignoreDataType (bool, optional) – Ignore if data is off different type to BoutRealxx

setLocation(self, location)

Set the location of the Field2D This does not do any modification of the data.

Parameters

location (string) – The location to be set, e.g. “YLOW” or “CELL_YLOW” are supported.

class boutcore.Field3D

The Field3D class

__add__(value, /)

Return self+value.

__delitem__(key, /)

Delete self[key].

__getitem__()

Get data from the Field3D Supports full 3D slicing support. Partially slicing is currently not supported.

Parameters

slices (tuple_like of slice) – List of slice objects, which shall be returned. Must contain 3 slice objects

Returns

Numpy array of the requested data

Return type

array

__iadd__(value, /)

Return self+=value.

__imul__(value, /)

Return self*=value.

__isub__(value, /)

Return self-=value.

__itruediv__(value, /)

Return self/=value.

__mul__(value, /)

Return self*value.

__neg__()
Returns

negative of the Field

Return type

Field3D

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__pow__()

other must be None

Returns

exponential of the field to the power of the exponential

Return type

Field3D

__radd__(self, lhs)
__rdiv__(self, lhs)
__reduce__()

Field3D.__reduce_cython__(self)

__rmul__(self, lhs)
__rpow__(value, mod=None, /)

Return pow(value, self, mod).

__rsub__(self, lhs)
__rtruediv__(self, lhs)
__setitem__()
Parameters
  • slices (tuple_like, slice) – slice objects of the data to be set. Must contain 3 slice objects

  • data (array_like) – Values to be set. Must be 3D and match the size of the slicing object.

__setstate__()

Field3D.__setstate_cython__(self, __pyx_state)

__sub__(value, /)

Return self-value.

__truediv__(value, /)

Return self/value.

applyBoundary(self, boundary=None, time=None)

Set the boundaries of a Field3D. Only one of both arguments can be provided. If no value is provided, the default boundary is applied.

Parameters
  • boundary (string, optional) – The boundary to be set. Has to be a valid boundary type, e.g. “neumann”.

  • time (float, optional) – The time to be used by the boundary, if time dependent boundary conditions are used.

applyParallelBoundary(self, boundary=None, time=None)

Set the boundaries of a Field3D. Only one of both arguments can be provided. If no value is provided, the default boundary is applied.

Parameters
  • boundary (string, optional) – The boundary to be set. Has to be a valid boundary type, e.g. “neumann”.

  • time (float, optional) – The time to be used by the boundary, if time dependent boundary conditions are used.

ddt(self, val=None)

Get or set the time derivative

Parameters

val (Field3D, optional) – If set, set the time derivative to val

Returns

The time derivative

Return type

Field3D

classmethod fromBoutOutputs(type cls, outputs, name, tind=-1, mesh=None, ignoreDataType=False)

Create a Field3D from reading in a datafile via collect.

Parameters
  • outputs (BoutOutputs) – object to read from

  • tind (int, optional) – time slice to read

  • mesh (Mesh, optional) – if not defined, use global mesh

  • ignoreDataType (bool, optional) – Do not fail if data is not float64

  • **kwargs – remaining arguments are passed to collect

classmethod fromCollect(type cls, name, tind=-1, mesh=None, ignoreDataType=False, **kwargs)

Create a Field3D from reading in a datafile via collect.

Parameters
  • tind (int, optional) – time slice to read

  • mesh (Mesh, optional) – if not defined, use global mesh

  • ignoreDataType (bool, optional) – Do not fail if data is not float64

  • **kwargs – remaining arguments are passed to collect

classmethod fromMesh(type cls, mesh=None)

Create a Field3D.

Parameters

mesh (Mesh, optional) – The mesh of the Field3D. If None, use global mesh

get(self)

Get all data of the Field3D

Returns

A 3D numpy array with the data of the Field3D

Return type

array

getAll(self)

Get all data of the Field3D

Returns

A 3D numpy array with the data of the Field3D

Return type

array

getLocation(self)

Get the location of the Field3D

Returns

Representation of the field’s location.

Return type

string

isAllocated(self)

Check if the Field3D has its own datablock allocated

Returns

whether the Field is allocated

Return type

bool

set(self, data, ignoreDataType=False)

Set all data of the Field3D

Parameters
  • data (array_like) – The data to be set

  • ignoreDataType (bool, optional) – Ignore if data is off different type to BoutReal

setAll(self, data, ignoreDataType=False)

Set all data of the Field3D

Parameters
  • data (array_like) – The data to be set

  • ignoreDataType (bool, optional) – Ignore if data is off different type to BoutRealxx

setLocation(self, location)

Set the location of the Field3D This does not do any modification of the data.

Parameters

location (string) – The location to be set, e.g. “YLOW” or “CELL_YLOW” are supported.

class boutcore.FieldFactory
__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

FieldFactory.__reduce_cython__(self)

__setstate__()

FieldFactory.__setstate_cython__(self, __pyx_state)

boutcore.Grad(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the derivative Grad

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Grad derivative

Return type

Vector3D

boutcore.Grad_par(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the derivative Grad_par

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Grad_par derivative

Return type

Field3D

boutcore.Grad_perp(Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the derivative Grad_perp

Parameters
  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Grad_perp derivative

Return type

Vector3D

boutcore.Grad_perp_dot_Grad_perp(Field3D a, Field3D b)
Parameters
  • a (Field3D) – The left field of the multiplication

  • b (Field3D) – The right field of the multiplication

Returns

the scalar product of the perpendicular gradient contributions

Return type

Field3D

boutcore.Laplace(Field3D a)

Compute the full Laplacian nabla^2(a)

Parameters

a (Field3D) – The Field3D object of which to calculate the derivative

Returns

The computed Laplacian

Return type

Field3D

class boutcore.Laplacian(section=None)

Laplacian inversion solver

Compute the Laplacian inversion of objects.

Equation solved is: dnabla^2_perp x + (1/c1)nabla_perp c2cdotnabla_perp x + exnabla_x x + eznabla_z x + a x = b

__init__()

Initialiase a Laplacian solver

Parameters

section (Options, optional) – The section from the Option tree to take the options from

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

Laplacian.__reduce_cython__(self)

__setstate__()

Laplacian.__setstate_cython__(self, __pyx_state)

setCoefA(self, Field3D A)

Set the “A” coefficient of the Laplacian solver

Parameters

A (Field3D) – Field to set as coefficient

setCoefC(self, Field3D C)

Set the “C” coefficient of the Laplacian solver

Parameters

C (Field3D) – Field to set as coefficient

setCoefC1(self, Field3D C1)

Set the “C1” coefficient of the Laplacian solver

Parameters

C1 (Field3D) – Field to set as coefficient

setCoefC2(self, Field3D C2)

Set the “C2” coefficient of the Laplacian solver

Parameters

C2 (Field3D) – Field to set as coefficient

setCoefD(self, Field3D D)

Set the “D” coefficient of the Laplacian solver

Parameters

D (Field3D) – Field to set as coefficient

setCoefEx(self, Field3D Ex)

Set the “Ex” coefficient of the Laplacian solver

Parameters

Ex (Field3D) – Field to set as coefficient

setCoefEz(self, Field3D Ez)

Set the “Ez” coefficient of the Laplacian solver

Parameters

Ez (Field3D) – Field to set as coefficient

setCoefs(self, **kwargs)

Set the coefficients for the Laplacian solver. The coefficients A, C, C1, C2, D, Ex and Ez can be passed as keyword arguments

solve(self, Field3D x, Field3D guess)

Calculate the Laplacian inversion

Parameters
  • x (Field3D) – Field to be inverted

  • guess (Field3D) – initial guess for the inversion

Returns

the inversion of x, where guess is a guess to start with

Return type

Field3D

class boutcore.Mesh(create=True, section=None, options=None)

Mesh class

Contains information about geometry. It contains also the coordinates and is responsible for taking deriavtives.

__init__()

Create a Mesh

createbool, optional

Create the underling C++ object. Disabled probably only useful for internal usage. Use at own risk.

sectionstring, optional

The section of the options which to read. If not given, default to the root section.

optionsOptions, optional

The Option which to use. Can be specified together with section, in which case the subsection from the current Options object is used. If nether section nor options is given, the default section (mesh) from the global Options object is used.

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

Mesh.__reduce_cython__(self)

__setstate__()

Mesh.__setstate_cython__(self, __pyx_state)

communicate(self, *args)

Communicate (MPI) the boundaries of the Field3Ds with neighbours

Parameters

args (Field3D) – Abitrary number of fields

coordinates

Get the Coordinates object of this mesh

classmethod getGlobal(type cls)

Get the global Mesh object

Returns

The global instance

Return type

Mesh

normalise(self, double norm)

Normalise the mesh.

Usefull if the Options are in SI units, but the simulation is written in Bohm units. Calling it multiple times will not change the mesh, if the normalisation is always the same.

It calls mesh->dx/=norm etc. followed by a call to geometry().

Parameters

norm (float) – The length with which to rescale

class boutcore.Options(name='')

The Options class

__init__()

Get a section from the global options tree

Parameters

name (string, optional) – The name of the section. Can contain “:” to specify subsections. Defaults to the root section “”.

Returns

The Options object

Return type

Options

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

Options.__reduce_cython__(self)

__setstate__()

Options.__setstate_cython__(self, __pyx_state)

classmethod fromFile(type cls, file)

Create a new Options object by reading a file

Parameters

file (string) – The path of the file to read

Returns

The Options object

Return type

Options

get(self, name, default)

Get an option

Parameters
  • name (string) – the name of the value to get. Can be relative, e.g. “mesh:ddx:first”.

  • default (bool or string or float) – Depending on the type of the default, different things will be returned. Supported types are bool, string or float

Returns

See default for the type. The option that was read if available, otherwise default

Return type

bool or string or float

set(self, name, value, source='PyInterface', force=False)

Set an option

Parameters
  • name (string) – the name of the value to be set. Can be relative, e.g. “mesh:ddx:first”.

  • value (string) – the value to be set

  • source (string, optional) – The source of the change. Useful for keeping track of where what was set.

  • force (bool, optional) – If a value is overwritten, an exception is thrown. setting this to True avoids the exception.

class boutcore.PhysicsModel

The PhysicsModel base class for python

To implement your own PhysicsModel derive from this class and provide a rhs function which takes the self and the simulation time as input, and the init function which takes self and whether the simulation has been restarted as an argument.

A complete simulation could look something like this:

import boutcore as bc

bc.init(“mesh:n=48”) class MyModel(bc.PhysicsModel):

def init(self,restart):

self.dens = bc.create3D(“sin(x)”) self.solve_for(n=self.dens)

def rhs(self,time):

self.dens.ddt(bc.DDX(self.dens))

model = MyModel() model.solve()

__dealloc__(self)
__init__(self)
__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

PhysicsModelBase.__reduce_cython__(self)

__setstate__()

PhysicsModelBase.__setstate_cython__(self, __pyx_state)

__weakref__

list of weak references to the object (if defined)

init(self, restart)

This can be overwritten to do model specific initialization

setInit(self, init)

set the init function to be called

Parameters

init (function) – Must not be a method, and must accept an bool (restart) as argument

setRhs(self, rhs)

set the rhs function to be called

Parameters

rhs (function) – Must not be a method, and must accept an double (time) as argument

solve(self)

Call the solver. This makes sure that self.init(restart) and self.rhs(time) are called from the solver.

solve_for(self, *args, **kwargs)

Add Field3D’s to be solved for. Need to pass as name=field - where name is the name that is used e.g. for the dump file and field is a Field3D

Parameters

kwargs (dictionary of Field2D or Field3D) – Keys must be strings, and value of dict must be the Field3D which should be evolved.

class boutcore.PhysicsModelBase

The PhysicsModelBase in python - better use the PhysicsModel class

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

PhysicsModelBase.__reduce_cython__(self)

__setstate__()

PhysicsModelBase.__setstate_cython__(self, __pyx_state)

setInit(self, init)

set the init function to be called

Parameters

init (function) – Must not be a method, and must accept an bool (restart) as argument

setRhs(self, rhs)

set the rhs function to be called

Parameters

rhs (function) – Must not be a method, and must accept an double (time) as argument

solve(self)
solve_for(self, **kwargs)
class boutcore.PythonModelCallback

Needed for callbacks from C++ to python

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

PythonModelCallback.__reduce_cython__(self)

__setstate__()

PythonModelCallback.__setstate_cython__(self, __pyx_state)

execute(self, parameter)void
boutcore.VDDX(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative VDDX

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed VDDX derivative

Return type

Field3D

boutcore.VDDY(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative VDDY

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed VDDY derivative

Return type

Field3D

boutcore.VDDZ(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT', region=u'RGN_NOBNDRY')

Compute the flux derivative VDDZ

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

  • region (string) – The region for which to calculate the derivative

Returns

The computed VDDZ derivative

Return type

Field3D

class boutcore.Vector2D

Vector2D class

A vector of Field2D

__mul__(value, /)

Return self*value.

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

Vector2D.__reduce_cython__(self)

__rmul__(value, /)

Return value*self.

__setstate__()

Vector2D.__setstate_cython__(self, __pyx_state)

get(self)

Get all data of the Vector2D

Returns

A 3D numpy array with the data of the Vector2D

Return type

np.ndarray

x

The Field2D in x direction

y

The Field2D in y direction

z

The Field2D in z direction

class boutcore.Vector3D

Vector3D class

A vector of Field3D

__mul__(value, /)

Return self*value.

__new__(**kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__()

Vector3D.__reduce_cython__(self)

__rmul__(value, /)

Return value*self.

__setstate__()

Vector3D.__setstate_cython__(self, __pyx_state)

get(self)

Get all data of the Vector3D

Returns

A 4D numpy array with the data of the Vector3D

Return type

np.ndarray

x

The Field3D in x direction

y

The Field3D in y direction

z

The Field3D in z direction

boutcore.Vpar_Grad_par(Field3D velocity, Field3D field, outloc=u'CELL_DEFAULT', method=u'DIFF_DEFAULT')

Compute the flux derivative Vpar_Grad_par

Parameters
  • velocity (Field3D) – The Field3D object of which the field is advected

  • field (Field3D) – The Field3D object of which to calculate the derivative

  • outloc (string) – The location where the derivative is expected. Defaults to the same as field.

  • method (string) – The method to calculate the derivative.

Returns

The computed Vpar_Grad_par derivative

Return type

Field3D

boutcore.__reduce_cython__(self)
boutcore.__setstate_cython__(self, __pyx_state)
boutcore.abs(a)

Calculate abs of a

Parameters

a (Field3D or Field2D) – The field for which to calculate abs

Returns

abs of a

Return type

Field3D or Field2D

boutcore.bracket(Field3D a, Field3D b, method=u'BRACKET_STD', outloc=u'CELL_DEFAULT')

Calculate the poison bracket for Field3D a and Field3D b.

Parameters
  • a (Field3D) – The left field in the bracket

  • b (Field3D) – The right field in the bracket

  • method (string) – The method to be used

  • outloc (string) – The location of the calculated derivative

Returns

The bracket

Return type

Field3D

boutcore.checkInit()

Assert that boutcore has been initialized

boutcore.cos(a)

Calculate cos of a

Parameters

a (Field3D or Field2D) – The field for which to calculate cos

Returns

cos of a

Return type

Field3D or Field2D

boutcore.create3D(string, Mesh msh=None, outloc=u'CELL_DEFAULT', time=0)

Returns a Field3D from the fieldfactory :Parameters: * string (string) – Expression to create. This can contain references to the options

  • msh (Mesh) – the Mesh to use, defaults to the global mesh.

  • outloc (string) – the cell location of the returned field

  • time (float) – is the time

Returns

the Field from the expression

Return type

Field3D

boutcore.cross(Vector3D a, Vector3D b)

Compute the cross product of two vectors

Parameters

a, b (Vector3D) – The two Vector3D objects of which to calculate the cross product

Returns

The cross product

Return type

Vector3D

boutcore.exp(a)

Calculate exp of a

Parameters

a (Field3D or Field2D) – The field for which to calculate exp

Returns

exp of a

Return type

Field3D or Field2D

boutcore.finalise()

Finalize BOUT++ and also MPI. After this most objects and functions are not valid anymore.

Note that this deallocates the C++ objects, thus the python objects might not work any more.

boutcore.init(args=[])

Initialization function for the library.

Parameters

args (list of string or string, optional) – It accepts ether a list of strings, or a string that is split at the spaces. This is passed on to MPI and other libraries that BOUT++ initializes.

boutcore.interp_to(Field3D f3d, location)

Interpolate a Field3D to a given location

Parameters
  • f3d (Field3D) – The field to interpolate

  • location (string) – The location to which to interploate

Returns

the interpolated field

Return type

Field3D

boutcore.log(a)

Calculate log of a

Parameters

a (Field3D or Field2D) – The field for which to calculate log

Returns

log of a

Return type

Field3D or Field2D

boutcore.max(Field3D a)

Get the maximum

Parameters

a (Field3D) – The field

Returns

the maximum value of a

Return type

float

boutcore.min(Field3D a)

Get the minimum

Parameters

a (Field3D) – The field

Returns

the minimum value of a

Return type

float

boutcore.pow(Field3D a, exponent)

Returns a**e where a is a Field3D and e is a number

Parameters
  • a (Field3D) – The field for which to calculate the power

  • exponent (float) – The exponent

Returns

The a**exponent

Return type

Field3D

boutcore.print(*args, sep=' ', end='\n')
boutcore.setOption(name, value, source='PyInterface', force=False)

Set an option in the global Options tree. Prefer Options.set to avoid unexpected results if several Option roots are avalaible.

Parameters
  • name (string) – the name of the value to be set. Can be relative, e.g. “mesh:ddx:first”.

  • value (string) – the value to be set

  • source (string) – The source of the change. Useful for keeping track of where what was set.

  • force (bool) – If a value is overwritten, an exception is thrown. setting this to True avoids the exception.

boutcore.sin(a)

Calculate sin of a

Parameters

a (Field3D or Field2D) – The field for which to calculate sin

Returns

sin of a

Return type

Field3D or Field2D

boutcore.sqrt(a)

Calculate sqrt of a

Parameters

a (Field3D or Field2D) – The field for which to calculate sqrt

Returns

sqrt of a

Return type

Field3D or Field2D