3.1.2.3. c3po.exchangeMethods.SharedRemapping module
Contain the class SharedRemapping.
- class c3po.exchangeMethods.SharedRemapping.Remapper(meshAlignment=False, offset=None, rescaling=1.0, rotation=0.0, outsideCellsScreening=False, reverseTransformations=True)
Bases:
objectAllow to share the mesh projection for different
SharedRemappingobjects 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
Remapperobject.- Parameters:
meshAlignment (bool) – If set to True, at the initialization phase of the
Remapperobject, meshes are translated such as their “bounding box” are radially centred on(x = 0., y = 0.)and, if the meshes are 3D, havezmin = 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 ofinitialize().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=Falseand 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:
ExchangeMethodSharedRemappingis anExchangeMethodwhich 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
SharedRemappingthrough aRemapperobject.- __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
SharedRemappingobject, to be given to anExchanger.- Parameters:
remapper (Remapper) – A
Remapperobject (defined in C3PO) performing the projection. It can thus be shared with other instances ofSharedRemapping(its initialization will always be done only once).reverse (bool) – Allows the
Remapperto be shared with an instance ofSharedRemappingperforming 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 fieldsfsuch as they becomea * f + b. The transformation is applied after the mesh projection.
- clean()
- getPatterns()
- initialize(fieldsToGet, fieldsToSet)
INTERNAL
- c3po.exchangeMethods.SharedRemapping.computeCellsToScreenOut(mesh1, mesh2)
INTERNAL