implementations.problem_classes.AdvectionDiffusionEquation_1D_FFT module¶
- class advectiondiffusion1d_imex(nvars=256, c=1.0, freq=-1, nu=0.02, L=1.0)[source]¶
Bases:
ptype
Example implementing the unforced one-dimensional advection diffusion equation
\[\frac{\partial u(x,t)}{\partial t} = - c \frac{\partial u(x,t)}{\partial x} + \nu \frac{\partial^2 u(x,t)}{\partial x^2}\]with periodic boundary conditions in \([-\frac{L}{2}, \frac{L}{2}]\) in spectral space. The advection part \(- c \frac{\partial u(x,t)}{\partial x}\) is treated explicitly, whereas the diffusion part \(\nu \frac{\partial^2 u(x,t)}{\partial x^2}\) will be treated numerically in an implicit way. The exact solution is given by
\[u(x, t) = \sin(\omega (x - c t)) \exp(-t \nu \omega^2)\]for \(\omega=2 \pi k\), where \(k\) denotes the wave number. Fast Fourier transform is used for the spatial discretization.
- Parameters:
nvars (int, optional) – Number of points in spatial discretization.
c (float, optional) – Advection speed \(c\).
freq (int, optional) – Wave number \(k\).
nu (float, optional) – Diffusion coefficient \(\nu\).
L (float, optional) – Denotes the period of the function to be approximated for the Fourier transform.
- xvalues¶
Contains the grid points in space.
- Type:
np.1darray
- ddx¶
Spectral operator for gradient.
- Type:
np.1darray
- lap¶
Spectral operator for Laplacian.
- Type:
np.1darray
- dtype_f¶
alias of
imex_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 at which 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
- class advectiondiffusion1d_implicit(nvars=256, c=1.0, freq=-1, nu=0.02, L=1.0)[source]¶
Bases:
advectiondiffusion1d_imex
Example implementing the unforced one-dimensional advection diffusion equation
\[\frac{\partial u(x,t)}{\partial t} = - c \frac{\partial u(x,t)}{\partial x} + \nu \frac{\partial^2 u(x,t)}{\partial x^2}\]with periodic boundary conditions in \([-\frac{L}{2}, \frac{L}{2}]\) in spectral space. This class implements the problem solving it with fully-implicit time-stepping. The exact solution is given by
\[u(x, t) = \sin(\omega (x - c t)) \exp(-t \nu \omega^2)\]for \(\omega=2 \pi k\), where \(k\) denotes the wave number. Fast Fourier transform is used for the spatial discretization.
Note
This class has the same attributes as the class it inherits from.
- 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 at which 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 and advection part (both are linear!).
- 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