Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_Response_Functional_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_Functional_impl_hpp__
44 #define __Panzer_Response_Functional_impl_hpp__
45 
46 #include "Teuchos_Comm.hpp"
47 #include "Teuchos_CommHelpers.hpp"
48 #include "Teuchos_dyn_cast.hpp"
49 
50 #include "PanzerDiscFE_config.hpp"
51 #ifdef PANZER_HAVE_EPETRA_STACK
52 #include "Epetra_LocalMap.h"
53 #endif
54 
55 #include "Sacado_Traits.hpp"
56 
57 namespace panzer {
58 
59 template <typename EvalT>
62 {
63  double locValue = Sacado::scalarValue(value);
64  double glbValue = 0.0;
65 
66  // do global summation
67  Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_SUM, static_cast<Thyra::Ordinal>(1), &locValue,&glbValue);
68 
69  value = glbValue;
70 
71  // built data in vectors
72 #ifdef PANZER_HAVE_EPETRA_STACK
73  if(this->useEpetra()) {
74  // use epetra
75  this->getEpetraVector()[0] = glbValue;
76  }
77  else
78  #endif
79  {
80  // use thyra
81  TEUCHOS_ASSERT(this->useThyra());
82 
83  this->getThyraVector()[0] = glbValue;
84  }
85 }
86 
87 template < >
90 {
91  using Teuchos::rcp_dynamic_cast;
92 
93  Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
94 
95  // if its null, don't do anything
96  if(dgdx_unique==Teuchos::null)
97  return;
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  // if its null, don't do anything
117  if(dgdx_unique==Teuchos::null)
118  return;
119 
120  uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
121  Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
122 
123  linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
124 
125  uniqueContainer_ = Teuchos::null;
126 }
127 #endif
128 
129 template < >
132 {
133  const int n = value.size();
134  const int num_deriv = this->numDeriv();
135  TEUCHOS_ASSERT(n == 0 || n == num_deriv);
136  ScalarT glbValue = ScalarT(num_deriv, 0.0);
137 
138  // do global summation -- it is possible to do the reduceAll() on the Fad's directly, but it is somewhat
139  // complicated for DFad (due to temporaries that might get created). Since this is just a sum, it is
140  // easier to do the reduction for each value and derivative component.
141  Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_SUM, Thyra::Ordinal(1), &value.val(), &glbValue.val());
142  if (num_deriv > 0)
143  Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_SUM, Thyra::Ordinal(n), value.dx(), &glbValue.fastAccessDx(0));
144 
145  value = glbValue;
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] = glbValue.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] = glbValue.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 // derivatives are required for
180 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
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.
void setSolnVectorSpace(const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &soln_vs)
Set solution vector space.
#define TEUCHOS_ASSERT(assertion_test)
void adjustForDirichletConditions(const GlobalEvaluationData &localBCRows, const GlobalEvaluationData &globalBCRows)