PRISMS-PF Manual
Loading...
Searching...
No Matches
grid_refiner_criterion.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#pragma once
5
6#include <deal.II/base/exceptions.h>
7
9
10#include <prismspf/config.h>
11
12#include <cfloat>
13#include <cstdint>
14#include <string>
15
17
21enum RefinementFlags : std::uint8_t
22{
27
31 Value = 0x0001,
32
36 Gradient = 0x0002,
37};
38
39// Function that enables bitwise OR between flags
40inline constexpr RefinementFlags
41operator|(const RefinementFlags flag_1, const RefinementFlags flag_2)
42{
43 return static_cast<RefinementFlags>(static_cast<unsigned int>(flag_1) |
44 static_cast<unsigned int>(flag_2));
45}
46
47// Function that enables bitwise compound OR between flags
48inline constexpr RefinementFlags &
50{
51 flag_1 = flag_1 | flag_2;
52 return flag_1;
53}
54
55// Function that enables bitwise AND between flags
56inline constexpr RefinementFlags
57operator&(const RefinementFlags flag_1, const RefinementFlags flag_2)
58{
59 return static_cast<RefinementFlags>(static_cast<unsigned int>(flag_1) &
60 static_cast<unsigned int>(flag_2));
61}
62
63// Function that enables bitwise compound AND between flags
64inline constexpr RefinementFlags &
66{
67 flag_1 = flag_1 & flag_2;
68 return flag_1;
69}
70
78{
83 const RefinementFlags &_criterion = RefinementFlags::Nothing,
84 const double &_value_lower_bound = DBL_MAX,
85 const double &_value_upper_bound = DBL_MAX,
86 const double &_gradient_lower_bound = DBL_MAX)
87 : criterion(_criterion)
88 , value_lower_bound(_value_lower_bound)
89 , value_upper_bound(_value_upper_bound)
90 , gradient_lower_bound(_gradient_lower_bound) {};
91
96 [[nodiscard]] bool
97 value_in_open_range(double value) const
98 {
99 return value > value_lower_bound && value < value_upper_bound;
100 }
101
105 [[nodiscard]] bool
106 gradient_magnitude_above_threshold(double gradient_magnitude) const
107 {
108 return gradient_magnitude > gradient_lower_bound;
109 }
110
114 [[nodiscard]] std::string
116 {
118 {
119 return "None";
120 }
121 if (((criterion & RefinementFlags::Value) != 0U) &&
123 {
124 return "Value and gradient";
125 }
126 if ((criterion & RefinementFlags::Value) != 0U)
127 {
128 return "Value";
129 }
131 {
132 return "Gradient";
133 }
134
135 return "Unknown criterion";
136 }
137
139 double value_lower_bound = DBL_MAX;
140 double value_upper_bound = DBL_MAX;
141 double gradient_lower_bound = DBL_MAX;
142};
143
144PRISMS_PF_END_NAMESPACE
constexpr RefinementFlags & operator|=(RefinementFlags &flag_1, const RefinementFlags flag_2)
Definition grid_refiner_criterion.h:49
constexpr RefinementFlags operator|(const RefinementFlags flag_1, const RefinementFlags flag_2)
Definition grid_refiner_criterion.h:41
constexpr RefinementFlags operator&(const RefinementFlags flag_1, const RefinementFlags flag_2)
Definition grid_refiner_criterion.h:57
RefinementFlags
Flags for refinement criterion.
Definition grid_refiner_criterion.h:22
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
@ Nothing
No adaptive refinement criterion.
Definition grid_refiner_criterion.h:26
@ Gradient
Use gradient of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:36
constexpr RefinementFlags & operator&=(RefinementFlags &flag_1, const RefinementFlags flag_2)
Definition grid_refiner_criterion.h:65
Definition conditional_ostreams.cc:20
RefinementCriterion(const RefinementFlags &_criterion=RefinementFlags::Nothing, const double &_value_lower_bound=DBL_MAX, const double &_value_upper_bound=DBL_MAX, const double &_gradient_lower_bound=DBL_MAX)
Constructor.
Definition grid_refiner_criterion.h:82
std::string criterion_string() const
Convert refinement criterion type to string.
Definition grid_refiner_criterion.h:115
bool value_in_open_range(double value) const
Whether the provided value is in the open range for the value refinement criteria.
Definition grid_refiner_criterion.h:97
double value_lower_bound
Definition grid_refiner_criterion.h:139
bool gradient_magnitude_above_threshold(double gradient_magnitude) const
Whether the provided gradient magnitude is greater than the minimum value.
Definition grid_refiner_criterion.h:106
double value_upper_bound
Definition grid_refiner_criterion.h:140
double gradient_lower_bound
Definition grid_refiner_criterion.h:141
RefinementFlags criterion
Definition grid_refiner_criterion.h:138