Thyra Package Browser (Single Doxygen Collection) Version of the Day
Classes
Templated Serial Implementation of the CG Method
CG Examples

Here is an example program that shows the use of the example serial templated matrix class ExampleTridiagSerialLinearOp with the example linear ANA implementation sillyCgSolve(). More...

Collaboration diagram for Templated Serial Implementation of the CG Method:

Classes

class  ExampleTridiagSerialLinearOp< Scalar >
 Simple example subclass for serial tridiagonal matrices. More...

Detailed Description

Here is an example program that shows the use of the example serial templated matrix class ExampleTridiagSerialLinearOp with the example linear ANA implementation sillyCgSolve().

The class ExampleTridiagSerialLinearOp that derives from the base class Thyra::SpmdLinearOpBase is quite simple and its complete implementation looks like:

The above serial matrix class is used in an example program (see runCgSolveExample() below) that calls sillyCgSolve() or sillierCgSolve(). In this example program, the matrix constructed and used is the following tridiagonal matrix

\[ A= \left[\begin{array}{rrrrrrrrrr} 2 a & -1 \\ -r(1) & 2 a & -1 \\ & \ddots & \ddots & \ddots \\ & & -r(n-2) & 2 a & -1 \\ & & & -r(n-1) & 2 a \end{array}\right] \]

where $a$ is an adjustable diagonal scale factories that makes the matrix $A$ more or less well conditioned and $r(i)$ is either $-1$ for a symmetric operator or $rand()$ for an unsymmetric operator.

If a symmetric operator is used, then CG is run using $A$ directly. If $A$ is unsymmetric, then the normal equations

\[ A^H A x = A^H b \]

are solved and the operator used is

\[ A \Rightarrow A^H A \]

The CG method is then run on the matrix $A$ or $A^H A$ for a number of iterations or until convergence to some tolerance is achieved.

The following templated function runCgSolveExample() implements the example described above:

The above templated function runCgSolveExample() is then instantiated with the following scalar types:

and is called multiple times from within the following main() program function:

The above example program is built as part of the Thyra package (unless examples where disabled at configure time) and the executable can be found at:

./example/operator_vector/sillyCgSolve_serial.exe 

where ./ is the base build directory for Thyra (e.g. $TRILINOS_BUILD_DIR/packages/thyra).

This example program should run successfully with no arguments and produces the following output:

This example program also takes a number of command-line options. To see what the command-line options are, use the --help option. The command-line options for this program returned from ./sillyCgSolve_serial.exe --echo-command-line --help are:

When the option --unsym-op is selected, the normal equations are solved which is shown in the following example:

Note in the above example how the normal operator $A^H A$ is described. This aggregate operator is created by the function calls Thyra::adjoint() and Thyra::multiply() which create implicit Thyra::ScaledAdjointedLinearOp and Thyra::DefaultMultipliedLinearOp objects.

To see the full listing of this example program click: sillyCgSolve_serial.cpp

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines