// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include #include // Xpetra and Galeri #include #include #include #include #include // MueLu #include #include #include int main(int argc, char *argv[]) { #include typedef Tpetra::Vector TVEC; typedef Tpetra::MultiVector TMV; typedef Tpetra::CrsMatrix TCRS; typedef Xpetra::CrsMatrix XCRS; typedef Xpetra::TpetraCrsMatrix XTCRS; typedef Xpetra::Matrix XMAT; typedef Xpetra::CrsMatrixWrap XWRAP; typedef typename Teuchos::ScalarTraits::magnitudeType real_type; typedef Xpetra::MultiVector RealValuedMultiVector; using Teuchos::RCP; using Teuchos::rcp; using Teuchos::TimeMonitor; Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); bool success = false; bool verbose = true; try { RCP > comm = Teuchos::DefaultComm::getComm(); Teuchos::CommandLineProcessor clp(false); //***********************// // Galeri Parameters // //***********************// GO nx, ny, nz; GO mx, my, mz; double stretchx, stretchy, stretchz, h, delta; int PMLXL, PMLXR, PMLYL, PMLYR, PMLZL, PMLZR; double omega, shift; int model; std::ifstream inputfile; inputfile.open("helm3D.inp"); inputfile >> nx >> ny >> nz; if (comm->getRank() == 0) std::cout << "nx: " << nx << " ny: " << ny << " nz: " << nz << std::endl; inputfile >> stretchx >> stretchy >> stretchz; if (comm->getRank() == 0) std::cout << "stretchx: " << stretchx << " stretchy: " << stretchy << " stretchz: " << stretchz << std::endl; inputfile >> h >> delta; if (comm->getRank() == 0) std::cout << "h: " << h << " delta: " << delta << std::endl; inputfile >> PMLXL >> PMLXR; if (comm->getRank() == 0) std::cout << "PMLXL: " << PMLXL << " PMLXR: " << PMLXR << std::endl; inputfile >> PMLYL >> PMLYR; if (comm->getRank() == 0) std::cout << "PMLYL: " << PMLYL << " PMLYR: " << PMLYR << std::endl; inputfile >> PMLZL >> PMLZR; if (comm->getRank() == 0) std::cout << "PMLZL: " << PMLZL << " PMLZR: " << PMLZR << std::endl; inputfile >> omega >> shift; if (comm->getRank() == 0) std::cout << "omega: " << omega << " shift: " << shift << std::endl; inputfile >> mx >> my >> mz; if (comm->getRank() == 0) std::cout << "mx: " << mx << " my: " << my << " mz: " << mz << std::endl; inputfile >> model; if (comm->getRank() == 0) std::cout << "velocity model: " << model << std::endl; Galeri::Xpetra::Parameters matrixParameters_helmholtz(clp, nx, ny, nz, "Helmholtz3D", 0, stretchx, stretchy, stretchz, h, delta, PMLXL, PMLXR, PMLYL, PMLYR, PMLZL, PMLZR, omega, 0.0, mx, my, mz, model); Galeri::Xpetra::Parameters matrixParameters_shifted(clp, nx, ny, nz, "Helmholtz3D", 0, stretchx, stretchy, stretchz, h, delta, PMLXL, PMLXR, PMLYL, PMLYR, PMLZL, PMLZR, omega, shift, mx, my, mz, model); Xpetra::Parameters xpetraParameters(clp); //****************************************// // Setup Galeri Problems and Matrices // //****************************************// RCP globalTimeMonitor = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: S - Global Time"))); RCP tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 1 - Matrix Build"))); Teuchos::ParameterList pl = matrixParameters_helmholtz.GetParameterList(); RCP coordinates; Teuchos::ParameterList galeriList; galeriList.set("nx", pl.get("nx", nx)); galeriList.set("ny", pl.get("ny", ny)); galeriList.set("nz", pl.get("nz", nz)); RCP map; map = Galeri::Xpetra::CreateMap(xpetraParameters.GetLib(), "Cartesian3D", comm, galeriList); coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates("3D", map, matrixParameters_helmholtz.GetParameterList()); RCP > tmap = Xpetra::toTpetra(map); Teuchos::ParameterList matrixParams_helmholtz = matrixParameters_helmholtz.GetParameterList(); Teuchos::ParameterList matrixParams_shifted = matrixParameters_shifted.GetParameterList(); RCP > Pr_helmholtz = Galeri::Xpetra::BuildProblem_Helmholtz(matrixParameters_helmholtz.GetMatrixType(), map, matrixParams_helmholtz); RCP Amat = Pr_helmholtz->BuildMatrix(); RCP > Pr_shifted = Galeri::Xpetra::BuildProblem_Helmholtz(matrixParameters_shifted.GetMatrixType(), map, matrixParams_shifted); RCP Pmat = Pr_shifted->BuildMatrix(); comm->barrier(); tm = Teuchos::null; //*************************************************************// // Setup Shifted Laplacian Preconditioner and Belos Solver // //*************************************************************// tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 2 - MueLu Setup"))); // initialize with the Shifted Laplacian operator (Pmat) RCP SLSolver = rcp(new ShiftedLaplacian); SLSolver->setPreconditioningMatrix(Pmat); SLSolver->initialize(); // set Helmholtz operator (Amat) SLSolver->setProblemMatrix(Amat); // setup with SL operator SLSolver->setupNormalRAP(); tm = Teuchos::null; //************************************// // Solve linear system with Belos // //************************************// tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 3 - LHS and RHS initialization"))); RCP X = Tpetra::createMultiVector(tmap, 1); RCP B = Tpetra::createMultiVector(tmap, 1); X->putScalar((SC)0.0); B->putScalar((SC)0.0); int pointsourceid = nx * ny * nz / 2 + nx * ny / 2 + nx / 2; if (map->isNodeGlobalElement(pointsourceid) == true) { B->replaceGlobalValue(pointsourceid, 0, (SC)1.0); } tm = Teuchos::null; tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 4 - Belos Solve"))); SLSolver->solve(B, X); tm = Teuchos::null; globalTimeMonitor = Teuchos::null; TimeMonitor::summarize(); success = true; } TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); return (success ? EXIT_SUCCESS : EXIT_FAILURE); } // main