libMesh
Classes | Functions
libMesh::Utility Namespace Reference

Classes

struct  CompareUnderlying
 Struct which defines a custom comparison object that can be used with std::sets of std::unique_ptrs. More...
 
struct  do_pow
 An efficient template instantiation for raising to an arbitrary integer power. More...
 
struct  do_pow< 0, T >
 
struct  do_pow< 1, T >
 
struct  do_pow< 6, T >
 
class  is_streamable
 Helper struct for enabling template metaprogramming/SFINAE. More...
 
class  ReverseBytes
 This Functor simply takes an object and reverses its byte representation. More...
 

Functions

template<typename T >
std::string enum_to_string (const T e)
 
uint32_t hashword (const uint32_t *k, size_t length, uint32_t initval=0)
 The hashword function takes an array of uint32_t's of length 'length' and computes a single key from it. More...
 
uint32_t hashword (const std::vector< uint32_t > &keys, uint32_t initval=0)
 Calls function above with slightly more convenient std::vector interface. More...
 
uint32_t hashword2 (const uint32_t &first, const uint32_t &second, uint32_t initval=0)
 This is a hard-coded version of hashword for hashing exactly 2 numbers. More...
 
uint64_t hashword2 (const uint64_t first, const uint64_t second)
 Call the 64-bit FNV hash function. More...
 
uint16_t hashword2 (const uint16_t first, const uint16_t second)
 
uint64_t hashword (const uint64_t *k, size_t length)
 Call the 64-bit FNV hash function. More...
 
uint16_t hashword (const uint16_t *k, size_t length)
 In a personal communication from Bob Jenkins, he recommended using "Probably final() from lookup3.c... More...
 
template<typename Container >
Container::value_type hashword (const Container &keys)
 Calls functions above with slightly more convenient std::vector/array compatible interface. More...
 
template<typename T >
string_to_enum (const std::string &s)
 
template<typename T >
string_to_enum (std::string_view s)
 
template<typename T >
string_to_enum (const char *s)
 
std::string get_timestamp ()
 
void print_timestamp (std::ostream &target=std::cout)
 
std::string system_info ()
 
template<typename Map , typename Key , typename std::enable_if<!is_streamable< Key >::value, Key >::type * = nullptr>
Map::mapped_type & map_find (Map &map, const Key &key, const char *filename, int line_number)
 -Wdangling-reference was nowhere near ready to add to -Wall in gcc 13. More...
 
template<typename Map , typename Key , typename std::enable_if<!is_streamable< Key >::value, Key >::type * = nullptr>
const Map::mapped_type & map_find (const Map &map, const Key &key, const char *filename, int line_number)
 A version of the function above that works for const objects. More...
 
template<typename Vector >
Vector::reference & vector_at (Vector &vec, typename Vector::size_type i, const char *filename, int line_number)
 A replacement for std::vector::at(i) which is meant to be used with a macro, and, unlike at(), gives a proper line number and useful error message when the index is past the end. More...
 
template<typename Vector >
Vector::const_reference & vector_at (const Vector &vec, typename Vector::size_type i, const char *filename, int line_number)
 Same as above, but for const inputs. More...
 
template<typename ForwardIter , typename T >
void iota (ForwardIter first, ForwardIter last, T value)
 Utility::iota was created back when std::iota was just an SGI STL extension. More...
 
template<class InputIterator >
bool is_sorted (InputIterator first, InputIterator last)
 Utility::is_sorted was created back when std::is_sorted was just an SGI STL extension. More...
 
template<class ForwardIterator , class T >
ForwardIterator binary_find (ForwardIterator first, ForwardIterator last, const T &value)
 The STL provides std::binary_search() which returns true or false depending on whether the searched-for value is found. More...
 
template<class ForwardIterator , class T , class Compare >
ForwardIterator binary_find (ForwardIterator first, ForwardIterator last, const T &value, Compare comp)
 As above, but takes a custom comparison object. More...
 
template<int N, typename T >
pow (const T &x)
 
