| 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 "Panzer_TpetraLinearObjFactory.hpp" |
| 20 |
#include "Panzer_Traits.hpp" |
| 21 |
#include "Panzer_IntrepidFieldPattern.hpp" |
| 22 |
|
| 23 |
// for testing gather/scatter construction |
| 24 |
#include "Panzer_PureBasis.hpp" |
| 25 |
#include "Panzer_IntegrationRule.hpp" |
| 26 |
#include "Panzer_TpetraLinearObjContainer.hpp" |
| 27 |
#include "Panzer_BlockedTpetraLinearObjContainer.hpp" |
| 28 |
#include "Panzer_BlockedTpetraLinearObjFactory.hpp" |
| 29 |
#include "Panzer_PauseToAttach.hpp" |
| 30 |
|
| 31 |
#include "UnitTest_ConnManager.hpp" |
| 32 |
|
| 33 |
#include "Thyra_TpetraThyraWrappers.hpp" |
| 34 |
#include "Thyra_ProductVectorBase.hpp" |
| 35 |
#include "Thyra_BlockedLinearOpBase.hpp" |
| 36 |
#include "Thyra_SpmdVectorBase.hpp" |
| 37 |
#include "Thyra_TpetraLinearOp.hpp" |
| 38 |
|
| 39 |
#include "Tpetra_Operator.hpp" |
| 40 |
#include "Tpetra_CrsMatrix.hpp" |
| 41 |
|
| 42 |
using Teuchos::rcp; |
| 43 |
using Teuchos::rcp_dynamic_cast; |
| 44 |
using Teuchos::RCP; |
| 45 |
using Teuchos::rcpFromRef; |
| 46 |
|
| 47 |
typedef double ScalarT; |
| 48 |
typedef int LocalOrdinalT; |
| 49 |
typedef panzer::GlobalOrdinal GlobalOrdinalT; |
| 50 |
typedef panzer::TpetraNodeType NodeT; |
| 51 |
|
| 52 |
typedef Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> VectorType; |
| 53 |
typedef Tpetra::Operator<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> OperatorType; |
| 54 |
typedef Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> CrsMatrixType; |
| 55 |
typedef Tpetra::CrsGraph<LocalOrdinalT,GlobalOrdinalT,NodeT> CrsGraphType; |
| 56 |
typedef Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> MapType; |
| 57 |
typedef Tpetra::Import<LocalOrdinalT,GlobalOrdinalT,NodeT> ImportType; |
| 58 |
typedef Tpetra::Export<LocalOrdinalT,GlobalOrdinalT,NodeT> ExportType; |
| 59 |
|
| 60 |
typedef Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> ThyraLinearOp; |
| 61 |
|
| 62 |
typedef panzer::BlockedTpetraLinearObjContainer<double,int,panzer::GlobalOrdinal> BLOC; |
| 63 |
typedef panzer::BlockedTpetraLinearObjFactory<panzer::Traits,double,int,panzer::GlobalOrdinal> BLOFact; |
| 64 |
|
| 65 |
|
| 66 |
namespace panzer { |
| 67 |
|
| 68 |
Teuchos::RCP<CrsMatrixType> getSubBlock_tp(int i,int j,Thyra::LinearOpBase<double> & lo) |
| 69 |
{ |
| 70 |
Thyra::BlockedLinearOpBase<double> & blo = Teuchos::dyn_cast<Thyra::BlockedLinearOpBase<double> >(lo); |
| 71 |
Teuchos::RCP<OperatorType> t_blo = |
| 72 |
rcp_dynamic_cast<Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(blo.getNonconstBlock(i,j),true)->getTpetraOperator(); |
| 73 |
|
| 74 |
return rcp_dynamic_cast<CrsMatrixType>(t_blo); |
| 75 |
} |
| 76 |
|
| 77 |
Teuchos::RCP<const CrsMatrixType> getSubBlock_tp(int i,int j,const Thyra::LinearOpBase<double> & lo) |
| 78 |
{ |
| 79 |
const Thyra::BlockedLinearOpBase<double> & blo = Teuchos::dyn_cast<const Thyra::BlockedLinearOpBase<double> >(lo); |
| 80 |
Teuchos::RCP<const OperatorType> t_blo = |
| 81 |
rcp_dynamic_cast<const Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(blo.getBlock(i,j),true)->getConstTpetraOperator(); |
| 82 |
|
| 83 |
return rcp_dynamic_cast<const CrsMatrixType>(t_blo); |
| 84 |
} |
| 85 |
|
| 86 |
void resumeFill(CrsMatrixType & A) |
| 87 |
{ |
| 88 |
A.resumeFill(); |
| 89 |
} |
| 90 |
|
| 91 |
void fillComplete(CrsMatrixType & A) |
| 92 |
{ |
| 93 |
A.fillComplete(A.getDomainMap(),A.getRangeMap()); |
| 94 |
} |
| 95 |
|
| 96 |
void putScalar(ScalarT s,CrsMatrixType & A) |
| 97 |
{ |
| 98 |
A.setAllToScalar(s); |
| 99 |
} |
| 100 |
|
| 101 |
template <typename Intrepid2Type> |
| 102 |
Teuchos::RCP<const panzer::FieldPattern> buildFieldPattern() |
| 103 |
{ |
| 104 |
using Teuchos::RCP; |
| 105 |
using Teuchos::rcp; |
| 106 |
|
| 107 |
// build a geometric pattern from a single basis |
| 108 |
RCP<Intrepid2::Basis<PHX::exec_space,double,double> > basis = rcp(new Intrepid2Type); |
| 109 |
RCP<const panzer::FieldPattern> pattern = rcp(new panzer::Intrepid2FieldPattern(basis)); |
| 110 |
return pattern; |
| 111 |
} |
| 112 |
|
| 113 |
Teuchos::RCP<const panzer::BlockedDOFManager> buildBlockedIndexer64(int myRank,int numProc,int numBlocks) |
| 114 |
{ |
| 115 |
std::string names[] = {"U","V","W","X"}; |
| 116 |
|
| 117 |
Teuchos::RCP<const FieldPattern> patternC1 |
| 118 |
= buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space,double,double> >(); |
| 119 |
Teuchos::RCP<ConnManager> connManager = rcp(new unit_test::ConnManager(myRank,numProc)); |
| 120 |
Teuchos::RCP<panzer::BlockedDOFManager> indexer = rcp(new panzer::BlockedDOFManager()); |
| 121 |
|
| 122 |
indexer->setConnManager(connManager,MPI_COMM_WORLD); |
| 123 |
|
| 124 |
std::vector<std::vector<std::string> > fieldOrder(numBlocks); |
| 125 |
for(int i=0;i<numBlocks;i++) { |
| 126 |
indexer->addField(names[i],patternC1); |
| 127 |
|
| 128 |
fieldOrder[i].push_back(names[i]); |
| 129 |
} |
| 130 |
indexer->setFieldOrder(fieldOrder); |
| 131 |
indexer->buildGlobalUnknowns(); |
| 132 |
|
| 133 |
return indexer; |
| 134 |
} |
| 135 |
|
| 136 |
TEUCHOS_UNIT_TEST(tBlockedTpetraLinearObjFactory, intializeContainer_tpetra) |
| 137 |
{ |
| 138 |
|
| 139 |
panzer::BlockedTpetraLinearObjContainer<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> container; |
| 140 |
|
| 141 |
TEST_ASSERT(container.checkCompatibility()); |
| 142 |
} |
| 143 |
|
| 144 |
TEUCHOS_UNIT_TEST(tBlockedTpetraLinearObjFactory, tpetra_factory_tests) |
| 145 |
{ |
| 146 |
|
| 147 |
#ifdef HAVE_MPI |
| 148 |
Teuchos::RCP<Teuchos::MpiComm<int> > comm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 149 |
#else |
| 150 |
NOPE_PANZER_DOESNT_SUPPORT_SERIAL |
| 151 |
#endif |
| 152 |
|
| 153 |
using Teuchos::RCP; |
| 154 |
using Teuchos::rcp; |
| 155 |
using Teuchos::rcp_dynamic_cast; |
| 156 |
|
| 157 |
// pauseToAttach(); |
| 158 |
|
| 159 |
typedef LinearObjContainer LOC; |
| 160 |
|
| 161 |
int numBlocks = 3; |
| 162 |
int myRank = comm->getRank(); |
| 163 |
int numProc = comm->getSize(); |
| 164 |
|
| 165 |
RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer64(myRank,numProc,numBlocks); |
| 166 |
BLOFact factory(comm,blkIndexer); |
| 167 |
|
| 168 |
RCP<LinearObjContainer> container = factory.buildLinearObjContainer(); |
| 169 |
RCP<LinearObjContainer> ghosted = factory.buildGhostedLinearObjContainer(); |
| 170 |
TEST_ASSERT(container!=Teuchos::null); |
| 171 |
TEST_ASSERT(ghosted!=Teuchos::null); |
| 172 |
|
| 173 |
|
| 174 |
RCP<BLOC> bContainer = rcp_dynamic_cast<BLOC>(container); |
| 175 |
RCP<BLOC> b_ghosted = rcp_dynamic_cast<BLOC>(ghosted); |
| 176 |
TEST_ASSERT(bContainer!=Teuchos::null); |
| 177 |
TEST_ASSERT(b_ghosted!=Teuchos::null); |
| 178 |
|
| 179 |
// tests global initialize |
| 180 |
{ |
| 181 |
// Generic code |
| 182 |
///////////////////////////////////////////////////////////// |
| 183 |
|
| 184 |
// test individial initializers |
| 185 |
factory.initializeContainer(LOC::X,*container); |
| 186 |
TEST_ASSERT(bContainer->get_x()!=Teuchos::null); |
| 187 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 188 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 189 |
TEST_EQUALITY(bContainer->get_A(), Teuchos::null) |
| 190 |
|
| 191 |
factory.initializeContainer(LOC::DxDt,*container); |
| 192 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 193 |
TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); |
| 194 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 195 |
TEST_EQUALITY(bContainer->get_A(), Teuchos::null) |
| 196 |
|
| 197 |
factory.initializeContainer(LOC::F,*container); |
| 198 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 199 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 200 |
TEST_ASSERT(bContainer->get_f()!=Teuchos::null); |
| 201 |
TEST_EQUALITY(bContainer->get_A(), Teuchos::null) |
| 202 |
|
| 203 |
factory.initializeContainer(LOC::Mat,*container); |
| 204 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 205 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 206 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 207 |
TEST_ASSERT(bContainer->get_A()!=Teuchos::null); |
| 208 |
|
| 209 |
// jacobian and residual vector output |
| 210 |
factory.initializeContainer(LOC::F | LOC::Mat,*container); |
| 211 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 212 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 213 |
TEST_ASSERT(bContainer->get_f()!=Teuchos::null); |
| 214 |
TEST_ASSERT(bContainer->get_A()!=Teuchos::null); |
| 215 |
|
| 216 |
// x and time dertivative input |
| 217 |
factory.initializeContainer(LOC::X | LOC::DxDt,*container); |
| 218 |
TEST_ASSERT(bContainer->get_x()!=Teuchos::null); |
| 219 |
TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); |
| 220 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 221 |
TEST_EQUALITY(bContainer->get_A(), Teuchos::null) |
| 222 |
|
| 223 |
// everything |
| 224 |
factory.initializeContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*container); |
| 225 |
TEST_ASSERT(bContainer->get_x()!=Teuchos::null); |
| 226 |
TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); |
| 227 |
TEST_ASSERT(bContainer->get_f()!=Teuchos::null); |
| 228 |
TEST_ASSERT(bContainer->get_A()!=Teuchos::null); |
| 229 |
|
| 230 |
// Epetra specific code |
| 231 |
///////////////////////////////////////////////////////////// |
| 232 |
|
| 233 |
// test individial initializers |
| 234 |
factory.initializeContainer(LOC::X,*bContainer); |
| 235 |
TEST_ASSERT(bContainer->get_x()!=Teuchos::null); |
| 236 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 237 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 238 |
TEST_EQUALITY(bContainer->get_A(), Teuchos::null) |
| 239 |
|
| 240 |
factory.initializeContainer(LOC::DxDt,*bContainer); |
| 241 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 242 |
TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); |
| 243 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 244 |
TEST_EQUALITY(bContainer->get_A(), Teuchos::null) |
| 245 |
|
| 246 |
factory.initializeContainer(LOC::F,*bContainer); |
| 247 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 248 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 249 |
TEST_ASSERT(bContainer->get_f()!=Teuchos::null); |
| 250 |
TEST_EQUALITY(bContainer->get_A(), Teuchos::null) |
| 251 |
|
| 252 |
factory.initializeContainer(LOC::Mat,*bContainer); |
| 253 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 254 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 255 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 256 |
TEST_ASSERT(bContainer->get_A()!=Teuchos::null); |
| 257 |
|
| 258 |
// jacobian and residual vector output |
| 259 |
factory.initializeContainer(LOC::F | LOC::Mat,*bContainer); |
| 260 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 261 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 262 |
TEST_ASSERT(bContainer->get_f()!=Teuchos::null); |
| 263 |
TEST_ASSERT(bContainer->get_A()!=Teuchos::null); |
| 264 |
|
| 265 |
// x and time dertivative input |
| 266 |
factory.initializeContainer(LOC::X | LOC::DxDt,*bContainer); |
| 267 |
TEST_ASSERT(bContainer->get_x()!=Teuchos::null); |
| 268 |
TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); |
| 269 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 270 |
TEST_EQUALITY(bContainer->get_A(), Teuchos::null) |
| 271 |
|
| 272 |
// everything |
| 273 |
factory.initializeContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*bContainer); |
| 274 |
TEST_ASSERT(bContainer->get_x()!=Teuchos::null); |
| 275 |
TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); |
| 276 |
TEST_ASSERT(bContainer->get_f()!=Teuchos::null); |
| 277 |
TEST_ASSERT(bContainer->get_A()!=Teuchos::null); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
TEUCHOS_UNIT_TEST(tBlockedTpetraLinearObjFactory, ghostToGlobal) |
| 282 |
{ |
| 283 |
|
| 284 |
// build global (or serial communicator) |
| 285 |
#ifdef HAVE_MPI |
| 286 |
Teuchos::RCP<Teuchos::MpiComm<int> > comm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 287 |
#else |
| 288 |
NOPE_PANZER_DOESNT_SUPPORT_SERIAL |
| 289 |
#endif |
| 290 |
|
| 291 |
using Teuchos::RCP; |
| 292 |
using Teuchos::rcp; |
| 293 |
using Teuchos::rcp_dynamic_cast; |
| 294 |
using Thyra::ProductVectorBase; |
| 295 |
using Thyra::SpmdVectorBase; |
| 296 |
|
| 297 |
// pauseToAttach(); |
| 298 |
|
| 299 |
int numBlocks = 2; |
| 300 |
int myRank = comm->getRank(); |
| 301 |
int numProc = comm->getSize(); |
| 302 |
|
| 303 |
RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer64(myRank,numProc,numBlocks); |
| 304 |
Teuchos::RCP<BLOFact> la_factory |
| 305 |
= Teuchos::rcp(new BLOFact(comm,blkIndexer)); |
| 306 |
|
| 307 |
Teuchos::RCP<LinearObjContainer> global = la_factory->buildLinearObjContainer(); |
| 308 |
Teuchos::RCP<LinearObjContainer> ghosted = la_factory->buildGhostedLinearObjContainer(); |
| 309 |
|
| 310 |
la_factory->initializeContainer(LinearObjContainer::Mat,*global); |
| 311 |
la_factory->initializeGhostedContainer(LinearObjContainer::Mat,*ghosted); |
| 312 |
|
| 313 |
Teuchos::rcp_dynamic_cast<BLOC>(ghosted)->initializeMatrix(1.0); |
| 314 |
|
| 315 |
la_factory->ghostToGlobalContainer(*ghosted,*global,LinearObjContainer::Mat); |
| 316 |
|
| 317 |
Teuchos::RCP<Thyra::LinearOpBase<double> > th_A = Teuchos::rcp_dynamic_cast<BLOC>(global)->get_A(); |
| 318 |
Teuchos::RCP<Thyra::BlockedLinearOpBase<double> > blk_A = Teuchos::rcp_dynamic_cast<Thyra::BlockedLinearOpBase<double> >(th_A); |
| 319 |
|
| 320 |
Teuchos::RCP<OperatorType> cA_00 = Teuchos::rcp_dynamic_cast<ThyraLinearOp>(blk_A->getNonconstBlock(0,0),true)->getTpetraOperator(); |
| 321 |
Teuchos::RCP<OperatorType> cA_01 = Teuchos::rcp_dynamic_cast<ThyraLinearOp>(blk_A->getNonconstBlock(0,1),true)->getTpetraOperator(); |
| 322 |
Teuchos::RCP<OperatorType> cA_10 = Teuchos::rcp_dynamic_cast<ThyraLinearOp>(blk_A->getNonconstBlock(1,0),true)->getTpetraOperator(); |
| 323 |
Teuchos::RCP<OperatorType> cA_11 = Teuchos::rcp_dynamic_cast<ThyraLinearOp>(blk_A->getNonconstBlock(1,1),true)->getTpetraOperator(); |
| 324 |
|
| 325 |
Teuchos::RCP<CrsMatrixType> A_00 = Teuchos::rcp_dynamic_cast<CrsMatrixType>(cA_00); |
| 326 |
Teuchos::RCP<CrsMatrixType> A_01 = Teuchos::rcp_dynamic_cast<CrsMatrixType>(cA_01); |
| 327 |
|
| 328 |
Teuchos::RCP<CrsMatrixType> A_10 = Teuchos::rcp_dynamic_cast<CrsMatrixType>(cA_10); |
| 329 |
Teuchos::RCP<CrsMatrixType> A_11 = Teuchos::rcp_dynamic_cast<CrsMatrixType>(cA_11); |
| 330 |
|
| 331 |
out << "A_00 = \n"; |
| 332 |
A_00->print(out); |
| 333 |
|
| 334 |
out << "A_01 = \n"; |
| 335 |
A_01->print(out); |
| 336 |
|
| 337 |
out << "A_10 = \n"; |
| 338 |
A_10->print(out); |
| 339 |
|
| 340 |
out << "A_11 = \n"; |
| 341 |
A_11->print(out); |
| 342 |
} |
| 343 |
|
| 344 |
TEUCHOS_UNIT_TEST(tBlockedTpetraLinearObjFactory, graph_constr) |
| 345 |
{ |
| 346 |
|
| 347 |
// build global (or serial communicator) |
| 348 |
#ifdef HAVE_MPI |
| 349 |
Teuchos::RCP<Teuchos::MpiComm<int> > comm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 350 |
#else |
| 351 |
NOPE_PANZER_DOESNT_SUPPORT_SERIAL |
| 352 |
#endif |
| 353 |
|
| 354 |
using Teuchos::RCP; |
| 355 |
using Teuchos::rcp; |
| 356 |
using Teuchos::rcp_dynamic_cast; |
| 357 |
using Thyra::ProductVectorBase; |
| 358 |
using Thyra::SpmdVectorBase; |
| 359 |
|
| 360 |
// pauseToAttach(); |
| 361 |
|
| 362 |
int numBlocks = 2; |
| 363 |
int myRank = comm->getRank(); |
| 364 |
int numProc = comm->getSize(); |
| 365 |
|
| 366 |
RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer64(myRank,numProc,numBlocks); |
| 367 |
Teuchos::RCP<BLOFact> la_factory = Teuchos::rcp(new BLOFact(comm,blkIndexer)); |
| 368 |
|
| 369 |
Teuchos::RCP<CrsMatrixType> A_00 = la_factory->getGhostedTpetraMatrix(0,0); putScalar(1.0,*A_00); |
| 370 |
Teuchos::RCP<CrsMatrixType> A_01 = la_factory->getGhostedTpetraMatrix(0,1); putScalar(1.0,*A_01); |
| 371 |
|
| 372 |
Teuchos::RCP<CrsMatrixType> A_10 = la_factory->getGhostedTpetraMatrix(1,0); putScalar(1.0,*A_10); |
| 373 |
Teuchos::RCP<CrsMatrixType> A_11 = la_factory->getGhostedTpetraMatrix(1,1); putScalar(1.0,*A_11); |
| 374 |
|
| 375 |
out << "A_00 = \n"; |
| 376 |
A_00->print(out); |
| 377 |
|
| 378 |
out << "A_01 = \n"; |
| 379 |
A_01->print(out); |
| 380 |
|
| 381 |
out << "A_10 = \n"; |
| 382 |
A_10->print(out); |
| 383 |
|
| 384 |
out << "A_11 = \n"; |
| 385 |
A_11->print(out); |
| 386 |
} |
| 387 |
|
| 388 |
TEUCHOS_UNIT_TEST(tBlockedTpetraLinearObjFactory, adjustDirichlet) |
| 389 |
{ |
| 390 |
|
| 391 |
// build global (or serial communicator) |
| 392 |
#ifdef HAVE_MPI |
| 393 |
Teuchos::RCP<Teuchos::MpiComm<int> > comm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 394 |
#else |
| 395 |
NOPE_PANZER_DOESNT_SUPPORT_SERIAL |
| 396 |
#endif |
| 397 |
|
| 398 |
using Teuchos::RCP; |
| 399 |
using Teuchos::rcp; |
| 400 |
using Teuchos::rcp_dynamic_cast; |
| 401 |
using Thyra::ProductVectorBase; |
| 402 |
using Thyra::SpmdVectorBase; |
| 403 |
|
| 404 |
// pauseToAttach(); |
| 405 |
|
| 406 |
int numBlocks = 3; |
| 407 |
int myRank = comm->getRank(); |
| 408 |
int numProc = comm->getSize(); |
| 409 |
|
| 410 |
RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer64(myRank,numProc,numBlocks); |
| 411 |
Teuchos::RCP<BLOFact> la_factory |
| 412 |
= Teuchos::rcp(new BLOFact(comm,blkIndexer)); |
| 413 |
|
| 414 |
RCP<LinearObjContainer> ghosted_0 = la_factory->buildGhostedLinearObjContainer(); |
| 415 |
RCP<LinearObjContainer> ghosted_1 = la_factory->buildGhostedLinearObjContainer(); |
| 416 |
RCP<LinearObjContainer> ghosted_sys = la_factory->buildGhostedLinearObjContainer(); |
| 417 |
|
| 418 |
la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_0); |
| 419 |
la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_1); |
| 420 |
la_factory->initializeGhostedContainer(LinearObjContainer::F | LinearObjContainer::Mat,*ghosted_sys); |
| 421 |
|
| 422 |
RCP<BLOC> b_0 = rcp_dynamic_cast<BLOC>(ghosted_0); |
| 423 |
RCP<BLOC> b_1 = rcp_dynamic_cast<BLOC>(ghosted_1); |
| 424 |
RCP<BLOC> b_sys = rcp_dynamic_cast<BLOC>(ghosted_sys); |
| 425 |
|
| 426 |
TEST_ASSERT(!Teuchos::is_null(b_0->get_f())); |
| 427 |
TEST_ASSERT(!Teuchos::is_null(b_1->get_f())); |
| 428 |
TEST_ASSERT(!Teuchos::is_null(b_sys->get_f())); |
| 429 |
TEST_ASSERT(!Teuchos::is_null(b_sys->get_A())); |
| 430 |
|
| 431 |
Thyra::assign(b_0->get_f().ptr(),0.0); // put some garbage in the systems |
| 432 |
Thyra::assign(b_1->get_f().ptr(),0.0); // put some garbage in the systems |
| 433 |
Thyra::assign(b_sys->get_f().ptr(),-3.0); // put some garbage in the systems |
| 434 |
|
| 435 |
// b_sys->get_A()->PutScalar(-3.0); |
| 436 |
for(int i=0;i<numBlocks;i++) { |
| 437 |
for(int j=0;j<numBlocks;j++) { |
| 438 |
RCP<CrsMatrixType> M = getSubBlock_tp(i,j,*b_sys->get_A()); |
| 439 |
M->setAllToScalar(-3.0); |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
// there are 3 cases for adjustDirichlet |
| 444 |
// 1. Local set only for GID |
| 445 |
// 2. Set on multiple processors |
| 446 |
// 3. Set remotely |
| 447 |
|
| 448 |
if(myRank==0) { |
| 449 |
for(int i=0;i<numBlocks;i++) { |
| 450 |
RCP<Thyra::VectorBase<double> > x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(i); |
| 451 |
RCP<Thyra::VectorBase<double> > x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(i); |
| 452 |
|
| 453 |
Teuchos::ArrayRCP<double> data_0,data_1; |
| 454 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); |
| 455 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); |
| 456 |
|
| 457 |
// case 0 |
| 458 |
data_0[0] = 1.0; // GID = 0 |
| 459 |
data_1[0] = 1.0; |
| 460 |
|
| 461 |
// case 1 |
| 462 |
data_0[2] = 1.0; // GID = 2 |
| 463 |
data_1[2] = 2.0; |
| 464 |
|
| 465 |
// case 2 |
| 466 |
data_1[5] = 2.0; // GID = 5 |
| 467 |
} |
| 468 |
} |
| 469 |
else if(myRank==1) { |
| 470 |
for(int i=0;i<numBlocks;i++) { |
| 471 |
RCP<Thyra::VectorBase<double> > x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(i); |
| 472 |
RCP<Thyra::VectorBase<double> > x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(i); |
| 473 |
|
| 474 |
Teuchos::ArrayRCP<double> data_0,data_1; |
| 475 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); |
| 476 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); |
| 477 |
|
| 478 |
// case 0 |
| 479 |
data_0[3] = 1.0; // GID = 9 |
| 480 |
data_1[3] = 1.0; |
| 481 |
|
| 482 |
// case 1 |
| 483 |
data_0[0] = 1.0; // GID =2 |
| 484 |
data_1[0] = 2.0; |
| 485 |
|
| 486 |
// case 2 |
| 487 |
data_1[6] = 2.0; // GID = 4 |
| 488 |
} |
| 489 |
} |
| 490 |
else |
| 491 |
TEUCHOS_ASSERT(false); |
| 492 |
|
| 493 |
out << "LOCAL " << std::endl; |
| 494 |
b_0->get_f()->describe(out,Teuchos::VERB_HIGH); |
| 495 |
out << std::endl; |
| 496 |
out << "GLOBAL " << std::endl; |
| 497 |
b_1->get_f()->describe(out,Teuchos::VERB_HIGH); |
| 498 |
out << std::endl; |
| 499 |
|
| 500 |
// run test for conditions |
| 501 |
la_factory->adjustForDirichletConditions(*ghosted_0,*ghosted_1,*ghosted_sys); |
| 502 |
|
| 503 |
std::size_t sz = 20; |
| 504 |
std::size_t numEntries = 0; |
| 505 |
typename CrsMatrixType::nonconst_local_inds_host_view_type indices("indices", sz); |
| 506 |
typename CrsMatrixType::nonconst_values_host_view_type values("values", sz); |
| 507 |
|
| 508 |
if(myRank==0) { |
| 509 |
RCP<const Thyra::LinearOpBase<double> > A = b_sys->get_A(); |
| 510 |
|
| 511 |
for(int i=0;i<numBlocks;i++) { |
| 512 |
Teuchos::ArrayRCP<const double> data; |
| 513 |
RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i); |
| 514 |
rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data)); |
| 515 |
|
| 516 |
TEST_EQUALITY(data[0],-3.0); // case 0 |
| 517 |
TEST_EQUALITY(data[2],-3.0/2.0); // case 1 |
| 518 |
TEST_EQUALITY(data[5],0.0); // case 2 |
| 519 |
|
| 520 |
for(int j=0;j<numBlocks;j++) { |
| 521 |
RCP<const CrsMatrixType> subA = getSubBlock_tp(i,j,*A); |
| 522 |
|
| 523 |
subA->getLocalRowCopy(0,indices,values,numEntries); |
| 524 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0); |
| 525 |
|
| 526 |
subA->getLocalRowCopy(2,indices,values,numEntries); |
| 527 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0/2.0); |
| 528 |
|
| 529 |
subA->getLocalRowCopy(5,indices,values,numEntries); |
| 530 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0); |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
else if(myRank==1) { |
| 535 |
RCP<const Thyra::LinearOpBase<double> > A = b_sys->get_A(); |
| 536 |
|
| 537 |
for(int i=0;i<numBlocks;i++) { |
| 538 |
Teuchos::ArrayRCP<const double> data; |
| 539 |
RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i); |
| 540 |
rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data)); |
| 541 |
|
| 542 |
TEST_EQUALITY(data[3],-3.0); // case 0 |
| 543 |
TEST_EQUALITY(data[0],-3.0/2.0); // case 1 |
| 544 |
TEST_EQUALITY(data[6],0.0); // case 2 |
| 545 |
|
| 546 |
for(int j=0;j<numBlocks;j++) { |
| 547 |
RCP<const CrsMatrixType> subA = getSubBlock_tp(i,j,*A); |
| 548 |
|
| 549 |
subA->getLocalRowCopy(3,indices,values,numEntries); |
| 550 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0); |
| 551 |
|
| 552 |
subA->getLocalRowCopy(0,indices,values,numEntries); |
| 553 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0/2.0); |
| 554 |
|
| 555 |
subA->getLocalRowCopy(6,indices,values,numEntries); |
| 556 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0); |
| 557 |
} |
| 558 |
} |
| 559 |
} |
| 560 |
else |
| 561 |
TEUCHOS_ASSERT(false); |
| 562 |
} |
| 563 |
|
| 564 |
TEUCHOS_UNIT_TEST(tBlockedTpetraLinearObjFactory, node_cell) |
| 565 |
{ |
| 566 |
|
| 567 |
// build global (or serial communicator) |
| 568 |
#ifdef HAVE_MPI |
| 569 |
Teuchos::RCP<Teuchos::MpiComm<int> > comm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 570 |
#else |
| 571 |
NOPE_PANZER_DOESNT_SUPPORT_SERIAL |
| 572 |
#endif |
| 573 |
|
| 574 |
using Teuchos::RCP; |
| 575 |
using Teuchos::rcp; |
| 576 |
using Teuchos::rcp_dynamic_cast; |
| 577 |
using Thyra::ProductVectorBase; |
| 578 |
using Thyra::SpmdVectorBase; |
| 579 |
|
| 580 |
// pauseToAttach(); |
| 581 |
|
| 582 |
int numBlocks = 2; |
| 583 |
int myRank = comm->getRank(); |
| 584 |
int numProc = comm->getSize(); |
| 585 |
|
| 586 |
RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer64(myRank,numProc,numBlocks); |
| 587 |
Teuchos::RCP<BLOFact> la_factory = Teuchos::rcp(new BLOFact(comm,blkIndexer)); |
| 588 |
|
| 589 |
RCP<LinearObjContainer> ghosted_0 = la_factory->buildGhostedLinearObjContainer(); |
| 590 |
RCP<LinearObjContainer> ghosted_1 = la_factory->buildGhostedLinearObjContainer(); |
| 591 |
RCP<LinearObjContainer> ghosted_sys = la_factory->buildGhostedLinearObjContainer(); |
| 592 |
|
| 593 |
la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_0); |
| 594 |
la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_1); |
| 595 |
la_factory->initializeGhostedContainer(LinearObjContainer::F | LinearObjContainer::Mat,*ghosted_sys); |
| 596 |
|
| 597 |
RCP<BLOC> b_0 = rcp_dynamic_cast<BLOC>(ghosted_0); |
| 598 |
RCP<BLOC> b_1 = rcp_dynamic_cast<BLOC>(ghosted_1); |
| 599 |
RCP<BLOC> b_sys = rcp_dynamic_cast<BLOC>(ghosted_sys); |
| 600 |
|
| 601 |
TEST_ASSERT(!Teuchos::is_null(b_0->get_f())); |
| 602 |
TEST_ASSERT(!Teuchos::is_null(b_1->get_f())); |
| 603 |
TEST_ASSERT(!Teuchos::is_null(b_sys->get_f())); |
| 604 |
TEST_ASSERT(!Teuchos::is_null(b_sys->get_A())); |
| 605 |
|
| 606 |
Thyra::assign(b_0->get_f().ptr(),0.0); // put some garbage in the systems |
| 607 |
Thyra::assign(b_1->get_f().ptr(),0.0); // put some garbage in the systems |
| 608 |
Thyra::assign(b_sys->get_f().ptr(),-3.0); // put some garbage in the systems |
| 609 |
|
| 610 |
for(int i=0;i<numBlocks;i++) |
| 611 |
for(int j=0;j<numBlocks;j++) |
| 612 |
putScalar(-3.0,*getSubBlock_tp(i,j,*b_sys->get_A())); |
| 613 |
|
| 614 |
// there are 3 cases for adjustDirichlet |
| 615 |
// 1. Local set only for GID |
| 616 |
// 2. Set on multiple processors |
| 617 |
// 3. Set remotely |
| 618 |
|
| 619 |
if(myRank==0) { |
| 620 |
RCP<Thyra::VectorBase<double> > x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(0); |
| 621 |
RCP<Thyra::VectorBase<double> > x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(0); |
| 622 |
|
| 623 |
Teuchos::ArrayRCP<double> data_0,data_1; |
| 624 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); |
| 625 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); |
| 626 |
|
| 627 |
// case 0 |
| 628 |
data_0[0] = 1.0; // GID = 0 |
| 629 |
data_1[0] = 1.0; |
| 630 |
|
| 631 |
// case 1 |
| 632 |
data_0[2] = 1.0; // GID = 2 |
| 633 |
data_1[2] = 2.0; |
| 634 |
|
| 635 |
// case 2 |
| 636 |
data_1[5] = 2.0; // GID = 5 |
| 637 |
|
| 638 |
{ |
| 639 |
x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(1); |
| 640 |
x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(1); |
| 641 |
|
| 642 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); |
| 643 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); |
| 644 |
|
| 645 |
data_1[0] = 2.0; |
| 646 |
} |
| 647 |
} |
| 648 |
else if(myRank==1) { |
| 649 |
RCP<Thyra::VectorBase<double> > x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(0); |
| 650 |
RCP<Thyra::VectorBase<double> > x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(0); |
| 651 |
|
| 652 |
Teuchos::ArrayRCP<double> data_0,data_1; |
| 653 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); |
| 654 |
rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); |
| 655 |
|
| 656 |
// case 0 |
| 657 |
data_0[3] = 1.0; // GID = 9 |
| 658 |
data_1[3] = 1.0; |
| 659 |
|
| 660 |
// case 1 |
| 661 |
data_0[0] = 1.0; // GID =2 |
| 662 |
data_1[0] = 2.0; |
| 663 |
|
| 664 |
// case 2 |
| 665 |
data_1[6] = 2.0; // GID = 4 |
| 666 |
} |
| 667 |
else |
| 668 |
TEUCHOS_ASSERT(false); |
| 669 |
|
| 670 |
out << "LOCAL " << std::endl; |
| 671 |
b_0->get_f()->describe(out,Teuchos::VERB_HIGH); |
| 672 |
out << std::endl; |
| 673 |
out << "GLOBAL " << std::endl; |
| 674 |
b_1->get_f()->describe(out,Teuchos::VERB_HIGH); |
| 675 |
out << std::endl; |
| 676 |
|
| 677 |
// run test for conditions |
| 678 |
la_factory->adjustForDirichletConditions(*ghosted_0,*ghosted_1,*ghosted_sys); |
| 679 |
|
| 680 |
std::size_t sz = 20; |
| 681 |
std::size_t numEntries = 0; |
| 682 |
typename CrsMatrixType::nonconst_local_inds_host_view_type indices("indices", sz); |
| 683 |
typename CrsMatrixType::nonconst_values_host_view_type values("values", sz); |
| 684 |
|
| 685 |
if(myRank==0) { |
| 686 |
RCP<const Thyra::LinearOpBase<double> > A = b_sys->get_A(); |
| 687 |
|
| 688 |
int i = 0; |
| 689 |
{ |
| 690 |
Teuchos::ArrayRCP<const double> data; |
| 691 |
RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i); |
| 692 |
rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data)); |
| 693 |
|
| 694 |
TEST_EQUALITY(data[0],-3.0); // case 0 |
| 695 |
TEST_EQUALITY(data[2],-3.0/2.0); // case 1 |
| 696 |
TEST_EQUALITY(data[5],0.0); // case 2 |
| 697 |
|
| 698 |
for(int j=0;j<numBlocks;j++) { |
| 699 |
RCP<const CrsMatrixType> subA = getSubBlock_tp(i,j,*A); |
| 700 |
|
| 701 |
subA->getLocalRowCopy(0,indices,values,numEntries); |
| 702 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0); |
| 703 |
|
| 704 |
subA->getLocalRowCopy(2,indices,values,numEntries); |
| 705 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0/2.0); |
| 706 |
|
| 707 |
subA->getLocalRowCopy(5,indices,values,numEntries); |
| 708 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0); |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
i = 1; |
| 713 |
{ |
| 714 |
Teuchos::ArrayRCP<const double> data; |
| 715 |
RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i); |
| 716 |
rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data)); |
| 717 |
|
| 718 |
TEST_EQUALITY(data[0],0.0); |
| 719 |
|
| 720 |
for(int j=0;j<numBlocks;j++) { |
| 721 |
RCP<const CrsMatrixType> subA = getSubBlock_tp(i,j,*A); |
| 722 |
|
| 723 |
subA->getLocalRowCopy(0,indices,values,numEntries); |
| 724 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0); |
| 725 |
} |
| 726 |
} |
| 727 |
} |
| 728 |
else if(myRank==1) { |
| 729 |
RCP<const Thyra::LinearOpBase<double> > A = b_sys->get_A(); |
| 730 |
|
| 731 |
int i = 0; |
| 732 |
{ |
| 733 |
Teuchos::ArrayRCP<const double> data; |
| 734 |
RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i); |
| 735 |
rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data)); |
| 736 |
|
| 737 |
TEST_EQUALITY(data[3],-3.0); // case 0 |
| 738 |
TEST_EQUALITY(data[0],-3.0/2.0); // case 1 |
| 739 |
TEST_EQUALITY(data[6],0.0); // case 2 |
| 740 |
|
| 741 |
for(int j=0;j<numBlocks;j++) { |
| 742 |
RCP<const CrsMatrixType> subA = getSubBlock_tp(i,j,*A); |
| 743 |
|
| 744 |
subA->getLocalRowCopy(3,indices,values,numEntries); |
| 745 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0); |
| 746 |
|
| 747 |
subA->getLocalRowCopy(0,indices,values,numEntries); |
| 748 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0/2.0); |
| 749 |
|
| 750 |
subA->getLocalRowCopy(6,indices,values,numEntries); |
| 751 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0); |
| 752 |
} |
| 753 |
} |
| 754 |
|
| 755 |
i = 1; |
| 756 |
{ |
| 757 |
Teuchos::ArrayRCP<const double> data; |
| 758 |
RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i); |
| 759 |
rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data)); |
| 760 |
|
| 761 |
TEST_EQUALITY(data[0],-3.0); |
| 762 |
|
| 763 |
for(int j=0;j<numBlocks;j++) { |
| 764 |
RCP<const CrsMatrixType> subA = getSubBlock_tp(i,j,*A); |
| 765 |
|
| 766 |
subA->getLocalRowCopy(0,indices,values,numEntries); |
| 767 |
for(std::size_t k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0); |
| 768 |
} |
| 769 |
} |
| 770 |
} |
| 771 |
else |
| 772 |
TEUCHOS_ASSERT(false); |
| 773 |
} |
| 774 |
|
| 775 |
TEUCHOS_UNIT_TEST(tBlockedTpetraLinearObjFactory, exclusion) |
| 776 |
{ |
| 777 |
|
| 778 |
// build global (or serial communicator) |
| 779 |
#ifdef HAVE_MPI |
| 780 |
Teuchos::RCP<Teuchos::MpiComm<int> > comm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); |
| 781 |
#else |
| 782 |
NOPE_PANZER_DOESNT_SUPPORT_SERIAL |
| 783 |
#endif |
| 784 |
|
| 785 |
using Teuchos::RCP; |
| 786 |
using Teuchos::rcp; |
| 787 |
using Teuchos::rcp_dynamic_cast; |
| 788 |
|
| 789 |
// pauseToAttach(); |
| 790 |
|
| 791 |
int numBlocks = 3; |
| 792 |
int myRank = comm->getRank(); |
| 793 |
int numProc = comm->getSize(); |
| 794 |
|
| 795 |
RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer64(myRank,numProc,numBlocks); |
| 796 |
BLOFact factory(comm,blkIndexer); |
| 797 |
|
| 798 |
// exclude some pairs |
| 799 |
std::vector<std::pair<int,int> > exPairs; |
| 800 |
exPairs.push_back(std::make_pair(0,2)); |
| 801 |
exPairs.push_back(std::make_pair(2,1)); |
| 802 |
factory.addExcludedPairs(exPairs); |
| 803 |
factory.addExcludedPair(1,2); |
| 804 |
|
| 805 |
RCP<LinearObjContainer> container = factory.buildLinearObjContainer(); |
| 806 |
RCP<LinearObjContainer> ghosted = factory.buildGhostedLinearObjContainer(); |
| 807 |
TEST_ASSERT(container!=Teuchos::null); |
| 808 |
TEST_ASSERT(ghosted!=Teuchos::null); |
| 809 |
|
| 810 |
RCP<BLOC> bContainer = rcp_dynamic_cast<BLOC>(container); |
| 811 |
RCP<BLOC> b_ghosted = rcp_dynamic_cast<BLOC>(ghosted); |
| 812 |
TEST_ASSERT(bContainer!=Teuchos::null); |
| 813 |
TEST_ASSERT(b_ghosted!=Teuchos::null); |
| 814 |
|
| 815 |
// tests global initialize |
| 816 |
{ |
| 817 |
// Generic code |
| 818 |
///////////////////////////////////////////////////////////// |
| 819 |
factory.initializeContainer(LinearObjContainer::Mat,*container); |
| 820 |
TEST_EQUALITY(bContainer->get_x(), Teuchos::null) |
| 821 |
TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) |
| 822 |
TEST_EQUALITY(bContainer->get_f(), Teuchos::null) |
| 823 |
TEST_ASSERT(bContainer->get_A()!=Teuchos::null); |
| 824 |
|
| 825 |
RCP<Thyra::BlockedLinearOpBase<double> > blo |
| 826 |
= rcp_dynamic_cast<Thyra::BlockedLinearOpBase<double> >(bContainer->get_A()); |
| 827 |
|
| 828 |
TEST_ASSERT(!blo->getNonconstBlock(0,0).is_null()); |
| 829 |
TEST_ASSERT(!blo->getNonconstBlock(0,1).is_null()); |
| 830 |
TEST_ASSERT(blo->getNonconstBlock(0,2).is_null()); |
| 831 |
|
| 832 |
TEST_ASSERT(!blo->getNonconstBlock(1,0).is_null()); |
| 833 |
TEST_ASSERT(!blo->getNonconstBlock(1,1).is_null()); |
| 834 |
TEST_ASSERT(blo->getNonconstBlock(1,2).is_null()); |
| 835 |
|
| 836 |
TEST_ASSERT(!blo->getNonconstBlock(2,0).is_null()); |
| 837 |
TEST_ASSERT(blo->getNonconstBlock(2,1).is_null()); |
| 838 |
TEST_ASSERT(!blo->getNonconstBlock(2,2).is_null()); |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
} |