@@ -320,6 +320,12 @@ class HeatChargeSimulation(AbstractSimulation):
320320 "specify Charge simulations or transient Heat simulations." ,
321321 )
322322
323+ def _post_init_validators (self ):
324+ """Call validators taking ``self`` that get run after init."""
325+
326+ # Charge mesh size validator
327+ self ._estimate_charge_mesh_size ()
328+
323329 @pd .validator ("structures" , always = True )
324330 def check_unsupported_geometries (cls , val ):
325331 """Error if structures contain unsupported yet geometries."""
@@ -930,24 +936,26 @@ def check_conduction_sim(cls, values):
930936
931937 return values
932938
933- @pd .root_validator (skip_on_failure = True )
934- def estimate_charge_mesh_size (cls , values ):
939+ def _estimate_charge_mesh_size (self ):
935940 """Make an estimate of the mesh size and raise a warning if too big.
936941 NOTE: this is a very rough estimate. The back-end will actually stop
937942 execution based on actual node-count."""
938943
939- if TCADAnalysisTypes .CHARGE not in cls . _check_simulation_types ( values = values ):
940- return values
944+ if TCADAnalysisTypes .CHARGE not in self . _get_simulation_types ( ):
945+ return
941946
942947 # let's raise a warning if the estimate is larger than 2M nodes
943948 max_nodes = 2e6
944949 nodes_estimate = 0
945950
946- structures = values [ " structures" ]
947- grid_spec = values [ " grid_spec" ]
951+ structures = self . structures
952+ grid_spec = self . grid_spec
948953
949954 non_refined_structures = grid_spec .non_refined_structures
950955
956+ sim_center = self .center
957+ sim_size = self .size
958+
951959 if isinstance (grid_spec , UniformUnstructuredGrid ):
952960 dl_min = grid_spec .dl
953961 dl_max = dl_min
@@ -957,7 +965,11 @@ def estimate_charge_mesh_size(cls, values):
957965
958966 for struct in structures :
959967 name = struct .name
960- bounds = struct .geometry .bounds
968+ bounds = np .array (struct .geometry .bounds )
969+ for dim in range (3 ):
970+ bounds [0 , dim ] = max (bounds [0 , dim ], sim_center [dim ] - sim_size [dim ] / 2 )
971+ bounds [1 , dim ] = min (bounds [1 , dim ], sim_center [dim ] + sim_size [dim ] / 2 )
972+
961973 dl = dl_min
962974 if name in non_refined_structures :
963975 dl = dl_max
@@ -980,7 +992,6 @@ def estimate_charge_mesh_size(cls, values):
980992 "the pipeline will be stopped. If this happens the grid specification "
981993 "may need to be modified."
982994 )
983- return values
984995
985996 @pd .root_validator (skip_on_failure = True )
986997 def check_transient_heat (cls , values ):
0 commit comments