@@ -53,7 +53,8 @@ def write_to_openpmd_file(
53
53
Whether the envelope is converted to normalized vector potential
54
54
before writing to file.
55
55
"""
56
- array = grid .get_temporal_field ()
56
+ # Get field on CPU
57
+ array = grid .get_temporal_field (to_cpu = True )
57
58
58
59
# Create file
59
60
series = io .Series ("{}_%05T.{}" .format (file_prefix , file_format ), io .Access .create )
@@ -76,7 +77,7 @@ def write_to_openpmd_file(
76
77
m .axis_labels = ["t" , "r" ]
77
78
78
79
# Store metadata needed to reconstruct the field
79
- m .set_attribute ("angularFrequency" , 2 * xp .pi * c / wavelength )
80
+ m .set_attribute ("angularFrequency" , 2 * np .pi * c / wavelength )
80
81
m .set_attribute ("polarization" , pol )
81
82
if save_as_vector_potential :
82
83
m .set_attribute ("envelopeField" , "normalized_vector_potential" )
@@ -91,20 +92,20 @@ def write_to_openpmd_file(
91
92
}
92
93
93
94
if save_as_vector_potential :
94
- array = field_to_vector_potential (grid , 2 * xp .pi * c / wavelength )
95
+ array = field_to_vector_potential (grid , 2 * np .pi * c / wavelength )
95
96
96
97
# Pick the correct field
97
98
if dim == "xyt" :
98
99
# Switch from x,y,t (internal to lasy) to t,y,x (in openPMD file)
99
100
# This is because many PIC codes expect x to be the fastest index
100
- data = xp .transpose (array ).copy ()
101
+ data = np .transpose (array ).copy ()
101
102
elif dim == "rt" :
102
103
# The representation of modes in openPMD
103
104
# (see https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#required-attributes-for-each-mesh-record)
104
105
# is different than the representation of modes internal to lasy.
105
106
# Thus, there is a non-trivial conversion here
106
107
ncomp = 2 * grid .n_azimuthal_modes - 1
107
- data = xp .zeros ((ncomp , grid .npoints [0 ], grid .npoints [1 ]), dtype = array .dtype )
108
+ data = np .zeros ((ncomp , grid .npoints [0 ], grid .npoints [1 ]), dtype = array .dtype )
108
109
data [0 , :, :] = array [0 , :, :]
109
110
for mode in range (1 , grid .n_azimuthal_modes ):
110
111
# cos(m*theta) part of the mode
@@ -113,12 +114,12 @@ def write_to_openpmd_file(
113
114
data [2 * mode , :, :] = - 1.0j * array [mode , :, :] + 1.0j * array [- mode , :, :]
114
115
# Switch from m,r,t (internal to lasy) to m,t,r (in openPMD file)
115
116
# This is because many PIC codes expect r to be the fastest index
116
- data = xp .transpose (data , axes = [0 , 2 , 1 ]).copy ()
117
+ data = np .transpose (data , axes = [0 , 2 , 1 ]).copy ()
117
118
118
119
# Define the dataset
119
120
dataset = io .Dataset (data .dtype , data .shape )
120
121
env = m [io .Mesh_Record_Component .SCALAR ]
121
- env .position = xp .zeros (len (dim ), dtype = xp .float64 )
122
+ env .position = np .zeros (len (dim ), dtype = np .float64 )
122
123
env .reset_dataset (dataset )
123
124
env .store_chunk (data )
124
125
0 commit comments