// @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 #include #include #include #include #include #include #include "Panzer_Traits.hpp" // for testing gather/scatter construction #include "Panzer_PureBasis.hpp" #include "Panzer_IntegrationRule.hpp" #include "Panzer_EpetraLinearObjContainer.hpp" #include "Panzer_BlockedEpetraLinearObjContainer.hpp" #include "Panzer_BlockedEpetraLinearObjFactory.hpp" #include "Panzer_PauseToAttach.hpp" #include "Panzer_IntrepidFieldPattern.hpp" #include "UnitTest_GlobalIndexer.hpp" #include "Thyra_EpetraThyraWrappers.hpp" #include "Thyra_ProductVectorBase.hpp" #include "Thyra_BlockedLinearOpBase.hpp" #include "Thyra_SpmdVectorBase.hpp" #include "Thyra_get_Epetra_Operator.hpp" #include "Thyra_VectorStdOps.hpp" #include "Epetra_Comm.h" #ifdef HAVE_MPI #include "Epetra_MpiComm.h" #else #include "Epetra_SerialComm.h" #endif #include "Epetra_Operator.h" #include "Epetra_CrsMatrix.h" #include "UnitTest_ConnManager.hpp" using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; using Teuchos::RCP; using Teuchos::rcpFromRef; namespace panzer { Teuchos::RCP getSubBlock(int i,int j,Thyra::LinearOpBase & lo) { Thyra::BlockedLinearOpBase & blo = Teuchos::dyn_cast >(lo); Teuchos::RCP e_blo = Thyra::get_Epetra_Operator(*blo.getNonconstBlock(i,j)); return rcp_dynamic_cast(e_blo); } Teuchos::RCP getSubBlock(int i,int j,const Thyra::LinearOpBase & lo) { const Thyra::BlockedLinearOpBase & blo = Teuchos::dyn_cast >(lo); Teuchos::RCP e_blo = Thyra::get_Epetra_Operator(*blo.getBlock(i,j)); return rcp_dynamic_cast(e_blo); } template Teuchos::RCP buildFieldPattern() { using Teuchos::RCP; using Teuchos::rcp; // build a geometric pattern from a single basis RCP > basis = rcp(new Intrepid2Type); RCP pattern = rcp(new panzer::Intrepid2FieldPattern(basis)); return pattern; } Teuchos::RCP buildBlockedIndexer(int myRank,int numProc,int numBlocks) { std::string names[] = {"U","V","W","X"}; Teuchos::RCP patternC1 = buildFieldPattern >(); Teuchos::RCP connManager = rcp(new unit_test::ConnManager(myRank,numProc)); Teuchos::RCP indexer = rcp(new panzer::BlockedDOFManager()); indexer->setConnManager(connManager,MPI_COMM_WORLD); std::vector > fieldOrder(numBlocks); for(int i=0;iaddField(names[i],patternC1); fieldOrder[i].push_back(names[i]); } indexer->setFieldOrder(fieldOrder); indexer->buildGlobalUnknowns(); return indexer; } RCP getEpetraMultiVector(RCP > & vec,const Epetra_Map & eMap) { return Thyra::get_Epetra_MultiVector(eMap,vec); } TEUCHOS_UNIT_TEST(tEpetraLinearObjFactory, gather_scatter_constr) { // build global (or serial communicator) #ifdef HAVE_MPI Teuchos::RCP eComm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD)); #else Teuchos::RCP eComm = Teuchos::rcp(new Epetra_SerialComm()); #endif Teuchos::RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; int myRank = eComm->MyPID(); int numProc = eComm->NumProc(); RCP indexer = rcp(new panzer::unit_test::GlobalIndexer(myRank,numProc)); // setup factory Teuchos::RCP > la_factory = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory(tComm.getConst(),indexer)); // build parameter lists for gather and scatters ////////////////////////////////////////////////////////////////// std::size_t numCells = 10; Teuchos::ParameterList gatherParams; { Teuchos::RCP topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); // auxiliary information needed to construct basis object std::string basisType = "Q1"; panzer::CellData cellData(numCells,topo); // build DOF names RCP > dofNames = rcp(new std::vector); dofNames->push_back("ux"); // in practice these probably would not be gathered together! dofNames->push_back("p"); // build basis RCP basis = rcp(new panzer::PureBasis(basisType,1,cellData)); // build gather parameter list gatherParams.set > >("DOF Names",dofNames); gatherParams.set > >("Indexer Names",dofNames); gatherParams.set >("Basis",basis); } Teuchos::ParameterList scatterParams; { Teuchos::RCP topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); std::string basisType = "Q1"; panzer::CellData cellData(numCells,topo); // build basis RCP basis = rcp(new panzer::PureBasis(basisType,1,cellData)); std::string scatterName = "Residual_NS"; // build DOF names RCP > evaluatedNames = rcp(new std::vector); evaluatedNames->push_back("Residual_ux"); // in practice these probably would not be scattered together! evaluatedNames->push_back("Residual_p"); // build evaluated map RCP > evaluatedMap = rcp(new std::map); evaluatedMap->insert(std::make_pair("Residual_ux","ux")); // in practice these probably would not be scattered together! evaluatedMap->insert(std::make_pair("Residual_p","p")); // build scatter parameter list scatterParams.set("Scatter Name",scatterName); scatterParams.set > >("Dependent Names",evaluatedNames); scatterParams.set > >("Dependent Map",evaluatedMap); scatterParams.set("Basis",basis); } Teuchos::ParameterList scatterDirichletParams; { Teuchos::RCP topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >())); std::string basisType = "Q1"; panzer::CellData cellData(numCells,topo); // build basis RCP basis = rcp(new panzer::PureBasis(basisType,1,cellData)); std::string scatterName = "Residual_NS"; // build DOF names RCP > evaluatedNames = rcp(new std::vector); evaluatedNames->push_back("Residual_ux"); // in practice these probably would not be scattered together! evaluatedNames->push_back("Residual_p"); // build evaluated map RCP > evaluatedMap = rcp(new std::map); evaluatedMap->insert(std::make_pair("Residual_ux","ux")); // in practice these probably would not be scattered together! evaluatedMap->insert(std::make_pair("Residual_p","p")); // build scatter parameter list scatterDirichletParams.set("Scatter Name",scatterName); scatterDirichletParams.set > >("Dependent Names",evaluatedNames); scatterDirichletParams.set > >("Dependent Map",evaluatedMap); scatterDirichletParams.set >("Basis",basis); scatterDirichletParams.set("Side Subcell Dimension",1); scatterDirichletParams.set("Local Side ID",2); scatterDirichletParams.set("Check Apply BC",false); } // Evaluator construction tests /////////////////////////////////////////////////////// RCP > evaluator; { typedef panzer::Traits::Residual EvalType; // gather test { evaluator = la_factory->buildGather(gatherParams); TEST_ASSERT(evaluator!=Teuchos::null); RCP > gatherSolutionEval = rcp_dynamic_cast >(evaluator); TEST_ASSERT(gatherSolutionEval!=Teuchos::null); const std::vector > & fields = gatherSolutionEval->evaluatedFields(); TEST_EQUALITY(fields.size(),2); TEST_EQUALITY(fields[0]->name(),"ux"); TEST_EQUALITY(fields[1]->name(),"p"); TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 } // scatter test { evaluator = la_factory->buildScatter(scatterParams); out << "SCATTER RES NAME: \"" << evaluator->getName() << "\"" << std::endl; TEST_ASSERT(evaluator!=Teuchos::null); RCP > scatterResidual = rcp_dynamic_cast >(evaluator); TEST_ASSERT(scatterResidual!=Teuchos::null); const std::vector > & evalFields = scatterResidual->evaluatedFields(); TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager const std::vector > & fields = scatterResidual->dependentFields(); TEST_EQUALITY(fields.size(),2); // these store the residual values TEST_EQUALITY(fields[0]->name(),"Residual_ux"); TEST_EQUALITY(fields[1]->name(),"Residual_p"); TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 } // scatter dirichlet test { evaluator = la_factory->buildScatterDirichlet(scatterDirichletParams); out << "SCATTER DIRICHLET RES NAME: \"" << evaluator->getName() << "\"" << std::endl; TEST_ASSERT(evaluator!=Teuchos::null); RCP > scatterResidual = rcp_dynamic_cast >(evaluator); TEST_ASSERT(scatterResidual!=Teuchos::null); const std::vector > & evalFields = scatterResidual->evaluatedFields(); TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager const std::vector > & fields = scatterResidual->dependentFields(); TEST_EQUALITY(fields.size(),2); // these store the residual values TEST_EQUALITY(fields[0]->name(),"Residual_ux"); TEST_EQUALITY(fields[1]->name(),"Residual_p"); TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 } } { typedef panzer::Traits::Jacobian EvalType; // gather test { evaluator = la_factory->buildGather(gatherParams); TEST_ASSERT(evaluator!=Teuchos::null); RCP > gatherSolutionEval = rcp_dynamic_cast >(evaluator); TEST_ASSERT(gatherSolutionEval!=Teuchos::null); const std::vector > & fields = gatherSolutionEval->evaluatedFields(); TEST_EQUALITY(fields.size(),2); TEST_EQUALITY(fields[0]->name(),"ux"); TEST_EQUALITY(fields[1]->name(),"p"); TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 } // scatter test { evaluator = la_factory->buildScatter(scatterParams); TEST_ASSERT(evaluator!=Teuchos::null); RCP > scatterResidual = rcp_dynamic_cast >(evaluator); TEST_ASSERT(scatterResidual!=Teuchos::null); const std::vector > & evalFields = scatterResidual->evaluatedFields(); TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager const std::vector > & fields = scatterResidual->dependentFields(); TEST_EQUALITY(fields.size(),2); // these store the residual values TEST_EQUALITY(fields[0]->name(),"Residual_ux"); TEST_EQUALITY(fields[1]->name(),"Residual_p"); TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 } // scatter dirichlet test { evaluator = la_factory->buildScatterDirichlet(scatterDirichletParams); out << "SCATTER DIRICHLET RES NAME: \"" << evaluator->getName() << "\"" << std::endl; TEST_ASSERT(evaluator!=Teuchos::null); RCP > scatterResidual = rcp_dynamic_cast >(evaluator); TEST_ASSERT(scatterResidual!=Teuchos::null); const std::vector > & evalFields = scatterResidual->evaluatedFields(); TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager const std::vector > & fields = scatterResidual->dependentFields(); TEST_EQUALITY(fields.size(),2); // these store the residual values TEST_EQUALITY(fields[0]->name(),"Residual_ux"); TEST_EQUALITY(fields[1]->name(),"Residual_p"); TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as(numCells)); TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as(4)); // for Q1 } } } TEUCHOS_UNIT_TEST(tEpetraLinearObjFactory, initializeContainer) { // build global (or serial communicator) #ifdef HAVE_MPI Teuchos::RCP eComm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD)); #else Teuchos::RCP eComm = Teuchos::rcp(new Epetra_SerialComm()); #endif using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; Teuchos::RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); int myRank = eComm->MyPID(); int numProc = eComm->NumProc(); typedef EpetraLinearObjContainer ELOC; RCP indexer = rcp(new unit_test::GlobalIndexer(myRank,numProc)); std::vector ownedIndices, ownedAndGhostedIndices; indexer->getOwnedIndices(ownedIndices); indexer->getOwnedAndGhostedIndices(ownedAndGhostedIndices); // setup factory Teuchos::RCP > la_factory = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory(tComm.getConst(),indexer)); RCP container = la_factory->buildLinearObjContainer(); RCP ghostedContainer = la_factory->buildGhostedLinearObjContainer(); RCP eContainer = rcp_dynamic_cast(container); RCP eGhostedContainer = rcp_dynamic_cast(ghostedContainer); // tests ghosted initialize { // Generic code ///////////////////////////////////////////////////////////// // test individial initializers la_factory->initializeGhostedContainer(ELOC::X,*ghostedContainer); TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_x()->MyLength(),(int) ownedAndGhostedIndices.size()); la_factory->initializeGhostedContainer(ELOC::DxDt,*ghostedContainer); TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null) TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_dxdt()->MyLength(),(int) ownedAndGhostedIndices.size()); la_factory->initializeGhostedContainer(ELOC::F,*ghostedContainer); TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null) TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_f()->MyLength(),(int) ownedAndGhostedIndices.size()); la_factory->initializeGhostedContainer(ELOC::Mat,*ghostedContainer); TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null) TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_A()->NumMyRows(),(int) ownedAndGhostedIndices.size()); // jacobian and residual vector output la_factory->initializeGhostedContainer(ELOC::F | ELOC::Mat,*ghostedContainer); TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null) TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null); // x and time dertivative input la_factory->initializeGhostedContainer(ELOC::X | ELOC::DxDt,*ghostedContainer); TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null) // everything la_factory->initializeGhostedContainer(ELOC::X | ELOC::DxDt | ELOC::F | ELOC::Mat,*ghostedContainer); TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null); // Epetra specific code ///////////////////////////////////////////////////////////// // test individial initializers la_factory->initializeGhostedContainer(ELOC::X,*eGhostedContainer); TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null) la_factory->initializeGhostedContainer(ELOC::DxDt,*eGhostedContainer); TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null) TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null) la_factory->initializeGhostedContainer(ELOC::F,*eGhostedContainer); TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null) TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null) la_factory->initializeGhostedContainer(ELOC::Mat,*eGhostedContainer); TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null) TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null); // jacobian and residual vector output la_factory->initializeGhostedContainer(ELOC::F | ELOC::Mat,*eGhostedContainer); TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null) TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null); // x and time dertivative input la_factory->initializeGhostedContainer(ELOC::X | ELOC::DxDt,*eGhostedContainer); TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null); TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null) TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null) // everything la_factory->initializeGhostedContainer(ELOC::X | ELOC::DxDt | ELOC::F | ELOC::Mat,*eGhostedContainer); TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null); TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null); } } TEUCHOS_UNIT_TEST(tBlockedLinearObjFactory, intializeContainer_epetra) { panzer::BlockedEpetraLinearObjContainer container; TEST_ASSERT(container.checkCompatibility()); } TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, epetra_factory_tests) { #ifdef HAVE_MPI Teuchos::RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); #else NOPE_PANZER_DOESNT_SUPPORT_SERIAL #endif using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; // pauseToAttach(); typedef LinearObjContainer LOC; typedef BlockedEpetraLinearObjContainer BLOC; int numBlocks = 3; int myRank = tComm->getRank(); int numProc = tComm->getSize(); RCP blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks); BlockedEpetraLinearObjFactory factory(tComm,blkIndexer); RCP container = factory.buildLinearObjContainer(); RCP ghosted = factory.buildGhostedLinearObjContainer(); TEST_ASSERT(container!=Teuchos::null); TEST_ASSERT(ghosted!=Teuchos::null); RCP bContainer = rcp_dynamic_cast(container); RCP b_ghosted = rcp_dynamic_cast(ghosted); TEST_ASSERT(bContainer!=Teuchos::null); TEST_ASSERT(b_ghosted!=Teuchos::null); // tests global initialize { // Generic code ///////////////////////////////////////////////////////////// // test individial initializers factory.initializeContainer(LOC::X,*container); TEST_ASSERT(bContainer->get_x()!=Teuchos::null); TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_EQUALITY(bContainer->get_A(), Teuchos::null) factory.initializeContainer(LOC::DxDt,*container); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_EQUALITY(bContainer->get_A(), Teuchos::null) factory.initializeContainer(LOC::F,*container); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_ASSERT(bContainer->get_f()!=Teuchos::null); TEST_EQUALITY(bContainer->get_A(), Teuchos::null) factory.initializeContainer(LOC::Mat,*container); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_ASSERT(bContainer->get_A()!=Teuchos::null); // jacobian and residual vector output factory.initializeContainer(LOC::F | LOC::Mat,*container); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_ASSERT(bContainer->get_f()!=Teuchos::null); TEST_ASSERT(bContainer->get_A()!=Teuchos::null); // x and time dertivative input factory.initializeContainer(LOC::X | LOC::DxDt,*container); TEST_ASSERT(bContainer->get_x()!=Teuchos::null); TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_EQUALITY(bContainer->get_A(), Teuchos::null) // everything factory.initializeContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*container); TEST_ASSERT(bContainer->get_x()!=Teuchos::null); TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); TEST_ASSERT(bContainer->get_f()!=Teuchos::null); TEST_ASSERT(bContainer->get_A()!=Teuchos::null); // Epetra specific code ///////////////////////////////////////////////////////////// // test individial initializers factory.initializeContainer(LOC::X,*bContainer); TEST_ASSERT(bContainer->get_x()!=Teuchos::null); TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_EQUALITY(bContainer->get_A(), Teuchos::null) factory.initializeContainer(LOC::DxDt,*bContainer); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_EQUALITY(bContainer->get_A(), Teuchos::null) factory.initializeContainer(LOC::F,*bContainer); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_ASSERT(bContainer->get_f()!=Teuchos::null); TEST_EQUALITY(bContainer->get_A(), Teuchos::null) factory.initializeContainer(LOC::Mat,*bContainer); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_ASSERT(bContainer->get_A()!=Teuchos::null); // jacobian and residual vector output factory.initializeContainer(LOC::F | LOC::Mat,*bContainer); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_ASSERT(bContainer->get_f()!=Teuchos::null); TEST_ASSERT(bContainer->get_A()!=Teuchos::null); // x and time dertivative input factory.initializeContainer(LOC::X | LOC::DxDt,*bContainer); TEST_ASSERT(bContainer->get_x()!=Teuchos::null); TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_EQUALITY(bContainer->get_A(), Teuchos::null) // everything factory.initializeContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*bContainer); TEST_ASSERT(bContainer->get_x()!=Teuchos::null); TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null); TEST_ASSERT(bContainer->get_f()!=Teuchos::null); TEST_ASSERT(bContainer->get_A()!=Teuchos::null); } } TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, ghostToGlobal) { // build global (or serial communicator) #ifdef HAVE_MPI Teuchos::RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); #else NOPE_PANZER_DOESNT_SUPPORT_SERIAL #endif using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; using Thyra::ProductVectorBase; using Thyra::SpmdVectorBase; // pauseToAttach(); int numBlocks = 2; int myRank = tComm->getRank(); int numProc = tComm->getSize(); RCP blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks); out << "Built indexer = " << blkIndexer << std::endl; Teuchos::RCP > la_factory = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory(tComm,blkIndexer)); out << "LA Factory = " << la_factory << std::endl; Teuchos::RCP global = la_factory->buildLinearObjContainer(); Teuchos::RCP ghosted = la_factory->buildGhostedLinearObjContainer(); out << "LOC = " << global << " " << ghosted << std::endl; la_factory->initializeContainer(LinearObjContainer::Mat,*global); la_factory->initializeGhostedContainer(LinearObjContainer::Mat,*ghosted); out << "Initialized matrices" << std::endl; Teuchos::rcp_dynamic_cast(ghosted)->initializeMatrix(1.0); out << "Initialize matrix" << std::endl; la_factory->ghostToGlobalContainer(*ghosted,*global,LinearObjContainer::Mat); out << "GhostToGlobal" << std::endl; Teuchos::RCP > th_A = Teuchos::rcp_dynamic_cast(global)->get_A(); Teuchos::RCP > blk_A = Teuchos::rcp_dynamic_cast >(th_A); out << "Blk A " << blk_A << std::endl; out << "Blk A " << Teuchos::describe(*blk_A,Teuchos::VERB_MEDIUM) << std::endl; Teuchos::RCP cA_00 = Thyra::get_Epetra_Operator(*blk_A->getNonconstBlock(0,0)); out << "00" << std::endl; Teuchos::RCP cA_01 = Thyra::get_Epetra_Operator(*blk_A->getNonconstBlock(0,1)); out << "01" << std::endl; Teuchos::RCP cA_10 = Thyra::get_Epetra_Operator(*blk_A->getNonconstBlock(1,0)); out << "10" << std::endl; Teuchos::RCP cA_11 = Thyra::get_Epetra_Operator(*blk_A->getNonconstBlock(1,1)); out << "11" << std::endl; Teuchos::RCP A_00 = Teuchos::rcp_dynamic_cast(cA_00); Teuchos::RCP A_01 = Teuchos::rcp_dynamic_cast(cA_01); Teuchos::RCP A_10 = Teuchos::rcp_dynamic_cast(cA_10); Teuchos::RCP A_11 = Teuchos::rcp_dynamic_cast(cA_11); out << "A_00 = \n"; A_00->Print(out); out << "A_01 = \n"; A_01->Print(out); out << "A_10 = \n"; A_10->Print(out); out << "A_11 = \n"; A_11->Print(out); } TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, graph_constr) { // build global (or serial communicator) #ifdef HAVE_MPI Teuchos::RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); #else NOPE_PANZER_DOESNT_SUPPORT_SERIAL #endif using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; using Thyra::ProductVectorBase; using Thyra::SpmdVectorBase; // pauseToAttach(); int numBlocks = 2; int myRank = tComm->getRank(); int numProc = tComm->getSize(); RCP blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks); Teuchos::RCP > la_factory = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory(tComm,blkIndexer)); Teuchos::RCP A_00 = la_factory->getGhostedEpetraMatrix(0,0); A_00->PutScalar(1.0); Teuchos::RCP A_01 = la_factory->getGhostedEpetraMatrix(0,1); A_01->PutScalar(1.0); Teuchos::RCP A_10 = la_factory->getGhostedEpetraMatrix(1,0); A_10->PutScalar(1.0); Teuchos::RCP A_11 = la_factory->getGhostedEpetraMatrix(1,1); A_11->PutScalar(1.0); std::cout << "A_00 = \n"; A_00->Print(out); std::cout << "A_01 = \n"; A_01->Print(out); std::cout << "A_10 = \n"; A_10->Print(out); std::cout << "A_11 = \n"; A_11->Print(out); } TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, adjustDirichlet) { // build global (or serial communicator) #ifdef HAVE_MPI Teuchos::RCP > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); #else NOPE_PANZER_DOESNT_SUPPORT_SERIAL #endif using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; using Thyra::ProductVectorBase; using Thyra::SpmdVectorBase; // pauseToAttach(); int numBlocks = 3; int myRank = tComm->getRank(); int numProc = tComm->getSize(); typedef BlockedEpetraLinearObjContainer BLOC; RCP blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks); Teuchos::RCP > la_factory = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory(tComm,blkIndexer)); RCP ghosted_0 = la_factory->buildGhostedLinearObjContainer(); RCP ghosted_1 = la_factory->buildGhostedLinearObjContainer(); RCP ghosted_sys = la_factory->buildGhostedLinearObjContainer(); la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_0); la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_1); la_factory->initializeGhostedContainer(LinearObjContainer::F | LinearObjContainer::Mat,*ghosted_sys); RCP b_0 = rcp_dynamic_cast(ghosted_0); RCP b_1 = rcp_dynamic_cast(ghosted_1); RCP b_sys = rcp_dynamic_cast(ghosted_sys); TEST_ASSERT(!Teuchos::is_null(b_0->get_f())); TEST_ASSERT(!Teuchos::is_null(b_1->get_f())); TEST_ASSERT(!Teuchos::is_null(b_sys->get_f())); TEST_ASSERT(!Teuchos::is_null(b_sys->get_A())); Thyra::assign(b_0->get_f().ptr(),0.0); // put some garbage in the systems Thyra::assign(b_1->get_f().ptr(),0.0); // put some garbage in the systems Thyra::assign(b_sys->get_f().ptr(),-3.0); // put some garbage in the systems // b_sys->get_A()->PutScalar(-3.0); for(int i=0;iget_A())->PutScalar(-3.0); // there are 3 cases for adjustDirichlet // 1. Local set only for GID // 2. Set on multiple processors // 3. Set remotely if(myRank==0) { for(int i=0;i > x_0 = rcp_dynamic_cast >(b_0->get_f())->getNonconstVectorBlock(i); RCP > x_1 = rcp_dynamic_cast >(b_1->get_f())->getNonconstVectorBlock(i); Teuchos::ArrayRCP data_0,data_1; rcp_dynamic_cast >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); rcp_dynamic_cast >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); // case 0 data_0[0] = 1.0; // GID = 0 data_1[0] = 1.0; // case 1 data_0[2] = 1.0; // GID = 2 data_1[2] = 2.0; // case 2 data_1[5] = 2.0; // GID = 5 } } else if(myRank==1) { for(int i=0;i > x_0 = rcp_dynamic_cast >(b_0->get_f())->getNonconstVectorBlock(i); RCP > x_1 = rcp_dynamic_cast >(b_1->get_f())->getNonconstVectorBlock(i); Teuchos::ArrayRCP data_0,data_1; rcp_dynamic_cast >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); rcp_dynamic_cast >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); // case 0 data_0[3] = 1.0; // GID = 9 data_1[3] = 1.0; // case 1 data_0[0] = 1.0; // GID =2 data_1[0] = 2.0; // case 2 data_1[6] = 2.0; // GID = 4 } } else TEUCHOS_ASSERT(false); out << "LOCAL " << std::endl; b_0->get_f()->describe(out,Teuchos::VERB_HIGH); out << std::endl; out << "GLOBAL " << std::endl; b_1->get_f()->describe(out,Teuchos::VERB_HIGH); out << std::endl; // run test for conditions la_factory->adjustForDirichletConditions(*ghosted_0,*ghosted_1,*ghosted_sys); int numEntries = 0; double * values = 0; int * indices = 0; if(myRank==0) { RCP > A = b_sys->get_A(); for(int i=0;i data; RCP > f = rcp_dynamic_cast >(b_sys->get_f())->getVectorBlock(i); rcp_dynamic_cast >(f)->getLocalData(Teuchos::ptrFromRef(data)); TEST_EQUALITY(data[0],-3.0); // case 0 TEST_EQUALITY(data[2],-3.0/2.0); // case 1 TEST_EQUALITY(data[5],0.0); // case 2 for(int j=0;j subA = getSubBlock(i,j,*A); subA->ExtractMyRowView(0,numEntries,values,indices); for(int k=0;kExtractMyRowView(2,numEntries,values,indices); for(int k=0;kExtractMyRowView(5,numEntries,values,indices); for(int k=0;k > A = b_sys->get_A(); for(int i=0;i data; RCP > f = rcp_dynamic_cast >(b_sys->get_f())->getVectorBlock(i); rcp_dynamic_cast >(f)->getLocalData(Teuchos::ptrFromRef(data)); TEST_EQUALITY(data[3],-3.0); // case 0 TEST_EQUALITY(data[0],-3.0/2.0); // case 1 TEST_EQUALITY(data[6],0.0); // case 2 for(int j=0;j subA = getSubBlock(i,j,*A); subA->ExtractMyRowView(3,numEntries,values,indices); for(int k=0;kExtractMyRowView(0,numEntries,values,indices); for(int k=0;kExtractMyRowView(6,numEntries,values,indices); for(int k=0;k > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); #else NOPE_PANZER_DOESNT_SUPPORT_SERIAL #endif using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; using Thyra::ProductVectorBase; using Thyra::SpmdVectorBase; // pauseToAttach(); int numBlocks = 2; int myRank = tComm->getRank(); int numProc = tComm->getSize(); typedef BlockedEpetraLinearObjContainer BLOC; RCP blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks); Teuchos::RCP > la_factory = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory(tComm,blkIndexer)); RCP ghosted_0 = la_factory->buildGhostedLinearObjContainer(); RCP ghosted_1 = la_factory->buildGhostedLinearObjContainer(); RCP ghosted_sys = la_factory->buildGhostedLinearObjContainer(); la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_0); la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_1); la_factory->initializeGhostedContainer(LinearObjContainer::F | LinearObjContainer::Mat,*ghosted_sys); RCP b_0 = rcp_dynamic_cast(ghosted_0); RCP b_1 = rcp_dynamic_cast(ghosted_1); RCP b_sys = rcp_dynamic_cast(ghosted_sys); TEST_ASSERT(!Teuchos::is_null(b_0->get_f())); TEST_ASSERT(!Teuchos::is_null(b_1->get_f())); TEST_ASSERT(!Teuchos::is_null(b_sys->get_f())); TEST_ASSERT(!Teuchos::is_null(b_sys->get_A())); Thyra::assign(b_0->get_f().ptr(),0.0); // put some garbage in the systems Thyra::assign(b_1->get_f().ptr(),0.0); // put some garbage in the systems Thyra::assign(b_sys->get_f().ptr(),-3.0); // put some garbage in the systems // b_sys->get_A()->PutScalar(-3.0); for(int i=0;iget_A())->PutScalar(-3.0); // there are 3 cases for adjustDirichlet // 1. Local set only for GID // 2. Set on multiple processors // 3. Set remotely if(myRank==0) { RCP > x_0 = rcp_dynamic_cast >(b_0->get_f())->getNonconstVectorBlock(0); RCP > x_1 = rcp_dynamic_cast >(b_1->get_f())->getNonconstVectorBlock(0); Teuchos::ArrayRCP data_0,data_1; rcp_dynamic_cast >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); rcp_dynamic_cast >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); // case 0 data_0[0] = 1.0; // GID = 0 data_1[0] = 1.0; // case 1 data_0[2] = 1.0; // GID = 2 data_1[2] = 2.0; // case 2 data_1[5] = 2.0; // GID = 5 { x_0 = rcp_dynamic_cast >(b_0->get_f())->getNonconstVectorBlock(1); x_1 = rcp_dynamic_cast >(b_1->get_f())->getNonconstVectorBlock(1); rcp_dynamic_cast >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); rcp_dynamic_cast >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); data_1[0] = 2.0; } } else if(myRank==1) { RCP > x_0 = rcp_dynamic_cast >(b_0->get_f())->getNonconstVectorBlock(0); RCP > x_1 = rcp_dynamic_cast >(b_1->get_f())->getNonconstVectorBlock(0); Teuchos::ArrayRCP data_0,data_1; rcp_dynamic_cast >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0)); rcp_dynamic_cast >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1)); // case 0 data_0[3] = 1.0; // GID = 9 data_1[3] = 1.0; // case 1 data_0[0] = 1.0; // GID =2 data_1[0] = 2.0; // case 2 data_1[6] = 2.0; // GID = 4 } else TEUCHOS_ASSERT(false); out << "LOCAL " << std::endl; b_0->get_f()->describe(out,Teuchos::VERB_HIGH); out << std::endl; out << "GLOBAL " << std::endl; b_1->get_f()->describe(out,Teuchos::VERB_HIGH); out << std::endl; // run test for conditions la_factory->adjustForDirichletConditions(*ghosted_0,*ghosted_1,*ghosted_sys); int numEntries = 0; double * values = 0; int * indices = 0; if(myRank==0) { RCP > A = b_sys->get_A(); int i = 0; { Teuchos::ArrayRCP data; RCP > f = rcp_dynamic_cast >(b_sys->get_f())->getVectorBlock(i); rcp_dynamic_cast >(f)->getLocalData(Teuchos::ptrFromRef(data)); TEST_EQUALITY(data[0],-3.0); // case 0 TEST_EQUALITY(data[2],-3.0/2.0); // case 1 TEST_EQUALITY(data[5],0.0); // case 2 for(int j=0;j subA = getSubBlock(i,j,*A); subA->ExtractMyRowView(0,numEntries,values,indices); for(int k=0;kExtractMyRowView(2,numEntries,values,indices); for(int k=0;kExtractMyRowView(5,numEntries,values,indices); for(int k=0;k data; RCP > f = rcp_dynamic_cast >(b_sys->get_f())->getVectorBlock(i); rcp_dynamic_cast >(f)->getLocalData(Teuchos::ptrFromRef(data)); TEST_EQUALITY(data[0],0.0); for(int j=0;j subA = getSubBlock(i,j,*A); subA->ExtractMyRowView(0,numEntries,values,indices); for(int k=0;k > A = b_sys->get_A(); int i = 0; { Teuchos::ArrayRCP data; RCP > f = rcp_dynamic_cast >(b_sys->get_f())->getVectorBlock(i); rcp_dynamic_cast >(f)->getLocalData(Teuchos::ptrFromRef(data)); TEST_EQUALITY(data[3],-3.0); // case 0 TEST_EQUALITY(data[0],-3.0/2.0); // case 1 TEST_EQUALITY(data[6],0.0); // case 2 for(int j=0;j subA = getSubBlock(i,j,*A); subA->ExtractMyRowView(3,numEntries,values,indices); for(int k=0;kExtractMyRowView(0,numEntries,values,indices); for(int k=0;kExtractMyRowView(6,numEntries,values,indices); for(int k=0;k data; RCP > f = rcp_dynamic_cast >(b_sys->get_f())->getVectorBlock(i); rcp_dynamic_cast >(f)->getLocalData(Teuchos::ptrFromRef(data)); TEST_EQUALITY(data[0],-3.0); for(int j=0;j subA = getSubBlock(i,j,*A); subA->ExtractMyRowView(0,numEntries,values,indices); for(int k=0;k > tComm = Teuchos::rcp(new Teuchos::MpiComm(MPI_COMM_WORLD)); #else NOPE_PANZER_DOESNT_SUPPORT_SERIAL #endif using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; // pauseToAttach(); typedef LinearObjContainer LOC; typedef BlockedEpetraLinearObjContainer BLOC; int numBlocks = 3; int myRank = tComm->getRank(); int numProc = tComm->getSize(); RCP blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks); BlockedEpetraLinearObjFactory factory(tComm,blkIndexer); // exclude some pairs std::vector > exPairs; exPairs.push_back(std::make_pair(0,2)); exPairs.push_back(std::make_pair(2,1)); factory.addExcludedPairs(exPairs); factory.addExcludedPair(1,2); RCP container = factory.buildLinearObjContainer(); RCP ghosted = factory.buildGhostedLinearObjContainer(); TEST_ASSERT(container!=Teuchos::null); TEST_ASSERT(ghosted!=Teuchos::null); RCP bContainer = rcp_dynamic_cast(container); RCP b_ghosted = rcp_dynamic_cast(ghosted); TEST_ASSERT(bContainer!=Teuchos::null); TEST_ASSERT(b_ghosted!=Teuchos::null); // tests global initialize { // Generic code ///////////////////////////////////////////////////////////// factory.initializeContainer(LOC::Mat,*container); TEST_EQUALITY(bContainer->get_x(), Teuchos::null) TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null) TEST_EQUALITY(bContainer->get_f(), Teuchos::null) TEST_ASSERT(bContainer->get_A()!=Teuchos::null); RCP > blo = rcp_dynamic_cast >(bContainer->get_A()); TEST_ASSERT(!blo->getNonconstBlock(0,0).is_null()); TEST_ASSERT(!blo->getNonconstBlock(0,1).is_null()); TEST_ASSERT(blo->getNonconstBlock(0,2).is_null()); TEST_ASSERT(!blo->getNonconstBlock(1,0).is_null()); TEST_ASSERT(!blo->getNonconstBlock(1,1).is_null()); TEST_ASSERT(blo->getNonconstBlock(1,2).is_null()); TEST_ASSERT(!blo->getNonconstBlock(2,0).is_null()); TEST_ASSERT(blo->getNonconstBlock(2,1).is_null()); TEST_ASSERT(!blo->getNonconstBlock(2,2).is_null()); } } }