53 #include <Tpetra_Import.hpp>
54 #include <BelosTpetraAdapter.hpp>
57 #include "TpetraExt_MatrixMatrix.hpp"
60 #include "Teuchos_CommandLineProcessor.hpp"
62 #include "BelosLinearProblem.hpp"
63 #include "BelosRCGSolMgr.hpp"
64 #include "BelosBlockCGSolMgr.hpp"
65 #include "BelosBiCGStabSolMgr.hpp"
66 #include "BelosBlockGmresSolMgr.hpp"
67 #include "BelosGCRODRSolMgr.hpp"
69 #include <MueLu_CreateTpetraPreconditioner.hpp>
80 std::vector<BoundaryGeometry *> geometries,
86 : isMatrixfilled_m(false)
88 , geometries_m(geometries)
90 , maxiters_m(maxiters)
99 for (
int i = 0; i < 3; i++) {
118 bp_m = std::unique_ptr<IrregularDomain>(
122 bp_m = std::unique_ptr<IrregularDomain>(
131 bp_m = std::unique_ptr<IrregularDomain>(
138 if (localId[0].length() !=
domain_m[0].length() ||
139 localId[1].length() !=
domain_m[1].length()) {
141 "The class ArbitraryDomain only works with parallelization\n"
143 "Please set PARFFTX=FALSE, PARFFTY=FALSE, PARFFTT=TRUE in \n"
144 "the definition of the field solver in the input file.\n");
148 bp_m = std::unique_ptr<IrregularDomain>(
152 map_p = Teuchos::null;
167 if (itsolver ==
"CG") {
177 }
else if (itsolver ==
"BICGSTAB") {
182 }
else if (itsolver ==
"GMRES") {
209 map_p = Teuchos::null;
224 throw OpalException(
"MGPoissonSolver",
"not implemented yet");
243 if (Teuchos::is_null(
LHS)){
248 Tpetra::Import<> importer(
map_p,
LHS->getMap());
249 tmplhs->doImport(*
LHS, importer, Tpetra::CombineMode::ADD);
257 for (
int i = 0; i <
n; ++i) {
259 Tpetra::Import<> importer(
map_p, it->getMap());
260 tmplhs.doImport(*it, importer, Tpetra::CombineMode::ADD);
270 else if (
OldLHS.size() == 1)
272 else if (
OldLHS.size() == 2)
273 LHS->update(2.0, *it++, -1.0, *it, 0.0);
274 else if (
OldLHS.size() > 2) {
277 for (
int i = 0; i <
n; ++i) {
278 *(
P_mp->getVectorNonConst(i)) = *it++;
280 for (
int k = 1; k <
n; ++k) {
281 for (
int i = 0; i < n - k; ++i) {
282 P_mp->getVectorNonConst(i)->update(-(i + 1) / (
float)k, *(
P_mp->getVector(i + 1)), (i + k + 1) / (float)k);
288 "Invalid number of old LHS: " + std::to_string(
OldLHS.size()));
310 bp_m->compute(hr, localId);
321 if (Teuchos::is_null(
RHS))
337 msg <<
"* Node:" <<
Ippl::myNode() <<
", Rho for final element: "
338 << rho[localId[0].last()][localId[1].last()][localId[2].last()].get()
342 msg <<
"* Node:" <<
Ippl::myNode() <<
", Local nx*ny*nz = "
343 << localId[2].last() * localId[0].last() * localId[1].last()
346 <<
", Number of reserved local elements in RHS: "
347 <<
RHS->getLocalLength() <<
endl;
349 <<
", Number of reserved global elements in RHS: "
350 <<
RHS->getGlobalLength() <<
endl;
353 for (
int idz = localId[2].first(); idz <= localId[2].last(); idz++) {
354 for (
int idy = localId[1].first(); idy <= localId[1].last(); idy++) {
355 for (
int idx = localId[0].first(); idx <= localId[0].last(); idx++) {
357 if (
bp_m->isInside(idx, idy, idz))
358 RHS->replaceGlobalValue(
bp_m->getIdx(idx, idy, idz),
368 <<
", Number of Local Inside Points " <<
id <<
endl;
375 #if defined(__clang__)
376 # pragma clang diagnostic push
377 # pragma clang diagnostic warning "-Wdeprecated-declarations"
379 if (Teuchos::is_null(
A))
381 #if defined(__clang__)
382 # pragma clang diagnostic pop
389 Tpetra::MatrixMarket::Writer<TpetraCrsMatrix_t>::writeSparseFile(
390 "DiscrStencil.dat",
A);
395 if (Teuchos::is_null(
prec_mp)) {
396 Teuchos::RCP<TpetraOperator_t> At = Teuchos::rcp_dynamic_cast<
TpetraOperator_t>(
A);
403 MueLu::ReuseTpetraPreconditioner(
A, *
prec_mp);
408 Teuchos::RCP<TpetraOperator_t> At = Teuchos::rcp_dynamic_cast<
TpetraOperator_t>(
A);
432 ERRORMSG(
"Belos::LinearProblem failed to set up correctly!" <<
endl);
438 double time = MPI_Wtime();
447 std::ofstream timings;
449 time = MPI_Wtime() - time;
450 double minTime = 0, maxTime = 0, avgTime = 0;
451 reduce(time, minTime, 1, std::less<double>());
452 reduce(time, maxTime, 1, std::greater<double>());
453 reduce(time, avgTime, 1, std::plus<double>());
457 snprintf(filename,
sizeof(filename),
458 "timing_MX%d_MY%d_MZ%d_nProc%d_recB%d_numB%d_nLHS%d",
462 timings.open(filename, std::ios::app);
463 timings <<
solver_mp->getNumIters() <<
"\t"
468 << numBlocks_m <<
"\t"
486 for (
int idz = localId[2].first(); idz <= localId[2].last(); idz++) {
487 for (
int idy = localId[1].first(); idy <= localId[1].last(); idy++) {
488 for (
int idx = localId[0].first(); idx <= localId[0].last(); idx++) {
490 if (
bp_m->isInside(idx, idy, idz))
508 int NumMyElements = 0;
509 std::vector<TpetraGlobalOrdinal_t> MyGlobalElements;
511 for (
int idz = localId[2].first(); idz <= localId[2].last(); idz++) {
512 for (
int idy = localId[1].first(); idy <= localId[1].last(); idy++) {
513 for (
int idx = localId[0].first(); idx <= localId[0].last(); idx++) {
514 if (
bp_m->isInside(idx, idy, idz)) {
515 MyGlobalElements.push_back(
bp_m->getIdx(idx, idy, idz));
523 map_p = Teuchos::rcp(
new TpetraMap_t(Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),
524 &MyGlobalElements[0], NumMyElements, indexbase,
comm_mp));
530 A->setAllToScalar(0.0);
532 #if defined(__clang__)
533 # pragma clang diagnostic push
534 # pragma clang diagnostic warning "-Wdeprecated-declarations"
536 int NumMyElements =
map_p->getLocalNumElements();
537 #if defined(__clang__)
538 # pragma clang diagnostic pop
541 auto MyGlobalElements =
map_p->getMyGlobalIndices();
543 std::vector<TpetraScalar_t> Values(6);
544 std::vector<TpetraGlobalOrdinal_t> Indices(6);
549 for (
int i = 0 ; i < NumMyElements ; i++) {
553 double scaleFactor=1.0;
555 bp_m->getBoundaryStencil(MyGlobalElements[i], value, scaleFactor);
556 RHS->scale(scaleFactor);
558 bp_m->getNeighbours(MyGlobalElements[i], index);
559 if (index.
east != -1) {
560 Indices[NumEntries] = index.
east;
561 Values[NumEntries++] = value.
east;
563 if (index.
west != -1) {
564 Indices[NumEntries] = index.
west;
565 Values[NumEntries++] = value.
west;
567 if (index.
south != -1) {
568 Indices[NumEntries] = index.
south;
569 Values[NumEntries++] = value.
south;
571 if (index.
north != -1) {
572 Indices[NumEntries] = index.
north;
573 Values[NumEntries++] = value.
north;
575 if (index.
front != -1) {
576 Indices[NumEntries] = index.
front;
577 Values[NumEntries++] = value.
front;
579 if (index.
back != -1) {
580 Indices[NumEntries] = index.
back;
581 Values[NumEntries++] = value.
back;
589 A->replaceGlobalValues(MyGlobalElements[i], NumEntries, &Values[0], &Indices[0]);
591 A->replaceGlobalValues(MyGlobalElements[i], 1, &value.
center, &MyGlobalElements[i]);
594 A->insertGlobalValues(MyGlobalElements[i], NumEntries, &Values[0], &Indices[0]);
596 A->insertGlobalValues(MyGlobalElements[i], 1, &value.
center, &MyGlobalElements[i]);
600 RCP<ParameterList_t> params = Teuchos::parameterList();
601 params->set (
"Optimize Storage",
true);
602 A->fillComplete(params);
610 #if defined(__clang__)
611 # pragma clang diagnostic push
612 # pragma clang diagnostic warning "-Wdeprecated-declarations"
614 size_t myNumPart =
map_p->getLocalNumElements();
615 size_t NumPart =
map_p->getGlobalNumElements() * 1.0 /
comm_mp->getSize();
616 #if defined(__clang__)
617 # pragma clang diagnostic pop
619 double imbalance = 1.0;
620 if (myNumPart >= NumPart)
621 imbalance += (myNumPart - NumPart) / NumPart;
623 imbalance += (NumPart - myNumPart) / NumPart;
625 double max = 0.0,
min = 0.0, avg = 0.0;
626 size_t minn = 0,
maxn = 0;
627 reduce(imbalance,
min, 1, std::less<double>());
628 reduce(imbalance, max, 1, std::greater<double>());
629 reduce(imbalance, avg, 1, std::plus<double>());
630 reduce(myNumPart, minn, 1, std::less<size_t>());
631 reduce(myNumPart,
maxn, 1, std::greater<size_t>());
634 *
gmsg <<
"LBAL min = " <<
min <<
", max = " << max <<
", avg = " << avg <<
endl;
635 *
gmsg <<
"min nr gridpoints = " << minn <<
", max nr gridpoints = " <<
maxn <<
endl;
647 belosList.set(
"Verbosity", Belos::Errors + Belos::Warnings +
648 Belos::TimingDetails + Belos::FinalSummary +
649 Belos::StatusTestDetails);
652 belosList.set(
"Verbosity", Belos::Errors + Belos::Warnings);
665 MueLuList_m.set(
"coarse: max size", coarsest_size);
670 MueLuList_m.set(
"filtered matrix: reuse eigenvalue",
false);
673 MueLuList_m.set(
"repartition: rebalance P and R",
false);
674 MueLuList_m.set(
"repartition: partitioner",
"zoltan2");
675 MueLuList_m.set(
"repartition: min rows per proc", 800);
680 Teuchos::ParameterList smparms;
681 smparms.set(
"chebyshev: degree", 3);
682 smparms.set(
"chebyshev: assume matrix does not change",
false);
683 smparms.set(
"chebyshev: zero starting solution",
true);
684 smparms.set(
"relaxation: sweeps", 3);
714 os <<
"* *************** M G P o i s s o n S o l v e r ************************************ " <<
endl;
715 os <<
"* h " <<
hr_m <<
'\n';
716 os <<
"* ********************************************************************************** " <<
endl;
Vector_t hr_m
mesh spacings in each direction
Tpetra::CrsMatrix TpetraCrsMatrix_t
constexpr double c
The velocity of light in m/s.
Teuchos::RCP< TpetraVector_t > LHS
left hand side of the linear system of equations we solve
int numBlocks_m
maximum number of blocks in Krylov space
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
IpplTimings::TimerRef FunctionTimer6_m
std::unique_ptr< IrregularDomain > bp_m
structure that holds boundary points
Teuchos::RCP< TpetraMap_t > map_p
Map holding the processor distribution of data.
T & localElement(const NDIndex< Dim > &) const
IpplTimings::TimerRef FunctionTimer2_m
IpplTimings::TimerRef FunctionTimer4_m
void printLoadBalanceStats()
useful load balance information
IpplTimings::TimerRef FunctionTimer7_m
double tol_m
tolerance for the iterative solver
IpplTimings::TimerRef FunctionTimer8_m
void setupMueLuList()
Setup the parameters for the SAAMG preconditioner.
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)
long long getLocalTrackStep() const
Teuchos::RCP< LinearProblem_t > problem_mp
void computeMap(NDIndex< 3 > localId)
recomputes the map
IpplTimings::TimerRef FunctionTimer3_m
Vektor< int, 3 > orig_nr_m
global number of mesh points in each direction
virtual Vector_t get_hr() const
Tpetra::Vector TpetraVector_t
Inform & endl(Inform &inf)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Teuchos::ParameterList MueLuList_m
parameter list for the MueLu solver
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
static void startTimer(TimerRef t)
std::string::iterator iterator
std::string getFilename() const
Teuchos::RCP< TpetraMultiVector_t > P_mp
Teuchos::RCP< SolverManager_t > solver_mp
int numBlocks
RCG: cycle length.
static Communicate * Comm
The base class for all OPAL exceptions.
NDIndex< Dim > getLocalNDIndex()
IpplTimings::TimerRef FunctionTimer5_m
IpplTimings::TimerRef FunctionTimer1_m
Teuchos::RCP< MueLuTpetraOperator_t > prec_mp
MueLu preconditioner object.
void IPPLToMap3D(NDIndex< 3 > localId)
bool verbose_m
flag specifying if we are verbose
static Track * block
The block of track data.
void setupBelosList()
Setup the parameters for the Belos iterative solver.
Teuchos::RCP< TpetraVector_t > RHS
right hand side of our problem
int nLHS
number of old left hand sides used to extrapolate a new start vector
int recycleBlocks_m
number of vectors in recycle space
Tpetra::Vector::scalar_type TpetraScalar_t
Topology getTopology() const
Teuchos::RCP< const Comm_t > comm_mp
communicator used by Trilinos
Teuchos::MpiComm< int > Comm_t
int recycleBlocks
RCG: number of recycle blocks.
MFLOAT get_meshSpacing(unsigned d) const
std::vector< BoundaryGeometry * > geometries_m
container for multiple geometries
std::deque< TpetraVector_t > OldLHS
int maxiters_m
maximal number of iterations for the iterative solver
Vektor< int, 3 > nr_m
current number of mesh points in each direction
Teuchos::ParameterList belosList
parameter list for the iterative solver (Belos)
Inform & level3(Inform &inf)
static TimerRef getTimer(const char *nm)
Tpetra::Operator TpetraOperator_t
static void stopTimer(TimerRef t)
void computePotential(Field_t &rho, Vector_t hr)
Inform & print(Inform &os) const
const NDIndex< Dim > & getDomain() const
Teuchos::RCP< TpetraCrsMatrix_t > A
matrix used in the linear system of equations
void ComputeStencil(Vector_t hr, Teuchos::RCP< TpetraVector_t > RHS)
int precmode_m
preconditioner mode
Tpetra::MultiVector TpetraMultiVector_t
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
unsigned int nLHS_m
last N LHS's for extrapolating the new LHS as starting vector
BoundaryGeometry * currentGeometry
holding the currently active geometry
PartBunch * itsBunch_m
PartBunch object.