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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
center: float = mohrCircle.getCircleCenter()
"""

loggerTitle : str = "MohrCircle"

class MohrCircle:

Expand Down
22 changes: 11 additions & 11 deletions geos-mesh/src/geos/mesh/utils/arrayModifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def fillPartialAttributes(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "fillPartialAttributes", True )
logger = getLogger( "fillPartialAttributes")

# Check if the input mesh is inherited from vtkMultiBlockDataSet.
if not isinstance( multiBlockDataSet, vtkMultiBlockDataSet ):
Expand Down Expand Up @@ -178,7 +178,7 @@ def fillAllPartialAttributes(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "fillAllPartialAttributes", True )
logger = getLogger( "fillAllPartialAttributes")

logger.warning(
"The filling value for the attributes is depending of the type of attribute's data:\n0 for uint data,\n-1 for int data,\nnan for float data."
Expand Down Expand Up @@ -260,7 +260,7 @@ def createConstantAttribute(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "createConstantAttribute", True )
logger = getLogger( "createConstantAttribute")

# Deals with multiBlocksDataSets.
if isinstance( mesh, ( vtkMultiBlockDataSet, vtkCompositeDataSet ) ):
Expand Down Expand Up @@ -307,7 +307,7 @@ def createConstantAttributeMultiBlock(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "createConstantAttributeMultiBlock", True )
logger = getLogger( "createConstantAttributeMultiBlock")

# Check if the input mesh is inherited from vtkMultiBlockDataSet.
if not isinstance( multiBlockDataSet, vtkMultiBlockDataSet ):
Expand Down Expand Up @@ -376,7 +376,7 @@ def createConstantAttributeDataSet(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "createConstantAttributeDataSet", True )
logger = getLogger( "createConstantAttributeDataSet")

# Check if all the values of listValues have the same type.
valueType: type = type( listValues[ 0 ] )
Expand Down Expand Up @@ -458,7 +458,7 @@ def createAttribute(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "createAttribute", True )
logger = getLogger( "createAttribute")

# Check if the input mesh is inherited from vtkDataSet.
if not isinstance( dataSet, vtkDataSet ):
Expand Down Expand Up @@ -568,7 +568,7 @@ def copyAttribute(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "copyAttribute", True )
logger = getLogger( "copyAttribute")

# Check if the multiBlockDataSetFrom is inherited from vtkMultiBlockDataSet.
if not isinstance( multiBlockDataSetFrom, vtkMultiBlockDataSet ):
Expand Down Expand Up @@ -650,7 +650,7 @@ def copyAttributeDataSet(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "copyAttributeDataSet", True )
logger = getLogger( "copyAttributeDataSet")

# Check if the dataSetFrom is inherited from vtkDataSet.
if not isinstance( dataSetFrom, vtkDataSet ):
Expand Down Expand Up @@ -724,7 +724,7 @@ def transferAttributeToDataSetWithElementMap(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "transferAttributeToDataSetWithElementMap", True )
logger = getLogger( "transferAttributeToDataSetWithElementMap")

if flatIdDataSetTo not in elementMap:
logger.error( f"The map is incomplete, there is no data for the final mesh (flat index { flatIdDataSetTo })." )
Expand Down Expand Up @@ -825,8 +825,8 @@ def transferAttributeWithElementMap(
bool: True if transfer successfully ended.
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "transferAttributeWithElementMap", True )
if logger is None:#
logger = getLogger( "transferAttributeWithElementMap")

if isinstance( meshTo, vtkDataSet ):
return transferAttributeToDataSetWithElementMap( meshFrom,
Expand Down
2 changes: 1 addition & 1 deletion geos-mesh/src/geos/mesh/utils/genericHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def computeSurfaceTextureCoordinates(
# Need to compute texture coordinates required for tangent calculation
vtkErrorLogger: Logger
if logger is None:
vtkErrorLogger = getLogger( "Compute Surface Texture Coordinates vtkError Logger", True )
vtkErrorLogger = getLogger( "Compute Surface Texture Coordinates vtkError Logger")
else:
vtkErrorLogger = logging.getLogger( f"{ logger.name } vtkError Logger" )
vtkErrorLogger.setLevel( logging.INFO )
Expand Down
1 change: 1 addition & 0 deletions geos-processing/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ maintainers = [
{name = "Alexandre Benedicto", email = "[email protected]" },
{name = "Romain Baville", email = "[email protected]" },
{name = "Paloma Martinez", email = "[email protected]" },
{name = "Jacques Franc", email = "[email protected]" },
]
license = {text = "Apache-2.0"}
classifiers = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# ruff: noqa: E402 # disable Module level import not at top of file
import numpy as np
import numpy.typing as npt
import logging
from typing_extensions import Self, Union
from vtkmodules.vtkCommonDataModel import vtkDataSet, vtkMultiBlockDataSet
from geos.mesh.utils.arrayModifiers import transferAttributeWithElementMap
Expand Down Expand Up @@ -41,21 +40,15 @@
attributeNames: set[ str ]
# Optional inputs.
onPoints: bool # defaults to False
speHandler: bool # defaults to False

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

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

# Do calculations.
attributeMappingFilter.applyFilter()
"""
Expand All @@ -71,7 +64,6 @@ def __init__(
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.

Expand All @@ -97,27 +89,7 @@ def __init__(
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." )
self.logger: Logger = getLogger( loggerTitle )

def getElementMap( self: Self ) -> dict[ int, npt.NDArray[ np.int64 ] ]:
"""Getter of the element mapping dictionary.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache 2.0
# SPDX-FileCopyrightText: Copyright 2023-2025 TotalEnergies
# SPDX-FileContributor: Jacques Franc
import logging

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -218,7 +217,7 @@ def __getFramePoints( self, vpts: vtkPoints ) -> tuple[ vtkPoints, vtkPoints ]:
class ClipToMainFrame( vtkTransformFilter ):
"""Filter to clip a mesh to the main frame using ClipToMainFrame class."""

def __init__( self, speHandler: bool = False, **properties: str ) -> None:
def __init__( self, **properties: str ) -> None:
"""Initialize the ClipToMainFrame Filter with optional speHandler args and forwarding properties to main class.

Args:
Expand All @@ -228,12 +227,7 @@ def __init__( self, speHandler: bool = False, **properties: str ) -> None:
"""
super().__init__( **properties )
# Logger.
self.logger: Logger
if not speHandler:
self.logger = getLogger( loggerTitle, True )
else:
self.logger = logging.getLogger( loggerTitle )
self.logger.setLevel( logging.INFO )
self.logger: Logger = getLogger( loggerTitle )

def ComputeTransform( self ) -> None:
"""Update the transformation."""
Expand All @@ -254,21 +248,7 @@ def ComputeTransform( self ) -> None:

clip.Update()
self.SetTransform( clip )

def SetLoggerHandler( 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." )
self.logger.info( f"{self.logger.name} applied successfully." )

def __locate_reference_point( self, multiBlockDataSet: vtkMultiBlockDataSet ) -> int:
"""Locate the block to use as reference for the transformation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
valueNpType: type
nbComponents: int
componentNames: tuple[ str, ... ]
speHandler: bool

# Instantiate the filter
createConstantAttributePerRegionFilter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
Expand All @@ -61,7 +60,6 @@
valueNpType,
nbComponents,
componentNames,
speHandler,
)

# Set your handler (only if speHandler is True).
Expand All @@ -86,7 +84,6 @@ def __init__(
valueNpType: type = np.float32,
nbComponents: int = 1,
componentNames: tuple[ str, ...] = (), # noqa: C408
speHandler: bool = False,
) -> None:
"""Create an attribute with constant value per region.

Expand Down Expand Up @@ -123,33 +120,13 @@ def __init__(
# Check if the new component have default values (information for the output message).
self.useDefaultValue: bool = False

# Warnings counter.
self.counter: CountWarningHandler = CountWarningHandler()
self.counter.setLevel( logging.INFO )

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

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:
# This warning does not count for the number of warning created during the application of the filter.
self.logger.warning( "The logger already has an handler, to use yours set the argument 'speHandler' to True"
" during the filter initialization." )
self.counter: CountWarningHandler = CountWarningHandler()
self.counter.setLevel( logging.INFO )
# Add the handler to count warnings messages.
self.logger.addHandler( self.counter )

def applyFilter( self: Self ) -> bool:
"""Create a constant attribute per region in the mesh.
Expand All @@ -159,9 +136,6 @@ def applyFilter( self: Self ) -> bool:
"""
self.logger.info( f"Apply filter { self.logger.name }." )

# Add the handler to count warnings messages.
self.logger.addHandler( self.counter )

# Check the validity of the attribute region.
if self.onPoints is None:
self.logger.error( f"{ self.regionName } is not in the mesh." )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from typing_extensions import Self
from typing import Union, Any

from geos.utils.Logger import logging, Logger, getLogger
from geos.utils.Logger import getLogger
from geos.mesh.utils.arrayModifiers import fillPartialAttributes
from geos.mesh.utils.arrayHelpers import getAttributePieceInfo

# from geos.utils.details import addLogSupport
from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet

__doc__ = """
Expand Down Expand Up @@ -61,7 +62,6 @@ def __init__(
self: Self,
multiBlockDataSet: vtkMultiBlockDataSet,
dictAttributesValues: dict[ str, Union[ list[ Any ], None ] ],
speHandler: bool = False,
) -> None:
"""Fill partial attributes with constant value per component.

Expand All @@ -74,37 +74,12 @@ def __init__(

Args:
multiBlockDataSet (vtkMultiBlockDataSet): The mesh where to fill the attribute.
dictAttributesValues (dict[str, Any]): The dictionary with the attribute to fill as keys
and the list of filling values as values.
speHandler (bool, optional): True to use a specific handler, False to use the internal handler.
Defaults to False.
dictAttributesValues (dict[str, Any]): The dictionary with the attribute to fill as keys and the list of filling values as items.
"""
self.logger = getLogger( loggerTitle )
self.multiBlockDataSet: vtkMultiBlockDataSet = multiBlockDataSet
self.dictAttributesValues: dict[ str, Union[ list[ Any ], None ] ] = dictAttributesValues

# 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:
"""Create a constant attribute per region in the mesh.

Expand Down
Loading