6#include <deal.II/base/config.h>
7#include <deal.II/base/exceptions.h>
8#include <deal.II/base/logstream.h>
9#include <deal.II/base/mpi.h>
10#include <deal.II/base/point.h>
11#include <deal.II/base/tensor.h>
12#include <deal.II/base/types.h>
13#include <deal.II/base/utilities.h>
14#include <deal.II/base/vectorization.h>
15#include <deal.II/matrix_free/evaluation_flags.h>
17#include <boost/range/algorithm.hpp>
18#include <boost/range/algorithm_ext.hpp>
22#include <prismspf/config.h>
26#include <unordered_map>
28#ifdef PRISMS_PF_WITH_CALIPER
29# include <caliper/cali-manager.h>
30# include <caliper/cali.h>
43 MPIInitFinalize(
int &argc,
char **&argv,
unsigned int _max_n_threads = 0);
53#ifdef PRISMS_PF_THREADS
54 static constexpr unsigned int max_n_threads = dealii::numbers::invalid_unsigned_int;
62#ifdef PRISMS_PF_WITH_CALIPER
63 cali::ConfigManager mgr;
67template <
typename dealii_vector>
71 for (
const auto index : vec.locally_owned_elements())
73 if (vec[index] == 0.0)
83template <
typename Type>
86 const std::unordered_map<std::string, Type> &table)
88 auto iterator = table.find(
string);
89 AssertThrow(iterator != table.end(),
90 dealii::ExcMessage(
"Unknown table entry: " +
string));
91 return iterator->second;
111template <
typename Type,
typename OtherType>
112std::pair<OtherType, Type>
114 const std::string &
string,
115 const std::unordered_map<std::string, Type> &table,
116 const std::unordered_map<std::string, OtherType> &other_table,
117 const std::pair<char, char> &delimiters = {
'(',
')'})
120 const auto opening_delimiter_position =
string.find(delimiters.first);
121 const auto closing_delimiter_position =
string.find(delimiters.second);
123 bool has_opening_delimiter = opening_delimiter_position != std::string_view::npos;
124 bool has_closing_delimiter = closing_delimiter_position != std::string_view::npos;
127 AssertThrow(closing_delimiter_position >= opening_delimiter_position,
129 "Opening delimiter must precede the closing delimiter. You had " +
131 AssertThrow(has_closing_delimiter == has_opening_delimiter,
132 dealii::ExcMessage(
"You must either have a delimiter pair or not. You seem "
133 "to only have one delimiter. You had " +
137 if (!has_closing_delimiter && !has_opening_delimiter)
141 return {first_type, second_type};
145 AssertThrow(closing_delimiter_position ==
string.size() - 1,
147 "Closing delimiter must be at the end of the string. You had " +
string));
150 std::string_view input_view {
string};
151 std::string_view outer_string = input_view.substr(0, opening_delimiter_position);
152 std::string_view inner_string =
153 input_view.substr(opening_delimiter_position + 1,
154 closing_delimiter_position - opening_delimiter_position - 1);
156 AssertThrow(!outer_string.empty() && !inner_string.empty(),
158 "Inner and outer map entries must not be empty. You had " +
string));
164 const auto second_type =
string_to_type(std::string(outer_string), table);
165 const auto first_type =
string_to_type(std::string(inner_string), other_table);
166 return {first_type, second_type};
173template <
typename Number>
174inline DEAL_II_ALWAYS_INLINE Number
175pmod(
const Number &value,
const Number &modulus)
187template <
unsigned int dim,
unsigned int degree,
typename T>
188inline DEAL_II_ALWAYS_INLINE T
190 const T &element_volume,
191 const dealii::Tensor<1, dim, T> &velocity,
192 const T &kinematic_viscosity)
194 using dealii::Utilities::fixed_power;
198 constexpr auto degree_modifier = T(1) / T(degree);
199 constexpr auto inv_pi = T(1) / T(M_PI);
200 const auto velocity_l2_norm = velocity.norm_square() + T(1e-12);
202 auto element_size = T(0);
203 if constexpr (dim == 1)
205 element_size = element_volume;
207 else if constexpr (dim == 2)
209 element_size = T(2) * sqrt(element_volume * inv_pi);
211 else if constexpr (dim == 3)
213 element_size = cbrt(T(6) * element_volume * inv_pi);
217 Assert(
false, dealii::ExcMessage(
"Invalid dimension for the stabilization term."));
219 element_size *= degree_modifier;
220 const auto element_size_2 = element_size * element_size;
221 const auto element_size_2_inv = T(1) / element_size_2;
222 const auto element_size_4_inv = element_size_2_inv * element_size_2_inv;
224 const T term_time = fixed_power<2>(T(2) / timestep);
225 const T term_adv = T(4) * velocity_l2_norm * element_size_2_inv;
226 const T term_diff = T(144) * fixed_power<2>(kinematic_viscosity) * element_size_4_inv;
228 return T(1) / sqrt(term_time + term_adv + term_diff);
240template <
unsigned int dim,
unsigned int degree,
typename T>
241inline DEAL_II_ALWAYS_INLINE T
243 const dealii::Tensor<1, dim, T> &velocity,
244 const T &kinematic_viscosity)
246 using dealii::Utilities::fixed_power;
250 constexpr auto degree_modifier = T(1) / T(degree);
251 constexpr auto inv_pi = T(1) / T(M_PI);
252 const auto velocity_l2_norm = velocity.norm_square() + T(1e-12);
254 auto element_size = T(0);
255 if constexpr (dim == 1)
257 element_size = element_volume;
259 else if constexpr (dim == 2)
261 element_size = T(2) * sqrt(element_volume * inv_pi);
263 else if constexpr (dim == 3)
265 element_size = cbrt(T(6) * element_volume * inv_pi);
269 Assert(
false, dealii::ExcMessage(
"Invalid dimension for the stabilization term."));
271 element_size *= degree_modifier;
272 const auto element_size_2 = element_size * element_size;
273 const auto element_size_2_inv = T(1) / element_size_2;
274 const auto element_size_4_inv = element_size_2_inv * element_size_2_inv;
276 const T term_adv = T(4) * velocity_l2_norm * element_size_2_inv;
277 const T term_diff = T(144) * fixed_power<2>(kinematic_viscosity) * element_size_4_inv;
279 return T(1) / sqrt(term_adv + term_diff);
291template <
unsigned int dim,
unsigned int degree,
typename T>
292inline DEAL_II_ALWAYS_INLINE T
294 const T &element_volume,
295 const dealii::Tensor<1, dim, T> &velocity)
297 using dealii::Utilities::fixed_power;
301 constexpr auto degree_modifier = T(1) / T(degree);
302 constexpr auto inv_pi = T(1) / T(M_PI);
303 const auto velocity_l2_norm = velocity.norm_square() + T(1e-12);
305 auto element_size = T(0);
306 if constexpr (dim == 1)
308 element_size = element_volume;
310 else if constexpr (dim == 2)
312 element_size = T(2) * sqrt(element_volume * inv_pi);
314 else if constexpr (dim == 3)
316 element_size = cbrt(T(6) * element_volume * inv_pi);
320 Assert(
false, dealii::ExcMessage(
"Invalid dimension for the stabilization term."));
322 element_size *= degree_modifier;
323 const auto element_size_2 = element_size * element_size;
324 const auto element_size_2_inv = T(1) / element_size_2;
325 const auto element_size_4_inv = element_size_2_inv * element_size_2_inv;
327 const T term_time = fixed_power<2>(T(2) / timestep);
328 const T term_adv = T(4) * velocity_l2_norm * element_size_2_inv;
330 return T(1) / sqrt(term_time + term_adv);
342template <
unsigned int dim,
unsigned int degree,
typename T>
343inline DEAL_II_ALWAYS_INLINE T
345 const dealii::Tensor<1, dim, T> &velocity)
347 using dealii::Utilities::fixed_power;
351 constexpr auto degree_modifier = T(1) / T(degree);
352 constexpr auto inv_pi = T(1) / T(M_PI);
353 const auto velocity_l2_norm = velocity.norm_square() + T(1e-12);
355 auto element_size = T(0);
356 if constexpr (dim == 1)
358 element_size = element_volume;
360 else if constexpr (dim == 2)
362 element_size = T(2) * sqrt(element_volume * inv_pi);
364 else if constexpr (dim == 3)
366 element_size = cbrt(T(6) * element_volume * inv_pi);
370 Assert(
false, dealii::ExcMessage(
"Invalid dimension for the stabilization term."));
372 element_size *= degree_modifier;
373 const auto element_size_2 = element_size * element_size;
374 const auto element_size_2_inv = T(1) / element_size_2;
375 const auto element_size_4_inv = element_size_2_inv * element_size_2_inv;
377 const T term_adv = T(4) * velocity_l2_norm * element_size_2_inv;
381 return T(1) / sqrt(term_adv);
390 std::string text = _text;
391 boost::range::remove_erase_if(text, ::isspace);
401 return boolean ?
"true" :
"false";
412 if ((flag & dealii::EvaluationFlags::EvaluationFlags::values) != 0U)
416 if ((flag & dealii::EvaluationFlags::EvaluationFlags::gradients) != 0U)
422 result +=
"gradients";
424 if ((flag & dealii::EvaluationFlags::EvaluationFlags::hessians) != 0U)
430 result +=
"hessians";
441template <
unsigned int dim,
typename number>
442inline DEAL_II_ALWAYS_INLINE std::vector<number>
445 static_assert(dim < 4,
"We only allow 3 space dimensions");
447 std::vector<number> vec(3, 0.0);
451 for (
unsigned int i = 0; i < dim; ++i)
461PRISMS_PF_END_NAMESPACE
static constexpr unsigned int max_n_threads
Number of threads to try and use.
Definition utilities.h:56
~MPIInitFinalize()
Definition utilities.cc:44
MPIInitFinalize(int &argc, char **&argv, unsigned int _max_n_threads=0)
Definition utilities.cc:16
Definition conditional_ostreams.cc:20
inline ::dealii::VectorizedArray< Number, width > fmod(const ::dealii::VectorizedArray< Number, width > &numer, const Number denom)
Definition vectorized_operations.h:54
Type
Factory function to create appropriate reader based on input file type not a member of ReadFieldBase ...
Definition read_field_factory.h:30
void set_zero_entries_to_one(dealii_vector &vec)
Definition utilities.h:69
std::string strip_whitespace(const std::string &_text)
Remove whitespace from strings.
Definition utilities.h:388
DEAL_II_ALWAYS_INLINE T stabilization_parameter(const T ×tep, const T &element_volume, const dealii::Tensor< 1, dim, T > &velocity, const T &kinematic_viscosity)
Stabilization term as defined by Tezduyar
Definition utilities.h:189
std::pair< OtherType, Type > string_to_type_pair_with_delimiters(const std::string &string, const std::unordered_map< std::string, Type > &table, const std::unordered_map< std::string, OtherType > &other_table, const std::pair< char, char > &delimiters={'(', ')'})
Helper function that converts a string to some type pair, given two mappings and a set of delimiters.
Definition utilities.h:113
Type string_to_type(const std::string &string, const std::unordered_map< std::string, Type > &table)
Helper function that converts a string to some type, given a mapping.
Definition utilities.h:85
std::string eval_flags_to_string(dealii::EvaluationFlags::EvaluationFlags flag)
Convert evaluation flags to string.
Definition utilities.h:408
DEAL_II_ALWAYS_INLINE std::vector< number > dealii_point_to_vector(const dealii::Point< dim, number > &point)
Definition utilities.h:443
DEAL_II_ALWAYS_INLINE Number pmod(const Number &value, const Number &modulus)
Positive moldulo (remainder) returns the normal remainder. (c++ fmod is defined abnormally for negati...
Definition utilities.h:175
const char * bool_to_string(bool boolean)
Convert bool to string.
Definition utilities.h:399