Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_ResponseScatterEvaluator_Functional.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_HPP
12#define PANZER_RESPONSE_SCATTER_EVALUATOR_FUNCTIONAL_HPP
13
14#include <iostream>
15#include <string>
16
17#include "PanzerDiscFE_config.hpp"
18#include "Panzer_Dimension.hpp"
19#include "Panzer_CellData.hpp"
23
24#include "Phalanx_Evaluator_Macros.hpp"
25#include "Phalanx_MDField.hpp"
26
28
29namespace panzer {
30
42public:
44
52 virtual void scatterDerivative(const PHX::MDField<const panzer::Traits::Jacobian::ScalarT,panzer::Cell> & cellIntegral,
55 const std::vector<Teuchos::ArrayRCP<double> > & dgdx) const = 0;
56
57#ifdef Panzer_BUILD_HESSIAN_SUPPORT
65 virtual void scatterHessian(const PHX::MDField<const panzer::Traits::Hessian::ScalarT,panzer::Cell> & cellIntegral,
68 const std::vector<Teuchos::ArrayRCP<double> > & d2gdx2) const = 0;
69#endif
70};
71
77template <typename LO,typename GO>
79public:
81 FunctionalScatter(const Teuchos::RCP<const panzer::GlobalIndexer> & globalIndexer)
82 {
83 if(globalIndexer!=Teuchos::null)
84 ugis_.push_back(globalIndexer);
85 }
86
88 FunctionalScatter(const std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > & ugis)
89 : ugis_(ugis) {}
90
92 void scatterDerivative(const PHX::MDField<const panzer::Traits::Jacobian::ScalarT,panzer::Cell> & cellIntegral,
95 const std::vector<Teuchos::ArrayRCP<double> > & dgdx) const;
96
97#ifdef Panzer_BUILD_HESSIAN_SUPPORT
99 void scatterHessian(const PHX::MDField<const panzer::Traits::Hessian::ScalarT,panzer::Cell> & cellIntegral,
102 const std::vector<Teuchos::ArrayRCP<double> > & d2gdx2) const;
103#endif
104
105private:
106
108 std::vector<Teuchos::RCP<const panzer::GlobalIndexer> > ugis_;
109};
110
122template<typename EvalT, typename Traits>
124 public PHX::EvaluatorDerived<EvalT, Traits> {
125public:
126
128
134 ResponseScatterEvaluator_Functional(const std::string & name,const CellData & cd,
135 const Teuchos::RCP<FunctionalScatterBase> & functionalScatter);
143 ResponseScatterEvaluator_Functional(const std::string & integrandName,const std::string & responseName,const CellData & cd,
144 const Teuchos::RCP<FunctionalScatterBase> & functionalScatter);
145
147 void evaluateFields(typename Traits::EvalData d);
148
150 void preEvaluate(typename Traits::PreEvalData d);
151
152private:
153 typedef typename EvalT::ScalarT ScalarT;
154
156 std::string responseName_;
158 Teuchos::RCP<Response_Functional<EvalT> > responseObj_;
159
160 Teuchos::RCP<PHX::FieldTag> scatterHolder_; // dummy target
161 PHX::MDField<const ScalarT,panzer::Cell> cellIntegral_; // holds cell integrals
163 Teuchos::RCP<FunctionalScatterBase> scatterObj_;
164};
165
166template <typename LO,typename GO>
167void FunctionalScatter<LO,GO>::scatterDerivative(const PHX::MDField<const panzer::Traits::Jacobian::ScalarT,panzer::Cell> & cellIntegral,
170 const std::vector<Teuchos::ArrayRCP<double> > & dgdx) const
171{
172 // for convenience pull out some objects from workset
173 std::string blockId = wda(workset).block_id;
174
175 std::vector<int> blockOffsets;
176 computeBlockOffsets(blockId,ugis_,blockOffsets);
177
178 TEUCHOS_ASSERT(dgdx.size()==ugis_.size());
179
180 auto cellIntegral_h = Kokkos::create_mirror_view(cellIntegral.get_view());
181 Kokkos::deep_copy(cellIntegral_h, cellIntegral.get_view());
182
183 const std::vector<std::size_t> & localCellIds = wda(workset).cell_local_ids;
184
185 for(std::size_t b=0;b<ugis_.size();b++) {
186 int start = blockOffsets[b];
187
188 auto LIDs = ugis_[b]->getLIDs();
189 auto LIDs_h = Kokkos::create_mirror_view(LIDs);
190 Kokkos::deep_copy(LIDs_h, LIDs);
191
192 Teuchos::ArrayRCP<double> dgdx_b = dgdx[b];
193
194 // scatter operation for each cell in workset
195 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
196 std::size_t cellLocalId = localCellIds[worksetCellIndex];
197
198 // loop over basis functions
199 for(std::size_t i=0;i<LIDs_h.extent(1);i++) {
200 dgdx_b[LIDs_h(cellLocalId, i)] += cellIntegral_h(worksetCellIndex).dx(start+i); // its possible functional is independent of solution value!
201 }
202 }
203 }
204}
205
206#ifdef Panzer_BUILD_HESSIAN_SUPPORT
207template <typename LO,typename GO>
208void FunctionalScatter<LO,GO>::scatterHessian(const PHX::MDField<const panzer::Traits::Hessian::ScalarT,panzer::Cell> & cellIntegral,
211 const std::vector<Teuchos::ArrayRCP<double> > & d2gdx2) const
212{
213 PHX::View<const LO*> LIDs;
214
215 // for convenience pull out some objects from workset
216 std::string blockId = wda(workset).block_id;
217
218 std::vector<int> blockOffsets;
219 computeBlockOffsets(blockId,ugis_,blockOffsets);
220
221 TEUCHOS_ASSERT(d2gdx2.size()==ugis_.size());
222
223 // scatter operation for each cell in workset
224 const std::vector<std::size_t> & localCellIds = wda(workset).cell_local_ids;
225 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
226 std::size_t cellLocalId = localCellIds[worksetCellIndex];
227
228 for(std::size_t b=0;b<ugis_.size();b++) {
229 int start = blockOffsets[b];
230
231 LIDs = ugis_[b]->getElementLIDs(cellLocalId);
232
233 Teuchos::ArrayRCP<double> d2gdx2_b = d2gdx2[b];
234
235 // loop over basis functions
236 for(std::size_t i=0;i<LIDs.size();i++) {
237 d2gdx2_b[LIDs[i]] += cellIntegral(worksetCellIndex).dx(start+i).dx(0); // its possible functional is independent of solution value!
238 }
239 }
240 }
241}
242#endif
243
244}
245
246#endif
Data for determining cell topology and dimensionality.
Wrapper to PHX::EvaluatorWithBaseImpl that implements Panzer-specific helpers.
Abstract interface for scattering a functional response's derivative back into global sensitivity vec...
virtual void scatterDerivative(const PHX::MDField< const panzer::Traits::Jacobian::ScalarT, panzer::Cell > &cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor &wda, const std::vector< Teuchos::ArrayRCP< double > > &dgdx) const =0
Accumulates dg/dx contributions from one workset's cell integrals into the global gradient vector(s).
virtual void scatterHessian(const PHX::MDField< const panzer::Traits::Hessian::ScalarT, panzer::Cell > &cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor &wda, const std::vector< Teuchos::ArrayRCP< double > > &d2gdx2) const =0
Accumulates d2g/dx2 contributions from one workset's cell integrals into the global Hessian-vector pr...
Concrete FunctionalScatterBase that scatters using one or more panzer::GlobalIndexer objects.
std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > ugis_
One global indexer per block; a single entry for non-blocked problems.
FunctionalScatter(const std::vector< Teuchos::RCP< const panzer::GlobalIndexer > > &ugis)
Construct for a blocked problem with one global indexer per block.
FunctionalScatter(const Teuchos::RCP< const panzer::GlobalIndexer > &globalIndexer)
Construct for a single global indexer (single-block problem); no-op if globalIndexer is null.
void scatterDerivative(const PHX::MDField< const panzer::Traits::Jacobian::ScalarT, panzer::Cell > &cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor &wda, const std::vector< Teuchos::ArrayRCP< double > > &dgdx) const
Accumulates dg/dx contributions from one workset's cell integrals into the global gradient vector(s).
void scatterHessian(const PHX::MDField< const panzer::Traits::Hessian::ScalarT, panzer::Cell > &cellIntegral, panzer::Traits::EvalData workset, WorksetDetailsAccessor &wda, const std::vector< Teuchos::ArrayRCP< double > > &d2gdx2) const
Accumulates d2g/dx2 contributions from one workset's cell integrals into the global Hessian-vector pr...
Teuchos::RCP< FunctionalScatterBase > scatterObj_
Used to scatter derivative/Hessian information into the response's global vectors.
Teuchos::RCP< Response_Functional< EvalT > > responseObj_
The response object accumulated into by evaluateFields().
void preEvaluate(typename Traits::PreEvalData d)
Looks up the Response_Functional to accumulate into for the upcoming fill.
void evaluateFields(typename Traits::EvalData d)
Sums this workset's per-cell integrand values (and scatters derivatives, via scatterObj_) into the re...
std::string responseName_
Name of the response this evaluator contributes to.
void computeBlockOffsets(const std::string &blockId, const std::vector< Teuchos::RCP< GlobalIndexer > > &ugis, std::vector< int > &blockOffsets)
User-defined data passed to PHX::Evaluator::preEvaluate(), called once before each residual/Jacobian ...