@@ -422,3 +422,74 @@ def test_volume_uniform_refinement_project_to_surface_false_skips_validation():
422422 )
423423
424424 assert errors is None , "No snappy validation error expected when project_to_surface=False"
425+
426+
427+ def test_snappy_proximity_spacing_error_when_exceeds_default_min_spacing ():
428+ """When min_spacing is not set on a BodyRefinement but proximity_spacing exceeds
429+ defaults.min_spacing, a ValueError should be raised."""
430+ message = "Proximity spacing for a BodyRefinement (5.0 mm) was set higher than the minimal spacing (3.0 mm)."
431+ with SI_unit_system , pytest .raises (pd .ValidationError , match = re .escape (message )):
432+ snappy .SurfaceMeshingParams (
433+ defaults = snappy .SurfaceMeshingDefaults (
434+ min_spacing = 3 * u .mm , max_spacing = 10 * u .mm , gap_resolution = 0.1 * u .mm
435+ ),
436+ refinements = [
437+ snappy .BodyRefinement (
438+ bodies = SnappyBody (name = "body1" , surfaces = [Surface (name = "surface" )]),
439+ proximity_spacing = 5 * u .mm ,
440+ max_spacing = 10 * u .mm ,
441+ ),
442+ ],
443+ )
444+
445+
446+ def test_snappy_proximity_spacing_ok_when_below_default_min_spacing ():
447+ """When proximity_spacing is already <= defaults.min_spacing, no error should be raised."""
448+ with SI_unit_system :
449+ body = SnappyBody (name = "body1" , surfaces = [Surface (name = "surface" )])
450+ params = snappy .SurfaceMeshingParams (
451+ defaults = snappy .SurfaceMeshingDefaults (
452+ min_spacing = 3 * u .mm , max_spacing = 10 * u .mm , gap_resolution = 0.1 * u .mm
453+ ),
454+ refinements = [
455+ snappy .BodyRefinement (
456+ bodies = body ,
457+ proximity_spacing = 2 * u .mm ,
458+ max_spacing = 10 * u .mm ,
459+ ),
460+ ],
461+ )
462+ assert params .refinements [0 ].proximity_spacing == 2 * u .mm
463+
464+
465+ def test_snappy_proximity_spacing_error_with_explicit_min_spacing ():
466+ """When both min_spacing and proximity_spacing are set on the refinement
467+ and proximity_spacing > min_spacing, the entity-level validator raises."""
468+ message = "Proximity spacing (6.0 mm) was set higher than the minimal spacing (4.0 mm)."
469+ with SI_unit_system , pytest .raises (pd .ValidationError , match = re .escape (message )):
470+ snappy .BodyRefinement (
471+ bodies = SnappyBody (name = "body1" , surfaces = [Surface (name = "surface" )]),
472+ min_spacing = 4 * u .mm ,
473+ proximity_spacing = 6 * u .mm ,
474+ max_spacing = 10 * u .mm ,
475+ )
476+
477+
478+ def test_snappy_proximity_spacing_ok_when_min_spacing_is_set ():
479+ """When min_spacing is explicitly set and proximity_spacing <= min_spacing, no error."""
480+ with SI_unit_system :
481+ body = SnappyBody (name = "body1" , surfaces = [Surface (name = "surface" )])
482+ params = snappy .SurfaceMeshingParams (
483+ defaults = snappy .SurfaceMeshingDefaults (
484+ min_spacing = 1 * u .mm , max_spacing = 10 * u .mm , gap_resolution = 0.1 * u .mm
485+ ),
486+ refinements = [
487+ snappy .BodyRefinement (
488+ bodies = body ,
489+ min_spacing = 4 * u .mm ,
490+ proximity_spacing = 3 * u .mm ,
491+ max_spacing = 10 * u .mm ,
492+ ),
493+ ],
494+ )
495+ assert params .refinements [0 ].proximity_spacing == 3 * u .mm
0 commit comments