Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_STK_ResponseEvaluatorFactory_SolutionWriter.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_STK_ResponseEvaluatorFactory_SolutionWriter_hpp__
12 #define __Panzer_STK_ResponseEvaluatorFactory_SolutionWriter_hpp__
13 
14 #include <string>
15 
16 #include "PanzerAdaptersSTK_config.hpp"
17 #include "Panzer_PhysicsBlock.hpp"
18 #include "Panzer_BC.hpp"
19 #include "Panzer_Traits.hpp"
21 
22 #include "Panzer_STK_Interface.hpp"
23 
24 #include "Teuchos_RCP.hpp"
26 
27 #include <unordered_map>
28 #include <unordered_set>
29 
30 namespace panzer_stk {
31 
34 template <typename EvalT>
36 public:
37 
39  : mesh_(mesh), addSolutionFields_(true), addCoordinateFields_(true) {}
40 
42 
52  virtual Teuchos::RCP<panzer::ResponseBase> buildResponseObject(const std::string & responseName) const;
53 
54  virtual Teuchos::RCP<panzer::ResponseBase> buildResponseObject(const std::string & responseName,
55  const std::vector<panzer::WorksetDescriptor>& /* wkstDesc */) const
56  { return buildResponseObject(responseName); }
57 
69  virtual void buildAndRegisterEvaluators(const std::string & responseName,
71  const panzer::PhysicsBlock & physicsBlock,
72  const Teuchos::ParameterList & user_data) const;
73 
81  virtual bool typeSupported() const;
82 
86  static void bucketByBasisType(const std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & providedDofs,
87  std::map<std::string,std::vector<std::string> > & basisBucket);
88 
98  void scaleField(const std::string & fieldName,double fieldScalar);
99 
102  void addAdditionalField(const std::string & fieldName,const Teuchos::RCP<const panzer::PureBasis> & basis);
103 
106  void setAddSolutionFields(bool asf)
107  { addSolutionFields_ = asf; }
108 
111  void setAddCoordinateFields(bool acf)
112  { addCoordinateFields_ = acf; }
113 
118  void removeField(const std::string & fieldName)
119  { removedFields_.push_back(fieldName); }
120 
121  // should be private but needs a lambda
122  void computeReferenceCentroid(const std::map<std::string,Teuchos::RCP<const panzer::PureBasis> > & bases,
123  int baseDimension,
124  Kokkos::DynRankView<double,PHX::Device> & centroid) const;
125 
126 private:
128  void deleteRemovedFields(const std::vector<std::string> & removedFields,
129  std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & fields) const;
130 
132  std::vector<std::string> removedFields_;
133  bool operator() (const std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > & field)
134  { return std::find(removedFields_.begin(),removedFields_.end(),field.first)!=removedFields_.end(); }
135  };
136 
138 
139  std::unordered_map<std::string,double> fieldToScalar_;
140  std::unordered_set<std::string> scaledFieldsHash_; // used to print the warning about unused scaling
141 
142  std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > additionalFields_;
143  std::vector<std::string> removedFields_;
146 };
147 
153 
155 
156  void scaleField(const std::string & fieldName,double fieldScalar)
157  { fieldToScalar_[fieldName] = fieldScalar; }
158 
159  void addAdditionalField(const std::string & fieldName,const Teuchos::RCP<const panzer::PureBasis> & basis)
160  { additionalFields_.push_back(std::make_pair(fieldName,basis)); }
161 
166  void removeField(const std::string & fieldName)
167  { removedFields_.push_back(fieldName); }
168 
169  template <typename T>
171  {
174 
175  // disable/enable the solution fields
176  ref->setAddSolutionFields(addSolutionFields_);
177 
178  // disable/enable the coordinate fields
179  ref->setAddCoordinateFields(addCoordinateFields_);
180 
181  // add all additional fields
182  for(std::size_t i=0;i<additionalFields_.size();i++)
183  ref->addAdditionalField(additionalFields_[i].first,additionalFields_[i].second);
184 
185  for(std::size_t i=0;i<removedFields_.size();i++)
186  ref->removeField(removedFields_[i]);
187 
188  // set all scaled field values
189  for(std::unordered_map<std::string,double>::const_iterator itr=fieldToScalar_.begin();
190  itr!=fieldToScalar_.end();++itr)
191  ref->scaleField(itr->first,itr->second);
192 
193  return ref;
194  }
195 
198  void setAddSolutionFields(bool asf)
199  { addSolutionFields_ = asf; }
200 
203  void setAddCoordinateFields(bool acf)
204  { addCoordinateFields_ = acf; }
205 
206 private:
207  std::unordered_map<std::string,double> fieldToScalar_;
208  std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > additionalFields_;
209  std::vector<std::string> removedFields_;
212 };
213 
214 }
215 
216 #endif
void deleteRemovedFields(const std::vector< std::string > &removedFields, std::vector< std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > > &fields) const
Delete from the argument all the fields that are in the removedFields array.
Object that contains information on the physics and discretization of a block of elements with the SA...
void scaleField(const std::string &fieldName, double fieldScalar)
void addAdditionalField(const std::string &fieldName, const Teuchos::RCP< const panzer::PureBasis > &basis)
virtual Teuchos::RCP< panzer::ResponseBase > buildResponseObject(const std::string &responseName) const
bool operator()(const std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > &field)
std::vector< std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > > additionalFields_
void addAdditionalField(const std::string &fieldName, const Teuchos::RCP< const panzer::PureBasis > &basis)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual Teuchos::RCP< panzer::ResponseBase > buildResponseObject(const std::string &responseName, const std::vector< panzer::WorksetDescriptor > &) const
static void bucketByBasisType(const std::vector< std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > > &providedDofs, std::map< std::string, std::vector< std::string > > &basisBucket)
Teuchos::RCP< panzer::ResponseEvaluatorFactoryBase > build() const
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we&#39;ll contribute, or in which we&#39;ll store, the result of computing this integral...
virtual void buildAndRegisterEvaluators(const std::string &responseName, PHX::FieldManager< panzer::Traits > &fm, const panzer::PhysicsBlock &physicsBlock, const Teuchos::ParameterList &user_data) const
std::vector< std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > > additionalFields_
void computeReferenceCentroid(const std::map< std::string, Teuchos::RCP< const panzer::PureBasis > > &bases, int baseDimension, Kokkos::DynRankView< double, PHX::Device > &centroid) const