Exemplo n.º 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 )
Exemplo n.º 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)
Exemplo n.º 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. ")
import os.path
import numpy as np
from os.path import basename
import matplotlib.pyplot as plt
from opmd_viewer import OpenPMDTimeSeries
from opmd_viewer.addons import LpaDiagnostics
from scipy.ndimage.filters import gaussian_filter
from scipy import fftpack
from scipy.signal import savgol_filter

from mpl_toolkits import mplot3d
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm

ts_laser = LpaDiagnostics('./diags/hdf5/', check_all_files=False)
ts_particles = OpenPMDTimeSeries('./diags/hdf5/', check_all_files=False)

fields = {'cmap': 'coolwarm'}
particles = {'cmap': 'jet'}

SimulationName = 'TrailingPulse_PulseTrain'

#Make directories for plots
Path = 'Plots_' + SimulationName
if not os.path.exists(Path):
    os.makedirs(Path)
if not os.path.exists(Path + '/EzLineout'):
    os.makedirs(Path + '/EzLineout')
if not os.path.exists(Path + '/ExLineout'):
    os.makedirs(Path + '/ExLineout')
Exemplo n.º 5
0
import os
import math
import os.path
import numpy as np
from os.path import basename
import matplotlib.pyplot as plt
from opmd_viewer import OpenPMDTimeSeries
from opmd_viewer.addons import LpaDiagnostics
from scipy.ndimage.filters import gaussian_filter

ts_laser = LpaDiagnostics('./diags/hdf5/', check_all_files=False)
ts_particles = OpenPMDTimeSeries('./diags/hdf5/', check_all_files=False)

fields = {'cmap': 'coolwarm'}
particles = {'cmap': 'jet'}

SimulationName = 'BeamLoading_PulseTrain'

#Make directories for plots
Path = 'Plots_' + SimulationName
if not os.path.exists(Path):
    os.makedirs(Path)
if not os.path.exists(Path + '/EzLineout'):
    os.makedirs(Path + '/EzLineout')
if not os.path.exists(Path + '/LaserEnvelope'):
    os.makedirs(Path + '/LaserEnvelope')
if not os.path.exists(Path + '/LaserEnvelope/Lineout'):
    os.makedirs(Path + '/LaserEnvelope/Lineout')
if not os.path.exists(Path + '/rho'):
    os.makedirs(Path + '/rho')
if not os.path.exists('TextFiles'):
import os
import math
import os.path
import numpy as np
from os.path import basename
import matplotlib.pyplot as plt
from opmd_viewer import OpenPMDTimeSeries
from opmd_viewer.addons import LpaDiagnostics
from scipy.ndimage.filters import gaussian_filter

ts_laser = LpaDiagnostics('./diags/hdf5/', check_all_files=False)
ts_particles = OpenPMDTimeSeries('./diags/hdf5/', check_all_files=False)

fields = {'cmap': 'coolwarm'}
particles = {'cmap': 'jet'}

SimulationName = 'PulseTrainSimulation'

#Make directories for plots
Path = 'Plots' + SimulationName
if not os.path.exists(Path):
    os.makedirs(Path)
if not os.path.exists(Path + '/EzLineout'):
    os.makedirs(Path + '/EzLineout')

if not os.path.exists(Path + '/LaserEnvelope'):
    os.makedirs(Path + '/LaserEnvelope')
if not os.path.exists(Path + '/LaserEnvelope/Lineout'):
    os.makedirs(Path + '/LaserEnvelope/Lineout')
if not os.path.exists(Path + '/rho'):
    os.makedirs(Path + '/rho')
Exemplo n.º 7
0
 def __init__(self, filename, species, slice_size, filterselection):
     self.filename = filename
     self.species = species
     self.slice_size = slice_size
     self.ts_2d = LpaDiagnostics(filename + 'h5/')
import os
import math
import os.path
import numpy as np
from os.path import basename
import matplotlib.pyplot as plt
from opmd_viewer import OpenPMDTimeSeries
from opmd_viewer.addons import LpaDiagnostics
from scipy.ndimage.filters import gaussian_filter
from scipy import fftpack
from scipy.signal import savgol_filter

ts_laser = LpaDiagnostics('./diags/hdf5/', check_all_files=False)
ts_particles = OpenPMDTimeSeries('./diags/hdf5/', check_all_files=False)

fields = {'cmap': 'coolwarm'}
particles = {'cmap': 'jet'}

SimulationName = 'TrailingPulse_PulseTrain'

#Make directories for plots
Path = 'Plots_' + SimulationName
if not os.path.exists(Path):
    os.makedirs(Path)
if not os.path.exists(Path + '/EzLineout'):
    os.makedirs(Path + '/EzLineout')
if not os.path.exists(Path + '/ExLineout'):
    os.makedirs(Path + '/ExLineout')
if not os.path.exists(Path + '/ExLineoutTrailingPulse'):
    os.makedirs(Path + '/ExLineoutTrailingPulse')
if not os.path.exists(Path + '/LaserEnvelope'):
Exemplo n.º 9
0
    #tslider=widgets.HBox([timestep,out])
    display(tslider)
    filterCheckbox = Darstellungen.createCheckbox(filterselection,
                                                  '<b>Filter:</b>')
    display(button1)


# In[6]:

filename = "/media/bigdata_runs/initial/simOutput/"
#filename="/bigdata/hplsim/external/bercea20/runs/initial/simOutput/"

species = 'e'
#slice_size = 1024**2
slice_size = 1024
ts_2d = LpaDiagnostics(filename + 'h5/')


class timestep:
    __slots__ = 'value'


timestep = timestep()
timestep.value = 5000

#FilterDictValues
FDV = {
    'gamma': (0, 250),
    # coords in meters
    'x': [-5 * 1e-6, 5 * 1e-6],
    'y': [-5 * 1e-6, 5 * 1e-6],