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
14 changes: 7 additions & 7 deletions geos-mesh/src/geos/mesh/utils/arrayModifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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 @@ -161,7 +161,7 @@ def fillAllPartialAttributes(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "fillAllPartialAttributes", True )
logger = getLogger( "fillAllPartialAttributes")

# Check if the input mesh is inherited from vtkMultiBlockDataSet.
if not isinstance( multiBlockDataSet, vtkMultiBlockDataSet ):
Expand Down Expand Up @@ -252,7 +252,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 @@ -353,7 +353,7 @@ def createAttribute(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "createAttribute", True )
logger = getLogger( "createAttribute")

# Check the piece.
if piece not in [ Piece.POINTS, Piece.CELLS ]:
Expand Down Expand Up @@ -458,7 +458,7 @@ def copyAttribute(
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "copyAttribute", True )
logger = getLogger( "copyAttribute")

if isinstance( meshTo, vtkDataSet ) and isinstance( meshFrom, vtkDataSet ):
# Small check to check if the two meshes are similar.
Expand Down Expand Up @@ -578,8 +578,8 @@ def transferAttributeWithElementMap(
AttributeError: Error with the attribute attributeName.
"""
# Check if an external logger is given.
if logger is None:
logger = getLogger( "transferAttributeWithElementMap", True )
if logger is None:#
logger = getLogger( "transferAttributeWithElementMap")

# Check the piece.
if piece not in [ Piece.POINTS, Piece.CELLS ]:
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 = "alexandre.benedicto@external.totalenergies.com" },
{name = "Romain Baville", email = "romain.baville@external.totalenergies.com" },
{name = "Paloma Martinez", email = "paloma.martinez@external.totalenergies.com" },
{name = "Jacques Franc", email = "jacques.franc@external.totalenergies.com" },
]
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 @@ -43,21 +42,15 @@
attributeNames: set[ str ]
# Optional inputs.
piece: Piece # defaults to Piece.CELLS
speHandler: bool # defaults to False

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

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

# Do calculations.
try:
attributeMappingFilter.applyFilter()
Expand All @@ -79,7 +72,6 @@ def __init__(
meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ],
attributeNames: set[ str ],
piece: Piece = Piece.CELLS,
speHandler: bool = False,
) -> None:
"""Transfer global attributes from a source mesh to a final mesh.

Expand All @@ -102,40 +94,8 @@ def __init__(
# Element map
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 )
self.logger.propagate = False

counter: CountVerbosityHandler = CountVerbosityHandler()
self.counter: CountVerbosityHandler
self.nbWarnings: int = 0
try:
self.counter = getLoggerHandlerType( type( counter ), self.logger )
self.counter.resetWarningCount()
except ValueError:
self.counter = counter
self.counter.setLevel( logging.INFO )

self.logger.addHandler( self.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 isHandlerInLogger( handler, self.logger ):
self.logger.addHandler( handler )
else:
self.logger.warning( "The logger already has this handler, it has not been added." )
# Logger.
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 @@ -227,41 +226,8 @@ def __init__( self, speHandler: bool = False, **properties: str ) -> None:
properties (kwargs): kwargs forwarded to vtkTransformFilter.
"""
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.propagate = False

counter: CountVerbosityHandler = CountVerbosityHandler()
self.counter: CountVerbosityHandler
self.nbWarnings: int = 0
try:
self.counter = getLoggerHandlerType( type( counter ), self.logger )
self.counter.resetWarningCount()
except ValueError:
self.counter = counter
self.counter.setLevel( logging.INFO )

self.logger.addHandler( self.counter )

def Update( self ) -> None: # type: ignore[override]
"""Update the filter."""
super().Update()

result: str = f"The filter { self.logger.name } succeeded"
if self.counter.warningCount > 0:
self.logger.warning( f"{ result } but { self.counter.warningCount } warnings have been logged." )
else:
self.logger.info( f"{ result }." )

# Keep number of warnings logged during the filter application and reset the warnings count in case the filter is applied again.
self.nbWarnings = self.counter.warningCount
self.counter.resetWarningCount()
# Logger.
self.logger: Logger = getLogger( loggerTitle )

def ComputeTransform( self ) -> None:
"""Update the transformation."""
Expand All @@ -284,20 +250,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 isHandlerInLogger( handler, self.logger ):
self.logger.addHandler( handler )
else:
self.logger.warning( "The logger already has this handler, it has not been added." )
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 @@ -43,7 +43,6 @@
valueNpType: type
nbComponents: int
componentNames: tuple[ str, ... ]
speHandler: bool

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

# Set your handler (only if speHandler is True).
Expand Down Expand Up @@ -85,7 +83,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 @@ -120,41 +117,14 @@ def __init__(
# Check if the new component have default values (information for the output message).
self.useDefaultValue: bool = False

# 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.propagate = False

counter: CountVerbosityHandler = CountVerbosityHandler()
self.counter: CountVerbosityHandler
self.nbWarnings: int = 0
try:
self.counter = getLoggerHandlerType( type( counter ), self.logger )
self.counter.resetWarningCount()
except ValueError:
self.counter = counter
self.counter.setLevel( logging.INFO )
# Logger.
self.logger: Logger = getLogger( loggerTitle ) # Warnings counter.

self.counter: CountWarningHandler = CountWarningHandler()
self.counter.setLevel( logging.INFO )
# Add the handler to count warnings messages.
self.logger.addHandler( self.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 isHandlerInLogger( handler, self.logger ):
self.logger.addHandler( handler )
else:
self.logger.warning( "The logger already has this handler, it has not been added." )

def applyFilter( self: Self ) -> None:
"""Create a constant attribute per region in the mesh.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from typing_extensions import Self
from typing import Union, Any

from geos.utils.pieceEnum import Piece
from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType )
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 @@ -68,7 +68,6 @@ def __init__(
self: Self,
multiBlockDataSet: vtkMultiBlockDataSet,
dictAttributesValues: dict[ str, Union[ list[ Any ], None ] ],
speHandler: bool = False,
Comment thread
jafranc marked this conversation as resolved.
) -> None:
"""Fill partial attributes with constant value per component.

Expand All @@ -81,50 +80,13 @@ 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 )
self.logger.propagate = False

counter: CountVerbosityHandler = CountVerbosityHandler()
self.counter: CountVerbosityHandler
self.nbWarnings: int = 0
try:
self.counter = getLoggerHandlerType( type( counter ), self.logger )
self.counter.resetWarningCount()
except ValueError:
self.counter = counter
self.counter.setLevel( logging.INFO )

self.logger.addHandler( self.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 isHandlerInLogger( handler, self.logger ):
self.logger.addHandler( handler )
else:
self.logger.warning( "The logger already has this handler, it has not been added." )

def applyFilter( self: Self ) -> None:
def applyFilter( self: Self ) -> bool:
"""Create a constant attribute per region in the mesh.

Raise:
Expand Down
Loading
Loading