Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e4aa661
First commit, move the plugin and the filter
RomainBaville Aug 22, 2025
702a3a4
fix issue with multiblock input
RomainBaville Aug 22, 2025
79a1db4
Update logger and refactor - plugin with the VTKPythonAlgorithmBase -…
RomainBaville Aug 25, 2025
da614d1
Merge branch 'main' into RomainBaville/feature/VTK_filter_and_paravie…
RomainBaville Sep 1, 2025
9b86c83
fix apply feature on paraview
RomainBaville Sep 1, 2025
8a92269
Update the doc and add input checks
RomainBaville Sep 1, 2025
2d778d8
update doc
RomainBaville Sep 1, 2025
40fae76
Update the name of the filter
RomainBaville Sep 2, 2025
8ba8e89
fix the function computeCellMapping, bounds are used instead of center
RomainBaville Sep 2, 2025
7f6a8a2
adapte the plugin to deals with global attributes only
RomainBaville Sep 2, 2025
975e86c
Add the function to get the vtk type of an attribute on a mesh
RomainBaville Sep 2, 2025
1d38c90
Change the method, meshes are parsed instead of merged
RomainBaville Sep 2, 2025
25b1fc3
add functions to compute the cellMapping from the coordinate between …
RomainBaville Sep 3, 2025
bebfdcd
clean for ci
RomainBaville Sep 3, 2025
5bcc52d
move function to compute the cellMap in arrayHelpers
RomainBaville Sep 3, 2025
4980797
clean for ci
RomainBaville Sep 3, 2025
4d6b521
clean for ci
RomainBaville Sep 3, 2025
ad3ba4d
update doc files
RomainBaville Sep 3, 2025
3521290
clean tests for computeElementMapping
RomainBaville Sep 5, 2025
d414a2d
Add the possibility to chose to map cell or point and use flat index …
RomainBaville Sep 5, 2025
2bb18c1
add teh function to transfer an attribute from a mesh to another with…
RomainBaville Sep 5, 2025
2f30167
update to choose the piece of the attribute to transefer
RomainBaville Sep 5, 2025
8438fc7
test of the vtk filter AttributeMapping
RomainBaville Sep 5, 2025
b90e8f7
fix nullblocks issues
RomainBaville Sep 5, 2025
147351e
add the test for the function transferAttribute
RomainBaville Sep 5, 2025
c93e188
fix for test
RomainBaville Sep 5, 2025
424938e
Fix double apply
RomainBaville Sep 8, 2025
da83524
Clean for ci
RomainBaville Sep 9, 2025
9d04059
Remove AttributeMappingFromCellId and clean the doc
RomainBaville Sep 9, 2025
04e692a
Update to the last verion of the main.
RomainBaville Sep 10, 2025
de2e64e
fix block id
RomainBaville Sep 10, 2025
8a2ef89
Apply suggestions from Paloma's review
RomainBaville Sep 11, 2025
e01211e
Clean the doc
RomainBaville Sep 11, 2025
6a62c73
Add info to the logger
RomainBaville Sep 11, 2025
36291c6
Clean the doc
RomainBaville Sep 11, 2025
4865557
clean the doc
RomainBaville Sep 11, 2025
484dcdd
clean the doc
RomainBaville Sep 11, 2025
b2cbc5e
Clean the doc and the plugin
RomainBaville Sep 11, 2025
fb325b7
Apply comments from Jacques review.
RomainBaville Sep 11, 2025
ea7e15e
Update to the last version of the main
RomainBaville Sep 11, 2025
f49880a
Clean for ci
RomainBaville Sep 12, 2025
e2822ec
Fix the tests
RomainBaville Sep 12, 2025
8866dba
Fix the tests
RomainBaville Sep 12, 2025
c9320aa
Move files to new directory
RomainBaville Sep 12, 2025
bca66e7
Add a vtp file
RomainBaville Sep 12, 2025
9849529
map volume to surface mesh
RomainBaville Sep 12, 2025
79b5a07
Update AttributeMapping to transfer attribute between Surface and vol…
RomainBaville Sep 12, 2025
cc730e4
Fix ci
RomainBaville Sep 15, 2025
e0a46c9
Apply Paloma and Jacques suggestions
RomainBaville Sep 25, 2025
a19dce1
Merge branch 'main' into RomainBaville/feature/VTK_filter_and_paravie…
RomainBaville Sep 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/geos_mesh_docs/processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Processing filters

The `processing` module of `geos-mesh` package contains filters to process meshes.

geos.mesh.processing.AttributeMapping filter
---------------------------------------------

.. automodule:: geos.mesh.processing.AttributeMapping
:members:
:undoc-members:
:show-inheritance:

geos.mesh.processing.CreateConstantAttributePerRegion filter
-------------------------------------------------------------

