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();
198 TEUCHOS_TEST_FOR_EXCEPTION((x_.is_null()) and (xEvRoGed_.is_null()),
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);
213 TEUCHOS_TEST_FOR_EXCEPTION(dxEvRoGed_.is_null(), logic_error,
"Cannot " \
214 "find sensitivity vector associated with \"" + sensitivities2ndPrefix_ +
215 globalDataKey_ +
"\" and \"" + post +
"\".")
228 typename TRAITS::EvalData workset)
234 using Teuchos::ArrayRCP;
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_];
256 TEUCHOS_ASSERT(
false);
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];