| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include <iostream> |
| 11 |
#include <complex> |
| 12 |
|
| 13 |
// Teuchos |
| 14 |
#include <Teuchos_StandardCatchMacros.hpp> |
| 15 |
|
| 16 |
// Xpetra and Galeri |
| 17 |
#include <Xpetra_MultiVectorFactory.hpp> |
| 18 |
#include <Galeri_XpetraParameters.hpp> |
| 19 |
#include <Galeri_XpetraProblemFactory_Helmholtz.hpp> |
| 20 |
#include <Galeri_XpetraUtils.hpp> |
| 21 |
#include <Galeri_XpetraMaps.hpp> |
| 22 |
|
| 23 |
// MueLu |
| 24 |
#include <MueLu_ShiftedLaplacian.hpp> |
| 25 |
#include <MueLu_UseDefaultTypesComplex.hpp> |
| 26 |
#include <MueLu_MutuallyExclusiveTime.hpp> |
| 27 |
|
| 28 |
int main(int argc, char *argv[]) { |
| 29 |
#include <MueLu_UseShortNames.hpp> |
| 30 |
|
| 31 |
typedef Tpetra::Vector<SC, LO, GO, NO> TVEC; |
| 32 |
typedef Tpetra::MultiVector<SC, LO, GO, NO> TMV; |
| 33 |
typedef Tpetra::CrsMatrix<SC, LO, GO, NO> TCRS; |
| 34 |
typedef Xpetra::CrsMatrix<SC, LO, GO, NO> XCRS; |
| 35 |
typedef Xpetra::TpetraCrsMatrix<SC, LO, GO, NO> XTCRS; |
| 36 |
typedef Xpetra::Matrix<SC, LO, GO, NO> XMAT; |
| 37 |
typedef Xpetra::CrsMatrixWrap<SC, LO, GO, NO> XWRAP; |
| 38 |
typedef typename Teuchos::ScalarTraits<SC>::magnitudeType real_type; |
| 39 |
typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector; |
| 40 |
|
| 41 |
using Teuchos::RCP; |
| 42 |
using Teuchos::rcp; |
| 43 |
using Teuchos::TimeMonitor; |
| 44 |
|
| 45 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); |
| 46 |
|
| 47 |
bool success = false; |
| 48 |
bool verbose = true; |
| 49 |
try { |
| 50 |
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 51 |
Teuchos::CommandLineProcessor clp(false); |
| 52 |
|
| 53 |
//***********************// |
| 54 |
// Galeri Parameters // |
| 55 |
//***********************// |
| 56 |
|
| 57 |
GO nx, ny, nz; |
| 58 |
GO mx, my, mz; |
| 59 |
double stretchx, stretchy, stretchz, h, delta; |
| 60 |
int PMLXL, PMLXR, PMLYL, PMLYR, PMLZL, PMLZR; |
| 61 |
double omega, shift; |
| 62 |
int model; |
| 63 |
|
| 64 |
std::ifstream inputfile; |
| 65 |
inputfile.open("helm3D.inp"); |
| 66 |
inputfile >> nx >> ny >> nz; |
| 67 |
if (comm->getRank() == 0) |
| 68 |
std::cout << "nx: " << nx << " ny: " << ny << " nz: " << nz << std::endl; |
| 69 |
inputfile >> stretchx >> stretchy >> stretchz; |
| 70 |
if (comm->getRank() == 0) |
| 71 |
std::cout << "stretchx: " << stretchx << " stretchy: " << stretchy << " stretchz: " << stretchz << std::endl; |
| 72 |
inputfile >> h >> delta; |
| 73 |
if (comm->getRank() == 0) |
| 74 |
std::cout << "h: " << h << " delta: " << delta << std::endl; |
| 75 |
inputfile >> PMLXL >> PMLXR; |
| 76 |
if (comm->getRank() == 0) |
| 77 |
std::cout << "PMLXL: " << PMLXL << " PMLXR: " << PMLXR << std::endl; |
| 78 |
inputfile >> PMLYL >> PMLYR; |
| 79 |
if (comm->getRank() == 0) |
| 80 |
std::cout << "PMLYL: " << PMLYL << " PMLYR: " << PMLYR << std::endl; |
| 81 |
inputfile >> PMLZL >> PMLZR; |
| 82 |
if (comm->getRank() == 0) |
| 83 |
std::cout << "PMLZL: " << PMLZL << " PMLZR: " << PMLZR << std::endl; |
| 84 |
inputfile >> omega >> shift; |
| 85 |
if (comm->getRank() == 0) |
| 86 |
std::cout << "omega: " << omega << " shift: " << shift << std::endl; |
| 87 |
inputfile >> mx >> my >> mz; |
| 88 |
if (comm->getRank() == 0) |
| 89 |
std::cout << "mx: " << mx << " my: " << my << " mz: " << mz << std::endl; |
| 90 |
inputfile >> model; |
| 91 |
if (comm->getRank() == 0) |
| 92 |
std::cout << "velocity model: " << model << std::endl; |
| 93 |
|
| 94 |
Galeri::Xpetra::Parameters<GO> matrixParameters_helmholtz(clp, nx, ny, nz, "HelmholtzFEM3D", 0, stretchx, stretchy, stretchz, |
| 95 |
h, delta, PMLXL, PMLXR, PMLYL, PMLYR, PMLZL, PMLZR, omega, 0.0, mx, my, mz, model); |
| 96 |
Galeri::Xpetra::Parameters<GO> matrixParameters_shifted(clp, nx, ny, nz, "HelmholtzFEM3D", 0, stretchx, stretchy, stretchz, |
| 97 |
h, delta, PMLXL, PMLXR, PMLYL, PMLYR, PMLZL, PMLZR, omega, shift, mx, my, mz, model); |
| 98 |
Xpetra::Parameters xpetraParameters(clp); |
| 99 |
|
| 100 |
//****************************************// |
| 101 |
// Setup Galeri Problems and Matrices // |
| 102 |
//****************************************// |
| 103 |
|
| 104 |
RCP<TimeMonitor> globalTimeMonitor = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: S - Global Time"))); |
| 105 |
RCP<TimeMonitor> tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 1 - Matrix Build"))); |
| 106 |
|
| 107 |
Teuchos::ParameterList pl = matrixParameters_helmholtz.GetParameterList(); |
| 108 |
RCP<RealValuedMultiVector> coordinates; |
| 109 |
Teuchos::ParameterList galeriList; |
| 110 |
galeriList.set("nx", pl.get("nx", nx)); |
| 111 |
galeriList.set("ny", pl.get("ny", ny)); |
| 112 |
galeriList.set("nz", pl.get("nz", nz)); |
| 113 |
RCP<const Map> map; |
| 114 |
|
| 115 |
map = Galeri::Xpetra::CreateMap<LO, GO, Node>(xpetraParameters.GetLib(), "Cartesian3D", comm, galeriList); |
| 116 |
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("3D", map, matrixParameters_helmholtz.GetParameterList()); |
| 117 |
|
| 118 |
RCP<const Tpetra::Map<LO, GO, NO> > tmap = Xpetra::toTpetra(map); |
| 119 |
|
| 120 |
Teuchos::ParameterList matrixParams_helmholtz = matrixParameters_helmholtz.GetParameterList(); |
| 121 |
Teuchos::ParameterList matrixParams_shifted = matrixParameters_shifted.GetParameterList(); |
| 122 |
|
| 123 |
RCP<Galeri::Xpetra::Problem_Helmholtz<Map, CrsMatrixWrap, MultiVector> > Pr_helmholtz = |
| 124 |
Galeri::Xpetra::BuildProblem_Helmholtz<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>(matrixParameters_helmholtz.GetMatrixType(), map, matrixParams_helmholtz); |
| 125 |
RCP<Matrix> Amat = Pr_helmholtz->BuildMatrix(); |
| 126 |
|
| 127 |
RCP<Galeri::Xpetra::Problem_Helmholtz<Map, CrsMatrixWrap, MultiVector> > Pr_shifted = |
| 128 |
Galeri::Xpetra::BuildProblem_Helmholtz<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>(matrixParameters_shifted.GetMatrixType(), map, matrixParams_shifted); |
| 129 |
RCP<Matrix> Pmat = Pr_shifted->BuildMatrix(); |
| 130 |
|
| 131 |
comm->barrier(); |
| 132 |
|
| 133 |
tm = Teuchos::null; |
| 134 |
|
| 135 |
//*************************************************************// |
| 136 |
// Setup Shifted Laplacian Preconditioner and Belos Solver // |
| 137 |
//*************************************************************// |
| 138 |
|
| 139 |
tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 2 - MueLu Setup"))); |
| 140 |
|
| 141 |
// initialize with the Shifted Laplacian operator (Pmat) |
| 142 |
RCP<ShiftedLaplacian> SLSolver = rcp(new ShiftedLaplacian); |
| 143 |
SLSolver->setPreconditioningMatrix(Pmat); |
| 144 |
SLSolver->initialize(); |
| 145 |
// set Helmholtz operator (Amat) |
| 146 |
SLSolver->setProblemMatrix(Amat); |
| 147 |
// setup with SL operator |
| 148 |
SLSolver->setupNormalRAP(); |
| 149 |
|
| 150 |
tm = Teuchos::null; |
| 151 |
|
| 152 |
//************************************// |
| 153 |
// Solve linear system with Belos // |
| 154 |
//************************************// |
| 155 |
|
| 156 |
tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 3 - LHS and RHS initialization"))); |
| 157 |
|
| 158 |
RCP<TMV> X = Tpetra::createMultiVector<SC, LO, GO, NO>(tmap, 1); |
| 159 |
RCP<TMV> B = Tpetra::createMultiVector<SC, LO, GO, NO>(tmap, 1); |
| 160 |
X->putScalar((SC)0.0); |
| 161 |
B->putScalar((SC)0.0); |
| 162 |
int pointsourceid = nx * ny * nz / 2 + nx * ny / 2 + nx / 2; |
| 163 |
if (map->isNodeGlobalElement(pointsourceid) == true) { |
| 164 |
B->replaceGlobalValue(pointsourceid, 0, (SC)1.0); |
| 165 |
} |
| 166 |
|
| 167 |
tm = Teuchos::null; |
| 168 |
|
| 169 |
tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 4 - Belos Solve"))); |
| 170 |
|
| 171 |
SLSolver->solve(B, X); |
| 172 |
|
| 173 |
tm = Teuchos::null; |
| 174 |
|
| 175 |
globalTimeMonitor = Teuchos::null; |
| 176 |
|
| 177 |
TimeMonitor::summarize(); |
| 178 |
|
| 179 |
success = true; |
| 180 |
} |
| 181 |
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); |
| 182 |
|
| 183 |
return (success ? EXIT_SUCCESS : EXIT_FAILURE); |
| 184 |
} // main |