43 #ifndef PANZER_GATHER_SOLUTION_EPETRA_IMPL_HPP 44 #define PANZER_GATHER_SOLUTION_EPETRA_IMPL_HPP 46 #include "Teuchos_Assert.hpp" 47 #include "Phalanx_DataLayout.hpp" 57 #include "Teuchos_FancyOStream.hpp" 59 #include "Epetra_Vector.h" 60 #include "Epetra_Map.h" 66 template<
typename TRAITS,
typename LO,
typename GO>
71 : globalIndexer_(indexer)
72 , has_tangent_fields_(false)
74 typedef std::vector< std::vector<std::string> > vvstring;
77 input.setParameterList(p);
79 const std::vector<std::string> & names =
input.getDofNames();
81 const vvstring & tangent_field_names =
input.getTangentNames();
83 indexerNames_ =
input.getIndexerNames();
84 useTimeDerivativeSolutionVector_ =
input.useTimeDerivativeSolutionVector();
85 globalDataKey_ =
input.getGlobalDataKey();
88 gatherFields_.resize(names.size());
89 for (std::size_t fd = 0; fd < names.size(); ++fd) {
92 this->addEvaluatedField(gatherFields_[fd]);
96 if (tangent_field_names.size()>0) {
97 TEUCHOS_ASSERT(gatherFields_.size() == tangent_field_names.size());
99 has_tangent_fields_ =
true;
100 tangentFields_.resize(gatherFields_.size());
101 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
102 tangentFields_[fd].resize(tangent_field_names[fd].size());
103 for (std::size_t i=0; i<tangent_field_names[fd].size(); ++i) {
104 tangentFields_[fd][i] =
105 PHX::MDField<const ScalarT,Cell,NODE>(tangent_field_names[fd][i],
basis->
functional);
106 this->addDependentField(tangentFields_[fd][i]);
112 std::string firstName =
"<none>";
114 firstName = names[0];
116 std::string n =
"GatherSolution (Epetra): "+firstName+
" (Residual)";
121 template<
typename TRAITS,
typename LO,
typename GO>
128 fieldIds_.resize(gatherFields_.size());
130 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
132 const std::string& fieldName = indexerNames_[fd];
133 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
136 if(fieldIds_[fd]==-1) {
138 "GatherSolution_Epetra<Residual>: Could not find field \"" + fieldName +
"\" in the global indexer. ");
143 this->utils.setFieldData(gatherFields_[fd],fm);
146 if (has_tangent_fields_) {
147 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd)
148 for (std::size_t i=0; i<tangentFields_[fd].size(); ++i)
149 this->utils.setFieldData(tangentFields_[fd][i],fm);
152 indexerNames_.clear();
156 template<
typename TRAITS,
typename LO,
typename GO>
161 using Teuchos::rcp_dynamic_cast;
166 std::string post = useTimeDerivativeSolutionVector_ ?
" - Xdot" :
" - X";
167 if(d.gedc.containsDataObject(globalDataKey_+post)) {
168 ged = d.gedc.getDataObject(globalDataKey_+post);
177 ged = d.gedc.getDataObject(globalDataKey_);
184 if(loc_pair!=Teuchos::null) {
190 if(epetraContainer!=Teuchos::null) {
191 if (useTimeDerivativeSolutionVector_)
194 x_ = epetraContainer->
get_x();
209 template<
typename TRAITS,
typename LO,
typename GO>
213 std::vector<int> LIDs;
216 std::string blockId = this->wda(workset).block_id;
217 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
224 Epetra_Vector & x = *x_;
227 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
228 std::size_t cellLocalId = localCellIds[worksetCellIndex];
230 LIDs = globalIndexer_->getElementLIDs(cellLocalId);
233 for (std::size_t fieldIndex=0; fieldIndex<gatherFields_.size();fieldIndex++) {
234 int fieldNum = fieldIds_[fieldIndex];
235 const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
241 (gatherFields_[fieldIndex])(worksetCellIndex,
basis) = x[lid];
251 template<
typename TRAITS,
typename LO,
typename GO>
256 : globalIndexer_(indexer)
257 , has_tangent_fields_(false)
259 typedef std::vector< std::vector<std::string> > vvstring;
262 input.setParameterList(p);
264 const std::vector<std::string> & names =
input.getDofNames();
266 const vvstring & tangent_field_names =
input.getTangentNames();
268 indexerNames_ =
input.getIndexerNames();
269 useTimeDerivativeSolutionVector_ =
input.useTimeDerivativeSolutionVector();
270 globalDataKey_ =
input.getGlobalDataKey();
273 gatherFields_.resize(names.size());
274 for (std::size_t fd = 0; fd < names.size(); ++fd) {
277 this->addEvaluatedField(gatherFields_[fd]);
281 if (tangent_field_names.size()>0) {
282 TEUCHOS_ASSERT(gatherFields_.size() == tangent_field_names.size());
284 has_tangent_fields_ =
true;
285 tangentFields_.resize(gatherFields_.size());
286 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
287 tangentFields_[fd].resize(tangent_field_names[fd].size());
288 for (std::size_t i=0; i<tangent_field_names[fd].size(); ++i) {
289 tangentFields_[fd][i] =
290 PHX::MDField<const ScalarT,Cell,NODE>(tangent_field_names[fd][i],
basis->
functional);
291 this->addDependentField(tangentFields_[fd][i]);
297 std::string firstName =
"<none>";
299 firstName = names[0];
301 std::string n =
"GatherSolution (Epetra): "+firstName+
" (Tangent)";
306 template<
typename TRAITS,
typename LO,
typename GO>
313 fieldIds_.resize(gatherFields_.size());
315 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
317 const std::string& fieldName = indexerNames_[fd];
318 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
321 if(fieldIds_[fd]==-1) {
323 "GatherSolution_Epetra<Tangent>: Could not find field \"" + fieldName +
"\" in the global indexer. ");
328 this->utils.setFieldData(gatherFields_[fd],fm);
331 if (has_tangent_fields_) {
332 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd)
333 for (std::size_t i=0; i<tangentFields_[fd].size(); ++i)
334 this->utils.setFieldData(tangentFields_[fd][i],fm);
337 indexerNames_.clear();
341 template<
typename TRAITS,
typename LO,
typename GO>
346 using Teuchos::rcp_dynamic_cast;
351 std::string post = useTimeDerivativeSolutionVector_ ?
" - Xdot" :
" - X";
352 if(d.gedc.containsDataObject(globalDataKey_+post)) {
353 ged = d.gedc.getDataObject(globalDataKey_+post);
361 ged = d.gedc.getDataObject(globalDataKey_);
368 if(loc_pair!=Teuchos::null) {
374 if(epetraContainer!=Teuchos::null) {
375 if (useTimeDerivativeSolutionVector_)
378 x_ = epetraContainer->
get_x();
393 template<
typename TRAITS,
typename LO,
typename GO>
397 std::vector<int> LIDs;
400 std::string blockId = this->wda(workset).block_id;
401 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
408 Epetra_Vector & x = *x_;
411 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
412 std::size_t cellLocalId = localCellIds[worksetCellIndex];
414 LIDs = globalIndexer_->getElementLIDs(cellLocalId);
417 for (std::size_t fieldIndex=0; fieldIndex<gatherFields_.size();fieldIndex++) {
418 int fieldNum = fieldIds_[fieldIndex];
419 const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
425 if (!has_tangent_fields_)
426 (gatherFields_[fieldIndex])(worksetCellIndex,
basis) = x[lid];
428 (gatherFields_[fieldIndex])(worksetCellIndex,
basis).val() = x[lid];
429 for (std::size_t i=0; i<tangentFields_[fieldIndex].size(); ++i)
430 (gatherFields_[fieldIndex])(worksetCellIndex,
basis).fastAccessDx(i) =
431 tangentFields_[fieldIndex][i](worksetCellIndex,
basis).val();
442 template<
typename TRAITS,
typename LO,
typename GO>
447 : globalIndexer_(indexer)
452 input.setParameterList(p);
454 const std::vector<std::string> & names =
input.getDofNames();
458 indexerNames_ =
input.getIndexerNames();
459 useTimeDerivativeSolutionVector_ =
input.useTimeDerivativeSolutionVector();
460 globalDataKey_ =
input.getGlobalDataKey();
462 gatherSeedIndex_ =
input.getGatherSeedIndex();
463 sensitivitiesName_ =
input.getSensitivitiesName();
464 disableSensitivities_ = !
input.firstSensitivitiesAvailable();
467 gatherFields_.resize(names.size());
468 for (std::size_t fd = 0; fd < names.size(); ++fd) {
470 gatherFields_[fd] = f;
471 this->addEvaluatedField(gatherFields_[fd]);
475 std::string firstName =
"<none>";
477 firstName = names[0];
480 if(disableSensitivities_) {
481 std::string n =
"GatherSolution (Epetra, No Sensitivities): "+firstName+
" (Jacobian)";
485 std::string n =
"GatherSolution (Epetra): "+firstName+
" ("+PHX::typeAsString<EvalT>()+
") ";
491 template<
typename TRAITS,
typename LO,
typename GO>
499 fieldIds_.resize(gatherFields_.size());
501 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
503 const std::string& fieldName = indexerNames_[fd];
504 fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName);
507 if(fieldIds_[fd]==-1) {
509 "GatherSolution_Epetra<Jacobian>: Could not find field \"" + fieldName +
"\" in the global indexer. ");
514 this->utils.setFieldData(gatherFields_[fd],fm);
517 indexerNames_.clear();
521 template<
typename TRAITS,
typename LO,
typename GO>
526 using Teuchos::rcp_dynamic_cast;
530 if(!disableSensitivities_) {
531 if(d.first_sensitivities_name==sensitivitiesName_)
532 applySensitivities_ =
true;
534 applySensitivities_ =
false;
537 applySensitivities_ =
false;
544 std::string post = useTimeDerivativeSolutionVector_ ?
" - Xdot" :
" - X";
545 if(d.gedc.containsDataObject(globalDataKey_+post)) {
546 ged = d.gedc.getDataObject(globalDataKey_+post);
555 ged = d.gedc.getDataObject(globalDataKey_);
562 if(loc_pair!=Teuchos::null) {
568 if(epetraContainer!=Teuchos::null) {
569 if (useTimeDerivativeSolutionVector_)
572 x_ = epetraContainer->
get_x();
587 template<
typename TRAITS,
typename LO,
typename GO>
592 std::string blockId = this->wda(workset).block_id;
593 const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
595 double seed_value = 0.0;
596 if(applySensitivities_) {
597 if (useTimeDerivativeSolutionVector_ && gatherSeedIndex_<0) {
598 seed_value = workset.alpha;
600 else if (gatherSeedIndex_<0) {
601 seed_value = workset.beta;
603 else if(!useTimeDerivativeSolutionVector_) {
604 seed_value = workset.gather_seeds[gatherSeedIndex_];
611 Epetra_Vector & x = *x_;
616 if(!applySensitivities_)
628 if (this->wda.getDetailsIndex() == 1) {
630 dos = globalIndexer_->getElementBlockGIDCount(workset.details(0).block_id);
634 for(std::size_t fieldIndex=0;
635 fieldIndex<gatherFields_.size();fieldIndex++) {
636 PHX::MDField<ScalarT,Cell,NODE> &
field = gatherFields_[fieldIndex];
637 int fieldNum = fieldIds_[fieldIndex];
638 const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
641 for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
642 std::size_t cellLocalId = localCellIds[worksetCellIndex];
644 const std::vector<int> & LIDs = globalIndexer_->getElementLIDs(cellLocalId);
646 if(!applySensitivities_) {
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)
PHX::MDField< const ScalarT > input
const Teuchos::RCP< Epetra_Vector > get_x() const
Teuchos::RCP< Epetra_Vector > getGhostedVector_Epetra() const
Get the ghosted vector (Epetra version)
PHX::MDField< const ScalarT, Cell, IP > field
Teuchos::RCP< const panzer::PureBasis > basis
Interpolates basis DOF values to IP DOF values.
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< PHX::DataLayout > functional
<Cell,Basis> or <Cell,Basis>
const Teuchos::RCP< Epetra_Vector > get_dxdt() const