Expand Down
12 changes: 0 additions & 12 deletions docs/geos_posp_docs/PVplugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ The plugins include:
* Processing plugins to compute additional geomechanical properties;
* Visualization plugins to plot Mohr's circles and cross plots using Paraview Python View.

PVAttributeMapping plugin
-----------------------------------

.. automodule:: PVplugins.PVAttributeMapping


PVExtractMergeBlocksVolume plugin
-------------------------------------------
Expand Down Expand Up @@ -85,10 +80,3 @@ PVplugins.PVSurfaceGeomechanics module

.. automodule:: PVplugins.PVSurfaceGeomechanics


PVTransferAttributesVolumeSurface plugin
--------------------------------------------------

.. automodule:: PVplugins.PVTransferAttributesVolumeSurface


32 changes: 0 additions & 32 deletions docs/geos_posp_docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@ vtk Filters

This package defines vtk filters that allows to process Geos outputs.

geos_posp.filters.AttributeMappingFromCellCoords module
--------------------------------------------------------

.. automodule:: geos_posp.filters.AttributeMappingFromCellCoords
:members:
:undoc-members:
:show-inheritance:

geos_posp.filters.AttributeMappingFromCellId module
-----------------------------------------------------------

.. automodule:: geos_posp.filters.AttributeMappingFromCellId
:members:
:undoc-members:
:show-inheritance:

geos_posp.filters.GeomechanicsCalculator module
---------------------------------------------------

Expand Down Expand Up @@ -50,19 +34,3 @@ geos_posp.filters.SurfaceGeomechanics module
:members:
:undoc-members:
:show-inheritance:

geos_posp.filters.TransferAttributesVolumeSurface module
------------------------------------------------------------

.. automodule:: geos_posp.filters.TransferAttributesVolumeSurface
:members:
:undoc-members:
:show-inheritance:

geos_posp.filters.VolumeSurfaceMeshMapper module
----------------------------------------------------

.. automodule:: geos_posp.filters.VolumeSurfaceMeshMapper
:members:
:undoc-members:
:show-inheritance:
4 changes: 4 additions & 0 deletions docs/geos_pv_docs/processing.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Post-/Pre-processing
=========================

PVAttributeMapping
--------------------

.. automodule:: geos.pv.plugins.PVAttributeMapping

PVCreateConstantAttributePerRegion
-----------------------------------
Expand Down
199 changes: 199 additions & 0 deletions geos-mesh/src/geos/mesh/processing/AttributeMapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Raphaël Vinour, Martin Lemay, Romain Baville
# ruff: noqa: E402 # disable Module level import not at top of file
import numpy as np
import numpy.typing as npt
import logging

from geos.utils.Logger import ( Logger, getLogger )
from typing_extensions import Self, Union, Set, List, Dict

from vtkmodules.vtkCommonDataModel import (
vtkDataSet,
vtkMultiBlockDataSet,
)

from geos.mesh.utils.arrayModifiers import transferAttributeWithElementMap
from geos.mesh.utils.arrayHelpers import ( computeElementMapping, getAttributeSet, isAttributeGlobal )

__doc__ = """
AttributeMapping is a vtk filter that transfers global attributes from a source mesh to a final mesh with same point/cell coordinates. The final mesh is updated directly, without creation of a copy.

Input meshes can be vtkDataSet or vtkMultiBlockDataSet.

.. Warning::
For one application of the filter, the attributes to transfer should all be located on the same piece (all on points or all on cells).

.. Note::
For cell, the coordinates of the points in the cell are compared.
If one of the two meshes is a surface and the other a volume, all the points of the surface must be points of the volume.

To use a logger handler of yours, set the variable 'speHandler' to True and add it using the member function setLoggerHandler.

To use the filter:

.. code-block:: python

from geos.mesh.processing.AttributeMapping import AttributeMapping

# Filter inputs.
meshFrom: Union[ vtkDataSet, vtkMultiBlockDataSet ]
meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ]
attributeNames: Set[ str ]
# Optional inputs.
onPoints: bool # defaults to False
speHandler: bool # defaults to False

# Instantiate the filter
filter: AttributeMapping = AttributeMapping( meshFrom,
meshTo,
attributeNames,
onPoints,
speHandler,
)

# Set the handler of yours (only if speHandler is True).
yourHandler: logging.Handler
filter.setLoggerHandler( yourHandler )

# Do calculations.
filter.applyFilter()
"""

loggerTitle: str = "Attribute Mapping"


class AttributeMapping:

