| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Panzer: A partial differential equation assembly |
| 4 |
// engine for strongly coupled complex multiphysics systems |
| 5 |
// |
| 6 |
// Copyright 2011 NTESS and the Panzer contributors. |
| 7 |
// SPDX-License-Identifier: BSD-3-Clause |
| 8 |
// ***************************************************************************** |
| 9 |
// @HEADER |
| 10 |
|
| 11 |
#include <Teuchos_ConfigDefs.hpp> |
| 12 |
#include <Teuchos_UnitTestHarness.hpp> |
| 13 |
#include <Teuchos_RCP.hpp> |
| 14 |
#include <Teuchos_TimeMonitor.hpp> |
| 15 |
|
| 16 |
#include <string> |
| 17 |
#include <iostream> |
| 18 |
|
| 19 |
#include "PanzerDiscFE_config.hpp" |
| 20 |
#include "Panzer_BlockedTpetraLinearObjFactory.hpp" |
| 21 |
#include "Panzer_TpetraLinearObjFactory.hpp" |
| 22 |
#include "Panzer_IntrepidFieldPattern.hpp" |
| 23 |
#include "Panzer_DOFManager.hpp" |
| 24 |
#include "Panzer_BlockedDOFManager.hpp" |
| 25 |
#include "Panzer_LinearObjFactory_Utilities.hpp" |
| 26 |
|
| 27 |
#include "Thyra_ProductVectorSpaceBase.hpp" |
| 28 |
#include "Thyra_ProductVectorBase.hpp" |
| 29 |
#include "Thyra_BlockedLinearOpBase.hpp" |
| 30 |
|
| 31 |
#include "UnitTest_ConnManager.hpp" |
| 32 |
|
| 33 |
#include "Teuchos_DefaultComm.hpp" |
| 34 |
|
| 35 |
#include "Kokkos_DynRankView.hpp" |
| 36 |
#include "Intrepid2_HGRAD_QUAD_C1_FEM.hpp" |
| 37 |
#include "Intrepid2_HGRAD_QUAD_C2_FEM.hpp" |
| 38 |
|
| 39 |
using Teuchos::rcp; |
| 40 |
using Teuchos::RCP; |
| 41 |
using Teuchos::rcp_dynamic_cast; |
| 42 |
using Teuchos::rcpFromRef; |
| 43 |
|
| 44 |
typedef Kokkos::DynRankView<double, PHX::Device> FieldContainer; |
| 45 |
|
| 46 |
namespace panzer |
| 47 |
{ |
| 48 |
|
| 49 |
typedef double ScalarT; |
| 50 |
using LocalOrdinalT = panzer::LocalOrdinal; |
| 51 |
using GlobalOrdinalT = panzer::GlobalOrdinal; |
| 52 |
|
| 53 |
typedef panzer::TpetraLinearObjFactory<panzer::Traits, ScalarT, LocalOrdinalT, GlobalOrdinalT> TpetraLinObjFactoryType; |
| 54 |
typedef panzer::TpetraLinearObjContainer<ScalarT, LocalOrdinalT, GlobalOrdinalT> TpetraLinObjContainerType; |
| 55 |
typedef panzer::BlockedTpetraLinearObjFactory<panzer::Traits, ScalarT, LocalOrdinalT, GlobalOrdinalT> BlockedTpetraLinObjFactoryType; |
| 56 |
typedef panzer::BlockedTpetraLinearObjContainer<ScalarT, LocalOrdinalT, GlobalOrdinalT> BlockedTpetraLinObjContainerType; |
| 57 |
|
| 58 |
template <typename Intrepid2Type> |
| 59 |
RCP<const panzer::FieldPattern> buildFieldPattern() |
| 60 |
{ |
| 61 |
// build a geometric pattern from a single basis |
| 62 |
RCP<Intrepid2::Basis<PHX::exec_space, double, double>> basis = rcp(new Intrepid2Type); |
| 63 |
RCP<const panzer::FieldPattern> pattern = rcp(new panzer::Intrepid2FieldPattern(basis)); |
| 64 |
return pattern; |
| 65 |
} |
| 66 |
|
| 67 |
TEUCHOS_UNIT_TEST(tCloneLOF, tpetra) |
| 68 |
{ |
| 69 |
// build global (or serial communicator) |
| 70 |
#ifdef HAVE_MPI |
| 71 |
Teuchos::RCP<const Teuchos::MpiComm<int>> tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 72 |
#else |
| 73 |
Teuchos::RCP<const Teuchos::SerialComm<int>> tComm = Teuchos::rcp(new Teuchos::SerialComm<int>(MPI_COMM_WORLD)); |
| 74 |
#endif |
| 75 |
|
| 76 |
int myRank = tComm->getRank(); |
| 77 |
int numProc = tComm->getSize(); |
| 78 |
|
| 79 |
RCP<ConnManager> connManager = rcp(new unit_test::ConnManager(myRank, numProc)); |
| 80 |
|
| 81 |
RCP<const FieldPattern> patternC1 = buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space, double, double>>(); |
| 82 |
|
| 83 |
RCP<panzer::DOFManager> indexer = rcp(new panzer::DOFManager()); |
| 84 |
indexer->setConnManager(connManager, MPI_COMM_WORLD); |
| 85 |
indexer->addField("U", patternC1); |
| 86 |
indexer->addField("V", patternC1); |
| 87 |
indexer->buildGlobalUnknowns(); |
| 88 |
|
| 89 |
RCP<panzer::DOFManager> control_indexer = rcp(new panzer::DOFManager()); |
| 90 |
control_indexer->setConnManager(connManager, MPI_COMM_WORLD); |
| 91 |
control_indexer->addField("Z", patternC1); |
| 92 |
control_indexer->buildGlobalUnknowns(); |
| 93 |
|
| 94 |
// setup factory |
| 95 |
RCP<TpetraLinObjFactoryType> t_lof = Teuchos::rcp(new TpetraLinObjFactoryType(tComm.getConst(), indexer)); |
| 96 |
|
| 97 |
// this is the member we are testing! |
| 98 |
RCP<const LinearObjFactory<Traits>> control_lof = cloneWithNewDomain(*t_lof, control_indexer); |
| 99 |
RCP<const TpetraLinObjFactoryType> t_control_lof = rcp_dynamic_cast<const TpetraLinObjFactoryType>(control_lof); |
| 100 |
|
| 101 |
std::vector<panzer::GlobalOrdinal> control_owned; |
| 102 |
control_indexer->getOwnedIndices(control_owned); |
| 103 |
|
| 104 |
TEST_ASSERT(t_control_lof->getMap()->isSameAs(*t_lof->getMap())); |
| 105 |
TEST_EQUALITY(t_control_lof->getColMap()->getLocalNumElements(), control_owned.size()); |
| 106 |
} |
| 107 |
|
| 108 |
TEUCHOS_UNIT_TEST(tCloneLOF, blocked_tpetra) |
| 109 |
{ |
| 110 |
// TODO: Uncomment when BlockedTpetraLinearObjFactory will be supported in cloneWithNewDomain method |
| 111 |
// typedef Thyra::ProductVectorBase<double> PVector; |
| 112 |
// typedef Thyra::BlockedLinearOpBase<double> BLinearOp; |
| 113 |
|
| 114 |
// build global (or serial communicator) |
| 115 |
#ifdef HAVE_MPI |
| 116 |
Teuchos::RCP<const Teuchos::MpiComm<int>> tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 117 |
#else |
| 118 |
Teuchos::RCP<const Teuchos::SerialComm<int>> tComm = Teuchos::rcp(new Teuchos::SerialComm<int>(MPI_COMM_WORLD)); |
| 119 |
#endif |
| 120 |
|
| 121 |
int myRank = tComm->getRank(); |
| 122 |
int numProc = tComm->getSize(); |
| 123 |
|
| 124 |
RCP<ConnManager> connManager = rcp(new unit_test::ConnManager(myRank, numProc)); |
| 125 |
|
| 126 |
RCP<const FieldPattern> patternC1 = buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space, double, double>>(); |
| 127 |
RCP<const FieldPattern> patternC2 = buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C2_FEM<PHX::exec_space, double, double>>(); |
| 128 |
|
| 129 |
RCP<panzer::BlockedDOFManager> indexer = rcp(new panzer::BlockedDOFManager()); |
| 130 |
{ |
| 131 |
std::vector<std::vector<std::string>> fieldOrder(2); |
| 132 |
|
| 133 |
indexer->setConnManager(connManager, MPI_COMM_WORLD); |
| 134 |
indexer->addField("U", patternC1); |
| 135 |
indexer->addField("V", patternC1); |
| 136 |
|
| 137 |
fieldOrder[0].push_back("U"); |
| 138 |
fieldOrder[1].push_back("V"); |
| 139 |
indexer->setFieldOrder(fieldOrder); |
| 140 |
indexer->buildGlobalUnknowns(); |
| 141 |
} |
| 142 |
|
| 143 |
RCP<panzer::BlockedDOFManager> control_indexer = rcp(new panzer::BlockedDOFManager()); |
| 144 |
{ |
| 145 |
std::vector<std::vector<std::string>> fieldOrder(1); |
| 146 |
control_indexer->setConnManager(connManager, MPI_COMM_WORLD); |
| 147 |
control_indexer->addField("Z", patternC1); |
| 148 |
fieldOrder[0].push_back("Z"); |
| 149 |
indexer->setFieldOrder(fieldOrder); |
| 150 |
control_indexer->buildGlobalUnknowns(); |
| 151 |
|
| 152 |
patternC2->print(out); |
| 153 |
|
| 154 |
{ |
| 155 |
std::vector<panzer::GlobalOrdinal> gids; |
| 156 |
control_indexer->getFieldDOFManagers()[0]->getOwnedIndices(gids); |
| 157 |
out << "GIDs 0 = " << gids.size() << std::endl; |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
// setup factory |
| 162 |
RCP<BlockedTpetraLinObjFactoryType> bt_lof = Teuchos::rcp(new BlockedTpetraLinObjFactoryType(tComm, indexer)); |
| 163 |
|
| 164 |
// NOT supported yet |
| 165 |
TEST_THROW(cloneWithNewDomain(*bt_lof, control_indexer), std::logic_error); |
| 166 |
|
| 167 |
// TODO: Uncomment when BlockedTpetraLinearObjFactory will be supported in cloneWithNewDomain method |
| 168 |
// // this is the member we are testing! |
| 169 |
// RCP<const LinearObjFactory<Traits>> control_lof = cloneWithNewDomain(*bt_lof, control_indexer); |
| 170 |
// RCP<const BlockedTpetraLinObjFactoryType> bt_control_lof = rcp_dynamic_cast<const BlockedTpetraLinObjFactoryType>(control_lof); |
| 171 |
|
| 172 |
// RCP<BLinearOp> mat = rcp_dynamic_cast<BLinearOp>(bt_control_lof->getThyraMatrix()); |
| 173 |
// RCP<BLinearOp> gmat = rcp_dynamic_cast<BLinearOp>(bt_control_lof->getGhostedThyraMatrix()); |
| 174 |
// RCP<PVector> x = rcp_dynamic_cast<PVector>(bt_control_lof->getThyraDomainVector()); |
| 175 |
// RCP<PVector> gx = rcp_dynamic_cast<PVector>(bt_control_lof->getGhostedThyraDomainVector()); |
| 176 |
// RCP<PVector> f = rcp_dynamic_cast<PVector>(bt_control_lof->getThyraRangeVector()); |
| 177 |
// RCP<PVector> gf = rcp_dynamic_cast<PVector>(bt_control_lof->getGhostedThyraRangeVector()); |
| 178 |
|
| 179 |
// TEST_EQUALITY(x->productSpace()->numBlocks(), 1); |
| 180 |
// TEST_EQUALITY(x->productSpace()->dim(), 18); |
| 181 |
// TEST_EQUALITY(gx->productSpace()->numBlocks(), 1); |
| 182 |
// TEST_EQUALITY(gx->productSpace()->dim(), 10 + 15); |
| 183 |
|
| 184 |
// TEST_EQUALITY(f->productSpace()->numBlocks(), 2); |
| 185 |
// TEST_EQUALITY(f->productSpace()->dim(), 36); |
| 186 |
// TEST_EQUALITY(gf->productSpace()->numBlocks(), 2); |
| 187 |
// TEST_EQUALITY(gf->productSpace()->dim(), 50); |
| 188 |
|
| 189 |
// TEST_EQUALITY(mat->productRange()->numBlocks(), 2); |
| 190 |
// TEST_EQUALITY(mat->productRange()->dim(), 36); |
| 191 |
// TEST_EQUALITY(mat->productDomain()->numBlocks(), 1); |
| 192 |
// TEST_EQUALITY(mat->productDomain()->dim(), 18); |
| 193 |
|
| 194 |
// TEST_EQUALITY(gmat->productRange()->numBlocks(), 2); |
| 195 |
// TEST_EQUALITY(gmat->productRange()->dim(), 50); |
| 196 |
// TEST_EQUALITY(gmat->productDomain()->numBlocks(), 1); |
| 197 |
// TEST_EQUALITY(gmat->productDomain()->dim(), 10 + 15); |
| 198 |
} |
| 199 |
|
| 200 |
TEUCHOS_UNIT_TEST(tCloneLOF, blocked_tpetra_nonblocked_domain) |
| 201 |
{ |
| 202 |
// TODO: Uncomment when BlockedTpetraLinearObjFactory will be supported in cloneWithNewDomain method |
| 203 |
// typedef Thyra::ProductVectorBase<double> PVector; |
| 204 |
// typedef Thyra::BlockedLinearOpBase<double> BLinearOp; |
| 205 |
// typedef Thyra::VectorBase<double> Vector; |
| 206 |
|
| 207 |
// build global (or serial communicator) |
| 208 |
#ifdef HAVE_MPI |
| 209 |
Teuchos::RCP<const Teuchos::MpiComm<int>> tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 210 |
#else |
| 211 |
Teuchos::RCP<const Teuchos::SerialComm<int>> tComm = Teuchos::rcp(new Teuchos::SerialComm<int>(MPI_COMM_WORLD)); |
| 212 |
#endif |
| 213 |
|
| 214 |
int myRank = tComm->getRank(); |
| 215 |
int numProc = tComm->getSize(); |
| 216 |
|
| 217 |
RCP<ConnManager> connManager = rcp(new unit_test::ConnManager(myRank, numProc)); |
| 218 |
|
| 219 |
RCP<const FieldPattern> patternC1 = buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space, double, double>>(); |
| 220 |
RCP<const FieldPattern> patternC2 = buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C2_FEM<PHX::exec_space, double, double>>(); |
| 221 |
|
| 222 |
RCP<panzer::BlockedDOFManager> indexer = rcp(new panzer::BlockedDOFManager()); |
| 223 |
{ |
| 224 |
std::vector<std::vector<std::string>> fieldOrder(2); |
| 225 |
|
| 226 |
indexer->setConnManager(connManager, MPI_COMM_WORLD); |
| 227 |
indexer->addField("U", patternC1); |
| 228 |
indexer->addField("V", patternC1); |
| 229 |
|
| 230 |
fieldOrder[0].push_back("U"); |
| 231 |
fieldOrder[1].push_back("V"); |
| 232 |
indexer->setFieldOrder(fieldOrder); |
| 233 |
indexer->buildGlobalUnknowns(); |
| 234 |
} |
| 235 |
|
| 236 |
RCP<panzer::DOFManager> control_indexer = rcp(new panzer::DOFManager()); |
| 237 |
{ |
| 238 |
control_indexer->setConnManager(connManager, MPI_COMM_WORLD); |
| 239 |
control_indexer->addField("Z", patternC1); |
| 240 |
control_indexer->buildGlobalUnknowns(); |
| 241 |
|
| 242 |
patternC2->print(out); |
| 243 |
} |
| 244 |
|
| 245 |
// setup factory |
| 246 |
out << "build lof" << std::endl; |
| 247 |
RCP<BlockedTpetraLinObjFactoryType> bt_lof = Teuchos::rcp(new BlockedTpetraLinObjFactoryType(tComm, indexer)); |
| 248 |
|
| 249 |
// NOT supported yet |
| 250 |
TEST_THROW(cloneWithNewDomain(*bt_lof, control_indexer), std::logic_error); |
| 251 |
|
| 252 |
// TODO: Uncomment when BlockedTpetraLinearObjFactory will be supported in cloneWithNewDomain method |
| 253 |
// // this is the member we are testing! |
| 254 |
// out << "cloning lof" << std::endl; |
| 255 |
// RCP<const LinearObjFactory<Traits>> control_lof = cloneWithNewDomain(*bt_lof, control_indexer); |
| 256 |
|
| 257 |
// out << "casting lof" << std::endl; |
| 258 |
// RCP<const BlockedTpetraLinObjFactoryType> bt_control_lof = rcp_dynamic_cast<const BlockedTpetraLinObjFactoryType>(control_lof, true); |
| 259 |
|
| 260 |
// out << "using casted lof" << std::endl; |
| 261 |
// RCP<BLinearOp> mat = rcp_dynamic_cast<BLinearOp>(bt_control_lof->getThyraMatrix(), true); |
| 262 |
// RCP<BLinearOp> gmat = rcp_dynamic_cast<BLinearOp>(bt_control_lof->getGhostedThyraMatrix(), true); |
| 263 |
// RCP<Vector> x = bt_control_lof->getThyraDomainVector(); |
| 264 |
// RCP<Vector> gx = bt_control_lof->getGhostedThyraDomainVector(); |
| 265 |
// RCP<PVector> f = rcp_dynamic_cast<PVector>(bt_control_lof->getThyraRangeVector(), true); |
| 266 |
// RCP<PVector> gf = rcp_dynamic_cast<PVector>(bt_control_lof->getGhostedThyraRangeVector(), true); |
| 267 |
|
| 268 |
// TEST_EQUALITY(x->space()->dim(), 18); |
| 269 |
// TEST_EQUALITY(gx->space()->dim(), 10 + 15); |
| 270 |
|
| 271 |
// TEST_EQUALITY(f->productSpace()->numBlocks(), 2); |
| 272 |
// TEST_EQUALITY(f->productSpace()->dim(), 36); |
| 273 |
// TEST_EQUALITY(gf->productSpace()->numBlocks(), 2); |
| 274 |
// TEST_EQUALITY(gf->productSpace()->dim(), 50); |
| 275 |
|
| 276 |
// TEST_EQUALITY(mat->productRange()->numBlocks(), 2); |
| 277 |
// TEST_EQUALITY(mat->productRange()->dim(), 36); |
| 278 |
// TEST_EQUALITY(mat->productDomain()->numBlocks(), 1); |
| 279 |
// TEST_EQUALITY(mat->productDomain()->dim(), 18); |
| 280 |
|
| 281 |
// TEST_EQUALITY(gmat->productRange()->numBlocks(), 2); |
| 282 |
// TEST_EQUALITY(gmat->productRange()->dim(), 50); |
| 283 |
// TEST_EQUALITY(gmat->productDomain()->numBlocks(), 1); |
| 284 |
// TEST_EQUALITY(gmat->productDomain()->dim(), 10 + 15); |
| 285 |
} |
| 286 |
|
| 287 |
} |