Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
565 changes: 323 additions & 242 deletions geos-mesh/src/geos/mesh/utils/arrayModifiers.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions geos-mesh/src/geos/mesh/utils/multiblockModifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def mergeBlocks(
vtkErrorLogger.addFilter( RegexExceptionFilter() ) # will raise VTKError if captured VTK Error

# Fill the partial attributes with default values to keep them during the merge.
if keepPartialAttributes and not fillAllPartialAttributes( inputMesh, logger ):
raise ValueError( "Failed to fill partial attributes. Merging without keeping partial attributes." )
if keepPartialAttributes:
fillAllPartialAttributes( inputMesh, logger )

outputMesh: vtkUnstructuredGrid

Expand Down
335 changes: 315 additions & 20 deletions geos-mesh/tests/test_arrayModifiers.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ def applyFilter( self: Self ) -> None:
raise ValueError( f"The two meshes do not have any shared { self.piece }." )

for attributeName in self.attributeNames:
# TODO:: Modify arrayModifiers function to raise error.
if not transferAttributeWithElementMap( self.meshFrom, self.meshTo, self.ElementMap, attributeName,
self.onPoints, self.logger ):
raise ValueError( f"Fail to transfer the attribute { attributeName }." )
transferAttributeWithElementMap( self.meshFrom, self.meshTo, self.ElementMap, attributeName, self.onPoints,
self.logger )

# Log the output message.
self._logOutputMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def applyFilter( self: Self ) -> None:
"""Create a constant attribute per region in the mesh.

Raises:
ValueError: Errors with the input value for the region index or errors during the creation of the new attribute.
ValueError: Errors with the input value for the region index.
AttributeError: Errors with the attribute of the mesh.
"""
self.logger.info( f"Apply filter { self.logger.name }." )
Expand Down Expand Up @@ -204,14 +204,12 @@ def applyFilter( self: Self ) -> None:
self.logger.warning(
f"The region indexes entered are not in the region attribute { self.regionName }." )

if not createConstantAttributeMultiBlock( self.mesh,
self.defaultValue,
self.newAttributeName,
componentNames=self.componentNames,
onPoints=self.onPoints,
logger=self.logger ):
raise ValueError(
f"Something went wrong with the creation of the attribute { self.newAttributeName }." )
createConstantAttributeMultiBlock( self.mesh,
self.defaultValue,
self.newAttributeName,
componentNames=self.componentNames,
onPoints=self.onPoints,
logger=self.logger )

else:
if len( invalidIndexes ) > 0:
Expand All @@ -225,14 +223,12 @@ def applyFilter( self: Self ) -> None:

regionArray = getArrayInObject( dataSet, self.regionName, self.onPoints )
newArray = self._createArrayFromRegionArrayWithValueMap( regionArray )
if not createAttribute( dataSet,
newArray,
self.newAttributeName,
componentNames=self.componentNames,
onPoints=self.onPoints,
logger=self.logger ):
raise ValueError(
f"Something went wrong with the creation of the attribute { self.newAttributeName }." )
createAttribute( dataSet,
newArray,
self.newAttributeName,
componentNames=self.componentNames,
onPoints=self.onPoints,
logger=self.logger )

else:
validIndexes, invalidIndexes = checkValidValuesInDataSet( self.mesh, self.regionName, listIndexes,
Expand All @@ -244,14 +240,12 @@ def applyFilter( self: Self ) -> None:
self.logger.warning(
f"The region indexes entered are not in the region attribute { self.regionName }." )

if not createConstantAttributeDataSet( self.mesh,
self.defaultValue,
self.newAttributeName,
componentNames=self.componentNames,
onPoints=self.onPoints,
logger=self.logger ):
raise ValueError(
f"Something went wrong with the creation of the attribute { self.newAttributeName }." )
createConstantAttributeDataSet( self.mesh,
self.defaultValue,
self.newAttributeName,
componentNames=self.componentNames,
onPoints=self.onPoints,
logger=self.logger )

else:
if len( invalidIndexes ) > 0:
Expand All @@ -260,14 +254,12 @@ def applyFilter( self: Self ) -> None:

regionArray = getArrayInObject( self.mesh, self.regionName, self.onPoints )
newArray = self._createArrayFromRegionArrayWithValueMap( regionArray )
if not createAttribute( self.mesh,
newArray,
self.newAttributeName,
componentNames=self.componentNames,
onPoints=self.onPoints,
logger=self.logger ):
raise ValueError(
f"Something went wrong with the creation of the attribute { self.newAttributeName }." )
createAttribute( self.mesh,
newArray,
self.newAttributeName,
componentNames=self.componentNames,
onPoints=self.onPoints,
logger=self.logger )

# Log the output message.
self._logOutputMessage( validIndexes )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ def applyFilter( self: Self ) -> None:
f"There is two attribute named { attributeName }, one on points and the other on cells. The attribute name must be unique."
)

if not fillPartialAttributes( self.multiBlockDataSet,
attributeName,
onPoints=onPoints,
listValues=self.dictAttributesValues[ attributeName ],
logger=self.logger ):
raise ValueError( "Something went wrong with the filling of partial attributes" )
fillPartialAttributes( self.multiBlockDataSet,
attributeName,
onPoints=onPoints,
listValues=self.dictAttributesValues[ attributeName ],
logger=self.logger )

self.logger.info( f"The filter { self.logger.name } succeed." )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,10 @@ def applyFilter( self: Self ) -> None:
logger=self.logger )

