11#ifndef PANZER_GATHER_SOLUTION_TPETRA_IMPL_HPP
12#define PANZER_GATHER_SOLUTION_TPETRA_IMPL_HPP
14#include "Teuchos_Assert.hpp"
15#include "Phalanx_DataLayout.hpp"
26#include "Teuchos_FancyOStream.hpp"
28#include "Tpetra_Vector.hpp"
29#include "Tpetra_Map.hpp"
35template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
38 const Teuchos::RCP<const panzer::GlobalIndexer> & indexer,
39 const Teuchos::ParameterList& p)
43 typedef std::vector< std::vector<std::string> > vvstring;
48 const std::vector<std::string> & names = input.
getDofNames();
49 Teuchos::RCP<const panzer::PureBasis> basis = input.
getBasis();
58 for (std::size_t fd = 0; fd < names.size(); ++fd) {
60 PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
65 if (tangent_field_names.size()>0) {
66 TEUCHOS_ASSERT(gatherFields_.size() == tangent_field_names.size());
68 has_tangent_fields_ = true;
69 tangentFields_.resize(gatherFields_.size());
70 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
71 tangentFields_[fd].resize(tangent_field_names[fd].size());
72 for (std::size_t i=0; i<tangent_field_names[fd].size(); ++i) {
73 tangentFields_[fd][i] =
74 PHX::MDField<const ScalarT,Cell,NODE>(tangent_field_names[fd][i],basis->functional);
75 this->addDependentField(tangentFields_[fd][i]);
81 std::string firstName =
"<none>";
85 std::string n =
"GatherSolution (Tpetra): "+firstName+
" (Residual)";
90template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
99 const Workset & workset_0 = (*d.worksets_)[0];
100 std::string blockId = this->
wda(workset_0).block_id;
108 const std::vector<int> & offsets =
globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
110 Kokkos::deep_copy(
scratch_offsets_[fd], Kokkos::View<const int*, Kokkos::HostSpace, Kokkos::MemoryUnmanaged>(offsets.data(), offsets.size()));
120template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
130 x_vector = Teuchos::rcp_dynamic_cast<RO_GED>(d.gedc->getDataObject(
globalDataKey_+post),
true)->getGhostedVector_Tpetra();
134 Teuchos::RCP<GlobalEvaluationData> ged = d.gedc->getDataObject(
globalDataKey_);
140 Teuchos::RCP<LOCPair_GlobalEvaluationData> loc_pair = Teuchos::rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(ged);
141 if(loc_pair!=Teuchos::null)
142 tpetraContainer_ = Teuchos::rcp_dynamic_cast<LOC>(loc_pair->getGhostedLOC());
153 x_vector = Teuchos::rcp_dynamic_cast<RO_GED>(ged,
true)->getGhostedVector_Tpetra();
157template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
162 std::string blockId = this->
wda(workset).block_id;
163 const std::vector<std::size_t> & localCellIds = this->
wda(workset).cell_local_ids;
165 auto x_data =
x_vector->getLocalViewDevice(Tpetra::Access::ReadOnly);
177 for (std::size_t fieldIndex=0; fieldIndex<
gatherFields_.size();fieldIndex++) {
179 auto gather_field =
gatherFields_[fieldIndex].get_static_view();
181 Kokkos::parallel_for(localCellIds.size(), KOKKOS_LAMBDA (std::size_t worksetCellIndex) {
183 for(std::size_t basis=0;basis<offsets.extent(0);basis++) {
184 int offset = offsets(basis);
185 LO lid = lids(worksetCellIndex,offset);
188 gather_field(worksetCellIndex,basis) = x_data(lid,0);
198template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
201 const Teuchos::RCP<const panzer::GlobalIndexer> & indexer,
202 const Teuchos::ParameterList& p)
206 typedef std::vector< std::vector<std::string> > vvstring;
211 const std::vector<std::string> & names = input.
getDofNames();
212 Teuchos::RCP<const panzer::PureBasis> basis = input.
getBasis();
221 for (std::size_t fd = 0; fd < names.size(); ++fd) {
223 PHX::MDField<ScalarT,Cell,NODE>(names[fd],basis->functional);
231 if (tangent_field_names.size()>0) {
232 TEUCHOS_ASSERT(gatherFields_.size() == tangent_field_names.size());
234 has_tangent_fields_ = true;
235 tangentFields_.resize(gatherFields_.size());
236 for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) {
237 tangentFields_[fd].resize(tangent_field_names[fd].size());
238 for (std::size_t i=0; i<tangent_field_names[fd].size(); ++i) {
239 tangentFields_[fd][i] =
240 PHX::MDField<const RealT,Cell,NODE>(tangent_field_names[fd][i],basis->functional);
241 this->addDependentField(tangentFields_[fd][i]);
247 std::string firstName =
"<none>";
249 firstName = names[0];
251 std::string n =
"GatherSolution (Tpetra): "+firstName+
" (Tangent)";
256template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
271 size_t inner_vector_max_size = 0;
273 inner_vector_max_size = std::max(inner_vector_max_size,
tangentFields_[fd].size());
300template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
310 x_vector = Teuchos::rcp_dynamic_cast<RO_GED>(d.gedc->getDataObject(
globalDataKey_+post),
true)->getGhostedVector_Tpetra();
314 Teuchos::RCP<GlobalEvaluationData> ged = d.gedc->getDataObject(
globalDataKey_);
320 Teuchos::RCP<LOCPair_GlobalEvaluationData> loc_pair = Teuchos::rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(ged);
321 if(loc_pair!=Teuchos::null)
322 tpetraContainer_ = Teuchos::rcp_dynamic_cast<LOC>(loc_pair->getGhostedLOC());
333 x_vector = Teuchos::rcp_dynamic_cast<RO_GED>(ged,
true)->getGhostedVector_Tpetra();
337template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
342 std::string blockId = this->
wda(workset).block_id;
344 typedef typename PHX::MDField<ScalarT,Cell,NODE>::array_type::reference_type reference_type;
345 auto cellLocalIdsKokkos = this->
wda(workset).getLocalCellIDs();
347 auto gidFieldOffsetsVoV = Teuchos::rcp_dynamic_cast<const panzer::DOFManager>(
globalIndexer_,
true)->getGIDFieldOffsetsKokkos(blockId,
fieldIds_);
348 auto gidFieldOffsets = gidFieldOffsetsVoV.getViewDevice();
350 auto x_view =
x_vector->getLocalViewDevice(Tpetra::Access::ReadOnly);
355 Kokkos::parallel_for(
"GatherSolutionTpetra<Tangent>",cellLocalIdsKokkos.extent(0),KOKKOS_LAMBDA(
const int worksetCellIndex) {
356 for (
size_t fieldIndex = 0; fieldIndex < gidFieldOffsets.extent(0); ++fieldIndex) {
357 for(
size_t basis=0;basis<gidFieldOffsets(fieldIndex).extent(0);basis++) {
358 int offset = gidFieldOffsets(fieldIndex)(basis);
359 LO lid = lids(cellLocalIdsKokkos(worksetCellIndex),offset);
360 auto gf_ref = (gatherFieldsDevice[fieldIndex])(worksetCellIndex,basis);
361 gf_ref.val() = x_view(lid,0);
362 for (std::size_t i=0; i<tangentInnerVectorSizes(fieldIndex); ++i) {
363 gf_ref.fastAccessDx(i) = tangentFieldsDevice(fieldIndex,i)(worksetCellIndex,basis);
370 Kokkos::parallel_for(
"GatherSolutionTpetra<Tangent>",cellLocalIdsKokkos.extent(0),KOKKOS_LAMBDA(
const int worksetCellIndex) {
371 for (
size_t fieldIndex = 0; fieldIndex < gidFieldOffsets.extent(0); ++fieldIndex) {
372 for(
size_t basis=0;basis<gidFieldOffsets(fieldIndex).extent(0);basis++) {
373 int offset = gidFieldOffsets(fieldIndex)(basis);
374 LO lid = lids(cellLocalIdsKokkos(worksetCellIndex),offset);
375 reference_type gf_ref = (gatherFieldsDevice[fieldIndex])(worksetCellIndex,basis);
376 gf_ref.val() = x_view(lid,0);
387template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
390 const Teuchos::RCP<const panzer::GlobalIndexer> & indexer,
391 const Teuchos::ParameterList& p)
399 const std::vector<std::string> & names = input.
getDofNames();
400 Teuchos::RCP<const panzer::PureBasis> basis = input.
getBasis();
413 for (std::size_t fd = 0; fd < names.size(); ++fd) {
414 PHX::MDField<ScalarT,Cell,NODE> f(names[fd],basis->functional);
423 std::string firstName =
"<none>";
425 firstName = names[0];
429 std::string n =
"GatherSolution (Tpetra, No Sensitivities): "+firstName+
" (Jacobian)";
433 std::string n =
"GatherSolution (Tpetra): "+firstName+
" (Jacobian) ";
439template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
448 const Workset & workset_0 = (*d.worksets_)[0];
449 std::string blockId = this->
wda(workset_0).block_id;
469template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
475 using Teuchos::rcp_dynamic_cast;
493 RCP<GlobalEvaluationData> ged;
500 RCP<RO_GED> ro_ged = rcp_dynamic_cast<RO_GED>(ged,
true);
502 x_vector = ro_ged->getGhostedVector_Tpetra();
511 RCP<LOC> tpetraContainer = rcp_dynamic_cast<LOC>(ged);
512 RCP<LOCPair_GlobalEvaluationData> loc_pair = rcp_dynamic_cast<LOCPair_GlobalEvaluationData>(ged);
514 if(loc_pair!=Teuchos::null) {
515 Teuchos::RCP<LinearObjContainer> loc = loc_pair->getGhostedLOC();
517 tpetraContainer = rcp_dynamic_cast<LOC>(loc);
520 if(tpetraContainer!=Teuchos::null) {
522 x_vector = tpetraContainer->get_dxdt_mv();
524 x_vector = tpetraContainer->get_x_mv();
532 RCP<RO_GED> ro_ged = rcp_dynamic_cast<RO_GED>(ged,
true);
534 x_vector = ro_ged->getGhostedVector_Tpetra();
539template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
544 std::string blockId = this->
wda(workset).block_id;
562 TEUCHOS_ASSERT(
false);
570 if (this->
wda.getDetailsIndex() == 1)
586 for(std::size_t fieldIndex=0;
593 Kokkos::parallel_for(workset.num_cells,*
this);
595 functor_data.x_data = Kokkos::View<const double**, Kokkos::LayoutLeft,PHX::Device>();
599template<
typename TRAITS,
typename LO,
typename GO,
typename NodeT>
600KOKKOS_INLINE_FUNCTION
605 for(std::size_t basis=0;basis<
functor_data.offsets.extent(0);basis++) {
WorksetDetailsAccessor wda
Teuchos::RCP< const panzer::GlobalIndexer > globalIndexer_
bool useTimeDerivativeSolutionVector_
std::string sensitivitiesName_
std::vector< int > fieldIds_
std::string globalDataKey_
panzer::Traits::Jacobian::ScalarT ScalarT
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
Creates a copy of this evaluator configured from a new ParameterList, sharing the same global indexer...
PHX::View< int ** > scratch_lids_
std::vector< std::string > indexerNames_
PHX::View< const int * > offsets
std::vector< PHX::View< int * > > scratch_offsets_
Teuchos::RCP< typename TpetraLinearObjContainer< double, LO, GO, NodeT >::MultiVectorType > x_vector
bool disableSensitivities_
struct panzer::GatherSolution_Tpetra< panzer::Traits::Jacobian, TRAITS, LO, GO, NodeT >::@277210013055204000354024303236206070250313074174 functor_data
Teuchos::RCP< const typename TpetraLinearObjContainer< double, LO, GO, NodeT >::MultiVectorType > x_vector
bool useTimeDerivativeSolutionVector_
std::vector< PHX::View< int * > > scratch_offsets_
Teuchos::RCP< const panzer::GlobalIndexer > globalIndexer_
std::vector< int > fieldIds_
PHX::View< int ** > scratch_lids_
std::vector< std::string > indexerNames_
std::string globalDataKey_
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
Teuchos::RCP< const TpetraLinearObjContainer< double, LO, GO, NodeT > > tpetraContainer_
PHX::ViewOfViews< 2, PHX::View< const RealT ** > > tangentFieldsVoV_
std::vector< std::string > indexerNames_
PHX::ViewOfViews< 1, PHX::View< ScalarT ** > > gatherFieldsVoV_
virtual Teuchos::RCP< CloneableEvaluator > clone(const Teuchos::ParameterList &pl) const
Creates a copy of this evaluator configured from a new ParameterList, sharing the same global indexer...
std::vector< int > fieldIds_
Teuchos::RCP< const TpetraLinearObjContainer< double, LO, GO, NodeT > > tpetraContainer_
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFields_
bool useTimeDerivativeSolutionVector_
Teuchos::RCP< const typename TpetraLinearObjContainer< double, LO, GO, NodeT >::MultiVectorType > x_vector
PHX::View< size_t * > tangentInnerVectorSizes_
std::string globalDataKey_
std::vector< std::vector< PHX::MDField< const RealT, Cell, NODE > > > tangentFields_
Teuchos::RCP< const panzer::GlobalIndexer > globalIndexer_
Gathers solution values from the Newton solution vector into the nodal fields of the field manager.
Tpetra-backed implementation of LinearObjContainer.