-
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
base: main
Are you sure you want to change the base?
refactor: Move PVMergeBlocksEnhanced
plugin and create the VTK filter
#129
Conversation
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.
IMO it may help to raise error and keep the old semantics of mergeBlocks()
other than that 👍
) | ||
|
||
from geos.utils.Logger import ( getLogger, Logger, logging, CountWarningHandler ) | ||
from geos.utils.Logger import getLogger, Logger, CountWarningHandler |
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
from geos.utils.Logger import getLogger, Logger, CountWarningHandler | |
from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler ) |
vtkUnstructuredGrid ) | ||
from vtkmodules.vtkFiltersCore import vtkAppendDataSets | ||
from geos.mesh.utils.arrayModifiers import fillAllPartialAttributes | ||
from geos.utils.Logger import getLogger, Logger |
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.
from geos.utils.Logger import getLogger, Logger | |
from geos.utils.Logger import ( getLogger, Logger ) |
meshMerged: vtkUnstructuredGrid | ||
if isinstance( mesh, vtkMultiBlockDataSet ): | ||
_, meshMerged = mergeBlocks( mesh ) | ||
else: | ||
meshMerged = mesh |
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.
wouldn't it be simpler if the behavior of mergeBlocks(mesh)
returned mesh
if not a vtkMultiBlockDataSet
with warning ?
|
||
# merge blocks | ||
return mergeBlocks( compositeBlock ) | ||
_, mergedBlocks = mergeBlocks( compositeBlock ) |
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.
_, mergedBlocks = mergeBlocks( compositeBlock ) | |
mergedBlocks = vtkUnstructuredGrid() | |
_, mergedBlocks = mergeBlocks( compositeBlock ) |
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.
would help typecheck (maybe)
fillPartialAttributes( serverMesh, attributeName, False ) | ||
|
||
mergedServerMesh: vtkUnstructuredGrid | ||
if isinstance( serverMesh, vtkUnstructuredGrid ): |
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.
Maybe it would be easier to return the merged mesh if composite or multiblock, the unstructured grid input if unstructured and raise an error if other case occur that you could catch here
if not inputMesh.IsA( "vtkMultiBlockDataSet" ) and not inputMesh.IsA( "vtkCompositeDataSet" ): | ||
logger.error( | ||
"The input mesh should be either a vtkMultiBlockDataSet or a vtkCompositeDataSet. Cannot proceed with the block merge." | ||
) | ||
return False, outputMesh | ||
|
||
# Fill the partial attributes with default values to keep them during the merge. | ||
if keepPartialAttributes and not fillAllPartialAttributes( inputMesh, logger ): | ||
logger.error( "Failed to fill partial attributes. Cannot proceed with the block merge." ) | ||
return False, outputMesh | ||
|
||
af: vtkAppendDataSets = vtkAppendDataSets() |
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.
Maybe raise a user define error there to avoid the Tuple
return
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.
I agree with @jafranc here, this function should only return a vtkUnstructuredGrid and raise errors when failure.
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.
As suggested by @jafranc , the mergeBlocks function needs to be reworked to raise errors which will require error handling in all the scripts using it
if not inputMesh.IsA( "vtkMultiBlockDataSet" ) and not inputMesh.IsA( "vtkCompositeDataSet" ): | ||
logger.error( | ||
"The input mesh should be either a vtkMultiBlockDataSet or a vtkCompositeDataSet. Cannot proceed with the block merge." | ||
) | ||
return False, outputMesh | ||
|
||
# Fill the partial attributes with default values to keep them during the merge. | ||
if keepPartialAttributes and not fillAllPartialAttributes( inputMesh, logger ): | ||
logger.error( "Failed to fill partial attributes. Cannot proceed with the block merge." ) | ||
return False, outputMesh | ||
|
||
af: vtkAppendDataSets = vtkAppendDataSets() |
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.
I agree with @jafranc here, this function should only return a vtkUnstructuredGrid and raise errors when failure.
|
||
success: bool | ||
outputMesh: vtkUnstructuredGrid | ||
success, outputMesh = mergeBlocks( self.inputMesh, True, self.logger ) |
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.
Following the comments made on mergeBlocks function, a try/except block can be used here to evaluate the success of the mergeBlocks function
@jafranc @alexbenedicto I changed the implementation of the |
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.
I think is we want to properly propagate the error, we should raise it where it happens mergeBlock
and deal with it where it makes most sense and where it can either be recovered from or end cleanly.
In most cases I think it is in the PV plugins, and if used outside of it, we should document the errors raised.
I'll push a commit with a proposal for this case
|
||
# merge blocks | ||
return mergeBlocks( compositeBlock ) | ||
mergedBlocks = mergeBlocks( compositeBlock ) |
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.
mergedBlocks = mergeBlocks( compositeBlock ) | |
try: | |
return mergeBlocks( compositeBlock ) | |
except TypeError: | |
raise TypeError |
Any reason to assign and return instead of simply return ?
|
||
if success: | ||
outputMesh.ShallowCopy( filter.getOutput() ) | ||
outputMesh.Modified() |
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.
outputMesh.Modified() | |
try: | |
filter.applyFilter() | |
except PPTypeError: | |
filter.logger.error("MergeBlocks fails due to TypeError") | |
else: | |
outputMesh.ShallowCopy( filter.getOutput() ) | |
outputMesh.Modified() |
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.
These last 4-5 commits are proposal on how to handle errors.
As we are dealing with vtkLogger
error that are rather registering callbacks than using handlers, there is quite a workaround throwing everything into a buffer to throw on match (here with vtkExecutive ) but could/should be improved.
This is open to comments and rewrite/extension/removal.
I also create an specific VTKError
class that is the first of specific PVPluginError
(hopefully) if go this path and chose to raise errors rather deep and catch them in RequestData()
or other high level.
…https://github.com/GEOS-DEV/geosPythonPackages into pmartinez/refactor/createMergeBlockEnhancedVTKFilter
Closes #92