@@ -103,6 +103,7 @@ def __init__(
103103 else :
104104 self .logger = logging .getLogger ( loggerTitle )
105105 self .logger .setLevel ( logging .INFO )
106+ self .logger .propagate = False
106107
107108 def setLoggerHandler ( self : Self , handler : logging .Handler ) -> None :
108109 """Set a specific handler for the filter logger.
@@ -113,7 +114,7 @@ def setLoggerHandler( self: Self, handler: logging.Handler ) -> None:
113114 Args:
114115 handler (logging.Handler): The handler to add.
115116 """
116- if not self .logger .hasHandlers () :
117+ if len ( self .logger .handlers ) == 0 :
117118 self .logger .addHandler ( handler )
118119 else :
119120 self .logger .warning ( "The logger already has an handler, to use yours set the argument 'speHandler'"
@@ -139,58 +140,58 @@ def applyFilter( self: Self ) -> bool:
139140 """
140141 self .logger .info ( f"Apply filter { self .logger .name } ." )
141142
142- if len ( self .attributeNames ) == 0 :
143- self .logger .warning ( f"Please enter at least one { self .piece } attribute to transfer." )
144- self .logger .warning ( f"The filter { self .logger .name } has not been used." )
145- return False
146-
147- attributesInMeshFrom : set [ str ] = getAttributeSet ( self .meshFrom , self .onPoints )
148- wrongAttributeNames : set [ str ] = self .attributeNames .difference ( attributesInMeshFrom )
149- if len ( wrongAttributeNames ) > 0 :
150- self .logger .error (
151- f"The { self .piece } attributes { wrongAttributeNames } are not present in the source mesh." )
152- self .logger .error ( f"The filter { self .logger .name } failed." )
153- return False
154-
155- attributesInMeshTo : set [ str ] = getAttributeSet ( self .meshTo , self .onPoints )
156- attributesAlreadyInMeshTo : set [ str ] = self .attributeNames .intersection ( attributesInMeshTo )
157- if len ( attributesAlreadyInMeshTo ) > 0 :
158- self .logger .error (
159- f"The { self .piece } attributes { attributesAlreadyInMeshTo } are already present in the final mesh." )
160- self .logger .error ( f"The filter { self .logger .name } failed." )
161- return False
143+ try :
144+ if len ( self .attributeNames ) == 0 :
145+ raise ValueError ( f"Please enter at least one { self .piece } attribute to transfer." )
146+
147+ attributesInMeshFrom : set [ str ] = getAttributeSet ( self .meshFrom , self .onPoints )
148+ wrongAttributeNames : set [ str ] = self .attributeNames .difference ( attributesInMeshFrom )
149+ if len ( wrongAttributeNames ) > 0 :
150+ raise AttributeError (
151+ f"The { self .piece } attributes { wrongAttributeNames } are not present in the source mesh." )
152+
153+ attributesInMeshTo : set [ str ] = getAttributeSet ( self .meshTo , self .onPoints )
154+ attributesAlreadyInMeshTo : set [ str ] = self .attributeNames .intersection ( attributesInMeshTo )
155+ if len ( attributesAlreadyInMeshTo ) > 0 :
156+ raise AttributeError (
157+ f"The { self .piece } attributes { attributesAlreadyInMeshTo } are already present in the final mesh."
158+ )
159+
160+ if isinstance ( self .meshFrom , vtkMultiBlockDataSet ):
161+ partialAttributes : list [ str ] = []
162+ for attributeName in self .attributeNames :
163+ if not isAttributeGlobal ( self .meshFrom , attributeName , self .onPoints ):
164+ partialAttributes .append ( attributeName )
165+
166+ if len ( partialAttributes ) > 0 :
167+ raise AttributeError (
168+ f"All { self .piece } attributes to transfer must be global, { partialAttributes } are partials."
169+ )
170+
171+ self .ElementMap = computeElementMapping ( self .meshFrom , self .meshTo , self .onPoints )
172+ sharedElement : bool = False
173+ for key in self .ElementMap :
174+ if np .any ( self .ElementMap [ key ] > - 1 ):
175+ sharedElement = True
176+
177+ if not sharedElement :
178+ raise ValueError ( f"The two meshes do not have any shared { self .piece } ." )
162179
163- if isinstance ( self .meshFrom , vtkMultiBlockDataSet ):
164- partialAttributes : list [ str ] = []
165180 for attributeName in self .attributeNames :
166- if not isAttributeGlobal ( self .meshFrom , attributeName , self .onPoints ):
167- partialAttributes .append ( attributeName )
168-
169- if len ( partialAttributes ) > 0 :
170- self .logger .error (
171- f"All { self .piece } attributes to transfer must be global, { partialAttributes } are partials." )
172- self .logger .error ( f"The filter { self .logger .name } failed." )
173-
174- self .ElementMap = computeElementMapping ( self .meshFrom , self .meshTo , self .onPoints )
175- sharedElement : bool = False
176- for key in self .ElementMap :
177- if np .any ( self .ElementMap [ key ] > - 1 ):
178- sharedElement = True
179-
180- if not sharedElement :
181- self .logger .warning ( f"The two meshes do not have any shared { self .piece } ." )
182- self .logger .warning ( f"The filter { self .logger .name } has not been used." )
181+ # TODO:: Modify arrayModifiers function to raise error.
182+ if not transferAttributeWithElementMap ( self .meshFrom , self .meshTo , self .ElementMap , attributeName ,
183+ self .onPoints , self .logger ):
184+ raise
185+
186+ # Log the output message.
187+ self ._logOutputMessage ()
188+ except ( TypeError , ValueError , AttributeError ) as e :
189+ self .logger .error ( f"The filter { self .logger .name } failed.\n { e } " )
190+ return False
191+ except Exception as e :
192+ mess : str = f"The filter { self .logger .name } failed.\n { e } "
193+ self .logger .critical ( mess , exc_info = True )
183194 return False
184-
185- for attributeName in self .attributeNames :
186- if not transferAttributeWithElementMap ( self .meshFrom , self .meshTo , self .ElementMap , attributeName ,
187- self .onPoints , self .logger ):
188- self .logger .error ( f"The attribute { attributeName } has not been mapped." )
189- self .logger .error ( f"The filter { self .logger .name } failed." )
190- return False
191-
192- # Log the output message.
193- self ._logOutputMessage ()
194195
195196 return True
196197
0 commit comments