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));
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>
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;
493 const std::string padding(digits - lc_string.size(),
'0');
494 lc_string.insert(padding_position, padding);
504 const std::string &from,
505 const std::string &to)
510 std::string out = input;
511 std::string::size_type pos = out.find(from);
513 while (pos != std::string::npos)
515 out.replace(pos, from.size(), to);
516 pos = out.find(from, pos + to.size());
524 std::string::size_type left = 0;
525 std::string::size_type right = input.size() > 0 ? input.size() - 1 : 0;
527 for (; left < input.size(); ++left)
529 if (std::isspace(input[left]) == 0)
535 for (; right >= left; --right)
537 if (std::isspace(input[right]) == 0)
543 return std::string(input, left, right - left + 1);
562 return static_cast<int>(
563 std::ceil(std::log10(std::fabs(max_number + 0.1))));
570 template <
typename Number>
576 if (!(std::fabs(number) > std::numeric_limits<Number>::min()))
580 static_cast<int>(std::floor(std::log10(std::fabs(number))));
582 const int shift = -order +
static_cast<int>(n_digits) - 1;
584 Assert(shift <=
static_cast<int>(std::floor(
585 std::log10(std::numeric_limits<Number>::max()))),
587 "Overflow. Use a smaller value for n_digits and/or make sure "
588 "that the absolute value of 'number' does not become too small."));
590 const Number factor =
std::pow(10.0,
static_cast<Number
>(shift));
592 const Number number_cutoff = std::trunc(number * factor) / factor;
594 return number_cutoff;
603 while ((s.size() > 0) && (s[0] ==
' '))
605 while ((s.size() > 0) && (s.back() ==
' '))
606 s.erase(s.end() - 1);
610 int i = std::numeric_limits<int>::max();
613 i = std::stoi(s, &pos);
628 ExcMessage(
"Can't convert <" + s +
"> to a double."));
639 std::vector<int> tmp(s.size());
640 for (
unsigned int i = 0; i < s.size(); ++i)
652 while ((s.size() > 0) && (s[0] ==
' '))
654 while ((s.size() > 0) && (s.back() ==
' '))
655 s.erase(s.end() - 1);
662 d = std::stod(s, &pos);
677 ExcMessage(
"Can't convert <" + s +
"> to a double."));
688 std::vector<double> tmp(s.size());
689 for (
unsigned int i = 0; i < s.size(); ++i)
696 std::vector<std::string>
705 while (tmp.size() != 0 && tmp.back() ==
' ')
706 tmp.erase(tmp.size() - 1, 1);
714 std::vector<std::string> split_list;
715 while (tmp.size() != 0)
720 if (name.find(delimiter) != std::string::npos)
722 name.erase(name.find(delimiter), std::string::npos);
723 tmp.erase(0, tmp.find(delimiter) + delimiter.size());
729 while ((name.size() != 0) && (name[0] ==
' '))
731 while (name.size() != 0 && name.back() ==
' ')
732 name.erase(name.size() - 1, 1);
734 split_list.push_back(name);
741 std::vector<std::string>
750 std::vector<std::string>
752 const unsigned int width,
753 const char delimiter)
755 std::string text = original_text;
756 std::vector<std::string> lines;
759 while ((text.size() != 0) && (text.back() == delimiter))
760 text.erase(text.size() - 1, 1);
763 while (text.size() != 0)
767 while ((text.size() != 0) && (text[0] == delimiter))
770 std::size_t pos_newline = text.find_first_of(
'\n', 0);
771 if (pos_newline != std::string::npos && pos_newline <= width)
773 std::string line(text, 0, pos_newline);
774 while ((line.size() != 0) && (line.back() == delimiter))
775 line.erase(line.size() - 1, 1);
776 lines.push_back(line);
777 text.erase(0, pos_newline + 1);
784 if (text.size() < width)
787 while ((text.size() != 0) && (text.back() == delimiter))
788 text.erase(text.size() - 1, 1);
789 lines.push_back(text);
798 for (; location > 0; --location)
799 if (text[location] == delimiter)
806 location <
static_cast<int>(text.size());
808 if (text[location] == delimiter)
814 std::string line(text, 0, location);
815 while ((line.size() != 0) && (line.back() == delimiter))
816 line.erase(line.size() - 1, 1);
817 lines.push_back(line);
818 text.erase(0, location);
830 if (pattern.size() > name.size())
833 for (
unsigned int i = 0; i < pattern.size(); ++i)
834 if (pattern[i] != name[i])
842 std::pair<int, unsigned int>
847 const std::string test_string(name.begin() + position, name.end());
849 std::istringstream str(test_string);
859 return std::make_pair(i, 1U);
861 return std::make_pair(i, 2U);
863 return std::make_pair(i, 3U);
865 return std::make_pair(i, 4U);
867 return std::make_pair(i, 5U);
868 else if (i < 1000000)
869 return std::make_pair(i, 6U);
870 else if (i < 10000000)
871 return std::make_pair(i, 7U);
899 return boost::normal_distribution<>(a,
900 sigma)(random_number_generator.
get());
912 std::ifstream cpuinfo;
913 cpuinfo.open(
"/proc/loadavg");
953 "Invalid DEAL_II_VECTORIZATION_WIDTH_IN_BITS."));
968 std::ifstream file(
"/proc/self/status");
974 if (name ==
"VmPeak:")
976 else if (name ==
"VmSize:")
978 else if (name ==
"VmHWM:")
980 else if (name ==
"VmRSS:")
996#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
997 const unsigned int N = 1024;
999 gethostname(&(hostname[0]), N - 1);
1001 std::string hostname(
"unknown");
1011 std::time_t time1 = std::time(
nullptr);
1012 const std::tm *time = std::localtime(&time1);
1014 std::ostringstream o;
1015 o << time->tm_hour <<
":" << (time->tm_min < 10 ?
"0" :
"")
1016 << time->tm_min <<
":" << (time->tm_sec < 10 ?
"0" :
"")
1027 std::time_t time1 = std::time(
nullptr);
1028 const std::tm *time = std::localtime(&time1);
1030 std::ostringstream o;
1031 o << time->tm_year + 1900 <<
"/" << time->tm_mon + 1 <<
"/"
1058 *memptr = std::malloc(size);
1077 template std::string
1079 template std::string
1081 template std::string
1083 template std::string
1085 template std::string
1087 template std::string
1089 template std::string
1091 template std::string
1093 template std::string
1101 template std::vector<std::array<std::uint64_t, 1>>
1105 template std::vector<std::array<std::uint64_t, 1>>
1107 const std::vector<std::array<std::uint64_t, 1>> &,
1109 template std::vector<std::array<std::uint64_t, 2>>
1113 template std::vector<std::array<std::uint64_t, 2>>
1115 const std::vector<std::array<std::uint64_t, 2>> &,
1117 template std::vector<std::array<std::uint64_t, 3>>
1121 template std::vector<std::array<std::uint64_t, 3>>
1123 const std::vector<std::array<std::uint64_t, 3>> &,
1126 template std::uint64_t
1128 template std::uint64_t
1130 template std::uint64_t
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)
const bool IsBlockVector< VectorType >::value
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)