Debian Codegraph @

packages/muelu/test/helmholtz/HelmholtzFEM2D.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 // 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("helm2D.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, "HelmholtzFEM2D", 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, "HelmholtzFEM2D", 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(), "Cartesian2D", comm, galeriList);
116 coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("2D", 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> Kmat, Mmat;
126 std::pair<RCP<Matrix>, RCP<Matrix> > system = Pr_helmholtz->BuildMatrices();
127 Kmat = system.first;
128 Mmat = system.second;
129 RCP<Matrix> Amat = Pr_helmholtz->BuildMatrix();
130
131 RCP<Galeri::Xpetra::Problem_Helmholtz<Map, CrsMatrixWrap, MultiVector> > Pr_shifted =
132 Galeri::Xpetra::BuildProblem_Helmholtz<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>(matrixParameters_shifted.GetMatrixType(), map, matrixParams_shifted);
133 RCP<Matrix> Pmat = Pr_shifted->BuildMatrix();
134
135 comm->barrier();
136
137 tm = Teuchos::null;
138
139 //*************************************************************//
140 // Setup Shifted Laplacian Preconditioner and Belos Solver //
141 //*************************************************************//
142
143 tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 2 - MueLu Setup")));
144
145 RCP<ShiftedLaplacian> SLSolver = rcp(new ShiftedLaplacian);
146 SLSolver->setstiff(Kmat);
147 SLSolver->setmass(Mmat);
148 SLSolver->setProblemMatrix(Amat);
149 SLSolver->setPreconditioningMatrix(Pmat);
150 SLSolver->initialize();
151 SLSolver->setupFastRAP();
152
153 tm = Teuchos::null;
154
155 //************************************//
156 // Solve linear system with Belos //
157 //************************************//
158
159 tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 3 - LHS and RHS initialization")));
160
161 RCP<TMV> X = Tpetra::createMultiVector<SC, LO, GO, NO>(tmap, 1);
162 RCP<TMV> B = Tpetra::createMultiVector<SC, LO, GO, NO>(tmap, 1);
163 X->putScalar((SC)0.0);
164 B->putScalar((SC)0.0);
165 int pointsourceid = nx * ny / 2 + nx / 2;
166 if (map->isNodeGlobalElement(pointsourceid) == true) {
167 B->replaceGlobalValue(pointsourceid, 0, (SC)1.0);
168 }
169
170 tm = Teuchos::null;
171
172 tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 4 - Belos Solve")));
173
174 SLSolver->solve(B, X);
175
176 tm = Teuchos::null;
177
178 globalTimeMonitor = Teuchos::null;
179
180 TimeMonitor::summarize();
181
182 success = true;
183 }
184 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
185 return (success ? EXIT_SUCCESS : EXIT_FAILURE);
186 } // main