88from gsim .meep import (
99 FDTD ,
1010 Domain ,
11- Geometry ,
1211 Material ,
1312 ModeSource ,
1413 Simulation ,
15- Symmetry ,
1614)
1715
1816# ---------------------------------------------------------------------------
2321class TestMaterial :
2422 """Tests for the Material model."""
2523
26- def test_basic (self ):
27- m = Material (n = 3.47 )
28- assert m .n == 3.47
29- assert m .k == 0.0
30-
31- def test_with_extinction (self ):
32- m = Material (n = 3.47 , k = 0.01 )
33- assert m .k == 0.01
34-
3524 def test_n_must_be_positive (self ):
3625 with pytest .raises (ValidationError ):
3726 Material (n = 0 )
@@ -41,65 +30,9 @@ def test_k_must_be_non_negative(self):
4130 Material (n = 1.5 , k = - 0.1 )
4231
4332
44- class TestModeSource :
45- """Tests for the ModeSource model."""
46-
47- def test_defaults (self ):
48- s = ModeSource ()
49- assert s .port is None
50- assert s .wavelength == 1.55
51- assert s .wavelength_span == 0.1
52- assert s .num_freqs == 11
53-
54- def test_custom (self ):
55- s = ModeSource (port = "o1" , wavelength = 1.31 , wavelength_span = 0.05 , num_freqs = 21 )
56- assert s .port == "o1"
57- assert s .wavelength == 1.31
58- assert s .wavelength_span == 0.05
59- assert s .num_freqs == 21
60-
61-
62- class TestDomain :
63- """Tests for the Domain model."""
64-
65- def test_defaults (self ):
66- d = Domain ()
67- assert d .pml == 1.0
68- assert d .margin == 0.5
69- assert d .margin_z_above == 0.5
70- assert d .margin_z_below == 0.5
71- assert d .port_margin == 0.5
72- assert d .extend_ports == 0.0
73- assert d .source_port_offset == 0.1
74- assert d .distance_source_to_monitors == 0.2
75- assert d .symmetries == []
76-
77- def test_custom (self ):
78- d = Domain (pml = 0.5 , margin = 0.2 , port_margin = 0.3 )
79- assert d .pml == 0.5
80- assert d .margin == 0.2
81- assert d .port_margin == 0.3
82-
83- def test_symmetries (self ):
84- d = Domain (symmetries = [Symmetry (direction = "Y" , phase = - 1 )])
85- assert len (d .symmetries ) == 1
86- assert d .symmetries [0 ].direction == "Y"
87- assert d .symmetries [0 ].phase == - 1
88-
89-
9033class TestStoppingFields :
9134 """Tests for the FDTD stopping criteria."""
9235
93- def test_defaults (self ):
94- f = FDTD ()
95- assert f .stopping == "energy_decay"
96- assert f .max_time == 2000.0
97- assert f .stopping_threshold == 0.01
98- assert f .stopping_min_time == 100.0
99- assert f .stopping_component == "Ey"
100- assert f .stopping_dt == 20.0
101- assert f .stopping_monitor_port is None
102-
10336 def test_fixed_mode (self ):
10437 f = FDTD (stopping = "fixed" , max_time = 100 )
10538 assert f .stopping == "fixed"
@@ -137,42 +70,11 @@ def test_invalid_mode(self):
13770class TestFDTD :
13871 """Tests for the FDTD model."""
13972
140- def test_defaults (self ):
141- f = FDTD ()
142- assert f .resolution == 32
143- assert f .stopping == "energy_decay"
144- assert f .max_time == 2000.0
145- assert f .subpixel is False
146- assert f .simplify_tol == 0.0
147-
148- def test_with_custom_stopping (self ):
149- f = FDTD (stopping = "field_decay" , stopping_threshold = 1e-4 )
150- assert f .stopping == "field_decay"
151- assert f .stopping_threshold == 1e-4
152-
15373 def test_resolution_custom (self ):
15474 f = FDTD (resolution = 64 )
15575 assert f .resolution == 64
15676
15777
158- class TestFDTDDiagnostics :
159- """Tests for the FDTD diagnostics settings."""
160-
161- def test_defaults (self ):
162- f = FDTD ()
163- assert f .save_geometry is True
164- assert f .save_fields is True
165- assert f .save_animation is False
166- assert f .preview_only is False
167- assert f .verbose_interval == 0
168-
169- def test_custom (self ):
170- f = FDTD (save_animation = True , verbose_interval = 5.0 , preview_only = True )
171- assert f .save_animation is True
172- assert f .verbose_interval == 5.0
173- assert f .preview_only is True
174-
175-
17678# ---------------------------------------------------------------------------
17779# Material normalization
17880# ---------------------------------------------------------------------------
@@ -502,42 +404,3 @@ def test_diagnostics_translation(self):
502404 cfg = sim ._diagnostics_config ()
503405 assert cfg .save_animation is True
504406 assert cfg .preview_only is True
505-
506-
507- # ---------------------------------------------------------------------------
508- # Import tests
509- # ---------------------------------------------------------------------------
510-
511-
512- class TestImports :
513- """Tests for importing the new declarative API."""
514-
515- def test_import_all_new_api (self ):
516- from gsim .meep import (
517- FDTD ,
518- Domain ,
519- Material ,
520- ModeSource ,
521- Simulation ,
522- Symmetry ,
523- )
524-
525- assert all (
526- cls is not None
527- for cls in [
528- Domain ,
529- FDTD ,
530- Geometry ,
531- Material ,
532- ModeSource ,
533- Simulation ,
534- Symmetry ,
535- ]
536- )
537-
538- def test_simulation_instantiation (self ):
539- sim = Simulation ()
540- assert sim .geometry .component is None
541- assert sim .materials == {}
542- assert sim .monitors == []
543- assert sim .solver .resolution == 32
0 commit comments