C++ Example Problems
Parallel Matrix-Free Example: kin_heat2D_nonlin_p
As an illustration using KINSOL for the solution of nonlinear systems in
parallel, we give a sample program called kin_heat2D_nonlin_p.cpp
. It uses
the KINSOL fixed-point (KIN_FP
) iteration with Anderson Acceleration and the
MPI parallel vector for the solution of a
steady-state 2D heat equation with an additional nonlinear term defined by
\(c(u)\):
where \(D\) is a diagonal matrix with entries \(k_x\) and \(k_y\) for the diffusivity in the \(x\) and \(y\) directions, respectively. The boundary conditions are
We chose the analytical solution to be
Hence, we define the static term \(b\) as follows
The spatial derivatives are computed using second-order centered differences, with the data distributed over \(n_x \times n_y\) points on a uniform spatial grid. The problem is set up to use spatial grid parameters \(n_x=64\) and \(n_y=64\), with heat conductivity parameters \(k_x=1.0\) and \(k_y=1.0\).
This problem is solved via a fixed point iteration with Anderson acceleration, where the fixed point is function formed by adding \(u\) to both sides of the equation, i.e.,
so that the fixed point function is
The problem is run using a tolerance of \(10^{-8}\), and a starting vector
containing all ones. This example highlights the use of the various
orthogonalization routine options within Anderson Acceleration, passed to the
example problem via the --orthaa
flag. Available options include 0
(KIN_ORTH_MGS
), 1 (KIN_ORTH_ICWY
), 2 (KIN_ORTH_CGS2
), and 3
(KIN_ORTH_DCGS2
).
The following tables contain all available input parameters when running the example problem.
Optional Input Parameter Flags
Flag |
Description |
---|---|
|
mesh points in the x and y directions |
|
number of MPI processes in the x and y directions |
|
domain upper bound in the x and y direction |
|
diffusion coefficients |
|
relative tolerance |
|
number of previous residuals for Anderson Acceleration |
|
damping parameter for Anderson Acceleration |
|
orthogonalization routine used in Anderson Acceleration |
|
max number of iterations |
|
nonlinear function choice (integer between 1 - 17) |
|
print timing data |
|
print available input parameters and exit |
Input Parameter Flags for Nonlinear Function \(c(u)\)
Flag |
Function |
---|---|
|
\(c(u) = u\) |
|
\(c(u) = u^3 - u\) |
|
\(c(u) = u - u^2\) |
|
\(c(u) = e^u\) |
|
\(c(u) = u^4\) |
|
\(c(u) = \cos^2(u) - \sin^2(u)\) |
|
\(c(u) = \cos^2(u) - \sin^2(u) - e^u\) |
|
\(c(u) = e^u u^4 - u e^{\cos(u)}\) |
|
\(c(u) = e^{(\cos^2(u))}\) |
|
\(c(u) = 10(u - u^2)\) |
|
\(c(u) = -13 + u + ((5-u)u - 2)u\) |
|
\(c(u) = \sqrt{5}(u - u^2)\) |
|
\(c(u) = (u - e^u)^2 + (u + u \sin(u) - \cos(u))^2\) |
|
\(c(u) = u + u e^u + u e^{-u}\) |
|
\(c(u) = u + u e^u + u e^{-u} + (u - e^u)^2\) |
|
\(c(u) = u + u e^u + u e^{-u} + (u - e^u)^2 + (u + u\sin(u) - \cos(u))^2\) |
|
\(c(u) = u + u e^{-u} + e^u (u + \sin(u) - \cos(u))^3\) |
Parallel Example Using hypre: kin_heat2D_nonlin_hypre_pfmg
As an illustration of the use of the KINSOL package for the solution of
nonlinear systems in parallel and using hypre linear solvers, we give a sample
program called kin_heat2D_nonlin_hypre_pfmg.cpp
. It uses the KINSOL
fixed-point (KIN_FP
) iteration with Anderson Acceleration and the MPI
parallel vector for the solution of a steady-state 2D
heat equation with an additional nonlinear term defined by \(c(u)\):
where \(D\) is a diagonal matrix with entries \(k_x\) and \(k_y\) for the diffusivity in the \(x\) and \(y\) directions, respectively. The boundary conditions are
We chose the analytical solution to be
Hence, we define the static term \(b\) as follows
The spatial derivatives are computed using second-order centered differences, with the data distributed over \(n_x \times n_y\) points on a uniform spatial grid. The problem is set up to use spatial grid parameters \(n_x=64\) and \(n_y=64\), with heat conductivity parameters \(k_x=1.0\) and \(k_y=1.0\).
This problem is solved via a fixed point iteration with Anderson acceleration, where the fixed point function is formed by implementing the Laplacian as a matrix-vector product,
and solving for \(u\) results in the fixed point function
The problem is run using a tolerance of \(10^{-8}\), and a starting vector
containing all ones. The linear system solve is executed using the PCG
linear solver with the hypre PFMG preconditioner. The setup
of the linear solver can be found in the Setup_LS
function, and setup of the
hypre preconditioner can be found in the Setup_Hypre
function. This
example highlights the use of the various orthogonalization routine options
within Anderson Acceleration, passed to the example problem via the --orthaa
flag. Available options include 0 (KIN_ORTH_MGS
), 1 (KIN_ORTH_ICWY
), 2
(KIN_ORTH_CGS2
), and 3 (KIN_ORTH_DCGS2
).
All input parameter flags available for the previous example are also available for this problem. In addition, all runtime flags controlling the linear solver and hypre related parameters are set using the flags in the following table.
Optional Input Parameter Flags for hypre
Flag |
Description |
---|---|
|
output residual history for PCG |
|
max number of iterations for PCG |
|
linear tolerance for PCG |
|
relaxation type in PFMG |
|
pre/post relaxation sweeps in PFMG |