Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_STK_ResponseEvaluatorFactory_SolutionWriter.hpp
Go to the documentation of this file.
1#ifndef __Panzer_STK_ResponseEvaluatorFactory_SolutionWriter_hpp__
2#define __Panzer_STK_ResponseEvaluatorFactory_SolutionWriter_hpp__
3
4#include <string>
5
6#include "PanzerAdaptersSTK_config.hpp"
8#include "Panzer_BC.hpp"
9#include "Panzer_Traits.hpp"
11
13
14#include "Teuchos_RCP.hpp"
15#include "Teuchos_ParameterList.hpp"
16
17#include <unordered_map>
18#include <unordered_set>
19
20namespace panzer_stk {
21
24template <typename EvalT>
26public:
27
28 ResponseEvaluatorFactory_SolutionWriter(const Teuchos::RCP<STK_Interface> & mesh)
29 : mesh_(mesh), addSolutionFields_(true), addCoordinateFields_(true) {}
30
32
42 virtual Teuchos::RCP<panzer::ResponseBase> buildResponseObject(const std::string & responseName) const;
43
44 virtual Teuchos::RCP<panzer::ResponseBase> buildResponseObject(const std::string & responseName,
45 const std::vector<panzer::WorksetDescriptor>& /* wkstDesc */) const
46 { return buildResponseObject(responseName); }
47
59 virtual void buildAndRegisterEvaluators(const std::string & responseName,
61 const panzer::PhysicsBlock & physicsBlock,
62 const Teuchos::ParameterList & user_data) const;
63
71 virtual bool typeSupported() const;
72
76 static void bucketByBasisType(const std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & providedDofs,
77 std::map<std::string,std::vector<std::string> > & basisBucket);
78
88 void scaleField(const std::string & fieldName,double fieldScalar);
89
92 void addAdditionalField(const std::string & fieldName,const Teuchos::RCP<const panzer::PureBasis> & basis);
93
96 void setAddSolutionFields(bool asf)
97 { addSolutionFields_ = asf; }
98
102 { addCoordinateFields_ = acf; }
103
108 void removeField(const std::string & fieldName)
109 { removedFields_.push_back(fieldName); }
110
111 // should be private but needs a lambda
112 void computeReferenceCentroid(const std::map<std::string,Teuchos::RCP<const panzer::PureBasis> > & bases,
113 int baseDimension,
114 Kokkos::DynRankView<double,PHX::Device> & centroid) const;
115
116private:
118 void deleteRemovedFields(const std::vector<std::string> & removedFields,
119 std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & fields) const;
120
121 struct RemovedFieldsSearchUnaryFunctor : public std::unary_function<std::pair<std::string,const panzer::PureBasis>,bool> {
122 std::vector<std::string> removedFields_;
123 bool operator() (const std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > & field)
124 { return std::find(removedFields_.begin(),removedFields_.end(),field.first)!=removedFields_.end(); }
125 };
126
127 Teuchos::RCP<STK_Interface> mesh_;
128
129 std::unordered_map<std::string,double> fieldToScalar_;
130 std::unordered_set<std::string> scaledFieldsHash_; // used to print the warning about unused scaling
131
132 std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > additionalFields_;
133 std::vector<std::string> removedFields_;
136};
137
143
144 Teuchos::RCP<panzer_stk::STK_Interface> mesh;
145
146 void scaleField(const std::string & fieldName,double fieldScalar)
147 { fieldToScalar_[fieldName] = fieldScalar; }
148
149 void addAdditionalField(const std::string & fieldName,const Teuchos::RCP<const panzer::PureBasis> & basis)
150 { additionalFields_.push_back(std::make_pair(fieldName,basis)); }
151
156 void removeField(const std::string & fieldName)
157 { removedFields_.push_back(fieldName); }
158
159 template <typename T>
160 Teuchos::RCP<panzer::ResponseEvaluatorFactoryBase> build() const
161 {
162 Teuchos::RCP<ResponseEvaluatorFactory_SolutionWriter<T> > ref =
164
165 // disable/enable the solution fields
166 ref->setAddSolutionFields(addSolutionFields_);
167
168 // disable/enable the coordinate fields
169 ref->setAddCoordinateFields(addCoordinateFields_);
170
171 // add all additional fields
172 for(std::size_t i=0;i<additionalFields_.size();i++)
173 ref->addAdditionalField(additionalFields_[i].first,additionalFields_[i].second);
174
175 for(std::size_t i=0;i<removedFields_.size();i++)
176 ref->removeField(removedFields_[i]);
177
178 // set all scaled field values
179 for(std::unordered_map<std::string,double>::const_iterator itr=fieldToScalar_.begin();
180 itr!=fieldToScalar_.end();++itr)
181 ref->scaleField(itr->first,itr->second);
182
183 return ref;
184 }
185
188 void setAddSolutionFields(bool asf)
189 { addSolutionFields_ = asf; }
190
194 { addCoordinateFields_ = acf; }
195
196private:
197 std::unordered_map<std::string,double> fieldToScalar_;
198 std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > additionalFields_;
199 std::vector<std::string> removedFields_;
202};
203
204}
205
206#endif
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we'll contribute, or in which we'll store, the result of computing this integral.
Object that contains information on the physics and discretization of a block of elements with the SA...
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.
virtual Teuchos::RCP< panzer::ResponseBase > buildResponseObject(const std::string &responseName, const std::vector< panzer::WorksetDescriptor > &) const
void addAdditionalField(const std::string &fieldName, const Teuchos::RCP< const panzer::PureBasis > &basis)
virtual void buildAndRegisterEvaluators(const std::string &responseName, PHX::FieldManager< panzer::Traits > &fm, const panzer::PhysicsBlock &physicsBlock, const Teuchos::ParameterList &user_data) const
void computeReferenceCentroid(const std::map< std::string, Teuchos::RCP< const panzer::PureBasis > > &bases, int baseDimension, Kokkos::DynRankView< double, PHX::Device > &centroid) 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)
std::vector< std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > > additionalFields_
virtual Teuchos::RCP< panzer::ResponseBase > buildResponseObject(const std::string &responseName) const
Teuchos::RCP< panzer::ResponseEvaluatorFactoryBase > build() const
void addAdditionalField(const std::string &fieldName, const Teuchos::RCP< const panzer::PureBasis > &basis)
void scaleField(const std::string &fieldName, double fieldScalar)
std::vector< std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > > additionalFields_
bool operator()(const std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > &field)