Commit 60e09405 authored by Leon Merten Lohse's avatar Leon Merten Lohse
Browse files

add flake8

parent 748b52a3
Pipeline #174164 failed with stage
in 30 seconds
image: python:3-alpine
stages:
- lint
pylint:
image: "python:latest"
flake8:
stage: lint
script:
- pip install pylint
- pylint fresnel
- flake8 --max-line-length=120 fresnel/*py
......@@ -11,11 +11,10 @@ class Solver2d():
dtype = np.complex128
def __init__(self, Az, Axx, F0, u0, dz, dx):
self._nx = u0.shape[-1]
self._ones = np.ones((self._nx,), dtype = self.dtype)
self._ones = np.ones((self._nx,), dtype=self.dtype)
self._boundary_slice = np.zeros_like(self._ones)
self.u = u0 * self._ones
......@@ -26,28 +25,24 @@ class Solver2d():
self.rz = self._compute_rz(Az)
self.rxx = self._compute_rxx(Axx)
self.f = self._compute_f(F0)
def _compute_rz(self, Az):
return Az * self._ones
def _compute_rxx(self, Axx):
return -Axx * self.dz / 2. / self.dx**2 * self._ones
return -Axx * self.dz / 2. / self.dx**2 * self._ones
def _compute_f(self, F):
return F * self.dz / 2. * self._ones
def step(self, F, boundary):
up = self.u
fp = self.f
self.f = self._compute_f(F)
u = self._boundary_slice
u = self._boundary_slice
# set boundary values
u[0] = boundary[0]
......@@ -58,20 +53,18 @@ class Solver2d():
return self.u
class Solver2dfull():
"""
Solver for 2d PDEs of the form
Az(x) * u_z = Axx(x) * u_xx + Ax(x) * u_x + F(x,z) * u
"""
dtype = np.complex128
def __init__(self, Az, Axx, Ax, F0, u0, dz, dx):
self._nx = u0.shape[-1]
self._ones = np.ones((self._nx,), dtype = self.dtype)
self._ones = np.ones((self._nx,), dtype=self.dtype)
self._boundary_slice = np.zeros_like(self._ones)
self.u = u0 * self._ones
......@@ -83,58 +76,53 @@ class Solver2dfull():
self.rxx = self._compute_rxx(Axx)
self.rx = self._compute_rx(Ax)
self.f = self._compute_f(F0)
def _compute_rz(self, Az):
return Az * self._ones
def _compute_rxx(self, Axx):
return -Axx * self.dz / 2. / self.dx**2 * self._ones
return -Axx * self.dz / 2. / self.dx**2 * self._ones
def _compute_rx(self, Ax):
return -Ax * self.dz / 4. / self.dx * self._ones
return -Ax * self.dz / 4. / self.dx * self._ones
def _compute_f(self, F):
return F * self.dz / 2. * self._ones
def step(self, F, boundary):
up = self.u
fp = self.f
self.f = self._compute_f(F)
u = self._boundary_slice
u = self._boundary_slice
# set boundary values
u[0] = boundary[0]
u[-1] = boundary[1]
self.u = _solver.step1d_AAF(self.rz, self.rxx, self.rx, fp, self.f, up, u)
self.u = _solver.step1d_AAF(self.rz, self.rxx, self.rx,
fp, self.f, up, u)
return self.u
class Solver3d():
"""
Solver for equations of the form
Az * u_z = Axx * u_xx + Ayy * u_yy + F(x,y,z) * u
Az, Axx, Ayy are complex constants.
"""
dtype = np.complex128
def __init__(self, Az, Axx, Ayy, F0, u0, dz, dy, dx):
def __init__(self, Az, Axx, Ayy, F0, u0, dz, dy, dx):
self._nx = u0.shape[-1]
self._ny = u0.shape[-2]
self._ones = np.ones((self._ny, self._nx,), dtype = self.dtype)
self._ones = np.ones((self._ny, self._nx,), dtype=self.dtype)
self._boundary_slice = np.zeros_like(self._ones)
self.u = u0 * self._ones
......@@ -142,46 +130,41 @@ class Solver3d():
self.dx = dx
self.dy = dy
self.dz = dz
self.rz = self._compute_rz(Az)
self.rxx = self._compute_rxx(Axx)
self.ryy = self._compute_ryy(Ayy)
self.f = self._compute_f(F0)
def _compute_rz(self, Az):
return Az * (1+0j)
def _compute_rxx(self, Axx):
return -Axx * self.dz / 2. / self.dx**2 * (1+0j)
return -Axx * self.dz / 2. / self.dx**2 * (1+0j)
def _compute_ryy(self, Ayy):
return -Ayy * self.dz / 2. / self.dy**2 * (1+0j)
return -Ayy * self.dz / 2. / self.dy**2 * (1+0j)
def _compute_f(self, F):
return F * self.dz / 4. * self._ones
def step(self, F, boundary):
up = self.u
fp = self.f
self.f = self._compute_f(F)
self.f = self._compute_f(F)
u = self._boundary_slice
u = self._boundary_slice
# set boundary values
u[ 0,:] = boundary[0]
u[-1,:] = boundary[1]
u[0, :] = boundary[0]
u[-1, :] = boundary[1]
u[:, 0] = boundary[2]
u[:,-1] = boundary[3]
u[:, -1] = boundary[3]
# the C++ functions use Eigen3 internally, which requires C-Major data storage
u_T = _solver.step2d_A0Fs(self.rz, self.rxx, self.ryy, fp.T, self.f.T, up.T, u.T)
self.u = u_T.T
return self.u
\ No newline at end of file
return self.u
import numpy as np
from pyfftw.interfaces.numpy_fft import fftfreq, ifftshift, fftshift
from pyfftw.interfaces.numpy_fft import fftfreq
def fftfreqn(N, d=1.0):
ndim = len(N)
d *= np.ones(ndim)
# index trick: n'th line is a list of ones with a -1 on n'th position
......@@ -20,12 +20,12 @@ def gridn(N):
# index trick: n'th line is a list of ones with a -1 on n'th position
shapes = np.ones((ndim, ndim), dtype='int') - 2 * np.eye(ndim, dtype='int')
x = [np.reshape(np.arange(-N[dim]+1, N[dim]), tuple(shapes[dim, :])) for dim in range(ndim)]
return x
def crop(a, crop_width):
slices = [slice(w[0], -w[1] if w[1] > 0 else None) for w in crop_width]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment