| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// ShyLU: Scalable Hybrid LU Preconditioner and Solver |
| 4 |
// |
| 5 |
// Copyright 2011 NTESS and the ShyLU contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
//#ifdef HAVE_MPI |
| 11 |
#include "mpi.h" |
| 12 |
|
| 13 |
#include <Teuchos_VerboseObject.hpp> |
| 14 |
#include <Teuchos_XMLParameterListCoreHelpers.hpp> |
| 15 |
#include <Teuchos_StackedTimer.hpp> |
| 16 |
|
| 17 |
#include <Xpetra_DefaultPlatform.hpp> |
| 18 |
#include <Xpetra_MultiVectorFactory.hpp> |
| 19 |
#include <Xpetra_VectorFactory.hpp> |
| 20 |
#include <Xpetra_MapFactory.hpp> |
| 21 |
|
| 22 |
#include "FROSch_LocalPartitionOfUnityBasis_def.hpp" |
| 23 |
|
| 24 |
|
| 25 |
using UN = unsigned; |
| 26 |
using SC = double; |
| 27 |
using LO = int; |
| 28 |
using GO = FROSch::DefaultGlobalOrdinal; |
| 29 |
using NO = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType; |
| 30 |
|
| 31 |
using namespace std; |
| 32 |
using namespace Teuchos; |
| 33 |
using namespace Xpetra; |
| 34 |
using namespace FROSch; |
| 35 |
|
| 36 |
int main(int argc, char *argv[]) |
| 37 |
{ |
| 38 |
oblackholestream blackhole; |
| 39 |
GlobalMPISession mpiSession(&argc,&argv,&blackhole); |
| 40 |
|
| 41 |
RCP<const Comm<int> > CommWorld = DefaultPlatform::getDefaultPlatform().getComm(); |
| 42 |
|
| 43 |
CommandLineProcessor My_CLP; |
| 44 |
|
| 45 |
RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream(); |
| 46 |
|
| 47 |
bool useepetra = true; |
| 48 |
My_CLP.setOption("USEEPETRA","USETPETRA",&useepetra,"Use Epetra infrastructure for the linear algebra."); |
| 49 |
|
| 50 |
My_CLP.recogniseAllOptions(true); |
| 51 |
My_CLP.throwExceptions(false); |
| 52 |
CommandLineProcessor::EParseCommandLineReturn parseReturn = My_CLP.parse(argc,argv); |
| 53 |
if (parseReturn == CommandLineProcessor::PARSE_HELP_PRINTED) { |
| 54 |
return(EXIT_SUCCESS); |
| 55 |
} |
| 56 |
|
| 57 |
CommWorld->barrier(); |
| 58 |
RCP<StackedTimer> stackedTimer = rcp(new StackedTimer("Local Partition of Unity Test")); |
| 59 |
TimeMonitor::setStackedTimer(stackedTimer); |
| 60 |
|
| 61 |
UnderlyingLib xpetraLib = UseTpetra; |
| 62 |
if (useepetra) { |
| 63 |
xpetraLib = UseEpetra; |
| 64 |
} else { |
| 65 |
xpetraLib = UseTpetra; |
| 66 |
} |
| 67 |
|
| 68 |
RCP<const Comm<LO> > SerialComm = rcp(new MpiComm<LO>(MPI_COMM_SELF)); |
| 69 |
|
| 70 |
Array<GO> nodes(9); |
| 71 |
Array<GO> dofs(27); |
| 72 |
Array<GO> dofs1(9); |
| 73 |
Array<GO> dofs2(9); |
| 74 |
Array<GO> dofs3(9); |
| 75 |
|
| 76 |
for (UN i=0; i<9; i++) { |
| 77 |
nodes[i] = i; |
| 78 |
dofs[3*i] = 3*i; |
| 79 |
dofs[3*i+1] = 3*i+1; |
| 80 |
dofs[3*i+2] = 3*i+2; |
| 81 |
dofs1[i] = 3*i; |
| 82 |
dofs2[i] = 3*i+1; |
| 83 |
dofs3[i] = 3*i+2; |
| 84 |
} |
| 85 |
|
| 86 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 87 |
RCP<Map<LO,GO,NO> > nodesMap = MapFactory<LO,GO,NO>::Build(xpetraLib,INVALID,nodes(),0,SerialComm); |
| 88 |
RCP<Map<LO,GO,NO> > dofsMap = MapFactory<LO,GO,NO>::Build(xpetraLib,INVALID,dofs(),0,SerialComm); |
| 89 |
ArrayRCP<RCP<Map<LO,GO,NO> > > dofsMaps (3); |
| 90 |
dofsMaps[0] = MapFactory<LO,GO,NO>::Build(xpetraLib,INVALID,dofs1(),0,SerialComm); |
| 91 |
dofsMaps[1] = MapFactory<LO,GO,NO>::Build(xpetraLib,INVALID,dofs2(),0,SerialComm); |
| 92 |
dofsMaps[2] = MapFactory<LO,GO,NO>::Build(xpetraLib,INVALID,dofs3(),0,SerialComm); |
| 93 |
|
| 94 |
ArrayRCP<RCP<const MultiVector<SC,LO,GO,NO> > > partitionOfUnity(2); |
| 95 |
|
| 96 |
RCP<MultiVector<SC,LO,GO,NO> > tmpVec = MultiVectorFactory<SC,LO,GO,NO>::Build(dofsMap,2); |
| 97 |
tmpVec->replaceLocalValue(dofsMaps[0]->getGlobalElement(nodes[0]),0,ScalarTraits<SC>::one()); |
| 98 |
tmpVec->replaceLocalValue(dofsMaps[1]->getGlobalElement(nodes[0]),0,ScalarTraits<SC>::one()); |
| 99 |
tmpVec->replaceLocalValue(dofsMaps[2]->getGlobalElement(nodes[0]),0,ScalarTraits<SC>::one()); |
| 100 |
|
| 101 |
tmpVec->replaceLocalValue(dofsMaps[0]->getGlobalElement(nodes[8]),1,ScalarTraits<SC>::one()); |
| 102 |
tmpVec->replaceLocalValue(dofsMaps[1]->getGlobalElement(nodes[8]),1,ScalarTraits<SC>::one()); |
| 103 |
tmpVec->replaceLocalValue(dofsMaps[2]->getGlobalElement(nodes[8]),1,ScalarTraits<SC>::one()); |
| 104 |
partitionOfUnity[0] = tmpVec; |
| 105 |
|
| 106 |
tmpVec = MultiVectorFactory<SC,LO,GO,NO>::Build(dofsMap,1); |
| 107 |
for (UN i=1; i<8; i++) { |
| 108 |
tmpVec->replaceLocalValue(dofsMaps[0]->getGlobalElement(nodes[i]),0,ScalarTraits<SC>::one()); |
| 109 |
tmpVec->replaceLocalValue(dofsMaps[1]->getGlobalElement(nodes[i]),0,ScalarTraits<SC>::one()); |
| 110 |
tmpVec->replaceLocalValue(dofsMaps[2]->getGlobalElement(nodes[i]),0,ScalarTraits<SC>::one()); |
| 111 |
} |
| 112 |
partitionOfUnity[1] = tmpVec; |
| 113 |
|
| 114 |
RCP<MultiVector<SC,LO,GO,NO> > nullspace = MultiVectorFactory<SC,LO,GO,NO>::Build(dofsMap,6); |
| 115 |
for (UN i=0; i<9; i++) { |
| 116 |
nullspace->replaceLocalValue(dofsMaps[0]->getGlobalElement(nodes[i]),0,ScalarTraits<SC>::one()); |
| 117 |
nullspace->replaceLocalValue(dofsMaps[1]->getGlobalElement(nodes[i]),1,ScalarTraits<SC>::one()); |
| 118 |
nullspace->replaceLocalValue(dofsMaps[2]->getGlobalElement(nodes[i]),2,ScalarTraits<SC>::one()); |
| 119 |
|
| 120 |
nullspace->replaceLocalValue(dofsMaps[0]->getGlobalElement(nodes[i]),3,ScalarTraits<SC>::one()*double(i)); |
| 121 |
nullspace->replaceLocalValue(dofsMaps[1]->getGlobalElement(nodes[i]),3,-ScalarTraits<SC>::one()*double(i)); |
| 122 |
nullspace->replaceLocalValue(dofsMaps[2]->getGlobalElement(nodes[i]),3,ScalarTraits<SC>::zero()); |
| 123 |
|
| 124 |
nullspace->replaceLocalValue(dofsMaps[0]->getGlobalElement(nodes[i]),4,-ScalarTraits<SC>::one()*double(i)); |
| 125 |
nullspace->replaceLocalValue(dofsMaps[1]->getGlobalElement(nodes[i]),4,ScalarTraits<SC>::zero()); |
| 126 |
nullspace->replaceLocalValue(dofsMaps[2]->getGlobalElement(nodes[i]),4,ScalarTraits<SC>::one()*double(i)); |
| 127 |
|
| 128 |
nullspace->replaceLocalValue(dofsMaps[0]->getGlobalElement(nodes[i]),5,ScalarTraits<SC>::zero()); |
| 129 |
nullspace->replaceLocalValue(dofsMaps[1]->getGlobalElement(nodes[i]),5,ScalarTraits<SC>::one()*double(i)); |
| 130 |
nullspace->replaceLocalValue(dofsMaps[2]->getGlobalElement(nodes[i]),5,-ScalarTraits<SC>::one()*double(i)); |
| 131 |
} |
| 132 |
|
| 133 |
Array<GO> partitionOfUnityMapVec1(2); |
| 134 |
partitionOfUnityMapVec1[0] = 0; |
| 135 |
partitionOfUnityMapVec1[1] = 1; |
| 136 |
Array<GO> partitionOfUnityMapVec2(1); |
| 137 |
partitionOfUnityMapVec1[0] = 0; |
| 138 |
|
| 139 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > partitionOfUnityMaps(2); |
| 140 |
partitionOfUnityMaps[0] = MapFactory<LO,GO,NO>::Build(xpetraLib,INVALID,partitionOfUnityMapVec1(),0,SerialComm); |
| 141 |
partitionOfUnityMaps[1] = MapFactory<LO,GO,NO>::Build(xpetraLib,INVALID,partitionOfUnityMapVec2(),0,SerialComm); |
| 142 |
|
| 143 |
RCP<ParameterList> parameterList = getParametersFromXmlFile("Parameters.xml"); |
| 144 |
|
| 145 |
LocalPartitionOfUnityBasis<SC,LO,GO,NO> TestBasis(SerialComm,SerialComm,3,parameterList,nullspace,partitionOfUnity,partitionOfUnityMaps); |
| 146 |
TestBasis.buildLocalPartitionOfUnityBasis(); |
| 147 |
|
| 148 |
RCP<CoarseSpace<SC,LO,GO,NO> > coarseSpace = TestBasis.getLocalPartitionOfUnitySpace(); |
| 149 |
|
| 150 |
for (UN i=0; i<coarseSpace->getAssembledBasis()->getLocalLength(); i++) { |
| 151 |
for (UN j=0; j<coarseSpace->getAssembledBasis()->getNumVectors(); j++) { |
| 152 |
std::cout << coarseSpace->getAssembledBasis()->getData(j)[i] << "\t"; |
| 153 |
} |
| 154 |
std::cout << "\n"; |
| 155 |
} |
| 156 |
std::cout << "\n"; |
| 157 |
|
| 158 |
CommWorld->barrier(); |
| 159 |
stackedTimer->stop("Local Partition of Unity Test"); |
| 160 |
StackedTimer::OutputOptions options; |
| 161 |
options.output_fraction = options.output_histogram = options.output_minmax = true; |
| 162 |
stackedTimer->report(*out,CommWorld,options); |
| 163 |
|
| 164 |
return(EXIT_SUCCESS); |
| 165 |
} |