Debian Codegraph @

packages/trilinoscouplings/examples/scaling/TrilinosCouplings_EpetraIntrepidPoissonExample.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Trilinos: An Object-Oriented Solver Framework
4 //
5 // Copyright 2001-2024 NTESS and the Trilinos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef __TrilinosCouplings_EpetraIntrepidPoissonExample_hpp
11 #define __TrilinosCouplings_EpetraIntrepidPoissonExample_hpp
12
13 #include "Epetra_CrsMatrix.h"
14 #include "Epetra_Vector.h"
15 #include "Teuchos_FancyOStream.hpp"
16 #include "Teuchos_ScalarTraits.hpp"
17
18
19 namespace TrilinosCouplings {
20 /// \namespace EpetraIntrepidPoissonExample
21 /// \brief Epetra version of the Intrepid Poisson test problem example.
22 ///
23 /// The Intrepid Poisson test problem uses Pamgen to construct a 3-D
24 /// mesh (a simple rectangular prism with hex elements) in parallel,
25 /// Sacado automatic differentiation to construct a right-hand side of
26 /// the PDE corresponding to a given exact solution, and Intrepid to
27 /// build a discretization.
28 ///
29 /// We provide two variants of the Intrepid Poisson test: one that
30 /// fills Epetra objects, and one that fills Tpetra objects. The two
31 /// variants do exactly the same things otherwise, so you can use them
32 /// to compare the performance of Epetra and Tpetra fill.
33 ///
34 /// This namespace contains the Epetra variant. It defines typedefs
35 /// which you can use when writing a main() driver to run the test.
36 /// The makeMatrixAndRightHandSide() function does all the work. You
37 /// can use the exactResidualNorm() function to test correctness of
38 /// the discretization. In particular, if the continuous exact
39 /// solution was chosen from the space of finite element polynomials,
40 /// the exact solution of the discrete linear system AX=B should match
41 /// the continuous exact solution exactly, modulo rounding error when
42 /// assembling the discretization.
43 ///
44 /// The solveWithBelos() function solves the given linear system using
45 /// a Belos iterative solver. You can provide a left and/or right
46 /// preconditioner if you want.
47 namespace EpetraIntrepidPoissonExample {
48
49 //
50 // Typedefs for use by main() and other functions.
51 //
52 typedef double ST;
53 typedef int LO;
54 typedef int GO;
55 typedef Epetra_CrsMatrix sparse_matrix_type;
56 typedef Epetra_Operator operator_type;
57 typedef Epetra_MultiVector multivector_type;
58 typedef Epetra_Vector vector_type;
59
60 /// \brief Create the mesh and build the linear system to solve.
61 ///
62 /// \param A [out] The sparse matrix.
63 /// \param B [out] The right-hand side(s).
64 /// \param X_exact [out] The exact solution of the PDE, projected onto
65 /// the discrete mesh. This may not necessarily be the same as the
66 /// exact solution of the discrete linear system.
67 /// \param X [out] The approximate solution(s).
68 /// \param err [out] Output stream for errors.
69 /// \param out [out] Output stream for verbose output.
70 /// \param comm [in] Communicator (as an Epetra_Comm).
71 /// \param meshInput [in] Pamgen mesh specification string.
72 ///
73 /// See the documentation of
74 /// TpetraIntrepidPoissonExample::makeMatrixAndRightHandSide() for an
75 /// explanation of Pamgen and a reference for the mesh specification
76 /// format.
77 void
78 makeMatrixAndRightHandSide (Teuchos::RCP<sparse_matrix_type>& A,
79 Teuchos::RCP<vector_type>& B,
80 Teuchos::RCP<vector_type>& X_exact,
81 Teuchos::RCP<vector_type>& X,
82 const Teuchos::RCP<const Epetra_Comm>& comm,
83 const std::string& meshInput,
84 const Teuchos::RCP<Teuchos::FancyOStream>& out,
85 const Teuchos::RCP<Teuchos::FancyOStream>& err,
86 const bool verbose = false,
87 const bool debug = false);
88
89 //! Just like above, but with multivector_type output arguments.
90 void
91 makeMatrixAndRightHandSide (Teuchos::RCP<sparse_matrix_type>& A,
92 Teuchos::RCP<multivector_type>& B,
93 Teuchos::RCP<multivector_type>& X_exact,
94 Teuchos::RCP<multivector_type>& X,
95 const Teuchos::RCP<const Epetra_Comm>& comm,
96 const std::string& meshInput,
97 const Teuchos::RCP<Teuchos::FancyOStream>& out,
98 const Teuchos::RCP<Teuchos::FancyOStream>& err,
99 const bool verbose = false,
100 const bool debug = false);
101
102 //! Return \f$\|B - A X_{\text{exact}}\|_2\f$, \f$\|B\|\f$, and \f$\|A\|_F\f$.
103 std::vector<Teuchos::ScalarTraits<ST>::magnitudeType>
104 exactResidualNorm (const Teuchos::RCP<const sparse_matrix_type>& A,
105 const Teuchos::RCP<const vector_type>& B,
106 const Teuchos::RCP<const vector_type>& X_exact);
107
108 /// \brief Solve the linear system(s) AX=B with Belos.
109 ///
110 /// X and B are both multivectors, meaning that you may ask Belos to
111 /// solve more than one linear system at a time. X and B must have
112 /// the same number of columns.
113 ///
114 /// This interface will change in the future to accept the name of the
115 /// Belos solver to use. For now, the solver is hard-coded to
116 /// Pseudoblock CG (implemented by Belos::PseudoBlockCGSolMgr).
117 ///
118 /// \param converged [out] Whether Belos reported that the iterative
119 /// method converged (solved the linear system to the desired
120 /// tolerance).
121 ///
122 /// \param numItersPerformed [out] Number of iterations that the Belos
123 /// solver performed.
124 ///
125 /// \param solverName [in] Which iterative linear solver to use.
126 /// Any name that Belos::SolverFactory knows will work here.
127 ///
128 /// \param tol [in] Convergence tolerance for the iterative method.
129 /// The meaning of this depends on the particular iterative method.
130 ///
131 /// \param maxNumIters [in] Maximum number of iterations that the
132 /// iterative method should perform, regardless of whether it
133 /// converged.
134 ///
135 /// \param num_steps [in] Number of "time steps", i.e., the number of
136 // times the solver is called in a fake time-step loop.
137 ///
138 /// \param X [in/out] On input: the initial guess(es) for the iterative
139 /// method. On output: the computed approximate solution.
140 ///
141 /// \param A [in] The matrix in the linear system(s) AX=B to solve.
142 ///
143 /// \param B [in] The right-hand side(s) in the linear system AX=B to solve.
144 ///
145 /// \param M_left [in] If nonnull, a left preconditioner that the
146 /// iterative method may use. If null, the iterative method will
147 /// not use a left preconditioner.
148 ///
149 /// \param M_right [in] If nonnull, a right preconditioner that the
150 /// iterative method may use. If null, the iterative method will
151 /// not use a right preconditioner.
152 void
153 solveWithBelos (bool& converged,
154 int& numItersPerformed,
155 const std::string& solverName,
156 const Teuchos::ScalarTraits<ST>::magnitudeType& tol,
157 const int maxNumIters,
158 const int num_steps,
159 const Teuchos::RCP<multivector_type>& X,
160 const Teuchos::RCP<const sparse_matrix_type>& A,
161 const Teuchos::RCP<const multivector_type>& B,
162 const Teuchos::RCP<operator_type>& M_left=Teuchos::null,
163 const Teuchos::RCP<operator_type>& M_right=Teuchos::null);
164
165 } // namespace EpetraIntrepidPoissonExample
166 } // namespace TrilinosCouplings
167
168 #endif // __TrilinosCouplings_EpetraIntrepidPoissonExample_hpp