// @HEADER // ***************************************************************************** // Panzer: A partial differential equation assembly // engine for strongly coupled complex multiphysics systems // // Copyright 2011 NTESS and the Panzer contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef PANZER_GATHER_TANGENT_TPETRA_IMPL_HPP #define PANZER_GATHER_TANGENT_TPETRA_IMPL_HPP #include "Teuchos_Assert.hpp" #include "Phalanx_DataLayout.hpp" #include "Panzer_GlobalIndexer.hpp" #include "Panzer_PureBasis.hpp" #include "Panzer_TpetraLinearObjContainer.hpp" #include "Panzer_LOCPair_GlobalEvaluationData.hpp" #include "Panzer_GlobalEvaluationDataContainer.hpp" #include "Panzer_DOFManager.hpp" #include "Teuchos_FancyOStream.hpp" #include "Tpetra_Vector.hpp" #include "Tpetra_Map.hpp" template panzer::GatherTangent_Tpetra:: GatherTangent_Tpetra( const Teuchos::RCP & indexer, const Teuchos::ParameterList& p) : globalIndexer_(indexer) , useTimeDerivativeSolutionVector_(false) , globalDataKey_("Tangent Gather Container") { const std::vector& names = *(p.get< Teuchos::RCP< std::vector > >("DOF Names")); indexerNames_ = p.get< Teuchos::RCP< std::vector > >("Indexer Names"); // this is beging to fix the issues with incorrect use of const Teuchos::RCP basis; if(p.isType< Teuchos::RCP >("Basis")) basis = p.get< Teuchos::RCP >("Basis"); else basis = p.get< Teuchos::RCP >("Basis"); gatherFields_.resize(names.size()); for (std::size_t fd = 0; fd < names.size(); ++fd) { gatherFields_[fd] = PHX::MDField(names[fd],basis->functional); this->addEvaluatedField(gatherFields_[fd]); // If tpetraContainer_ is null, the evalaution is a no-op. In this // case we need to preserve zero initial value. Do this by not // sharing. this->addUnsharedField(gatherFields_[fd].fieldTag().clone()); } if (p.isType("Use Time Derivative Solution Vector")) useTimeDerivativeSolutionVector_ = p.get("Use Time Derivative Solution Vector"); if (p.isType("Global Data Key")) globalDataKey_ = p.get("Global Data Key"); this->setName("Gather Tangent"); } // ********************************************************************** template void panzer::GatherTangent_Tpetra:: postRegistrationSetup(typename TRAITS::SetupData /* d */, PHX::FieldManager& /* fm */) { TEUCHOS_ASSERT(gatherFields_.size() == indexerNames_->size()); fieldIds_.resize(gatherFields_.size()); gatherFieldsVoV_.initialize("GatherSolution_Teptra",gatherFields_.size()); for (std::size_t fd = 0; fd < gatherFields_.size(); ++fd) { const std::string& fieldName = (*indexerNames_)[fd]; fieldIds_[fd] = globalIndexer_->getFieldNum(fieldName); gatherFieldsVoV_.addView(gatherFields_[fd].get_static_view(),fd); } gatherFieldsVoV_.syncHostToDevice(); indexerNames_ = Teuchos::null; // Don't need this anymore } // ********************************************************************** template void panzer::GatherTangent_Tpetra:: preEvaluate(typename TRAITS::PreEvalData d) { using Teuchos::RCP; using Teuchos::rcp_dynamic_cast; typedef TpetraLinearObjContainer LOC; // try to extract linear object container if (d.gedc->containsDataObject(globalDataKey_)) { RCP ged = d.gedc->getDataObject(globalDataKey_); RCP loc_pair = rcp_dynamic_cast(ged); if(loc_pair!=Teuchos::null) { Teuchos::RCP loc = loc_pair->getGhostedLOC(); tpetraContainer_ = rcp_dynamic_cast(loc,true); } if(tpetraContainer_==Teuchos::null) { tpetraContainer_ = rcp_dynamic_cast(ged,true); } } } // ********************************************************************** template void panzer::GatherTangent_Tpetra:: evaluateFields(typename TRAITS::EvalData workset) { // If tpetraContainer_ was not initialized, then no global evaluation data // container was set, in which case this evaluator becomes a no-op if (tpetraContainer_ == Teuchos::null) return; typedef TpetraLinearObjContainer LOC; // for convenience pull out some objects from workset std::string blockId = this->wda(workset).block_id; Teuchos::RCP x; if (useTimeDerivativeSolutionVector_) x = tpetraContainer_->get_dxdt(); else x = tpetraContainer_->get_x(); auto cellLocalIdsKokkos = this->wda(workset).getLocalCellIDs(); auto lids = globalIndexer_->getLIDs(); auto vov = Teuchos::rcp_dynamic_cast(globalIndexer_,true)->getGIDFieldOffsetsKokkos(blockId,fieldIds_); auto gidFieldOffsets = vov.getViewDevice(); auto gatherFieldsDevice = gatherFieldsVoV_.getViewDevice(); auto x_view = x->getLocalViewDevice(Tpetra::Access::ReadWrite); Kokkos::MDRangePolicy> policy({0,0},{cellLocalIdsKokkos.extent(0),gidFieldOffsets.extent(0)}); Kokkos::parallel_for("GatherSolutionTpetra",policy,KOKKOS_LAMBDA(const int worksetCellIndex, const int fieldIndex) { for(std::size_t basis=0;basis