ThunderEgg  1.0.0
MPIInterpolator.h
Go to the documentation of this file.
1 /***************************************************************************
2  * ThunderEgg, a library for solvers on adaptively refined block-structured
3  * Cartesian grids.
4  *
5  * Copyright (c) 2020-2021 Scott Aiton
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  ***************************************************************************/
20 
21 #ifndef THUNDEREGG_GMG_MPIINTERPOLATOR_H
22 #define THUNDEREGG_GMG_MPIINTERPOLATOR_H
23 
28 #include <ThunderEgg/Domain.h>
31 #include <ThunderEgg/GMG/Level.h>
32 namespace ThunderEgg::GMG {
37 template<int D>
38 class MPIInterpolator : public Interpolator<D>
39 {
40 private:
44  mutable InterLevelComm<D> ilc;
45 
46 public:
52  MPIInterpolator(const Domain<D>& coarser_domain, const Domain<D>& finer_domain)
53  : ilc(coarser_domain, finer_domain)
54  {}
68  virtual void interpolatePatches(
69  const std::vector<std::pair<int, std::reference_wrapper<const PatchInfo<D>>>>& patches,
70  const Vector<D>& coarser_vector,
71  Vector<D>& finer_vector) const = 0;
72 
79  void interpolate(const Vector<D>& coarse, Vector<D>& fine) const
80  {
81  if constexpr (ENABLE_DEBUG) {
82  if (coarse.getNumLocalPatches() != ilc.getCoarserDomain().getNumLocalPatches()) {
83  throw RuntimeError("coarse vector is incorrect length. Expected Length of " +
84  std::to_string(ilc.getCoarserDomain().getNumLocalPatches()) +
85  " but vector was length " + std::to_string(coarse.getNumLocalPatches()));
86  }
87  if (fine.getNumLocalPatches() != ilc.getFinerDomain().getNumLocalPatches()) {
88  throw RuntimeError("fine vector is incorrect length. Expected Length of " +
89  std::to_string(ilc.getFinerDomain().getNumLocalPatches()) +
90  " but vector was length " + std::to_string(fine.getNumLocalPatches()));
91  }
92  }
93  Vector<D> coarse_ghost = ilc.getNewGhostVector(coarse.getNumComponents());
94 
95  // start scatter for ghost values
96  ilc.getGhostPatchesStart(coarse, coarse_ghost);
97 
98  // interpolate form local values
99  interpolatePatches(ilc.getPatchesWithLocalParent(), coarse, fine);
100 
101  // finish scatter for ghost values
102  ilc.getGhostPatchesFinish(coarse, coarse_ghost);
103 
104  // interpolator from ghost values
105  interpolatePatches(ilc.getPatchesWithGhostParent(), coarse_ghost, fine);
106  }
107 };
108 } // namespace ThunderEgg::GMG
109 // explicit instantiation
110 extern template class ThunderEgg::GMG::MPIInterpolator<2>;
111 extern template class ThunderEgg::GMG::MPIInterpolator<3>;
112 #endif
ThunderEgg::GMG::InterLevelComm
Facilitates communication between a finer domain and a coarser domain.
Definition: InterLevelComm.h:52
ThunderEgg::GMG::InterLevelComm::getPatchesWithGhostParent
const std::vector< std::pair< int, std::reference_wrapper< const PatchInfo< D > > > > & getPatchesWithGhostParent() const
Get the vector of finer patches that have a ghost parent.
Definition: InterLevelComm.h:276
ThunderEgg::GMG::MPIInterpolator::interpolatePatches
virtual void interpolatePatches(const std::vector< std::pair< int, std::reference_wrapper< const PatchInfo< D >>>> &patches, const Vector< D > &coarser_vector, Vector< D > &finer_vector) const =0
Interpolate values from coarse vector to the finer vector.
ThunderEgg::Domain
Uses a collection of PatchInfo objects to represent the domain of the problem.
Definition: Domain.h:50
Level.h
Level class.
Interpolator.h
Interpolator class.
ThunderEgg::GMG::InterLevelComm::getGhostPatchesFinish
void getGhostPatchesFinish(const Vector< D > &vector, Vector< D > &ghost_vector)
Finish the communication for getting ghost values.
Definition: InterLevelComm.h:516
ThunderEgg::GMG::InterLevelComm::getFinerDomain
const Domain< D > & getFinerDomain() const
Get the finer Domain.
Definition: InterLevelComm.h:580
ThunderEgg::GMG::MPIInterpolator::MPIInterpolator
MPIInterpolator(const Domain< D > &coarser_domain, const Domain< D > &finer_domain)
Create new MPIInterpolator object.
Definition: MPIInterpolator.h:52
ThunderEgg::PatchInfo
Contains metadata for a patch.
Definition: PatchInfo.h:51
InterLevelComm.h
InterLevelComm class.
ThunderEgg::GMG::Interpolator
Abstract class for interpolation operators.
Definition: Interpolator.h:35
Domain.h
Domain class.
ThunderEgg::GMG::InterLevelComm::getPatchesWithLocalParent
const std::vector< std::pair< int, std::reference_wrapper< const PatchInfo< D > > > > & getPatchesWithLocalParent() const
Get the vector of finer patches that have a local parent.
Definition: InterLevelComm.h:260
ThunderEgg::GMG::InterLevelComm::getCoarserDomain
const Domain< D > & getCoarserDomain() const
Get the coarser Domain.
Definition: InterLevelComm.h:574
ThunderEgg::GMG::MPIInterpolator
Base class that makes the necessary mpi calls, derived classes only have to implement interpolatePatc...
Definition: MPIInterpolator.h:38
ThunderEgg::Vector
Vector class for use in thunderegg.
Definition: Vector.h:42
ThunderEgg::GMG
Geometric-Multigrid classes.
Definition: Cycle.h:33
ThunderEgg::Vector::getNumLocalPatches
int getNumLocalPatches() const
Get the number of local patches.
Definition: Vector.h:316
ThunderEgg::GMG::MPIInterpolator::interpolate
void interpolate(const Vector< D > &coarse, Vector< D > &fine) const
interpolation function
Definition: MPIInterpolator.h:79
ThunderEgg::GMG::InterLevelComm::getNewGhostVector
Vector< D > getNewGhostVector(int num_components) const
Allocate a new vector for ghost patch values.
Definition: InterLevelComm.h:243
ThunderEgg::RuntimeError
ThunderEgg runtime exception.
Definition: RuntimeError.h:36
ThunderEgg::GMG::InterLevelComm::getGhostPatchesStart
void getGhostPatchesStart(const Vector< D > &vector, Vector< D > &ghost_vector)
Start the communication for getting ghost values.
Definition: InterLevelComm.h:437