11 #ifndef __Panzer_GatherSolution_Epetra_Hessian_impl_hpp__
12 #define __Panzer_GatherSolution_Epetra_Hessian_impl_hpp__
15 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
24 #include "Epetra_Map.h"
25 #include "Epetra_Vector.h"
36 #include "Phalanx_DataLayout.hpp"
39 #include "Teuchos_Assert.hpp"
40 #include "Teuchos_FancyOStream.hpp"
43 #include "Thyra_SpmdVectorBase.hpp"
50 template<
typename TRAITS,
typename LO,
typename GO>
56 globalIndexer_(indexer)
84 MDField<ScalarT, Cell, NODE>(names[fd], basis->functional);
85 this->addEvaluatedField(gatherFields_[fd]);
89 string firstName(
"<none>"), n(
"Gather Solution (Epetra");
92 if (not firstSensitivitiesAvailable_)
93 n +=
", No First Sensitivities";
94 n +=
"): " + firstName +
" (" + print<EvalT>() +
") ";
103 template<
typename TRAITS,
typename LO,
typename GO>
107 typename TRAITS::SetupData ,
110 using std::logic_error;
119 const string& fieldName(indexerNames_[fd]);
120 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
124 "GatherSolution_Epetra<Hessian>: Could not find field \"" + fieldName
125 +
"\" in the global indexer. ")
127 indexerNames_.clear();
135 template<
typename TRAITS,
typename LO,
typename GO>
139 typename TRAITS::PreEvalData d)
141 using std::logic_error;
144 using Teuchos::rcp_dynamic_cast;
152 firstApplySensitivities_ =
false;
153 if ((firstSensitivitiesAvailable_ ) and
154 (d.first_sensitivities_name == sensitivitiesName_))
155 firstApplySensitivities_ =
true;
156 secondApplySensitivities_ =
false;
157 if ((secondSensitivitiesAvailable_ ) and
158 (d.second_sensitivities_name == sensitivitiesName_))
159 secondApplySensitivities_ =
true;
163 string post(useTimeDerivativeSolutionVector_ ?
" - Xdot" :
" - X");
164 if (d.gedc->containsDataObject(globalDataKey_ + post))
166 ged = d.gedc->getDataObject(globalDataKey_ + post);
167 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
171 else if (d.gedc->containsDataObject(globalDataKey_))
173 ged = d.gedc->getDataObject(globalDataKey_);
176 xEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged);
177 auto epetraContainer = rcp_dynamic_cast<ELOC>(ged);
181 auto locPair = rcp_dynamic_cast<LPGED>(ged);
182 if (not locPair.is_null())
184 RCP<LOC> loc = locPair->getGhostedLOC();
185 epetraContainer = rcp_dynamic_cast<ELOC>(loc);
188 if ((xEvRoGed_.is_null()) and (not epetraContainer.is_null()))
190 if (useTimeDerivativeSolutionVector_)
191 x_ = epetraContainer->get_dxdt();
193 x_ = epetraContainer->get_x();
199 logic_error,
"GatherSolution_Epetra_Hessian::preEvaluate(): Unable to " \
200 "find solution vector.")
203 if (not secondApplySensitivities_)
207 if (d.gedc->containsDataObject(sensitivities2ndPrefix_ + globalDataKey_))
209 ged = d.gedc->getDataObject(sensitivities2ndPrefix_ + globalDataKey_);
210 dxEvRoGed_ = rcp_dynamic_cast<EVROGED>(ged,
true);
214 "find sensitivity vector associated with \"" + sensitivities2ndPrefix_ +
215 globalDataKey_ +
"\" and \"" + post +
"\".")
224 template<typename TRAITS, typename LO, typename GO>
228 typename TRAITS::EvalData workset)
235 using Teuchos::ptrFromRef;
237 using Teuchos::rcp_dynamic_cast;
238 using Thyra::SpmdVectorBase;
241 string blockId(this->wda(workset).block_id);
242 const vector<size_t>& localCellIds = this->wda(workset).cell_local_ids;
243 int numFields(gatherFields_.size()), numCells(localCellIds.size());
247 if (firstApplySensitivities_)
249 if ((useTimeDerivativeSolutionVector_) and (gatherSeedIndex_ < 0))
250 seedValue = workset.alpha;
251 else if (gatherSeedIndex_ < 0)
252 seedValue = workset.beta;
253 else if (not useTimeDerivativeSolutionVector_)
254 seedValue = workset.gather_seeds[gatherSeedIndex_];
262 if (not firstApplySensitivities_)
269 if (this->wda.getDetailsIndex() == 1)
272 dos = globalIndexer_->getElementBlockGIDCount(workset.details(0).block_id);
278 for (
int fieldIndex(0); fieldIndex <
numFields; ++fieldIndex)
280 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldIndex];
281 int fieldNum(fieldIds_[fieldIndex]);
282 const vector<int>& elmtOffset =
283 globalIndexer_->getGIDFieldOffsets(blockId, fieldNum);
284 int numBases(elmtOffset.size());
287 for (
int cell(0); cell < numCells; ++cell)
289 size_t cellLocalId(localCellIds[cell]);
290 auto LIDs = globalIndexer_->getElementLIDs(cellLocalId);
293 for (
int basis(0); basis < numBases; ++basis)
295 int offset(elmtOffset[basis]), lid(LIDs[offset]);
296 field(cell, basis) = (*xEvRoGed_)[lid];
304 for (
int fieldIndex(0); fieldIndex <
numFields; ++fieldIndex)
306 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldIndex];
307 int fieldNum(fieldIds_[fieldIndex]);
308 const vector<int>& elmtOffset =
309 globalIndexer_->getGIDFieldOffsets(blockId, fieldNum);
310 int numBases(elmtOffset.size());
313 for (
int cell(0); cell < numCells; ++cell)
315 size_t cellLocalId(localCellIds[cell]);
316 auto LIDs = globalIndexer_->getElementLIDs(cellLocalId);
319 for (
int basis(0); basis < numBases; ++basis)
321 int offset(elmtOffset[basis]), lid(LIDs[offset]);
322 field(cell, basis) = (*x_)[lid];
329 if (firstApplySensitivities_)
332 for (
int fieldIndex(0); fieldIndex <
numFields; ++fieldIndex)
334 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldIndex];
335 int fieldNum(fieldIds_[fieldIndex]);
336 const vector<int>& elmtOffset =
337 globalIndexer_->getGIDFieldOffsets(blockId, fieldNum);
338 int numBases(elmtOffset.size());
341 for (
int cell(0); cell < numCells; ++cell)
344 for (
int basis(0); basis < numBases; ++basis)
346 int offset(elmtOffset[basis]);
347 field(cell, basis).fastAccessDx(dos + offset) = seedValue;
354 if (secondApplySensitivities_)
357 for (
int fieldIndex(0); fieldIndex <
numFields; ++fieldIndex)
359 MDField<ScalarT, Cell, NODE>&
field = gatherFields_[fieldIndex];
360 int fieldNum(fieldIds_[fieldIndex]);
361 const vector<int>& elmtOffset =
362 globalIndexer_->getGIDFieldOffsets(blockId, fieldNum);
363 int numBases(elmtOffset.size());
366 for (
int cell(0); cell < numCells; ++cell)
368 size_t cellLocalId(localCellIds[cell]);
369 auto LIDs = globalIndexer_->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_Epetra_Hessian_impl_hpp__
Gathers solution values from the Newton solution vector into the nodal fields of the field manager...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
This class provides a boundary exchange communication mechanism for vectors.
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...
GatherSolution_Epetra (Hessian Specialization)
Description and data layouts associated with a particular basis.
#define TEUCHOS_ASSERT(assertion_test)