-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Move PVMergeBlocksEnhanced plugin and create the VTK filter
#129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexbenedicto
merged 41 commits into
main
from
pmartinez/refactor/createMergeBlockEnhancedVTKFilter
Oct 17, 2025
Merged
Changes from 14 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
06eca95
Modify isAttributeGlobal function to take into account recursive mult…
paloma-martinez 8651018
Add bool output to mergeBlocks function for better logging and error …
paloma-martinez fbe6bf2
Adding a VTK filter for enhanced merge block
paloma-martinez b9855ce
Move and update plugin
paloma-martinez 21d8b7d
Merge branch 'main' into pmartinez/refactor/createMergeBlockEnhancedV…
paloma-martinez 54c70eb
Clean
paloma-martinez 2de326a
Fix import format
paloma-martinez 3d20b99
Typing
paloma-martinez 22828f7
Adding tests and data for test for merge blocks
paloma-martinez 29a038b
Documentation
paloma-martinez 3d153cd
Yapf
paloma-martinez af3990e
Yapf again
paloma-martinez d9f289d
Yapf
paloma-martinez 14bcb85
Fix docstring and typing
paloma-martinez 05a1c17
Fix from Romain review
paloma-martinez df24923
Merge branch 'main' into pmartinez/refactor/createMergeBlockEnhancedV…
paloma-martinez f771dd6
Modification of mergeBlocks function following review's comment
paloma-martinez 4d9c3d0
Merge branch 'main' into pmartinez/refactor/createMergeBlockEnhancedV…
paloma-martinez b3112f9
yapf
paloma-martinez b1b681b
bad merge fix
paloma-martinez 682f50e
first error handling version
jafranc 7da34e9
adding Fails test
jafranc 43dd2d1
First completed attempt to capture errors from VTK
jafranc 396ed11
last fixes
jafranc e0ab6fc
ruff + yapf
jafranc ba9e2b1
yapf tests
jafranc f8d2b1a
Update python-package.yml as order might matters
jafranc b8b1481
clean up
jafranc cd48656
Merge branch 'pmartinez/refactor/createMergeBlockEnhancedVTKFilter' o…
jafranc b839532
CI is testing vtk9.5.1 so skip the failing test for now
jafranc 262932a
mypy and yapf
jafranc b98b49e
wrong version dispatch
jafranc 073f4cd
Clean and formatting
paloma-martinez 3d0c57c
Merge branch 'main' into pmartinez/refactor/createMergeBlockEnhancedV…
paloma-martinez 3a7b061
bad merge
paloma-martinez 907b2d6
Force int type to avoid errors
alexbenedicto 24a8d27
Add comments to new Logger functionalities
alexbenedicto f9b5cf0
Correct invalid pattern
alexbenedicto df766cd
Fix error in doc
alexbenedicto d572700
Fix ruff error
alexbenedicto 18b13f7
Add child logger to prevent to much verbosity in parent logger
paloma-martinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
geos-mesh/src/geos/mesh/processing/MergeBlockEnhanced.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies. | ||
| # SPDX-FileContributor: Paloma Martinez | ||
| # ruff: noqa: E402 # disable Module level import not at top of file | ||
| import logging | ||
|
|
||
| from typing import Union | ||
| from typing_extensions import Self | ||
|
|
||
| from geos.utils.Logger import Logger, getLogger | ||
| from geos.mesh.utils.multiblockModifiers import mergeBlocks | ||
|
|
||
| from vtkmodules.vtkCommonDataModel import ( | ||
| vtkCompositeDataSet, | ||
| vtkMultiBlockDataSet, | ||
| vtkUnstructuredGrid, | ||
| ) | ||
|
|
||
| __doc__ = """ | ||
| Merge Blocks Keeping Partial Attributes is a filter that allows to merge blocks from a multiblock dataset while keeping partial attributes. | ||
| Input is a vtkMultiBlockDataSet and output is a vtkUnstructuredGrid. | ||
| .. Note:: | ||
| - You may encounter issues if two datasets of the input multiblock dataset have duplicated cell IDs. | ||
| - Partial attributes are filled with default values depending on their types. | ||
| - 0 for uint data. | ||
| - -1 for int data. | ||
| - nan for float data. | ||
| To use it: | ||
| .. code-block:: python | ||
| from geos.mesh.processing.MergeBlockEnhanced import MergeBlockEnhanced | ||
| # Define filter inputs | ||
| multiblockdataset: vtkMultiblockDataSet | ||
| speHandler: bool # optional | ||
| # Instantiate the filter | ||
| filter: MergeBlockEnhanced = MergeBlockEnhanced( multiblockdataset, speHandler ) | ||
| # Use your own handler (if speHandler is True) | ||
| yourHandler: logging.Handler | ||
| filter.addLoggerHandler( yourHandler ) | ||
RomainBaville marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Do calculations | ||
| filter.applyFilter() | ||
| # Get the merged mesh | ||
| filter.getOutput() | ||
| """ | ||
|
|
||
| loggerTitle: str = "Merge Block Enhanced" | ||
|
|
||
|
|
||
| class MergeBlockEnhanced: | ||
|
|
||
| def __init__( | ||
| self: Self, | ||
| inputMesh: vtkMultiBlockDataSet, | ||
| speHandler: bool = False, | ||
| ) -> None: | ||
| """Merge a multiblock dataset and keep the partial attributes in the output mesh. | ||
| Partial attributes are filled with default values depending on the data type such that: | ||
| - 0 for uint data. | ||
| - -1 for int data. | ||
| - nan for float data. | ||
| Args: | ||
| inputMesh (vtkMultiBlockDataSet): The input multiblock dataset to merge. | ||
| speHandler (bool, optional) : True to use a specific handler, False to use the internal handler. | ||
| Defaults to False. | ||
| """ | ||
| self.inputMesh: vtkMultiBlockDataSet = inputMesh | ||
| self.outputMesh: vtkUnstructuredGrid = vtkUnstructuredGrid() | ||
|
|
||
| # 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 applyFilter( self: Self ) -> bool: | ||
| """Merge the blocks of a multiblock dataset mesh. | ||
jafranc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Returns: | ||
| bool: True if the blocks were successfully merged, False otherwise. | ||
| """ | ||
| self.logger.info( f"Applying filter { self.logger.name }." ) | ||
|
|
||
| if not isinstance( self.inputMesh, vtkCompositeDataSet ) or not isinstance( self.inputMesh, | ||
| vtkMultiBlockDataSet ): | ||
| self.logger.error( | ||
| f"Expected a vtkMultiblockdataset or vtkCompositeDataSet, Got a {type(self.inputMesh)} \n The filter { self.logger.name } failed." | ||
| ) | ||
| return False | ||
|
|
||
| success: bool | ||
| outputMesh: Union[ vtkUnstructuredGrid, vtkMultiBlockDataSet, vtkCompositeDataSet ] | ||
RomainBaville marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| success, outputMesh = mergeBlocks( self.inputMesh, True, self.logger ) | ||
|
||
|
|
||
| if not success: | ||
| self.logger.error( f"The filter {self.logger.name} failed." ) | ||
| return False | ||
|
|
||
| else: | ||
| self.logger.info( f"The filter { self.logger.name } succeeded." ) | ||
| self.outputMesh = outputMesh | ||
| return True | ||
|
|
||
| def getOutput( self: Self ) -> vtkUnstructuredGrid: | ||
| """Get the merged mesh. | ||
| Returns: | ||
| vtkUnstructuredGrid: The merged mesh. | ||
| """ | ||
| return self.outputMesh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,45 +1,74 @@ | ||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||
| # SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies. | ||||||
| # SPDX-FileContributor: Martin Lemay | ||||||
| # SPDX-FileContributor: Martin Lemay, Paloma Martinez | ||||||
| from typing import Union | ||||||
| from vtkmodules.vtkCommonDataModel import ( vtkCompositeDataSet, vtkDataObjectTreeIterator, vtkMultiBlockDataSet, | ||||||
| vtkUnstructuredGrid ) | ||||||
| from vtkmodules.vtkFiltersCore import vtkAppendDataSets | ||||||
| from geos.mesh.utils.arrayModifiers import fillAllPartialAttributes | ||||||
| from geos.utils.Logger import getLogger, Logger | ||||||
|
||||||
| from geos.utils.Logger import getLogger, Logger | |
| from geos.utils.Logger import ( getLogger, Logger ) |
jafranc marked this conversation as resolved.
Show resolved
Hide resolved
jafranc marked this conversation as resolved.
Show resolved
Hide resolved
RomainBaville marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
RomainBaville marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
RomainBaville marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
RomainBaville marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0"?> | ||
| <VTKFile type="vtkMultiBlockDataSet" version="1.0"> | ||
| <vtkMultiBlockDataSet> | ||
| <Block name="cartesianMesh"> | ||
| <Block name="Level0"> | ||
| <Block name="CellElementRegion"> | ||
| <Block name="reservoir"> | ||
| <DataSet name="rank_0" file="simpleReservoirViz_small_000478/cartesianMesh/Level0/reservoir/rank_0.vtu" /> | ||
| <DataSet name="rank_1" file="simpleReservoirViz_small_000478/cartesianMesh/Level0/reservoir/rank_1.vtu" /> | ||
| </Block> | ||
| </Block> | ||
| <Block name="WellElementRegion"> | ||
| <Block name="wellRegion"> | ||
| <DataSet name="rank_1" file="simpleReservoirViz_small_000478/cartesianMesh/Level0/wellRegion/rank_1.vtu" /> | ||
| </Block> | ||
| </Block> | ||
| </Block> | ||
| </Block> | ||
| </vtkMultiBlockDataSet> | ||
| </VTKFile> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep parenthesis when doing multiple import other than standard