unsigned int factorial (unsigned int n)
 A simple implementation of the factorial. More...
 
template<typename T >
binomial (T n, T k)
 
template<typename T >
void deallocate (std::vector< T > &vec)
 A convenient method to truly empty a vector using the "swap trick". More...
 
std::string complex_filename (std::string basename, unsigned int r_o_c=0)
 
void prepare_complex_data (const std::vector< Complex > &source, std::vector< Real > &real_part, std::vector< Real > &imag_part)
 Prepare complex data for writing. More...
 
int mkdir (const char *pathname)
 Create a directory. More...
 
std::string unzip_file (std::string_view name)
 Create an unzipped copy of a bz2 or xz file, returning the name of the now-unzipped file that can be directly opened. More...
 

Function Documentation

◆ binary_find() [1/2]

template<class ForwardIterator , class T >
ForwardIterator libMesh::Utility::binary_find ( ForwardIterator  first,
ForwardIterator  last,
const T &  value 
)

The STL provides std::binary_search() which returns true or false depending on whether the searched-for value is found.

In contrast, Utility::binary_find() uses a std::lower_bound() based search on a sorted range to find the required value.

Returns
An iterator to the searched-for element, or "last" if the element is not found.

Definition at line 265 of file utility.h.

References value.

Referenced by libMesh::UnstructuredMesh::stitching_helper(), and libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

266 {
267  ForwardIterator it = std::lower_bound(first, last, value);
268  return (it == last || value < *it) ? last : it;
269 }
static const bool value
Definition: xdr_io.C:54

◆ binary_find() [2/2]

template<class ForwardIterator , class T , class Compare >
ForwardIterator libMesh::Utility::binary_find ( ForwardIterator  first,
ForwardIterator  last,
const T &  value,
Compare  comp 
)

As above, but takes a custom comparison object.

Definition at line 275 of file utility.h.

References value.

276 {
277  ForwardIterator it = std::lower_bound(first, last, value, comp);
278  return (it == last || comp(value,*it)) ? last : it;
279 }
static const bool value
Definition: xdr_io.C:54

◆ binomial()

template<typename T >
T libMesh::Utility::binomial ( n,
k 
)

Definition at line 354 of file utility.h.

Referenced by libMesh::FE< Dim, LAGRANGE_VEC >::shape_deriv(), and libMesh::FE< Dim, LAGRANGE_VEC >::shape_second_deriv().

355 {
356  T ret = 1;
357 
358  // Binomial function is "symmetric" in k, C(n, k) = C(n, n-k).
359  if (k > n - k)
360  k = n - k;
361 
362  // Compute n * (n-1) * ... * (n-k+1) / (k * (k-1) * ... * 1)
363  for (T i = 0; i < k; ++i)
364  {
365  ret *= (n - i);
366  ret /= (i + 1);
367  }
368 
369  return ret;
370 }

◆ complex_filename()

std::string libMesh::Utility::complex_filename ( std::string  basename,
unsigned int  r_o_c = 0 
)
Returns
For r_o_c = 0 the filename for output of the real part of complex data, and for r_o_c = 1 the filename for the imaginary part.

Definition at line 111 of file utility.C.

113 {
114  if (r_o_c == 0)
115  basename.append(".real");
116 
117  else
118  basename.append(".imag");
119 
120  return basename;
121 }

◆ deallocate()

template<typename T >
void libMesh::Utility::deallocate ( std::vector< T > &  vec)

A convenient method to truly empty a vector using the "swap trick".

Definition at line 377 of file utility.h.

Referenced by libMesh::Nemesis_IO::read().

378 {
379  std::vector<T>().swap(vec);
380 }

◆ enum_to_string()

template<typename T >
std::string libMesh::Utility::enum_to_string ( const T  e)
Returns
the string which matches the enumeration e of type T.

