libMesh::Utility Namespace Reference

Classes

struct  do_pow
struct  do_pow< 6, T >
struct  do_pow< 1, T >
struct  do_pow< 0, T >
class  ReverseBytes

Functions

template<>
ElemType string_to_enum< ElemType > (const std::string &s)
template<>
std::string enum_to_string< ElemType > (const ElemType e)
template<>
Order string_to_enum< Order > (const std::string &s)
template<>
std::string enum_to_string< Order > (const Order o)
template<>
FEFamily string_to_enum< FEFamily > (const std::string &s)
template<>
std::string enum_to_string< FEFamily > (const FEFamily f)
template<>
InfMapType string_to_enum< InfMapType > (const std::string &s)
template<>
std::string enum_to_string< InfMapType > (const InfMapType i)
template<>
QuadratureType string_to_enum< QuadratureType > (const std::string &s)
template<>
std::string enum_to_string< QuadratureType > (const QuadratureType i)
template<>
PreconditionerType string_to_enum< PreconditionerType > (const std::string &s)
template<>
std::string enum_to_string< PreconditionerType > (const PreconditionerType i)
template<>
Elem::RefinementState string_to_enum< Elem::RefinementState > (const std::string &s)
template<>
std::string enum_to_string< Elem::RefinementState > (const Elem::RefinementState i)
std::string get_timestamp ()
uint32_t hashword (const uint32_t *k, size_t length, uint32_t initval=0)
uint32_t hashword2 (const uint32_t &first, const uint32_t &second, uint32_t initval=0)
uint64_t hashword2 (const uint64_t first, const uint64_t second)
uint16_t hashword2 (const uint16_t first, const uint16_t second)
uint64_t hashword (const uint64_t *k, size_t length)
uint16_t hashword (const uint16_t *k, size_t length)
template<typename T >
string_to_enum (const std::string &s)
template<typename T >
std::string enum_to_string (const T e)
void print_timestamp (std::ostream &target=std::cout)
std::string system_info ()
template<typename ForwardIter , typename T >
void iota (ForwardIter first, ForwardIter last, T value)
template<class InputIterator >
bool is_sorted (InputIterator first, InputIterator last)
template<class ForwardIterator , class T >
ForwardIterator binary_find (ForwardIterator first, ForwardIterator last, const T &value)
template<int N, typename T >
pow (const T &x)
unsigned int factorial (unsigned int n)
template<typename T >
void deallocate (std::vector< T > &vec)
std::string complex_filename (const 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)

Function Documentation

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

The STL provides binary_search() which returns true/false depending on whether the searched-for value is found. Utility::binary_find() uses a binary search on a sorted range to return an iterator to the searched-for element, or "last" if the element is not found.

Definition at line 130 of file utility.h.

Referenced by libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole().

00131   {
00132     ForwardIterator it = std::lower_bound(first, last, value);
00133     return (it == last || value < *it) ? last : it;
00134   }

