21 #ifndef FUB_TAGGING_GRADIENT_DETECTOR_HPP
22 #define FUB_TAGGING_GRADIENT_DETECTOR_HPP
34 template <std::
size_t DestRank, std::
size_t SrcRank>
35 std::array<std::ptrdiff_t, DestRank>
37 if constexpr (DestRank == SrcRank) {
40 std::array<std::ptrdiff_t, DestRank> dest{};
41 std::copy_n(
index.begin(),
static_cast<std::ptrdiff_t
>(SrcRank),
47 template <
typename Proj,
typename State>
49 decltype(std::invoke(std::declval<Proj>(), std::declval<State>()));
51 template <
typename Proj,
typename State>
54 template <
typename Equation,
typename... Projections>
58 const std::pair<Projections, double>&... conds)
64 const std::tuple<std::pair<Projections, double>...>&
GetConditions() const
74 template <
typename Equation,
typename... Projections>
79 const std::pair<Projections, double>&... conds);
81 template <
typename T,
int TagRank>
86 template <
int TagRank>
99 template <
typename Equation,
typename... Projections>
103 static constexpr
int Rank = Equation::Rank();
106 const std::pair<Projections, double>&... conds);
119 template <
bool IsArray,
typename Eq,
typename... Ps>
124 template <
typename Eq,
typename... Ps>
131 template <
typename Eq,
typename... Ps>
134 (IsProjection<Ps&, const CompleteArray<Eq>&>::value && ...), Eq,
142 :
Base(equation, projs...) {}
145 template <
typename Eq,
typename... Ps>
147 ->GradientDetector<Eq, Ps...>;
149 template <
typename Equation,
typename... Projections>
151 const Equation& equation,
const std::pair<Projections, double>&... conds)
152 :
Base(equation, conds...) {}
154 template <
typename Equation,
typename... Projections>
155 template <
typename T,
int TagRank>
161 [[maybe_unused]] constexpr std::size_t sTagRank =
162 static_cast<std::size_t
>(TagRank);
163 const auto tagbox = tags.
Box();
164 for (std::size_t dir = 0; dir < Extents<0>(states).rank(); ++dir) {
167 using Index = std::array<std::ptrdiff_t,
sizeof...(is)>;
168 const Index mid{is...};
169 if (
Contains(tagbox, EmbedInSpace<sTagRank>(mid))) {
172 boost::mp11::tuple_for_each(Base::conditions_, [&](
auto cond) {
173 auto&& [proj, tolerance] = cond;
174 Load(sL, states, left);
175 Load(sM, states, mid);
176 Load(sR, states, right);
177 auto&& xL = std::invoke(proj, sL);
178 auto&& xM = std::invoke(proj, sM);
179 auto&& xR = std::invoke(proj, sR);
180 if (xM != xR || xM != xL) {
182 std::abs(xM - xL) / (std::abs(xM) + std::abs(xL));
184 std::abs(xM - xR) / (std::abs(xM) + std::abs(xR));
185 tags(EmbedInSpace<sTagRank>(mid)) |=
186 static_cast<T
>(left > tolerance || right > tolerance);
194 template <
typename Equation,
typename... Projections>
195 template <
int TagRank>
200 const auto tagbox = tags.
Box();
201 for (std::size_t dir = 0; dir < Extents<0>(states).rank(); ++dir) {
204 using Index = std::array<std::ptrdiff_t,
sizeof...(is)>;
205 const Index mid{is...};
209 if (volumes(left) > 0.0 && volumes(mid) > 0.0 &&
210 volumes(right) > 0.0) {
211 boost::mp11::tuple_for_each(Base::conditions_, [&](
auto cond) {
212 auto&& [proj, tolerance] = cond;
213 Load(sL, states, left);
214 Load(sM, states, mid);
215 Load(sR, states, right);
216 auto&& xL = std::invoke(proj, sL);
217 auto&& xM = std::invoke(proj, sM);
218 auto&& xR = std::invoke(proj, sR);
219 if (xM != xR || xM != xL) {
221 std::abs(xM - xL) / (std::abs(xM) + std::abs(xL));
223 std::abs(xM - xR) / (std::abs(xM) + std::abs(xR));
225 static_cast<char>(left > tolerance || right > tolerance);
234 template <
typename Equation,
typename... Projections>
236 const Equation& equation,
const std::pair<Projections, double>&... conds)
237 :
Base(equation, conds...) {}
239 template <
typename Equation,
typename... Projections>
245 std::tuple views{tags,
Shrink(shifted, dir, {0, 2}),
246 Shrink(shifted, dir, {1, 1}),
Shrink(shifted, dir, {2, 0})};
252 char* tags_pointer = tags_row.
begin();
257 int n =
static_cast<int>(get<0>(pEnd) - get<0>(pR));
268 boost::mp11::tuple_for_each(Base::conditions_, [&](
auto&& condition) {
269 auto&& [proj, tolerance] = condition;
270 const Array1d xL = std::invoke(proj, sL_);
271 const Array1d xM = std::invoke(proj, sM_);
272 const Array1d xR = std::invoke(proj, sR_);
273 const Array1d left = (xM - xL).abs() / (xM.abs() + xL.abs());
274 const Array1d right = (xM - xR).abs() / (xM.abs() + xR.abs());
275 tags_array = (left < tolerance).select(tags_array, ones);
276 tags_array = (right < tolerance).select(tags_array, ones);
281 n =
static_cast<int>(get<0>(pEnd) - get<0>(pR));
287 LoadN(tags_array, tags_pointer, n);
288 boost::mp11::tuple_for_each(Base::conditions_, [&](
auto&& condition) {
289 auto&& [proj, tolerance] = condition;
290 const Array1d xL = std::invoke(proj, sL_);
291 const Array1d xM = std::invoke(proj, sM_);
292 const Array1d xR = std::invoke(proj, sR_);
293 const Array1d left = (xM - xL).abs() / (xM.abs() + xL.abs());
294 const Array1d right = (xM - xR).abs() / (xM.abs() + xR.abs());
295 tags_array = (left < tolerance).select(tags_array, ones);
296 tags_array = (right < tolerance).select(tags_array, ones);
298 StoreN(tags_pointer, tags_array, n);
#define FUB_ASSERT(x)
Definition: assert.hpp:39
Definition: tagging_method/GradientDetector.hpp:101
CompleteArray< Equation > sL_
Definition: tagging_method/GradientDetector.hpp:114
static constexpr int Rank
Definition: tagging_method/GradientDetector.hpp:103
CompleteArray< Equation > sM_
Definition: tagging_method/GradientDetector.hpp:115
ArrayGradientDetector_(const Equation &equation, const std::pair< Projections, double > &... conds)
Definition: tagging_method/GradientDetector.hpp:235
void TagCellsForRefinement(const PatchDataView< char, Rank, layout_stride > &tags, const View< const Complete< Equation >> &states)
Definition: tagging_method/GradientDetector.hpp:240
CompleteArray< Equation > sR_
Definition: tagging_method/GradientDetector.hpp:116
Definition: tagging_method/GradientDetector.hpp:55
Equation & GetEquation() noexcept
Definition: tagging_method/GradientDetector.hpp:61
GradientDetectorBase_(const Equation &equation, const std::pair< Projections, double > &... conds)
Definition: tagging_method/GradientDetector.hpp:57
Equation equation_
Definition: tagging_method/GradientDetector.hpp:70
std::tuple< std::pair< Projections, double >... > conditions_
Definition: tagging_method/GradientDetector.hpp:71
const std::tuple< std::pair< Projections, double >... > & GetConditions() const noexcept
Definition: tagging_method/GradientDetector.hpp:64
const Equation & GetEquation() const noexcept
Definition: tagging_method/GradientDetector.hpp:62
Definition: tagging_method/GradientDetector.hpp:76
void TagCellsForRefinement(const PatchDataView< T, TagRank, layout_stride > &tags, const View< const Complete< Equation >> &states)
Definition: tagging_method/GradientDetector.hpp:156
ScalarGradientDetector_(const Equation &equation, const std::pair< Projections, double > &... conds)
Definition: tagging_method/GradientDetector.hpp:150
Complete< Equation > sR
Definition: tagging_method/GradientDetector.hpp:96
Complete< Equation > sL
Definition: tagging_method/GradientDetector.hpp:94
Complete< Equation > sM
Definition: tagging_method/GradientDetector.hpp:95
A span is a view over a contiguous sequence of objects, the storage of which is owned by some other o...
Definition: span.hpp:81
constexpr iterator begin() const noexcept
Returns an iterator pointing to the first element of the span.
Definition: span.hpp:428
Function ForEachIndex(const layout_left::mapping< Extents > &mapping, Function function)
Iterate through the multi-dimensional index space descibed by mapping and invoke function for each su...
Definition: ForEach.hpp:74
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
auto Shrink(const layout_left::mapping< Extent > &layout, Direction dir, std::ptrdiff_t n=1)
Definition: Equation.hpp:78
std::conditional_t< N==1||M==1, Eigen::Array< T, N, M >, Eigen::Array< T, N, M, Eigen::RowMajor > > Array
Definition: Eigen.hpp:50
View< State > Subview(const BasicView< State, Layout, Rank > &state, const IndexBox< Rank > &box)
Definition: Equation.hpp:86
Array< double, 1 > Array1d
Definition: Eigen.hpp:53
constexpr const int kDefaultChunkSize
Definition: Eigen.hpp:39
GradientDetector(const Eq &, const std::pair< Ps, double > &...) -> GradientDetector< Eq, Ps... >
void StoreN(nodeduce_t< ViewPointer< Conservative< Eq >>> pointer, const ConservativeArray< Eq > &state, int n)
Definition: StateArray.hpp:416
IndexBox< Rank > Grow(const IndexBox< Rank > &box, Direction dir, const std::array< std::ptrdiff_t, 2 > &shifts)
Definition: PatchDataView.hpp:106
void ForEachRow(const Tuple &views, Function f)
Definition: StateRow.hpp:172
void Load(State &state, const BasicView< const State, Layout, Rank > &view, const std::array< std::ptrdiff_t, State::Equation::Rank()> &index)
Definition: State.hpp:640
ViewPointer< State > Begin(const BasicView< State, Layout, Rank > &view)
Definition: State.hpp:769
void LoadN(CompleteArray< Eq, N > &state, const BasicView< const Complete< Eq >, Layout, Rank > &view, int size, nodeduce_t< const std::array< std::ptrdiff_t, std::size_t(Rank)> & > pos)
Definition: StateArray.hpp:310
std::array< std::ptrdiff_t, DestRank > EmbedInSpace(const std::array< std::ptrdiff_t, SrcRank > &index)
Definition: tagging_method/GradientDetector.hpp:36
decltype(std::invoke(std::declval< Proj >(), std::declval< State >())) Projection_t
Definition: tagging_method/GradientDetector.hpp:49
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
void Advance(ViewPointer< State > &pointer, std::ptrdiff_t n) noexcept
Definition: State.hpp:825
std::array< std::ptrdiff_t, static_cast< std::size_t >(Rank)> Index
Definition: PatchDataView.hpp:34
bool Contains(const IndexBox< Rank > &b1, const IndexBox< Rank > &b2)
Definition: PatchDataView.hpp:73
ViewPointer< State > End(const BasicView< State, Layout, Rank > &view)
Definition: State.hpp:782
std::array< std::ptrdiff_t, N > Shift(const std::array< std::ptrdiff_t, N > &idx, Direction dir, std::ptrdiff_t shift)
Definition: PatchDataView.hpp:37
std::ptrdiff_t index
Definition: type_traits.hpp:179
Definition: State.hpp:403
Definition: tagging_method/GradientDetector.hpp:120
This class tags cells with a relative error to their neighbors.
Definition: tagging_method/GradientDetector.hpp:135
static constexpr bool is_array_based
Definition: tagging_method/GradientDetector.hpp:137
GradientDetector(const Eq &equation, const std::pair< Ps, double > &... projs)
Definition: tagging_method/GradientDetector.hpp:141
Definition: PatchDataView.hpp:201
IndexBox< R > Box() const noexcept
Definition: PatchDataView.hpp:232
Definition: StateRow.hpp:51
Definition: State.hpp:750
This is std::true_type if Op<Args...> is a valid SFINAE expression.
Definition: type_traits.hpp:92