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 //
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_Response_Probe_impl_hpp__
44 #define __Panzer_Response_Probe_impl_hpp__
45 
46 #include "Teuchos_Comm.hpp"
47 #include "Teuchos_CommHelpers.hpp"
48 #include "Teuchos_dyn_cast.hpp"
49 
50 #include "Epetra_LocalMap.h"
51 
52 #include "Sacado_Traits.hpp"
53 
54 namespace panzer {
55 
56 template <typename EvalT>
58 Response_Probe(const std::string & responseName, MPI_Comm comm,
59  const Teuchos::RCP<const panzer::LinearObjFactory<panzer::Traits> > & linObjFact)
60  : ResponseMESupport_Default<EvalT>(responseName,comm), value(0.0),
61  have_probe(false), linObjFactory_(linObjFact)
62 {
63  if(linObjFactory_!=Teuchos::null) {
64  // requires thyra object factory
65  thyraObjFactory_ = Teuchos::rcp_dynamic_cast<const panzer::ThyraObjFactory<double> >(linObjFactory_,true);
66  setSolnVectorSpace(thyraObjFactory_->getThyraDomainSpace());
67 
68  // build a ghosted container, with a solution vector
69  ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
70 
71  // set ghosted container (work space for assembly)
72  linObjFactory_->initializeGhostedContainer(panzer::LinearObjContainer::X,*ghostedContainer_);
73  }
74 }
75 
76 template <typename EvalT>
79 {
80  value = 0.0;
81  have_probe = false;
82 
83  if(ghostedContainer_!=Teuchos::null) ghostedContainer_->initialize();
84 }
85 
86 template <typename EvalT>
89 {
90  double glbValue = Sacado::ScalarValue<ScalarT>::eval(value);
91 
92  // find the minimum processor who has the probe value
93  int locProc = have_probe ? this->getComm()->getRank() : this->getComm()->getSize();
94  int glbProc = 0;
95  Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, Thyra::Ordinal(1), &locProc, &glbProc);
96 
97  TEUCHOS_ASSERT(glbProc < this->getComm()->getSize());
98 
99  // now broadcast the value from proc glbProc
100  Teuchos::broadcast(*this->getComm(), glbProc, Thyra::Ordinal(1), &glbValue);
101 
102  value = glbValue;
103 
104  // built data in vectors
105  if(this->useEpetra()) {
106  // use epetra
107  this->getEpetraVector()[0] = glbValue;
108  }
109  else {
110  // use thyra
111  TEUCHOS_ASSERT(this->useThyra());
112 
113  this->getThyraVector()[0] = glbValue;
114  }
115 }
116 
117 template < >
120 {
121  using Teuchos::rcp_dynamic_cast;
122 
123  Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
124 
125  uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
126  Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
127 
128  linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
129 
130  uniqueContainer_ = Teuchos::null;
131 }
132 
133 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
134 template < >
137 {
138  using Teuchos::rcp_dynamic_cast;
139 
140  Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
141 
142  uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
143  Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
144 
145  linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
146 
147  uniqueContainer_ = Teuchos::null;
148 }
149 #endif
150 
151 template < >
154 {
155  const int n = value.size();
156  const int num_deriv = this->numDeriv();
157  TEUCHOS_ASSERT(n == 0 || n == num_deriv);
158  if (n == 0)
159  value.resize(num_deriv);
160 
161  // find the minimum processor who has the probe value
162  if (num_deriv > 0) {
163  int locProc = have_probe ? this->getComm()->getRank() : this->getComm()->getSize();
164  int glbProc = 0;
165  Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, Thyra::Ordinal(1), &locProc, &glbProc);
166 
167  TEUCHOS_ASSERT(glbProc < this->getComm()->getSize());
168 
169  // now broadcast the derivatives from proc glbProc
170  Teuchos::broadcast(*this->getComm(), glbProc, Thyra::Ordinal(num_deriv), &value.fastAccessDx(0));
171  }
172 
173  // copy data in vectors
174  if(this->useEpetra()) {
175  // use epetra
176  Epetra_MultiVector& deriv = this->getEpetraMultiVector();
177  for (int i=0; i<num_deriv; ++i)
178  deriv[i][0] = value.dx(i);
179  }
180  else {
181  // use thyra
182  TEUCHOS_ASSERT(this->useThyra());
183  Thyra::ArrayRCP< Thyra::ArrayRCP<double> > deriv = this->getThyraMultiVector();
184  for (int i=0; i<num_deriv; ++i)
185  deriv[i][0] = value.dx(i);
186  }
187 }
188 
189 // Do nothing unless derivatives are actually required
190 template <typename EvalT>
193 
194 // derivatives are required for
195 template < >
198 {
199  setDerivativeVectorSpace(soln_vs);
200 }
201 
202 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
203 // derivatives are required for
204 template < >
207 {
208  setDerivativeVectorSpace(soln_vs);
209 }
210 #endif
211 
212 // Do nothing unless derivatives are required
213 template <typename EvalT>
215 adjustForDirichletConditions(const GlobalEvaluationData & /* localBCRows */, const GlobalEvaluationData & /* globalBCRows */) { }
216 
217 // Do nothing unless derivatives are required
218 template < >
221 {
222  linObjFactory_->adjustForDirichletConditions(Teuchos::dyn_cast<const LinearObjContainer>(localBCRows),
223  Teuchos::dyn_cast<const LinearObjContainer>(globalBCRows),
224  *ghostedContainer_,true,true);
225 }
226 
227 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
228 // Do nothing unless derivatives are required
229 template < >
232 {
233  linObjFactory_->adjustForDirichletConditions(Teuchos::dyn_cast<const LinearObjContainer>(localBCRows),
234  Teuchos::dyn_cast<const LinearObjContainer>(globalBCRows),
235  *ghostedContainer_,true,true);
236 }
237 #endif
238 
239 }
240 
241 #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_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
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)