std::string libMesh::Utility::complex_filename ( const 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 83 of file utility.C.

References libMesh::Quality::name().

Referenced by libMesh::LegacyXdrIO::read_mgf_soln(), and libMesh::LegacyXdrIO::write_mgf_soln().

00085 {
00086   std::string name(basename);
00087 
00088   if (r_o_c == 0)
00089     name.append(".real");
00090 
00091   else
00092     name.append(".imag");
00093 
00094   return name;
00095 }

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

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

Definition at line 214 of file utility.h.

References swap().

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

00215   {
00216     std::vector<T>().swap(vec);
00217   }

template<typename T >
std::string libMesh::Utility::enum_to_string ( const T  e  )  [inline]

Takes the enumeration e of type T and returns the matching string.

Referenced by libMesh::AbaqusIO::assign_sideset_ids(), libMesh::Elem::get_info(), and libMesh::DofMap::reinit().

template<>
std::string libMesh::Utility::enum_to_string< Elem::RefinementState > ( const Elem::RefinementState  i  )  [inline]
template<>
std::string libMesh::Utility::enum_to_string< ElemType > ( const ElemType  e  )  [inline]
template<>
std::string libMesh::Utility::enum_to_string< FEFamily > ( const FEFamily  f  )  [inline]
template<>
std::string libMesh::Utility::enum_to_string< InfMapType > ( const InfMapType  i  )  [inline]
template<>
std::string libMesh::Utility::enum_to_string< Order > ( const Order  o  )  [inline]
template<>
std::string libMesh::Utility::enum_to_string< PreconditionerType > ( const PreconditionerType  i  )  [inline]
template<>
std::string libMesh::Utility::enum_to_string< QuadratureType > ( const QuadratureType  i  )  [inline]
unsigned int libMesh::Utility::factorial ( unsigned int  n  )  [inline]

A simple implementation of the factorial.

Definition at line 194 of file utility.h.

Referenced by libMesh::FE< Dim, T >::shape(), and libMesh::FE< Dim, T >::shape_deriv().

00195     {
00196 
00197       unsigned int factorial_n = 1;
00198 
00199       if (n==0)
00200         return factorial_n;
00201 
00202       for (unsigned int i=1; i<n; i++)
00203         factorial_n *= i+1;
00204 
00205       return factorial_n;
00206     }

std::string libMesh::Utility::get_timestamp (  ) 
uint16_t libMesh::Utility::hashword ( const uint16_t *  k,
size_t  length 
) [inline]

Definition at line 183 of file hashword.h.

00184     {
00185       // "big" prime number
00186       const uint16_t bp = 257;
00187 
00188       uint16_t c = 0;
00189       uint16_t shift=0;
00190       for (size_t i=0; i != length; ++i)
00191         {
00192           c = static_cast<uint16_t>
00193             (c + static_cast<uint16_t>(k[i] << shift) % bp);
00194           shift = static_cast<uint16_t>(shift+3);
00195         }
00196 
00197       return c;
00198     }

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

Definition at line 165 of file hashword.h.

00166     {
00167       // big prime number
00168       const unsigned int bp = 65449;
00169 
00170       uint64_t c = 0;
00171       unsigned int shift=0;
00172       for (size_t i=0; i != length; ++i)
00173         {
00174           c += (k[i] << shift) % bp;
00175           shift += 5;
00176         }
00177 
00178       return c;
00179     }

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

Definition at line 92 of file hashword.h.

Referenced by libMesh::Elem::compute_key().

00093     {
00094       uint32_t a,b,c;
00095 
00096       // Set up the internal state
00097       a = b = c = 0xdeadbeef + ((static_cast<uint32_t>(length))<<2) + initval;
00098 
00099       //------------------------------------------------- handle most of the key
00100       while (length > 3)
00101         {
00102           a += k[0];
00103           b += k[1];
00104           c += k[2];
00105           mix(a,b,c);
00106           length -= 3;
00107           k += 3;
00108         }
00109 
00110       //------------------------------------------- handle the last 3 uint32_t's
00111       switch(length)                     // all the case statements fall through
00112         {
00113         case 3 : c+=k[2];
00114         case 2 : b+=k[1];
00115         case 1 : a+=k[0];
00116           final(a,b,c);
00117         default:     // case 0: nothing left to add
00118           break;
00119         }
00120 
00121       //------------------------------------------------------ report the result
00122       return c;
00123     }

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

Definition at line 155 of file hashword.h.

00156     {
00157       // "big" prime number
00158       const uint16_t bp = 257;
00159 
00160       return static_cast<uint16_t>(first%bp + (second<<3)%bp);
00161     }

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

Definition at line 146 of file hashword.h.

00147     {
00148       // big prime number
00149       const unsigned int bp = 65449;
00150 
00151       return (first%bp + (second<<5)%bp);
00152     }

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

Definition at line 130 of file hashword.h.

Referenced by libMesh::Elem::compute_key().

00131     {
00132       uint32_t a,b,c;
00133 
00134       // Set up the internal state
00135       a = b = c = 0xdeadbeef + 8 + initval;
00136 
00137       b+=second;
00138       a+=first;
00139       final(a,b,c);
00140 
00141       return c;
00142     }

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

Utility::iota is a duplication of the SGI STL extension std::iota. It simply assigns sequentially increasing values to a range. That is, it assigns value to *first, value + 1 to *(first + 1) and so on. In general, each iterator i in the range [first, last) is assigned value + (i - first).

Definition at line 58 of file utility.h.

Referenced by libMesh::PetscVector< T >::create_subvector(), and libMesh::PetscVector< T >::localize().

00059   {
00060     while (first != last)
00061       {
00062         *first = value++;
00063         ++first;
00064       }
00065   }

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

Utility::is_sorted mimics the behavior of the SGI STL extension std::is_sorted. Checks to see if the range [first,last) is sorted in non-decreasing order, ie. for each "i" in [first,last) *i <= *(i+1).

Definition at line 75 of file utility.h.

00076   {
00077     if ( first == last )
00078       return true;
00079 
00080     // "prev" always points to the entry just to the left of "first"
00081     //  [-    -    -    -    -    -]
00082     //   ^    ^
00083     // prev first
00084     //
00085     //  [-    -    -    -    -    -]
00086     //        ^    ^
00087     //      prev first
00088     //
00089     //  [-    -    -    -    -    -]
00090     //             ^    ^
00091     //           prev first
00092     InputIterator prev( first );
00093     for ( ++first; first != last; ++prev, ++first )
00094       if ( *first < *prev  )    // Note: this is the same as *prev > *first,
00095            return false;        // but we only require op< to be defined.
00096 
00097     // If we haven't returned yet, it's sorted!
00098     return true;
00099 
00100 
00101     // A one-liner version using adjacent_find.  This doesn't work for
00102     // C-style arrays, since their pointers do not have a value_type.
00103     //
00104     // Works by checking to see if adjacent entries satisfy *i >
00105     // *(i+1) and returns the first one which does.  If "last" is
00106     // returned, no such pair was found, and therefore the range must
00107     // be in non-decreasing order.
00108     //
00109     // return (last ==
00110     // std::adjacent_find(first, last,
00111     // std::greater< typename InputIterator::value_type >()));
00112 
00113     // A second one-linear attempt.  This one checks for a **strictly
00114     // increasing** (no duplicate entries) range.  Also doesn't work
00115     // with C-style arrays.
00116     //
00117     // return (last ==
00118     // std::adjacent_find(first, last,
00119     // std::not2(std::less<typename InputIterator::value_type>())));
00120   }

template<int N, typename T >
T libMesh::Utility::pow ( const T &  x  )  [inline]
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 99 of file utility.C.

Referenced by libMesh::LegacyXdrIO::read_mgf_soln(), and libMesh::LegacyXdrIO::write_mgf_soln().

00102 {
00103   const unsigned int len = source.size();
00104 
00105   real_part.resize(len);
00106   imag_part.resize(len);
00107 
00108   for (unsigned int i=0; i<len; i++)
00109     {
00110       real_part[i] = source[i].real();
00111       imag_part[i] = source[i].imag();
00112     }
00113 }

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

Definition at line 37 of file timestamp.h.

References get_timestamp().

00038   {
00039     target << get_timestamp() << std::endl;
00040   }

template<typename T >
T libMesh::Utility::string_to_enum ( const std::string &  s  )  [inline]

Takes the string s and returns the matching enumeration of type T.

template<>
Elem::RefinementState libMesh::Utility::string_to_enum< Elem::RefinementState > ( const std::string &  s  )  [inline]
template<>
ElemType libMesh::Utility::string_to_enum< ElemType > ( const std::string &  s  )  [inline]
template<>
FEFamily libMesh::Utility::string_to_enum< FEFamily > ( const std::string &  s  )  [inline]
template<>
InfMapType libMesh::Utility::string_to_enum< InfMapType > ( const std::string &  s  )  [inline]
template<>
Order libMesh::Utility::string_to_enum< Order > ( const std::string &  s  )  [inline]
template<>
PreconditionerType libMesh::Utility::string_to_enum< PreconditionerType > ( const std::string &  s  )  [inline]
template<>
QuadratureType libMesh::Utility::string_to_enum< QuadratureType > ( const std::string &  s  )  [inline]

Referenced by libMesh::QBase::build().

std::string libMesh::Utility::system_info (  ) 

The system_info function returns information about the system you are running on.

Definition at line 45 of file utility.C.

References get_timestamp().

00046 {
00047   std::ostringstream oss;
00048 
00049   std::string date = Utility::get_timestamp();
00050 
00051   // Get system information
00052   struct utsname sysInfo;
00053   uname(&sysInfo);
00054 
00055   // Get user information
00056 #ifdef LIBMESH_HAVE_GETPWUID
00057       struct passwd* p = getpwuid(getuid());
00058 #endif
00059 
00060 
00061   oss << '\n'
00062       << " ---------------------------------------------------------------------\n"
00063       << "| Time:           " << date             << '\n'
00064       << "| OS:             " << sysInfo.sysname  << '\n'
00065       << "| HostName:       " << sysInfo.nodename << '\n'
00066       << "| OS Release      " << sysInfo.release  << '\n'
00067       << "| OS Version:     " << sysInfo.version  << '\n'
00068       << "| Machine:        " << sysInfo.machine  << '\n'
00069 #ifdef LIBMESH_HAVE_GETPWUID
00070       << "| Username:       " << p->pw_name       << '\n'
00071 #else
00072       << "| Username:       " << "Unknown"        << '\n'
00073 #endif
00074       << " ---------------------------------------------------------------------\n";
00075 
00076   return oss.str();
00077 }


Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:49 UTC

Hosted By:
SourceForge.net Logo