Thyra Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages

Here is an example program that shows the use of the Epetra adapter subclasses with the example linear ANA implementation sillyPowerMethod(). More...

Collaboration diagram for Epetra Implemenation of the Power Method:

Here is an example program that shows the use of the Epetra adapter subclasses with the example linear ANA implementation sillyPowerMethod().

This example program is contained in the source file

./thyra/example/sillyPowerMethod_epetra.cpp 

where ./ is the base source directory for epetra (i.e. ???/Trilinos/packages/epetra).

This example program is broken down into a few pieces in an attempt to be more understandable.

The first piece of example code we show is the function Thyra::createTridiagEpetraLinearOp(). This function creates an Epetra_CrsMatrix object that represents the well-known tridiagonal matrix

\[ A= \left[\begin{array}{rrrrrrrrrr} 2 & -1 \\ -1 & 2 & -1 \\ & \ddots & \ddots & \ddots \\ & & -1 & 2 & -1 \\ & & & -1 & 2 \end{array}\right]. \]

After the Epetra_CrsMatrix object is created, it is used to create a Thyra::EpetraLinearOp object that adapts it into a Thyra::LinearOp object.

The implementation of the function Thyra::createTridiagEpetraLinearOp() is shown below:

The above matrix-building function Thyra::createTridiagEpetraLinearOp() is then called in the following MPI-enabled main() driver program:

The above driver program should be very strightforward to follow and generates the exact same numerical results as in the double case in the tempalted serial version.

Notice however that the above driver program calls a helper function called scaleFirstDiagElement() which hides the details of scaling the first diagonal entry of the tridiagonal matrix operator. This helper function is not too tricking and takes the form:

One important thing to notice about the above helper function is how the underlying Epetra_CrsMatrix object is accessed given the Thyra::LinearOp interface to the Thyra::EpetraLinearOp object that was created by Thyra::createTridiagEpetraLinearOp(). Actually, most of the C++ magic is performed in the helper function Thyra::get_Epetra_Operator() which is then followed by a simple dynamic cast.

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

./thyra/example/sillyPowerMethod_epetra.exe 

where ./ is the base build directory for epetra (e.g. ???/Trilinos/$BUILD_DIR/packages/epetra).

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 returned from ./sillyPowerMethod_epetra.exe –echo-command-line –help are:

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