Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_ResponseLibrary_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef __Panzer_ResponseLibrary_impl_hpp__
12 #define __Panzer_ResponseLibrary_impl_hpp__
13 
18 
20 
21 #include "Thyra_VectorStdOps.hpp"
22 #include "Thyra_VectorSpaceBase.hpp"
23 
24 #include <unordered_set>
25 
26 namespace panzer {
27 
28 template <typename TraitsT>
30  : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
31  , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
32 {
33 }
34 
35 template <typename TraitsT>
38  const Teuchos::RCP<const LinearObjFactory<TraitsT> > & lof,
39  bool residualType)
40  : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
41  , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
42 {
43  if(residualType)
44  initializeResidualType(wc,ugi,lof);
45  else
46  initialize(wc,ugi,lof);
47 }
48 
49 template <typename TraitsT>
51  : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
52  , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
53 {
54  initialize(rl);
55 }
56 
57 template <typename TraitsT>
61  const Teuchos::RCP<const LinearObjFactory<TraitsT> > & lof)
62 {
63  disableScatter_ = true;
64  residualType_ = false;
65 
66  wkstContainer_ = wc;
67  globalIndexer_ = ugi;
68  linObjFactory_ = lof;
69 }
70 
71 template <typename TraitsT>
75  const Teuchos::RCP<const LinearObjFactory<TraitsT> > & lof)
76 {
77  disableScatter_ = false; // we want equation set scatters for this
78  // residual type response
79  residualType_ = true;
80 
81  wkstContainer_ = wc;
82  globalIndexer_ = ugi;
83  linObjFactory_ = lof;
84 
85  // add the response reponse object
86  addResidualResponse();
87 }
88 
89 template <typename TraitsT>
92 {
93  if(rl.residualType_)
94  initializeResidualType(rl.wkstContainer_,rl.globalIndexer_,rl.linObjFactory_);
95  else
96  initialize(rl.wkstContainer_,rl.globalIndexer_,rl.linObjFactory_);
97 }
98 
99 template <typename TraitsT>
102 {
103  TEUCHOS_ASSERT(false);
104 }
105 
106 namespace panzer_tmp {
107  // This is a builder for building a ResponseBase object by evaluation type
108  template <typename TraitsT>
111  std::string respName_;
112  std::vector<WorksetDescriptor> wkstDesc_;
113 
114  public:
115 
116  // ResponseBase_Builder(const Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > & respFact,
117  // const std::string & respName, const std::vector<std::string> & eBlocks)
118  // : respFact_(respFact), respName_(respName)
119  // {
120  // for(std::size_t i=0;i<eBlocks.size();i++)
121  // wkstDesc_.push_back(blockDescriptor(eBlocks[i]));
122  // }
123 
125  const std::string & respName, const std::vector<std::pair<std::string,std::string> > & sidesets)
126  : respFact_(respFact), respName_(respName)
127  {
128  for(std::size_t i=0;i<sidesets.size();i++)
129  wkstDesc_.push_back(sidesetDescriptor(sidesets[i].first,sidesets[i].second));
130  }
131 
133  const std::string & respName, const std::vector<WorksetDescriptor> & wkstDesc)
134  : respFact_(respFact), respName_(respName), wkstDesc_(wkstDesc)
135  { }
136 
137  template <typename T>
139  {
140  Teuchos::RCP<const panzer::ResponseEvaluatorFactoryBase> baseObj = respFact_->template getAsBase<T>();
141 
142  // only build this templated set of objects if the there is something to build them with
143  if(baseObj!=Teuchos::null && baseObj->typeSupported()) {
145 
146  return resp;
147  }
148 
149  return Teuchos::null;
150  }
151  };
152 
153  // This is a builder for building a ResponseBase object by evaluation type
154  template <typename TraitsT>
156  std::string respName_;
158 
159  public:
160 
161  ResidualResponse_Builder(const std::string & respName,const Teuchos::RCP<const LinearObjFactory<TraitsT> > & lof)
162  : respName_(respName), lof_(lof)
163  { }
164 
165  template <typename T>
168  };
169 }
170 
171 template <typename TraitsT>
172 template <typename ResponseEvaluatorFactory_BuilderT>
174 addResponse(const std::string & responseName,
175  const std::vector<std::string> & blocks,
176  const ResponseEvaluatorFactory_BuilderT & builder)
177 {
178  using Teuchos::RCP;
179  using Teuchos::rcp;
180 
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\"!");
184 
185  // build response factory objects for each evaluation type
188  modelFact_tm->buildObjects(builder);
189 
190  std::vector<WorksetDescriptor> wkst_desc;
191  for(std::size_t i=0;i<blocks.size();i++)
192  wkst_desc.push_back(blockDescriptor(blocks[i]));
193 
194  addResponse(responseName,wkst_desc,modelFact_tm);
195 }
196 
197 template <typename TraitsT>
198 template <typename ResponseEvaluatorFactory_BuilderT>
200 addResponse(const std::string & responseName,
201  const std::vector<std::pair<std::string,std::string> > & sideset_blocks,
202  const ResponseEvaluatorFactory_BuilderT & builder)
203 {
204  using Teuchos::RCP;
205  using Teuchos::rcp;
206 
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\"!");
210 
211  // build response factory objects for each evaluation type
214  modelFact_tm->buildObjects(builder);
215 
216  // build a response object for each evaluation type
217  panzer_tmp::ResponseBase_Builder<TraitsT> respData_builder(modelFact_tm,responseName,sideset_blocks);
218  responseObjects_[responseName].buildObjects(respData_builder);
219 
220  // associate response objects with all element blocks required
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;
224 
225  BC bc(nextBC_id,BCT_Neumann,sideset,blockId,"Whatever",responseName+"_BCStrategy");
226 
227  // allocate the vector for "bc", if it hasn't yet been allocated
229  = respBCFactories_[bc];
230  if(block_tm==Teuchos::null) {
231  block_tm = Teuchos::rcp(new std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > >);
232  respBCFactories_[bc] = block_tm;
233  }
234 
235  // add response factory TM to vector that stores them
236  block_tm->push_back(std::make_pair(responseName,modelFact_tm));
237 
238  nextBC_id++;
239  }
240 }
241 
242 template <typename TraitsT>
243 template <typename ResponseEvaluatorFactory_BuilderT>
245 addResponse(const std::string & responseName,
246  const std::vector<WorksetDescriptor> & wkst_desc,
247  const ResponseEvaluatorFactory_BuilderT & builder)
248 {
249  using Teuchos::RCP;
250  using Teuchos::rcp;
251 
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\"!");
255 
256  if(wkst_desc[0].useSideset() && !wkst_desc[0].sideAssembly()) {
257  // this is a simple side integration, use the "other" addResponse method
258 
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));
264  }
265 
266  // add in the response (as a side set)
267  addResponse(responseName,sideset_blocks,builder);
268 
269  return;
270  }
271 
272  // build response factory objects for each evaluation type
275  modelFact_tm->buildObjects(builder);
276 
277  addResponse(responseName,wkst_desc,modelFact_tm);
278 }
279 
280 template <typename TraitsT>
282 addResponse(const std::string & responseName,
283  const std::vector<WorksetDescriptor> & wkst_desc,
285 {
286  // build a response object for each evaluation type
287  panzer_tmp::ResponseBase_Builder<TraitsT> respData_builder(modelFact_tm,responseName,wkst_desc);
288  responseObjects_[responseName].buildObjects(respData_builder);
289 
290  // associate response objects with all workset descriptors
291  for(std::size_t i=0;i<wkst_desc.size();i++) {
292  const WorksetDescriptor & desc = wkst_desc[i];
293 
294  // add response factory TM to vector that stores them
295  respFactories_[desc].push_back(std::make_pair(responseName,modelFact_tm));
296  }
297 }
298 
299 template <typename TraitsT>
302 {
303  std::string responseName = "RESIDUAL";
304 
305  // setup responses to be constructed
306  panzer_tmp::ResidualResponse_Builder<TraitsT> respData_builder(responseName,linObjFactory_);
307 
308  // build all the response objects (for each evaluation type)
309  responseObjects_[responseName].buildObjects(respData_builder);
310 }
311 
312 template <typename TraitsT>
313 template <typename EvalT>
315 getResponse(const std::string & responseName) const
316 {
317  typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
318  HashMap::const_iterator itr = responseObjects_.find(responseName);
319 
320  // response was not in list of responses
321  if(itr==responseObjects_.end())
322  return Teuchos::null;
323 
324  // response was found, return it
325  return itr->second.get<EvalT>();
326 }
327 
328 template <typename TraitsT>
329 template <typename EvalT>
331 getResponses(std::vector<Teuchos::RCP<ResponseBase> > & responses) const
332 {
333  typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
334 
335  responses.clear();
336 
337  // loop over all respones adding them to the vector
338  for(HashMap::const_iterator itr=responseObjects_.begin();itr!=responseObjects_.end();++itr)
339  responses.push_back(itr->second.get<EvalT>());
340 }
341 
342 template <typename TraitsT>
344 public:
345  typedef std::unordered_map<WorksetDescriptor,
346  std::vector<std::pair<std::string,Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > RespFactoryTable;
347 
349  : userData_(userData), rft_(rft) {}
350 
352  {
353  using Teuchos::RCP;
354  using Teuchos::rcp;
355 
357 
358  // because we reduce the physics blocks to only ones we need, this find should succeed
359  typename RespFactoryTable::iterator itr=rft_.find(wd);
360 
361  TEUCHOS_ASSERT(itr!=rft_.end() && itr->second.size()>0);
362 
363  // loop over each template manager in the block, and then each evaluation type
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;
368  // what is going on here?
369  if(fact==Teuchos::null)
370  continue;
371 
372  // loop over each evaluation type
373  for(typename ResponseEvaluatorFactory_TemplateManager<TraitsT>::iterator rf_itr=fact->begin();
374  rf_itr!=fact->end();++rf_itr) {
375 
376  // not setup for this template type, ignore it
377  if(rf_itr.rcp()==Teuchos::null || !rf_itr.rcp()->typeSupported())
378  continue;
379 
380  // build and register evaluators, store field tag, make it required
381  rf_itr->buildAndRegisterEvaluators(responseName,fm,pb,userData_);
382  }
383  }
384 
385  return true;
386  }
387 
388 private:
391 };
392 
393 template <typename TraitsT>
396  const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
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)
403 {
404  using Teuchos::RCP;
405 
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\"!");
409 
410  typedef std::unordered_map<WorksetDescriptor,
411  std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > RespFactoryTable;
412 
413  // first compute subset of physics blocks required to build responses
415 
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) {
420  // is there something to do?
421  if(itr->second.size()==0)
422  continue;
423 
424  const WorksetDescriptor & wd = itr->first;
425 
426  // find physics block with right element block
427  bool failure = true;
428  for(std::size_t i=0;i<physicsBlocks.size();i++) {
429  if(physicsBlocks[i]->elementBlockID()==wd.getElementBlock()) {
430  requiredVolPhysicsBlocks.push_back(physicsBlocks[i]);
431  failure = false;
432  break;
433  }
434  }
435 
436  // we must find at least one physics block
437  // TEUCHOS_ASSERT(!failure);
438  if(!failure)
439  requiredWorksetDesc.push_back(wd);
440  }
441 
442  // build boundary response array
443  std::vector<BC> bcs;
444  for(typename BCHashMap::const_iterator itr=respBCFactories_.begin();
445  itr!=respBCFactories_.end();++itr)
446  bcs.push_back(itr->first);
447 
448  // second construct generic evaluator factory from required response factories
450  RVEF2<TraitsT> rvef2(user_data,respFactories_);
451 
452  // third build field manager builder using the required physics blocks
454 
455  response_bc_adapters::BCFactoryResponse bc_factory(respBCFactories_);
456 
457  // don't build scatter evaluators
458  fmb2_ = Teuchos::rcp(new FieldManagerBuilder(disableScatter_,disableGather_));
459 
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);
464  else
465  fmb2_->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory_,user_data);
466 
467  if(write_graphviz_file) {
468  fmb2_->writeVolumeGraphvizDependencyFiles("Response_Volume_"+graphviz_file_prefix,requiredVolPhysicsBlocks);
469  fmb2_->writeBCGraphvizDependencyFiles("Response_Surface_"+graphviz_file_prefix);
470  }
471 
472  // fourth build assembly engine from FMB
474 
475  AssemblyEngine_TemplateBuilder builder(fmb2_,linObjFactory_);
476  ae_tm2_.buildObjects(builder);
477 
478  responseEvaluatorsBuilt_ = true;
479 }
480 
481 template <typename TraitsT>
484  const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
485  const panzer::EquationSetFactory & eqset_factory,
486  const std::vector<BC> & bcs,
487  const panzer::BCStrategyFactory& bc_factory,
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)
493 {
494  using Teuchos::RCP;
495 
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\"!");
499 
500  // don't build scatter evaluators
501  fmb2_ = Teuchos::rcp(new FieldManagerBuilder(disableScatter_,disableGather_));
502 
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);
506 
507  // Print Phalanx DAGs
508  if (write_graphviz_file){
509  fmb2_->writeVolumeGraphvizDependencyFiles("ResidualResponse_Volume_"+graphviz_file_prefix,physicsBlocks);
510  fmb2_->writeBCGraphvizDependencyFiles("ResidualResponse_Surface_"+graphviz_file_prefix);
511  }
512 
513  // fourth build assembly engine from FMB
515 
516  AssemblyEngine_TemplateBuilder builder(fmb2_,linObjFactory_);
517  ae_tm2_.buildObjects(builder);
518 
519  responseEvaluatorsBuilt_ = true;
520 }
521 
522 template <typename TraitsT>
523 template <typename EvalT>
526 {
527  std::vector<Teuchos::RCP<ResponseBase> > responses;
528  this->getResponses<EvalT>(responses);
529 
530  // add all responses to input args
531  if(!residualType_) {
532  for(std::size_t i=0;i<responses.size();i++) {
533  if(responses[i]!=Teuchos::null) {
534  input_args.addGlobalEvaluationData(responses[i]->getLookupName(),responses[i]);
535  }
536  }
537  }
538  else { // residualType_ == true
539  addResidualResponsesToInArgs(Overloader<EvalT>(),input_args);
540  }
541 }
542 
543 template <typename TraitsT>
546 {
547  using Teuchos::RCP;
548  using Teuchos::rcp_dynamic_cast;
549 
550  typedef typename TraitsT::Residual EvalT;
551  typedef typename TraitsT::RealType ScalarT;
552 
553  // extract the residual response
554  RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(getResponse<EvalT>("RESIDUAL"));
555  resp->initializeResponse();
556 
557  // setup the local ghosted container
558  if(ghostedContainer_==Teuchos::null)
559  ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
560 
561  // replace ghosted container with local one
562  const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
563  Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(ghostedContainer_);
564  input_args.ghostedContainer_ = ghostedContainer_;
565 
566  // convert responses into thyra object
567  const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
568  Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.container_);
569 
570  // set the ghosted and unique residual
571  thGhostedContainer->set_f_th(resp->getGhostedResidual());
572  thGlobalContainer->set_f_th(resp->getResidual());
573 
574  TEUCHOS_ASSERT(thGhostedContainer->get_f_th()!=Teuchos::null);
575  TEUCHOS_ASSERT(thGlobalContainer->get_f_th()!=Teuchos::null);
576 
577  // clear out ghosted residual
578  Thyra::assign(thGhostedContainer->get_f_th().ptr(),0.0);
579 }
580 
581 template <typename TraitsT>
584 {
585  using Teuchos::RCP;
586  using Teuchos::rcp_dynamic_cast;
587 
588  typedef typename TraitsT::Jacobian EvalT;
589  typedef typename TraitsT::RealType ScalarT;
590 
591  // extract the residual response
592  RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(getResponse<EvalT>("RESIDUAL"));
593  resp->initializeResponse();
594 
595  // setup the local ghosted container
596  if(ghostedContainer_==Teuchos::null)
597  ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
598 
599  // replace ghosted container with local one
600  const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
601  Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(ghostedContainer_);
602  input_args.ghostedContainer_ = ghostedContainer_;
603 
604  // convert responses into thyra object
605  const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
606  Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.container_);
607 
608  // set the ghosted and unique residual
609  thGhostedContainer->set_A_th(resp->getGhostedJacobian());
610 
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());
614 
615  // Zero values in ghosted container objects
616  thGhostedContainer->initializeMatrix(0.0);
617 }
618 
619 template <typename TraitsT>
622 {
623  using Teuchos::RCP;
624  using Teuchos::rcp_dynamic_cast;
625 
626  typedef typename TraitsT::Tangent EvalT;
627  typedef typename TraitsT::RealType ScalarT;
628 
629  // extract the residual response
630  RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(getResponse<EvalT>("RESIDUAL"));
631  resp->initializeResponse();
632 
633  // setup the local ghosted container
634  if(ghostedContainer_==Teuchos::null)
635  ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
636 
637  // replace ghosted container with local one
638  const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
639  Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(ghostedContainer_);
640  input_args.ghostedContainer_ = ghostedContainer_;
641 
642  // convert responses into thyra object
643  const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
644  Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.container_);
645 
646  // At this point it isn't clear what to do for Tangent. We probably need to extend the linear object containers
647  // to support df/dp.
648 
649  /*
650  // set the ghosted and unique residual
651  thGhostedContainer->set_A_th(resp->getGhostedJacobian());
652 
653  RCP<Thyra::VectorBase<ScalarT> > dummy_f = Thyra::createMember(resp->getJacobian()->range());
654  thGlobalContainer->set_f_th(dummy_f);
655  thGlobalContainer->set_A_th(resp->getJacobian());
656 
657  // Zero values in ghosted container objects
658  thGhostedContainer->initializeMatrix(0.0);
659  */
660 }
661 
662 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
663 template <typename TraitsT>
666 {
667  using Teuchos::RCP;
668  using Teuchos::rcp_dynamic_cast;
669 
670  typedef typename TraitsT::Hessian EvalT;
671  typedef typename TraitsT::RealType ScalarT;
672 
673  // extract the residual response
674  RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(getResponse<EvalT>("RESIDUAL"));
675  resp->initializeResponse();
676 
677  // setup the local ghosted container
678  if(ghostedContainer_==Teuchos::null)
679  ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
680 
681  // replace ghosted container with local one
682  const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
683  Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(ghostedContainer_);
684  input_args.ghostedContainer_ = ghostedContainer_;
685 
686  // convert responses into thyra object
687  const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
688  Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.container_);
689 
690  // set the ghosted and unique residual
691  thGhostedContainer->set_A_th(resp->getGhostedHessian());
692 
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());
696 
697  // Zero values in ghosted container objects
698  thGhostedContainer->initializeMatrix(0.0);
699 }
700 #endif
701 
702 template <typename TraitsT>
703 template <typename EvalT>
706 {
707  ae_tm2_.template getAsObject<EvalT>()->evaluate(input_args);
708 }
709 
710 template <typename TraitsT>
712 print(std::ostream & os) const
713 {
714  typedef std::unordered_map<std::string, Response_TemplateManager> RespObjType;
715 
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));
720  os << std::endl;
721  }
722 }
723 
724 }
725 
726 #endif
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)
Teuchos::RCP< const GlobalIndexer > globalIndexer_
std::string elementBlockID() const
Ptr< T > ptr() const
Teuchos::RCP< const LinearObjFactory< TraitsT > > lof_
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.
Definition: Panzer_BC.hpp:48
#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_
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.