Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
AnyTaggingMethod.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #ifndef FUB_TAGGING_METHOD_HPP
22 #define FUB_TAGGING_METHOD_HPP
23 
24 #include "fub/Direction.hpp"
25 #include "fub/Duration.hpp"
26 #include "fub/Meta.hpp"
27 
28 #include <memory>
29 
30 namespace fub {
31 
32 /// \defgroup TaggingMethod Tagging Methods
33 /// \ingroup GriddingAlgorithm
34 /// This modules collects all components that tag cells for refinement.
35 
36 template <typename GriddingAlgorithm> struct TaggingMethodStrategy_ {
38  virtual ~TaggingMethodStrategy_() = default;
39  virtual std::unique_ptr<TaggingMethodStrategy_> Clone() const = 0;
41  GriddingAlgorithm& gridding, int level,
42  Duration time_point) = 0;
43 };
44 
45 /// \ingroup TaggingMethod PolymorphicValueType
46 /// \brief This class is a polymorphic value type that stores objects which
47 /// satisfies the TaggingMethod<GriddingAlgorithm> concept.
48 template <typename GriddingAlgorithm> class AnyTaggingMethod {
49 public:
51 
52  /// @{
53  /// \name Constructors
54 
55  /// \brief This constructs a method that does nothing on invocation.
56  AnyTaggingMethod() = default;
57 
58  /// \brief Stores any object which satisfies the tagging method concept.
59  template <typename T,
60  typename = std::enable_if_t<!decays_to<T, AnyTaggingMethod>()>>
61  AnyTaggingMethod(T&& tag);
62 
63  /// \brief Copies the implementation.
64  AnyTaggingMethod(const AnyTaggingMethod& other);
65 
66  /// \brief Copies the implementation.
68 
69  /// \brief Moves the `other` object without allocating and leaves an empty
70  /// method.
71  AnyTaggingMethod(AnyTaggingMethod&& other) noexcept = default;
72 
73  /// \brief Moves the `other` object without allocating and leaves an empty
74  /// method.
75  AnyTaggingMethod& operator=(AnyTaggingMethod&& other) noexcept = default;
76  /// @}
77 
78  /// @{
79  /// \name Member functions
80 
81  /// \brief Mask cells that need further refinement in a regridding procedure.
83  int level, Duration t);
84  /// @}
85 
86 private:
87  std::unique_ptr<TaggingMethodStrategy_<GriddingAlgorithm>> tag_;
88 };
89 
90 ///////////////////////////////////////////////////////////////////////////////
91 // Implementation
92 
93 template <typename GriddingAlgorithm, typename T>
95  : public TaggingMethodStrategy_<GriddingAlgorithm> {
97 
98  TaggingMethodWrapper_(const T& tag) : tag_{tag} {}
99  TaggingMethodWrapper_(T&& tag) : tag_{std::move(tag)} {}
100 
102  int level, Duration time_point) override {
103  tag_.TagCellsForRefinement(tags, gridding, level, time_point);
104  }
105 
106  std::unique_ptr<TaggingMethodStrategy_<GriddingAlgorithm>>
107  Clone() const override {
108  return std::make_unique<TaggingMethodWrapper_<GriddingAlgorithm, T>>(tag_);
109  };
110 
111  T tag_;
112 };
113 
114 template <typename GriddingAlgorithm>
116  const AnyTaggingMethod& other)
117  : tag_(other.tag_ ? other.tag_->Clone() : nullptr) {}
118 
119 template <typename GriddingAlgorithm>
122  AnyTaggingMethod tmp(other);
123  return *this = std::move(tmp);
124 }
125 
126 template <typename GriddingAlgorithm>
127 template <typename T, typename>
129  : tag_{std::make_unique<
131  std::forward<T>(tag))} {}
132 
133 template <typename GriddingAlgorithm>
135  TagDataHandle tags, GriddingAlgorithm& gridding, int level,
136  Duration time_point) {
137  if (tag_) {
138  return tag_->TagCellsForRefinement(tags, gridding, level, time_point);
139  }
140 }
141 
142 } // namespace fub
143 
144 #endif
This class is a polymorphic value type that stores objects which satisfies the TaggingMethod<Gridding...
Definition: AnyTaggingMethod.hpp:48
typename GridTraits< GriddingAlgorithm >::TagDataHandle TagDataHandle
Definition: AnyTaggingMethod.hpp:50
AnyTaggingMethod(AnyTaggingMethod &&other) noexcept=default
Moves the other object without allocating and leaves an empty method.
AnyTaggingMethod()=default
This constructs a method that does nothing on invocation.
AnyTaggingMethod & operator=(AnyTaggingMethod &&other) noexcept=default
Moves the other object without allocating and leaves an empty method.
AnyTaggingMethod & operator=(const AnyTaggingMethod &other)
Copies the implementation.
Definition: AnyTaggingMethod.hpp:121
void TagCellsForRefinement(TagDataHandle tags, GriddingAlgorithm &gridding, int level, Duration t)
Mask cells that need further refinement in a regridding procedure.
Definition: AnyTaggingMethod.hpp:134
std::unique_ptr< TaggingMethodStrategy_< GriddingAlgorithm > > tag_
Definition: AnyTaggingMethod.hpp:87
std::decay_t< decltype(*std::declval< T >().GetGriddingAlgorithm())> GriddingAlgorithm
A template typedef to detect the member function.
Definition: Meta.hpp:56
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
typename remove_cvref< T >::type remove_cvref_t
Definition: type_traits.hpp:226
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
Definition: Meta.hpp:67
Definition: AnyTaggingMethod.hpp:36
typename GridTraits< GriddingAlgorithm >::TagDataHandle TagDataHandle
Definition: AnyTaggingMethod.hpp:37
virtual std::unique_ptr< TaggingMethodStrategy_ > Clone() const =0
virtual ~TaggingMethodStrategy_()=default
virtual void TagCellsForRefinement(TagDataHandle tags, GriddingAlgorithm &gridding, int level, Duration time_point)=0
Definition: AnyTaggingMethod.hpp:95
TaggingMethodWrapper_(T &&tag)
Definition: AnyTaggingMethod.hpp:99
std::unique_ptr< TaggingMethodStrategy_< GriddingAlgorithm > > Clone() const override
Definition: AnyTaggingMethod.hpp:107
TaggingMethodWrapper_(const T &tag)
Definition: AnyTaggingMethod.hpp:98
T tag_
Definition: AnyTaggingMethod.hpp:109
void TagCellsForRefinement(TagDataHandle tags, GriddingAlgorithm &gridding, int level, Duration time_point) override
Definition: AnyTaggingMethod.hpp:101