# Create index attribute keeping the index in initial mesh
if not createConstantAttribute( volumeMesh, [ blockIndex ],
PostProcessingOutputsEnum.BLOCK_INDEX.attributeName,
onPoints=False,
logger=self.logger ):
raise ValueError(
f"Something went wrong during the creation of the attribute { PostProcessingOutputsEnum.BLOCK_INDEX.attributeName }."
)
createConstantAttribute( volumeMesh, [ blockIndex ],
PostProcessingOutputsEnum.BLOCK_INDEX.attributeName,
onPoints=False,
logger=self.logger )

# Rename attributes
self.renameAttributes( volumeMesh )
Expand Down Expand Up @@ -207,9 +204,9 @@ def renameAttributes(
if suffix == "_density":
for phaseName in self.phaseNameDict[ PhaseTypeEnum.ROCK.type ]:
if phaseName in attributeName:
renameAttribute( mesh, attributeName, newName, False )
renameAttribute( mesh, attributeName, newName, False, logger=self.logger )
else:
renameAttribute( mesh, attributeName, newName, False )
renameAttribute( mesh, attributeName, newName, False, logger=self.logger )

return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,14 @@ def convertAttributesFromLocalToXYZBasis( self: Self ) -> None:
arrayXYZ: npt.NDArray[ np.float64 ] = self.__computeXYZCoordinates( localArray )

# Create converted attribute array in dataset
if createAttribute( self.outputMesh,
arrayXYZ,
attrNameXYZ,
ComponentNameEnum.XYZ.value,
onPoints=self.attributeOnPoints,
logger=self.logger ):
self.logger.info( f"Attribute {attrNameXYZ} added to the output mesh." )
self.newAttributeNames.add( attrNameXYZ )
else:
raise ValueError( f"Something went wrong during the creation of the attribute { attrNameXYZ }." )
createAttribute( self.outputMesh,
arrayXYZ,
attrNameXYZ,
ComponentNameEnum.XYZ.value,
onPoints=self.attributeOnPoints,
logger=self.logger )
self.logger.info( f"Attribute {attrNameXYZ} added to the output mesh." )
self.newAttributeNames.add( attrNameXYZ )

return

Expand Down Expand Up @@ -386,12 +384,13 @@ def computeShearCapacityUtilization( self: Self ) -> None:
self.frictionAngle )

# Create attribute
if not createAttribute(
self.outputMesh, scuAttribute, SCUAttributeName, (), self.attributeOnPoints, logger=self.logger ):
raise ValueError( f"Failed to create attribute {SCUAttributeName}." )
else:
self.logger.info( "SCU computed and added to the output mesh." )
self.newAttributeNames.add( SCUAttributeName )
createAttribute( self.outputMesh,
scuAttribute,
SCUAttributeName, (),
self.attributeOnPoints,
logger=self.logger )
self.logger.info( "SCU computed and added to the output mesh." )
self.newAttributeNames.add( SCUAttributeName )

return

