11 #ifndef __Panzer_ResponseLibrary_impl_hpp__
12 #define __Panzer_ResponseLibrary_impl_hpp__
21 #include "Thyra_VectorStdOps.hpp"
22 #include "Thyra_VectorSpaceBase.hpp"
24 #include <unordered_set>
28 template <
typename TraitsT>
30 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
31 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
35 template <
typename TraitsT>
40 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
41 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
49 template <
typename TraitsT>
51 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
52 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
57 template <
typename TraitsT>
63 disableScatter_ =
true;
64 residualType_ =
false;
71 template <
typename TraitsT>
77 disableScatter_ =
false;
86 addResidualResponse();
89 template <
typename TraitsT>
99 template <
typename TraitsT>
106 namespace panzer_tmp {
108 template <
typename TraitsT>
125 const std::string & respName,
const std::vector<std::pair<std::string,std::string> > & sidesets)
128 for(std::size_t i=0;i<sidesets.size();i++)
133 const std::string & respName,
const std::vector<WorksetDescriptor> & wkstDesc)
137 template <
typename T>
149 return Teuchos::null;
154 template <
typename TraitsT>
165 template <
typename T>
171 template <
typename TraitsT>
172 template <
typename ResponseEvaluatorFactory_BuilderT>
175 const std::vector<std::string> & blocks,
176 const ResponseEvaluatorFactory_BuilderT & builder)
182 "panzer::ResponseLibrary::addResponse: Method can't be called when the "
183 "response library is a \"residualType\"!");
188 modelFact_tm->buildObjects(builder);
190 std::vector<WorksetDescriptor> wkst_desc;
191 for(std::size_t i=0;i<blocks.size();i++)
194 addResponse(responseName,wkst_desc,modelFact_tm);
197 template <
typename TraitsT>
198 template <
typename ResponseEvaluatorFactory_BuilderT>
201 const std::vector<std::pair<std::string,std::string> > & sideset_blocks,
202 const ResponseEvaluatorFactory_BuilderT & builder)
208 "panzer::ResponseLibrary::addResponse: Method can't be called when the "
209 "response library is a \"residualType\"!");
214 modelFact_tm->buildObjects(builder);
218 responseObjects_[responseName].buildObjects(respData_builder);
221 for(std::size_t i=0;i<sideset_blocks.size();i++) {
222 std::string sideset = sideset_blocks[i].first;
223 std::string blockId = sideset_blocks[i].second;
225 BC bc(nextBC_id,
BCT_Neumann,sideset,blockId,
"Whatever",responseName+
"_BCStrategy");
229 = respBCFactories_[bc];
230 if(block_tm==Teuchos::null) {
232 respBCFactories_[bc] = block_tm;
236 block_tm->push_back(std::make_pair(responseName,modelFact_tm));
242 template <
typename TraitsT>
243 template <
typename ResponseEvaluatorFactory_BuilderT>
246 const std::vector<WorksetDescriptor> & wkst_desc,
247 const ResponseEvaluatorFactory_BuilderT & builder)
253 "panzer::ResponseLibrary::addResponse: Method can't be called when the "
254 "response library is a \"residualType\"!");
256 if(wkst_desc[0].useSideset() && !wkst_desc[0].sideAssembly()) {
259 std::vector<std::pair<std::string,std::string> > sideset_blocks;
260 for(std::size_t i=0;i<wkst_desc.size();i++) {
261 std::string sideset = wkst_desc[i].getSideset();
262 std::string blockId = wkst_desc[i].getElementBlock();
263 sideset_blocks.push_back(std::make_pair(sideset,blockId));
267 addResponse(responseName,sideset_blocks,builder);
275 modelFact_tm->buildObjects(builder);
277 addResponse(responseName,wkst_desc,modelFact_tm);
280 template <
typename TraitsT>
283 const std::vector<WorksetDescriptor> & wkst_desc,
288 responseObjects_[responseName].buildObjects(respData_builder);
291 for(std::size_t i=0;i<wkst_desc.size();i++) {
295 respFactories_[desc].push_back(std::make_pair(responseName,modelFact_tm));
299 template <
typename TraitsT>
303 std::string responseName =
"RESIDUAL";
309 responseObjects_[responseName].buildObjects(respData_builder);
312 template <
typename TraitsT>
313 template <
typename EvalT>
317 typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
318 HashMap::const_iterator itr = responseObjects_.find(responseName);
321 if(itr==responseObjects_.end())
322 return Teuchos::null;
325 return itr->second.get<EvalT>();
328 template <
typename TraitsT>
329 template <
typename EvalT>
333 typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
338 for(HashMap::const_iterator itr=responseObjects_.begin();itr!=responseObjects_.end();++itr)
339 responses.push_back(itr->second.get<EvalT>());
342 template <
typename TraitsT>
346 std::vector<std::pair<std::string,Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > >
RespFactoryTable;
359 typename RespFactoryTable::iterator itr=
rft_.find(wd);
364 std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > & respFacts = itr->second;
365 for(std::size_t i=0;i<respFacts.size();i++) {
366 std::string responseName = respFacts[i].first;
369 if(fact==Teuchos::null)
374 rf_itr!=fact->end();++rf_itr) {
377 if(rf_itr.rcp()==Teuchos::null || !rf_itr.rcp()->typeSupported())
381 rf_itr->buildAndRegisterEvaluators(responseName,fm,pb,
userData_);
393 template <
typename TraitsT>
401 const bool write_graphviz_file,
402 const std::string& graphviz_file_prefix)
407 "panzer::ResponseLibrary::buildResponseEvaluators: Method can't be called when the "
408 "response library is a \"residualType\"!");
411 std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > RespFactoryTable;
416 std::vector<Teuchos::RCP<panzer::PhysicsBlock> > requiredVolPhysicsBlocks;
417 std::vector<WorksetDescriptor> requiredWorksetDesc;
418 for(
typename RespFactoryTable::const_iterator itr=respFactories_.begin();
419 itr!=respFactories_.end();++itr) {
421 if(itr->second.size()==0)
424 const WorksetDescriptor & wd = itr->first;
428 for(std::size_t i=0;i<physicsBlocks.size();i++) {
430 requiredVolPhysicsBlocks.push_back(physicsBlocks[i]);
439 requiredWorksetDesc.push_back(wd);
444 for(
typename BCHashMap::const_iterator itr=respBCFactories_.begin();
445 itr!=respBCFactories_.end();++itr)
446 bcs.push_back(itr->first);
460 fmb2_->setWorksetContainer(wkstContainer_);
461 fmb2_->setupVolumeFieldManagers(requiredVolPhysicsBlocks,requiredWorksetDesc,cm_factory,closure_models,*linObjFactory_,user_data,rvef2,closureModelByEBlock_);
462 if(eqset_factory==Teuchos::null)
463 fmb2_->setupBCFieldManagers(bcs,physicsBlocks,cm_factory,bc_factory,closure_models,*linObjFactory_,user_data);
465 fmb2_->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory_,user_data);
467 if(write_graphviz_file) {
468 fmb2_->writeVolumeGraphvizDependencyFiles(
"Response_Volume_"+graphviz_file_prefix,requiredVolPhysicsBlocks);
469 fmb2_->writeBCGraphvizDependencyFiles(
"Response_Surface_"+graphviz_file_prefix);
476 ae_tm2_.buildObjects(builder);
478 responseEvaluatorsBuilt_ =
true;
481 template <
typename TraitsT>
486 const std::vector<BC> & bcs,
491 const bool write_graphviz_file,
492 const std::string& graphviz_file_prefix)
497 "panzer::ResponseLibrary::buildResidualResponseEvaluators: Method can only be called when the "
498 "response library is a \"residualType\"!");
503 fmb2_->setWorksetContainer(wkstContainer_);
504 fmb2_->setupVolumeFieldManagers(physicsBlocks,cm_factory,closure_models,*linObjFactory_,user_data);
505 fmb2_->setupBCFieldManagers(bcs,physicsBlocks,eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory_,user_data);
508 if (write_graphviz_file){
509 fmb2_->writeVolumeGraphvizDependencyFiles(
"ResidualResponse_Volume_"+graphviz_file_prefix,physicsBlocks);
510 fmb2_->writeBCGraphvizDependencyFiles(
"ResidualResponse_Surface_"+graphviz_file_prefix);
517 ae_tm2_.buildObjects(builder);
519 responseEvaluatorsBuilt_ =
true;
522 template <
typename TraitsT>
523 template <
typename EvalT>
527 std::vector<Teuchos::RCP<ResponseBase> > responses;
528 this->getResponses<EvalT>(responses);
532 for(std::size_t i=0;i<responses.size();i++) {
533 if(responses[i]!=Teuchos::null) {
543 template <
typename TraitsT>
548 using Teuchos::rcp_dynamic_cast;
550 typedef typename TraitsT::Residual EvalT;
551 typedef typename TraitsT::RealType ScalarT;
555 resp->initializeResponse();
558 if(ghostedContainer_==Teuchos::null)
559 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
571 thGhostedContainer->set_f_th(resp->getGhostedResidual());
572 thGlobalContainer->set_f_th(resp->getResidual());
578 Thyra::assign(thGhostedContainer->get_f_th().
ptr(),0.0);
581 template <
typename TraitsT>
586 using Teuchos::rcp_dynamic_cast;
588 typedef typename TraitsT::Jacobian EvalT;
589 typedef typename TraitsT::RealType ScalarT;
593 resp->initializeResponse();
596 if(ghostedContainer_==Teuchos::null)
597 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
609 thGhostedContainer->set_A_th(resp->getGhostedJacobian());
612 thGlobalContainer->set_f_th(dummy_f);
613 thGlobalContainer->set_A_th(resp->getJacobian());
616 thGhostedContainer->initializeMatrix(0.0);
619 template <
typename TraitsT>
624 using Teuchos::rcp_dynamic_cast;
626 typedef typename TraitsT::Tangent EvalT;
627 typedef typename TraitsT::RealType ScalarT;
631 resp->initializeResponse();
634 if(ghostedContainer_==Teuchos::null)
635 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
662 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
663 template <
typename TraitsT>
668 using Teuchos::rcp_dynamic_cast;
670 typedef typename TraitsT::Hessian EvalT;
671 typedef typename TraitsT::RealType ScalarT;
675 resp->initializeResponse();
678 if(ghostedContainer_==Teuchos::null)
679 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
691 thGhostedContainer->set_A_th(resp->getGhostedHessian());
694 thGlobalContainer->set_f_th(dummy_f);
695 thGlobalContainer->set_A_th(resp->getHessian());
698 thGhostedContainer->initializeMatrix(0.0);
702 template <
typename TraitsT>
703 template <
typename EvalT>
707 ae_tm2_.template getAsObject<EvalT>()->evaluate(input_args);
710 template <
typename TraitsT>
714 typedef std::unordered_map<std::string, Response_TemplateManager> RespObjType;
716 for(RespObjType::const_iterator itr=responseObjects_.begin();itr!=responseObjects_.end();++itr) {
717 std::string respName = itr->first;
718 os <<
"Response \"" << respName <<
"\": ";
719 Sacado::mpl::for_each<typename Response_TemplateManager::types_vector>(
Printer(itr->second,os));
Interface for constructing a BCStrategy_TemplateManager.
void addResponse(const std::string &responseName, const std::vector< std::string > &blocks, const ResponseEvaluatorFactory_BuilderT &builder)
Allocates and initializes an equation set template manager.
Object that contains information on the physics and discretization of a block of elements with the SA...
void getResponses(std::vector< Teuchos::RCP< ResponseBase > > &responses) const
void addResponsesToInArgs(panzer::AssemblyEngineInArgs &input_args) const
virtual bool typeSupported() const =0
ResidualResponse_Builder(const std::string &respName, const Teuchos::RCP< const LinearObjFactory< TraitsT > > &lof)
std::unordered_map< WorksetDescriptor, std::vector< std::pair< std::string, Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > > > > RespFactoryTable
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const std::string & getElementBlock(const int block=0) const
Get element block name.
WorksetDescriptor sidesetDescriptor(const std::string &eBlock, const std::string &sideset)
Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > respFact_
Teuchos::RCP< panzer::LinearObjContainer > ghostedContainer_
void evaluate(const panzer::AssemblyEngineInArgs &input_args)
void buildResidualResponseEvaluators(const std::vector< Teuchos::RCP< panzer::PhysicsBlock > > &physicsBlocks, const panzer::EquationSetFactory &eqset_factory, const std::vector< BC > &bcs, const panzer::BCStrategyFactory &bc_factory, const panzer::ClosureModelFactory_TemplateManager< panzer::Traits > &cm_factory, const Teuchos::ParameterList &closure_models, const Teuchos::ParameterList &user_data, const bool write_graphviz_file=false, const std::string &graphviz_file_prefix="")
Teuchos::RCP< panzer::LinearObjContainer > container_
void addGlobalEvaluationData(const std::string &key, const Teuchos::RCP< GlobalEvaluationData > &ged)
void buildResponseEvaluators(const std::vector< Teuchos::RCP< panzer::PhysicsBlock > > &physicsBlocks, const panzer::ClosureModelFactory_TemplateManager< panzer::Traits > &cm_factory, const Teuchos::ParameterList &closure_models, const Teuchos::ParameterList &user_data, const bool write_graphviz_file=false, const std::string &graphviz_file_prefix="")
Teuchos::RCP< ResponseBase > build() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void copyResponses(const ResponseLibrary &rl)
std::vector< WorksetDescriptor > wkstDesc_
Teuchos::RCP< const GlobalIndexer > globalIndexer_
std::string elementBlockID() const
Teuchos::RCP< const LinearObjFactory< TraitsT > > lof_
Teuchos::RCP< ResponseBase > build() const
Teuchos::RCP< ResponseBase > getResponse(const std::string &responseName) const
Teuchos::RCP< WorksetContainer > wkstContainer_
bool registerEvaluators(PHX::FieldManager< TraitsT > &fm, const WorksetDescriptor &wd, const PhysicsBlock &pb) const
void initialize(const Teuchos::RCP< WorksetContainer > &wc, const Teuchos::RCP< const GlobalIndexer > &ugi, const Teuchos::RCP< const LinearObjFactory< TraitsT > > &lof)
void print(std::ostream &os) const
ResponseBase_Builder(const Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > &respFact, const std::string &respName, const std::vector< std::pair< std::string, std::string > > &sidesets)
void initializeResidualType(const Teuchos::RCP< WorksetContainer > &wc, const Teuchos::RCP< const GlobalIndexer > &ugi, const Teuchos::RCP< const LinearObjFactory< TraitsT > > &lof)
WorksetDescriptor blockDescriptor(const std::string &eBlock)
Teuchos::RCP< const LinearObjFactory< TraitsT > > linObjFactory_
Stores input information for a boundary condition.
#define TEUCHOS_ASSERT(assertion_test)
virtual Teuchos::RCP< ResponseBase > buildResponseObject(const std::string &responseName, const std::vector< WorksetDescriptor > &wkstdescs) const =0
const Teuchos::ParameterList & userData_
void addResidualResponse()
ResponseBase_Builder(const Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > &respFact, const std::string &respName, const std::vector< WorksetDescriptor > &wkstDesc)
RVEF2(const Teuchos::ParameterList &userData, RespFactoryTable &rft)
void addResidualResponsesToInArgs(Overloader< typename TraitsT::Residual >, panzer::AssemblyEngineInArgs &input_args) const
A struct for handling function overloading.