Example #1
0
    def test_all_config(self):
        efconf = Config(TimeGridConf(200, 20, 2), SpatialMeshConf((5, 5, 5), (.1, .1, .1)),
                        sources=[ParticleSourceConf('a', Box()),
                                 ParticleSourceConf('c', Cylinder()),
                                 ParticleSourceConf('d', Tube())],
                        inner_regions=[InnerRegionConf('1', Box(), 1),
                                       InnerRegionConf('2', Sphere(), -2),
                                       InnerRegionConf('3', Cylinder(), 0),
                                       InnerRegionConf('4', Tube(), 4)],
                        output_file=OutputFileConf(), boundary_conditions=BoundaryConditionsConf(-2.7),
                        particle_interaction_model=ParticleInteractionModelConf('binary'),
                        external_fields=[ExternalFieldUniformConf('x', 'electric', (-2, -2, 1)),
                                         ExternalFieldExpressionConf('y', 'magnetic',
                                                                     ('0', '0', '3*x + sqrt(y) - z**2'))])

        parser = ConfigParser()
        parser.read_string(efconf.export_to_string())
        sim = Config.from_configparser(parser).make()
        assert sim.time_grid == TimeGrid(200, 2, 20)
        assert sim.spat_mesh == SpatialMesh.do_init((5, 5, 5), (.1, .1, .1), BoundaryConditionsConf(-2.7))
        assert sim.inner_regions == [InnerRegion('1', Box(), 1),
                                     InnerRegion('2', Sphere(), -2),
                                     InnerRegion('3', Cylinder(), 0),
                                     InnerRegion('4', Tube(), 4)]
        assert type(sim._field_solver) == FieldSolver
        assert sim.particle_sources == [ParticleSourceConf('a', Box()).make(),
                                        ParticleSourceConf('c', Cylinder()).make(),
                                        ParticleSourceConf('d', Tube()).make()]
        assert sim.electric_fields == [ExternalFieldUniform('x', 'electric', np.array((-2, -2, 1)))]
        assert sim.magnetic_fields == [ExternalFieldExpression('y', 'magnetic', '0', '0', '3*x + sqrt(y) - z**2')]
        assert sim.particle_interaction_model == ParticleInteractionModel("binary")
        assert sim._output_filename_prefix == "out_"
        assert sim._output_filename_suffix == ".h5"
Example #2
0
def read_conf(parser, prefix, suffix, format_):
    conf = Config.from_configparser(parser)
    if prefix:
        conf.output_file.prefix = prefix
    if suffix:
        conf.output_file.suffix = suffix
    conf.output_file.format_ = format_
    print(conf)
    return conf
