OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
MGPoissonSolver.h
Go to the documentation of this file.
1//
2// Class MGPoissonSolver
3// This class contains methods for solving Poisson's equation for the
4// space charge portion of the calculation.
5//
6// A smoothed aggregation based AMG preconditioned iterative solver for space charge
7// \see FFTPoissonSolver
8// \warning This solver is in an EXPERIMENTAL STAGE. For reliable simulations use the FFTPoissonSolver
9//
10// Copyright (c) 2008, Yves Ineichen, ETH Zürich,
11// 2013 - 2015, Tülin Kaman, Paul Scherrer Institut, Villigen PSI, Switzerland
12// 2017 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
13// All rights reserved
14//
15// Implemented as part of the master thesis
16// "A Parallel Multigrid Solver for Beam Dynamics"
17// and the paper
18// "A fast parallel Poisson solver on irregular domains applied to beam dynamics simulations"
19// (https://doi.org/10.1016/j.jcp.2010.02.022)
20//
21// In 2020, the code was ported to the second generation Trilinos packages,
22// i.e., Epetra --> Tpetra, ML --> MueLu. See also issue #507.
23//
24// This file is part of OPAL.
25//
26// OPAL is free software: you can redistribute it and/or modify
27// it under the terms of the GNU General Public License as published by
28// the Free Software Foundation, either version 3 of the License, or
29// (at your option) any later version.
30//
31// You should have received a copy of the GNU General Public License
32// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
33//
34#ifndef MG_POISSON_SOLVER_H_
35#define MG_POISSON_SOLVER_H_
36
38#include "PoissonSolver.h"
39#include "IrregularDomain.h"
41
42#include "mpi.h"
43
44#include <Tpetra_Vector.hpp>
45#include <Tpetra_CrsMatrix.hpp>
46
47#include <Teuchos_DefaultMpiComm.hpp>
48
49#include <BelosLinearProblem.hpp>
50#include <BelosSolverFactory.hpp>
51
52#include <MueLu.hpp>
53#include <MueLu_TpetraOperator.hpp>
54
55#include "Teuchos_ParameterList.hpp"
57
61typedef Cell Center_t;
64
65enum {
69};
70
72
74
75public:
76 typedef Tpetra::Vector<> TpetraVector_t;
77 typedef Tpetra::MultiVector<> TpetraMultiVector_t;
78 typedef Tpetra::Map<> TpetraMap_t;
79 typedef Tpetra::Vector<>::scalar_type TpetraScalar_t;
80 typedef Tpetra::Vector<>::global_ordinal_type TpetraGlobalOrdinal_t;
81 typedef Tpetra::Operator<> TpetraOperator_t;
82 typedef MueLu::TpetraOperator<> MueLuTpetraOperator_t;
83 typedef Tpetra::CrsMatrix<> TpetraCrsMatrix_t;
84 typedef Teuchos::MpiComm<int> Comm_t;
85
86 typedef Teuchos::ParameterList ParameterList_t;
87
88 typedef Belos::SolverManager<TpetraScalar_t,
91
92 typedef Belos::LinearProblem<TpetraScalar_t,
95
96
97
99 FieldLayout_t *fl,
100 std::vector<BoundaryGeometry *> geometries,
101 std::string itsolver, std::string interpl,
102 double tol, int maxiters, std::string precmode);
103
105
110 void computePotential(Field_t &rho, Vector_t hr);
111 void computePotential(Field_t &rho, Vector_t hr, double zshift);
112
114 void setGeometry(std::vector<BoundaryGeometry *> geometries);
115
116 double getXRangeMin(unsigned short /*level*/) { return bp_m->getXRangeMin(); }
117 double getXRangeMax(unsigned short /*level*/) { return bp_m->getXRangeMax(); }
118 double getYRangeMin(unsigned short /*level*/) { return bp_m->getYRangeMin(); }
119 double getYRangeMax(unsigned short /*level*/) { return bp_m->getYRangeMax(); }
120 double getZRangeMin(unsigned short /*level*/) { return bp_m->getZRangeMin(); }
121 double getZRangeMax(unsigned short /*level*/) { return bp_m->getZRangeMax(); }
122 void test(PartBunchBase<double, 3>* /*bunch*/) { }
125
126 void extrapolateLHS();
127
128 void resizeMesh(Vector_t& origin, Vector_t& hr, const Vector_t& rmin,
129 const Vector_t& rmax, double dh)
130 {
131 bp_m->resizeMesh(origin, hr, rmin, rmax, dh);
132 }
133
134 Inform &print(Inform &os) const;
135
136
137
138private:
139
141
142 // true if CG and GMRES; false if BiCGStab
144
145 //TODO: we need to update this and maybe change attached
146 //solver!
149
151 std::vector<BoundaryGeometry *> geometries_m;
152
156
158 double tol_m;
167
169 std::unique_ptr<IrregularDomain> bp_m;
170
172 Teuchos::RCP<TpetraVector_t> RHS;
174 Teuchos::RCP<TpetraVector_t> LHS;
176 Teuchos::RCP<TpetraCrsMatrix_t> A;
177
179 Teuchos::RCP<TpetraMap_t> map_p;
180
182 Teuchos::RCP<const Comm_t> comm_mp;
183
185 unsigned int nLHS_m;
186 Teuchos::RCP<TpetraMultiVector_t> P_mp;
187 std::deque< TpetraVector_t > OldLHS;
188
189 Teuchos::RCP<LinearProblem_t> problem_mp;
190 Teuchos::RCP<SolverManager_t> solver_mp;
191
193 Teuchos::RCP<MueLuTpetraOperator_t> prec_mp;
194
196 Teuchos::ParameterList MueLuList_m;
198 Teuchos::ParameterList belosList;
199
202
203 // mesh and layout objects for rho_m
206
207 // domains for the various fields
209
216
217 // timers
226
227 void deletePtr();
228
230 void computeMap(NDIndex<3> localId);
231
234 void IPPLToMap3D(NDIndex<3> localId);
235
241 void ComputeStencil(Vector_t hr, Teuchos::RCP<TpetraVector_t> RHS);
242
243
244
245protected:
247 void setupBelosList();
248
250 void setupMueLuList();
251};
252
253
255 return fs.print(os);
256}
257
258#endif
UniformCartesian< 3, double > Mesh_t
Cell Center_t
ParticleSpatialLayout< double, 3 >::SingleParticlePos_t Vector_t
Field< double, 3, Mesh_t, Center_t > Field_t
Inform & operator<<(Inform &os, const MGPoissonSolver &fs)
ParticleSpatialLayout< double, 3, Mesh_t > Layout_t
CenteredFieldLayout< 3, Mesh_t, Center_t > FieldLayout_t
@ REUSE_HIERARCHY
@ STD_PREC
@ REUSE_PREC
FRONT * fs
Definition: hypervolume.cpp:59
int precmode_m
preconditioner mode
Teuchos::RCP< TpetraVector_t > LHS
left hand side of the linear system of equations we solve
void computeMap(NDIndex< 3 > localId)
recomputes the map
Teuchos::MpiComm< int > Comm_t
void setupMueLuList()
Setup the parameters for the SAAMG preconditioner.
IpplTimings::TimerRef FunctionTimer2_m
IpplTimings::TimerRef FunctionTimer4_m
Teuchos::RCP< LinearProblem_t > problem_mp
Tpetra::CrsMatrix TpetraCrsMatrix_t
Inform & print(Inform &os) const
double getXRangeMax(unsigned short)
NDIndex< 3 > domain_m
Tpetra::Vector ::global_ordinal_type TpetraGlobalOrdinal_t
Tpetra::Vector ::scalar_type TpetraScalar_t
void printLoadBalanceStats()
useful load balance information
Tpetra::Vector TpetraVector_t
Vector_t hr_m
mesh spacings in each direction
MueLu::TpetraOperator MueLuTpetraOperator_t
Teuchos::ParameterList belosList
parameter list for the iterative solver (Belos)
PartBunch * itsBunch_m
PartBunch object.
int recycleBlocks_m
number of vectors in recycle space
int numBlocks_m
maximum number of blocks in Krylov space
IpplTimings::TimerRef FunctionTimer5_m
double getXRangeMin(unsigned short)
Tpetra::MultiVector TpetraMultiVector_t
Teuchos::ParameterList ParameterList_t
Vektor< int, 3 > nr_m
current number of mesh points in each direction
double getYRangeMax(unsigned short)
IpplTimings::TimerRef FunctionTimer3_m
double tol_m
tolerance for the iterative solver
double getYRangeMin(unsigned short)
std::deque< TpetraVector_t > OldLHS
void setupBelosList()
Setup the parameters for the Belos iterative solver.
double getZRangeMax(unsigned short)
void computePotential(Field_t &rho, Vector_t hr)
FieldLayout_t * layout_m
IpplTimings::TimerRef FunctionTimer7_m
int maxiters_m
maximal number of iterations for the iterative solver
Teuchos::RCP< MueLuTpetraOperator_t > prec_mp
MueLu preconditioner object.
void IPPLToMap3D(NDIndex< 3 > localId)
void setGeometry(std::vector< BoundaryGeometry * > geometries)
set a geometry
void ComputeStencil(Vector_t hr, Teuchos::RCP< TpetraVector_t > RHS)
unsigned int nLHS_m
last N LHS's for extrapolating the new LHS as starting vector
Teuchos::RCP< const Comm_t > comm_mp
communicator used by Trilinos
bool verbose_m
flag specifying if we are verbose
void resizeMesh(Vector_t &origin, Vector_t &hr, const Vector_t &rmin, const Vector_t &rmax, double dh)
MGPoissonSolver(PartBunch *beam, Mesh_t *mesh, FieldLayout_t *fl, std::vector< BoundaryGeometry * > geometries, std::string itsolver, std::string interpl, double tol, int maxiters, std::string precmode)
BoundaryGeometry * currentGeometry
holding the currently active geometry
Tpetra::Operator TpetraOperator_t
Belos::SolverManager< TpetraScalar_t, TpetraMultiVector_t, TpetraOperator_t > SolverManager_t
Vektor< int, 3 > orig_nr_m
global number of mesh points in each direction
Teuchos::RCP< TpetraMap_t > map_p
Map holding the processor distribution of data.
Teuchos::RCP< SolverManager_t > solver_mp
Tpetra::Map TpetraMap_t
double getZRangeMin(unsigned short)
IpplTimings::TimerRef FunctionTimer6_m
Belos::LinearProblem< TpetraScalar_t, TpetraMultiVector_t, TpetraOperator_t > LinearProblem_t
Teuchos::RCP< TpetraMultiVector_t > P_mp
IpplTimings::TimerRef FunctionTimer8_m
Teuchos::RCP< TpetraVector_t > RHS
right hand side of our problem
IpplTimings::TimerRef FunctionTimer1_m
Teuchos::ParameterList MueLuList_m
parameter list for the MueLu solver
void test(PartBunchBase< double, 3 > *)
std::vector< BoundaryGeometry * > geometries_m
container for multiple geometries
Teuchos::RCP< TpetraCrsMatrix_t > A
matrix used in the linear system of equations
std::unique_ptr< IrregularDomain > bp_m
structure that holds boundary points
Definition: Centering.h:32
Definition: Inform.h:42
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176