def __init__(
self: Self,
meshFrom: Union[ vtkDataSet, vtkMultiBlockDataSet ],
meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ],
attributeNames: Set[ str ],
onPoints: bool = False,
speHandler: bool = False,
) -> None:
"""Transfer global attributes from a source mesh to a final mesh, mapping the piece of the attributes to transfer.

Args:
meshFrom (Union[ vtkDataSet, vtkMultiBlockDataSet ]): The source mesh with attributes to transfer.
meshTo (Union[ vtkDataSet, vtkMultiBlockDataSet ]): The final mesh where to transfer attributes.
attributeNames (Set[str]): Names of the attributes to transfer.
onPoints (bool): True if attributes are on points, False if they are on cells.
Defaults to False.
speHandler (bool, optional): True to use a specific handler, False to use the internal handler.
Defaults to False.
"""
self.meshFrom: Union[ vtkDataSet, vtkMultiBlockDataSet ] = meshFrom
self.meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ] = meshTo
self.attributeNames: Set[ str ] = attributeNames
self.onPoints: bool = onPoints
#TODO/refact (@RomainBaville) make it an enum
self.piece: str = "points" if self.onPoints else "cells"

# cell map
self.ElementMap: Dict[ int, npt.NDArray[ np.int64 ] ] = {}

# Logger.
self.logger: Logger
if not speHandler:
self.logger = getLogger( loggerTitle, True )
else:
self.logger = logging.getLogger( loggerTitle )
self.logger.setLevel( logging.INFO )

def setLoggerHandler( self: Self, handler: logging.Handler ) -> None:
"""Set a specific handler for the filter logger.

In this filter 4 log levels are use, .info, .error, .warning and .critical, be sure to have at least the same 4 levels.

Args:
handler (logging.Handler): The handler to add.
"""
if not self.logger.hasHandlers():
self.logger.addHandler( handler )
else:
self.logger.warning(
"The logger already has an handler, to use yours set the argument 'speHandler' to True during the filter initialization."
)

def getElementMap( self: Self ) -> Dict[ int, npt.NDArray[ np.int64 ] ]:
"""Getter of the element mapping dictionary.

If attribute to transfer are on points it will be a pointMap, else it will be a cellMap.

Returns:
self.elementMap (Dict[int, npt.NDArray[np.int64]]): The element mapping dictionary.
"""
return self.ElementMap

def applyFilter( self: Self ) -> bool:
"""Transfer global attributes from a source mesh to a final mesh, mapping the piece of the attributes to transfer.

Returns:
boolean (bool): True if calculation successfully ended, False otherwise.
"""
self.logger.info( f"Apply filter { self.logger.name }." )

if len( self.attributeNames ) == 0:
self.logger.warning( f"Please enter at least one { self.piece } attribute to transfer." )
self.logger.warning( f"The filter { self.logger.name } has not been used." )
return False

attributesInMeshFrom: Set[ str ] = getAttributeSet( self.meshFrom, self.onPoints )
wrongAttributeNames: Set[ str ] = self.attributeNames.difference( attributesInMeshFrom )
if len( wrongAttributeNames ) > 0:
self.logger.error(
f"The { self.piece } attributes { wrongAttributeNames } are not present in the source mesh." )
self.logger.error( f"The filter { self.logger.name } failed." )
return False

attributesInMeshTo: Set[ str ] = getAttributeSet( self.meshTo, self.onPoints )
attributesAlreadyInMeshTo: Set[ str ] = self.attributeNames.intersection( attributesInMeshTo )
if len( attributesAlreadyInMeshTo ) > 0:
self.logger.error(
f"The { self.piece } attributes { attributesAlreadyInMeshTo } are already present in the final mesh." )
self.logger.error( f"The filter { self.logger.name } failed." )
return False

if isinstance( self.meshFrom, vtkMultiBlockDataSet ):
partialAttributes: List[ str ] = []
for attributeName in self.attributeNames:
if not isAttributeGlobal( self.meshFrom, attributeName, self.onPoints ):
partialAttributes.append( attributeName )

if len( partialAttributes ) > 0:
self.logger.error(
f"All { self.piece } attributes to transfer must be global, { partialAttributes } are partials." )
self.logger.error( f"The filter { self.logger.name } failed." )

self.ElementMap = computeElementMapping( self.meshFrom, self.meshTo, self.onPoints )
sharedElement: bool = False
for key in self.ElementMap:
if np.any( self.ElementMap[ key ] > -1 ):
sharedElement = True

if not sharedElement:
self.logger.warning( f"The two meshes do not have any shared { self.piece }." )
self.logger.warning( f"The filter { self.logger.name } has not been used." )
return False

for attributeName in self.attributeNames:
if not transferAttributeWithElementMap( self.meshFrom, self.meshTo, self.ElementMap, attributeName,
self.onPoints, self.logger ):
self.logger.error( f"The attribute { attributeName } has not been mapped." )
self.logger.error( f"The filter { self.logger.name } failed." )
return False

# Log the output message.
self._logOutputMessage()

return True

def _logOutputMessage( self: Self ) -> None:
"""Create and log result messages of the filter."""
self.logger.info( f"The filter { self.logger.name } succeeded." )
self.logger.info(
f"The { self.piece } attributes { self.attributeNames } have been transferred from the source mesh to the final mesh with the { self.piece } mapping."
)
Loading