Panzer  Version of the Day
Panzer_GatherSolution_Tpetra_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef PANZER_EVALUATOR_GATHER_SOLUTION_TPETRA_DECL_HPP
44 #define PANZER_EVALUATOR_GATHER_SOLUTION_TPETRA_DECL_HPP
45 
46 #include "Phalanx_config.hpp"
47 #include "Phalanx_Evaluator_Macros.hpp"
48 #include "Phalanx_MDField.hpp"
49 
50 #include "Teuchos_ParameterList.hpp"
51 
52 #include "PanzerDiscFE_config.hpp"
53 #include "Panzer_Dimension.hpp"
54 #include "Panzer_Traits.hpp"
57 
58 #include"Panzer_NodeType.hpp"
59 
61 
63 
64 namespace panzer {
65 
66 template <typename LocalOrdinalT,typename GlobalOrdinalT>
67 class UniqueGlobalIndexer; //forward declaration
68 
76 template<typename EvalT, typename Traits,typename LO,typename GO,typename NodeT=panzer::TpetraNodeType>
78 
79 // **************************************************************
80 // **************************************************************
81 // * Specializations
82 // **************************************************************
83 // **************************************************************
84 
85 
86 // **************************************************************
87 // Residual
88 // **************************************************************
89 template<typename TRAITS,typename LO,typename GO,typename NodeT>
90 class GatherSolution_Tpetra<panzer::Traits::Residual,TRAITS,LO,GO,NodeT>
91  : public panzer::EvaluatorWithBaseImpl<TRAITS>,
92  public PHX::EvaluatorDerived<panzer::Traits::Residual, TRAITS>,
94 
95 
96 public:
97 
98  GatherSolution_Tpetra(const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer) :
99  globalIndexer_(indexer) {}
100 
101  GatherSolution_Tpetra(const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer,
102  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 d);
110 
111  virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
112  { return Teuchos::rcp(new GatherSolution_Tpetra<panzer::Traits::Residual,TRAITS,LO,GO,NodeT>(globalIndexer_,pl)); }
113 
114  // for testing purposes
115  const PHX::FieldTag & getFieldTag(int i) const
116  { TEUCHOS_ASSERT(i < Teuchos::as<int>(gatherFields_.size())); return gatherFields_[i].fieldTag(); }
117 
118 private:
119 
120  typedef typename panzer::Traits::Residual EvalT;
122 
123  // maps the local (field,element,basis) triplet to a global ID
124  // for scattering
125  Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > globalIndexer_;
126  std::vector<int> fieldIds_; // field IDs needing mapping
127 
128  std::vector< PHX::MDField<ScalarT,Cell,NODE> > gatherFields_;
129 
130  std::vector<std::string> indexerNames_;
132  std::string globalDataKey_; // what global data does this fill?
133 
134  Teuchos::RCP<const TpetraLinearObjContainer<double,LO,GO,NodeT> > tpetraContainer_;
135 
136  // Fields for storing tangent components dx/dp of solution vector x
137  // These are not actually used by the residual specialization of this evaluator,
138  // even if they are supplied, but it is useful to declare them as dependencies anyway
139  // when saving the tangent components to the output file
141  std::vector< std::vector< PHX::MDField<const ScalarT,Cell,NODE> > > tangentFields_;
142 
144 };
145 
146 // **************************************************************
147 // Tangent
148 // **************************************************************
149 template<typename TRAITS,typename LO,typename GO,typename NodeT>
150 class GatherSolution_Tpetra<panzer::Traits::Tangent,TRAITS,LO,GO,NodeT>
151  : public panzer::EvaluatorWithBaseImpl<TRAITS>,
152  public PHX::EvaluatorDerived<panzer::Traits::Tangent, TRAITS>,
154 
155 
156 public:
157 
158  GatherSolution_Tpetra(const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer) :
159  globalIndexer_(indexer) {}
160 
161  GatherSolution_Tpetra(const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer,
162  const Teuchos::ParameterList& p);
163 
164  void postRegistrationSetup(typename TRAITS::SetupData d,
166 
167  void preEvaluate(typename TRAITS::PreEvalData d);
168 
169  void evaluateFields(typename TRAITS::EvalData d);
170 
171  virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
172  { return Teuchos::rcp(new GatherSolution_Tpetra<panzer::Traits::Tangent,TRAITS,LO,GO,NodeT>(globalIndexer_,pl)); }
173 
174 private:
175 
176  typedef typename panzer::Traits::Tangent EvalT;
178  typedef typename panzer::Traits::RealType RealT;
179 
180  // maps the local (field,element,basis) triplet to a global ID
181  // for scattering
182  Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > globalIndexer_;
183  std::vector<int> fieldIds_; // field IDs needing mapping
184 
185  std::vector< PHX::MDField<ScalarT,Cell,NODE> > gatherFields_;
186 
187  std::vector<std::string> indexerNames_;
189  std::string globalDataKey_; // what global data does this fill?
190 
191  Teuchos::RCP<const TpetraLinearObjContainer<double,LO,GO,NodeT> > tpetraContainer_;
192 
193  // Fields for storing tangent components dx/dp of solution vector x
195  std::vector< std::vector< PHX::MDField<const RealT,Cell,NODE> > > tangentFields_;
196 
198 };
199 
200 // **************************************************************
201 // Jacobian
202 // **************************************************************
203 template<typename TRAITS,typename LO,typename GO,typename NodeT>
205  : public panzer::EvaluatorWithBaseImpl<TRAITS>,
206  public PHX::EvaluatorDerived<panzer::Traits::Jacobian, TRAITS>,
208 
209 public:
210  GatherSolution_Tpetra(const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer) :
211  globalIndexer_(indexer) {}
212 
213  GatherSolution_Tpetra(const Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > & indexer,
214  const Teuchos::ParameterList& p);
215 
216  void postRegistrationSetup(typename TRAITS::SetupData d,
218 
219  void preEvaluate(typename TRAITS::PreEvalData d);
220 
221  void evaluateFields(typename TRAITS::EvalData d);
222 
223  virtual Teuchos::RCP<CloneableEvaluator> clone(const Teuchos::ParameterList & pl) const
224  { return Teuchos::rcp(new GatherSolution_Tpetra<panzer::Traits::Jacobian,TRAITS,LO,GO,NodeT>(globalIndexer_,pl)); }
225 
226  KOKKOS_INLINE_FUNCTION
227  void operator()(const int cell) const;
228 
229 
230  // No seeding of the AD fuctor
231  struct NoSeed {};
232  KOKKOS_INLINE_FUNCTION
233  void operator()(const NoSeed,const int cell) const;
234 
235 private:
236 
237  typedef typename panzer::Traits::Jacobian EvalT;
239 
240  // maps the local (field,element,basis) triplet to a global ID
241  // for scattering
242  Teuchos::RCP<const panzer::UniqueGlobalIndexer<LO,GO> > globalIndexer_;
243  std::vector<int> fieldIds_; // field IDs needing mapping
244 
245  std::vector< PHX::MDField<ScalarT,Cell,NODE> > gatherFields_;
246 
247  std::vector<std::string> indexerNames_;
249  bool disableSensitivities_; // This disables sensitivities absolutely
250  std::string sensitivitiesName_; // This sets which gather operations have sensitivities
251  bool applySensitivities_; // This is a local variable that is used by evaluateFields
252  // to turn on/off a certain set of sensitivities
253  std::string globalDataKey_; // what global data does this fill?
254  int gatherSeedIndex_; // what gather seed in the workset to use
255  // if less than zero then use alpha or beta
256  // as appropriate
257 
258  Teuchos::RCP<const TpetraLinearObjContainer<double,LO,GO,NodeT> > tpetraContainer_;
259  Teuchos::RCP<typename TpetraLinearObjContainer<double,LO,GO,NodeT>::VectorType> x_vector;
260 
262 
263  Kokkos::View<int**,PHX::Device> scratch_lids_;
264  std::vector<Kokkos::View<int*,PHX::Device> > scratch_offsets_;
265 
266  // functor data
267  struct {
268  // input values
269  Kokkos::View<const LO**,PHX::Device> lids; // local indices for unknowns
270  Kokkos::View<const int*,PHX::Device> offsets; // how to get a particular field
271  Kokkos::View<const double**, Kokkos::LayoutLeft,PHX::Device> x_data;
272  double seed_value; // AD seed information
273 
274  // output fields
275  PHX::MDField<ScalarT,Cell,NODE> field;
276  } functor_data;
277 };
278 
279 }
280 
281 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
283 #endif
284 
285 // **************************************************************
286 #endif
Teuchos::RCP< const TpetraLinearObjContainer< double, LO, GO, NodeT > > tpetraContainer_
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
Teuchos::RCP< const TpetraLinearObjContainer< double, LO, GO, NodeT > > tpetraContainer_
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
void operator()(const FieldMultTag< NUM_FIELD_MULT > &, const std::size_t &cell) const
Teuchos::RCP< typename TpetraLinearObjContainer< double, LO, GO, NodeT >::VectorType > x_vector
GatherSolution_Tpetra(const Teuchos::RCP< const panzer::UniqueGlobalIndexer< LO, GO > > &indexer)
GatherSolution_Tpetra(const Teuchos::RCP< const panzer::UniqueGlobalIndexer< LO, GO > > &indexer)
Wrapper to PHX::EvaluatorWithBaseImpl that implements Panzer-specific helpers.
Gathers solution values from the Newton solution vector into the nodal fields of the field manager...
Teuchos::RCP< const TpetraLinearObjContainer< double, LO, GO, NodeT > > tpetraContainer_
std::vector< std::vector< PHX::MDField< const ScalarT, Cell, NODE > > > tangentFields_
GatherSolution_Tpetra(const Teuchos::RCP< const panzer::UniqueGlobalIndexer< LO, GO > > &indexer)
Non-templated empty base class for template managers.
std::vector< std::vector< PHX::MDField< const RealT, Cell, NODE > > > tangentFields_