Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_ResponseLibrary_impl.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Panzer: A partial differential equation assembly
5// engine for strongly coupled complex multiphysics systems
6// Copyright (2011) Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39// Eric C. Cyr (eccyr@sandia.gov)
40// ***********************************************************************
41// @HEADER
42
43#ifndef __Panzer_ResponseLibrary_impl_hpp__
44#define __Panzer_ResponseLibrary_impl_hpp__
45
50
52
53#include "Thyra_VectorStdOps.hpp"
54#include "Thyra_VectorSpaceBase.hpp"
55
56#include <unordered_set>
57
58namespace panzer {
59
60template <typename TraitsT>
62 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
63 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
64{
65}
66
67template <typename TraitsT>
68ResponseLibrary<TraitsT>::ResponseLibrary(const Teuchos::RCP<WorksetContainer> & wc,
69 const Teuchos::RCP<const GlobalIndexer> & ugi,
70 const Teuchos::RCP<const LinearObjFactory<TraitsT> > & lof,
71 bool residualType)
72 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
73 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
74{
75 if(residualType)
76 initializeResidualType(wc,ugi,lof);
77 else
78 initialize(wc,ugi,lof);
79}
80
81template <typename TraitsT>
83 : nextBC_id(0), closureModelByEBlock_(false), disableGather_(false)
84 , disableScatter_(true), residualType_(false), responseEvaluatorsBuilt_(false)
85{
86 initialize(rl);
87}
88
89template <typename TraitsT>
91initialize(const Teuchos::RCP<WorksetContainer> & wc,
92 const Teuchos::RCP<const GlobalIndexer> & ugi,
93 const Teuchos::RCP<const LinearObjFactory<TraitsT> > & lof)
94{
95 disableScatter_ = true;
96 residualType_ = false;
97
98 wkstContainer_ = wc;
99 globalIndexer_ = ugi;
100 linObjFactory_ = lof;
101}
102
103template <typename TraitsT>
105initializeResidualType(const Teuchos::RCP<WorksetContainer> & wc,
106 const Teuchos::RCP<const GlobalIndexer> & ugi,
107 const Teuchos::RCP<const LinearObjFactory<TraitsT> > & lof)
108{
109 disableScatter_ = false; // we want equation set scatters for this
110 // residual type response
111 residualType_ = true;
112
113 wkstContainer_ = wc;
114 globalIndexer_ = ugi;
115 linObjFactory_ = lof;
116
117 // add the response reponse object
118 addResidualResponse();
119}
120
121template <typename TraitsT>
124{
125 if(rl.residualType_)
126 initializeResidualType(rl.wkstContainer_,rl.globalIndexer_,rl.linObjFactory_);
127 else
128 initialize(rl.wkstContainer_,rl.globalIndexer_,rl.linObjFactory_);
129}
130
131template <typename TraitsT>
134{
135 TEUCHOS_ASSERT(false);
136}
137
138namespace panzer_tmp {
139 // This is a builder for building a ResponseBase object by evaluation type
140 template <typename TraitsT>
142 Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > respFact_;
143 std::string respName_;
144 std::vector<WorksetDescriptor> wkstDesc_;
145
146 public:
147
148 // ResponseBase_Builder(const Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > & respFact,
149 // const std::string & respName, const std::vector<std::string> & eBlocks)
150 // : respFact_(respFact), respName_(respName)
151 // {
152 // for(std::size_t i=0;i<eBlocks.size();i++)
153 // wkstDesc_.push_back(blockDescriptor(eBlocks[i]));
154 // }
155
157 const std::string & respName, const std::vector<std::pair<std::string,std::string> > & sidesets)
158 : respFact_(respFact), respName_(respName)
159 {
160 for(std::size_t i=0;i<sidesets.size();i++)
161 wkstDesc_.push_back(sidesetDescriptor(sidesets[i].first,sidesets[i].second));
162 }
163
165 const std::string & respName, const std::vector<WorksetDescriptor> & wkstDesc)
166 : respFact_(respFact), respName_(respName), wkstDesc_(wkstDesc)
167 { }
168
169 template <typename T>
170 Teuchos::RCP<ResponseBase> build() const
171 {
172 Teuchos::RCP<const panzer::ResponseEvaluatorFactoryBase> baseObj = respFact_->template getAsBase<T>();
173
174 // only build this templated set of objects if the there is something to build them with
175 if(baseObj!=Teuchos::null && baseObj->typeSupported()) {
176 Teuchos::RCP<ResponseBase> resp = baseObj->buildResponseObject(respName_,wkstDesc_);
177
178 return resp;
179 }
180
181 return Teuchos::null;
182 }
183 };
184
185 // This is a builder for building a ResponseBase object by evaluation type
186 template <typename TraitsT>
188 std::string respName_;
189 Teuchos::RCP<const LinearObjFactory<TraitsT> > lof_;
190
191 public:
192
193 ResidualResponse_Builder(const std::string & respName,const Teuchos::RCP<const LinearObjFactory<TraitsT> > & lof)
194 : respName_(respName), lof_(lof)
195 { }
196
197 template <typename T>
198 Teuchos::RCP<ResponseBase> build() const
199 { return Teuchos::rcp(new Response_Residual<T>(respName_,lof_)); }
200 };
201}
202
203template <typename TraitsT>
204template <typename ResponseEvaluatorFactory_BuilderT>
206addResponse(const std::string & responseName,
207 const std::vector<std::string> & blocks,
208 const ResponseEvaluatorFactory_BuilderT & builder)
209{
210 using Teuchos::RCP;
211 using Teuchos::rcp;
212
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\"!");
216
217 // build response factory objects for each evaluation type
218 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
220 modelFact_tm->buildObjects(builder);
221
222 std::vector<WorksetDescriptor> wkst_desc;
223 for(std::size_t i=0;i<blocks.size();i++)
224 wkst_desc.push_back(blockDescriptor(blocks[i]));
225
226 addResponse(responseName,wkst_desc,modelFact_tm);
227}
228
229template <typename TraitsT>
230template <typename ResponseEvaluatorFactory_BuilderT>
232addResponse(const std::string & responseName,
233 const std::vector<std::pair<std::string,std::string> > & sideset_blocks,
234 const ResponseEvaluatorFactory_BuilderT & builder)
235{
236 using Teuchos::RCP;
237 using Teuchos::rcp;
238
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\"!");
242
243 // build response factory objects for each evaluation type
244 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
246 modelFact_tm->buildObjects(builder);
247
248 // build a response object for each evaluation type
249 panzer_tmp::ResponseBase_Builder<TraitsT> respData_builder(modelFact_tm,responseName,sideset_blocks);
250 responseObjects_[responseName].buildObjects(respData_builder);
251
252 // associate response objects with all element blocks required
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;
256
257 BC bc(nextBC_id,BCT_Neumann,sideset,blockId,"Whatever",responseName+"_BCStrategy");
258
259 // allocate the vector for "bc", if it hasn't yet been allocated
260 RCP<std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > block_tm
261 = respBCFactories_[bc];
262 if(block_tm==Teuchos::null) {
263 block_tm = Teuchos::rcp(new std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > >);
264 respBCFactories_[bc] = block_tm;
265 }
266
267 // add response factory TM to vector that stores them
268 block_tm->push_back(std::make_pair(responseName,modelFact_tm));
269
270 nextBC_id++;
271 }
272}
273
274template <typename TraitsT>
275template <typename ResponseEvaluatorFactory_BuilderT>
277addResponse(const std::string & responseName,
278 const std::vector<WorksetDescriptor> & wkst_desc,
279 const ResponseEvaluatorFactory_BuilderT & builder)
280{
281 using Teuchos::RCP;
282 using Teuchos::rcp;
283
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\"!");
287
288 if(wkst_desc[0].useSideset() && !wkst_desc[0].sideAssembly()) {
289 // this is a simple side integration, use the "other" addResponse method
290
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));
296 }
297
298 // add in the response (as a side set)
299 addResponse(responseName,sideset_blocks,builder);
300
301 return;
302 }
303
304 // build response factory objects for each evaluation type
305 RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > modelFact_tm
307 modelFact_tm->buildObjects(builder);
308
309 addResponse(responseName,wkst_desc,modelFact_tm);
310}
311
312template <typename TraitsT>
314addResponse(const std::string & responseName,
315 const std::vector<WorksetDescriptor> & wkst_desc,
316 const Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > & modelFact_tm)
317{
318 // build a response object for each evaluation type
319 panzer_tmp::ResponseBase_Builder<TraitsT> respData_builder(modelFact_tm,responseName,wkst_desc);
320 responseObjects_[responseName].buildObjects(respData_builder);
321
322 // associate response objects with all workset descriptors
323 for(std::size_t i=0;i<wkst_desc.size();i++) {
324 const WorksetDescriptor & desc = wkst_desc[i];
325
326 // add response factory TM to vector that stores them
327 respFactories_[desc].push_back(std::make_pair(responseName,modelFact_tm));
328 }
329}
330
331template <typename TraitsT>
334{
335 std::string responseName = "RESIDUAL";
336
337 // setup responses to be constructed
338 panzer_tmp::ResidualResponse_Builder<TraitsT> respData_builder(responseName,linObjFactory_);
339
340 // build all the response objects (for each evaluation type)
341 responseObjects_[responseName].buildObjects(respData_builder);
342}
343
344template <typename TraitsT>
345template <typename EvalT>
346Teuchos::RCP<ResponseBase> ResponseLibrary<TraitsT>::
347getResponse(const std::string & responseName) const
348{
349 typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
350 HashMap::const_iterator itr = responseObjects_.find(responseName);
351
352 // response was not in list of responses
353 if(itr==responseObjects_.end())
354 return Teuchos::null;
355
356 // response was found, return it
357 return itr->second.get<EvalT>();
358}
359
360template <typename TraitsT>
361template <typename EvalT>
363getResponses(std::vector<Teuchos::RCP<ResponseBase> > & responses) const
364{
365 typedef std::unordered_map<std::string, Response_TemplateManager> HashMap;
366
367 responses.clear();
368
369 // loop over all respones adding them to the vector
370 for(HashMap::const_iterator itr=responseObjects_.begin();itr!=responseObjects_.end();++itr)
371 responses.push_back(itr->second.get<EvalT>());
372}
373
374template <typename TraitsT>
376public:
377 typedef std::unordered_map<WorksetDescriptor,
378 std::vector<std::pair<std::string,Teuchos::RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > RespFactoryTable;
379
380 RVEF2(const Teuchos::ParameterList & userData,RespFactoryTable & rft)
381 : userData_(userData), rft_(rft) {}
382
384 {
385 using Teuchos::RCP;
386 using Teuchos::rcp;
387
388 TEUCHOS_ASSERT(wd.getElementBlock()==pb.elementBlockID());
389
390 // because we reduce the physics blocks to only ones we need, this find should succeed
391 typename RespFactoryTable::iterator itr=rft_.find(wd);
392
393 TEUCHOS_ASSERT(itr!=rft_.end() && itr->second.size()>0);
394
395 // loop over each template manager in the block, and then each evaluation type
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;
400 // what is going on here?
401 if(fact==Teuchos::null)
402 continue;
403
404 // loop over each evaluation type
405 for(typename ResponseEvaluatorFactory_TemplateManager<TraitsT>::iterator rf_itr=fact->begin();
406 rf_itr!=fact->end();++rf_itr) {
407
408 // not setup for this template type, ignore it
409 if(rf_itr.rcp()==Teuchos::null || !rf_itr.rcp()->typeSupported())
410 continue;
411
412 // build and register evaluators, store field tag, make it required
413 rf_itr->buildAndRegisterEvaluators(responseName,fm,pb,userData_);
414 }
415 }
416
417 return true;
418 }
419
420private:
421 const Teuchos::ParameterList & userData_;
423};
424
425template <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)
435{
436 using Teuchos::RCP;
437
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\"!");
441
442 typedef std::unordered_map<WorksetDescriptor,
443 std::vector<std::pair<std::string,RCP<ResponseEvaluatorFactory_TemplateManager<TraitsT> > > > > RespFactoryTable;
444
445 // first compute subset of physics blocks required to build responses
447
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) {
452 // is there something to do?
453 if(itr->second.size()==0)
454 continue;
455
456 const WorksetDescriptor & wd = itr->first;
457
458 // find physics block with right element block
459 bool failure = true;
460 for(std::size_t i=0;i<physicsBlocks.size();i++) {
461 if(physicsBlocks[i]->elementBlockID()==wd.getElementBlock()) {
462 requiredVolPhysicsBlocks.push_back(physicsBlocks[i]);
463 failure = false;
464 break;
465 }
466 }
467
468 // we must find at least one physics block
469 // TEUCHOS_ASSERT(!failure);
470 if(!failure)
471 requiredWorksetDesc.push_back(wd);
472 }
473
474 // build boundary response array
475 std::vector<BC> bcs;
476 for(typename BCHashMap::const_iterator itr=respBCFactories_.begin();
477 itr!=respBCFactories_.end();++itr)
478 bcs.push_back(itr->first);
479
480 // second construct generic evaluator factory from required response factories
482 RVEF2<TraitsT> rvef2(user_data,respFactories_);
483
484 // third build field manager builder using the required physics blocks
486
487 response_bc_adapters::BCFactoryResponse bc_factory(respBCFactories_);
488
489 // don't build scatter evaluators
490 fmb2_ = Teuchos::rcp(new FieldManagerBuilder(disableScatter_,disableGather_));
491
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);
496 else
497 fmb2_->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory_,user_data);
498
499 if(write_graphviz_file) {
500 fmb2_->writeVolumeGraphvizDependencyFiles("Response_Volume_"+graphviz_file_prefix,requiredVolPhysicsBlocks);
501 fmb2_->writeBCGraphvizDependencyFiles("Response_Surface_"+graphviz_file_prefix);
502 }
503
504 // fourth build assembly engine from FMB
506
507 AssemblyEngine_TemplateBuilder builder(fmb2_,linObjFactory_);
508 ae_tm2_.buildObjects(builder);
509
510 responseEvaluatorsBuilt_ = true;
511}
512
513template <typename TraitsT>
516 const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
517 const panzer::EquationSetFactory & eqset_factory,
518 const std::vector<BC> & bcs,
519 const panzer::BCStrategyFactory& bc_factory,
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)
525{
526 using Teuchos::RCP;
527
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\"!");
531
532 // don't build scatter evaluators
533 fmb2_ = Teuchos::rcp(new FieldManagerBuilder(disableScatter_,disableGather_));
534
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);
538
539 // Print Phalanx DAGs
540 if (write_graphviz_file){
541 fmb2_->writeVolumeGraphvizDependencyFiles("ResidualResponse_Volume_"+graphviz_file_prefix,physicsBlocks);
542 fmb2_->writeBCGraphvizDependencyFiles("ResidualResponse_Surface_"+graphviz_file_prefix);
543 }
544
545 // fourth build assembly engine from FMB
547
548 AssemblyEngine_TemplateBuilder builder(fmb2_,linObjFactory_);
549 ae_tm2_.buildObjects(builder);
550
551 responseEvaluatorsBuilt_ = true;
552}
553
554template <typename TraitsT>
555template <typename EvalT>
558{
559 std::vector<Teuchos::RCP<ResponseBase> > responses;
560 this->getResponses<EvalT>(responses);
561
562 // add all responses to input args
563 if(!residualType_) {
564 for(std::size_t i=0;i<responses.size();i++) {
565 if(responses[i]!=Teuchos::null) {
566 input_args.addGlobalEvaluationData(responses[i]->getLookupName(),responses[i]);
567 }
568 }
569 }
570 else { // residualType_ == true
571 addResidualResponsesToInArgs(Overloader<EvalT>(),input_args);
572 }
573}
574
575template <typename TraitsT>
578{
579 using Teuchos::RCP;
580 using Teuchos::rcp_dynamic_cast;
581
582 typedef typename TraitsT::Residual EvalT;
583 typedef typename TraitsT::RealType ScalarT;
584
585 // extract the residual response
586 RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(getResponse<EvalT>("RESIDUAL"));
587 resp->initializeResponse();
588
589 // setup the local ghosted container
590 if(ghostedContainer_==Teuchos::null)
591 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
592
593 // replace ghosted container with local one
594 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
595 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(ghostedContainer_);
596 input_args.ghostedContainer_ = ghostedContainer_;
597
598 // convert responses into thyra object
599 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
600 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.container_);
601
602 // set the ghosted and unique residual
603 thGhostedContainer->set_f_th(resp->getGhostedResidual());
604 thGlobalContainer->set_f_th(resp->getResidual());
605
606 TEUCHOS_ASSERT(thGhostedContainer->get_f_th()!=Teuchos::null);
607 TEUCHOS_ASSERT(thGlobalContainer->get_f_th()!=Teuchos::null);
608
609 // clear out ghosted residual
610 Thyra::assign(thGhostedContainer->get_f_th().ptr(),0.0);
611}
612
613template <typename TraitsT>
616{
617 using Teuchos::RCP;
618 using Teuchos::rcp_dynamic_cast;
619
620 typedef typename TraitsT::Jacobian EvalT;
621 typedef typename TraitsT::RealType ScalarT;
622
623 // extract the residual response
624 RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(getResponse<EvalT>("RESIDUAL"));
625 resp->initializeResponse();
626
627 // setup the local ghosted container
628 if(ghostedContainer_==Teuchos::null)
629 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
630
631 // replace ghosted container with local one
632 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
633 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(ghostedContainer_);
634 input_args.ghostedContainer_ = ghostedContainer_;
635
636 // convert responses into thyra object
637 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
638 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.container_);
639
640 // set the ghosted and unique residual
641 thGhostedContainer->set_A_th(resp->getGhostedJacobian());
642
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());
646
647 // Zero values in ghosted container objects
648 thGhostedContainer->initializeMatrix(0.0);
649}
650
651template <typename TraitsT>
654{
655 using Teuchos::RCP;
656 using Teuchos::rcp_dynamic_cast;
657
658 typedef typename TraitsT::Tangent EvalT;
659 typedef typename TraitsT::RealType ScalarT;
660
661 // extract the residual response
662 RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(getResponse<EvalT>("RESIDUAL"));
663 resp->initializeResponse();
664
665 // setup the local ghosted container
666 if(ghostedContainer_==Teuchos::null)
667 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
668
669 // replace ghosted container with local one
670 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
671 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(ghostedContainer_);
672 input_args.ghostedContainer_ = ghostedContainer_;
673
674 // convert responses into thyra object
675 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
676 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.container_);
677
678 // At this point it isn't clear what to do for Tangent. We probably need to extend the linear object containers
679 // to support df/dp.
680
681 /*
682 // set the ghosted and unique residual
683 thGhostedContainer->set_A_th(resp->getGhostedJacobian());
684
685 RCP<Thyra::VectorBase<ScalarT> > dummy_f = Thyra::createMember(resp->getJacobian()->range());
686 thGlobalContainer->set_f_th(dummy_f);
687 thGlobalContainer->set_A_th(resp->getJacobian());
688
689 // Zero values in ghosted container objects
690 thGhostedContainer->initializeMatrix(0.0);
691 */
692}
693
694#ifdef Panzer_BUILD_HESSIAN_SUPPORT
695template <typename TraitsT>
698{
699 using Teuchos::RCP;
700 using Teuchos::rcp_dynamic_cast;
701
702 typedef typename TraitsT::Hessian EvalT;
703 typedef typename TraitsT::RealType ScalarT;
704
705 // extract the residual response
706 RCP<Response_Residual<EvalT> > resp = rcp_dynamic_cast<Response_Residual<EvalT> >(getResponse<EvalT>("RESIDUAL"));
707 resp->initializeResponse();
708
709 // setup the local ghosted container
710 if(ghostedContainer_==Teuchos::null)
711 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
712
713 // replace ghosted container with local one
714 const RCP<ThyraObjContainer<ScalarT> > thGhostedContainer =
715 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(ghostedContainer_);
716 input_args.ghostedContainer_ = ghostedContainer_;
717
718 // convert responses into thyra object
719 const RCP<ThyraObjContainer<ScalarT> > thGlobalContainer =
720 Teuchos::rcp_dynamic_cast<ThyraObjContainer<ScalarT> >(input_args.container_);
721
722 // set the ghosted and unique residual
723 thGhostedContainer->set_A_th(resp->getGhostedHessian());
724
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());
728
729 // Zero values in ghosted container objects
730 thGhostedContainer->initializeMatrix(0.0);
731}
732#endif
733
734template <typename TraitsT>
735template <typename EvalT>
737evaluate(const panzer::AssemblyEngineInArgs& input_args)
738{
739 ae_tm2_.template getAsObject<EvalT>()->evaluate(input_args);
740}
741
742template <typename TraitsT>
744print(std::ostream & os) const
745{
746 typedef std::unordered_map<std::string, Response_TemplateManager> RespObjType;
747
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));
752 os << std::endl;
753 }
754}
755
756}
757
758#endif
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.
Definition Panzer_BC.hpp:81
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)
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="")
void copyResponses(const ResponseLibrary &rl)
void print(std::ostream &os) const
void getResponses(std::vector< Teuchos::RCP< ResponseBase > > &responses) const
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)
Teuchos::RCP< const GlobalIndexer > globalIndexer_
Teuchos::RCP< WorksetContainer > wkstContainer_
void addResponsesToInArgs(panzer::AssemblyEngineInArgs &input_args) const
void addResidualResponsesToInArgs(Overloader< typename TraitsT::Residual >, panzer::AssemblyEngineInArgs &input_args) const
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)
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_
WorksetDescriptor sidesetDescriptor(const std::string &eBlock, const std::string &sideset)
WorksetDescriptor blockDescriptor(const std::string &eBlock)
@ BCT_Neumann
Definition Panzer_BC.hpp:76
Interface for constructing a BCStrategy_TemplateManager.
Allocates and initializes an equation set template manager.
A struct for handling function overloading.