Referenced by libMesh::LaspackLinearSolver< T >::adjoint_solve(), libMesh::AbaqusIO::assign_sideset_ids(), libMesh::AbaqusIO::assign_subdomain_ids(), libMesh::FETransformationBase< OutputShape >::build(), libMesh::Partitioner::build(), libMesh::FEAbstract::build(), libMesh::FEGenericBase< FEOutputType< T >::type >::build(), libMesh::Elem::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::FEGenericBase< FEOutputType< T >::type >::build_InfFE(), libMesh::System::calculate_norm(), libMesh::Elem::complete_order_equivalent_type(), libMesh::InfFE< Dim, T_radial, T_map >::compute_node_indices(), libMesh::InfFE< Dim, T_radial, T_map >::compute_node_indices_fast(), libMesh::InfFE< Dim, T_radial, T_map >::compute_shape_indices(), libMesh::TriangleWrapper::copy_tri_to_mesh(), libMesh::System::discrete_var_norm(), libMesh::UNVIO::elements_out(), libMesh::ReferenceElem::get(), libMesh::FEInterface::get_continuity(), libMesh::InfFEBase::get_elem_type(), libMesh::Elem::get_info(), libMesh::MeshBase::get_info(), libMesh::FEAbstract::get_refspace_nodes(), libMesh::MeshTools::Generation::Private::idx(), libMesh::FEInterface::ifem_inverse_map(), libMesh::FEInterface::ifem_map(), libMesh::FEInterface::ifem_nodal_soln(), libMesh::PetscVector< libMesh::Number >::init(), libMesh::QNodal::init_1D(), libMesh::QClough::init_2D(), libMesh::QGaussLobatto::init_2D(), libMesh::QGrid::init_2D(), libMesh::QConical::init_2D(), libMesh::QGauss::init_2D(), libMesh::QSimpson::init_2D(), libMesh::QTrap::init_2D(), libMesh::QNodal::init_2D(), libMesh::QGrundmann_Moller::init_2D(), libMesh::QClough::init_3D(), libMesh::QGaussLobatto::init_3D(), libMesh::QGrid::init_3D(), libMesh::QTrap::init_3D(), libMesh::QSimpson::init_3D(), libMesh::QConical::init_3D(), libMesh::QGauss::init_3D(), libMesh::QNodal::init_3D(), libMesh::QGrundmann_Moller::init_3D(), libMesh::FEInterface::is_hierarchic(), libMesh::LIBMESH_DEFAULT_VECTORIZED_FE(), libMesh::monomial_n_dofs(), libMesh::FEAbstract::on_reference_element(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::LinearSolver< Number >::print_converged_reason(), libMesh::Elem::quality(), libMesh::ExodusII_IO::read(), libMesh::AbaqusIO::read_elements(), libMesh::DofMap::reinit(), libMesh::Elem::second_order_equivalent_type(), libMesh::PetscLinearSolver< Number >::set_petsc_solver_type(), libMesh::SlepcEigenSolver< libMesh::Number >::set_slepc_solver_type(), libMesh::AztecLinearSolver< T >::set_solver_type(), libMesh::FE< Dim, LAGRANGE_VEC >::shape(), libMesh::FE< Dim, LAGRANGE_VEC >::shape_deriv(), libMesh::FE< Dim, LAGRANGE_VEC >::shape_second_deriv(), libMesh::EigenSparseLinearSolver< T >::solve(), libMesh::LaspackLinearSolver< T >::solve(), VolumeTest::test_elem(), ExodusTest< elem_type >::test_read_gold(), ExodusTest< elem_type >::test_write(), QuadratureTest::testBuild(), libMesh::TriangleInterface::triangulate(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO_Helper::write_elements(), and libMesh::GmshIO::write_post().

◆ factorial()

unsigned int libMesh::Utility::factorial ( unsigned int  n)
inline

A simple implementation of the factorial.

Definition at line 337 of file utility.h.

338 {
339 
340  unsigned int factorial_n = 1;
341 
342  if (n==0)
343  return factorial_n;
344 
345  for (unsigned int i=1; i<n; i++)
346  factorial_n *= i+1;
347 
348  return factorial_n;
349 }

◆ get_timestamp()

std::string libMesh::Utility::get_timestamp ( )

Definition at line 37 of file timestamp.C.

References libMesh::out.

Referenced by libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::PerfLog::get_info_header(), print_timestamp(), system_info(), libMesh::TransientRBConstruction::update_residual_terms(), and libMesh::RBConstruction::update_residual_terms().

38 {
39 #ifdef LIBMESH_HAVE_LOCALE
40  // Create time_put "facet"
41  std::locale loc;
42  const std::time_put<char> & tp = std::use_facet <std::time_put<char>> (loc);
43 
44  // Call C-style time getting functions
45  time_t now = time(nullptr);
46  tm * tm_struct = localtime(&now);
47 
48  // Date will eventually be stored in this ostringstream's string
49  std::ostringstream date_stream;
50 
51  // See below for documentation on the use of the
52  // std::time_put::put() function
53  tp.put(date_stream, /*s*/
54  date_stream, /*str*/
55  date_stream.fill(), /*fill*/
56  tm_struct, /*tm*/
57  'c'); /*format*/
58 
59  // Another way to use it is to totally customize the format...
60  // char pattern[]="%d %B %Y %I:%M:%S %p";
61  // tp.put(date_stream, /*s*/
62  // date_stream, /*str*/
63  // date_stream.fill(), /*fill*/
64  // tm_struct, /*tm*/
65  // pattern, /*format begin*/
66  // pattern+sizeof(pattern)-1); /*format end */
67 
68  return date_stream.str();
69 #else
70  // C-style code originally found here:
71  // http://people.sc.fsu.edu/~burkardt/cpp_src/timestamp/timestamp.C
72  // Author: John Burkardt, 24 September 2003
73  const unsigned int time_size = 40;
74  char time_buffer[time_size];
75 
76  time_t now = time (nullptr);
77  tm * tm_struct = localtime (&now);
78 
79  // No more than time_size characters will be placed into the array. If the
80  // total number of resulting characters, including the terminating
81  // NUL character, is not more than time_size, strftime() returns the
82  // number of characters in the array, not counting the terminating
83  // NUL. Otherwise, zero is returned and the buffer contents are
84  // indeterminate.
85  size_t len = strftime ( time_buffer, time_size, "%c", tm_struct );
86 
87  if (len != 0)
88  return std::string(time_buffer);
89  else
90  {
91  libMesh::out << "Error formatting time buffer, returning empty string!" << std::endl;
92  return std::string("");
93  }
94 
95 #endif // LIBMESH_HAVE_LOCALE
96 }
OStreamProxy out

◆ hashword() [1/5]

uint32_t libMesh::Utility::hashword ( const uint32_t *  k,
size_t  length,
uint32_t  initval = 0 
)
inline

The hashword function takes an array of uint32_t's of length 'length' and computes a single key from it.

Author
Bob Jenkins
Date
May 2006

Definition at line 153 of file hashword.h.

Referenced by libMesh::Elem::compute_key(), libMesh::SparsityPattern::Build::handle_vi_vj(), hashword(), and libMesh::Elem::key().

154 {
155  uint32_t a,b,c;
156 
157  // Set up the internal state
158  a = b = c = 0xdeadbeef + ((static_cast<uint32_t>(length))<<2) + initval;
159 
160  //------------------------------------------------- handle most of the key
161  while (length > 3)
162  {
163  a += k[0];
164  b += k[1];
165  c += k[2];
166  mix(a,b,c);
167  length -= 3;
168  k += 3;
169  }
170 
171  //------------------------------------------- handle the last 3 uint32_t's
172  switch(length) // all the case statements fall through
173  {
174  case 3 : c+=k[2];
175  libmesh_fallthrough();
176  case 2 : b+=k[1];
177  libmesh_fallthrough();
178  case 1 : a+=k[0];
179  final(a,b,c);
180  libmesh_fallthrough();
181  default: // case 0: nothing left to add
182  break;
183  }
184 
185  //------------------------------------------------------ report the result
186  return c;
187 }

◆ hashword() [2/5]

uint32_t libMesh::Utility::hashword ( const std::vector< uint32_t > &  keys,
uint32_t  initval = 0 
)
inline

Calls function above with slightly more convenient std::vector interface.

Definition at line 195 of file hashword.h.

References hashword().

196 {
197  return hashword(keys.data(), keys.size(), initval);
198 }
Container::value_type hashword(const Container &keys)
Calls functions above with slightly more convenient std::vector/array compatible interface.
Definition: hashword.h:304

◆ hashword() [3/5]

uint64_t libMesh::Utility::hashword ( const uint64_t *  k,
size_t  length 
)
inline

Call the 64-bit FNV hash function.

Definition at line 249 of file hashword.h.

250 {
251  return fnv_64_buf(k, 8*length);
252 }

◆ hashword() [4/5]

uint16_t libMesh::Utility::hashword ( const uint16_t *  k,
size_t  length 
)
inline

In a personal communication from Bob Jenkins, he recommended using "Probably final() from lookup3.c...

You could hash up to 6 16-bit integers that way. The output is c, or the top or bottom 16 bits of c if you only need 16 bit hash values." [JWP]

Definition at line 263 of file hashword.h.

264 {
265  // Three values that will be passed to final() after they are initialized.
266  uint32_t a = 0;
267  uint32_t b = 0;
268  uint32_t c = 0;
269 
270  switch (length)
271  {
272  case 3:
273  {
274  // Cast the inputs to 32 bit integers and call final().
275  a = k[0];
276  b = k[1];
277  c = k[2];
278  break;
279  }
280  case 4:
281  {
282  // Combine the 4 16-bit inputs, "w, x, y, z" into two 32-bit
283  // inputs "wx" and "yz" using bit operations and call final.
284  a = ((k[0]<<16) | (k[1] & 0xffff)); // wx
285  b = ((k[2]<<16) | (k[3] & 0xffff)); // yz
286  break;
287  }
288  default:
289  libmesh_error_msg("Unsupported length: " << length);
290  }
291 
292  // Result is returned in c
293  final(a,b,c);
294  return static_cast<uint16_t>(c);
295 }

◆ hashword() [5/5]

template<typename Container >
Container::value_type libMesh::Utility::hashword ( const Container &  keys)
inline

Calls functions above with slightly more convenient std::vector/array compatible interface.

Definition at line 304 of file hashword.h.

References hashword().

305 {
306  return hashword(keys.data(), keys.size());
307 }
Container::value_type hashword(const Container &keys)
Calls functions above with slightly more convenient std::vector/array compatible interface.
Definition: hashword.h:304

◆ hashword2() [1/3]

uint32_t libMesh::Utility::hashword2 ( const uint32_t &  first,
const uint32_t &  second,
uint32_t  initval = 0 
)
inline

This is a hard-coded version of hashword for hashing exactly 2 numbers.

Author
Bob Jenkins
Date
May 2006

Definition at line 210 of file hashword.h.

Referenced by libMesh::Elem::compute_key(), and libMesh::SparsityPattern::Build::handle_vi_vj().

211 {
212  uint32_t a,b,c;
213 
214  // Set up the internal state
215  a = b = c = 0xdeadbeef + 8 + initval;
216 
217  b+=second;
218  a+=first;
219  final(a,b,c);
220 
221  return c;
222 }

◆ hashword2() [2/3]

uint64_t libMesh::Utility::hashword2 ( const uint64_t  first,
const uint64_t  second 
)
inline

Call the 64-bit FNV hash function.

Definition at line 228 of file hashword.h.

229 {
230  // This isn't optimal (it would be nice to avoid this packing step)
231  // but we are going to go ahead and conform to the 32-bit
232  // hashword2() interface.
233  uint64_t k[2] = {first, second};
234 
235  // len is the total number of bytes in two 64-bit ints
236  return fnv_64_buf(k, /*len=*/8*2);
237 }

◆ hashword2() [3/3]

uint16_t libMesh::Utility::hashword2 ( const uint16_t  first,
const uint16_t  second 
)
inline

Definition at line 240 of file hashword.h.

241 {
242  return static_cast<uint16_t>(first%65449 + (second<<5)%65449);
243 }

◆ iota()

template<typename ForwardIter , typename T >
void libMesh::Utility::iota ( ForwardIter  first,
ForwardIter  last,
value 
)

◆ is_sorted()

template<class InputIterator >
bool libMesh::Utility::is_sorted ( InputIterator  first,
InputIterator  last 
)

Utility::is_sorted was created back when std::is_sorted was just an SGI STL extension.

Definition at line 247 of file utility.h.

248 {
249  libmesh_deprecated();
250  return std::is_sorted(first, last);
251 }
bool is_sorted(InputIterator first, InputIterator last)
Utility::is_sorted was created back when std::is_sorted was just an SGI STL extension.
Definition: utility.h:247

◆ map_find() [1/2]

template<typename Map , typename Key , typename std::enable_if<!is_streamable< Key >::value, Key >::type * = nullptr>
Map::mapped_type & libMesh::Utility::map_find ( Map &  map,
const Key &  key,
const char *  filename,
int  line_number 
)
inline

-Wdangling-reference was nowhere near ready to add to -Wall in gcc 13.

A version of the map_find() utility which can only be used if the map key is printable via std::stream.

It's been moved to -Wextra, but we use that too. :-)

See e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109642

Our map_find functions trigger it. This function should not be called directly (although it can be), instead see the libmesh_map_find() macro.

Calls find(key), and checks the result against end(). Returns the corresponding value if found, throws an error otherwise. Templated on the type of map, so this will work with both std::map and std::unordered_map.

Definition at line 105 of file utility.h.

109 {
110  auto it = map.find(key);
111  libmesh_error_msg_if(it == map.end(),
112  "map_find() error: key not found in file "
113  << filename << " on line " << line_number);
114  return it->second;
115 }

◆ map_find() [2/2]

template<typename Map , typename Key , typename std::enable_if<!is_streamable< Key >::value, Key >::type * = nullptr>
const Map::mapped_type & libMesh::Utility::map_find ( const Map &  map,
const Key &  key,
const char *  filename,
int  line_number 
)
inline

A version of the function above that works for const objects.

Definition at line 124 of file utility.h.

128 {
129  auto it = map.find(key);
130  libmesh_error_msg_if(it == map.end(),
131  "map_find() error: key not found in file "
132  << filename << " on line " << line_number);
133  return it->second;
134 }

◆ mkdir()

int libMesh::Utility::mkdir ( const char *  pathname)

Create a directory.

Definition at line 144 of file utility.C.

Referenced by libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::write_out_interior_basis_functions(), libMesh::RBEIMEvaluation::write_out_node_basis_functions(), libMesh::RBEIMEvaluation::write_out_side_basis_functions(), libMesh::RBEvaluation::write_out_vectors(), and libMesh::RBConstruction::write_riesz_representors_to_files().

144  {
145 #if defined(LIBMESH_HAVE_MKDIR)
146  return ::mkdir(pathname, 0755);
147 #elif LIBMESH_HAVE_DECL__MKDIR
148  return _mkdir(pathname);
149 #else
150  libmesh_error_msg("Function mkdir not available on this system.");
151 #endif
152 
153 }
int mkdir(const char *pathname)
Create a directory.
Definition: utility.C:144

◆ pow()

template<int N, typename T >
T libMesh::Utility::pow ( const T &  x)
inline

Definition at line 328 of file utility.h.

References libMesh::Utility::do_pow< N, T >::apply().

Referenced by GETPOT_NAMESPACE::GetPot::_DBE_expand(), assemble_ellipticdg(), assemble_laplace(), compute_jacobian(), compute_residual(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), libMesh::ContinuationSystem::continuation_solve(), exact_derivative(), exact_solution(), libMesh::RBConstructionBase< CondensedEigenSystem >::generate_training_parameters_deterministic(), libMesh::RBConstructionBase< CondensedEigenSystem >::generate_training_parameters_random(), libMesh::FESubdivision::init_shape_functions(), libMesh::RBEIMConstruction::inner_product(), libMesh::InverseDistanceInterpolation< KDDim >::interpolate(), libMesh::LIBMESH_DEFAULT_VECTORIZED_FE(), std::LIBMESH_FLOAT128_BINARY(), main(), libMesh::VariationalMeshSmoother::maxE(), libMesh::VariationalMeshSmoother::metr_data_gen(), libMesh::VariationalMeshSmoother::minJ(), libMesh::VariationalMeshSmoother::minJ_BC(), libMesh::RBEIMConstruction::node_inner_product(), libMesh::Hex::quality(), libMesh::TransientRBEvaluation::rb_solve(), libMesh::FESubdivision::regular_shape(), libMesh::FE< Dim, LAGRANGE_VEC >::shape_deriv(), libMesh::FE< Dim, LAGRANGE_VEC >::shape_second_deriv(), libMesh::RBEIMConstruction::side_inner_product(), libMesh::MeshTools::Modification::smooth(), libMesh::TwostepTimeSolver::solve(), ElemTest< elem_type >::test_n_refinements(), QuadratureTest::testJacobi(), QuadratureTest::testPolynomial(), libMesh::BoundaryInfo::transfer_boundary_ids_from_children(), and libMesh::VariationalMeshSmoother::vertex().

329 {
330  return do_pow<N,T>::apply(x);
331 }

◆ prepare_complex_data()

void libMesh::Utility::prepare_complex_data ( const std::vector< Complex > &  source,
std::vector< Real > &  real_part,
std::vector< Real > &  imag_part 
)

Prepare complex data for writing.

Definition at line 125 of file utility.C.

128 {
129  const unsigned int len = source.size();
130 
131  real_part.resize(len);
132  imag_part.resize(len);
133 
134  for (unsigned int i=0; i<len; i++)
135  {
136  real_part[i] = source[i].real();
137  imag_part[i] = source[i].imag();
138  }
139 }

◆ print_timestamp()

void libMesh::Utility::print_timestamp ( std::ostream &  target = std::cout)
inline

Definition at line 37 of file timestamp.h.

References get_timestamp().

38 {
39  target << get_timestamp() << std::endl;
40 }
std::string get_timestamp()
Definition: timestamp.C:37

◆ string_to_enum() [1/3]

template<typename T >
T libMesh::Utility::string_to_enum ( const std::string &  s)
Returns
the enumeration of type T which matches the string s.

◆ string_to_enum() [2/3]

template<typename T >
T libMesh::Utility::string_to_enum ( std::string_view  s)
Returns
the enumeration of type T which matches the string_view s.

◆ string_to_enum() [3/3]

template<typename T >
T libMesh::Utility::string_to_enum ( const char *  s)
Returns
the enumeration of type T which matches the C-style string s.

◆ system_info()

std::string libMesh::Utility::system_info ( )
Returns
A string containing information about the system you are running on.

Definition at line 63 of file utility.C.

References get_timestamp().

64 {
65  std::ostringstream oss;
66 
67  std::string date = Utility::get_timestamp();
68 
69 #ifdef LIBMESH_HAVE_SYS_UTSNAME_H
70  // Get system information
71  struct utsname sysInfo;
72  uname(&sysInfo);
73 #endif
74 
75  // Get user information
76 #ifdef LIBMESH_HAVE_GETPWUID
77  struct passwd * p = getpwuid(getuid());
78 #endif
79 
80 
81  oss << '\n'
82  << " ---------------------------------------------------------------------\n"
83  << "| Time: " << date << '\n'
84 #ifdef LIBMESH_HAVE_SYS_UTSNAME_H
85  << "| OS: " << sysInfo.sysname << '\n'
86  << "| HostName: " << sysInfo.nodename << '\n'
87  << "| OS Release " << sysInfo.release << '\n'
88  << "| OS Version: " << sysInfo.version << '\n'
89  << "| Machine: " << sysInfo.machine << '\n'
90 #else
91  << "| OS: " << "Unknown" << '\n'
92  << "| HostName: " << "Unknown" << '\n'
93  << "| OS Release " << "Unknown" << '\n'
94  << "| OS Version: " << "Unknown" << '\n'
95  << "| Machine: " << "Unknown" << '\n'
96 #endif
97 #ifdef LIBMESH_HAVE_GETPWUID
98  << "| Username: " << p->pw_name << '\n'
99 #else
100  << "| Username: " << "Unknown" << '\n'
101 #endif
102  << " ---------------------------------------------------------------------\n";
103 
104  return oss.str();
105 }
std::string get_timestamp()
Definition: timestamp.C:37

◆ unzip_file()

std::string libMesh::Utility::unzip_file ( std::string_view  name)

Create an unzipped copy of a bz2 or xz file, returning the name of the now-unzipped file that can be directly opened.

This is a hack because we don't have a neat bz2/xz equivalent to gzstreams.

Definition at line 156 of file utility.C.

References libMesh::Quality::name().

Referenced by libMesh::Xdr::open(), libMesh::AbaqusIO::read(), and libMesh::DynaIO::read().

157 {
158  std::ostringstream pid_suffix;
159  pid_suffix << '_' << getpid();
160 
161  std::string new_name { name };
162  if (name.rfind(".bz2") == name.size() - 4)
163  {
164 #ifdef LIBMESH_HAVE_BZIP
165  new_name.erase(new_name.end() - 4, new_name.end());
166  new_name += pid_suffix.str();
167  LOG_SCOPE("system(bunzip2)", "Utility");
168  std::string system_string = "bunzip2 -f -k -c ";
169  system_string.append(name);
170  system_string += " > " + new_name;
171  if (std::system(system_string.c_str()))
172  libmesh_file_error(system_string);
173 #else
174  libmesh_error_msg("ERROR: need bzip2/bunzip2 to open .bz2 file " << name);
175 #endif
176  }
177  else if (name.rfind(".xz") == name.size() - 3)
178  {
179 #ifdef LIBMESH_HAVE_XZ
180  new_name.erase(new_name.end() - 3, new_name.end());
181  new_name += pid_suffix.str();
182  LOG_SCOPE("system(xz -d)", "Utility");
183  std::string system_string = "xz -f -d -k -c ";
184  system_string.append(name);
185  system_string += " > " + new_name;
186  if (std::system(system_string.c_str()))
187  libmesh_file_error(system_string);
188 #else
189  libmesh_error_msg("ERROR: need xz to open .xz file " << name);
190 #endif
191  }
192  return new_name;
193 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42

◆ vector_at() [1/2]

template<typename Vector >
Vector::reference& libMesh::Utility::vector_at ( Vector &  vec,
typename Vector::size_type  i,
const char *  filename,
int  line_number 
)
inline

A replacement for std::vector::at(i) which is meant to be used with a macro, and, unlike at(), gives a proper line number and useful error message when the index is past the end.

Definition at line 192 of file utility.h.

196 {
197  libmesh_error_msg_if(i >= vec.size(),
198  "vec_at() error: Index " << i <<
199  " past end of vector in file " << filename <<
200  " on line " << line_number);
201  return vec[i];
202 }

◆ vector_at() [2/2]

template<typename Vector >
Vector::const_reference& libMesh::Utility::vector_at ( const Vector &  vec,
typename Vector::size_type  i,
const char *  filename,
int  line_number 
)
inline

Same as above, but for const inputs.

Definition at line 210 of file utility.h.

214 {
215  libmesh_error_msg_if(i >= vec.size(),
216  "vec_at() error: Index " << i <<
217  " past end of vector in file " << filename <<
218  " on line " << line_number);
219  return vec[i];
220 }