ThunderEgg  1.0.0
DirectInterpolator.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) 2018-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_DRCTINTP_H
22 #define THUNDEREGG_GMG_DRCTINTP_H
23 
29 #include <ThunderEgg/Domain.h>
32 #include <memory>
33 
34 namespace ThunderEgg::GMG {
40 template<int D>
42 {
43 public:
51  DirectInterpolator(const Domain<D>& coarse_domain, const Domain<D>& fine_domain)
52  : MPIInterpolator<D>(coarse_domain, fine_domain)
53  {}
59  DirectInterpolator<D>* clone() const override { return new DirectInterpolator<D>(*this); }
61  const std::vector<std::pair<int, std::reference_wrapper<const PatchInfo<D>>>>& patches,
62  const Vector<D>& coarser_vector,
63  Vector<D>& finer_vector) const override
64  {
65  for (auto pair : patches) {
66  const PatchInfo<D>& pinfo = pair.second.get();
67  PatchView<const double, D> coarse_view = coarser_vector.getPatchView(pair.first);
68  PatchView<double, D> fine_view = finer_vector.getPatchView(pinfo.local_index);
69 
70  if (pinfo.hasCoarseParent()) {
71  Orthant<D> orth = pinfo.orth_on_parent;
72  std::array<int, D> starts;
73  for (size_t i = 0; i < D; i++) {
74  starts[i] = orth.isLowerOnAxis(i) ? 0 : (coarse_view.getEnd()[i] + 1);
75  }
76 
77  Loop::OverInteriorIndexes<D + 1>(fine_view, [&](const std::array<int, D + 1>& coord) {
78  std::array<int, D + 1> coarse_coord;
79  for (size_t x = 0; x < D; x++) {
80  coarse_coord[x] = (coord[x] + starts[x]) / 2;
81  }
82  coarse_coord[D] = coord[D];
83  fine_view[coord] += coarse_view[coarse_coord];
84  });
85  } else {
86  Loop::OverInteriorIndexes<D + 1>(fine_view, [&](const std::array<int, D + 1>& coord) {
87  fine_view[coord] += coarse_view[coord];
88  });
89  }
90  }
91  }
92 };
93 extern template class DirectInterpolator<2>;
94 extern template class DirectInterpolator<3>;
95 } // namespace ThunderEgg::GMG
96 #endif
ThunderEgg::Orthant
An enum-style class that represents the octants of a cube.
Definition: Orthant.h:43
ThunderEgg::PatchInfo::orth_on_parent
Orthant< D > orth_on_parent
The orthant of the parent that this parent resides on.
Definition: PatchInfo.h:113
ThunderEgg::GMG::DirectInterpolator::clone
DirectInterpolator< D > * clone() const override
Clone this interpolator.
Definition: DirectInterpolator.h:59
ThunderEgg::Domain
Uses a collection of PatchInfo objects to represent the domain of the problem.
Definition: Domain.h:50
ThunderEgg::PatchInfo::local_index
int local_index
The local index of the patch in the Domain.
Definition: PatchInfo.h:69
ThunderEgg::GMG::DirectInterpolator::DirectInterpolator
DirectInterpolator(const Domain< D > &coarse_domain, const Domain< D > &fine_domain)
Create new DirectInterpolator object.
Definition: DirectInterpolator.h:51
ThunderEgg::PatchView
View for accessing data of a patch. It supports variable striding.
Definition: PatchView.h:37
ThunderEgg::GMG::DirectInterpolator::interpolatePatches
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 override
Interpolate values from coarse vector to the finer vector.
Definition: DirectInterpolator.h:60
ThunderEgg::View< T, D+1 >::getEnd
const std::array< int, D > & getEnd() const
Get the coordinate of the last element.
Definition: View.h:211
ThunderEgg::PatchInfo
Contains metadata for a patch.
Definition: PatchInfo.h:51
InterLevelComm.h
InterLevelComm class.
Domain.h
Domain class.
ThunderEgg::GMG::DirectInterpolator
Directly places values from coarse cell into the corresponding fine cells.
Definition: DirectInterpolator.h:41
ThunderEgg::GMG::MPIInterpolator
Base class that makes the necessary mpi calls, derived classes only have to implement interpolatePatc...
Definition: MPIInterpolator.h:38
ThunderEgg::Vector::getPatchView
PatchView< double, D > getPatchView(int patch_local_index)
Get the View objects for the specified patch index of View object will correspond to component index.
Definition: Vector.h:358
ThunderEgg::Vector
Vector class for use in thunderegg.
Definition: Vector.h:42
MPIInterpolator.h
MPIInterpolator class.
ThunderEgg::GMG
Geometric-Multigrid classes.
Definition: Cycle.h:33
ThunderEgg::PatchInfo::hasCoarseParent
bool hasCoarseParent() const
Return whether the patch has a coarser parent.
Definition: PatchInfo.h:303