31#define BOOST_BIND_GLOBAL_PLACEHOLDERS
32#include <boost/archive/iterators/base64_from_binary.hpp>
33#include <boost/archive/iterators/binary_from_base64.hpp>
34#include <boost/archive/iterators/transform_width.hpp>
35#include <boost/iostreams/copy.hpp>
36#include <boost/lexical_cast.hpp>
37#include <boost/random.hpp>
38#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
55#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
64#ifdef DEAL_II_WITH_TRILINOS
65# ifdef DEAL_II_WITH_MPI
70# include <Epetra_MpiComm.h>
71# include <Teuchos_DefaultComm.hpp>
73# include <Epetra_SerialComm.h>
74# include <Teuchos_RCP.hpp>
85 <<
"When trying to convert " << arg1 <<
" to a string with "
86 << arg2 <<
" digits");
90 <<
"Can't convert the string " << arg1
91 <<
" to the desired type");
108 std::vector<std::array<std::uint64_t, effective_dim>>
109 inverse_Hilbert_space_filling_curve_effective(
112 const std::array<LongDouble, dim> & extents,
113 const std::bitset<dim> & valid_extents,
115 const Integer max_int)
117 std::vector<std::array<Integer, effective_dim>> int_points(points.size());
119 for (
unsigned int i = 0; i < points.size(); ++i)
122 unsigned int eff_d = 0;
123 for (
unsigned int d = 0; d < dim; ++d)
124 if (valid_extents[d])
127 const LongDouble v = (
static_cast<LongDouble
>(points[i][d]) -
128 static_cast<LongDouble
>(bl[d])) /
132 int_points[i][eff_d] =
133 static_cast<Integer
>(v *
static_cast<LongDouble
>(max_int));
139 return inverse_Hilbert_space_filling_curve<effective_dim>(int_points,
144 template <
int dim,
typename Number>
145 std::vector<std::array<std::uint64_t, dim>>
148 const int bits_per_dim)
150 using Integer = std::uint64_t;
152 using LongDouble =
long double;
155 if (points.size() == 0)
156 return std::vector<std::array<std::uint64_t, dim>>();
160 for (
const auto &p : points)
161 for (
unsigned int d = 0; d < dim; ++d)
163 const double cid = p[d];
168 std::array<LongDouble, dim> extents;
169 std::bitset<dim> valid_extents;
170 for (
unsigned int i = 0; i < dim; ++i)
173 static_cast<LongDouble
>(tr[i]) -
static_cast<LongDouble
>(bl[i]);
174 valid_extents[i] = (extents[i] > 0.);
181 std::min(std::numeric_limits<Integer>::digits,
182 std::numeric_limits<LongDouble>::digits));
185 const Integer max_int = (min_bits == std::numeric_limits<Integer>::digits ?
186 std::numeric_limits<Integer>::max() :
187 (Integer(1) << min_bits) - 1);
189 const unsigned int effective_dim = valid_extents.count();
190 if (effective_dim == dim)
192 return inverse_Hilbert_space_filling_curve_effective<dim,
197 points, bl, extents, valid_extents, min_bits, max_int);
201 std::array<std::uint64_t, dim> zero_ind;
202 for (
unsigned int d = 0; d < dim; ++d)
205 std::vector<std::array<std::uint64_t, dim>> ind(points.size(), zero_ind);
207 if (dim == 3 && effective_dim == 2)
210 inverse_Hilbert_space_filling_curve_effective<dim,
215 points, bl, extents, valid_extents, min_bits, max_int);
217 for (
unsigned int i = 0; i < ind.size(); ++i)
218 for (
unsigned int d = 0; d < 2; ++d)
219 ind[i][d + 1] = ind2[i][d];
223 else if (effective_dim == 1)
226 inverse_Hilbert_space_filling_curve_effective<dim,
231 points, bl, extents, valid_extents, min_bits, max_int);
233 for (
unsigned int i = 0; i < ind.size(); ++i)
234 ind[i][dim - 1] = ind1[i][0];
245 for (
unsigned int i = 0; i < points.size(); ++i)
254 std::vector<std::array<std::uint64_t, dim>>
256 const std::vector<std::array<std::uint64_t, dim>> &points,
257 const int bits_per_dim)
259 using Integer = std::uint64_t;
261 std::vector<std::array<Integer, dim>> int_points(points);
263 std::vector<std::array<Integer, dim>> res(int_points.size());
286 Assert(bits_per_dim <= std::numeric_limits<Integer>::digits,
287 ExcMessage(
"This integer type can not hold " +
288 std::to_string(bits_per_dim) +
" bits."));
290 const Integer M = Integer(1) << (bits_per_dim - 1);
292 for (
unsigned int index = 0; index < int_points.size(); ++index)
294 auto &X = int_points[index];
295 auto &L = res[index];
298 for (Integer q = M; q > 1; q >>= 1)
300 const Integer p = q - 1;
301 for (
unsigned int i = 0; i < dim; ++i)
311 const Integer t = (X[0] ^ X[i]) & p;
319 for (
unsigned int i = 1; i < dim; ++i)
323 for (Integer q = M; q > 1; q >>= 1)
326 for (
unsigned int i = 0; i < dim; ++i)
341 for (
unsigned int i = 0; i < dim; ++i)
345 for (Integer q = M; q > 0; q >>= 1)
368 const int bits_per_dim)
370 using Integer = std::uint64_t;
375 const Integer mask = (Integer(1) << bits_per_dim) - 1;
378 for (
unsigned int i = 0; i < dim; ++i)
381 const Integer v = (mask & index[dim - 1 - i]) << (bits_per_dim * i);
392#ifdef DEAL_II_WITH_ZLIB
393 namespace bio = boost::iostreams;
395 std::stringstream compressed;
396 std::stringstream origin(input);
398 bio::filtering_streambuf<bio::input> out;
399 out.push(bio::gzip_compressor());
401 bio::copy(out, compressed);
403 return compressed.str();
414#ifdef DEAL_II_WITH_ZLIB
415 namespace bio = boost::iostreams;
417 std::stringstream compressed(compressed_input);
418 std::stringstream decompressed;
420 bio::filtering_streambuf<bio::input> out;
421 out.push(bio::gzip_decompressor());
422 out.push(compressed);
423 bio::copy(out, decompressed);
425 return decompressed.str();
427 return compressed_input;
436 using namespace boost::archive::iterators;
437 using It = base64_from_binary<
438 transform_width<std::vector<unsigned char>::const_iterator, 6, 8>>;
439 auto base64 = std::string(It(binary_input.begin()), It(binary_input.end()));
441 return base64.append((3 - binary_input.size() % 3) % 3,
'=');
446 std::vector<unsigned char>
449 using namespace boost::archive::iterators;
451 transform_width<binary_from_base64<std::string::const_iterator>, 8, 6>;
452 auto binary = std::vector<unsigned char>(It(base64_input.begin()),
453 It(base64_input.end()));
455 auto length = base64_input.size();
456 if (binary.size() > 2 && base64_input[length - 1] ==
'=' &&
457 base64_input[length - 2] ==
'=')
459 binary.erase(binary.end() - 2, binary.end());
461 else if (binary.size() > 1 && base64_input[length - 1] ==
'=')
463 binary.erase(binary.end() - 1, binary.end());
478 template <
typename number>
480 to_string(
const number value,
const unsigned int digits)
490 std::string lc_string = (std::is_integral<number>::value ?
491 std::to_string(value) :
492 boost::lexical_cast<std::string>(value));
495 (lc_string.size() < digits))
498 const unsigned int padding_position = (lc_string[0] ==
'-') ? 1 : 0;
500 const std::string padding(digits - lc_string.size(),
'0');
501 lc_string.insert(padding_position, padding);
511 const std::string &from,
512 const std::string &to)
517 std::string out = input;
518 std::string::size_type pos = out.find(from);
520 while (pos != std::string::npos)
522 out.replace(pos, from.size(), to);
523 pos = out.find(from, pos + to.size());
531 std::string::size_type left = 0;
532 std::string::size_type right = input.size() > 0 ? input.size() - 1 : 0;
534 for (; left < input.size(); ++left)
536 if (std::isspace(input[left]) == 0)
542 for (; right >= left; --right)
544 if (std::isspace(input[right]) == 0)
550 return std::string(input, left, right - left + 1);
569 return static_cast<int>(
570 std::ceil(std::log10(std::fabs(max_number + 0.1))));
577 template <
typename Number>
583 if (!(std::fabs(number) > std::numeric_limits<Number>::min()))
587 static_cast<int>(std::floor(std::log10(std::fabs(number))));
589 const int shift = -order +
static_cast<int>(n_digits) - 1;
591 Assert(shift <=
static_cast<int>(std::floor(
592 std::log10(std::numeric_limits<Number>::max()))),
594 "Overflow. Use a smaller value for n_digits and/or make sure "
595 "that the absolute value of 'number' does not become too small."));
597 const Number factor =
std::pow(10.0,
static_cast<Number
>(shift));
599 const Number number_cutoff = std::trunc(number * factor) / factor;
601 return number_cutoff;
610 while ((s.size() > 0) && (s[0] ==
' '))
612 while ((s.size() > 0) && (s.back() ==
' '))
613 s.erase(s.end() - 1);
623 const int i = std::strtol(s.c_str(), &p, 10);
634 ((s.size() > 0) && (*p !=
'\0'))),
635 ExcMessage(
"Can't convert <" + s +
"> to an integer."));
645 std::vector<int> tmp(s.size());
646 for (
unsigned int i = 0; i < s.size(); ++i)
658 while ((s.size() > 0) && (s[0] ==
' '))
660 while ((s.size() > 0) && (s.back() ==
' '))
661 s.erase(s.end() - 1);
671 const double d = std::strtod(s.c_str(), &p);
682 ((s.size() > 0) && (*p !=
'\0'))),
683 ExcMessage(
"Can't convert <" + s +
"> to a double."));
693 std::vector<double> tmp(s.size());
694 for (
unsigned int i = 0; i < s.size(); ++i)
701 std::vector<std::string>
710 while (tmp.size() != 0 && tmp.back() ==
' ')
711 tmp.erase(tmp.size() - 1, 1);
719 std::vector<std::string> split_list;
720 while (tmp.size() != 0)
725 if (name.find(delimiter) != std::string::npos)
727 name.erase(name.find(delimiter), std::string::npos);
728 tmp.erase(0, tmp.find(delimiter) + delimiter.size());
734 while ((name.size() != 0) && (name[0] ==
' '))
736 while (name.size() != 0 && name.back() ==
' ')
737 name.erase(name.size() - 1, 1);
739 split_list.push_back(name);
746 std::vector<std::string>
755 std::vector<std::string>
757 const unsigned int width,
758 const char delimiter)
760 std::string text = original_text;
761 std::vector<std::string> lines;
764 while ((text.size() != 0) && (text.back() == delimiter))
765 text.erase(text.size() - 1, 1);
768 while (text.size() != 0)
772 while ((text.size() != 0) && (text[0] == delimiter))
775 std::size_t pos_newline = text.find_first_of(
'\n', 0);
776 if (pos_newline != std::string::npos && pos_newline <= width)
778 std::string line(text, 0, pos_newline);
779 while ((line.size() != 0) && (line.back() == delimiter))
780 line.erase(line.size() - 1, 1);
781 lines.push_back(line);
782 text.erase(0, pos_newline + 1);
789 if (text.size() < width)
792 while ((text.size() != 0) && (text.back() == delimiter))
793 text.erase(text.size() - 1, 1);
794 lines.push_back(text);
802 int location = std::min<int>(width, text.size() - 1);
803 for (; location > 0; --location)
804 if (text[location] == delimiter)
810 for (location = std::min<int>(width, text.size() - 1);
811 location < static_cast<int>(text.size());
813 if (text[location] == delimiter)
819 std::string line(text, 0, location);
820 while ((line.size() != 0) && (line.back() == delimiter))
821 line.erase(line.size() - 1, 1);
822 lines.push_back(line);
823 text.erase(0, location);
835 if (pattern.size() > name.size())
838 for (
unsigned int i = 0; i < pattern.size(); ++i)
839 if (pattern[i] != name[i])
847 std::pair<int, unsigned int>
852 const std::string test_string(name.begin() + position, name.end());
854 std::istringstream str(test_string);
864 return std::make_pair(i, 1U);
866 return std::make_pair(i, 2U);
868 return std::make_pair(i, 3U);
870 return std::make_pair(i, 4U);
872 return std::make_pair(i, 5U);
873 else if (i < 1000000)
874 return std::make_pair(i, 6U);
875 else if (i < 10000000)
876 return std::make_pair(i, 7U);
904 return boost::normal_distribution<>(a,
905 sigma)(random_number_generator.
get());
917 std::ifstream cpuinfo;
918 cpuinfo.open(
"/proc/loadavg");
958 "Invalid DEAL_II_VECTORIZATION_WIDTH_IN_BITS."));
973 std::ifstream file(
"/proc/self/status");
979 if (name ==
"VmPeak:")
981 else if (name ==
"VmSize:")
983 else if (name ==
"VmHWM:")
985 else if (name ==
"VmRSS:")
1001#if defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETHOSTNAME)
1002 const unsigned int N = 1024;
1004 gethostname(&(hostname[0]), N - 1);
1006 std::string hostname(
"unknown");
1016 std::time_t time1 = std::time(
nullptr);
1017 std::tm * time = std::localtime(&time1);
1019 std::ostringstream o;
1020 o << time->tm_hour <<
":" << (time->tm_min < 10 ?
"0" :
"")
1021 << time->tm_min <<
":" << (time->tm_sec < 10 ?
"0" :
"")
1032 std::time_t time1 = std::time(
nullptr);
1033 std::tm * time = std::localtime(&time1);
1035 std::ostringstream o;
1036 o << time->tm_year + 1900 <<
"/" << time->tm_mon + 1 <<
"/"
1055 *memptr = malloc(size);
1071 template std::string
1072 to_string<int>(
int,
unsigned int);
1073 template std::string
1074 to_string<long int>(
long int,
unsigned int);
1075 template std::string
1076 to_string<long long int>(
long long int,
unsigned int);
1077 template std::string
1078 to_string<unsigned int>(
unsigned int,
unsigned int);
1079 template std::string
1080 to_string<unsigned long int>(
unsigned long int,
unsigned int);
1081 template std::string
1082 to_string<unsigned long long int>(
unsigned long long int,
unsigned int);
1083 template std::string
1084 to_string<float>(
float,
unsigned int);
1085 template std::string
1086 to_string<double>(
double,
unsigned int);
1087 template std::string
1088 to_string<long double>(
long double,
unsigned int);
1095 template std::vector<std::array<std::uint64_t, 1>>
1096 inverse_Hilbert_space_filling_curve<1, double>(
1099 template std::vector<std::array<std::uint64_t, 1>>
1100 inverse_Hilbert_space_filling_curve<1>(
1101 const std::vector<std::array<std::uint64_t, 1>> &,
1103 template std::vector<std::array<std::uint64_t, 2>>
1104 inverse_Hilbert_space_filling_curve<2, double>(
1107 template std::vector<std::array<std::uint64_t, 2>>
1108 inverse_Hilbert_space_filling_curve<2>(
1109 const std::vector<std::array<std::uint64_t, 2>> &,
1111 template std::vector<std::array<std::uint64_t, 3>>
1112 inverse_Hilbert_space_filling_curve<3, double>(
1115 template std::vector<std::array<std::uint64_t, 3>>
1116 inverse_Hilbert_space_filling_curve<3>(
1117 const std::vector<std::array<std::uint64_t, 3>> &,
1120 template std::uint64_t
1121 pack_integers<1>(
const std::array<std::uint64_t, 1> &,
const int);
1122 template std::uint64_t
1123 pack_integers<2>(
const std::array<std::uint64_t, 2> &,
const int);
1124 template std::uint64_t
1125 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)
static ::ExceptionBase & ExcNotImplemented()
#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)
const 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)