Expand Down
52 changes: 18 additions & 34 deletions geos-processing/tests/test_CreateConstantAttributePerRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,80 +103,64 @@ def test_CreateConstantAttributePerRegion(


@pytest.mark.parametrize(
"meshType, newAttributeName, regionName, dictRegionValues, componentNames, componentNamesTest, valueNpType",
"meshType, newAttributeName, regionName",
[
( "dataset", "newAttribute", "PERM", {}, (), (), np.float32 ), # Region attribute has too many components
( "multiblock", "newAttribute", "FAULT", {}, (), (), np.float32 ), # Region attribute is partial.
( "dataset", "newAttribute", "PERM" ), # Region attribute has too many components
( "multiblock", "newAttribute", "FAULT" ), # Region attribute is partial.
( "dataset", "PERM", "FAULT" ), # The attribute name already exist in the mesh.
] )
def test_CreateConstantAttributePerRegionRaisesAttributeError(
dataSetTest: Union[ vtkMultiBlockDataSet, vtkDataSet ],
meshType: str,
newAttributeName: str,
regionName: str,
dictRegionValues: dict[ Any, Any ],
componentNames: tuple[ str, ...],
componentNamesTest: tuple[ str, ...],
valueNpType: int,
) -> None:
"""Test tes fails of CreateConstantAttributePerRegion with attributes issues."""
"""Test the fails of CreateConstantAttributePerRegion with attributes issues."""
mesh: Union[ vtkMultiBlockDataSet, vtkDataSet ] = dataSetTest( meshType )
nbComponents: int = len( componentNamesTest )
if nbComponents == 0: # If the attribute has one component, the component has no name.
nbComponents += 1

createConstantAttributePerRegionFilter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
mesh,
regionName,
dictRegionValues,
{},
newAttributeName,
valueNpType=valueNpType,
nbComponents=nbComponents,
componentNames=componentNames,
)

with pytest.raises( AttributeError ):
createConstantAttributePerRegionFilter.applyFilter()


@pytest.mark.parametrize(
"meshType, newAttributeName, regionName, dictRegionValues, componentNames, componentNamesTest, valueNpType",
"dictRegionValues, componentNames",
[
( "dataset", "newAttribute", "FAULT", {
( {
0: [ 0 ],
100: [ 1, 1 ],
}, (), (), np.float32 ), # Number of value inconsistent.
( "dataset", "newAttribute", "FAULT", {
}, () ), # Number of value inconsistent.
( {
0: [ 0, 0 ],
100: [ 1, 1 ],
}, (), (), np.float32 ), # More values than components.
( "dataset", "newAttribute", "FAULT", {
}, () ), # More values than components.
( {
0: [ 0 ],
100: [ 1 ],
}, ( "X", "Y" ), ( "X", "Y" ), np.float32 ), # More components than value.
( "dataset", "PERM", "FAULT", {}, (), (), np.float32 ), # The attribute name already exist in the mesh.
}, ( "X", "Y" ) ), # More components than value.
] )
def test_CreateConstantAttributePerRegionRaisesValueError(
dataSetTest: Union[ vtkMultiBlockDataSet, vtkDataSet ],
meshType: str,
newAttributeName: str,
regionName: str,
dataSetTest: vtkDataSet,
dictRegionValues: dict[ Any, Any ],
componentNames: tuple[ str, ...],
componentNamesTest: tuple[ str, ...],
valueNpType: int,
) -> None:
"""Test the fails of CreateConstantAttributePerRegion with inputs value issues."""
mesh: Union[ vtkMultiBlockDataSet, vtkDataSet ] = dataSetTest( meshType )
nbComponents: int = len( componentNamesTest )
mesh: vtkDataSet = dataSetTest( 'dataset' )
nbComponents: int = len( componentNames )
if nbComponents == 0: # If the attribute has one component, the component has no name.
nbComponents += 1

createConstantAttributePerRegionFilter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
mesh,
regionName,
"FAULT",
dictRegionValues,
newAttributeName,
valueNpType=valueNpType,
"newAttribute",
nbComponents=nbComponents,
componentNames=componentNames,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ def RequestData(

# Create elementCenter attribute in the volume mesh if needed
cellCenterAttributeName: str = GeosMeshOutputsEnum.ELEMENT_CENTER.attributeName
createCellCenterAttribute( outputCells, cellCenterAttributeName )
if cellCenterAttributeName not in meshAttributes:
createCellCenterAttribute( outputCells, cellCenterAttributeName, logger=self.logger )

# Stop the time step iteration
request.Remove( executive.CONTINUE_EXECUTING() )
Expand Down
12 changes: 5 additions & 7 deletions mesh-doctor/src/geos/mesh_doctor/actions/generateCube.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,11 @@ def addFields( mesh: vtkUnstructuredGrid, fields: Iterable[ FieldInfo ] ) -> vtk
# Create list of values (all 1.0) for each component
listValues = [ 1.0 ] * fieldInfo.dimension
# Use the robust createConstantAttributeDataSet function
success = createConstantAttributeDataSet( dataSet=mesh,
listValues=listValues,
attributeName=fieldInfo.name,
onPoints=onPoints,
logger=setupLogger )
if not success:
setupLogger.warning( f"Failed to create field {fieldInfo.name}" )
createConstantAttributeDataSet( dataSet=mesh,
listValues=listValues,
attributeName=fieldInfo.name,
onPoints=onPoints,
logger=setupLogger )
return mesh


Expand Down