Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_ResponseScatterEvaluator_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_SCATTER_EVALUATOR_FUNCTIONAL_IMPL_HPP
44 #define PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_IMPL_HPP
45 
46 #include <iostream>
47 #include <string>
48 
49 #include "PanzerDiscFE_config.hpp"
50 
51 #include "Phalanx_Evaluator_Macros.hpp"
52 #include "Phalanx_MDField.hpp"
53 #include "Phalanx_DataLayout_MDALayout.hpp"
54 
55 #include "Panzer_ResponseBase.hpp"
56 #include "Panzer_Dimension.hpp"
58 
59 #include "Thyra_DefaultProductVector.hpp"
60 #include "Thyra_SpmdVectorBase.hpp"
61 #include "Thyra_ProductVectorBase.hpp"
62 
63 #include "Teuchos_ArrayRCP.hpp"
64 
65 namespace panzer {
66 
70 template<typename EvalT, typename Traits>
72 ResponseScatterEvaluator_Functional(const std::string & name,
73  const CellData & cd,
74  const Teuchos::RCP<FunctionalScatterBase> & functionalScatter)
75  : responseName_(name)
76  , scatterObj_(functionalScatter)
77 {
78  using Teuchos::RCP;
79  using Teuchos::rcp;
80 
81  std::string dummyName = ResponseBase::buildLookupName(name) + " dummy target";
82 
83  // build dummy target tag
84  RCP<PHX::DataLayout> dl_dummy = rcp(new PHX::MDALayout<panzer::Dummy>(0));
85  scatterHolder_ = rcp(new PHX::Tag<ScalarT>(dummyName,dl_dummy));
86  this->addEvaluatedField(*scatterHolder_);
87 
88  // build dendent field
89  RCP<PHX::DataLayout> dl_cell = rcp(new PHX::MDALayout<panzer::Cell>(cd.numCells()));
90  cellIntegral_ = PHX::MDField<const ScalarT,panzer::Cell>(name,dl_cell);
91  this->addDependentField(cellIntegral_);
92 
93  std::string n = "Functional Response Scatter: " + name;
94  this->setName(n);
95 }
96 
97 template<typename EvalT, typename Traits>
99 ResponseScatterEvaluator_Functional(const std::string & integrandName,
100  const std::string & responseName,
101  const CellData & cd,
102  const Teuchos::RCP<FunctionalScatterBase> & functionalScatter)
103  : responseName_(responseName)
104  , scatterObj_(functionalScatter)
105 {
106  using Teuchos::RCP;
107  using Teuchos::rcp;
108 
109  std::string dummyName = ResponseBase::buildLookupName(responseName) + " dummy target";
110 
111  // build dummy target tag
112  RCP<PHX::DataLayout> dl_dummy = rcp(new PHX::MDALayout<panzer::Dummy>(0));
113  scatterHolder_ = rcp(new PHX::Tag<ScalarT>(dummyName,dl_dummy));
114  this->addEvaluatedField(*scatterHolder_);
115 
116  // build dendent field
117  RCP<PHX::DataLayout> dl_cell = rcp(new PHX::MDALayout<panzer::Cell>(cd.numCells()));
118  cellIntegral_ = PHX::MDField<const ScalarT,panzer::Cell>(integrandName,dl_cell);
119  this->addDependentField(cellIntegral_);
120 
121  std::string n = "Functional Response Scatter: " + responseName;
122  this->setName(n);
123 }
124 
125 template<typename EvalT, typename Traits>
128 {
129  // extract linear object container
130  responseObj_ = Teuchos::rcp_dynamic_cast<Response_Functional<EvalT> >(
131  d.gedc->getDataObject(ResponseBase::buildLookupName(responseName_)),true);
132 }
133 
134 
135 template<typename EvalT, typename Traits>
138 {
139  for(index_t i=0;i<d.num_cells;i++) {
140  responseObj_->value += cellIntegral_(i);
141  }
142 }
143 
144 template < >
147 {
148  using Teuchos::RCP;
149  using Teuchos::rcp_dynamic_cast;
150  using Thyra::SpmdVectorBase;
152 
153  TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
154  TEUCHOS_ASSERT(responseObj_->getGhostedVector()!=Teuchos::null);
155 
156  RCP<ProductVectorBase<double> > prod_dgdx = Thyra::castOrCreateNonconstProductVectorBase(responseObj_->getGhostedVector());
157 
158  std::vector<Teuchos::ArrayRCP<double> > local_dgdxs;
159  for(int b=0;b<prod_dgdx->productSpace()->numBlocks();b++) {
160  // grab local data for inputing
161  Teuchos::ArrayRCP<double> local_dgdx;
162  RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(prod_dgdx->getNonconstVectorBlock(b));
163  dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
164 
165  TEUCHOS_ASSERT(!local_dgdx.is_null());
166 
167  local_dgdxs.push_back(local_dgdx);
168  }
169 
170  scatterObj_->scatterDerivative(cellIntegral_,d,this->wda,local_dgdxs);
171 }
172 
173 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
174 template < >
177 {
178  using Teuchos::RCP;
179  using Teuchos::rcp_dynamic_cast;
180  using Thyra::SpmdVectorBase;
182 
183  TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
184  TEUCHOS_ASSERT(responseObj_->getGhostedVector()!=Teuchos::null);
185 
186  RCP<ProductVectorBase<double> > prod_dgdx = Thyra::castOrCreateNonconstProductVectorBase(responseObj_->getGhostedVector());
187 
188  std::vector<Teuchos::ArrayRCP<double> > local_dgdxs;
189  for(int b=0;b<prod_dgdx->productSpace()->numBlocks();b++) {
190  // grab local data for inputing
191  Teuchos::ArrayRCP<double> local_dgdx;
192  RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(prod_dgdx->getNonconstVectorBlock(b));
193  dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
194 
195  TEUCHOS_ASSERT(!local_dgdx.is_null());
196 
197  local_dgdxs.push_back(local_dgdx);
198  }
199 
200  // TEUCHOS_ASSERT(false);
201  scatterObj_->scatterHessian(cellIntegral_,d,this->wda,local_dgdxs);
202 }
203 #endif
204 
205 }
206 
207 #endif
Teuchos::RCP< GlobalEvaluationDataContainer > gedc
ResponseScatterEvaluator_Functional(const std::string &name, const CellData &cd, const Teuchos::RCP< FunctionalScatterBase > &functionalScatter)
A constructor with concrete arguments instead of a parameter list.
static std::string buildLookupName(const std::string &responseName)
std::size_t numCells() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Data for determining cell topology and dimensionality.
#define TEUCHOS_ASSERT(assertion_test)
bool is_null() const