File: divide_mpi_processes.py

package info (click to toggle)
meep-mpi-default 1.17.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 51,672 kB
  • sloc: cpp: 29,881; python: 17,210; lisp: 1,225; makefile: 477; sh: 249; ansic: 133; javascript: 5
file content (55 lines) | stat: -rw-r--r-- 1,923 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from __future__ import division

import unittest
import meep as mp

@unittest.skipIf(mp.count_processors() < 2, "MPI specific test")
class TestDivideParallelProcesses(unittest.TestCase):

    def test_divide_parallel_processes(self):        
        resolution = 20

        sxy = 4
        dpml = 1
        cell = mp.Vector3(sxy+2*dpml,sxy+2*dpml)

        pml_layers = [mp.PML(dpml)]

        n = mp.divide_parallel_processes(2)
        fcen = 1.0/(n+1)

        sources = [mp.Source(src=mp.GaussianSource(fcen,fwidth=0.2*fcen),
                             center=mp.Vector3(),
                             component=mp.Ez)]
        
        symmetries = [mp.Mirror(mp.X),
                      mp.Mirror(mp.Y)]

        self.sim = mp.Simulation(cell_size=cell,
                                 resolution=resolution,
                                 sources=sources,
                                 symmetries=symmetries,
                                 boundary_layers=pml_layers)

    
        flux_box = self.sim.add_flux(fcen, 0, 1,
                                     mp.FluxRegion(mp.Vector3(y=0.5*sxy), size=mp.Vector3(sxy)),
                                     mp.FluxRegion(mp.Vector3(y=-0.5*sxy), size=mp.Vector3(sxy), weight=-1),
                                     mp.FluxRegion(mp.Vector3(0.5*sxy), size=mp.Vector3(y=sxy)),
                                     mp.FluxRegion(mp.Vector3(-0.5*sxy), size=mp.Vector3(y=sxy), weight=-1))

        self.sim.run(until_after_sources=30)

        tot_flux = mp.get_fluxes(flux_box)[0]
        
        tot_fluxes = mp.merge_subgroup_data(tot_flux)
        fcens = mp.merge_subgroup_data(fcen)            

        self.assertEqual(fcens[0],1)
        self.assertEqual(fcens[1],0.5)
        self.assertAlmostEqual(tot_fluxes[0], 9.8628728533)
        self.assertAlmostEqual(tot_fluxes[1], 19.6537275387)
        
if __name__ == '__main__':
    unittest.main()