117117from .validators import (
118118 assert_objects_contained_in_sim_bounds ,
119119 assert_objects_in_sim_bounds ,
120+ named_obj_descr ,
120121 validate_mode_objects_symmetry ,
121122)
122123from .viz import (
@@ -2961,8 +2962,9 @@ def _validate_2d_geometry_has_2d_medium(cls, val, values):
29612962 for geom in flatten_groups (structure .geometry ):
29622963 zero_dims = geom .zero_dims
29632964 if len (zero_dims ) > 0 :
2965+ obj_descr = named_obj_descr (structure , "structures" , i )
29642966 consolidated_logger .warning (
2965- f"Structure at 'structures[ { i } ]' has geometry with zero size along "
2967+ f"Structure: { obj_descr } has geometry with zero size along "
29662968 f"dimensions { zero_dims } , and with a medium that is not a 'Medium2D'. "
29672969 "This is probably not correct, since the resulting simulation will "
29682970 "depend on the details of the numerical grid. Consider either "
@@ -3018,10 +3020,11 @@ def _structures_not_close_pml(cls, val, values):
30183020
30193021 with log as consolidated_logger :
30203022
3021- def warn (istruct , side ):
3023+ def warn (structure , istruct , side ):
30223024 """Warning message for a structure too close to PML."""
3025+ obj_descr = named_obj_descr (structure , "structures" , istruct )
30233026 consolidated_logger .warning (
3024- f"Structure at structures[ { istruct } ] was detected as being less "
3027+ f"Structure: { obj_descr } was detected as being less "
30253028 f"than half of a central wavelength from a PML on side { side } . "
30263029 "To avoid inaccurate results or divergence, please increase gap between "
30273030 "any structures and PML or fully extend structure through the pml." ,
@@ -3044,7 +3047,7 @@ def warn(istruct, side):
30443047 and struct_val > sim_val
30453048 and abs (sim_val - struct_val ) < lambda0 / 2
30463049 ):
3047- warn (istruct , axis + "-min" )
3050+ warn (structure , istruct , axis + "-min" )
30483051
30493052 zipped = zip (["x" , "y" , "z" ], sim_bound_max , struct_bound_max , boundaries )
30503053 for axis , sim_val , struct_val , boundary in zipped :
@@ -3056,7 +3059,7 @@ def warn(istruct, side):
30563059 and struct_val < sim_val
30573060 and abs (sim_val - struct_val ) < lambda0 / 2
30583061 ):
3059- warn (istruct , axis + "-max" )
3062+ warn (structure , istruct , axis + "-max" )
30603063
30613064 return val
30623065
@@ -3095,20 +3098,20 @@ def _warn_monitor_mediums_frequency_range(cls, val, values):
30953098 medium_str = "The simulation background medium"
30963099 custom_loc = ["medium" , "frequency_range" ]
30973100 else :
3098- medium_str = (
3099- f"The medium associated with structures[{ medium_index - 1 } ]"
3100- )
3101+ medium_descr = named_obj_descr (medium , "mediums" , medium_index )
3102+ medium_str = f"The medium associated with { medium_descr } "
31013103 custom_loc = [
31023104 "structures" ,
31033105 medium_index - 1 ,
31043106 "medium" ,
31053107 "frequency_range" ,
31063108 ]
31073109
3110+ monitor_descr = named_obj_descr (monitor , "monitors" , monitor_index )
31083111 consolidated_logger .warning (
31093112 f"{ medium_str } has a frequency range: ({ sci_fmin_med } , { sci_fmax_med } ) "
3110- "(Hz) that does not fully cover the frequencies contained in "
3111- f"monitors[ { monitor_index } ]. "
3113+ "(Hz) that does not fully cover the frequencies contained "
3114+ f"in { monitor_descr } . "
31123115 "This can cause inaccuracies in the recorded results." ,
31133116 custom_loc = custom_loc ,
31143117 )
@@ -3806,8 +3809,9 @@ def _validate_custom_source_time(self):
38063809 data_times = source .source_time .data_times
38073810 mint = np .min (data_times )
38083811 maxt = np .max (data_times )
3812+ obj_descr = named_obj_descr (source , "sources" , idx )
38093813 log .warning (
3810- f"'CustomSourceTime' at 'sources[ { idx } ]' is defined over a time range "
3814+ f"'CustomSourceTime': { obj_descr } is defined over a time range "
38113815 f"'({ mint } , { maxt } )' which does not include any of the 'Simulation' "
38123816 f"times '({ 0 , run_time } )'. The envelope will be constant extrapolated "
38133817 "from the first or last value in the 'CustomSourceTime', which may not "
@@ -3837,8 +3841,9 @@ def _validate_no_structures_pml(self) -> None:
38373841 if not isinstance (bound_edge , Absorber ) and (in_pml_plus or in_pml_mnus ):
38383842 warn = True
38393843 if warn :
3844+ obj_descr = named_obj_descr (structure , "structures" , i )
38403845 consolidated_logger .warning (
3841- f"A bound of Simulation.structures[ { i } ] was detected as being "
3846+ f"A bound of { obj_descr } was detected as being "
38423847 "within the simulation PML. We recommend extending structures to "
38433848 "infinity or completely outside of the simulation PML to avoid "
38443849 "unexpected effects when the structures are not translationally "
@@ -3956,8 +3961,9 @@ def _validate_nonlinear_specs(self) -> None:
39563961 if isinstance (monitor , AuxFieldTimeMonitor ):
39573962 for aux_field in monitor .fields :
39583963 if aux_field not in self .aux_fields :
3964+ obj_descr = named_obj_descr (monitor , "monitors" , i )
39593965 log .warning (
3960- f"Monitor at 'monitors[ { i } ]' stores field '{ aux_field } ', "
3966+ f"Monitor: { obj_descr } stores field '{ aux_field } ', "
39613967 "which is not used by any of the nonlinear models present "
39623968 "in the mediums in the simulation. The resulting data "
39633969 "will be zero."
0 commit comments