Skip to content
Snippets Groups Projects
Commit f8d4cd39 authored by Pierre Augier's avatar Pierre Augier
Browse files

Cache phase_shift and test _get_phase_shift in 2d and 3d

parent 0bb16db3
No related branches found
No related tags found
1 merge request!156Topic/default/phaseshift3d
......@@ -216,8 +216,10 @@
def _get_phase_shift(self):
"""Compute the phase shift term."""
if hasattr(self, "_phase_shift") and self._phase_shift is not None:
return self._phase_shift
oper = self.sim.oper
ndim = len(oper.axes)
if ndim == 1:
phase = 0.5 * oper.deltax * oper.kx
elif ndim == 2:
......@@ -219,9 +221,9 @@
oper = self.sim.oper
ndim = len(oper.axes)
if ndim == 1:
phase = 0.5 * oper.deltax * oper.kx
elif ndim == 2:
phase = 0.5 * (oper.deltax * oper.Kx + oper.deltay * oper.Ky)
phase = 0.5 * (oper.deltax * oper.KX + oper.deltay * oper.KY)
elif ndim == 3:
phase = 0.5 * (
oper.deltax * oper.Kx
......@@ -230,8 +232,8 @@
)
else:
raise NotImplementedError
return np.exp(1j * phase)
self._phase_shift = np.exp(1j * phase)
return self._phase_shift
def _get_phase_shift_random(self):
"""Compute two random phase shift terms."""
......
......@@ -143,6 +143,11 @@
sim.time_stepping.start()
# testing phase_shift
phase_shift = sim.time_stepping._get_phase_shift()
assert phase_shift.shape == sim.oper.KX.shape
assert sim.time_stepping._get_phase_shift() is phase_shift
sim.state.compute("rot_fft")
sim.state.compute("rot_fft")
......
......@@ -102,6 +102,11 @@
sim = self.sim
sim.time_stepping.start()
# testing phase_shift
phase_shift = sim.time_stepping._get_phase_shift()
assert phase_shift.shape == sim.oper.Kx.shape
assert sim.time_stepping._get_phase_shift() is phase_shift
if mpi.nb_proc == 1:
phys_fields = sim.output.phys_fields
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment