| 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_BlockedEpetraLinearObjFactory.hpp" |
| 21 |
#include "Panzer_IntrepidFieldPattern.hpp" |
| 22 |
#include "Panzer_DOFManager.hpp" |
| 23 |
#include "Panzer_BlockedDOFManager.hpp" |
| 24 |
#include "Panzer_LinearObjFactory_Utilities.hpp" |
| 25 |
|
| 26 |
#include "Thyra_ProductVectorSpaceBase.hpp" |
| 27 |
#include "Thyra_ProductVectorBase.hpp" |
| 28 |
#include "Thyra_BlockedLinearOpBase.hpp" |
| 29 |
|
| 30 |
#include "UnitTest_ConnManager.hpp" |
| 31 |
|
| 32 |
#ifdef HAVE_MPI |
| 33 |
#include "Epetra_MpiComm.h" |
| 34 |
#else |
| 35 |
#include "Epetra_SerialComm.h" |
| 36 |
#endif |
| 37 |
|
| 38 |
#include "Epetra_Map.h" |
| 39 |
|
| 40 |
#include "Kokkos_DynRankView.hpp" |
| 41 |
#include "Intrepid2_HGRAD_QUAD_C1_FEM.hpp" |
| 42 |
#include "Intrepid2_HGRAD_QUAD_C2_FEM.hpp" |
| 43 |
|
| 44 |
using Teuchos::rcp; |
| 45 |
using Teuchos::rcp_dynamic_cast; |
| 46 |
using Teuchos::RCP; |
| 47 |
using Teuchos::rcpFromRef; |
| 48 |
|
| 49 |
typedef Kokkos::DynRankView<double,PHX::Device> FieldContainer; |
| 50 |
|
| 51 |
namespace panzer { |
| 52 |
|
| 53 |
template <typename Intrepid2Type> |
| 54 |
RCP<const panzer::FieldPattern> buildFieldPattern() |
| 55 |
{ |
| 56 |
// build a geometric pattern from a single basis |
| 57 |
RCP<Intrepid2::Basis<PHX::exec_space,double,double> > basis = rcp(new Intrepid2Type); |
| 58 |
RCP<const panzer::FieldPattern> pattern = rcp(new panzer::Intrepid2FieldPattern(basis)); |
| 59 |
return pattern; |
| 60 |
} |
| 61 |
|
| 62 |
TEUCHOS_UNIT_TEST(tCloneLOF, epetra) |
| 63 |
{ |
| 64 |
|
| 65 |
// build global (or serial communicator) |
| 66 |
#ifdef HAVE_MPI |
| 67 |
Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD)); |
| 68 |
#else |
| 69 |
Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_SerialComm()); |
| 70 |
#endif |
| 71 |
|
| 72 |
Teuchos::RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 73 |
|
| 74 |
int myRank = eComm->MyPID(); |
| 75 |
int numProc = eComm->NumProc(); |
| 76 |
|
| 77 |
RCP<ConnManager> connManager = rcp(new unit_test::ConnManager(myRank,numProc)); |
| 78 |
|
| 79 |
RCP<const FieldPattern> patternC1 |
| 80 |
= buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space,double,double> >(); |
| 81 |
|
| 82 |
RCP<panzer::DOFManager> indexer = rcp(new panzer::DOFManager()); |
| 83 |
indexer->setConnManager(connManager,MPI_COMM_WORLD); |
| 84 |
indexer->addField("U",patternC1); |
| 85 |
indexer->addField("V",patternC1); |
| 86 |
indexer->buildGlobalUnknowns(); |
| 87 |
|
| 88 |
RCP<panzer::DOFManager> control_indexer = rcp(new panzer::DOFManager()); |
| 89 |
control_indexer->setConnManager(connManager,MPI_COMM_WORLD); |
| 90 |
control_indexer->addField("Z",patternC1); |
| 91 |
control_indexer->buildGlobalUnknowns(); |
| 92 |
|
| 93 |
// setup factory |
| 94 |
RCP<BlockedEpetraLinearObjFactory<Traits,int> > ep_lof |
| 95 |
= Teuchos::rcp(new BlockedEpetraLinearObjFactory<Traits,int>(tComm.getConst(),indexer)); |
| 96 |
|
| 97 |
// this is the member we are testing! |
| 98 |
RCP<const LinearObjFactory<Traits> > control_lof = cloneWithNewDomain(*ep_lof,control_indexer); |
| 99 |
RCP<const BlockedEpetraLinearObjFactory<Traits,int> > ep_control_lof |
| 100 |
= rcp_dynamic_cast<const BlockedEpetraLinearObjFactory<Traits,int> >(control_lof); |
| 101 |
|
| 102 |
std::vector<panzer::GlobalOrdinal> control_owned; |
| 103 |
control_indexer->getOwnedIndices(control_owned); |
| 104 |
|
| 105 |
TEST_ASSERT(ep_control_lof->getMap(0)->SameAs(*ep_lof->getMap(0))); |
| 106 |
TEST_EQUALITY(ep_control_lof->getColMap(0)->NumMyElements(),Teuchos::as<int>(control_owned.size())); |
| 107 |
} |
| 108 |
|
| 109 |
TEUCHOS_UNIT_TEST(tCloneLOF, blocked_epetra) |
| 110 |
{ |
| 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<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD)); |
| 117 |
#else |
| 118 |
Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_SerialComm()); |
| 119 |
#endif |
| 120 |
|
| 121 |
Teuchos::RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 122 |
|
| 123 |
|
| 124 |
int myRank = eComm->MyPID(); |
| 125 |
int numProc = eComm->NumProc(); |
| 126 |
|
| 127 |
RCP<ConnManager> connManager = rcp(new unit_test::ConnManager(myRank,numProc)); |
| 128 |
|
| 129 |
RCP<const FieldPattern> patternC1 |
| 130 |
= buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space,double,double> >(); |
| 131 |
RCP<const FieldPattern> patternC2 |
| 132 |
= buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C2_FEM<PHX::exec_space,double,double> >(); |
| 133 |
|
| 134 |
RCP<panzer::BlockedDOFManager> indexer = rcp(new panzer::BlockedDOFManager()); |
| 135 |
{ |
| 136 |
std::vector<std::vector<std::string> > fieldOrder(2); |
| 137 |
|
| 138 |
indexer->setConnManager(connManager,MPI_COMM_WORLD); |
| 139 |
indexer->addField("U",patternC1); |
| 140 |
indexer->addField("V",patternC1); |
| 141 |
|
| 142 |
fieldOrder[0].push_back("U"); |
| 143 |
fieldOrder[1].push_back("V"); |
| 144 |
indexer->setFieldOrder(fieldOrder); |
| 145 |
indexer->buildGlobalUnknowns(); |
| 146 |
} |
| 147 |
|
| 148 |
RCP<panzer::BlockedDOFManager> control_indexer = rcp(new panzer::BlockedDOFManager()); |
| 149 |
{ |
| 150 |
std::vector<std::vector<std::string> > fieldOrder(1); |
| 151 |
control_indexer->setConnManager(connManager,MPI_COMM_WORLD); |
| 152 |
control_indexer->addField("Z",patternC1); |
| 153 |
fieldOrder[0].push_back("Z"); |
| 154 |
indexer->setFieldOrder(fieldOrder); |
| 155 |
control_indexer->buildGlobalUnknowns(); |
| 156 |
|
| 157 |
patternC2->print(out); |
| 158 |
|
| 159 |
{ |
| 160 |
std::vector<panzer::GlobalOrdinal> gids; |
| 161 |
control_indexer->getFieldDOFManagers()[0]->getOwnedIndices(gids); |
| 162 |
out << "GIDs 0 = " << gids.size() << std::endl; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
// setup factory |
| 167 |
RCP<BlockedEpetraLinearObjFactory<Traits,int> > ep_lof |
| 168 |
= Teuchos::rcp(new BlockedEpetraLinearObjFactory<Traits,int>(tComm,indexer)); |
| 169 |
|
| 170 |
// this is the member we are testing! |
| 171 |
RCP<const LinearObjFactory<Traits> > control_lof = cloneWithNewDomain(*ep_lof,control_indexer); |
| 172 |
RCP<const BlockedEpetraLinearObjFactory<Traits,int> > ep_control_lof |
| 173 |
= rcp_dynamic_cast<const BlockedEpetraLinearObjFactory<Traits,int> >(control_lof); |
| 174 |
|
| 175 |
RCP<BLinearOp> mat = rcp_dynamic_cast<BLinearOp>(ep_control_lof->getThyraMatrix()); |
| 176 |
RCP<BLinearOp> gmat = rcp_dynamic_cast<BLinearOp>(ep_control_lof->getGhostedThyraMatrix()); |
| 177 |
RCP<PVector> x = rcp_dynamic_cast<PVector>(ep_control_lof->getThyraDomainVector()); |
| 178 |
RCP<PVector> gx = rcp_dynamic_cast<PVector>(ep_control_lof->getGhostedThyraDomainVector()); |
| 179 |
RCP<PVector> f = rcp_dynamic_cast<PVector>(ep_control_lof->getThyraRangeVector()); |
| 180 |
RCP<PVector> gf = rcp_dynamic_cast<PVector>(ep_control_lof->getGhostedThyraRangeVector()); |
| 181 |
|
| 182 |
TEST_EQUALITY(x->productSpace()->numBlocks(),1); |
| 183 |
TEST_EQUALITY(x->productSpace()->dim(),18); |
| 184 |
TEST_EQUALITY(gx->productSpace()->numBlocks(),1); |
| 185 |
TEST_EQUALITY(gx->productSpace()->dim(),10+15); |
| 186 |
|
| 187 |
TEST_EQUALITY(f->productSpace()->numBlocks(),2); |
| 188 |
TEST_EQUALITY(f->productSpace()->dim(),36); |
| 189 |
TEST_EQUALITY(gf->productSpace()->numBlocks(),2); |
| 190 |
TEST_EQUALITY(gf->productSpace()->dim(),50); |
| 191 |
|
| 192 |
|
| 193 |
TEST_EQUALITY(mat->productRange()->numBlocks(),2); |
| 194 |
TEST_EQUALITY(mat->productRange()->dim(),36); |
| 195 |
TEST_EQUALITY(mat->productDomain()->numBlocks(),1); |
| 196 |
TEST_EQUALITY(mat->productDomain()->dim(),18); |
| 197 |
|
| 198 |
TEST_EQUALITY(gmat->productRange()->numBlocks(),2); |
| 199 |
TEST_EQUALITY(gmat->productRange()->dim(),50); |
| 200 |
TEST_EQUALITY(gmat->productDomain()->numBlocks(),1); |
| 201 |
TEST_EQUALITY(gmat->productDomain()->dim(),10+15); |
| 202 |
} |
| 203 |
|
| 204 |
TEUCHOS_UNIT_TEST(tCloneLOF, blocked_epetra_nonblocked_domain) |
| 205 |
{ |
| 206 |
typedef Thyra::ProductVectorBase<double> PVector; |
| 207 |
typedef Thyra::BlockedLinearOpBase<double> BLinearOp; |
| 208 |
typedef Thyra::VectorBase<double> Vector; |
| 209 |
|
| 210 |
// build global (or serial communicator) |
| 211 |
#ifdef HAVE_MPI |
| 212 |
Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD)); |
| 213 |
#else |
| 214 |
Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_SerialComm()); |
| 215 |
#endif |
| 216 |
|
| 217 |
Teuchos::RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 218 |
|
| 219 |
|
| 220 |
int myRank = eComm->MyPID(); |
| 221 |
int numProc = eComm->NumProc(); |
| 222 |
|
| 223 |
RCP<ConnManager> connManager = rcp(new unit_test::ConnManager(myRank,numProc)); |
| 224 |
|
| 225 |
RCP<const FieldPattern> patternC1 |
| 226 |
= buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space,double,double> >(); |
| 227 |
RCP<const FieldPattern> patternC2 |
| 228 |
= buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C2_FEM<PHX::exec_space,double,double> >(); |
| 229 |
|
| 230 |
RCP<panzer::BlockedDOFManager> indexer = rcp(new panzer::BlockedDOFManager()); |
| 231 |
{ |
| 232 |
std::vector<std::vector<std::string> > fieldOrder(2); |
| 233 |
|
| 234 |
indexer->setConnManager(connManager,MPI_COMM_WORLD); |
| 235 |
indexer->addField("U",patternC1); |
| 236 |
indexer->addField("V",patternC1); |
| 237 |
|
| 238 |
fieldOrder[0].push_back("U"); |
| 239 |
fieldOrder[1].push_back("V"); |
| 240 |
indexer->setFieldOrder(fieldOrder); |
| 241 |
indexer->buildGlobalUnknowns(); |
| 242 |
} |
| 243 |
|
| 244 |
RCP<panzer::DOFManager> control_indexer = rcp(new panzer::DOFManager()); |
| 245 |
{ |
| 246 |
control_indexer->setConnManager(connManager,MPI_COMM_WORLD); |
| 247 |
control_indexer->addField("Z",patternC1); |
| 248 |
control_indexer->buildGlobalUnknowns(); |
| 249 |
|
| 250 |
patternC2->print(out); |
| 251 |
} |
| 252 |
|
| 253 |
// setup factory |
| 254 |
out << "build lof" << std::endl; |
| 255 |
RCP<BlockedEpetraLinearObjFactory<Traits,int> > ep_lof |
| 256 |
= Teuchos::rcp(new BlockedEpetraLinearObjFactory<Traits,int>(tComm,indexer)); |
| 257 |
|
| 258 |
// this is the member we are testing! |
| 259 |
out << "cloning lof" << std::endl; |
| 260 |
RCP<const LinearObjFactory<Traits> > control_lof = cloneWithNewDomain(*ep_lof,control_indexer); |
| 261 |
|
| 262 |
out << "casting lof" << std::endl; |
| 263 |
RCP<const BlockedEpetraLinearObjFactory<Traits,int> > ep_control_lof |
| 264 |
= rcp_dynamic_cast<const BlockedEpetraLinearObjFactory<Traits,int> >(control_lof,true); |
| 265 |
|
| 266 |
out << "using casted lof" << std::endl; |
| 267 |
RCP<BLinearOp> mat = rcp_dynamic_cast<BLinearOp>(ep_control_lof->getThyraMatrix(),true); |
| 268 |
RCP<BLinearOp> gmat = rcp_dynamic_cast<BLinearOp>(ep_control_lof->getGhostedThyraMatrix(),true); |
| 269 |
RCP<Vector> x = ep_control_lof->getThyraDomainVector(); |
| 270 |
RCP<Vector> gx = ep_control_lof->getGhostedThyraDomainVector(); |
| 271 |
RCP<PVector> f = rcp_dynamic_cast<PVector>(ep_control_lof->getThyraRangeVector(),true); |
| 272 |
RCP<PVector> gf = rcp_dynamic_cast<PVector>(ep_control_lof->getGhostedThyraRangeVector(),true); |
| 273 |
|
| 274 |
TEST_EQUALITY(x->space()->dim(),18); |
| 275 |
TEST_EQUALITY(gx->space()->dim(),10+15); |
| 276 |
|
| 277 |
TEST_EQUALITY(f->productSpace()->numBlocks(),2); |
| 278 |
TEST_EQUALITY(f->productSpace()->dim(),36); |
| 279 |
TEST_EQUALITY(gf->productSpace()->numBlocks(),2); |
| 280 |
TEST_EQUALITY(gf->productSpace()->dim(),50); |
| 281 |
|
| 282 |
|
| 283 |
TEST_EQUALITY(mat->productRange()->numBlocks(),2); |
| 284 |
TEST_EQUALITY(mat->productRange()->dim(),36); |
| 285 |
TEST_EQUALITY(mat->productDomain()->numBlocks(),1); |
| 286 |
TEST_EQUALITY(mat->productDomain()->dim(),18); |
| 287 |
|
| 288 |
TEST_EQUALITY(gmat->productRange()->numBlocks(),2); |
| 289 |
TEST_EQUALITY(gmat->productRange()->dim(),50); |
| 290 |
TEST_EQUALITY(gmat->productDomain()->numBlocks(),1); |
| 291 |
TEST_EQUALITY(gmat->productDomain()->dim(),10+15); |
| 292 |
} |
| 293 |
|
| 294 |
} |