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>
 
   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>
 
   95    disableScatter_ = 
true;
 
   96    residualType_ = 
false;
 
  100    linObjFactory_ = lof;
 
  103 template <
typename TraitsT>
 
  109    disableScatter_ = 
false; 
 
  111    residualType_ = 
true;
 
  114    globalIndexer_ = ugi;
 
  115    linObjFactory_ = lof;
 
  118    addResidualResponse();
 
  121 template <
typename TraitsT>
 
  131 template <
typename TraitsT>
 
  138 namespace panzer_tmp {
 
  140   template <
typename TraitsT>
 
  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++)
 
  165                          const std::string & respName, 
const std::vector<WorksetDescriptor> & wkstDesc)
 
  169     template <
typename T>
 
  181       return Teuchos::null;
 
  186   template <
typename TraitsT>
 
  197     template <
typename T>
 
  203 template <
typename TraitsT>
 
  204 template <
typename ResponseEvaluatorFactory_BuilderT>
 
  207             const std::vector<std::string> & blocks,
 
  208             const ResponseEvaluatorFactory_BuilderT & builder) 
 
  214                               "panzer::ResponseLibrary::addResponse: Method can't be called when the " 
  215                               "response library is a \"residualType\"!");
 
  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) 
 
  240                               "panzer::ResponseLibrary::addResponse: Method can't be called when the " 
  241                               "response library is a \"residualType\"!");
 
  246    modelFact_tm->buildObjects(builder);
 
  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");
 
  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) 
 
  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);
 
  307   modelFact_tm->buildObjects(builder);
 
  309   addResponse(responseName,wkst_desc,modelFact_tm);
 
  312 template <
typename TraitsT>
 
  315             const std::vector<WorksetDescriptor> & 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";
 
  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>
 
  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);
 
  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;
 
  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>
 
  433          const bool write_graphviz_file,
 
  434          const std::string& graphviz_file_prefix)
 
  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) 
 
  456      const WorksetDescriptor & wd = itr->first;
 
  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>
 
  518          const std::vector<BC> & bcs,
 
  523          const bool write_graphviz_file,
 
  524          const std::string& graphviz_file_prefix)
 
  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();
 
  603   thGhostedContainer->set_f_th(resp->getGhostedResidual());
 
  604   thGlobalContainer->set_f_th(resp->getResidual());
 
  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();
 
  641   thGhostedContainer->set_A_th(resp->getGhostedJacobian());
 
  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();
 
  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();
 
  723   thGhostedContainer->set_A_th(resp->getGhostedHessian());
 
  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. 
 
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.