Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 25, 2023
1 parent c3bc107 commit e9d758b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
18 changes: 9 additions & 9 deletions lasy/laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ def normalize(self, value, kind="energy"):
else:
raise ValueError(f'kind "{kind}" not recognized')

def propagate(self, distance, initial_optical_element=None,
nr_boundary=None, backend="NP"):
def propagate(
self, distance, initial_optical_element=None, nr_boundary=None, backend="NP"
):
"""
Propagate the laser pulse by the distance specified.
Expand Down Expand Up @@ -201,10 +202,9 @@ def propagate(self, distance, initial_optical_element=None,
omega_shape = (1, 1, self.grid.field.shape[time_axis_indx])

if self.dim == "rt":

# Apply optical element
# Apply optical element
if initial_optical_element is not None:
r, w = np.meshgrid( self.grid.axes[0], omega, indexing="ij")
r, w = np.meshgrid(self.grid.axes[0], omega, indexing="ij")
# The line below assumes that amplitude_multiplier
# is cylindrically-symmetric, hence we pass
# `r` as `x` and 0 as `y`
Expand Down Expand Up @@ -232,11 +232,11 @@ def propagate(self, distance, initial_optical_element=None,
self.prop[i_m].step(transform_data, distance, overwrite=True)
field_fft[i_m, :, :] = np.transpose(transform_data).copy()
else:

# Apply optical element
# Apply optical element
if initial_optical_element is not None:
x, y, w = np.meshgrid(self.grid.axes[0], self.grid.axes[1],
omega, indexing="ij")
x, y, w = np.meshgrid(
self.grid.axes[0], self.grid.axes[1], omega, indexing="ij"
)
field_fft *= initial_optical_element.amplitude_multiplier(x, y, w)

# Construct the propagator (check if exists)
Expand Down
2 changes: 1 addition & 1 deletion lasy/optical_elements/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .parabolic_mirror import ParabolicMirror

__all__ = ['ParabolicMirror']
__all__ = ["ParabolicMirror"]
11 changes: 5 additions & 6 deletions lasy/optical_elements/axiparabola.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from scipy.constants import c


class AxiParabolaWithDelay(OpticalElement):
r"""
Class that represents the combination of an axiparabola with
Expand Down Expand Up @@ -39,19 +40,17 @@ def __init__(self, f0, delta, R):
# Assuming uniform intensity on the axiparabola, and in order to get
# a z-independent intensity over the focal range, we need
# (see Eq. 6 in Oubrerie et al.)
z_foc = lambda r: self.f0 + self.delta * (r/self.R)**2
z_foc = lambda r: self.f0 + self.delta * (r / self.R) ** 2

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable z_foc is not used.

# Solve Eq. 2 in Oubrerie et al. to find the sag function

def amplitude_multiplier(self, x, y, omega):


# Interpolation
sag = np.zeros_like(x)

# Calculate phase shift
T = np.exp( -2j*(omega/c)*sag )
T = np.exp(-2j * (omega / c) * sag)
# Remove intensity beyond R
T[ x**2 + y**2 > self.R**2 ] = 0
T[x**2 + y**2 > self.R**2] = 0

return T
return T
1 change: 1 addition & 0 deletions lasy/optical_elements/optical_element.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np


class OpticalElement(object):
"""
Base class to model thin optical elements.
Expand Down
3 changes: 2 additions & 1 deletion lasy/optical_elements/parabolic_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from scipy.constants import c


class ParabolicMirror(OpticalElement):
r"""
Derived class for a parabolic mirror.
Expand All @@ -27,4 +28,4 @@ def __init__(self, f):
self.f = f

def amplitude_multiplier(self, x, y, omega):
return np.exp( -1j*omega*(x**2 + y**2)/(2*c*self.f) )
return np.exp(-1j * omega * (x**2 + y**2) / (2 * c * self.f))
10 changes: 7 additions & 3 deletions tests/test_parabolic_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
tau = 30.0e-15 # s
gaussian_profile = GaussianProfile(wavelength, pol, laser_energy, w0, tau, t_peak)


def get_w0(laser):
# Calculate the laser waist
if laser.dim == "xyt":
Expand All @@ -42,16 +43,18 @@ def get_w0(laser):

return sigma


def check_parabolic_mirror(laser):
# Propagate laser after parabolic mirror + vacuum
f0 = 8. # focal distance in m
laser.propagate( f0, initial_optical_element=ParabolicMirror( f=f0 ) )
f0 = 8.0 # focal distance in m
laser.propagate(f0, initial_optical_element=ParabolicMirror(f=f0))
# Check that the value is the expected one in the near field
w0_num = get_w0(laser)
w0_theor = wavelength * f0 / (np.pi*w0)
w0_theor = wavelength * f0 / (np.pi * w0)
err = 2 * np.abs(w0_theor - w0_num) / (w0_theor + w0_num)
assert err < 1e-3


def test_3D_case():
# - 3D case
# The laser is initialized in the near field
Expand All @@ -63,6 +66,7 @@ def test_3D_case():
laser = Laser(dim, lo, hi, npoints, gaussian_profile)
check_parabolic_mirror(laser)


def test_RT_case():
# - Cylindrical case
# The laser is initialized in the near field
Expand Down

0 comments on commit e9d758b

Please sign in to comment.