Skip to content

Conversation

paloma-martinez
Copy link
Collaborator

Closes #92

Copy link
Contributor

@jafranc jafranc left a 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
Copy link
Contributor

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

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from geos.utils.Logger import getLogger, Logger
from geos.utils.Logger import ( getLogger, Logger )

Comment on lines 802 to 806
meshMerged: vtkUnstructuredGrid
if isinstance( mesh, vtkMultiBlockDataSet ):
_, meshMerged = mergeBlocks( mesh )
else:
meshMerged = mesh
Copy link
Contributor

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 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, mergedBlocks = mergeBlocks( compositeBlock )
mergedBlocks = vtkUnstructuredGrid()
_, mergedBlocks = mergeBlocks( compositeBlock )

Copy link
Contributor

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 ):
Copy link
Contributor

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

Comment on lines 45 to 56
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()
Copy link
Contributor

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

Copy link
Collaborator

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.

Copy link
Collaborator

@alexbenedicto alexbenedicto left a 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

Comment on lines 45 to 56
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()
Copy link
Collaborator

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 )
Copy link
Collaborator

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

@paloma-martinez
Copy link
Collaborator Author

@jafranc @alexbenedicto I changed the implementation of the mergeBlocks function, now it should either return the input mesh if it is already a single block, or VTK filters called should raise errors that will be caught by the MergeBlockEnhanced filter

Copy link
Contributor

@jafranc jafranc left a 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 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outputMesh.Modified()
try:
filter.applyFilter()
except PPTypeError:
filter.logger.error("MergeBlocks fails due to TypeError")
else:
outputMesh.ShallowCopy( filter.getOutput() )
outputMesh.Modified()

Copy link
Contributor

@jafranc jafranc left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create vtk filter from PVMergeBlocksEnhanced in geos-mesh and move PV plugin to geos-pv

4 participants