Panzer  Version of the Day
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"
57 
58 #include "Thyra_DefaultProductVector.hpp"
59 #include "Thyra_SpmdVectorBase.hpp"
60 #include "Thyra_ProductVectorBase.hpp"
61 
62 #include "Teuchos_ArrayRCP.hpp"
63 
64 namespace panzer {
65 
69 template<typename EvalT, typename Traits>
71 ResponseScatterEvaluator_Functional(const std::string & name,
72  const CellData & cd,
73  const Teuchos::RCP<FunctionalScatterBase> & functionalScatter)
74  : responseName_(name)
75  , scatterObj_(functionalScatter)
76 {
77  using Teuchos::RCP;
78  using Teuchos::rcp;
79 
80  std::string dummyName = ResponseBase::buildLookupName(name) + " dummy target";
81 
82  // build dummy target tag
83  RCP<PHX::DataLayout> dl_dummy = rcp(new PHX::MDALayout<panzer::Dummy>(0));
84  scatterHolder_ = rcp(new PHX::Tag<ScalarT>(dummyName,dl_dummy));
85  this->addEvaluatedField(*scatterHolder_);
86 
87  // build dendent field
88  RCP<PHX::DataLayout> dl_cell = rcp(new PHX::MDALayout<panzer::Cell>(cd.numCells()));
89  cellIntegral_ = PHX::MDField<const ScalarT,panzer::Cell>(name,dl_cell);
90  this->addDependentField(cellIntegral_);
91 
92  std::string n = "Functional Response Scatter: " + name;
93  this->setName(n);
94 }
95 
96 template<typename EvalT, typename Traits>
98 ResponseScatterEvaluator_Functional(const std::string & integrandName,
99  const std::string & responseName,
100  const CellData & cd,
101  const Teuchos::RCP<FunctionalScatterBase> & functionalScatter)
102  : responseName_(responseName)
103  , scatterObj_(functionalScatter)
104 {
105  using Teuchos::RCP;
106  using Teuchos::rcp;
107 
108  std::string dummyName = ResponseBase::buildLookupName(responseName) + " dummy target";
109 
110  // build dummy target tag
111  RCP<PHX::DataLayout> dl_dummy = rcp(new PHX::MDALayout<panzer::Dummy>(0));
112  scatterHolder_ = rcp(new PHX::Tag<ScalarT>(dummyName,dl_dummy));
113  this->addEvaluatedField(*scatterHolder_);
114 
115  // build dendent field
116  RCP<PHX::DataLayout> dl_cell = rcp(new PHX::MDALayout<panzer::Cell>(cd.numCells()));
117  cellIntegral_ = PHX::MDField<const ScalarT,panzer::Cell>(integrandName,dl_cell);
118  this->addDependentField(cellIntegral_);
119 
120  std::string n = "Functional Response Scatter: " + responseName;
121  this->setName(n);
122 }
123 
124 template<typename EvalT, typename Traits>
127 {
128  // extract linear object container
129  responseObj_ = Teuchos::rcp_dynamic_cast<Response_Functional<EvalT> >(
130  d.gedc.getDataObject(ResponseBase::buildLookupName(responseName_)),true);
131 }
132 
133 
134 template<typename EvalT, typename Traits>
138 {
139  this->utils.setFieldData(cellIntegral_,fm);
140 }
141 
142 template<typename EvalT, typename Traits>
145 {
146  for(index_t i=0;i<d.num_cells;i++) {
147  responseObj_->value += cellIntegral_(i);
148  }
149 }
150 
151 template < >
154 {
155  using Teuchos::RCP;
156  using Teuchos::rcp_dynamic_cast;
157  using Thyra::SpmdVectorBase;
159 
160  TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
161  TEUCHOS_ASSERT(responseObj_->getGhostedVector()!=Teuchos::null);
162 
163  RCP<ProductVectorBase<double> > prod_dgdx = Thyra::castOrCreateNonconstProductVectorBase(responseObj_->getGhostedVector());
164 
165  std::vector<Teuchos::ArrayRCP<double> > local_dgdxs;
166  for(int b=0;b<prod_dgdx->productSpace()->numBlocks();b++) {
167  // grab local data for inputing
168  Teuchos::ArrayRCP<double> local_dgdx;
169  RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(prod_dgdx->getNonconstVectorBlock(b));
170  dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
171 
172  TEUCHOS_ASSERT(!local_dgdx.is_null());
173 
174  local_dgdxs.push_back(local_dgdx);
175  }
176 
177  scatterObj_->scatterDerivative(cellIntegral_,d,this->wda,local_dgdxs);
178 }
179 
180 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
181 template < >
184 {
185  using Teuchos::RCP;
186  using Teuchos::rcp_dynamic_cast;
187  using Thyra::SpmdVectorBase;
189 
190  TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
191  TEUCHOS_ASSERT(responseObj_->getGhostedVector()!=Teuchos::null);
192 
193  RCP<ProductVectorBase<double> > prod_dgdx = Thyra::castOrCreateNonconstProductVectorBase(responseObj_->getGhostedVector());
194 
195  std::vector<Teuchos::ArrayRCP<double> > local_dgdxs;
196  for(int b=0;b<prod_dgdx->productSpace()->numBlocks();b++) {
197  // grab local data for inputing
198  Teuchos::ArrayRCP<double> local_dgdx;
199  RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(prod_dgdx->getNonconstVectorBlock(b));
200  dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
201 
202  TEUCHOS_ASSERT(!local_dgdx.is_null());
203 
204  local_dgdxs.push_back(local_dgdx);
205  }
206 
207  // TEUCHOS_ASSERT(false);
208  scatterObj_->scatterHessian(cellIntegral_,d,this->wda,local_dgdxs);
209 }
210 #endif
211 
212 }
213 
214 #endif
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)
Teuchos::RCP< GlobalEvaluationData > getDataObject(const std::string &key) const
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
Data for determining cell topology and dimensionality.
GlobalEvaluationDataContainer gedc
std::size_t numCells() const