Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_ScatterResidual_BlockedTpetra.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef PANZER_EVALUATOR_SCATTER_RESIDUAL_BLOCKEDTPETRA_DECL_HPP
12#define PANZER_EVALUATOR_SCATTER_RESIDUAL_BLOCKEDTPETRA_DECL_HPP
13
14#include "Phalanx_config.hpp"
15#include "Phalanx_Evaluator_Macros.hpp"
16#include "Phalanx_MDField.hpp"
17#include "Phalanx_KokkosViewOfViews.hpp"
18
19#include "Teuchos_ParameterList.hpp"
20
21#include "PanzerDiscFE_config.hpp"
22#include "Panzer_Dimension.hpp"
23#include "Panzer_Traits.hpp"
26#include "KokkosSparse_CrsMatrix.hpp"
27
29
30namespace panzer {
31
32// Forward declarations
33class BlockedDOFManager;
34class GlobalIndexer;
35
40template <typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT=panzer::TpetraNodeType>
42 : public panzer::EvaluatorWithBaseImpl<TRAITS>,
43 public PHX::EvaluatorDerived<panzer::Traits::Residual, TRAITS>,
45public:
46 typedef typename EvalT::ScalarT ScalarT;
47
48 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & /* indexer */)
49 { }
50 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & gidProviders,
51 const Teuchos::ParameterList& p);
52
53 virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
54 { return Teuchos::rcp(new ScatterResidual_BlockedTpetra<EvalT,TRAITS,LO,GO,NodeT>(Teuchos::null,pl)); }
55
56 void postRegistrationSetup(typename TRAITS::SetupData /* d */, PHX::FieldManager<TRAITS>& /* vm */)
57 { }
58 void evaluateFields(typename TRAITS::EvalData /* d */)
59 { std::cout << "unspecialized version of \"ScatterResidual_BlockedTpetra::evaluateFields\" on \""+PHX::print<EvalT>()+"\" should not be used!" << std::endl;
60 TEUCHOS_ASSERT(false); }
61};
62
63// **************************************************************
64// **************************************************************
65// * Specializations
66// **************************************************************
67// **************************************************************
68
69
70// **************************************************************
71// Residual
72// **************************************************************
73template <typename TRAITS,typename LO,typename GO,typename NodeT>
75 : public panzer::EvaluatorWithBaseImpl<TRAITS>,
76 public PHX::EvaluatorDerived<panzer::Traits::Residual, TRAITS>,
78
79public:
80 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer)
81 : globalIndexer_(indexer) {}
82
85 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
86 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & /* colIndexers */)
87 : globalIndexer_(indexer) {}
88
89 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
90 const Teuchos::ParameterList& p);
91
92 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
93 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & /* colIndexers */,
94 const Teuchos::ParameterList& p)
95 : ScatterResidual_BlockedTpetra(indexer,p) {}
96
97 void postRegistrationSetup(typename TRAITS::SetupData d,
99
100 void preEvaluate(typename TRAITS::PreEvalData d);
101
102 void evaluateFields(typename TRAITS::EvalData workset);
103
104 virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
105 { return Teuchos::rcp(new ScatterResidual_BlockedTpetra<panzer::Traits::Residual,TRAITS,LO,GO,NodeT>(globalIndexer_,pl)); }
106
107private:
109 typedef typename TRAITS::RealType RealType;
110
112 typedef Tpetra::Vector<RealType,LO,GO,NodeT> VectorType;
113 typedef Tpetra::CrsMatrix<RealType,LO,GO,NodeT> CrsMatrixType;
114 typedef Tpetra::CrsGraph<LO,GO,NodeT> CrsGraphType;
115 typedef Tpetra::Map<LO,GO,NodeT> MapType;
116 typedef Tpetra::Import<LO,GO,NodeT> ImportType;
117 typedef Tpetra::Export<LO,GO,NodeT> ExportType;
118
120 Teuchos::RCP<PHX::FieldTag> scatterHolder_;
121
123 std::vector< PHX::MDField<const ScalarT,Cell,NODE> > scatterFields_;
124
126 Teuchos::RCP<const BlockedDOFManager> globalIndexer_;
127
129 std::vector<Teuchos::RCP<const panzer::GlobalIndexer>> fieldGlobalIndexers_;
130
132 std::vector<int> fieldIds_;
133
136 std::vector<int> productVectorBlockIndex_;
137
138 // This maps the scattered field names to the DOF manager field
139 // For instance a Navier-Stokes map might look like
140 // fieldMap_["RESIDUAL_Velocity"] --> "Velocity"
141 // fieldMap_["RESIDUAL_Pressure"] --> "Pressure"
142 Teuchos::RCP<const std::map<std::string,std::string> > fieldMap_;
143
144 std::string globalDataKey_; // what global data does this fill?
145 Teuchos::RCP<const BlockedTpetraLinearObjContainer<RealType,LO,GO,NodeT> > blockedContainer_;
146
148 PHX::View<LO**> worksetLIDs_;
149
151 std::vector<PHX::View<int*>> fieldOffsets_;
152
154};
155
156// **************************************************************
157// Jacobian
158// **************************************************************
159
160template <typename TRAITS,typename LO,typename GO,typename NodeT>
162 : public panzer::EvaluatorWithBaseImpl<TRAITS>,
163 public PHX::EvaluatorDerived<panzer::Traits::Jacobian, TRAITS>,
165
166public:
167
188 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer)
189 : globalIndexer_(indexer) {}
190
194 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
195 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & colIndexers)
196 : globalIndexer_(indexer), colGlobalIndexers_(colIndexers), hasColIndexers_(true) {}
197
198 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
199 const Teuchos::ParameterList& p);
200
201 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
202 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & colIndexers,
203 const Teuchos::ParameterList& p);
204
205 void postRegistrationSetup(typename TRAITS::SetupData d,
207
208 void preEvaluate(typename TRAITS::PreEvalData d);
209
210 void evaluateFields(typename TRAITS::EvalData workset);
211
212 virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
213 { return Teuchos::rcp(new ScatterResidual_BlockedTpetra<panzer::Traits::Jacobian,TRAITS,LO,GO,NodeT>(globalIndexer_,colGlobalIndexers_,pl)); }
214
215private:
217 typedef typename TRAITS::RealType RealType;
218
220 typedef Tpetra::Operator<RealType,LO,GO,NodeT> OperatorType;
221 typedef Tpetra::CrsMatrix<RealType,LO,GO,NodeT> CrsMatrixType;
222 typedef Tpetra::Map<LO,GO,NodeT> MapType;
223
224 typedef Thyra::TpetraLinearOp<RealType,LO,GO,NodeT> ThyraLinearOp;
225
226 // dummy field so that the evaluator will have something to do
227 Teuchos::RCP<PHX::FieldTag> scatterHolder_;
228
229 // fields that need to be scattered will be put in this vector
230 std::vector< PHX::MDField<const ScalarT,Cell,NODE> > scatterFields_;
231
232 // maps the local (field,element,basis) triplet to a global ID
233 // for scattering
234 Teuchos::RCP<const BlockedDOFManager> globalIndexer_;
235
236 std::vector<int> fieldIds_; // field IDs needing mapping
237
240 std::vector<int> productVectorBlockIndex_;
241
242 // This maps the scattered field names to the DOF manager field
243 // For instance a Navier-Stokes map might look like
244 // fieldMap_["RESIDUAL_Velocity"] --> "Velocity"
245 // fieldMap_["RESIDUAL_Pressure"] --> "Pressure"
246 Teuchos::RCP<const std::map<std::string,std::string> > fieldMap_;
247
248 std::string globalDataKey_; // what global data does this fill?
249 Teuchos::RCP<const BlockedTpetraLinearObjContainer<RealType,LO,GO,NodeT> > blockedContainer_;
250
252 Kokkos::View<LO**, Kokkos::LayoutRight, PHX::Device> worksetLIDs_;
253
255 Kokkos::View<typename Sacado::ScalarType<ScalarT>::type**, Kokkos::LayoutRight, PHX::Device> workset_vals_;
256
258 std::vector<PHX::View<int*>> fieldOffsets_;
259
261 PHX::View<LO*> blockOffsets_;
262
266 std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > colGlobalIndexers_;
267
269 bool hasColIndexers_ = false;
270
272 Kokkos::View<LO**, Kokkos::LayoutRight, PHX::Device> colWorksetLIDs_;
273 PHX::View<LO*> colBlockOffsets_;
274
276 using LocalMatrixType = KokkosSparse::CrsMatrix<double,LO,PHX::Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>,size_t>;
277
283 PHX::View<LocalMatrixType**> jacTpetraBlocks_;
284 typename PHX::View<LocalMatrixType**>::host_mirror_type hostJacTpetraBlocks_;
285 PHX::View<int**> blockExistsInJac_;
286 typename PHX::View<int**>::host_mirror_type hostBlockExistsInJac_;
287
289 typename PHX::View<LO*>::host_mirror_type blockOffsets_h_;
290 typename PHX::View<LO*>::host_mirror_type colBlockOffsets_h_;
291
293};
294
295// **************************************************************
296// Tangent
297// **************************************************************
298template <typename TRAITS,typename LO,typename GO,typename NodeT>
300 : public panzer::EvaluatorWithBaseImpl<TRAITS>,
301 public PHX::EvaluatorDerived<panzer::Traits::Residual, TRAITS>,
303
304public:
305 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer)
306 : globalIndexer_(indexer) {}
307
310 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
311 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & /* colIndexers */)
312 : globalIndexer_(indexer) {}
313
314 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
315 const Teuchos::ParameterList& p);
316
317 ScatterResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
318 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & /* colIndexers */,
319 const Teuchos::ParameterList& p)
320 : ScatterResidual_BlockedTpetra(indexer,p) {}
321
322 void postRegistrationSetup(typename TRAITS::SetupData d,
324
325 void preEvaluate(typename TRAITS::PreEvalData d);
326
327 void evaluateFields(typename TRAITS::EvalData workset);
328
329 virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
330 { return Teuchos::rcp(new ScatterResidual_BlockedTpetra<panzer::Traits::Tangent,TRAITS,LO,GO,NodeT>(globalIndexer_,pl)); }
331
332private:
334 typedef typename TRAITS::RealType RealType;
335
337 typedef Tpetra::Vector<RealType,LO,GO,NodeT> VectorType;
338 typedef Tpetra::CrsMatrix<RealType,LO,GO,NodeT> CrsMatrixType;
339 typedef Tpetra::CrsGraph<LO,GO,NodeT> CrsGraphType;
340 typedef Tpetra::Map<LO,GO,NodeT> MapType;
341 typedef Tpetra::Import<LO,GO,NodeT> ImportType;
342 typedef Tpetra::Export<LO,GO,NodeT> ExportType;
343
345 Teuchos::RCP<PHX::FieldTag> scatterHolder_;
346
348 std::vector< PHX::MDField<const ScalarT,Cell,NODE> > scatterFields_;
349
351 Teuchos::RCP<const BlockedDOFManager> globalIndexer_;
352
354 std::vector<Teuchos::RCP<const panzer::GlobalIndexer>> fieldGlobalIndexers_;
355
357 std::vector<int> fieldIds_;
358
361 std::vector<int> productVectorBlockIndex_;
362
363 // This maps the scattered field names to the DOF manager field
364 // For instance a Navier-Stokes map might look like
365 // fieldMap_["RESIDUAL_Velocity"] --> "Velocity"
366 // fieldMap_["RESIDUAL_Pressure"] --> "Pressure"
367 Teuchos::RCP<const std::map<std::string,std::string> > fieldMap_;
368
369 std::string globalDataKey_; // what global data does this fill?
370 Teuchos::RCP<const BlockedTpetraLinearObjContainer<RealType,LO,GO,NodeT> > blockedContainer_;
371
373 PHX::ViewOfViews<2,Kokkos::View<RealType**,Kokkos::LayoutLeft,PHX::Device>> dfdpFieldsVoV_;
374
379 std::vector<std::vector<Teuchos::RCP<VectorType> > > dfdpVectors_;
380
382 PHX::View<LO**> worksetLIDs_;
383
385 std::vector<PHX::View<int*>> fieldOffsets_;
386
388};
389
390}
391
392#ifdef Panzer_BUILD_HESSIAN_SUPPORT
394#endif
395
396// **************************************************************
397#endif
Non-templated empty base class for template managers.
Wrapper to PHX::EvaluatorWithBaseImpl that implements Panzer-specific helpers.
Kokkos::View< typename Sacado::ScalarType< ScalarT >::type **, Kokkos::LayoutRight, PHX::Device > workset_vals_
Scratch space for local values.
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
std::vector< PHX::View< int * > > fieldOffsets_
Offset into the cell lids for each field. Size of number of fields to scatter.
KokkosSparse::CrsMatrix< double, LO, PHX::Device, Kokkos::MemoryTraits< Kokkos::Unmanaged >, size_t > LocalMatrixType
Sub-block matrix type handed to the scatter kernel.
PHX::View< LO * >::host_mirror_type blockOffsets_h_
Host copies of the offsets, filled once since the offsets never change.
Teuchos::RCP< const BlockedTpetraLinearObjContainer< RealType, LO, GO, NodeT > > blockedContainer_
PHX::View< LO * > blockOffsets_
The offset values of the blocked DOFs per element. Size of number of blocks in the product vector + 1...
Kokkos::View< LO **, Kokkos::LayoutRight, PHX::Device > colWorksetLIDs_
Column LIDs and derivative offsets. Aliases of the row members when square.
Kokkos::View< LO **, Kokkos::LayoutRight, PHX::Device > worksetLIDs_
Local indices for unknowns.
ScatterResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &colIndexers)
Ctor for a non-square operator, whose columns are indexed separately from its rows (a distributed par...
Teuchos::RCP< const BlockedDOFManager > globalIndexer_
Maps the local (field,element,basis) triplet to a global ID for scattering.
std::vector< PHX::View< int * > > fieldOffsets_
Offset into the cell lids for each field.
std::vector< int > fieldIds_
Field IDs in the local product vector block (not global field id)
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
Teuchos::RCP< PHX::FieldTag > scatterHolder_
Dummy evalauted field so that the evaluator will have something to do.
std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > fieldGlobalIndexers_
Vector of global indexers, one for each scattered field respectively.
ScatterResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &, const Teuchos::ParameterList &p)
ScatterResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &)
std::vector< PHX::MDField< const ScalarT, Cell, NODE > > scatterFields_
Fields that need to be scattered will be put in this vector.
Teuchos::RCP< const BlockedTpetraLinearObjContainer< RealType, LO, GO, NodeT > > blockedContainer_
ScatterResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &, const Teuchos::ParameterList &p)
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
Teuchos::RCP< const BlockedDOFManager > globalIndexer_
Maps the local (field,element,basis) triplet to a global ID for scattering.
std::vector< PHX::View< int * > > fieldOffsets_
Offset into the cell lids for each field.
PHX::ViewOfViews< 2, Kokkos::View< RealType **, Kokkos::LayoutLeft, PHX::Device > > dfdpFieldsVoV_
Storage for the tangent data.
Teuchos::RCP< PHX::FieldTag > scatterHolder_
Dummy evalauted field so that the evaluator will have something to do.
std::vector< int > fieldIds_
Field IDs in the local product vector block (not global field id)
std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > fieldGlobalIndexers_
Vector of global indexers, one for each scattered field respectively.
std::vector< PHX::MDField< const ScalarT, Cell, NODE > > scatterFields_
Fields that need to be scattered will be put in this vector.
ScatterResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &)
Teuchos::RCP< const BlockedTpetraLinearObjContainer< RealType, LO, GO, NodeT > > blockedContainer_
Pushes residual values into the residual vector for a Newton-based solve.
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
void postRegistrationSetup(typename TRAITS::SetupData, PHX::FieldManager< TRAITS > &)
ScatterResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &)
Evaluation type for computing the residual and its Jacobian, using FadType as the scalar type.
Evaluation type for computing the residual only, using RealType as the scalar type.
Evaluation type for computing directional derivatives (e.g. parameter sensitivities),...