implementations.problem_classes.HeatEquation_2D_PETSc_forced module

class heat2d_petsc_forced(cnvars, nu, freq, refine, comm=petsc4py.PETSc.COMM_WORLD, sol_tol=1e-10, sol_maxiter=None)[source]

Bases: ptype

Example implementing the forced two-dimensional heat equation with Dirichlet boundary conditions \((x, y) \in [0,1]^2\)

\[\frac{\partial u}{\partial t} = \nu \left( \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} \right) + f(x, y, t)\]

and forcing term \(f(x, y, t)\) such that the exact solution is

\[u(x, y, t) = \sin(2 \pi x) \sin(2 \pi y) \cos(t).\]

The spatial discretization uses central finite differences and is realized with PETSc [1], [2].

Parameters:
  • cnvars (tuple, optional) – Spatial resolution for the 2D problem, e.g. cnvars=(16, 16).

  • nu (float, optional) – Diffusion coefficient \(\nu\).

  • freq (int, optional) – Spatial frequency of the initial conditions (equal for both dimensions).

  • refine (int, optional) – Defines the refinement of the mesh, e.g. refine=2 means the mesh is refined with factor 2.

  • comm (COMM_WORLD) – Communicator for PETSc.

  • sol_tol (float, optional) – Tolerance that the solver needs to satisfy for termination.

  • sol_maxiter (int, optional) – Maximum number of iterations for the solver to terminate.

A

Second-order FD discretization of the 2D Laplace operator.

Type:

PETSc matrix object

Id

Identity matrix.

Type:

PETSc matrix object

dx

Distance between two spatial nodes in x direction.

Type:

float

dy

Distance between two spatial nodes in y direction.

Type:

float

ksp

PETSc linear solver object.

Type:

object

ksp_ncalls

Calls of PETSc’s linear solver object.

Type:

int

ksp_itercount

Iterations done by PETSc’s linear solver object.

Type:

int

References

dtype_f

alias of petsc_vec_imex

dtype_u

alias of petsc_vec

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 at.

Returns:

f – Right-hand side of the problem.

Return type:

dtype_f

solve_system(rhs, factor, u0, t)[source]

KSP 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 – Solution.

Return type:

dtype_u

u_exact(t)[source]

Routine to compute the exact solution at time \(t\).

Parameters:

t (float) – Time of the exact solution.

Returns:

me – Exact solution.

Return type:

dtype_u