Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_ScatterDirichletResidual_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_DIRICHLET_RESIDUAL_BLOCKEDTPETRA_HPP
12#define PANZER_EVALUATOR_SCATTER_DIRICHLET_RESIDUAL_BLOCKEDTPETRA_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 Thyra {
31 template <typename ScalarT> class ProductVectorBase;
32}
33
34namespace panzer {
35
36class BlockedDOFManager;
37class GlobalIndexer;
38
47template <typename EvalT,typename TRAITS,typename LO,typename GO,typename NodeT=panzer::TpetraNodeType>
49 : public panzer::EvaluatorWithBaseImpl<TRAITS>,
50 public PHX::EvaluatorDerived<panzer::Traits::Residual, TRAITS>,
52public:
53 typedef typename EvalT::ScalarT ScalarT;
54 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & /* indexer */)
55 { }
56
57 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & gidProviders,
58 const Teuchos::ParameterList& p);
59
60 virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
61 { return Teuchos::rcp(new ScatterDirichletResidual_BlockedTpetra<EvalT,TRAITS,LO,GO,NodeT>(Teuchos::null,pl)); }
62
63 void postRegistrationSetup(typename TRAITS::SetupData /* d */, PHX::FieldManager<TRAITS>& /* vm */)
64 { }
65 void evaluateFields(typename TRAITS::EvalData /* d */)
66 { std::cout << "unspecialized version of \"ScatterDirichletResidual_BlockedTpetra::evaluateFields\" on \""+PHX::print<EvalT>()+"\" should not be used!" << std::endl;
67 TEUCHOS_ASSERT(false); }
68};
69
70// **************************************************************
71// **************************************************************
72// * Specializations
73// **************************************************************
74// **************************************************************
75
76
77// **************************************************************
78// Residual
79// **************************************************************
80template <typename TRAITS,typename LO,typename GO,typename NodeT>
82 : public panzer::EvaluatorWithBaseImpl<TRAITS>,
83 public PHX::EvaluatorDerived<panzer::Traits::Residual, TRAITS>,
85
86public:
87 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer)
88 : globalIndexer_(indexer) {}
89
92 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
93 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & /* colIndexers */)
94 : globalIndexer_(indexer) {}
95
96 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
97 const Teuchos::ParameterList& p);
98
99 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
100 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & /* colIndexers */,
101 const Teuchos::ParameterList& p)
103
104 void postRegistrationSetup(typename TRAITS::SetupData d,
106
107 void preEvaluate(typename TRAITS::PreEvalData d);
108
109 void evaluateFields(typename TRAITS::EvalData workset);
110
111 virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
113
114private:
116 typedef typename TRAITS::RealType RealType;
117
119 typedef Tpetra::Vector<RealType,LO,GO,NodeT> VectorType;
120 typedef Tpetra::CrsMatrix<RealType,LO,GO,NodeT> CrsMatrixType;
121 typedef Tpetra::CrsGraph<LO,GO,NodeT> CrsGraphType;
122 typedef Tpetra::Map<LO,GO,NodeT> MapType;
123 typedef Tpetra::Import<LO,GO,NodeT> ImportType;
124 typedef Tpetra::Export<LO,GO,NodeT> ExportType;
125
126 // dummy field so that the evaluator will have something to do
127 Teuchos::RCP<PHX::FieldTag> scatterHolder_;
128
129 // fields that need to be scattered will be put in this vector
130 std::vector< PHX::MDField<const ScalarT,Cell,NODE> > scatterFields_;
131
132 // maps the local (field,element,basis) triplet to a global ID
133 // for scattering
134 Teuchos::RCP<const panzer::BlockedDOFManager> globalIndexer_;
135
139 std::vector<Teuchos::RCP<const panzer::GlobalIndexer>> fieldGlobalIndexers_;
140
142 std::vector<int> fieldIds_;
143
146 std::vector<int> productVectorBlockIndex_;
147
148 // This maps the scattered field names to the DOF manager field
149 // For instance a Navier-Stokes map might look like
150 // fieldMap_["RESIDUAL_Velocity"] --> "Velocity"
151 // fieldMap_["RESIDUAL_Pressure"] --> "Pressure"
152 Teuchos::RCP<const std::map<std::string,std::string> > fieldMap_;
153
155 PHX::View<LO**> worksetLIDs_;
156
158 std::vector<PHX::View<int*>> fieldOffsets_;
159
163 std::vector<PHX::View<int*>> basisIndexForMDFieldOffsets_;
164
165 std::size_t side_subcell_dim_;
166 std::size_t local_side_id_;
167
168 Teuchos::RCP<Thyra::ProductVectorBase<double> > dirichletCounter_;
169 std::string globalDataKey_; // what global data does this fill?
170 Teuchos::RCP<const BlockedTpetraLinearObjContainer<RealType,LO,GO,NodeT> > blockedContainer_;
171
174
175 // If set to true, scattering an initial condition
177
178 // Allows runtime disabling of dirichlet BCs on node-by-node basis
179 std::vector< PHX::MDField<const bool,Cell,NODE> > applyBC_;
180
182};
183
184// **************************************************************
185// Jacobian
186// **************************************************************
187template <typename TRAITS,typename LO,typename GO,typename NodeT>
189 : public panzer::EvaluatorWithBaseImpl<TRAITS>,
190 public PHX::EvaluatorDerived<panzer::Traits::Jacobian, TRAITS>,
192
193public:
194 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer)
195 : globalIndexer_(indexer) {}
196
200 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
201 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & colIndexers)
202 : globalIndexer_(indexer), colGlobalIndexers_(colIndexers), hasColIndexers_(true) {}
203
204 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
205 const Teuchos::ParameterList& p);
206
207 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
208 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & colIndexers,
209 const Teuchos::ParameterList& p);
210
211 void preEvaluate(typename TRAITS::PreEvalData d);
212
213 void postRegistrationSetup(typename TRAITS::SetupData d,
215
216 void evaluateFields(typename TRAITS::EvalData workset);
217
218 virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
219 { return Teuchos::rcp(new ScatterDirichletResidual_BlockedTpetra<panzer::Traits::Jacobian,TRAITS,LO,GO,NodeT>(globalIndexer_,colGlobalIndexers_,pl)); }
220
221private:
223 typedef typename TRAITS::RealType RealType;
224
226 typedef Tpetra::Operator<RealType,LO,GO,NodeT> OperatorType;
227 typedef Tpetra::CrsMatrix<RealType,LO,GO,NodeT> CrsMatrixType;
228 typedef Tpetra::Map<LO,GO,NodeT> MapType;
229
230 typedef Thyra::TpetraLinearOp<RealType,LO,GO,NodeT> ThyraLinearOp;
231
232 // dummy field so that the evaluator will have something to do
233 Teuchos::RCP<PHX::FieldTag> scatterHolder_;
234
235 // fields that need to be scattered will be put in this vector
236 std::vector< PHX::MDField<const ScalarT,Cell,NODE> > scatterFields_;
237
238 // maps the local (field,element,basis) triplet to a global ID
239 // for scattering
240 Teuchos::RCP<const panzer::BlockedDOFManager> globalIndexer_;
241
242 std::vector<int> fieldIds_; // field IDs needing mapping
243
246 std::vector<int> productVectorBlockIndex_;
247
248 // This maps the scattered field names to the DOF manager field
249 // For instance a Navier-Stokes map might look like
250 // fieldMap_["RESIDUAL_Velocity"] --> "Velocity"
251 // fieldMap_["RESIDUAL_Pressure"] --> "Pressure"
252 Teuchos::RCP<const std::map<std::string,std::string> > fieldMap_;
253
254 std::size_t side_subcell_dim_;
255 std::size_t local_side_id_;
256
257 Teuchos::RCP<Thyra::ProductVectorBase<double> > dirichletCounter_;
258 std::string globalDataKey_; // what global data does this fill?
259 Teuchos::RCP<const BlockedTpetraLinearObjContainer<RealType,LO,GO,NodeT> > blockedContainer_;
260
262 PHX::View<LO**> worksetLIDs_;
263
265 std::vector<PHX::View<int*>> fieldOffsets_;
266
270 std::vector<PHX::View<int*>> basisIndexForMDFieldOffsets_;
271
273 PHX::View<LO*> blockOffsets_;
274
278 std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > colGlobalIndexers_;
279
281 bool hasColIndexers_ = false;
282
284 PHX::View<LO**> colWorksetLIDs_;
285 PHX::View<LO*> colBlockOffsets_;
286
288 using LocalMatrixType = KokkosSparse::CrsMatrix<double,LO,PHX::Device,Kokkos::MemoryTraits<Kokkos::Unmanaged>,size_t>;
289
295 PHX::View<LocalMatrixType**> jacTpetraBlocks_;
296 typename PHX::View<LocalMatrixType**>::host_mirror_type hostJacTpetraBlocks_;
297 PHX::View<int**> blockExistsInJac_;
298 typename PHX::View<int**>::host_mirror_type hostBlockExistsInJac_;
299
301 typename PHX::View<LO*>::host_mirror_type blockOffsets_h_;
302 typename PHX::View<LO*>::host_mirror_type colBlockOffsets_h_;
303
306
307 // Allows runtime disabling of dirichlet BCs on node-by-node basis
308 std::vector< PHX::MDField<const bool,Cell,NODE> > applyBC_;
309
311 static constexpr int maxDerivativeArraySize_ = 256;
312
314};
315
316// **************************************************************
317// Tangent
318// **************************************************************
319template <typename TRAITS,typename LO,typename GO,typename NodeT>
321 : public panzer::EvaluatorWithBaseImpl<TRAITS>,
322 public PHX::EvaluatorDerived<panzer::Traits::Tangent, TRAITS>,
324
325public:
326 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer)
327 : globalIndexer_(indexer) {}
328
331 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
332 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & /* colIndexers */)
333 : globalIndexer_(indexer) {}
334
335 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
336 const Teuchos::ParameterList& p);
337
338 ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP<const BlockedDOFManager> & indexer,
339 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & /* colIndexers */,
340 const Teuchos::ParameterList& p)
342
343 void postRegistrationSetup(typename TRAITS::SetupData d,
345
346 void preEvaluate(typename TRAITS::PreEvalData d);
347
348 void evaluateFields(typename TRAITS::EvalData workset);
349
350 virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
352
353private:
355 typedef typename TRAITS::RealType RealType;
356
358 typedef Tpetra::Vector<RealType,LO,GO,NodeT> VectorType;
359 typedef Tpetra::CrsMatrix<RealType,LO,GO,NodeT> CrsMatrixType;
360 typedef Tpetra::CrsGraph<LO,GO,NodeT> CrsGraphType;
361 typedef Tpetra::Map<LO,GO,NodeT> MapType;
362 typedef Tpetra::Import<LO,GO,NodeT> ImportType;
363 typedef Tpetra::Export<LO,GO,NodeT> ExportType;
364
365 // dummy field so that the evaluator will have something to do
366 Teuchos::RCP<PHX::FieldTag> scatterHolder_;
367
368 // fields that need to be scattered will be put in this vector
369 std::vector< PHX::MDField<const ScalarT,Cell,NODE> > scatterFields_;
370
371 // maps the local (field,element,basis) triplet to a global ID
372 // for scattering
373 Teuchos::RCP<const panzer::BlockedDOFManager> globalIndexer_;
374
378 std::vector<Teuchos::RCP<const panzer::GlobalIndexer>> fieldGlobalIndexers_;
379
381 std::vector<int> fieldIds_;
382
385 std::vector<int> productVectorBlockIndex_;
386
387 // This maps the scattered field names to the DOF manager field
388 // For instance a Navier-Stokes map might look like
389 // fieldMap_["RESIDUAL_Velocity"] --> "Velocity"
390 // fieldMap_["RESIDUAL_Pressure"] --> "Pressure"
391 Teuchos::RCP<const std::map<std::string,std::string> > fieldMap_;
392
394 PHX::View<LO**> worksetLIDs_;
395
397 std::vector<PHX::View<int*>> fieldOffsets_;
398
402 std::vector<PHX::View<int*>> basisIndexForMDFieldOffsets_;
403
404 std::size_t side_subcell_dim_;
405 std::size_t local_side_id_;
406
407 Teuchos::RCP<Thyra::ProductVectorBase<double> > dirichletCounter_;
408 std::string globalDataKey_; // what global data does this fill?
409 Teuchos::RCP<const BlockedTpetraLinearObjContainer<RealType,LO,GO,NodeT> > blockedContainer_;
410
413
414 // If set to true, scattering an initial condition
416
417 // Allows runtime disabling of dirichlet BCs on node-by-node basis
418 std::vector< PHX::MDField<const bool,Cell,NODE> > applyBC_;
419
420 // Storage for the tangent data
421 PHX::ViewOfViews<2,Kokkos::View<RealType**,Kokkos::LayoutLeft,PHX::Device>> dfdpFieldsVoV_;
422
423 // The df/dp sub-block vectors dfdpFieldsVoV_ is filled from, indexed
424 // [parameter][block]. The device views are acquired and released within
425 // evaluateFields() so that they never outlive the kernel launches, which
426 // would block host access to the same vectors.
427 std::vector<std::vector<Teuchos::RCP<VectorType> > > dfdpVectors_;
428
430};
431
432}
433
434#ifdef Panzer_BUILD_HESSIAN_SUPPORT
436#endif
437
438// **************************************************************
439#endif
Non-templated empty base class for template managers.
Wrapper to PHX::EvaluatorWithBaseImpl that implements Panzer-specific helpers.
PHX::View< LO ** > colWorksetLIDs_
Column LIDs and derivative offsets. Aliases of the row members when square.
PHX::View< LO * > blockOffsets_
The offset values of the blocked DOFs per element. Size of number of blocks in the product vector + 1...
std::vector< PHX::View< int * > > fieldOffsets_
Offset into the cell lids for each field. Size of number of fields to scatter.
PHX::View< LO * >::host_mirror_type blockOffsets_h_
Host copies of the offsets, filled once since the offsets never change.
ScatterDirichletResidual_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...
KokkosSparse::CrsMatrix< double, LO, PHX::Device, Kokkos::MemoryTraits< Kokkos::Unmanaged >, size_t > LocalMatrixType
Sub-block matrix type handed to the scatter kernel.
ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &)
ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &, const Teuchos::ParameterList &p)
ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &)
ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &indexer, const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &, const Teuchos::ParameterList &p)
Pushes residual values into the residual vector for a Newton-based solve.
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
ScatterDirichletResidual_BlockedTpetra(const Teuchos::RCP< const BlockedDOFManager > &)
void postRegistrationSetup(typename TRAITS::SetupData, PHX::FieldManager< TRAITS > &)
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),...