implementations.problem_classes.AllenCahn_1D_FD module¶
- class allencahn_front_finel(nvars=127, dw=-0.04, eps=0.04, newton_maxiter=100, newton_tol=1e-12, interval=(-0.5, 0.5), stop_at_nan=True, stop_at_maxiter=False)[source]¶
Bases:
allencahn_front_fullyimplicit
This class implements the one-dimensional Allen-Cahn equation with driving force using inhomogeneous Dirichlet boundary conditions
\[\frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2} - \frac{2}{\varepsilon^2} u (1 - u) (1 - 2u) - 6 d_w u (1 - u)\]for \(u \in [0, 1]\). Centered finite differences are used for discretization of the Laplacian. The exact solution is given by
\[u(x, t) = 0.5 \left(1 + \tanh\left(\frac{x - vt}{\sqrt{2}\varepsilon}\right)\right)\]with \(v = 3 \sqrt{2} \varepsilon d_w\).
Let \(A\) denote the finite difference matrix to discretize \(\frac{\partial^2 u}{\partial x^2}\). Here, Finel’s trick is used. Let
\[a = \tanh\left(\frac{\Delta x}{\sqrt{2}\varepsilon}\right)^2,\]then, the right-hand side of the problem can be written as
\[\frac{\partial u}{\partial t} = A u - \frac{1}{\Delta x^2} \left[ \frac{1 - a}{1 - a (2u - 1)^2} - 1 \right] (2u - 1).\]For time-stepping, this problem will be treated in a fully-implicit way. The nonlinear system is solved using Newton.
- 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 Newton solver.
- Parameters:
rhs (dtype_f) – Right-hand side for the nonlinear system.
factor (float) – Abbrev. for the node-to-node stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver.
t (float) – Current time (e.g. for time-dependent BCs).
- Returns:
me – The solution as mesh.
- Return type:
dtype_u
- class allencahn_front_fullyimplicit(nvars=127, dw=-0.04, eps=0.04, newton_maxiter=100, newton_tol=1e-12, interval=(-0.5, 0.5), stop_at_nan=True, stop_at_maxiter=False)[source]¶
Bases:
ptype
Example implementing the one-dimensional Allen-Cahn equation with driving force using inhomogeneous Dirichlet boundary conditions
\[\frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2} - \frac{2}{\varepsilon^2} u (1 - u) (1 - 2u) - 6 d_w u (1 - u)\]for \(u \in [0, 1]\). The second order spatial derivative is approximated using centered finite differences. The exact solution is given by
\[u(x, t)= 0.5 \left(1 + \tanh\left(\frac{x - vt}{\sqrt{2}\varepsilon}\right)\right)\]with \(v = 3 \sqrt{2} \varepsilon d_w\). For time-stepping, this problem is implemented to be treated fully-implicit using Newton to solve the nonlinear system.
- Parameters:
nvars (int) – Number of unknowns in the problem.
dw (float) – Driving force.
eps (float) – Scaling parameter \(\varepsilon\).
newton_maxiter (int) – Maximum number of iterations for Newton’s method.
newton_tol (float) – Tolerance for Newton’s method to terminate.
interval (list) – Interval of spatial domain.
stop_at_nan (bool, optional) – Indicates that the Newton solver should stop if
nan
values arise.
- A¶
Second-order FD discretization of the 1D laplace operator.
- Type:
scipy.diags
- dx¶
Distance between two spatial nodes.
- Type:
float
- xvalues¶
Spatial grid values.
- Type:
np.1darray
- uext¶
Contains additionally the external values of the boundary.
- Type:
dtype_u
- work_counters¶
Counter for statistics. Here, number of Newton calls and number of evaluations of right-hand side are counted.
- Type:
- dtype_f¶
alias of
mesh
- dtype_u¶
alias of
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 Newton solver.
- Parameters:
rhs (dtype_f) – Right-hand side for the nonlinear system.
factor (float) – Abbrev. for the node-to-node stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver.
t (float) – Current time (required here for the BC).
- Returns:
me – The solution as mesh.
- Return type:
dtype_u
- class allencahn_front_semiimplicit(nvars=127, dw=-0.04, eps=0.04, newton_maxiter=100, newton_tol=1e-12, interval=(-0.5, 0.5), stop_at_nan=True, stop_at_maxiter=False)[source]¶
Bases:
allencahn_front_fullyimplicit
This class implements the one-dimensional Allen-Cahn equation with driving force using inhomogeneous Dirichlet boundary conditions
\[\frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2} - \frac{2}{\varepsilon^2} u (1 - u) (1 - 2u) - 6 d_w u (1 - u)\]for \(u \in [0, 1]\). Centered finite differences are used for discretization of the second order spatial derivative. The exact solution is given by
\[u(x, t) = 0.5 \left(1 + \tanh\left(\frac{x - vt}{\sqrt{2}\varepsilon}\right)\right)\]with \(v = 3 \sqrt{2} \varepsilon d_w\). For time-stepping, this problem will be treated in a semi-implicit way, i.e., the Laplacian is treated implicitly, and the rest of the right-hand side will be handled explicitly.
- dtype_f¶
alias of
imex_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 linear solver for \((I-factor\cdot A)\vec{u}=\vec{rhs}\).
- Parameters:
rhs (dtype_f) – Right-hand side for the linear system.
factor (float) – Abbrev. for the local stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver.
t (float) – Current time (e.g. for time-dependent BCs).
- Returns:
me – The solution as mesh.
- Return type:
dtype_u
- class allencahn_periodic_fullyimplicit(nvars=128, dw=-0.04, eps=0.04, newton_maxiter=100, newton_tol=1e-12, interval=(-0.5, 0.5), radius=0.25, stop_at_nan=True)[source]¶
Bases:
ptype
Example implementing the one-dimensional Allen-Cahn equation with driving force and periodic boundary conditions
\[\frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2} - \frac{2}{\varepsilon^2} u (1 - u) (1 - 2u) - 6 d_w u (1 - u)\]for \(u \in [0, 1]\). Centered finite differences are used for discretization of the Laplacian. The exact solution is
\[u(x, t) = 0.5 \left(1 + \tanh\left(\frac{r - |x| - vt}{\sqrt{2}\varepsilon}\right)\right)\]with \(v = 3 \sqrt{2} \varepsilon d_w\) and radius \(r\) of the circles. For time-stepping, the problem is treated fully-implicitly, i.e., the nonlinear system is solved by Newton.
- Parameters:
nvars (int) – Number of unknowns in the problem.
dw (float) – Driving force.
eps (float) – Scaling parameter \(\varepsilon\).
newton_maxiter (int) – Maximum number of iterations for Newton’s method.
newton_tol (float) – Tolerance for Newton’s method to terminate.
interval (list) – Interval of spatial domain.
radius (float) – Radius of the circles.
stop_at_nan (bool, optional) – Indicates that the Newton solver should stop if nan values arise.
- A¶
Second-order FD discretization of the 1D laplace operator.
- Type:
scipy.diags
- dx¶
Distance between two spatial nodes.
- Type:
float
- xvalues¶
Spatial grid points.
- Type:
np.1darray
- work_counters¶
Counter for statistics. Here, number of Newton calls and number of evaluations of right-hand side are counted.
- Type:
- dtype_f¶
alias of
mesh
- dtype_u¶
alias of
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 Newton solver.
- Parameters:
rhs (dtype_f) – Right-hand side for the nonlinear system.
factor (float) – Abbrev. for the node-to-node stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver.
t (float) – Current time (required here for the BC).
- Returns:
u – The solution as mesh.
- Return type:
dtype_u
- class allencahn_periodic_multiimplicit(nvars=128, dw=-0.04, eps=0.04, newton_maxiter=100, newton_tol=1e-12, interval=(-0.5, 0.5), radius=0.25, stop_at_nan=True)[source]¶
Bases:
allencahn_periodic_fullyimplicit
This class implements the one-dimensional Allen-Cahn equation with driving force and periodic boundary conditions
\[\frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2} - \frac{2}{\varepsilon^2} u (1 - u) (1 - 2u) - 6 d_w u (1 - u)\]for \(u \in [0, 1]\). For discretization of the second order spatial derivative, centered finite differences are used. The exact solution is then given by
\[u(x, t) = 0.5 \left(1 + \tanh\left(\frac{r - |x| - vt}{\sqrt{2}\varepsilon}\right)\right)\]with \(v = 3 \sqrt{2} \varepsilon d_w\) and radius \(r\) of the circles. For time-stepping, the problem is treated in a multi-implicit fashion, i.e., the nonlinear system containing the part with the Laplacian is solved with a linear solver provided by a
SciPy
routine, and the nonlinear system including the rest of the right-hand side is solved by Newton’s method.- dtype_f¶
alias of
comp2_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 (not used here).
- Returns:
f – The right-hand side of the problem.
- Return type:
dtype_f
- solve_system_1(rhs, factor, u0, t)[source]¶
Simple linear solver for \((I-factor\cdot A)\vec{u}=\vec{rhs}\).
- Parameters:
rhs (dtype_f) – Right-hand side for the linear system.
factor (float) – Abbrev. for the local stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver.
t (float) – Current time (e.g. for time-dependent BCs).
- Returns:
me – The solution as mesh.
- Return type:
dtype_u
- solve_system_2(rhs, factor, u0, t)[source]¶
Simple linear solver for \((I-factor\cdot A)\vec{u}=\vec{rhs}\).
- Parameters:
rhs (dtype_f) – Right-hand side for the linear system.
factor (float) – Abbrev. for the local stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver.
t (float) – Current time (e.g. for time-dependent BCs).
- Returns:
me – The solution as mesh.
- Return type:
dtype_u
- class allencahn_periodic_semiimplicit(nvars=128, dw=-0.04, eps=0.04, newton_maxiter=100, newton_tol=1e-12, interval=(-0.5, 0.5), radius=0.25, stop_at_nan=True)[source]¶
Bases:
allencahn_periodic_fullyimplicit
This class implements the one-dimensional Allen-Cahn equation with driving force and periodic boundary conditions
\[\frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2} - \frac{2}{\varepsilon^2} u (1 - u) (1 - 2u) - 6 d_w u (1 - u)\]for \(u \in [0, 1]\). For discretization of the Laplacian, centered finite differences are used. The exact solution is
\[u(x, t) = 0.5 \left(1 + \tanh\left(\frac{r - |x| - vt}{\sqrt{2}\varepsilon}\right)\right)\]with \(v = 3 \sqrt{2} \varepsilon d_w\) and radius \(r\) of the circles. For time-stepping, the problem is treated in semi-implicit way, i.e., the part containing the Laplacian is treated implicitly, and the rest of the right-hand side is only evaluated at each time.
- dtype_f¶
alias of
imex_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 linear solver for \((I-factor\cdot A)\vec{u}=\vec{rhs}\).
- Parameters:
rhs (dtype_f) – Right-hand side for the linear system.
factor (float) – Abbrev. for the local stepsize (or any other factor required).
u0 (dtype_u) – Initial guess for the iterative solver.
t (float) – Current time (e.g. for time-dependent BCs).
- Returns:
me – The solution as mesh.
- Return type:
dtype_u