コード例 #1
0
def test_parametric_sim_twoproc():
    "Test the example input script with two proc in `docs/source/example_input`"

    temporary_dir = './tests/tmp_test_dir'

    # Create a temporary directory for the simulation
    # and copy the example script into this directory
    if os.path.exists( temporary_dir ):
        shutil.rmtree( temporary_dir )
    os.mkdir( temporary_dir )
    shutil.copy(
        './docs/source/example_input/parametric_script.py', temporary_dir )

    # Enter the temporary directory
    os.chdir( temporary_dir )

    # Read the script and check that the targeted lines are present
    with open('parametric_script.py') as f:
        script = f.read()
        # Check that the targeted lines are present
        if script.find('save_checkpoints = False') == -1 \
            or script.find('use_restart = False') == -1:
            raise RuntimeError(
            'Did not find expected lines in parametric_script.py')

    # Modify the script so as to enable checkpoints
    script = script.replace('save_checkpoints = False',
                                'save_checkpoints = True')
    with open('parametric_script.py', 'w') as f:
        f.write(script)
    # Launch the modified script from the OS, with 2 proc
    response = os.system( 'mpirun -np 2 python parametric_script.py' )
    assert response==0

    # Modify the script so as to enable restarts
    script = script.replace('use_restart = False',
                                'use_restart = True')
    script = script.replace('save_checkpoints = True',
                                'save_checkpoints = False')
    with open('parametric_script.py', 'w') as f:
        f.write(script)
    # Launch the modified script from the OS, with 2 proc
    response = os.system( 'mpirun -np 2 python parametric_script.py' )
    assert response==0

    # Check that the simulation produced two output directories
    # and that these directories correspond to different values of
    # a0 (this is done by checking the a0 of the laser, with openPMD-viewer)
    for a0 in [ 2.0, 4.0 ]:
        # Open the diagnotics
        diag_folder = 'diags_a0_%.1f/hdf5' %a0
        ts = LpaDiagnostics( diag_folder )
        # Check that the value of a0 in the diagnostics is the
        # expected one.
        a0_in_diag = ts.get_a0( iteration=80, pol='x' )
        assert abs( (a0 - a0_in_diag)/a0 ) < 1.e-2

    # Exit the temporary directory and suppress it
    os.chdir('../../')
    shutil.rmtree( temporary_dir )
コード例 #2
0
def test_parametric_sim_twoproc():
    "Test the example input script with two proc in `docs/source/example_input`"

    temporary_dir = './tests/tmp_test_dir'

    # Create a temporary directory for the simulation
    # and copy the example script into this directory
    if os.path.exists(temporary_dir):
        shutil.rmtree(temporary_dir)
    os.mkdir(temporary_dir)
    shutil.copy('./docs/source/example_input/parametric_script.py',
                temporary_dir)
    # Shortcut for the script file, which is repeatedly changed
    script_filename = os.path.join(temporary_dir, 'parametric_script.py')

    # Read the script
    with open(script_filename) as f:
        script = f.read()

    # Modify the script so as to enable checkpoints
    script = replace_string(script, 'save_checkpoints = False',
                            'save_checkpoints = True')
    with open(script_filename, 'w') as f:
        f.write(script)

    # Launch the modified script from the OS, with 2 proc
    response = os.system('cd %s; mpirun -np 2 python parametric_script.py' %
                         temporary_dir)
    assert response == 0

    # Modify the script so as to enable restarts
    script = replace_string(script, 'use_restart = False',
                            'use_restart = True')
    script = replace_string(script, 'save_checkpoints = True',
                            'save_checkpoints = False')
    with open(script_filename, 'w') as f:
        f.write(script)
    # Launch the modified script from the OS, with 2 proc
    response = os.system('cd %s; mpirun -np 2 python parametric_script.py' %
                         temporary_dir)
    assert response == 0

    # Check that the simulation produced two output directories
    # and that these directories correspond to different values of
    # a0 (this is done by checking the a0 of the laser, with openPMD-viewer)
    for a0 in [2.0, 4.0]:
        # Open the diagnotics
        diag_folder = os.path.join(temporary_dir, 'diags_a0_%.2f/hdf5' % a0)
        ts = LpaDiagnostics(diag_folder)
        # Check that the value of a0 in the diagnostics is the
        # expected one.
        a0_in_diag = ts.get_a0(iteration=80, pol='x')
        assert abs((a0 - a0_in_diag) / a0) < 1.e-2

    # Suppress the temporary directory
    shutil.rmtree(temporary_dir)
コード例 #3
0
    tdeb = MPI.Wtime()

em.step(N_step)

tend = MPI.Wtime()
if (me == 0):
    print("Final runtime (s): " + str(tend - tdeb))

# ------------------------------------------------------------------------------
# Test Diagnostics
# ------------------------------------------------------------------------------

print("=== Test waist, ctau and a0 ===")

# Load the diags OpenPMD
ts = LpaDiagnostics('./diags/hdf5/')

# Values of waist, ctau and a0 set in the script
laser_waist_simu = ts.get_laser_waist(iteration=ts.iterations[0], pol='x')
ctau_simu = ts.get_ctau(iteration=ts.iterations[0], pol='x')
a0_simu = ts.get_a0(iteration=ts.iterations[0], pol='x')

# Compare the values and crash the code if not equal

assert np.isclose(laser_waist, laser_waist_simu, 5.e-2), "waist error. "
print("waist checked. ")
assert np.isclose(ctau, ctau_simu, 5.e-2), "ctau error. "
print("ctau checked. ")
assert np.isclose(a0, a0_simu, 5.e-2), "a0 error. "
print("a0 checked. ")
        Erestricted.append(Ez[100][i + int(0.0 * len(Ez[100]))])

    EzMinPerSnapshot.append(np.amax(Erestricted))
    #plt.ylim(-6e9,6e9)
    plt.savefig('%sEzLineout_%09i2.png' % (Path + '/EzLineout/', iter),
                bbox_inches='tight')
    plt.close()

    rho, info_rho = ts_particles.get_field(iteration=iter,
                                           field='rho',
                                           plot=True,
                                           **particles)
    plt.savefig('%s/rho_%09i.png' % (Path + '/rho', iter), bbox_inches='tight')
    plt.close()

    a0 = ts_laser.get_a0(iteration=iter, pol='x')
    #print(a0)
    a0PerSnapshot.append(a0)

    waist = ts_laser.get_laser_waist(iteration=iter, pol='x')
    #print(waist)
    PulsewaistPerSnapshot.append(waist)

    length = ts_laser.get_ctau(iteration=iter, pol='x')
    #print(length)
    PulselengthPerSnapshot.append(length)

    ts_particles.get_particle(['z', 'uz'], species='electrons', iteration=iter)
    z_selected, uz_selected = ts_particles.get_particle(
        ['z', 'uz'],
        species='electrons',