Debian Codegraph @

packages/trilinoscouplings/examples/scaling/TrilinosCouplings_EpetraIntrepidPoissonExample_SolveWithAztecOO.cpp

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 #include "TrilinosCouplings_EpetraIntrepidPoissonExample_SolveWithAztecOO.hpp"
11
12 // AztecOO solver
13 #include "AztecOO.h"
14
15 namespace TrilinosCouplings {
16 namespace EpetraIntrepidPoissonExample {
17
18 void
19 solveWithAztecOO (bool& converged,
20 int& numItersPerformed,
21 const double tol,
22 const int maxNumIters,
23 const int num_steps,
24 const Teuchos::RCP<Epetra_Vector>& X,
25 const Teuchos::RCP<Epetra_Operator>& A,
26 const Teuchos::RCP<Epetra_Vector>& B,
27 const Teuchos::RCP<Epetra_Operator>& M_right)
28 {
29 // Set these in advance, so that if the AztecOO solver throws an
30 // exception for some reason, these will have sensible values.
31 converged = false;
32 numItersPerformed = 0;
33
34 TEUCHOS_TEST_FOR_EXCEPTION(A.is_null () || X.is_null () || B.is_null (),
35 std::invalid_argument, "solveWithBelos: The A, X, and B arguments must all "
36 "be nonnull.");
37
38 AztecOO solver;
39 solver.SetAztecOption(AZ_solver, AZ_gmres);
40 solver.SetAztecOption(AZ_precond, AZ_none);
41 solver.SetAztecOption(AZ_kspace, 200);
42 solver.SetAztecOption(AZ_conv, AZ_r0);
43 solver.SetAztecOption(AZ_output, 10);
44 solver.SetUserOperator(A.get());
45 if (M_right != Teuchos::null)
46 solver.SetPrecOperator(M_right.get());
47 solver.SetRHS(B.get());
48
49 // Enter "time step" loop -- we're really solving the same system repeatedly
50 converged = true;
51 numItersPerformed = 0;
52 for (int step=0; step<num_steps; ++step) {
53
54 // Set x
55 X->PutScalar(0.0);
56
57 // Reset problem
58 solver.SetLHS(X.get());
59
60 int result = solver.Iterate(maxNumIters, tol);
61
62 converged = converged && (result == 0);
63 numItersPerformed += solver.NumIters ();
64
65 }
66 }
67
68 } // namespace EpetraIntrepidPoissonExample
69 } // namespace TrilinosCouplings