43 #ifndef __Panzer_ResponseLibrary_impl_hpp__ 44 #define __Panzer_ResponseLibrary_impl_hpp__ 53 #include "Thyra_VectorStdOps.hpp" 54 #include "Thyra_VectorSpaceBase.hpp" 56 #include <unordered_set> 60 template <
typename TraitsT>
62 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
63 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
67 template <
typename TraitsT>
69 const Teuchos::RCP<const UniqueGlobalIndexerBase> & ugi,
72 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
73 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
81 template <
typename TraitsT>
83 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
84 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
89 template <
typename TraitsT>
92 const Teuchos::RCP<const UniqueGlobalIndexerBase> & ugi,
95 disableScatter_ =
true;
96 residualType_ =
false;
100 linObjFactory_ = lof;
103 template <
typename TraitsT>
106 const Teuchos::RCP<const UniqueGlobalIndexerBase> & ugi,
109 disableScatter_ =
false;
111 residualType_ =
true;
114 globalIndexer_ = ugi;
115 linObjFactory_ = lof;
118 addResidualResponse();
121 template <
typename TraitsT>
131 template <
typename TraitsT>
135 TEUCHOS_ASSERT(
false);
140 template <
typename TraitsT>
141 class ResponseBase_Builder {
142 Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> >
respFact_;
148 ResponseBase_Builder(
const Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > & respFact,
149 const std::string & respName,
const std::vector<std::string> & eBlocks)
152 for(std::size_t i=0;i<eBlocks.size();i++)
156 ResponseBase_Builder(
const Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > & respFact,
157 const std::string & respName,
const std::vector<std::pair<std::string,std::string> > & sidesets)
160 for(std::size_t i=0;i<sidesets.size();i++)
164 ResponseBase_Builder(
const Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > & respFact,
165 const std::string & respName,
const std::vector<WorksetDescriptor> & wkstDesc)
169 template <
typename T>
170 Teuchos::RCP<ResponseBase> build()
const 172 Teuchos::RCP<const panzer::ResponseEvaluatorFactoryBase> baseObj =
respFact_->template getAsBase<T>();
175 if(baseObj!=Teuchos::null && baseObj->typeSupported()) {
181 return Teuchos::null;
186 template <
typename TraitsT>
187 class ResidualResponse_Builder {
189 Teuchos::RCP<const LinearObjFactory<TraitsT> >
lof_;
193 ResidualResponse_Builder(
const std::string & respName,
const Teuchos::RCP<
const LinearObjFactory<TraitsT> > & lof)
197 template <
typename T>
198 Teuchos::RCP<ResponseBase> build()
const 199 {
return Teuchos::rcp(
new Response_Residual<T>(
respName_,
lof_)); }
203 template <
typename TraitsT>
204 template <
typename ResponseEvaluatorFactory_BuilderT>
207 const std::vector<std::string> & blocks,
208 const ResponseEvaluatorFactory_BuilderT & builder)
213 TEUCHOS_TEST_FOR_EXCEPTION(residualType_,std::invalid_argument,
214 "panzer::ResponseLibrary::addResponse: Method can't be called when the " 215 "response library is a \"residualType\"!");
218 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
220 modelFact_tm->buildObjects(builder);
222 std::vector<WorksetDescriptor> wkst_desc;
223 for(std::size_t i=0;i<blocks.size();i++)
226 addResponse(responseName,wkst_desc,modelFact_tm);
229 template <
typename TraitsT>
230 template <
typename ResponseEvaluatorFactory_BuilderT>
233 const std::vector<std::pair<std::string,std::string> > & sideset_blocks,
234 const ResponseEvaluatorFactory_BuilderT & builder)
239 TEUCHOS_TEST_FOR_EXCEPTION(residualType_,std::invalid_argument,
240 "panzer::ResponseLibrary::addResponse: Method can't be called when the " 241 "response library is a \"residualType\"!");
244 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
246 modelFact_tm->buildObjects(builder);
249 ResponseBase_Builder<TraitsT> respData_builder(modelFact_tm,responseName,sideset_blocks);
250 responseObjects_[responseName].buildObjects(respData_builder);
253 for(std::size_t i=0;i<sideset_blocks.size();i++) {
254 std::string sideset = sideset_blocks[i].first;
255 std::string blockId = sideset_blocks[i].second;
257 BC bc(nextBC_id,
BCT_Neumann,sideset,blockId,
"Whatever",responseName+
"_BCStrategy");
260 RCP<std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > block_tm
261 = respBCFactories_[bc];
262 if(block_tm==Teuchos::null) {
264 respBCFactories_[bc] = block_tm;
268 block_tm->push_back(std::make_pair(responseName,modelFact_tm));
274 template <
typename TraitsT>
275 template <
typename ResponseEvaluatorFactory_BuilderT>
278 const std::vector<WorksetDescriptor> & wkst_desc,
279 const ResponseEvaluatorFactory_BuilderT & builder)
284 TEUCHOS_TEST_FOR_EXCEPTION(residualType_,std::invalid_argument,
285 "panzer::ResponseLibrary::addResponse: Method can't be called when the " 286 "response library is a \"residualType\"!");
288 if(wkst_desc[0].useSideset() && !wkst_desc[0].sideAssembly()) {
291 std::vector<std::pair<std::string,std::string> > sideset_blocks;
292 for(std::size_t i=0;i<wkst_desc.size();i++) {
293 std::string sideset = wkst_desc[i].getSideset();
294 std::string blockId = wkst_desc[i].getElementBlock();
295 sideset_blocks.push_back(std::make_pair(sideset,blockId));
299 addResponse(responseName,sideset_blocks,builder);
305 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
307 modelFact_tm->buildObjects(builder);
309 addResponse(responseName,wkst_desc,modelFact_tm);
312 template <
typename TraitsT>
315 const std::vector<WorksetDescriptor> & wkst_desc,
319 ResponseBase_Builder<TraitsT> respData_builder(modelFact_tm,responseName,wkst_desc);
320 responseObjects_[responseName].buildObjects(respData_builder);
323 for(std::size_t i=0;i<wkst_desc.size();i++) {
327 respFactories_[desc].push_back(std::make_pair(responseName,modelFact_tm));
331 template <
typename TraitsT>
335 std::string responseName =
"RESIDUAL";
338 ResidualResponse_Builder<TraitsT> respData_builder(responseName,linObjFactory_);
341 responseObjects_[responseName].buildObjects(respData_builder);
344 template <
typename TraitsT>
345 template <
typename EvalT>
349 typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
350 HashMap::const_iterator itr = responseObjects_.find(responseName);
353 if(itr==responseObjects_.end())
354 return Teuchos::null;
357 return itr->second.get<EvalT>();
360 template <
typename TraitsT>
361 template <
typename EvalT>
363 getResponses(std::vector<Teuchos::RCP<ResponseBase> > & responses)
const 365 typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
370 for(HashMap::const_iterator itr=responseObjects_.begin();itr!=responseObjects_.end();++itr)
371 responses.push_back(itr->second.get<EvalT>());
374 template <
typename TraitsT>
378 std::vector<std::pair<std::string,Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > >
RespFactoryTable;
391 typename RespFactoryTable::iterator itr=
rft_.find(wd);
393 TEUCHOS_ASSERT(itr!=
rft_.end() && itr->second.size()>0);
396 std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > & respFacts = itr->second;
397 for(std::size_t i=0;i<respFacts.size();i++) {
398 std::string responseName = respFacts[i].first;
399 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > fact = respFacts[i].second;
401 if(fact==Teuchos::null)
406 rf_itr!=fact->end();++rf_itr) {
409 if(rf_itr.rcp()==Teuchos::null || !rf_itr.rcp()->typeSupported())
413 rf_itr->buildAndRegisterEvaluators(responseName,fm,pb,
userData_);
425 template <
typename TraitsT>
428 const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
429 const Teuchos::Ptr<const panzer::EquationSetFactory> & eqset_factory,
431 const Teuchos::ParameterList& closure_models,
432 const Teuchos::ParameterList& user_data,
433 const bool write_graphviz_file,
434 const std::string& graphviz_file_prefix)
438 TEUCHOS_TEST_FOR_EXCEPTION(residualType_,std::invalid_argument,
439 "panzer::ResponseLibrary::buildResponseEvaluators: Method can't be called when the " 440 "response library is a \"residualType\"!");
443 std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > RespFactoryTable;
448 std::vector<Teuchos::RCP<panzer::PhysicsBlock> > requiredVolPhysicsBlocks;
449 std::vector<WorksetDescriptor> requiredWorksetDesc;
450 for(
typename RespFactoryTable::const_iterator itr=respFactories_.begin();
451 itr!=respFactories_.end();++itr) {
453 if(itr->second.size()==0)
460 for(std::size_t i=0;i<physicsBlocks.size();i++) {
462 requiredVolPhysicsBlocks.push_back(physicsBlocks[i]);
471 requiredWorksetDesc.push_back(wd);
476 for(
typename BCHashMap::const_iterator itr=respBCFactories_.begin();
477 itr!=respBCFactories_.end();++itr)
478 bcs.push_back(itr->first);
492 fmb2_->setWorksetContainer(wkstContainer_);
493 fmb2_->setupVolumeFieldManagers(requiredVolPhysicsBlocks,requiredWorksetDesc,cm_factory,closure_models,*linObjFactory_,user_data,rvef2,closureModelByEBlock_);
494 if(eqset_factory==Teuchos::null)
495 fmb2_->setupBCFieldManagers(bcs,physicsBlocks,cm_factory,bc_factory,closure_models,*linObjFactory_,user_data);
497 fmb2_->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory_,user_data);
499 if(write_graphviz_file) {
500 fmb2_->writeVolumeGraphvizDependencyFiles(
"Response_Volume_"+graphviz_file_prefix,requiredVolPhysicsBlocks);
501 fmb2_->writeBCGraphvizDependencyFiles(
"Response_Surface_"+graphviz_file_prefix);
508 ae_tm2_.buildObjects(builder);
510 responseEvaluatorsBuilt_ =
true;
513 template <
typename TraitsT>
516 const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
518 const std::vector<BC> & bcs,
521 const Teuchos::ParameterList& closure_models,
522 const Teuchos::ParameterList& user_data,
523 const bool write_graphviz_file,
524 const std::string& graphviz_file_prefix)
528 TEUCHOS_TEST_FOR_EXCEPTION(!residualType_,std::invalid_argument,
529 "panzer::ResponseLibrary::buildResidualResponseEvaluators: Method can only be called when the " 530 "response library is a \"residualType\"!");
535 fmb2_->setWorksetContainer(wkstContainer_);
536 fmb2_->setupVolumeFieldManagers(physicsBlocks,cm_factory,closure_models,*linObjFactory_,user_data);
537 fmb2_->setupBCFieldManagers(bcs,physicsBlocks,eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory_,user_data);
540 if (write_graphviz_file){
541 fmb2_->writeVolumeGraphvizDependencyFiles(
"ResidualResponse_Volume_"+graphviz_file_prefix,physicsBlocks);
542 fmb2_->writeBCGraphvizDependencyFiles(
"ResidualResponse_Surface_"+graphviz_file_prefix);
549 ae_tm2_.buildObjects(builder);
551 responseEvaluatorsBuilt_ =
true;
554 template <
typename TraitsT>
555 template <
typename EvalT>
559 std::vector<Teuchos::RCP<ResponseBase> > responses;
560 this->getResponses<EvalT>(responses);
564 for(std::size_t i=0;i<responses.size();i++) {
565 if(responses[i]!=Teuchos::null) {
575 template <
typename TraitsT>
580 using Teuchos::rcp_dynamic_cast;
582 typedef typename TraitsT::Residual EvalT;
583 typedef typename TraitsT::RealType ScalarT;
587 resp->initializeResponse();
590 if(ghostedContainer_==Teuchos::null)
591 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
594 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
599 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
603 thGhostedContainer->
set_f_th(resp->getGhostedResidual());
604 thGlobalContainer->set_f_th(resp->getResidual());
606 TEUCHOS_ASSERT(thGhostedContainer->get_f_th()!=Teuchos::null);
607 TEUCHOS_ASSERT(thGlobalContainer->get_f_th()!=Teuchos::null);
610 Thyra::assign(thGhostedContainer->get_f_th().ptr(),0.0);
613 template <
typename TraitsT>
618 using Teuchos::rcp_dynamic_cast;
620 typedef typename TraitsT::Jacobian EvalT;
621 typedef typename TraitsT::RealType ScalarT;
625 resp->initializeResponse();
628 if(ghostedContainer_==Teuchos::null)
629 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
632 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
637 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
641 thGhostedContainer->
set_A_th(resp->getGhostedJacobian());
643 RCP<Thyra::VectorBase<ScalarT> > dummy_f = Thyra::createMember(resp->getJacobian()->range());
644 thGlobalContainer->set_f_th(dummy_f);
645 thGlobalContainer->set_A_th(resp->getJacobian());
648 thGhostedContainer->initializeMatrix(0.0);
651 template <
typename TraitsT>
656 using Teuchos::rcp_dynamic_cast;
658 typedef typename TraitsT::Tangent EvalT;
659 typedef typename TraitsT::RealType ScalarT;
663 resp->initializeResponse();
666 if(ghostedContainer_==Teuchos::null)
667 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
670 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
675 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
694 #ifdef Panzer_BUILD_HESSIAN_SUPPORT 695 template <
typename TraitsT>
700 using Teuchos::rcp_dynamic_cast;
702 typedef typename TraitsT::Hessian EvalT;
703 typedef typename TraitsT::RealType ScalarT;
707 resp->initializeResponse();
710 if(ghostedContainer_==Teuchos::null)
711 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
714 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
719 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
723 thGhostedContainer->
set_A_th(resp->getGhostedHessian());
725 RCP<Thyra::VectorBase<ScalarT> > dummy_f = Thyra::createMember(resp->getHessian()->range());
726 thGlobalContainer->set_f_th(dummy_f);
727 thGlobalContainer->set_A_th(resp->getHessian());
730 thGhostedContainer->initializeMatrix(0.0);
734 template <
typename TraitsT>
735 template <
typename EvalT>
739 ae_tm2_.template getAsObject<EvalT>()->evaluate(input_args);
742 template <
typename TraitsT>
746 typedef std::unordered_map<std::string, Response_TemplateManager> RespObjType;
748 for(RespObjType::const_iterator itr=responseObjects_.begin();itr!=responseObjects_.end();++itr) {
749 std::string respName = itr->first;
750 os <<
"Response \"" << respName <<
"\": ";
751 Sacado::mpl::for_each<typename Response_TemplateManager::types_vector>(
Printer(itr->second,os));
Interface for constructing a BCStrategy_TemplateManager.
Teuchos::RCP< const LinearObjFactory< TraitsT > > lof_
void addResponse(const std::string &responseName, const std::vector< std::string > &blocks, const ResponseEvaluatorFactory_BuilderT &builder)
Allocates and initializes an equation set template manager.
void initializeResidualType(const Teuchos::RCP< WorksetContainer > &wc, const Teuchos::RCP< const UniqueGlobalIndexerBase > &ugi, const Teuchos::RCP< const LinearObjFactory< TraitsT > > &lof)
Object that contains information on the physics and discretization of a block of elements with the SA...
void initialize(const Teuchos::RCP< WorksetContainer > &wc, const Teuchos::RCP< const UniqueGlobalIndexerBase > &ugi, const Teuchos::RCP< const LinearObjFactory< TraitsT > > &lof)
void addResponsesToInArgs(panzer::AssemblyEngineInArgs &input_args) const
std::unordered_map< WorksetDescriptor, std::vector< std::pair< std::string, Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > > > > RespFactoryTable
Teuchos::RCP< const UniqueGlobalIndexerBase > globalIndexer_
Teuchos::RCP< ResponseBase > getResponse(const std::string &responseName) const
std::string elementBlockID() const
std::vector< WorksetDescriptor > wkstDesc_
bool registerEvaluators(PHX::FieldManager< TraitsT > &fm, const WorksetDescriptor &wd, const PhysicsBlock &pb) const
WorksetDescriptor sidesetDescriptor(const std::string &eBlock, const std::string &sideset)
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="")
void addResidualResponsesToInArgs(Overloader< typename TraitsT::Residual >, panzer::AssemblyEngineInArgs &input_args) const
void copyResponses(const ResponseLibrary &rl)
virtual void set_f_th(const Teuchos::RCP< Thyra::VectorBase< ScalarT > > &in)=0
Teuchos::RCP< WorksetContainer > wkstContainer_
void getResponses(std::vector< Teuchos::RCP< ResponseBase > > &responses) const
virtual void set_A_th(const Teuchos::RCP< Thyra::LinearOpBase< ScalarT > > &in)=0
Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > respFact_
WorksetDescriptor blockDescriptor(const std::string &eBlock)
Teuchos::RCP< const LinearObjFactory< TraitsT > > linObjFactory_
Stores input information for a boundary condition.
void print(std::ostream &os) const
const std::string & getElementBlock(const int block=0) const
Get element block name.
const Teuchos::ParameterList & userData_
void addResidualResponse()
RVEF2(const Teuchos::ParameterList &userData, RespFactoryTable &rft)
A struct for handling function overloading.