30#define BOOST_BIND_GLOBAL_PLACEHOLDERS
31#include <boost/archive/iterators/base64_from_binary.hpp>
32#include <boost/archive/iterators/binary_from_base64.hpp>
33#include <boost/archive/iterators/transform_width.hpp>
34#include <boost/iostreams/copy.hpp>
35#include <boost/lexical_cast.hpp>
36#include <boost/random.hpp>
37#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
54#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
63#ifdef DEAL_II_WITH_TRILINOS
64# ifdef DEAL_II_WITH_MPI
69# include <Epetra_MpiComm.h>
70# include <Teuchos_DefaultComm.hpp>
72# include <Epetra_SerialComm.h>
73# include <Teuchos_RCP.hpp>
84 <<
"When trying to convert " << arg1 <<
" to a string with "
85 << arg2 <<
" digits");
89 <<
"Can't convert the string " << arg1
90 <<
" to the desired type");
107 std::vector<std::array<std::uint64_t, effective_dim>>
108 inverse_Hilbert_space_filling_curve_effective(
111 const std::array<LongDouble, dim> &extents,
112 const std::bitset<dim> &valid_extents,
114 const Integer max_int)
116 std::vector<std::array<Integer, effective_dim>> int_points(points.size());
118 for (
unsigned int i = 0; i < points.size(); ++i)
121 unsigned int eff_d = 0;
122 for (
unsigned int d = 0; d < dim; ++d)
123 if (valid_extents[d])
126 const LongDouble v = (
static_cast<LongDouble
>(points[i][d]) -
127 static_cast<LongDouble
>(bl[d])) /
131 int_points[i][eff_d] =
132 static_cast<Integer
>(v *
static_cast<LongDouble
>(max_int));
138 return inverse_Hilbert_space_filling_curve<effective_dim>(int_points,
143 template <
int dim,
typename Number>
144 std::vector<std::array<std::uint64_t, dim>>
147 const int bits_per_dim)
149 using Integer = std::uint64_t;
151 using LongDouble =
long double;
155 return std::vector<std::array<std::uint64_t, dim>>();
159 for (
const auto &p : points)
160 for (
unsigned int d = 0; d < dim; ++d)
162 const double cid = p[d];
167 std::array<LongDouble, dim> extents;
168 std::bitset<dim> valid_extents;
169 for (
unsigned int i = 0; i < dim; ++i)
172 static_cast<LongDouble
>(tr[i]) -
static_cast<LongDouble
>(bl[i]);
173 valid_extents[i] = (extents[i] > 0.);
180 std::min(std::numeric_limits<Integer>::digits,
181 std::numeric_limits<LongDouble>::digits));
184 const Integer max_int = (min_bits == std::numeric_limits<Integer>::digits ?
185 std::numeric_limits<Integer>::max() :
186 (Integer(1) << min_bits) - 1);
188 const unsigned int effective_dim = valid_extents.count();
189 if (effective_dim == dim)
191 return inverse_Hilbert_space_filling_curve_effective<dim,
196 points, bl, extents, valid_extents, min_bits, max_int);
200 std::array<std::uint64_t, dim> zero_ind;
201 for (
unsigned int d = 0; d < dim; ++d)
204 std::vector<std::array<std::uint64_t, dim>> ind(points.size(), zero_ind);
206 if (dim == 3 && effective_dim == 2)
209 inverse_Hilbert_space_filling_curve_effective<dim,
214 points, bl, extents, valid_extents, min_bits, max_int);
216 for (
unsigned int i = 0; i < ind.size(); ++i)
217 for (
unsigned int d = 0; d < 2; ++d)
218 ind[i][d + 1] = ind2[i][d];
222 else if (effective_dim == 1)
225 inverse_Hilbert_space_filling_curve_effective<dim,
230 points, bl, extents, valid_extents, min_bits, max_int);
232 for (
unsigned int i = 0; i < ind.size(); ++i)
233 ind[i][dim - 1] = ind1[i][0];
244 for (
unsigned int i = 0; i < points.size(); ++i)
253 std::vector<std::array<std::uint64_t, dim>>
255 const std::vector<std::array<std::uint64_t, dim>> &points,
256 const int bits_per_dim)
258 using Integer = std::uint64_t;
260 std::vector<std::array<Integer, dim>> int_points(points);
262 std::vector<std::array<Integer, dim>> res(int_points.size());
285 Assert(bits_per_dim <= std::numeric_limits<Integer>::digits,
286 ExcMessage(
"This integer type can not hold " +
287 std::to_string(bits_per_dim) +
" bits."));
289 const Integer M = Integer(1) << (bits_per_dim - 1);
291 for (
unsigned int index = 0; index < int_points.size(); ++index)
293 auto &X = int_points[index];
294 auto &L = res[index];
297 for (Integer q = M; q > 1; q >>= 1)
299 const Integer p = q - 1;
300 for (
unsigned int i = 0; i < dim; ++i)
310 const Integer t = (X[0] ^ X[i]) & p;
318 for (
unsigned int i = 1; i < dim; ++i)
322 for (Integer q = M; q > 1; q >>= 1)
325 for (
unsigned int i = 0; i < dim; ++i)
340 for (
unsigned int i = 0; i < dim; ++i)
344 for (Integer q = M; q > 0; q >>= 1)
367 const int bits_per_dim)
369 using Integer = std::uint64_t;
374 const Integer mask = (Integer(1) << bits_per_dim) - 1;
377 for (
unsigned int i = 0; i < dim; ++i)
380 const Integer v = (mask & index[dim - 1 - i]) << (bits_per_dim * i);
391#ifdef DEAL_II_WITH_ZLIB
392 namespace bio = boost::iostreams;
394 std::stringstream compressed;
395 std::stringstream origin(input);
397 bio::filtering_streambuf<bio::input> out;
398 out.push(bio::gzip_compressor());
400 bio::copy(out, compressed);
402 return compressed.str();
413#ifdef DEAL_II_WITH_ZLIB
414 namespace bio = boost::iostreams;
416 std::stringstream compressed(compressed_input);
417 std::stringstream decompressed;
419 bio::filtering_streambuf<bio::input> out;
420 out.push(bio::gzip_decompressor());
421 out.push(compressed);
422 bio::copy(out, decompressed);
424 return decompressed.str();
426 return compressed_input;
435 using namespace boost::archive::iterators;
436 using It = base64_from_binary<
437 transform_width<std::vector<unsigned char>::const_iterator, 6, 8>>;
438 auto base64 = std::string(It(binary_input.begin()), It(binary_input.end()));
440 return base64.append((3 - binary_input.size() % 3) % 3,
'=');
445 std::vector<unsigned char>
448 using namespace boost::archive::iterators;
450 transform_width<binary_from_base64<std::string::const_iterator>, 8, 6>;
451 auto binary = std::vector<unsigned char>(It(base64_input.begin()),
452 It(base64_input.end()));
454 auto length = base64_input.size();
455 if (binary.size() > 2 && base64_input[length - 1] ==
'=' &&
456 base64_input[length - 2] ==
'=')
458 binary.erase(binary.end() - 2, binary.end());
460 else if (binary.size() > 1 && base64_input[length - 1] ==
'=')
462 binary.erase(binary.end() - 1, binary.end());
477 template <
typename number>
479 to_string(
const number value,
const unsigned int digits)
489 std::string lc_string =
490 (std::is_integral_v<number> ? std::to_string(value) :
491 boost::lexical_cast<std::string>(value));
494 (lc_string.size() < digits))
497 const unsigned int padding_position = (lc_string[0] ==
'-') ? 1 : 0;
499 const std::string padding(digits - lc_string.size(),
'0');
500 lc_string.insert(padding_position, padding);
510 const std::string &from,
511 const std::string &to)
516 std::string out = input;
517 std::string::size_type pos = out.find(from);
519 while (pos != std::string::npos)
521 out.replace(pos, from.size(), to);
522 pos = out.find(from, pos + to.size());
530 std::string::size_type left = 0;
531 std::string::size_type right = input.size() > 0 ? input.size() - 1 : 0;
533 for (; left < input.size(); ++left)
535 if (std::isspace(input[left]) == 0)
541 for (; right >= left; --right)
543 if (std::isspace(input[right]) == 0)
549 return std::string(input, left, right - left + 1);
568 return static_cast<int>(
569 std::ceil(std::log10(std::fabs(max_number + 0.1))));
576 template <
typename Number>
582 if (!(std::fabs(number) > std::numeric_limits<Number>::min()))
586 static_cast<int>(std::floor(std::log10(std::fabs(number))));
588 const int shift = -order +
static_cast<int>(n_digits) - 1;
590 Assert(shift <=
static_cast<int>(std::floor(
591 std::log10(std::numeric_limits<Number>::max()))),
593 "Overflow. Use a smaller value for n_digits and/or make sure "
594 "that the absolute value of 'number' does not become too small."));
596 const Number factor =
std::pow(10.0,
static_cast<Number
>(shift));
598 const Number number_cutoff = std::trunc(number * factor) / factor;
600 return number_cutoff;
609 while ((s.size() > 0) && (s[0] ==
' '))
611 while ((s.size() > 0) && (s.back() ==
' '))
612 s.erase(s.end() - 1);
622 const int i = std::strtol(s.c_str(), &p, 10);
633 ((s.size() > 0) && (*p !=
'\0'))),
634 ExcMessage(
"Can't convert <" + s +
"> to an integer."));
644 std::vector<int> tmp(s.size());
645 for (
unsigned int i = 0; i < s.size(); ++i)
657 while ((s.size() > 0) && (s[0] ==
' '))
659 while ((s.size() > 0) && (s.back() ==
' '))
660 s.erase(s.end() - 1);
670 const double d = std::strtod(s.c_str(), &p);
681 ((s.size() > 0) && (*p !=
'\0'))),
682 ExcMessage(
"Can't convert <" + s +
"> to a double."));
692 std::vector<double> tmp(s.size());
693 for (
unsigned int i = 0; i < s.size(); ++i)
700 std::vector<std::string>
709 while (tmp.size() != 0 && tmp.back() ==
' ')
710 tmp.erase(tmp.size() - 1, 1);
718 std::vector<std::string> split_list;
719 while (tmp.size() != 0)
724 if (name.find(delimiter) != std::string::npos)
726 name.erase(name.find(delimiter), std::string::npos);
727 tmp.erase(0, tmp.find(delimiter) + delimiter.size());
733 while ((name.size() != 0) && (name[0] ==
' '))
735 while (name.size() != 0 && name.back() ==
' ')
736 name.erase(name.size() - 1, 1);
738 split_list.push_back(name);
745 std::vector<std::string>
754 std::vector<std::string>
756 const unsigned int width,
757 const char delimiter)
759 std::string text = original_text;
760 std::vector<std::string> lines;
763 while ((text.size() != 0) && (text.back() == delimiter))
764 text.erase(text.size() - 1, 1);
767 while (text.size() != 0)
771 while ((text.size() != 0) && (text[0] == delimiter))
774 std::size_t pos_newline = text.find_first_of(
'\n', 0);
775 if (pos_newline != std::string::npos && pos_newline <= width)
777 std::string line(text, 0, pos_newline);
778 while ((line.size() != 0) && (line.back() == delimiter))
779 line.erase(line.size() - 1, 1);
780 lines.push_back(line);
781 text.erase(0, pos_newline + 1);
788 if (text.size() < width)
791 while ((text.size() != 0) && (text.back() == delimiter))
792 text.erase(text.size() - 1, 1);
793 lines.push_back(text);
801 int location = std::min<int>(width, text.size() - 1);
802 for (; location > 0; --location)
803 if (text[location] == delimiter)
809 for (location = std::min<int>(width, text.size() - 1);
810 location < static_cast<int>(text.size());
812 if (text[location] == delimiter)
818 std::string line(text, 0, location);
819 while ((line.size() != 0) && (line.back() == delimiter))
820 line.erase(line.size() - 1, 1);
821 lines.push_back(line);
822 text.erase(0, location);
834 if (pattern.size() > name.size())
837 for (
unsigned int i = 0; i < pattern.size(); ++i)
838 if (pattern[i] != name[i])
846 std::pair<int, unsigned int>
851 const std::string test_string(name.begin() + position, name.end());
853 std::istringstream str(test_string);
863 return std::make_pair(i, 1U);
865 return std::make_pair(i, 2U);
867 return std::make_pair(i, 3U);
869 return std::make_pair(i, 4U);
871 return std::make_pair(i, 5U);
872 else if (i < 1000000)
873 return std::make_pair(i, 6U);
874 else if (i < 10000000)
875 return std::make_pair(i, 7U);
903 return boost::normal_distribution<>(a,
904 sigma)(random_number_generator.
get());
916 std::ifstream cpuinfo;
917 cpuinfo.open(
"/proc/loadavg");
957 "Invalid DEAL_II_VECTORIZATION_WIDTH_IN_BITS."));
972 std::ifstream file(
"/proc/self/status");
978 if (name ==
"VmPeak:")
980 else if (name ==
"VmSize:")
982 else if (name ==
"VmHWM:")
984 else if (name ==
"VmRSS:")
1000#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
1001 const unsigned int N = 1024;
1003 gethostname(&(hostname[0]), N - 1);
1005 std::string hostname(
"unknown");
1015 std::time_t time1 = std::time(
nullptr);
1016 const std::tm *time = std::localtime(&time1);
1018 std::ostringstream o;
1019 o << time->tm_hour <<
":" << (time->tm_min < 10 ?
"0" :
"")
1020 << time->tm_min <<
":" << (time->tm_sec < 10 ?
"0" :
"")
1031 std::time_t time1 = std::time(
nullptr);
1032 const std::tm *time = std::localtime(&time1);
1034 std::ostringstream o;
1035 o << time->tm_year + 1900 <<
"/" << time->tm_mon + 1 <<
"/"
1062 *memptr = malloc(
size);
1081 template std::string
1082 to_string<int>(
int,
unsigned int);
1083 template std::string
1084 to_string<long int>(
long int,
unsigned int);
1085 template std::string
1086 to_string<long long int>(
long long int,
unsigned int);
1087 template std::string
1088 to_string<unsigned int>(
unsigned int,
unsigned int);
1089 template std::string
1090 to_string<unsigned long int>(
unsigned long int,
unsigned int);
1091 template std::string
1092 to_string<unsigned long long int>(
unsigned long long int,
unsigned int);
1093 template std::string
1094 to_string<float>(
float,
unsigned int);
1095 template std::string
1096 to_string<double>(
double,
unsigned int);
1097 template std::string
1098 to_string<long double>(
long double,
unsigned int);
1105 template std::vector<std::array<std::uint64_t, 1>>
1106 inverse_Hilbert_space_filling_curve<1, double>(
1109 template std::vector<std::array<std::uint64_t, 1>>
1110 inverse_Hilbert_space_filling_curve<1>(
1111 const std::vector<std::array<std::uint64_t, 1>> &,
1113 template std::vector<std::array<std::uint64_t, 2>>
1114 inverse_Hilbert_space_filling_curve<2, double>(
1117 template std::vector<std::array<std::uint64_t, 2>>
1118 inverse_Hilbert_space_filling_curve<2>(
1119 const std::vector<std::array<std::uint64_t, 2>> &,
1121 template std::vector<std::array<std::uint64_t, 3>>
1122 inverse_Hilbert_space_filling_curve<3, double>(
1125 template std::vector<std::array<std::uint64_t, 3>>
1126 inverse_Hilbert_space_filling_curve<3>(
1127 const std::vector<std::array<std::uint64_t, 3>> &,
1130 template std::uint64_t
1131 pack_integers<1>(
const std::array<std::uint64_t, 1> &,
const int);
1132 template std::uint64_t
1133 pack_integers<2>(
const std::array<std::uint64_t, 2> &,
const int);
1134 template std::uint64_t
1135 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
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)
#define DEAL_II_NOT_IMPLEMENTED()
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)
static const 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)