ThunderEgg  1.0.0
PatchOperator.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) 2019-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_PATCHOPERATOR_H
22 #define THUNDEREGG_PATCHOPERATOR_H
23 
28 #include <ThunderEgg/Domain.h>
29 #include <ThunderEgg/GhostFiller.h>
30 #include <ThunderEgg/Operator.h>
31 #include <ThunderEgg/Vector.h>
32 namespace ThunderEgg {
39 template<int D>
40 class PatchOperator : public Operator<D>
41 {
42 private:
46  Domain<D> domain;
50  std::shared_ptr<const GhostFiller<D>> ghost_filler;
51 
52 public:
61  PatchOperator(const Domain<D>& domain, const GhostFiller<D>& ghost_filler)
62  : domain(domain)
63  , ghost_filler(ghost_filler.clone())
64  {}
70  virtual PatchOperator<D>* clone() const override = 0;
74  virtual ~PatchOperator() {}
75 
85  virtual void applySinglePatch(const PatchInfo<D>& pinfo,
86  const PatchView<const double, D>& u_view,
87  const PatchView<double, D>& f_view) const = 0;
88 
100  virtual void modifyRHSForInternalBoundaryConditions(const PatchInfo<D>& pinfo,
101  const PatchView<const double, D>& u_view,
102  const PatchView<double, D>& f_view) const = 0;
103 
114  const PatchInfo<D>& pinfo,
115  const PatchView<const double, D>& u_view,
116  const PatchView<double, D>& f_view) const = 0;
117 
126  void apply(const Vector<D>& u, Vector<D>& f) const override
127  {
128  if constexpr (ENABLE_DEBUG) {
129  if (u.getNumLocalPatches() != domain.getNumLocalPatches()) {
130  throw RuntimeError("u vector is incorrect length");
131  }
132  if (f.getNumLocalPatches() != domain.getNumLocalPatches()) {
133  throw RuntimeError("f vector is incorrect length");
134  }
135  }
136  f.setWithGhost(0);
137  ghost_filler->fillGhost(u);
138  for (const PatchInfo<D>& pinfo : domain.getPatchInfoVector()) {
139  PatchView<const double, D> u_view = u.getPatchView(pinfo.local_index);
140  PatchView<double, D> f_view = f.getPatchView(pinfo.local_index);
141  applySinglePatch(pinfo, u_view, f_view);
142  }
143  }
147  const Domain<D>& getDomain() const { return domain; }
151  const GhostFiller<D>& getGhostFiller() const { return *ghost_filler; }
152 };
153 } // namespace ThunderEgg
154 extern template class ThunderEgg::PatchOperator<2>;
155 extern template class ThunderEgg::PatchOperator<3>;
156 #endif
ThunderEgg::PatchOperator::PatchOperator
PatchOperator(const Domain< D > &domain, const GhostFiller< D > &ghost_filler)
Construct a new Patch Operator object.
Definition: PatchOperator.h:61
Vector.h
Vector class.
Operator.h
Operator class.
ThunderEgg::PatchOperator::modifyRHSForInternalBoundaryConditions
virtual void modifyRHSForInternalBoundaryConditions(const PatchInfo< D > &pinfo, const PatchView< const double, D > &u_view, const PatchView< double, D > &f_view) const =0
Treat the internal patch boundaries as domain boundaires and modify RHS accordingly.
ThunderEgg::Domain
Uses a collection of PatchInfo objects to represent the domain of the problem.
Definition: Domain.h:50
ThunderEgg::Domain::getNumLocalPatches
int getNumLocalPatches() const
Get the number of local patches.
Definition: Domain.h:272
ThunderEgg::PatchOperator::applySinglePatch
virtual void applySinglePatch(const PatchInfo< D > &pinfo, const PatchView< const double, D > &u_view, const PatchView< double, D > &f_view) const =0
Apply the operator to a single patch.
ThunderEgg::PatchOperator::applySinglePatchWithInternalBoundaryConditions
virtual void applySinglePatchWithInternalBoundaryConditions(const PatchInfo< D > &pinfo, const PatchView< const double, D > &u_view, const PatchView< double, D > &f_view) const =0
Apply the operator to a single patch.
ThunderEgg::PatchView
View for accessing data of a patch. It supports variable striding.
Definition: PatchView.h:37
ThunderEgg
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31
GhostFiller.h
GhostFiller class.
ThunderEgg::GhostFiller
Fills ghost cells on patches.
Definition: GhostFiller.h:36
ThunderEgg::PatchInfo
Contains metadata for a patch.
Definition: PatchInfo.h:51
ThunderEgg::Vector::setWithGhost
void setWithGhost(double alpha)
set all values in the vector (including ghost cells)
Definition: Vector.h:404
Domain.h
Domain class.
ThunderEgg::PatchOperator::getDomain
const Domain< D > & getDomain() const
Get the Domain object associated with this PatchOperator.
Definition: PatchOperator.h:147
ThunderEgg::PatchOperator
This is an Operator where derived classes only have to implement the two virtual functions that opera...
Definition: PatchOperator.h:40
ThunderEgg::PatchOperator::getGhostFiller
const GhostFiller< D > & getGhostFiller() const
Get the GhostFiller object associated with this PatchOperator.
Definition: PatchOperator.h:151
ThunderEgg::Operator
Base class for operators.
Definition: Operator.h:37
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::PatchOperator::clone
virtual PatchOperator< D > * clone() const override=0
Clone this patch operator.
ThunderEgg::Vector
Vector class for use in thunderegg.
Definition: Vector.h:42
ThunderEgg::PatchOperator::apply
void apply(const Vector< D > &u, Vector< D > &f) const override
Apply the operator.
Definition: PatchOperator.h:126
ThunderEgg::Domain::getPatchInfoVector
const std::vector< PatchInfo< D > > & getPatchInfoVector() const
Get a vector of PatchInfo pointers where index in the vector corresponds to the patch's local index.
Definition: Domain.h:259
ThunderEgg::PatchOperator::~PatchOperator
virtual ~PatchOperator()
Destroy the PatchOperator object.
Definition: PatchOperator.h:74
ThunderEgg::Vector::getNumLocalPatches
int getNumLocalPatches() const
Get the number of local patches.
Definition: Vector.h:316
ThunderEgg::RuntimeError
ThunderEgg runtime exception.
Definition: RuntimeError.h:36