Debian Codegraph @

packages/muelu/test/helmholtz/Helmholtz3D.cpp

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