Panzer Version of the Day
Loading...
Searching...
No Matches
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
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
65namespace panzer {
66
70template<typename EvalT, typename Traits>
72ResponseScatterEvaluator_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
97template<typename EvalT, typename Traits>
99ResponseScatterEvaluator_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
125template<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
135template<typename EvalT, typename Traits>
138{
139 auto cellIntegral_h = Kokkos::create_mirror_view ( cellIntegral_.get_static_view());
140 Kokkos::deep_copy(cellIntegral_h, cellIntegral_.get_static_view());
141 for(index_t i=0;i<d.num_cells;i++) {
142 responseObj_->value += cellIntegral_h(i);
143 }
144}
145
146template < >
149{
150 using Teuchos::RCP;
151 using Teuchos::rcp_dynamic_cast;
152 using Thyra::SpmdVectorBase;
154
155 TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
156 TEUCHOS_ASSERT(responseObj_->getGhostedVector()!=Teuchos::null);
157
158 RCP<ProductVectorBase<double> > prod_dgdx = Thyra::castOrCreateNonconstProductVectorBase(responseObj_->getGhostedVector());
159
160 std::vector<Teuchos::ArrayRCP<double> > local_dgdxs;
161 for(int b=0;b<prod_dgdx->productSpace()->numBlocks();b++) {
162 // grab local data for inputing
163 Teuchos::ArrayRCP<double> local_dgdx;
164 RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(prod_dgdx->getNonconstVectorBlock(b));
165 dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
166
167 TEUCHOS_ASSERT(!local_dgdx.is_null());
168
169 local_dgdxs.push_back(local_dgdx);
170 }
171
172 scatterObj_->scatterDerivative(cellIntegral_,d,this->wda,local_dgdxs);
173}
174
175#ifdef Panzer_BUILD_HESSIAN_SUPPORT
176template < >
179{
180 using Teuchos::RCP;
181 using Teuchos::rcp_dynamic_cast;
182 using Thyra::SpmdVectorBase;
184
185 TEUCHOS_ASSERT(scatterObj_!=Teuchos::null);
186 TEUCHOS_ASSERT(responseObj_->getGhostedVector()!=Teuchos::null);
187
188 RCP<ProductVectorBase<double> > prod_dgdx = Thyra::castOrCreateNonconstProductVectorBase(responseObj_->getGhostedVector());
189
190 std::vector<Teuchos::ArrayRCP<double> > local_dgdxs;
191 for(int b=0;b<prod_dgdx->productSpace()->numBlocks();b++) {
192 // grab local data for inputing
193 Teuchos::ArrayRCP<double> local_dgdx;
194 RCP<SpmdVectorBase<double> > dgdx = rcp_dynamic_cast<SpmdVectorBase<double> >(prod_dgdx->getNonconstVectorBlock(b));
195 dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
196
197 TEUCHOS_ASSERT(!local_dgdx.is_null());
198
199 local_dgdxs.push_back(local_dgdx);
200 }
201
202 // TEUCHOS_ASSERT(false);
203 scatterObj_->scatterHessian(cellIntegral_,d,this->wda,local_dgdxs);
204}
205#endif
206
207}
208
209#endif
Data for determining cell topology and dimensionality.
std::size_t numCells() const
static std::string buildLookupName(const std::string &responseName)
ResponseScatterEvaluator_Functional(const std::string &name, const CellData &cd, const Teuchos::RCP< FunctionalScatterBase > &functionalScatter)
A constructor with concrete arguments instead of a parameter list.
int num_cells
DEPRECATED - use: numCells()
Teuchos::RCP< GlobalEvaluationDataContainer > gedc