implementations.problem_classes.AllenCahn_2D_FFT_gpu module¶
- class allencahn2d_imex(nvars=None, nu=2, eps=0.04, radius=0.25, L=1.0, init_type='circle')[source]¶
Bases:
ptype
Example implementing the two-dimensional Allen-Cahn equation with periodic boundary conditions \(u \in [-1, 1]^2\)
\[\frac{\partial u}{\partial t} = \Delta u + \frac{1}{\varepsilon^2} u (1 - u^\nu)\]on a spatial domain \([-\frac{L}{2}, \frac{L}{2}]^2\), and constant parameter \(\nu\). Different initial conditions can be used, for example, circles of the form
\[u({\bf x}, 0) = \tanh\left(\frac{r - \sqrt{x_i^2 + y_j^2}}{\sqrt{2}\varepsilon}\right),\]or checker-board
\[u({\bf x}, 0) = \sin(2 \pi x_i) \sin(2 \pi y_j),\]or uniform distributed random numbers in \([-1, 1]\) for \(i, j=0,..,N-1\), where \(N\) is the number of spatial grid points. For time-stepping, the problem is treated semi-implicitly, i.e., the diffusion part is solved with Fast-Fourier Tranform (FFT) and the nonlinear term is treated explicitly.
An exact solution is not known, but instead the numerical solution can be compared via a generated reference solution computed by a
SciPy
routine.This class is especially developed for solving it on GPUs using
CuPy
.- Parameters:
nvars (List of int tuples, optional) – Number of unknowns in the problem, e.g.
nvars=[(128, 128), (128, 128)]
.nu (float, optional) – Problem parameter \(\nu\).
eps (float, optional) – Scaling parameter \(\varepsilon\).
radius (float, optional) – Radius of the circles.
L (float, optional) – Denotes the period of the function to be approximated for the Fourier transform.
init_type (str, optional) – Indicates which type of initial condition is used.
- xvalues¶
Grid points in space.
- Type:
cp.1darray
- dx¶
Cupy mesh width.
- Type:
float
- lap¶
Spectral operator for Laplacian.
- Type:
cp.1darray
- dtype_f¶
alias of
imex_cupy_mesh
- dtype_u¶
alias of
cupy_mesh
- eval_f(u, t)[source]¶
Routine to evaluate the right-hand side of the problem.
- Parameters:
u (dtype_u) – Current values of the numerical solution.
t (float) – Current time of the numerical solution is computed.
- Returns:
f – The right-hand side of the problem.
- Return type:
dtype_f
- solve_system(rhs, factor, u0, t)[source]¶
Simple FFT solver for the diffusion part.
- Parameters:
rhs (dtype_f) – Right-hand side for the linear system.
factor (float) – Abbrev. for the node-to-node stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver (not used here so far).
t (float) – Current time (e.g. for time-dependent BCs).
me (dtype_u) – The solution as mesh.
- class allencahn2d_imex_stab(nvars=None, nu=2, eps=0.04, radius=0.25, L=1.0, init_type='circle')[source]¶
Bases:
allencahn2d_imex
This implements the two-dimensional Allen-Cahn equation with periodic boundary conditions \(u \in [-1, 1]^2\) with stabilized splitting
\[\frac{\partial u}{\partial t} = \Delta u + \frac{1}{\varepsilon^2} u (1 - u^\nu) + \frac{2}{\varepsilon^2}u\]on a spatial domain \([-\frac{L}{2}, \frac{L}{2}]^2\), and constant parameter \(\nu\). Different initial conditions can be used here, for example, circles of the form
\[u({\bf x}, 0) = \tanh\left(\frac{r - \sqrt{x_i^2 + y_j^2}}{\sqrt{2}\varepsilon}\right),\]or checker-board
\[u({\bf x}, 0) = \sin(2 \pi x_i) \sin(2 \pi y_j),\]or uniform distributed random numbers in \([-1, 1]\) for \(i, j=0,..,N-1\), where \(N\) is the number of spatial grid points. For time-stepping, the problem is treated semi-implicitly, i.e., the diffusion part is solved with Fast-Fourier Tranform (FFT) and the nonlinear term is treated explicitly.
An exact solution is not known, but instead the numerical solution can be compared via a generated reference solution computed by a
SciPy
routine.This class is especially developed for solving it on GPUs using
CuPy
.- Parameters:
nvars (List of int tuples, optional) – Number of unknowns in the problem, e.g.
nvars=[(128, 128), (128, 128)]
.nu (float, optional) – Problem parameter \(\nu\).
eps (float, optional) – Scaling parameter \(\varepsilon\).
radius (float, optional) – Radius of the circles.
L (float, optional) – Denotes the period of the function to be approximated for the Fourier transform.
init_type (str, optional) – Indicates which type of initial condition is used.
- xvalues¶
Grid points in space.
- Type:
cp.1darray
- dx¶
Cupy mesh width.
- Type:
float
- lap¶
Spectral operator for Laplacian.
- Type:
cp.1darray
- eval_f(u, t)[source]¶
Routine to evaluate the right-hand side of the problem.
- Parameters:
u (dtype_u) – Current values of the numerical solution.
t (float) – Current time of the numerical solution is computed.
- Returns:
f – The right-hand side of the problem.
- Return type:
dtype_f
- solve_system(rhs, factor, u0, t)[source]¶
Simple FFT solver for the diffusion part.
- Parameters:
rhs (dtype_f) – Right-hand side for the linear system.
factor (float) – Abbrev. for the node-to-node stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver (not used here so far).
t (float) – Current time (e.g. for time-dependent BCs).
- Returns:
me – The solution as mesh.
- Return type:
dtype_u