Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
58 
59 #include "Thyra_SpmdVectorBase.hpp"
60 #include "Teuchos_ArrayRCP.hpp"
61 
62 namespace panzer {
63 
67 template<typename EvalT, typename Traits>
69 ResponseScatterEvaluator_ExtremeValue(const std::string & name,
70  const CellData & cd,
71  bool useMax,
72  const Teuchos::RCP<ExtremeValueScatterBase> & extremeValueScatter)
73  : responseName_(name)
74  , scatterObj_(extremeValueScatter)
75  , useMax_(useMax)
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  cellExtremeValue_ = PHX::MDField<const ScalarT,panzer::Cell>(name,dl_cell);
90  this->addDependentField(cellExtremeValue_);
91 
92  std::string n = "Extreme Value Response Scatter: " + name;
93  this->setName(n);
94 }
95 
96 template<typename EvalT, typename Traits>
98 ResponseScatterEvaluator_ExtremeValue(const std::string & integrandName,
99  const std::string & responseName,
100  const CellData & cd,
101  bool useMax,
102  const Teuchos::RCP<ExtremeValueScatterBase> & extremeValueScatter)
103  : responseName_(responseName)
104  , scatterObj_(extremeValueScatter)
105  , useMax_(useMax)
106 {
107  using Teuchos::RCP;
108  using Teuchos::rcp;
109 
110  std::string dummyName = ResponseBase::buildLookupName(responseName) + " dummy target";
111 
112  // build dummy target tag
113  RCP<PHX::DataLayout> dl_dummy = rcp(new PHX::MDALayout<panzer::Dummy>(0));
114  scatterHolder_ = rcp(new PHX::Tag<ScalarT>(dummyName,dl_dummy));
115  this->addEvaluatedField(*scatterHolder_);
116 
117  // build dendent field
118  RCP<PHX::DataLayout> dl_cell = rcp(new PHX::MDALayout<panzer::Cell>(cd.numCells()));
119  cellExtremeValue_ = PHX::MDField<const ScalarT,panzer::Cell>(integrandName,dl_cell);
120  this->addDependentField(cellExtremeValue_);
121 
122  std::string n = "Extreme Value Response Scatter: " + responseName;
123  this->setName(n);
124 }
125 
126 template<typename EvalT, typename Traits>
129 {
130  // extract linear object container
131  responseObj_ = Teuchos::rcp_dynamic_cast<Response_ExtremeValue<EvalT> >(
132  d.gedc->getDataObject(ResponseBase::buildLookupName(responseName_)),true);
133 }
134 
135 
136 template<typename EvalT, typename Traits>
139 {
140  for(index_t i=0;i<d.num_cells;i++) {
141  if(useMax_)
142  responseObj_->value = (responseObj_->value < cellExtremeValue_(i)) ? cellExtremeValue_(i) : responseObj_->value;
143  else
144  responseObj_->value = (responseObj_->value > cellExtremeValue_(i)) ? cellExtremeValue_(i) : responseObj_->value;
145  }
146 }
147 
148 template < >
151 {
152  using Teuchos::RCP;
153  using Teuchos::rcp_dynamic_cast;
154  using Thyra::SpmdVectorBase;
155 
156  TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
157 
158  // grab local data for inputing
159  Teuchos::ArrayRCP<double> local_dgdx;
160  RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(responseObj_->getGhostedVector());
161  dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
162  TEUCHOS_ASSERT(!local_dgdx.is_null());
163 
164  scatterObj_->scatterDerivative(cellExtremeValue_,d,this->wda,local_dgdx);
165 }
166 
167 }
168 
169 #endif
Teuchos::RCP< GlobalEvaluationDataContainer > gedc
static std::string buildLookupName(const std::string &responseName)
std::size_t numCells() const
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_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