Panzer  Version of the Day
Panzer_ResponseScatterEvaluator_ExtremeValue_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_EXTREMEVALUE_IMPL_HPP
44 #define PANZER_RESPONSE_SCATTER_EVALUATOR_EXTREMEVALUE_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_SpmdVectorBase.hpp"
59 #include "Teuchos_ArrayRCP.hpp"
60 
61 namespace panzer {
62 
66 template<typename EvalT, typename Traits>
68 ResponseScatterEvaluator_ExtremeValue(const std::string & name,
69  const CellData & cd,
70  bool useMax,
71  const Teuchos::RCP<ExtremeValueScatterBase> & extremeValueScatter)
72  : responseName_(name)
73  , scatterObj_(extremeValueScatter)
74  , useMax_(useMax)
75 {
76  using Teuchos::RCP;
77  using Teuchos::rcp;
78 
79  std::string dummyName = ResponseBase::buildLookupName(name) + " dummy target";
80 
81  // build dummy target tag
82  RCP<PHX::DataLayout> dl_dummy = rcp(new PHX::MDALayout<panzer::Dummy>(0));
83  scatterHolder_ = rcp(new PHX::Tag<ScalarT>(dummyName,dl_dummy));
84  this->addEvaluatedField(*scatterHolder_);
85 
86  // build dendent field
87  RCP<PHX::DataLayout> dl_cell = rcp(new PHX::MDALayout<panzer::Cell>(cd.numCells()));
88  cellExtremeValue_ = PHX::MDField<const ScalarT,panzer::Cell>(name,dl_cell);
89  this->addDependentField(cellExtremeValue_);
90 
91  std::string n = "Functional Response Scatter: " + name;
92  this->setName(n);
93 }
94 
95 template<typename EvalT, typename Traits>
97 ResponseScatterEvaluator_ExtremeValue(const std::string & integrandName,
98  const std::string & responseName,
99  const CellData & cd,
100  bool useMax,
101  const Teuchos::RCP<ExtremeValueScatterBase> & extremeValueScatter)
102  : responseName_(responseName)
103  , scatterObj_(extremeValueScatter)
104  , useMax_(useMax)
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  cellExtremeValue_ = PHX::MDField<const ScalarT,panzer::Cell>(integrandName,dl_cell);
119  this->addDependentField(cellExtremeValue_);
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_ExtremeValue<EvalT> >(
131  d.gedc.getDataObject(ResponseBase::buildLookupName(responseName_)),true);
132 }
133 
134 
135 template<typename EvalT, typename Traits>
139 {
140  this->utils.setFieldData(cellExtremeValue_,fm);
141 }
142 
143 template<typename EvalT, typename Traits>
146 {
147  for(index_t i=0;i<d.num_cells;i++) {
148  if(useMax_)
149  responseObj_->value = (responseObj_->value < cellExtremeValue_(i)) ? cellExtremeValue_(i) : responseObj_->value;
150  else
151  responseObj_->value = (responseObj_->value > cellExtremeValue_(i)) ? cellExtremeValue_(i) : responseObj_->value;
152  }
153 }
154 
155 template < >
158 {
159  using Teuchos::RCP;
160  using Teuchos::rcp_dynamic_cast;
161  using Thyra::SpmdVectorBase;
162 
163  TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
164 
165  // grab local data for inputing
166  Teuchos::ArrayRCP<double> local_dgdx;
167  RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(responseObj_->getGhostedVector());
168  dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
169  TEUCHOS_ASSERT(!local_dgdx.is_null());
170 
171  scatterObj_->scatterDerivative(cellExtremeValue_,d,this->wda,local_dgdx);
172 }
173 
174 }
175 
176 #endif
static std::string buildLookupName(const std::string &responseName)
ResponseScatterEvaluator_ExtremeValue(const std::string &name, const CellData &cd, bool useMax, const Teuchos::RCP< ExtremeValueScatterBase > &functionalScatter)
A constructor with concrete arguments instead of a parameter list.
Teuchos::RCP< GlobalEvaluationData > getDataObject(const std::string &key) const
Data for determining cell topology and dimensionality.
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &fm)
GlobalEvaluationDataContainer gedc
std::size_t numCells() const