From 1ebfed117e098b211c83d196c1939611e1524b40 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 9 Jan 2020 17:54:17 +0100 Subject: fixed small bug --- .../Modules/laser_injection_from_file/analysis.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'Examples/Modules/laser_injection_from_file/analysis.py') diff --git a/Examples/Modules/laser_injection_from_file/analysis.py b/Examples/Modules/laser_injection_from_file/analysis.py index b8d0899f0..d1ef8a001 100755 --- a/Examples/Modules/laser_injection_from_file/analysis.py +++ b/Examples/Modules/laser_injection_from_file/analysis.py @@ -80,6 +80,11 @@ def gauss_env(T,XX,ZZ): return E_max * np.real(np.exp(exp_arg)) def write_file(fname, x, y, t, E): + """ For a given filename fname, space coordinates x and y, time coordinate t + and field E, write a WarpX-compatible input binary file containing the + profile of the laser pulse + """ + with open(fname, 'wb') as file: flag_unif = 0 file.write(flag_unif.to_bytes(1, byteorder='little')) @@ -93,6 +98,12 @@ def write_file(fname, x, y, t, E): def write_file_unf(fname, x, y, t, E): + """ For a given filename fname, space coordinates x and y, time coordinate t + and field E, write a WarpX-compatible input binary file containing the + profile of the laser pulse. This function should be used in the case + of a uniform spatio-temporal mesh + """ + with open(fname, 'wb') as file: flag_unif = 1 file.write(flag_unif.to_bytes(1, byteorder='little')) @@ -103,11 +114,13 @@ def write_file_unf(fname, x, y, t, E): file.write(t[-1].tobytes()) file.write(x[0].tobytes()) file.write(x[-1].tobytes()) - file.write(y[0].tobytes()) - file.write(y[-1].tobytes()) + if len(y) == 1 : + file.write(y[0].tobytes()) + else : + file.write(y[0].tobytes()) + file.write(y[-1].tobytes()) file.write(E.tobytes()) - def create_gaussian_2d(): T, X, Y = np.meshgrid(tcoords, xcoords, np.array([0.0]), indexing='ij') E_t = gauss(T,X,Y,'2d') -- cgit v1.2.3