/*! \mainpage Epetra to Thyra Operator/Vector Adapters This doxygen collection documents a small amount of code that wraps Epetra objects to create adapter objects which implement the Fundamental Thyra ANA Operator/Vector Interfaces. These wrappers use a minimal amount of code by making heavy use of the standard implementations Thyra::DefaultMPIVectorSpace, Thyra::DefaultMPIVector, and Thyra::DefaultMPIMultiVector. Click on the links below to browse adapter code and examples: \section EpetraThyra_links_sec Links to other software */ /** \defgroup Epetra_Thyra_Op_Vec_adapters_grp Epetra to Thyra Operator/Vector Adapter Code The following functions and classes are used to create %Thyra objects which wrap (or adapt) Epetra objects: The above adapter code is based directly from the general \ref \ref Thyra_Op_Vec_adapters_MPI_support_grp. Therefore these Epetra adapted objects are automatically compatible with any other such MPI-based SPMD adapter subclasses. There is, however, one issue that requires a little care and that is using arbitrary Thyra::VectorBase and Thyra::MultiVectorBase objects with the vector and multi-vector versions of Thyra::EpetraLinearOp::apply(). The issue is that the underlying Epetra_Operator::Apply() function can only accept Epetra_MultiVector objects. The utility functions Thyra::get_Epetra_MultiVector() return an Epetra_MultiVector view of any Thyra::MultiVectorBase object with a compatible range space. Studying the implementations of these utility functions will show you how simple it is to provide for this type of interoperabiity. This type of interoperabiity machinary should also be used for other types of concrete adapter subclasses. Other types of code will need to extract an Epetra_Vector view of a Thyra::VectorBase object. For this purpose the Thyra::get_Epetra_Vector() functions are provided. The utility functions Thyra::get_Epetra_Operator() are also provided that encapsulate the extraction of an "adapted" Epetra_Operator object out of a Thyra::EpetraLinearOp object through its Thyra::LinearOpBase base interface. This is a common type of activity in object-oriented programming. \section Epetra_Thyra_Op_Vec_examples_sec Examples */ /** \defgroup Epetra_Thyra_Op_Vec_examples_grp Assorted Epetra to Thyra Operator/Vector Adapter Example Code \brief Below are links to example code that demonstrate various use cases for the %Epetra to %Thyra operator/vector adapters:
  1. \ref Epetra_Thyra_Op_Vec_examples_power_method_grp
  2. \ref Epetra_Thyra_Op_Vec_examples_cg_grp
  3. \ref Epetra_Thyra_epetra_adapters_testing_prg_grp
*/ /** \example createTridiagEpetraLinearOp.hpp Click \ref Epetra_Thyra_Op_Vec_examples_power_method_grp "here" and \ref Epetra_Thyra_Op_Vec_examples_cg_grp "here" for example programs that call the function. */ /** \example createTridiagEpetraLinearOp.cpp Click \ref Epetra_Thyra_Op_Vec_examples_power_method_grp "here" and \ref Epetra_Thyra_Op_Vec_examples_cg_grp "here" for example programs that call the function. */ /** \example sillyPowerMethod_epetra.cpp Click \ref Epetra_Thyra_Op_Vec_examples_power_method_grp "here" for a more detailed discussion of this example function. */ /** \example sillyCgSolve_epetra.cpp Click \ref Epetra_Thyra_Op_Vec_examples_cg_grp "here" for a more detailed discussion of this example program. */ /** \defgroup Epetra_Thyra_Op_Vec_examples_power_method_grp Epetra Implemenation of the Power Method \ingroup Epetra_Thyra_Op_Vec_examples_grp \brief Here is an example program that shows the use of the \ref Epetra_Thyra_Op_Vec_adapters_Epetra_grp "Epetra adapter subclasses" with the example linear ANA implementation sillyPowerMethod(). This example program is contained in the source file \verbatim ./thyra/example/sillyPowerMethod_epetra.cpp \endverbatim 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. \dontinclude createTridiagEpetraLinearOp.cpp 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 \f[ A= \left[\begin{array}{rrrrrrrrrr} 2 & -1 \\ -1 & 2 & -1 \\ & \ddots & \ddots & \ddots \\ & & -1 & 2 & -1 \\ & & & -1 & 2 \end{array}\right]. \f] 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: \skip Teuchos::RCP > \until end createTridiagEpetraLinearOp \dontinclude sillyPowerMethod_epetra.cpp The above matrix-building function %Thyra::%createTridiagEpetraLinearOp() is then called in the following MPI-enabled main() driver program: \skip int main \until end main The above driver program should be very strightforward to follow and generates the exact same numerical results as in the double case in the \ref Thyra_Op_Vec_examples_power_method_serial_grp "tempalted serial version". \dontinclude sillyPowerMethod_epetra.cpp 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: \skip void scaleFirstDiagElement \until end scaleFirstDiagElement 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: \verbatim ./thyra/example/sillyPowerMethod_epetra.exe \endverbatim 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: \verbinclude sillyPowerMethod_epetra.default.out 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: \verbinclude sillyPowerMethod_epetra.help.out To see the full listing of this example program click: sillyPowerMethod_epetra.cpp */ /** \defgroup Epetra_Thyra_Op_Vec_examples_cg_grp Epetra Implemenation of the CG Method \ingroup Epetra_Thyra_Op_Vec_examples_grp \brief Here is an example program that shows the use of the \ref Epetra_Thyra_Op_Vec_adapters_Epetra_grp "Epetra adapter subclasses" with the example linear ANA implementation sillyCgSolve(). This example program is contained in the source file \verbatim ./thyra/example/sillyCgSolve_epetra.cpp \endverbatim 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. \dontinclude createTridiagEpetraLinearOp.cpp 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 \f[ A= \left[\begin{array}{rrrrrrrrrr} 2 a & -1 \\ -1 & 2 a & -1 \\ & \ddots & \ddots & \ddots \\ & & -1 & 2 a & -1 \\ & & & -1 & 2 a \end{array}\right] \f] where \f$a\f$ is an adjustable diagonal scale factor that makes the matrix \f$A\f$ more or less well conditioned. The implementation of the function Thyra::createTridiagEpetraLinearOp() is shown below: \skip Teuchos::RCP > \until end createTridiagEpetraLinearOp \dontinclude sillyCgSolve_epetra.cpp The above matrix-building function %Thyra::%createTridiagEpetraLinearOp() is then called along with the sillyCgSolve() function in the following MPI-enabled main() driver program: \skip int main \until end main The above driver program should be very strightforward to follow and generates the exact same numerical results as in the double case in the \ref Thyra_Op_Vec_examples_cg_serial_grp "tempalted serial version". 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: \verbatim ./thyra/example/sillyCgSolve_epetra.exe \endverbatim 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: \verbinclude sillyCgSolve_epetra.default.out 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 ./sillyCgSolve_epetra.exe --echo-command-line --help are: \verbinclude sillyCgSolve_epetra.help.out To see the full listing of this example program click: sillyCgSolve_epetra.cpp */ /** \defgroup Epetra_Thyra_epetra_adapters_testing_prg_grp Testing Program for Thyra/Epetra Adapters \ingroup Epetra_Thyra_Op_Vec_examples_grp \brief Here we show the testing program that is used to perform regression tests on the \ref Epetra_Thyra_adapters_Epetra_grp "Epetra adapter subclasses" and tests a number of other classes as well. This testing program is contained in the source file \verbatim ./thyra/test/test_epetra_adapters.cpp \endverbatim where ./ is the base source directory for epetra. \dontinclude test_epetra_adapters.cpp This testing program will be shown in its entirety below but first we will point out some of the more significant parts of the program and highlight some interesting functionality. First, the testing program reads in a number of options as shown below: \skip local_dim \until return parse_return Next, some MPI functions are called to get the context of the parallel program (if built with MPI support and RTOp_USE_MPI is defined): \skip RTOp_USE_MPI \until endif This program then creates two different (parallel or serial) vector spaces where one is of type Thyra::EpetraVectorSpace and the other is some non-Epetra vector space: \skip RCP \until end create Given these vector spaces a couple %Epetra and non-Epetra vectors and multi-vectors are created: \skip RCP \until neV2 Most of the operations performed in this testing program are fairly mundane and we show a few of these simpler examples before going onto some more interesting ones. These vectors and multi-vectors are then initialized using the Thyra::assign() wrapper functions: \skip assign \until neV2 The one norms of these vectors and multi-vectors are are then computed using various overloads of Thyra::norm_1() as: \skip Scalar \until neV2_nrm The first set of more interesting operations are mixing objects of different concrete type in vector transformation operations. The following code shows assigning vectors and multi-vectors of various types \skip Thyra::assign \until Thyra::assign \skip Thyra::assign \until Thyra::assign \skip Thyra::assign \until Thyra::assign \skip Thyra::assign \until Thyra::assign \skip Thyra::assign \until Thyra::assign \skip Thyra::assign \until Thyra::assign \skip Thyra::assign \until Thyra::assign What is significant about some of the above function calls is that they mix and match objects with different concrete types. For example, a non-Epetra vector is assigned to an %Epetra in the line: \verbatim Thyra::assign( &*ev1, *nev2 ); \endverbatim and an %Epetra vector is assigned to a non-Epetra in the line: \verbatim Thyra::assign( &*nev1, *ev2 ); \endverbatim Similarly, non-Epetra and %Epetra multi-vectors are assigned to and from in the calls: \verbatim Thyra::assign( &*eV1, *neV2 ); Thyra::assign( &*neV1, *eV2 ); \endverbatim Developer's that really want to understand how this type of interoperability between different concrete types works are cautiously encouraged to look at the implementations of the functions Thyra::SerialVectorBase::applyOp() and Thyra::SerialMultiVectorBase::applyOp() in a serial build and Thyra::MPIVectorBase::applyOp() and Thyra::MPIMultiVectorBase::applyOp(). The Thyra::LinearOpBase interface that all vectors and multi-vectors support is tested by the testing class Thyra::LinearOpTester which is created in the line: \skip LinearOpTester \until LinearOpTester This testing class is then called for all of the vector and multi-vector objects is the following lines: \skipline linearOpTester \skipline linearOpTester \skipline linearOpTester \skipline linearOpTester Now we show how an Epetra_Operator object is wrapped by a Thyra::EpetraLinearOp object to give the %Epetra object a %Thyra skin. First we create a simple diagonal %Epetra operator in the following lines of code: \skip epetra_op \until end epetra_op We then wrap this %Epetra operator object as: \skip LinearOp \until EpetraLinearOp This object is then tested in the line: \skipline linearOpTester Before the next set of tests we create some %Epetra and non-Epetra working vectors and mulit-vectors in the lines: \skip RCP \until neY In the next set of lines of code shows how different %Epetra and non-Epetra vectors and multi-vectors can be mixed and matched with with this Thyra::EpetraLinearOp object: \skipline NOTRANS \skipline NOTRANS \skipline NOTRANS \skipline NOTRANS \skipline NOTRANS \skipline NOTRANS \skipline NOTRANS \skipline NOTRANS \skipline NOTRANS Note that many of the above function calls involve using non-Epetra vector and multi-vector objects with the underlying Epetra_Operator object. This magic happens through the use of the utility function Thyra::get_Epetra_MultiVector() by the overridden function Thyra::EpetraLinearOp::euclideanApply(). ToDo: Finish this discussion. To see the full listing of this click: test_epetra_adpaters.cpp . */ /** \example test_epetra_adapters.cpp Click \ref Epetra_Thyra_epetra_adapters_testing_prg_grp "here" for a more detailed discusion of this example/test program. */