Example #3
0
    def test_all_config(self, backend):
        efconf = Config(
            TimeGridConf(200, 20, 2),
            SpatialMeshConf((5, 5, 5), (.1, .1, .1)),
            sources=[
                ParticleSourceConf('a', Box()),
                ParticleSourceConf('c', Cylinder()),
                ParticleSourceConf('d', Tube(start=(0, 0, 0), end=(0, 0, 1)))
            ],
            inner_regions=[
                InnerRegionConf('1', Box(), 1),
                InnerRegionConf('2', Sphere(), -2),
                InnerRegionConf('3', Cylinder(), 0),
                InnerRegionConf('4', Tube(), 4)
            ],
            output_file=OutputFileConf(),
            boundary_conditions=BoundaryConditionsConf(-2.7),
            particle_interaction_model=ParticleInteractionModelConf('binary'),
            external_fields=[
                ExternalElectricFieldUniformConf('x', (-2, -2, 1)),
                ExternalMagneticFieldExpressionConf(
                    'y', ('0', '0', '3*x + sqrt(y) - z**2'))
            ])

        parser = ConfigParser()
        parser.read_string(efconf.export_to_string())
        conf = Config.from_configparser(parser)
        sim = conf.make()
        assert_dataclass_eq(sim.time_grid, TimeGrid(200, 2, 20))
        assert_dataclass_eq(sim.mesh, MeshGrid(5, 51))
        assert_dataclass_eq(
            sim.electric_field,
            FieldOnGrid('spatial_mesh', 'electric', self.Array(sim.mesh, 3)))
        assert_dataclass_eq(sim.charge_density, self.Array(sim.mesh))
        expected = np.full((51, 51, 51), -2.7)
        expected[1:-1, 1:-1, 1:-1] = 0
        assert_dataclass_eq(sim.potential, self.Array(sim.mesh, (), expected))
        _assert_value_eq(sim.inner_regions, [
            InnerRegion('1', Box(), 1),
            InnerRegion('2', Sphere(), -2),
            InnerRegion('3', Cylinder(), 0),
            InnerRegion('4', Tube(), 4)
        ])
        _assert_value_eq(sim.particle_sources, [
            ParticleSourceConf('a', Box()).make(),
            ParticleSourceConf('c', Cylinder()).make(),
            ParticleSourceConf('d', Tube(start=(0, 0, 0),
                                         end=(0, 0, 1))).make()
        ])
        assert_dataclass_eq(
            sim.electric_fields,
            FieldUniform('x', 'electric', np.array((-2, -2, 1))))
        assert_dataclass_eq(
            sim.magnetic_fields,
            FieldExpression('y', 'magnetic', '0', '0', '3*x + sqrt(y) - z**2'))
        assert sim.particle_interaction_model == Model.binary
Example #4
0
 def test_init_from_config(self):
     efconf = Config()
     parser = ConfigParser()
     parser.read_string(efconf.export_to_string())
     sim = Config.from_configparser(parser).make()
     assert sim.time_grid == TimeGrid(100, 1, 10)
     assert sim.spat_mesh == SpatialMesh.do_init((10, 10, 10), (1, 1, 1), BoundaryConditionsConf(0))
     assert sim.inner_regions == []
     assert type(sim._field_solver) == FieldSolver
     assert sim.particle_sources == []
     assert sim.electric_fields == []
     assert sim.magnetic_fields == []
     assert sim.particle_interaction_model == ParticleInteractionModel("PIC")
     assert sim._output_filename_prefix == "out_"
     assert sim._output_filename_suffix == ".h5"
def construct_domain(config_or_h5_file):
    extension = config_or_h5_file[config_or_h5_file.rfind(".") + 1:]
    if extension == "h5":
        with h5py.File(config_or_h5_file, 'r') as h5file:
            filename_prefix, filename_suffix = \
                extract_filename_prefix_and_suffix_from_h5filename(config_or_h5_file)
            dom = Simulation.init_from_h5(h5file, filename_prefix,
                                          filename_suffix)
            continue_from_h5 = True
    else:
        conf = configparser.ConfigParser()
        conf.read(config_or_h5_file)
        echo_config(config_or_h5_file, conf)
        dom = Config.from_configparser(conf).make()
        continue_from_h5 = False
    return dom, continue_from_h5
Example #6
0
 def test_init_from_config(self, backend):
     efconf = Config()
     parser = ConfigParser()
     parser.read_string(efconf.export_to_string())
     sim = Config.from_configparser(parser).make()
     assert_dataclass_eq(sim.time_grid, TimeGrid(100, 1, 10))
     g = MeshGrid(10, 11)
     assert_dataclass_eq(sim.mesh, g)
     assert_dataclass_eq(sim.potential, self.Array(g))
     assert_dataclass_eq(sim.charge_density, self.Array(g))
     assert_dataclass_eq(
         sim.electric_field,
         FieldOnGrid('spatial_mesh', 'electric', self.Array(g, 3)))
     assert sim.inner_regions == []
     assert sim.particle_sources == []
     assert_dataclass_eq(sim.electric_fields,
                         FieldZero('ZeroSum', 'electric'))
     assert_dataclass_eq(sim.magnetic_fields,
                         FieldZero('ZeroSum', 'magnetic'))
     assert sim.particle_interaction_model == Model.PIC