Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem reading lasy file with rt geometry #343

Open
delaossa opened this issue Jan 20, 2025 · 1 comment
Open

Problem reading lasy file with rt geometry #343

delaossa opened this issue Jan 20, 2025 · 1 comment

Comments

@delaossa
Copy link
Contributor

delaossa commented Jan 20, 2025

Lasy is failing to read back a laser file (created by lasy itself) in rt geometry.

Check this piece of code based on one of the tutorials

from lasy.laser import Laser
from lasy.profiles.gaussian_profile import GaussianProfile
from lasy.profiles.from_openpmd_profile import FromOpenPMDProfile

wavelength = 800e-9  # Laser wavelength in meters
polarization = (1, 0)  # Linearly polarized in the x direction
energy = 1.5  # Energy of the laser pulse in joules
spot_size = 25e-6  # Waist of the laser pulse in meters
pulse_duration = 30e-15  # Pulse duration of the laser in seconds
t_peak = 0.0  # Location of the peak of the laser pulse in time

laser_profile = GaussianProfile(
    wavelength, polarization, energy, spot_size, pulse_duration, t_peak
)

dimensions = "rt"  # Use cylindrical geometry
lo = (0, -2.5 * pulse_duration)  # Lower bounds of the simulation box
hi = (5 * spot_size, 2.5 * pulse_duration)  # Upper bounds of the simulation box
num_points = (300, 500)  # Number of points in each dimension

laser = Laser(dimensions, lo, hi, num_points, laser_profile)

file_prefix = "test_output"  # The file name will start with this prefix
file_format = "h5"  # Format to be used for the output file
laser.write_to_file(file_prefix, file_format, write_dir='.')

lasy_profile = FromOpenPMDProfile(
            path='.',
            iteration=0,
            pol=(1, 0),
            field='laserEnvelope',
            prefix=file_prefix,
            theta=0,
        )

which fails when reading back the file, throwing this error:

ValueError: There are 300 points and 1 values in dimension 0

I have tracked the error to this line:

self.combined_field_interp = RegularGridInterpolator(

The reason why it fails is that RegularGridInterpolator is waiting a 2d array, but a 3d one is passed.
This comes from adding the azimuthal dimension to the read field in here:

F = F[np.newaxis, :]

In principle, one would have to make the combined_field_interp to account for the different azimuthal modes.
However, in the way the field is read at the moment in FromOpenPMDProfile, the azimuthal dimension will always have just one element.
So, for now, a quick workaround would be to take only the first (and only) mode.

See here -> PR #344

@MaxThevenet
Copy link
Contributor

Axisymmetric works OK now thanks to #344, but full mode decomposition still to be implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants