22#define BOOST_BIND_GLOBAL_PLACEHOLDERS
23#include <boost/archive/iterators/base64_from_binary.hpp>
24#include <boost/archive/iterators/binary_from_base64.hpp>
25#include <boost/archive/iterators/transform_width.hpp>
26#include <boost/iostreams/copy.hpp>
27#include <boost/lexical_cast.hpp>
28#include <boost/random.hpp>
31#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
33#ifdef DEAL_II_WITH_ZLIB
34# include <boost/iostreams/filter/gzip.hpp>
51#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
77 <<
"When trying to convert " << arg1 <<
" to a string with "
78 << arg2 <<
" digits");
82 <<
"Can't convert the string " << arg1
83 <<
" to the desired type");
100 std::vector<std::array<std::uint64_t, effective_dim>>
101 inverse_Hilbert_space_filling_curve_effective(
104 const std::array<LongDouble, dim> &extents,
105 const std::bitset<dim> &valid_extents,
107 const Integer max_int)
109 std::vector<std::array<Integer, effective_dim>> int_points(points.size());
111 for (
unsigned int i = 0; i < points.size(); ++i)
114 unsigned int eff_d = 0;
115 for (
unsigned int d = 0; d < dim; ++d)
116 if (valid_extents[d])
119 const LongDouble v = (
static_cast<LongDouble
>(points[i][d]) -
120 static_cast<LongDouble
>(bl[d])) /
124 int_points[i][eff_d] =
125 static_cast<Integer
>(v *
static_cast<LongDouble
>(max_int));
131 return inverse_Hilbert_space_filling_curve<effective_dim>(int_points,
136 template <
int dim,
typename Number>
137 std::vector<std::array<std::uint64_t, dim>>
140 const int bits_per_dim)
142 using Integer = std::uint64_t;
144 using LongDouble =
long double;
148 return std::vector<std::array<std::uint64_t, dim>>();
152 for (
const auto &p : points)
153 for (
unsigned int d = 0; d < dim; ++d)
155 const double cid = p[d];
160 std::array<LongDouble, dim> extents;
161 std::bitset<dim> valid_extents;
162 for (
unsigned int i = 0; i < dim; ++i)
165 static_cast<LongDouble
>(tr[i]) -
static_cast<LongDouble
>(bl[i]);
166 valid_extents[i] = (extents[i] > 0.);
171 const int min_bits =
std::min({bits_per_dim,
172 std::numeric_limits<Integer>::digits,
173 std::numeric_limits<LongDouble>::digits});
176 const Integer max_int = (min_bits == std::numeric_limits<Integer>::digits ?
177 std::numeric_limits<Integer>::max() :
178 (Integer(1) << min_bits) - 1);
180 const unsigned int effective_dim = valid_extents.count();
181 if (effective_dim == dim)
183 return inverse_Hilbert_space_filling_curve_effective<dim,
188 points, bl, extents, valid_extents, min_bits, max_int);
192 std::array<std::uint64_t, dim> zero_ind;
193 for (
unsigned int d = 0; d < dim; ++d)
196 std::vector<std::array<std::uint64_t, dim>> ind(points.size(), zero_ind);
198 if (dim == 3 && effective_dim == 2)
201 inverse_Hilbert_space_filling_curve_effective<dim,
206 points, bl, extents, valid_extents, min_bits, max_int);
208 for (
unsigned int i = 0; i < ind.size(); ++i)
209 for (
unsigned int d = 0; d < 2; ++d)
210 ind[i][d + 1] = ind2[i][d];
214 else if (effective_dim == 1)
217 inverse_Hilbert_space_filling_curve_effective<dim,
222 points, bl, extents, valid_extents, min_bits, max_int);
224 for (
unsigned int i = 0; i < ind.size(); ++i)
225 ind[i][dim - 1] = ind1[i][0];
236 for (
unsigned int i = 0; i < points.size(); ++i)
245 std::vector<std::array<std::uint64_t, dim>>
247 const std::vector<std::array<std::uint64_t, dim>> &points,
248 const int bits_per_dim)
250 using Integer = std::uint64_t;
252 std::vector<std::array<Integer, dim>> int_points(points);
254 std::vector<std::array<Integer, dim>> res(int_points.size());
277 Assert(bits_per_dim <= std::numeric_limits<Integer>::digits,
278 ExcMessage(
"This integer type can not hold " +
279 std::to_string(bits_per_dim) +
" bits."));
281 const Integer M = Integer(1) << (bits_per_dim - 1);
283 for (
unsigned int index = 0; index < int_points.size(); ++index)
285 auto &X = int_points[index];
286 auto &L = res[index];
289 for (Integer q = M; q > 1; q >>= 1)
291 const Integer p = q - 1;
292 for (
unsigned int i = 0; i < dim; ++i)
302 const Integer t = (X[0] ^ X[i]) & p;
310 for (
unsigned int i = 1; i < dim; ++i)
314 for (Integer q = M; q > 1; q >>= 1)
317 for (
unsigned int i = 0; i < dim; ++i)
332 for (
unsigned int i = 0; i < dim; ++i)
336 for (Integer q = M; q > 0; q >>= 1)
359 const int bits_per_dim)
361 using Integer = std::uint64_t;
366 const Integer mask = (Integer(1) << bits_per_dim) - 1;
369 for (
unsigned int i = 0; i < dim; ++i)
372 const Integer v = (mask & index[dim - 1 - i]) << (bits_per_dim * i);
383#ifdef DEAL_II_WITH_ZLIB
384 namespace bio = boost::iostreams;
386 std::stringstream compressed;
387 std::stringstream origin(input);
389 bio::filtering_streambuf<bio::input> out;
390 out.push(bio::gzip_compressor());
392 bio::copy(out, compressed);
394 return compressed.str();
405#ifdef DEAL_II_WITH_ZLIB
406 namespace bio = boost::iostreams;
408 std::stringstream compressed(compressed_input);
409 std::stringstream decompressed;
411 bio::filtering_streambuf<bio::input> out;
412 out.push(bio::gzip_decompressor());
413 out.push(compressed);
414 bio::copy(out, decompressed);
416 return decompressed.str();
418 return compressed_input;
427 using It = boost::archive::iterators::base64_from_binary<
428 boost::archive::iterators::
429 transform_width<std::vector<unsigned char>::const_iterator, 6, 8>>;
430 auto base64 = std::string(It(binary_input.begin()), It(binary_input.end()));
432 return base64.append((3 - binary_input.size() % 3) % 3,
'=');
437 std::vector<unsigned char>
440 using It = boost::archive::iterators::transform_width<
441 boost::archive::iterators::binary_from_base64<
442 std::string::const_iterator>,
445 auto binary = std::vector<unsigned char>(It(base64_input.begin()),
446 It(base64_input.end()));
448 auto length = base64_input.size();
449 if (binary.size() > 2 && base64_input[length - 1] ==
'=' &&
450 base64_input[length - 2] ==
'=')
452 binary.erase(binary.end() - 2, binary.end());
454 else if (binary.size() > 1 && base64_input[length - 1] ==
'=')
456 binary.erase(binary.end() - 1, binary.end());
471 template <
typename number>
473 to_string(
const number value,
const unsigned int digits)
483 std::string lc_string =
484 (std::is_integral_v<number> ? std::to_string(value) :
485 boost::lexical_cast<std::string>(value));
488 (lc_string.size() < digits))
491 const unsigned int padding_position = (lc_string[0] ==
'-') ? 1 : 0;
492 lc_string.insert(padding_position, digits - lc_string.size(),
'0');
502 const std::string &from,
503 const std::string &to)
508 std::string out = input;
509 std::string::size_type pos = out.find(from);
511 while (pos != std::string::npos)
513 out.replace(pos, from.size(), to);
514 pos = out.find(from, pos + to.size());
522 std::string::size_type left = 0;
523 std::string::size_type right = input.size() > 0 ? input.size() - 1 : 0;
525 for (; left < input.size(); ++left)
527 if (std::isspace(input[left]) == 0)
533 for (; right >= left; --right)
535 if (std::isspace(input[right]) == 0)
541 return std::string(input, left, right - left + 1);
560 return static_cast<int>(
561 std::ceil(std::log10(std::fabs(max_number + 0.1))));
568 template <
typename Number>
574 if (!(std::fabs(number) > std::numeric_limits<Number>::min()))
578 static_cast<int>(std::floor(std::log10(std::fabs(number))));
580 const int shift = -order +
static_cast<int>(n_digits) - 1;
582 Assert(shift <=
static_cast<int>(std::floor(
583 std::log10(std::numeric_limits<Number>::max()))),
585 "Overflow. Use a smaller value for n_digits and/or make sure "
586 "that the absolute value of 'number' does not become too small."));
588 const Number factor =
std::pow(10.0,
static_cast<Number
>(shift));
590 const Number number_cutoff = std::trunc(number * factor) / factor;
592 return number_cutoff;
601 while ((s.size() > 0) && (s[0] ==
' '))
603 while ((s.size() > 0) && (s.back() ==
' '))
604 s.erase(s.end() - 1);
608 int i = std::numeric_limits<int>::max();
611 i = std::stoi(s, &pos);
626 ExcMessage(
"Can't convert <" + s +
"> to a double."));
637 std::vector<int> tmp(s.size());
638 for (
unsigned int i = 0; i < s.size(); ++i)
650 while ((s.size() > 0) && (s[0] ==
' '))
652 while ((s.size() > 0) && (s.back() ==
' '))
653 s.erase(s.end() - 1);
657 double d = numbers::signaling_nan<double>();
660 d = std::stod(s, &pos);
675 ExcMessage(
"Can't convert <" + s +
"> to a double."));
686 std::vector<double> tmp(s.size());
687 for (
unsigned int i = 0; i < s.size(); ++i)
694 std::vector<std::string>
703 while (tmp.size() != 0 && tmp.back() ==
' ')
704 tmp.erase(tmp.size() - 1, 1);
712 std::vector<std::string> split_list;
713 while (tmp.size() != 0)
718 if (name.find(delimiter) != std::string::npos)
720 name.erase(name.find(delimiter), std::string::npos);
721 tmp.erase(0, tmp.find(delimiter) + delimiter.size());
727 while ((name.size() != 0) && (name[0] ==
' '))
729 while (name.size() != 0 && name.back() ==
' ')
730 name.erase(name.size() - 1, 1);
732 split_list.push_back(name);
739 std::vector<std::string>
748 std::vector<std::string>
750 const unsigned int width,
751 const char delimiter)
753 std::vector<std::string> lines;
756 std::size_t start = 0;
759 const std::size_t pos = original_text.find(
'\n', start);
760 std::string text = original_text.substr(
761 start, (pos == std::string::npos ? std::string::npos : pos - start));
764 while ((text.size() != 0) && (text.front() == delimiter))
766 while ((text.size() != 0) && (text.back() == delimiter))
773 if (pos != std::string::npos)
774 lines.emplace_back();
778 while (text.size() > width)
783 std::size_t location = text.rfind(delimiter, width);
784 if (location == 0 || location == std::string::npos)
786 location = text.find(delimiter, width);
787 if (location == std::string::npos)
791 std::string line = text.substr(0, location);
792 while ((line.size() != 0) && (line.back() == delimiter))
794 lines.push_back(line);
796 text.erase(0, location);
797 while ((text.size() != 0) && (text.front() == delimiter))
801 if (text.size() != 0)
802 lines.push_back(text);
805 if (pos == std::string::npos)
818 if (pattern.size() > name.size())
821 for (
unsigned int i = 0; i < pattern.size(); ++i)
822 if (pattern[i] != name[i])
830 std::pair<int, unsigned int>
835 const std::string test_string(name.begin() + position, name.end());
837 std::istringstream str(test_string);
847 return std::make_pair(i, 1U);
849 return std::make_pair(i, 2U);
851 return std::make_pair(i, 3U);
853 return std::make_pair(i, 4U);
855 return std::make_pair(i, 5U);
856 else if (i < 1000000)
857 return std::make_pair(i, 6U);
858 else if (i < 10000000)
859 return std::make_pair(i, 7U);
887 return boost::normal_distribution<>(a,
888 sigma)(random_number_generator.
get());
900 std::ifstream cpuinfo;
901 cpuinfo.open(
"/proc/loadavg");
941 "Invalid DEAL_II_VECTORIZATION_WIDTH_IN_BITS."));
956 std::ifstream file(
"/proc/self/status");
962 if (name ==
"VmPeak:")
964 else if (name ==
"VmSize:")
966 else if (name ==
"VmHWM:")
968 else if (name ==
"VmRSS:")
984#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
985 const unsigned int N = 1024;
987 gethostname(&(hostname[0]), N - 1);
989 std::string hostname(
"unknown");
999 std::time_t time1 = std::time(
nullptr);
1000 const std::tm *time = std::localtime(&time1);
1002 std::ostringstream o;
1003 o << time->tm_hour <<
":" << (time->tm_min < 10 ?
"0" :
"")
1004 << time->tm_min <<
":" << (time->tm_sec < 10 ?
"0" :
"")
1015 std::time_t time1 = std::time(
nullptr);
1016 const std::tm *time = std::localtime(&time1);
1018 std::ostringstream o;
1019 o << time->tm_year + 1900 <<
"/" << time->tm_mon + 1 <<
"/"
1046 *memptr = std::malloc(
size);
1065 template std::string
1066 to_string<int>(
int,
unsigned int);
1067 template std::string
1068 to_string<long int>(
long int,
unsigned int);
1069 template std::string
1070 to_string<long long int>(
long long int,
unsigned int);
1071 template std::string
1072 to_string<unsigned int>(
unsigned int,
unsigned int);
1073 template std::string
1074 to_string<unsigned long int>(
unsigned long int,
unsigned int);
1075 template std::string
1076 to_string<unsigned long long int>(
unsigned long long int,
unsigned int);
1077 template std::string
1078 to_string<float>(
float,
unsigned int);
1079 template std::string
1080 to_string<double>(
double,
unsigned int);
1081 template std::string
1082 to_string<long double>(
long double,
unsigned int);
1089 template std::vector<std::array<std::uint64_t, 1>>
1090 inverse_Hilbert_space_filling_curve<1, double>(
1093 template std::vector<std::array<std::uint64_t, 1>>
1094 inverse_Hilbert_space_filling_curve<1>(
1095 const std::vector<std::array<std::uint64_t, 1>> &,
1097 template std::vector<std::array<std::uint64_t, 2>>
1098 inverse_Hilbert_space_filling_curve<2, double>(
1101 template std::vector<std::array<std::uint64_t, 2>>
1102 inverse_Hilbert_space_filling_curve<2>(
1103 const std::vector<std::array<std::uint64_t, 2>> &,
1105 template std::vector<std::array<std::uint64_t, 3>>
1106 inverse_Hilbert_space_filling_curve<3, double>(
1109 template std::vector<std::array<std::uint64_t, 3>>
1110 inverse_Hilbert_space_filling_curve<3>(
1111 const std::vector<std::array<std::uint64_t, 3>> &,
1114 template std::uint64_t
1115 pack_integers<1>(
const std::array<std::uint64_t, 1> &,
const int);
1116 template std::uint64_t
1117 pack_integers<2>(
const std::array<std::uint64_t, 2> &,
const int);
1118 template std::uint64_t
1119 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)