3.1.2.3. c3po.exchangeMethods.SharedRemapping module

Inheritance diagram of c3po.exchangeMethods.SharedRemapping

Contain the class SharedRemapping.

class c3po.exchangeMethods.SharedRemapping.Remapper(meshAlignment=False, offset=None, rescaling=1.0, rotation=0.0, outsideCellsScreening=False, reverseTransformations=True)

Bases: object

Allow to share the mesh projection for different SharedRemapping objects by building them with the same instance of this class.

__init__(meshAlignment=False, offset=None, rescaling=1.0, rotation=0.0, outsideCellsScreening=False, reverseTransformations=True)

Build a Remapper object.

Parameters:
  • meshAlignment (bool) – If set to True, at the initialization phase of the Remapper object, meshes are translated such as their “bounding box” are radially centred on (x = 0., y = 0.) and, if the meshes are 3D, have zmin = 0.

  • offset – Value of the offset between the source and the target meshes (>0 on z means that the source mesh is above the target one). The given vector is used to translate the source mesh (after the mesh alignment, if any). The dimension of offset must be >= the dimension of the meshes (we use only the first components).

  • rescaling (float) – Value of a rescaling factor to be applied between the source and the target meshes (>1 means that the source mesh is initially larger than the target one). The scaling is centered on [0., 0.(, 0.)] and is applied to the source mesh after mesh alignment or translation, if any.

  • rotation (float) – Value of the rotation between the source and the target meshes. The rotation is centered on [0., 0.(, 0.)] and is about the vertical axis. >0 means that the source mesh is rotated of the given angle compared to the target one. The inverse rotation is applied to the source mesh, after mesh alignment or translation, if any. pi means half turn.

  • outsideCellsScreening (bool) – If set to True, target (and source) cells whose barycentre is outside of source (or target) mesh are screen out (defaultValue is assigned to them). It can be useful to screen out cells that are in contact with the other mesh, but that should not be intersected by it. On the other hand, it will screen out cells actually intersected if their barycenter is outside of the other mesh ! Be careful with this option.

  • reverseTransformations (bool) – If set to True, all the transformations (translation, rescaling and rotation) applied in initialize() on the provided meshes are reversed at the end of initialize().

  • warning:: (..) – There seems to be a bug in MEDCoupling that may cause wrong results when rescaling is used with a source mesh of nature ExtensiveMaximum or IntensiveConservation. In this case, it is necessary to use reverseTransformations=False and to never perform a remapping on a field whose underling mesh has not been rescaled.

directRemap(field, defaultValue)

INTERNAL

exportMatrix(fileName)

Export remapping matrix on file.

This file can be loaded using loadMatrix() method in order to save initialization time.

Parameters:

fileName – Name of the file to write in.

getMatrix()

Export remapping matrix.

The matrix can be serialized using pickle, then it can be loaded using setMatrix() method in order to save initialization time.

Note

This method requires scipy.

Return type:

Matrix object.

initialize(sourceMesh, targetMesh)

INTERNAL

loadMatrix(fileName)

Load remapping matrix from file.

This file is usually written by exportMatrix() method.

Note

This method requires scipy.

Parameters:

fileName – Name of the file to read from.

reverseRemap(field, defaultValue)

INTERNAL

setMatrix(matrix)

Load remapping matrix.

This matrix is usually obtained by exportMatrix() method.

Note

This method requires scipy.

Parameters:

matrix – Matrix object.

class c3po.exchangeMethods.SharedRemapping.SharedRemapping(remapper, reverse=False, defaultValue=0.0, linearTransform=(1.0, 0.0))

Bases: ExchangeMethod

SharedRemapping is an ExchangeMethod which projects the input fields one by one before returning them as outputs, in the same order.

See c3po.Exchanger.Exchanger.__init__().

The method assumes that all input fields have the same mesh, and produces output fields on identical meshes.

This output mesh is the one of the first field passed to the method (obtained by getInputMEDFieldTemplate()).

The input scalars are returned in the same order, without modification.

The initialization of the projection method (long operation) is done only once, and can be shared with other instances of SharedRemapping through a Remapper object.

__call__(fieldsToGet, fieldsToSet, valuesToGet)

Project the input fields one by one before returning them as outputs, in the same order.

__init__(remapper, reverse=False, defaultValue=0.0, linearTransform=(1.0, 0.0))

Build an SharedRemapping object, to be given to an Exchanger.

Parameters:
  • remapper (Remapper) – A Remapper object (defined in C3PO) performing the projection. It can thus be shared with other instances of SharedRemapping (its initialization will always be done only once).

  • reverse (bool) – Allows the Remapper to be shared with an instance of SharedRemapping performing the reverse exchange (the projection will be done in the reverse direction if reverse is set to True).

  • defaultValue (float) – This is the default value to be assigned, during the projection, in the meshes of the target mesh that are not intersected by the source mesh.

  • linearTransform (tuple[float, float]) – Tuple (a,b): apply a linear function to all output fields f such as they become a * f + b. The transformation is applied after the mesh projection.

clean()

See ExchangeMethod.clean().

getPatterns()

See ExchangeMethod.getPatterns().

initialize(fieldsToGet, fieldsToSet)

INTERNAL

c3po.exchangeMethods.SharedRemapping.computeCellsToScreenOut(mesh1, mesh2)

INTERNAL