24#define BOOST_BIND_GLOBAL_PLACEHOLDERS
25#include <boost/archive/iterators/base64_from_binary.hpp>
26#include <boost/archive/iterators/binary_from_base64.hpp>
27#include <boost/archive/iterators/transform_width.hpp>
28#include <boost/iostreams/copy.hpp>
29#include <boost/lexical_cast.hpp>
30#include <boost/random.hpp>
33#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
35#ifdef DEAL_II_WITH_ZLIB
36# include <boost/iostreams/filter/gzip.hpp>
53#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
79 <<
"When trying to convert " << arg1 <<
" to a string with "
80 << arg2 <<
" digits");
84 <<
"Can't convert the string " << arg1
85 <<
" to the desired type");
102 std::vector<std::array<std::uint64_t, effective_dim>>
103 inverse_Hilbert_space_filling_curve_effective(
106 const std::array<LongDouble, dim> &extents,
107 const std::bitset<dim> &valid_extents,
109 const Integer max_int)
111 std::vector<std::array<Integer, effective_dim>> int_points(points.size());
113 for (
unsigned int i = 0; i < points.size(); ++i)
116 unsigned int eff_d = 0;
117 for (
unsigned int d = 0; d < dim; ++d)
118 if (valid_extents[d])
121 const LongDouble v = (
static_cast<LongDouble
>(points[i][d]) -
122 static_cast<LongDouble
>(bl[d])) /
126 int_points[i][eff_d] =
127 static_cast<Integer
>(v *
static_cast<LongDouble
>(max_int));
133 return inverse_Hilbert_space_filling_curve<effective_dim>(int_points,
138 template <
int dim,
typename Number>
139 std::vector<std::array<std::uint64_t, dim>>
142 const int bits_per_dim)
144 using Integer = std::uint64_t;
146 using LongDouble =
long double;
150 return std::vector<std::array<std::uint64_t, dim>>();
154 for (
const auto &p : points)
155 for (
unsigned int d = 0; d < dim; ++d)
157 const double cid = p[d];
162 std::array<LongDouble, dim> extents;
163 std::bitset<dim> valid_extents;
164 for (
unsigned int i = 0; i < dim; ++i)
167 static_cast<LongDouble
>(tr[i]) -
static_cast<LongDouble
>(bl[i]);
168 valid_extents[i] = (extents[i] > 0.);
173 const int min_bits =
std::min({bits_per_dim,
174 std::numeric_limits<Integer>::digits,
175 std::numeric_limits<LongDouble>::digits});
178 const Integer max_int = (min_bits == std::numeric_limits<Integer>::digits ?
179 std::numeric_limits<Integer>::max() :
180 (Integer(1) << min_bits) - 1);
182 const unsigned int effective_dim = valid_extents.count();
183 if (effective_dim == dim)
185 return inverse_Hilbert_space_filling_curve_effective<dim,
190 points, bl, extents, valid_extents, min_bits, max_int);
194 std::array<std::uint64_t, dim> zero_ind;
195 for (
unsigned int d = 0; d < dim; ++d)
198 std::vector<std::array<std::uint64_t, dim>> ind(points.size(), zero_ind);
200 if (dim == 3 && effective_dim == 2)
203 inverse_Hilbert_space_filling_curve_effective<dim,
208 points, bl, extents, valid_extents, min_bits, max_int);
210 for (
unsigned int i = 0; i < ind.size(); ++i)
211 for (
unsigned int d = 0; d < 2; ++d)
212 ind[i][d + 1] = ind2[i][d];
216 else if (effective_dim == 1)
219 inverse_Hilbert_space_filling_curve_effective<dim,
224 points, bl, extents, valid_extents, min_bits, max_int);
226 for (
unsigned int i = 0; i < ind.size(); ++i)
227 ind[i][dim - 1] = ind1[i][0];
238 for (
unsigned int i = 0; i < points.size(); ++i)
247 std::vector<std::array<std::uint64_t, dim>>
249 const std::vector<std::array<std::uint64_t, dim>> &points,
250 const int bits_per_dim)
252 using Integer = std::uint64_t;
254 std::vector<std::array<Integer, dim>> int_points(points);
256 std::vector<std::array<Integer, dim>> res(int_points.size());
279 Assert(bits_per_dim <= std::numeric_limits<Integer>::digits,
280 ExcMessage(
"This integer type can not hold " +
281 std::to_string(bits_per_dim) +
" bits."));
283 const Integer M = Integer(1) << (bits_per_dim - 1);
285 for (
unsigned int index = 0; index < int_points.size(); ++index)
287 auto &X = int_points[index];
288 auto &L = res[index];
291 for (Integer q = M; q > 1; q >>= 1)
293 const Integer p = q - 1;
294 for (
unsigned int i = 0; i < dim; ++i)
304 const Integer t = (X[0] ^ X[i]) & p;
312 for (
unsigned int i = 1; i < dim; ++i)
316 for (Integer q = M; q > 1; q >>= 1)
319 for (
unsigned int i = 0; i < dim; ++i)
334 for (
unsigned int i = 0; i < dim; ++i)
338 for (Integer q = M; q > 0; q >>= 1)
361 const int bits_per_dim)
363 using Integer = std::uint64_t;
368 const Integer mask = (Integer(1) << bits_per_dim) - 1;
371 for (
unsigned int i = 0; i < dim; ++i)
374 const Integer v = (mask & index[dim - 1 - i]) << (bits_per_dim * i);
385#ifdef DEAL_II_WITH_ZLIB
386 namespace bio = boost::iostreams;
388 std::stringstream compressed;
389 std::stringstream origin(input);
391 bio::filtering_streambuf<bio::input> out;
392 out.push(bio::gzip_compressor());
394 bio::copy(out, compressed);
396 return compressed.str();
407#ifdef DEAL_II_WITH_ZLIB
408 namespace bio = boost::iostreams;
410 std::stringstream compressed(compressed_input);
411 std::stringstream decompressed;
413 bio::filtering_streambuf<bio::input> out;
414 out.push(bio::gzip_decompressor());
415 out.push(compressed);
416 bio::copy(out, decompressed);
418 return decompressed.str();
420 return compressed_input;
429 using It = boost::archive::iterators::base64_from_binary<
430 boost::archive::iterators::
431 transform_width<std::vector<unsigned char>::const_iterator, 6, 8>>;
432 auto base64 = std::string(It(binary_input.begin()), It(binary_input.end()));
434 return base64.append((3 - binary_input.size() % 3) % 3,
'=');
439 std::vector<unsigned char>
442 using It = boost::archive::iterators::transform_width<
443 boost::archive::iterators::binary_from_base64<
444 std::string::const_iterator>,
447 auto binary = std::vector<unsigned char>(It(base64_input.begin()),
448 It(base64_input.end()));
450 auto length = base64_input.size();
451 if (binary.size() > 2 && base64_input[length - 1] ==
'=' &&
452 base64_input[length - 2] ==
'=')
454 binary.erase(binary.end() - 2, binary.end());
456 else if (binary.size() > 1 && base64_input[length - 1] ==
'=')
458 binary.erase(binary.end() - 1, binary.end());
473 template <
typename number>
475 to_string(
const number value,
const unsigned int digits)
485 std::string lc_string =
486 (std::is_integral_v<number> ? std::to_string(value) :
487 boost::lexical_cast<std::string>(value));
490 (lc_string.size() < digits))
493 const unsigned int padding_position = (lc_string[0] ==
'-') ? 1 : 0;
495 const std::string padding(digits - lc_string.size(),
'0');
496 lc_string.insert(padding_position, padding);
506 const std::string &from,
507 const std::string &to)
512 std::string out = input;
513 std::string::size_type pos = out.find(from);
515 while (pos != std::string::npos)
517 out.replace(pos, from.size(), to);
518 pos = out.find(from, pos + to.size());
526 std::string::size_type left = 0;
527 std::string::size_type right = input.size() > 0 ? input.size() - 1 : 0;
529 for (; left < input.size(); ++left)
531 if (std::isspace(input[left]) == 0)
537 for (; right >= left; --right)
539 if (std::isspace(input[right]) == 0)
545 return std::string(input, left, right - left + 1);
564 return static_cast<int>(
565 std::ceil(std::log10(std::fabs(max_number + 0.1))));
572 template <
typename Number>
578 if (!(std::fabs(number) > std::numeric_limits<Number>::min()))
582 static_cast<int>(std::floor(std::log10(std::fabs(number))));
584 const int shift = -order +
static_cast<int>(n_digits) - 1;
586 Assert(shift <=
static_cast<int>(std::floor(
587 std::log10(std::numeric_limits<Number>::max()))),
589 "Overflow. Use a smaller value for n_digits and/or make sure "
590 "that the absolute value of 'number' does not become too small."));
592 const Number factor =
std::pow(10.0,
static_cast<Number
>(shift));
594 const Number number_cutoff = std::trunc(number * factor) / factor;
596 return number_cutoff;
605 while ((s.size() > 0) && (s[0] ==
' '))
607 while ((s.size() > 0) && (s.back() ==
' '))
608 s.erase(s.end() - 1);
612 int i = std::numeric_limits<int>::max();
615 i = std::stoi(s, &pos);
630 ExcMessage(
"Can't convert <" + s +
"> to a double."));
641 std::vector<int> tmp(s.size());
642 for (
unsigned int i = 0; i < s.size(); ++i)
654 while ((s.size() > 0) && (s[0] ==
' '))
656 while ((s.size() > 0) && (s.back() ==
' '))
657 s.erase(s.end() - 1);
661 double d = numbers::signaling_nan<double>();
664 d = std::stod(s, &pos);
679 ExcMessage(
"Can't convert <" + s +
"> to a double."));
690 std::vector<double> tmp(s.size());
691 for (
unsigned int i = 0; i < s.size(); ++i)
698 std::vector<std::string>
707 while (tmp.size() != 0 && tmp.back() ==
' ')
708 tmp.erase(tmp.size() - 1, 1);
716 std::vector<std::string> split_list;
717 while (tmp.size() != 0)
722 if (name.find(delimiter) != std::string::npos)
724 name.erase(name.find(delimiter), std::string::npos);
725 tmp.erase(0, tmp.find(delimiter) + delimiter.size());
731 while ((name.size() != 0) && (name[0] ==
' '))
733 while (name.size() != 0 && name.back() ==
' ')
734 name.erase(name.size() - 1, 1);
736 split_list.push_back(name);
743 std::vector<std::string>
752 std::vector<std::string>
754 const unsigned int width,
755 const char delimiter)
757 std::string text = original_text;
758 std::vector<std::string> lines;
761 while ((text.size() != 0) && (text.back() == delimiter))
762 text.erase(text.size() - 1, 1);
765 while (text.size() != 0)
769 while ((text.size() != 0) && (text[0] == delimiter))
772 std::size_t pos_newline = text.find_first_of(
'\n', 0);
773 if (pos_newline != std::string::npos && pos_newline <= width)
775 std::string line(text, 0, pos_newline);
776 while ((line.size() != 0) && (line.back() == delimiter))
777 line.erase(line.size() - 1, 1);
778 lines.push_back(line);
779 text.erase(0, pos_newline + 1);
786 if (text.size() < width)
789 while ((text.size() != 0) && (text.back() == delimiter))
790 text.erase(text.size() - 1, 1);
791 lines.push_back(text);
799 int location = std::min<int>(width, text.size() - 1);
800 for (; location > 0; --location)
801 if (text[location] == delimiter)
807 for (location = std::min<int>(width, text.size() - 1);
808 location < static_cast<int>(text.size());
810 if (text[location] == delimiter)
816 std::string line(text, 0, location);
817 while ((line.size() != 0) && (line.back() == delimiter))
818 line.erase(line.size() - 1, 1);
819 lines.push_back(line);
820 text.erase(0, location);
832 if (pattern.size() > name.size())
835 for (
unsigned int i = 0; i < pattern.size(); ++i)
836 if (pattern[i] != name[i])
844 std::pair<int, unsigned int>
849 const std::string test_string(name.begin() + position, name.end());
851 std::istringstream str(test_string);
861 return std::make_pair(i, 1U);
863 return std::make_pair(i, 2U);
865 return std::make_pair(i, 3U);
867 return std::make_pair(i, 4U);
869 return std::make_pair(i, 5U);
870 else if (i < 1000000)
871 return std::make_pair(i, 6U);
872 else if (i < 10000000)
873 return std::make_pair(i, 7U);
901 return boost::normal_distribution<>(a,
902 sigma)(random_number_generator.
get());
914 std::ifstream cpuinfo;
915 cpuinfo.open(
"/proc/loadavg");
955 "Invalid DEAL_II_VECTORIZATION_WIDTH_IN_BITS."));
970 std::ifstream file(
"/proc/self/status");
976 if (name ==
"VmPeak:")
978 else if (name ==
"VmSize:")
980 else if (name ==
"VmHWM:")
982 else if (name ==
"VmRSS:")
998#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
999 const unsigned int N = 1024;
1001 gethostname(&(hostname[0]), N - 1);
1003 std::string hostname(
"unknown");
1013 std::time_t time1 = std::time(
nullptr);
1014 const std::tm *time = std::localtime(&time1);
1016 std::ostringstream o;
1017 o << time->tm_hour <<
":" << (time->tm_min < 10 ?
"0" :
"")
1018 << time->tm_min <<
":" << (time->tm_sec < 10 ?
"0" :
"")
1029 std::time_t time1 = std::time(
nullptr);
1030 const std::tm *time = std::localtime(&time1);
1032 std::ostringstream o;
1033 o << time->tm_year + 1900 <<
"/" << time->tm_mon + 1 <<
"/"
1060 *memptr = std::malloc(
size);
1079 template std::string
1080 to_string<int>(
int,
unsigned int);
1081 template std::string
1082 to_string<long int>(
long int,
unsigned int);
1083 template std::string
1084 to_string<long long int>(
long long int,
unsigned int);
1085 template std::string
1086 to_string<unsigned int>(
unsigned int,
unsigned int);
1087 template std::string
1088 to_string<unsigned long int>(
unsigned long int,
unsigned int);
1089 template std::string
1090 to_string<unsigned long long int>(
unsigned long long int,
unsigned int);
1091 template std::string
1092 to_string<float>(
float,
unsigned int);
1093 template std::string
1094 to_string<double>(
double,
unsigned int);
1095 template std::string
1096 to_string<long double>(
long double,
unsigned int);
1103 template std::vector<std::array<std::uint64_t, 1>>
1104 inverse_Hilbert_space_filling_curve<1, double>(
1107 template std::vector<std::array<std::uint64_t, 1>>
1108 inverse_Hilbert_space_filling_curve<1>(
1109 const std::vector<std::array<std::uint64_t, 1>> &,
1111 template std::vector<std::array<std::uint64_t, 2>>
1112 inverse_Hilbert_space_filling_curve<2, double>(
1115 template std::vector<std::array<std::uint64_t, 2>>
1116 inverse_Hilbert_space_filling_curve<2>(
1117 const std::vector<std::array<std::uint64_t, 2>> &,
1119 template std::vector<std::array<std::uint64_t, 3>>
1120 inverse_Hilbert_space_filling_curve<3, double>(
1123 template std::vector<std::array<std::uint64_t, 3>>
1124 inverse_Hilbert_space_filling_curve<3>(
1125 const std::vector<std::array<std::uint64_t, 3>> &,
1128 template std::uint64_t
1129 pack_integers<1>(
const std::array<std::uint64_t, 1> &,
const int);
1130 template std::uint64_t
1131 pack_integers<2>(
const std::array<std::uint64_t, 2> &,
const int);
1132 template std::uint64_t
1133 pack_integers<3>(
const std::array<std::uint64_t, 3> &,
const int);
A class that provides a separate storage location on each thread that accesses the object.
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_PACKAGE_VERSION
#define DEAL_II_VECTORIZATION_WIDTH_IN_BITS
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_PACKAGE_NAME
#define DEAL_II_NOT_IMPLEMENTED()
static ::ExceptionBase & ExcInvalidNumber2StringConversersion(unsigned int arg1, unsigned int arg2)
static ::ExceptionBase & ExcOutOfMemory(std::size_t arg1)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcInvalidNumber(unsigned int arg1)
#define Assert(cond, exc)
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcCantConvertString(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void get_memory_stats(MemoryStats &stats)
std::string get_hostname()
void posix_memalign(void **memptr, std::size_t alignment, std::size_t size)
std::string get_current_vectorization_level()
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Number truncate_to_n_digits(const Number number, const unsigned int n_digits)
std::string dim_string(const int dim, const int spacedim)
std::uint64_t pack_integers(const std::array< std::uint64_t, dim > &index, const int bits_per_dim)
std::pair< int, unsigned int > get_integer_at_position(const std::string &name, const unsigned int position)
std::string encode_base64(const std::vector< unsigned char > &binary_input)
std::string replace_in_string(const std::string &input, const std::string &from, const std::string &to)
std::vector< unsigned char > decode_base64(const std::string &base64_input)
std::vector< std::string > break_text_into_lines(const std::string &original_text, const unsigned int width, const char delimiter=' ')
std::string to_string(const number value, const unsigned int digits=numbers::invalid_unsigned_int)
std::vector< std::array< std::uint64_t, dim > > inverse_Hilbert_space_filling_curve(const std::vector< Point< dim, Number > > &points, const int bits_per_dim=64)
std::string compress(const std::string &input)
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
bool match_at_string_start(const std::string &name, const std::string &pattern)
std::string decompress(const std::string &compressed_input)
unsigned int needed_digits(const unsigned int max_number)
double string_to_double(const std::string &s)
std::string dealii_version_string()
std::string trim(const std::string &input)
double generate_normal_random_number(const double a, const double sigma)
int string_to_int(const std::string &s)
constexpr unsigned int invalid_unsigned_int
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)