Beispiel #1
0
def test_large_grid(solver_, backend_):
    try:
        configure_application(solver_, backend_)
        c = Config(TimeGridConf(1, 1, 1), SpatialMeshConf(100, 1),
                   inner_regions=[InnerRegionConf('tube',
                                                  Tube((50, 50, 10), (50, 50, 12), 10, 90),
                                                  10)])
        r = Runner(c.make())
        r.eval_and_write_fields_without_particles()
        assert r.simulation.potential.data.mean() >= 0
        assert r.simulation.potential.data.mean() <= 10
        assert abs(r.simulation.potential.data.max() - 10) < 0.01
        assert abs(r.simulation.potential.data.min()) < 0.01
    finally:
        inject.clear()
Beispiel #2
0
 def test_particle_generation(self, monkeypatch, tmpdir,
                              backend_and_solver):
     monkeypatch.chdir(tmpdir)
     conf = Config(
         TimeGridConf(2, 1, 1),
         SpatialMeshConf((5, 5, 5), (.1, .1, .1)),
         sources=[
             ParticleSourceConf('a',
                                Box((2, 2, 2), (0, 0, 0)),
                                2,
                                1, (0, 0, 0),
                                0,
                                charge=0),
             ParticleSourceConf('b',
                                Box((1, 1, 1), (0, 0, 0)),
                                7,
                                5, (0, 0, 0),
                                0,
                                charge=0)
         ],
         inner_regions=[InnerRegionConf('1', Box((.5, .5, .5), (1, 1, 1)))],
         output_file=OutputFileConf(),
         boundary_conditions=BoundaryConditionsConf(),
         particle_interaction_model=ParticleInteractionModelConf(
             'noninteracting'),
         external_fields=[])
     sim = conf.make()
     Runner(sim).start()
     assert [len(a.ids) for a in sim.particle_arrays] == [4]
Beispiel #3
0
 def test_cube_of_gas(self, model, backend_and_solver):
     sim = Config(TimeGridConf(1.0, save_step=.5, step=.1),
                  SpatialMeshConf((10, 10, 10), (1, 1, 1)), [
                      ParticleSourceConf('gas', Box(size=(10, 10, 10)), 50,
                                         0, np.zeros(3), 300)
                  ],
                  particle_interaction_model=ParticleInteractionModelConf(
                      model)).make()
     Runner(sim).start()
Beispiel #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("config_or_h5_file",
                        help="config or h5 file",
                        type=guess_input_type)
    parser.add_argument("--output-format",
                        default="cpp",
                        help="select output hdf5 format",
                        choices=["python", "cpp", "history", "none"])
    parser.add_argument("--prefix", help="customize output file prefix")
    parser.add_argument("--suffix", help="customize output file suffix")
    parser.add_argument("--solver",
                        default="amg",
                        help="select field solving library",
                        choices=["amg", "amgx"])
    parser.add_argument("--backend",
                        default="numpy",
                        help="select acceleration library",
                        choices=["numpy", "cupy"])

    args = parser.parse_args()

    is_config, parser_or_h5_filename = args.config_or_h5_file
    configure_application(args.solver, args.backend)
    if is_config:
        conf = read_conf(parser_or_h5_filename, args.prefix, args.suffix,
                         args.output_format)
        sim = conf.make()
        writer = conf.output_file.make()
        Runner(sim, output_writer=writer).start()
    else:
        print("Continuing from h5 file:", parser_or_h5_filename)
        prefix, suffix = merge_h5_prefix_suffix(parser_or_h5_filename,
                                                args.prefix, args.suffix)
        print("Using output prefix and suffix:", prefix, suffix)
        with h5py.File(parser_or_h5_filename, 'r') as h5file:
            sim = Reader.read_simulation(h5file)
        writer = OutputFileConf(prefix, suffix, args.output_format).make()
        Runner(sim, output_writer=writer).continue_()
    del sim
    return 0
Beispiel #5
0
 def test_id_generation(self, backend_and_solver):
     conf = Config(TimeGridConf(0.001, save_step=.0005, step=0.0001),
                   SpatialMeshConf((10, 10, 10), (1, 1, 1)),
                   sources=[
                       ParticleSourceConf('gas',
                                          Box((4, 4, 4), size=(1, 1, 1)),
                                          50, 0, np.zeros(3), 0.00),
                       ParticleSourceConf('gas2',
                                          Box((5, 5, 5), size=(1, 1, 1)),
                                          50, 0, np.zeros(3), 0.00)
                   ],
                   particle_interaction_model=ParticleInteractionModelConf(
                       'noninteracting'))
     assert len(conf.sources) == 2
     sim = conf.make()
     assert len(sim.particle_sources) == 2
     assert len(sim.particle_arrays) == 0
     Runner(sim).start()
     assert len(sim.particle_sources) == 2
     assert len(sim.particle_arrays) == 1
     sim.particle_arrays[0].xp.testing.assert_array_equal(
         sim.particle_arrays[0].ids, range(100))
Beispiel #6
0
def test_example_conf(fname, tmpdir, monkeypatch, backend_and_solver):
    sim = Config.from_fname(fname).make()
    monkeypatch.chdir(tmpdir)
    Runner(sim).start()