11 #ifndef __Panzer_GatherSolution_BlockedEpetra_Hessian_impl_hpp__
12 #define __Panzer_GatherSolution_BlockedEpetra_Hessian_impl_hpp__
15 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
33 #include "Phalanx_DataLayout.hpp"
36 #include "Teuchos_Assert.hpp"
37 #include "Teuchos_FancyOStream.hpp"
40 #include "Thyra_ProductVectorBase.hpp"
41 #include "Thyra_SpmdVectorBase.hpp"
48 template<
typename TRAITS,
typename LO,
typename GO>
83 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
84 this->addEvaluatedField(gatherFields_[fd]);
88 string firstName(
"<none>"), n(
"GatherSolution (BlockedEpetra");
91 if (not firstSensitivitiesAvailable_)
92 n +=
", No First Sensitivities";
93 n +=
"): " + firstName +
" (" + print<EvalT>() +
")";
102 template<
typename TRAITS,
typename LO,
typename GO>
106 typename TRAITS::SetupData ,
118 const string& fieldName(indexerNames_[fd]);
120 subFieldIds_[fd] = indexers_[indexerIds_[fd]]->getFieldNum(fieldName);
123 indexerNames_.clear();
131 template<
typename TRAITS,
typename LO,
typename GO>
135 typename TRAITS::PreEvalData d)
138 using std::logic_error;
141 using Teuchos::rcp_dynamic_cast;
148 firstApplySensitivities_ =
false;
149 if ((firstSensitivitiesAvailable_ ) and
150 (d.first_sensitivities_name == sensitivitiesName_))
151 firstApplySensitivities_ =
true;
152 secondApplySensitivities_ =
false;
153 if ((secondSensitivitiesAvailable_ ) and
154 (d.second_sensitivities_name == sensitivitiesName_))
155 secondApplySensitivities_ =
true;
159 string post(useTimeDerivativeSolutionVector_ ?
" - Xdot" :
" - X");
160 if (d.gedc->containsDataObject(globalDataKey_ + post))
162 ged = d.gedc->getDataObject(globalDataKey_ + post);
163 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
167 else if (d.gedc->containsDataObject(globalDataKey_))
169 ged = d.gedc->getDataObject(globalDataKey_);
172 auto roGed = rcp_dynamic_cast<
const BVROGED>(ged);
173 auto blockedContainer = rcp_dynamic_cast<
const BELOC>(ged);
174 if (not roGed.is_null())
175 xBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
176 else if (not blockedContainer.is_null())
178 if (useTimeDerivativeSolutionVector_)
179 x_ = rcp_dynamic_cast<ProductVectorBase<double>>
180 (blockedContainer->get_dxdt());
182 x_ = rcp_dynamic_cast<ProductVectorBase<double>>
183 (blockedContainer->get_x());
191 if (not secondApplySensitivities_)
195 if (d.gedc->containsDataObject(sensitivities2ndPrefix_ + globalDataKey_))
197 ged = d.gedc->getDataObject(sensitivities2ndPrefix_ + globalDataKey_);
198 dxBvRoGed_ = rcp_dynamic_cast<BVROGED>(ged,
true);
203 "Cannot find sensitivity vector associated with \"" +
204 sensitivities2ndPrefix_ + globalDataKey_ +
"\" and \"" + post +
"\".");
212 template<
typename TRAITS,
typename LO,
typename GO>
216 typename TRAITS::EvalData workset)
223 using Teuchos::ptrFromRef;
225 using Teuchos::rcp_dynamic_cast;
227 using Thyra::SpmdVectorBase;
231 string blockId(this->wda(workset).block_id);
232 const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
233 int numFields(gatherFields_.size()), numCells(localCellIds.size());
235 if (firstApplySensitivities_)
237 if ((useTimeDerivativeSolutionVector_) and (gatherSeedIndex_ < 0))
238 seedValue = workset.alpha;
239 else if (gatherSeedIndex_ < 0)
240 seedValue = workset.beta;
241 else if (not useTimeDerivativeSolutionVector_)
242 seedValue = workset.gather_seeds[gatherSeedIndex_];
250 if (not firstApplySensitivities_)
253 vector<int> blockOffsets;
258 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
260 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
261 int indexerId(indexerIds_[fieldInd]),
262 subFieldNum(subFieldIds_[fieldInd]);
265 auto xEvRoGed = xBvRoGed_->getGEDBlock(indexerId);
266 auto subRowIndexer = indexers_[indexerId];
267 const vector<int>& elmtOffset =
268 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
269 int numBases(elmtOffset.size());
272 for (
int cell(0); cell < numCells; ++cell)
274 size_t cellLocalId(localCellIds[cell]);
275 auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
278 for (
int basis(0); basis < numBases; ++basis)
280 int offset(elmtOffset[basis]), lid(LIDs[offset]);
281 field(cell, basis) = (*xEvRoGed)[lid];
289 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
291 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
292 int indexerId(indexerIds_[fieldInd]),
293 subFieldNum(subFieldIds_[fieldInd]);
297 rcp_dynamic_cast<SpmdVectorBase<double>>(x_->
298 getNonconstVectorBlock(indexerId))->getLocalData(ptrFromRef(x));
299 auto subRowIndexer = indexers_[indexerId];
300 const vector<int>& elmtOffset =
301 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
302 int numBases(elmtOffset.size());
305 for (
int cell(0); cell < numCells; ++cell)
307 size_t cellLocalId(localCellIds[cell]);
308 auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
311 for (
int basis(0); basis < numBases; ++basis)
313 int offset(elmtOffset[basis]), lid(LIDs[offset]);
314 field(cell, basis) = x[lid];
321 if (firstApplySensitivities_)
324 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
326 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
327 int indexerId(indexerIds_[fieldInd]),
328 subFieldNum(subFieldIds_[fieldInd]);
329 auto subRowIndexer = indexers_[indexerId];
330 const vector<int>& elmtOffset =
331 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
332 int startBlkOffset(blockOffsets[indexerId]),
333 numBases(elmtOffset.size());
336 for (
int cell(0); cell < numCells; ++cell)
339 for (
int basis(0); basis < numBases; ++basis)
341 int offset(elmtOffset[basis]);
342 field(cell, basis).fastAccessDx(startBlkOffset + offset) = seedValue;
349 if (secondApplySensitivities_)
352 for (
int fieldInd(0); fieldInd <
numFields; ++fieldInd)
354 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldInd];
355 int indexerId(indexerIds_[fieldInd]),
356 subFieldNum(subFieldIds_[fieldInd]);
359 auto dxEvRoGed = dxBvRoGed_->getGEDBlock(indexerId);
360 auto subRowIndexer = indexers_[indexerId];
361 const vector<int>& elmtOffset =
362 subRowIndexer->getGIDFieldOffsets(blockId, subFieldNum);
363 int numBases(elmtOffset.size());
366 for (
int cell(0); cell < numCells; ++cell)
368 size_t cellLocalId(localCellIds[cell]);
369 auto LIDs = subRowIndexer->getElementLIDs(cellLocalId);
372 for (
int basis(0); basis < numBases; ++basis)
374 int offset(elmtOffset[basis]), lid(LIDs[offset]);
375 field(cell, basis).val().fastAccessDx(0) = (*dxEvRoGed)[lid];
382 #endif // Panzer_BUILD_HESSIAN_SUPPORT
384 #endif // __Panzer_GatherSolution_BlockedEpetra_Hessian_impl_hpp__
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void computeBlockOffsets(const std::string &blockId, const std::vector< Teuchos::RCP< GlobalIndexer >> &ugis, std::vector< int > &blockOffsets)
This class encapsulates the needs of a gather operation to do a halo exchange for blocked vectors...
int getFieldBlock(const std::string &fieldName, const std::vector< Teuchos::RCP< const GlobalIndexer >> &ugis)
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &fm)
Post-Registration Setup.
GatherSolution_BlockedEpetra(const Teuchos::ParameterList &p)
Constructor.
virtual void preEvaluate(typename Traits::PreEvalData d)=0
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we'll contribute, or in which we'll store, the result of computing this integral...
void evaluateFields(typename TRAITS::EvalData d)
Evaluate Fields.
Description and data layouts associated with a particular basis.
#define TEUCHOS_ASSERT(assertion_test)
std::string typeName(const T &t)