Debian Codegraph @

packages/nox/test/tpetra/ME_Tpetra_1DFEM.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // NOX: An Object-Oriented Nonlinear Solver Package
4 //
5 // Copyright 2002 NTESS and the NOX contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 #ifndef NOX_TPETRA_ME_1DFEM_DECL_HPP
10 #define NOX_TPETRA_ME_1DFEM_DECL_HPP
11
12 #include "Thyra_StateFuncModelEvaluatorBase.hpp"
13
14 #include "Tpetra_Map.hpp"
15 #include "Tpetra_Vector.hpp"
16 #include "Tpetra_Import.hpp"
17 #include "Tpetra_CrsGraph.hpp"
18 #include "Tpetra_CrsMatrix.hpp"
19 #include "Teuchos_TimeMonitor.hpp"
20
21 template<class Scalar, class LO, class GO, class Node>
22 class EvaluatorTpetra1DFEM;
23
24 /** \brief Nonmember constuctor.
25 *
26 * \relates EvaluatorTpetra1DFEM
27 */
28 template<class Scalar, class LO, class GO, class Node>
29 Teuchos::RCP<EvaluatorTpetra1DFEM<Scalar, LO, GO, Node> >
30 evaluatorTpetra1DFEM(const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
31 const Tpetra::global_size_t numGlobalElements,
32 const Scalar zMin,
33 const Scalar zMax);
34
35
36 /** \brief 1D Finite Element model for nonlinear heat conduction
37 *
38 * The equation modeled is:
39
40 \verbatim
41
42 d2T
43 --- - k * T**2 = 0
44 dz2
45
46 subject to:
47 T = p(4), defaults to 1.0 @ z = zMin
48 T' = 0.0 @ z = zMax
49 k = p(2), defaults to 1.0 (independent parameter)
50
51 For LOCA testing, parameters and responses are used to evaluate a
52 contraint equation. The parameter k is the unknown variable used to
53 enforce the response. We add in dummy responses for unit testing
54 correct offsets in LOCA parameter handling code.:
55
56 p(0) is a dummy parameter (throws if queried)
57 p(1) is a dummy parameter (throws if queried)
58 p(2) is a constant "k" multiplier on the source term
59 p(3) is a dummy parameter (throws if queried)
60 p(4) is the Dirichlet BC temperature value for left side node "T_left"
61
62 g(0) is a dummy response (throws if queried)
63 g(1) is a dummy response (throws if queried)
64 g(2) is a dummy response (throws if queried)
65 g(3) is a dummy response (throws if queried)
66 g(4) = T(zMax) - 2.0
67 g(5) is a dummy response (throws if queried)
68 g(6) = 2.0 * T(zMin) - T(zMax)
69
70 \endverbatim
71
72 * The Matrix <tt>W = d(f)/d(x)</tt> is implemented as a
73 * <tt>Thyra::LinearOpBase</tt> object and the class
74 * <tt>Thyra::DefaultSerialDenseLinearOpWithSolveFactory</tt> is used to
75 * create the linear solver.
76 */
77 template<class Scalar, class LO, class GO, class Node>
78 class EvaluatorTpetra1DFEM : public ::Thyra::ModelEvaluator<Scalar>
79 {
80 public:
81
82 // Public typedefs
83 typedef Scalar scalar_type;
84 typedef LO local_ordinal_type;
85 typedef GO global_ordinal_type;
86 typedef Node node_type;
87 typedef Tpetra::Map<LO, GO, Node> tpetra_map;
88 typedef Tpetra::CrsGraph<LO, GO, Node> tpetra_graph;
89 typedef Tpetra::CrsMatrix<Scalar, LO, GO, Node> tpetra_matrix;
90 typedef Tpetra::Vector<Scalar, LO, GO, Node> tpetra_vec;
91 typedef ::Thyra::VectorBase<Scalar> thyra_vec;
92 typedef ::Thyra::MultiVectorBase<Scalar> thyra_mvec;
93 typedef ::Thyra::VectorSpaceBase<Scalar> thyra_vec_space;
94 typedef ::Thyra::LinearOpBase<Scalar> thyra_op;
95 typedef ::Thyra::PreconditionerBase<Scalar> thyra_prec;
96
97 // Constructor
98 EvaluatorTpetra1DFEM(const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
99 const Tpetra::global_size_t numGlobalElements,
100 const Scalar zMin,
101 const Scalar zMax);
102
103 /** \name Initializers/Accessors */
104 //@{
105
106 /** \brief . */
107 void set_x0(const Teuchos::ArrayView<const Scalar> &x0);
108
109 /** \brief . */
110 void setShowGetInvalidArgs(bool showGetInvalidArg);
111
112 void set_W_factory(const Teuchos::RCP<const ::Thyra::LinearOpWithSolveFactoryBase<Scalar> >& W_factory);
113
114 //@}
115
116 /** \name Public functions overridden from ModelEvaulator. */
117 //@{
118
119 Teuchos::RCP<const thyra_vec_space> get_x_space() const;
120 Teuchos::RCP<const thyra_vec_space> get_f_space() const;
121 ::Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
122 Teuchos::RCP<thyra_op> create_W_op() const;
123 Teuchos::RCP<const ::Thyra::LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const;
124 ::Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
125 Teuchos::RCP<thyra_prec> create_W_prec() const;
126
127 // These are for constraint solver support
128 int Np () const;
129 int Ng () const;
130 ::Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgs() const;
131 Teuchos::RCP<const ::Thyra::VectorSpaceBase<Scalar> > get_p_space(int l) const;
132 Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
133 Teuchos::RCP<const ::Thyra::VectorSpaceBase<Scalar> > get_g_space(int j) const;
134 Teuchos::ArrayView<const std::string> get_g_names(int j) const;
135 Teuchos::RCP<::Thyra::LinearOpBase<Scalar>> create_DfDp_op(int l) const;
136 Teuchos::RCP<::Thyra::LinearOpBase<Scalar> > create_DgDx_op(int j) const;
137 Teuchos::RCP<::Thyra::LinearOpBase<Scalar> > create_DgDx_dot_op(int j) const;
138 Teuchos::RCP<::Thyra::LinearOpBase<Scalar> > create_DgDp_op( int j, int l ) const;
139
140 void evalModel(const ::Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
141 const ::Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs) const;
142
143 // Dummy
144 Teuchos::RCP<const thyra_vec_space> get_f_multiplier_space() const{return Teuchos::null;}
145 Teuchos::RCP<const thyra_vec_space> get_g_multiplier_space(int j) const{return Teuchos::null;}
146 ::Thyra::ModelEvaluatorBase::InArgs<Scalar> getLowerBounds() const{return prototypeInArgs_;}
147 ::Thyra::ModelEvaluatorBase::InArgs<Scalar> getUpperBounds() const{return prototypeInArgs_;}
148 Teuchos::RCP<::Thyra::LinearOpWithSolveBase<Scalar>> create_W() const{return Teuchos::null;}
149 Teuchos::RCP<::Thyra::LinearOpBase<Scalar>> create_hess_f_xx() const{return Teuchos::null;}
150 Teuchos::RCP<::Thyra::LinearOpBase<Scalar>> create_hess_f_xp(int l) const{return Teuchos::null;}
151 Teuchos::RCP<::Thyra::LinearOpBase<Scalar>> create_hess_f_pp( int l1, int l2 ) const{return Teuchos::null;}
152 Teuchos::RCP<::Thyra::LinearOpBase<Scalar>> create_hess_g_xx(int j) const{return Teuchos::null;}
153 Teuchos::RCP<::Thyra::LinearOpBase<Scalar>> create_hess_g_xp( int j, int l ) const{return Teuchos::null;}
154 Teuchos::RCP<::Thyra::LinearOpBase<Scalar>> create_hess_g_pp( int j, int l1, int l2 ) const{return Teuchos::null;}
155 void reportFinalPoint (const ::Thyra::ModelEvaluatorBase::InArgs<Scalar> &finalPoint, const bool wasSolved);
156 //@}
157
158 std::pair<int,int> get_p_index(const std::string& p_name) const;
159 std::pair<int,int> get_g_index(const std::string& g_name) const;
160
161 private:
162
163 /** Allocates and returns the Jacobian matrix graph */
164 virtual Teuchos::RCP<const tpetra_graph> createGraph();
165
166 private: // data members
167
168 const Teuchos::RCP<const Teuchos::Comm<int> > comm_;
169 const Tpetra::global_size_t numGlobalElements_;
170 const Scalar zMin_;
171 const Scalar zMax_;
172 const int Np_; // Number of parameters
173 const int Ng_; // Number of responses
174 const bool printDebug_;
175
176 Teuchos::RCP<const thyra_vec_space> xSpace_;
177 Teuchos::RCP<const tpetra_map> xOwnedMap_;
178 Teuchos::RCP<const tpetra_map> xGhostedMap_;
179 Teuchos::RCP<const Tpetra::Import<LO, GO, Node> > importer_;
180
181 Teuchos::RCP<const thyra_vec_space> fSpace_;
182 Teuchos::RCP<const tpetra_map> fOwnedMap_;
183
184 Teuchos::RCP<const tpetra_graph> W_graph_;
185
186 Teuchos::RCP<const ::Thyra::LinearOpWithSolveFactoryBase<Scalar> > W_factory_;
187
188 Teuchos::RCP<tpetra_vec> nodeCoordinates_;
189
190 mutable Teuchos::RCP<tpetra_vec> uPtr_;
191 mutable Teuchos::RCP<tpetra_vec> xPtr_;
192
193 mutable Teuchos::RCP<tpetra_vec> J_diagonal_;
194
195 ::Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_;
196 Teuchos::RCP<thyra_vec> x0_;
197 bool showGetInvalidArg_;
198 ::Thyra::ModelEvaluatorBase::InArgs<Scalar> prototypeInArgs_;
199 ::Thyra::ModelEvaluatorBase::OutArgs<Scalar> prototypeOutArgs_;
200
201 mutable Teuchos::RCP<Teuchos::Time> residTimer_;
202 mutable Teuchos::RCP<Teuchos::Time> jacTimer_;
203
204 // Optional parameter and response support for LOCA
205 std::vector<Teuchos::RCP<Teuchos::Array<std::string>>> pNames_;
206 std::vector<std::vector<std::string>> gNames_;
207 Teuchos::RCP<const tpetra_map> pMap_; // locally replicated scalar
208 Teuchos::RCP<const thyra_vec_space> pSpace_;
209 Teuchos::RCP<thyra_vec> p2_; // k value in equation
210 Teuchos::RCP<thyra_vec> p4_; // T_left value in equation Dirichlet BC
211 Teuchos::RCP<const tpetra_map> gMap_; // locally replicated scalar
212 Teuchos::RCP<const thyra_vec_space> gSpace_;
213 Teuchos::RCP<const tpetra_map> dgdpMap_; // locally replicated dense matrix
214 Teuchos::RCP<const thyra_vec_space> dgdpSpace_;
215
216 std::unordered_map<std::string,std::pair<int,int>> p_name_to_index_;
217 std::unordered_map<std::string,std::pair<int,int>> g_name_to_index_;
218 };
219
220 //==================================================================
221 #include "ME_Tpetra_1DFEM_def.hpp"
222 //==================================================================
223
224 #endif