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>
28template <
typename TraitsT>
35template <
typename TraitsT>
37 const Teuchos::RCP<const GlobalIndexer> & ugi,
49template <
typename TraitsT>
57template <
typename TraitsT>
59initialize(
const Teuchos::RCP<WorksetContainer> & wc,
60 const Teuchos::RCP<const GlobalIndexer> & ugi,
71template <
typename TraitsT>
74 const Teuchos::RCP<const GlobalIndexer> & ugi,
89template <
typename TraitsT>
99template <
typename TraitsT>
103 TEUCHOS_ASSERT(
false);
108 template <
typename TraitsT>
110 Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> >
respFact_;
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>
138 Teuchos::RCP<ResponseBase>
build()
const
140 Teuchos::RCP<const panzer::ResponseEvaluatorFactoryBase> baseObj =
respFact_->template getAsBase<T>();
143 if(baseObj!=Teuchos::null && baseObj->typeSupported()) {
149 return Teuchos::null;
154 template <
typename TraitsT>
157 Teuchos::RCP<const LinearObjFactory<TraitsT> >
lof_;
165 template <
typename T>
166 Teuchos::RCP<ResponseBase>
build()
const
171template <
typename TraitsT>
172template <
typename ResponseEvaluatorFactory_BuilderT>
175 const std::vector<std::string> & blocks,
176 const ResponseEvaluatorFactory_BuilderT & builder)
181 TEUCHOS_TEST_FOR_EXCEPTION(
residualType_,std::invalid_argument,
182 "panzer::ResponseLibrary::addResponse: Method can't be called when the "
183 "response library is a \"residualType\"!");
186 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
188 modelFact_tm->buildObjects(builder);
190 std::vector<WorksetDescriptor> wkst_desc;
191 for(std::size_t i=0;i<blocks.size();i++)
197template <
typename TraitsT>
198template <
typename ResponseEvaluatorFactory_BuilderT>
201 const std::vector<std::pair<std::string,std::string> > & sideset_blocks,
202 const ResponseEvaluatorFactory_BuilderT & builder)
207 TEUCHOS_TEST_FOR_EXCEPTION(
residualType_,std::invalid_argument,
208 "panzer::ResponseLibrary::addResponse: Method can't be called when the "
209 "response library is a \"residualType\"!");
212 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
214 modelFact_tm->buildObjects(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;
228 RCP<std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > block_tm
230 if(block_tm==Teuchos::null) {
236 block_tm->push_back(std::make_pair(responseName,modelFact_tm));
242template <
typename TraitsT>
243template <
typename ResponseEvaluatorFactory_BuilderT>
246 const std::vector<WorksetDescriptor> & wkst_desc,
247 const ResponseEvaluatorFactory_BuilderT & builder)
252 TEUCHOS_TEST_FOR_EXCEPTION(
residualType_,std::invalid_argument,
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));
273 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
275 modelFact_tm->buildObjects(builder);
280template <
typename TraitsT>
283 const std::vector<WorksetDescriptor> & wkst_desc,
291 for(std::size_t i=0;i<wkst_desc.size();i++) {
295 respFactories_[desc].push_back(std::make_pair(responseName,modelFact_tm));
299template <
typename TraitsT>
303 std::string responseName =
"RESIDUAL";
312template <
typename TraitsT>
313template <
typename EvalT>
317 typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
322 return Teuchos::null;
325 return itr->second.get<EvalT>();
328template <
typename TraitsT>
329template <
typename EvalT>
331getResponses(std::vector<Teuchos::RCP<ResponseBase> > & responses)
const
333 typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
339 responses.push_back(itr->second.get<EvalT>());
342template <
typename TraitsT>
346 std::vector<std::pair<std::string,Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > >
RespFactoryTable;
359 typename RespFactoryTable::iterator itr=
rft_.find(wd);
361 TEUCHOS_ASSERT(itr!=
rft_.end() && itr->second.size()>0);
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;
367 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > fact = respFacts[i].second;
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_);
393template <
typename TraitsT>
396 const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
397 const Teuchos::Ptr<const panzer::EquationSetFactory> & eqset_factory,
399 const Teuchos::ParameterList& closure_models,
400 const Teuchos::ParameterList& user_data,
401 const bool write_graphviz_file,
402 const std::string& graphviz_file_prefix)
406 TEUCHOS_TEST_FOR_EXCEPTION(
residualType_,std::invalid_argument,
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();
421 if(itr->second.size()==0)
428 for(std::size_t i=0;i<physicsBlocks.size();i++) {
430 requiredVolPhysicsBlocks.push_back(physicsBlocks[i]);
439 requiredWorksetDesc.push_back(wd);
446 bcs.push_back(itr->first);
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);
481template <
typename TraitsT>
484 const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
486 const std::vector<BC> & bcs,
489 const Teuchos::ParameterList& closure_models,
490 const Teuchos::ParameterList& user_data,
491 const bool write_graphviz_file,
492 const std::string& graphviz_file_prefix)
496 TEUCHOS_TEST_FOR_EXCEPTION(!
residualType_,std::invalid_argument,
497 "panzer::ResponseLibrary::buildResidualResponseEvaluators: Method can only be called when the "
498 "response library is a \"residualType\"!");
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);
522template <
typename TraitsT>
523template <
typename EvalT>
527 std::vector<Teuchos::RCP<ResponseBase> > responses;
532 for(std::size_t i=0;i<responses.size();i++) {
533 if(responses[i]!=Teuchos::null) {
543template <
typename TraitsT>
548 using Teuchos::rcp_dynamic_cast;
550 typedef typename TraitsT::Residual EvalT;
551 typedef typename TraitsT::RealType ScalarT;
554 RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(
getResponse<EvalT>(
"RESIDUAL"));
555 resp->initializeResponse();
562 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
567 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
568 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.
container_);
571 thGhostedContainer->set_f_th(resp->getGhostedResidual());
572 thGlobalContainer->set_f_th(resp->getResidual());
574 TEUCHOS_ASSERT(thGhostedContainer->get_f_th()!=Teuchos::null);
575 TEUCHOS_ASSERT(thGlobalContainer->get_f_th()!=Teuchos::null);
578 Thyra::assign(thGhostedContainer->get_f_th().ptr(),0.0);
581template <
typename TraitsT>
586 using Teuchos::rcp_dynamic_cast;
588 typedef typename TraitsT::Jacobian EvalT;
589 typedef typename TraitsT::RealType ScalarT;
592 RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(
getResponse<EvalT>(
"RESIDUAL"));
593 resp->initializeResponse();
600 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
605 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
606 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.
container_);
609 thGhostedContainer->set_A_th(resp->getGhostedJacobian());
611 RCP<Thyra::VectorBase<ScalarT> > dummy_f = Thyra::createMember(resp->getJacobian()->range());
612 thGlobalContainer->set_f_th(dummy_f);
613 thGlobalContainer->set_A_th(resp->getJacobian());
616 thGhostedContainer->initializeMatrix(0.0);
619template <
typename TraitsT>
624 using Teuchos::rcp_dynamic_cast;
626 typedef typename TraitsT::Tangent EvalT;
627 typedef typename TraitsT::RealType ScalarT;
630 RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(
getResponse<EvalT>(
"RESIDUAL"));
631 resp->initializeResponse();
638 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
643 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
644 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.
container_);
662#ifdef Panzer_BUILD_HESSIAN_SUPPORT
663template <
typename TraitsT>
668 using Teuchos::rcp_dynamic_cast;
670 typedef typename TraitsT::Hessian EvalT;
671 typedef typename TraitsT::RealType ScalarT;
674 RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(
getResponse<EvalT>(
"RESIDUAL"));
675 resp->initializeResponse();
682 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
687 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
688 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.
container_);
691 thGhostedContainer->set_A_th(resp->getGhostedHessian());
693 RCP<Thyra::VectorBase<ScalarT> > dummy_f = Thyra::createMember(resp->getHessian()->range());
694 thGlobalContainer->set_f_th(dummy_f);
695 thGlobalContainer->set_A_th(resp->getHessian());
698 thGhostedContainer->initializeMatrix(0.0);
702template <
typename TraitsT>
703template <
typename EvalT>
707 ae_tm2_.template getAsObject<EvalT>()->evaluate(input_args);
710template <
typename TraitsT>
712print(std::ostream & os)
const
714 typedef std::unordered_map<std::string, Response_TemplateManager> RespObjType;
717 std::string respName = itr->first;
718 os <<
"Response \"" << respName <<
"\": ";
719 Sacado::mpl::for_each<typename Response_TemplateManager::types_vector>(
Printer(itr->second,os));
724template <
typename TraitsT>
725template <
typename EvalT>
729 auto mb =
ae_tm2_.template getAsObject<EvalT>()->getManagerBuilder();
730 auto workset_descriptors = mb->getVolumeWorksetDescriptors();
731 for (
auto& w : workset_descriptors) {
732 std::string prefix_with_eb_info = prefix+
"element_block_"+w.getElementBlock();
733 mb->getVolumeFieldManager(w)->writeGraphvizFile(prefix_with_eb_info);
Adapts ResponseEvaluatorFactory objects so they can be driven through the BCStrategy interface.
Builder functor used with Sacado::mpl::TemplateManager to construct one panzer::AssemblyEngine<EvalT>...
void addGlobalEvaluationData(const std::string &key, const Teuchos::RCP< GlobalEvaluationData > &ged)
Teuchos::RCP< panzer::LinearObjContainer > ghostedContainer_
Teuchos::RCP< panzer::LinearObjContainer > container_
Stores input information for a boundary condition.
A PHX::TemplateManager holding one panzer::ClosureModelFactory<EvalT> per evaluation type in Traits::...
Object that contains information on the physics and discretization of a block of elements with the SA...
std::string elementBlockID() const
std::unordered_map< WorksetDescriptor, std::vector< std::pair< std::string, Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > > > > RespFactoryTable
const Teuchos::ParameterList & userData_
bool registerEvaluators(PHX::FieldManager< TraitsT > &fm, const WorksetDescriptor &wd, const PhysicsBlock &pb) const
RVEF2(const Teuchos::ParameterList &userData, RespFactoryTable &rft)
A PHX::TemplateManager holding one panzer::ResponseEvaluatorFactory<EvalT> per evaluation type in Tra...
void addResidualResponse()
bool closureModelByEBlock_
void initialize(const Teuchos::RCP< WorksetContainer > &wc, const Teuchos::RCP< const GlobalIndexer > &ugi, const Teuchos::RCP< const LinearObjFactory< TraitsT > > &lof)
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="")
AssemblyEngine_TemplateManager< panzer::Traits > ae_tm2_
void copyResponses(const ResponseLibrary &rl)
void print(std::ostream &os) const
void getResponses(std::vector< Teuchos::RCP< ResponseBase > > &responses) const
bool responseEvaluatorsBuilt_
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< const LinearObjFactory< TraitsT > > linObjFactory_
Teuchos::RCP< ResponseBase > getResponse(const std::string &responseName) const
void addResponse(const std::string &responseName, const std::vector< std::string > &blocks, const ResponseEvaluatorFactory_BuilderT &builder)
void initializeResidualType(const Teuchos::RCP< WorksetContainer > &wc, const Teuchos::RCP< const GlobalIndexer > &ugi, const Teuchos::RCP< const LinearObjFactory< TraitsT > > &lof)
void evaluate(const panzer::AssemblyEngineInArgs &input_args)
std::unordered_map< std::string, Response_TemplateManager > responseObjects_
Store all the response objects.
Teuchos::RCP< LinearObjContainer > ghostedContainer_
Teuchos::RCP< const GlobalIndexer > globalIndexer_
Teuchos::RCP< WorksetContainer > wkstContainer_
BCHashMap respBCFactories_
void addResponsesToInArgs(panzer::AssemblyEngineInArgs &input_args) const
void writeGraphvizFiles(const std::string &prefix="")
Teuchos::RCP< FieldManagerBuilder > fmb2_
void addResidualResponsesToInArgs(Overloader< typename TraitsT::Residual >, panzer::AssemblyEngineInArgs &input_args) const
std::unordered_map< WorksetDescriptor, std::vector< std::pair< std::string, Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > > > > respFactories_
const std::string & getElementBlock(const int block=0) const
Get element block name.
Teuchos::RCP< const LinearObjFactory< TraitsT > > lof_
ResidualResponse_Builder(const std::string &respName, const Teuchos::RCP< const LinearObjFactory< TraitsT > > &lof)
Teuchos::RCP< ResponseBase > build() const
std::vector< WorksetDescriptor > wkstDesc_
ResponseBase_Builder(const Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > &respFact, const std::string &respName, const std::vector< WorksetDescriptor > &wkstDesc)
ResponseBase_Builder(const Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > &respFact, const std::string &respName, const std::vector< std::pair< std::string, std::string > > &sidesets)
Teuchos::RCP< ResponseEvaluatorFactory_TemplateManager< TraitsT > > respFact_
Teuchos::RCP< ResponseBase > build() const
BCStrategyFactory that produces a BCStrategy_TemplateManager wrapping the responses registered for ea...
WorksetDescriptor sidesetDescriptor(const std::string &eBlock, const std::string &sideset)
WorksetDescriptor blockDescriptor(const std::string &eBlock)
Interface for constructing a BCStrategy_TemplateManager.
Allocates and initializes an equation set template manager.
A struct for handling function overloading.