Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_Response_Probe_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_Response_Probe_impl_hpp__
12 #define __Panzer_Response_Probe_impl_hpp__
13 
14 #include "Teuchos_Comm.hpp"
15 #include "Teuchos_CommHelpers.hpp"
16 #include "Teuchos_dyn_cast.hpp"
17 
18 #include "PanzerDiscFE_config.hpp"
19 #ifdef PANZER_HAVE_EPETRA_STACK
20 #include "Epetra_LocalMap.h"
21 #endif
22 
23 #include "Sacado_Traits.hpp"
24 
25 namespace panzer {
26 
27 template <typename EvalT>
29 Response_Probe(const std::string & responseName, MPI_Comm comm,
30  const Teuchos::RCP<const panzer::LinearObjFactory<panzer::Traits> > & linObjFact)
31  : ResponseMESupport_Default<EvalT>(responseName,comm), value(0.0),
32  have_probe(false), linObjFactory_(linObjFact)
33 {
34  if(linObjFactory_!=Teuchos::null) {
35  // requires thyra object factory
36  thyraObjFactory_ = Teuchos::rcp_dynamic_cast<const panzer::ThyraObjFactory<double> >(linObjFactory_,true);
37  setSolnVectorSpace(thyraObjFactory_->getThyraDomainSpace());
38 
39  // build a ghosted container, with a solution vector
40  ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
41 
42  // set ghosted container (work space for assembly)
43  linObjFactory_->initializeGhostedContainer(panzer::LinearObjContainer::X,*ghostedContainer_);
44  }
45 }
46 
47 template <typename EvalT>
50 {
51  value = 0.0;
52  have_probe = false;
53 
54  if(ghostedContainer_!=Teuchos::null) ghostedContainer_->initialize();
55 }
56 
57 template <typename EvalT>
60 {
61  double glbValue = Sacado::scalarValue(value);
62 
63  // find the minimum processor who has the probe value
64  int locProc = have_probe ? this->getComm()->getRank() : this->getComm()->getSize();
65  int glbProc = 0;
66  Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, Thyra::Ordinal(1), &locProc, &glbProc);
67 
68  TEUCHOS_ASSERT(glbProc < this->getComm()->getSize());
69 
70  // now broadcast the value from proc glbProc
71  Teuchos::broadcast(*this->getComm(), glbProc, Thyra::Ordinal(1), &glbValue);
72 
73  value = glbValue;
74 
75  // built data in vectors
76 #ifdef PANZER_HAVE_EPETRA_STACK
77  if(this->useEpetra()) {
78  // use epetra
79  this->getEpetraVector()[0] = glbValue;
80  }
81  else
82 #endif
83  {
84  // use thyra
85  TEUCHOS_ASSERT(this->useThyra());
86 
87  this->getThyraVector()[0] = glbValue;
88  }
89 }
90 
91 template < >
94 {
95  using Teuchos::rcp_dynamic_cast;
96 
97  Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
98 
99  uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
100  Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
101 
102  linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
103 
104  uniqueContainer_ = Teuchos::null;
105 }
106 
107 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
108 template < >
111 {
112  using Teuchos::rcp_dynamic_cast;
113 
114  Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
115 
116  uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
117  Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
118 
119  linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
120 
121  uniqueContainer_ = Teuchos::null;
122 }
123 #endif
124 
125 template < >
128 {
129  const int n = value.size();
130  const int num_deriv = this->numDeriv();
131  TEUCHOS_ASSERT(n == 0 || n == num_deriv);
132  if (n == 0)
133  value.resize(num_deriv);
134 
135  // find the minimum processor who has the probe value
136  if (num_deriv > 0) {
137  int locProc = have_probe ? this->getComm()->getRank() : this->getComm()->getSize();
138  int glbProc = 0;
139  Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, Thyra::Ordinal(1), &locProc, &glbProc);
140 
141  TEUCHOS_ASSERT(glbProc < this->getComm()->getSize());
142 
143  // now broadcast the derivatives from proc glbProc
144  Teuchos::broadcast(*this->getComm(), glbProc, Thyra::Ordinal(num_deriv), &value.fastAccessDx(0));
145  }
146 
147  // copy data in vectors
148 #ifdef PANZER_HAVE_EPETRA_STACK
149  if(this->useEpetra()) {
150  // use epetra
151  Epetra_MultiVector& deriv = this->getEpetraMultiVector();
152  for (int i=0; i<num_deriv; ++i)
153  deriv[i][0] = value.dx(i);
154  }
155  else
156 #endif
157  {
158  // use thyra
159  TEUCHOS_ASSERT(this->useThyra());
160  Thyra::ArrayRCP< Thyra::ArrayRCP<double> > deriv = this->getThyraMultiVector();
161  for (int i=0; i<num_deriv; ++i)
162  deriv[i][0] = value.dx(i);
163  }
164 }
165 
166 // Do nothing unless derivatives are actually required
167 template <typename EvalT>
170 
171 // derivatives are required for
172 template < >
175 {
176  setDerivativeVectorSpace(soln_vs);
177 }
178 
179 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
180 // derivatives are required for
181 template < >
184 {
185  setDerivativeVectorSpace(soln_vs);
186 }
187 #endif
188 
189 // Do nothing unless derivatives are required
190 template <typename EvalT>
192 adjustForDirichletConditions(const GlobalEvaluationData & /* localBCRows */, const GlobalEvaluationData & /* globalBCRows */) { }
193 
194 // Do nothing unless derivatives are required
195 template < >
198 {
199  linObjFactory_->adjustForDirichletConditions(Teuchos::dyn_cast<const LinearObjContainer>(localBCRows),
200  Teuchos::dyn_cast<const LinearObjContainer>(globalBCRows),
201  *ghostedContainer_,true,true);
202 }
203 
204 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
205 // Do nothing unless derivatives are required
206 template < >
209 {
210  linObjFactory_->adjustForDirichletConditions(Teuchos::dyn_cast<const LinearObjContainer>(localBCRows),
211  Teuchos::dyn_cast<const LinearObjContainer>(globalBCRows),
212  *ghostedContainer_,true,true);
213 }
214 #endif
215 
216 }
217 
218 #endif
virtual void scatterResponse()
This simply does global summation, then shoves the result into a vector.
Teuchos::RCP< LinearObjContainer > ghostedContainer_
Teuchos::RCP< const panzer::LinearObjFactory< panzer::Traits > > linObjFactory_
void adjustForDirichletConditions(const GlobalEvaluationData &localBCRows, const GlobalEvaluationData &globalBCRows)
Teuchos::RCP< const panzer::ThyraObjFactory< double > > thyraObjFactory_
void setSolnVectorSpace(const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &soln_vs)
Set solution vector space.
#define TEUCHOS_ASSERT(assertion_test)