Poster of Linux kernelThe best gift for a Linux geek
Utility

Utility

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

Utility -  

SYNOPSIS


 

Classes


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<typename T > T string_to_enum (const std::string &s)

template<typename T > std::string enum_to_string (const T e)

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> Real pow (const Real x)

template<> Real pow< 8 > (const Real x)

template<> Real pow< 6 > (const Real x)

template<> Real pow< 4 > (const Real x)

template<> Real pow< 3 > (const Real x)

template<> Real pow< 2 > (const Real x)

template<> Real pow< 1 > (const Real x)

template<> Real pow< 0 > (const Real)

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 Utility::binary_find (ForwardIteratorfirst, ForwardIteratorlast, const T &value)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.

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

std::string Utility::complex_filename (const std::string &basename, unsigned intr_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 95 of file utility.C.

References Quality::name().

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

{
  std::string name(basename);
  
  if (r_o_c == 0)
    name.append('.real');
  
  else
    name.append('.imag');
  
  return name;
}
 

template<typename T > void Utility::deallocate (std::vector< T > &vec)A convenient method to truly empty a vector using the 'swap trick'

Definition at line 232 of file utility.h.

Referenced by Nemesis_IO::read().

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

template<typename T > std::string Utility::enum_to_string (const Te)Takes the enumeration e of type T and returns the matching string.

Referenced by DofMap::reinit().  

template<> std::string Utility::enum_to_string< ElemType > (const ElemTypee)

Definition at line 428 of file string_to_enum.C.

Referenced by MeshTools::Modification::all_tri().

  {
    init_enum_to_elem_type();

    if (!enum_to_elem_type.count(e))
      libmesh_error();

    return enum_to_elem_type[e];
  }
 

template<> std::string Utility::enum_to_string< FEFamily > (const FEFamilyf)

Definition at line 490 of file string_to_enum.C.

Referenced by System::get_info().

  {
    init_enum_to_fefamily();

    if (!enum_to_fefamily.count(f))
      libmesh_error();

    return enum_to_fefamily[f];
  }
 

template<> std::string Utility::enum_to_string< InfMapType > (const InfMapTypei)

Definition at line 521 of file string_to_enum.C.

Referenced by System::get_info().

  {
    init_enum_to_inf_map_type();

    if (!enum_to_inf_map_type.count(i))
      libmesh_error();

    return enum_to_inf_map_type[i];
  }
 

template<> std::string Utility::enum_to_string< Order > (const Ordero)

Definition at line 459 of file string_to_enum.C.

Referenced by System::get_info().

  {
    init_enum_to_order();

    if (!enum_to_order.count(o))
      libmesh_error();

    return enum_to_order[o];
  }
 

template<> std::string Utility::enum_to_string< PreconditionerType > (const PreconditionerTypei)

Definition at line 582 of file string_to_enum.C.

  {
    init_enum_to_preconditioner_type();

    if (!enum_to_preconditioner_type.count(i))
      libmesh_error();

    return enum_to_preconditioner_type[i];
  }
 

template<> std::string Utility::enum_to_string< QuadratureType > (const QuadratureTypei)

Definition at line 552 of file string_to_enum.C.

  {
    init_enum_to_quadrature_type();

    if (!enum_to_quadrature_type.count(i))
      libmesh_error();

    return enum_to_quadrature_type[i];
  }
 

unsigned int Utility::factorial (unsigned intn) [inline]A simple implementation of the factorial.

Definition at line 212 of file utility.h.

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

    {

      unsigned int factorial_n = 1;

      if (n==0)
        return factorial_n;
      
      for (unsigned int i=1; i<n; i++)
        factorial_n *= i+1;

      return factorial_n;
    }
 

template<typename ForwardIter , typename T > void Utility::iota (ForwardIterfirst, ForwardIterlast, Tvalue)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 PetscVector< T >::create_subvector(), PetscVector< T >::localize(), TransientSystem< Base >::re_update(), and System::re_update().

  {
    while (first != last)
      {
        *first = value++;
        ++first;
      }
  }
 

template<class InputIterator > bool Utility::is_sorted (InputIteratorfirst, InputIteratorlast)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.

  {
    if ( first == last )
      return true;

    // 'prev' always points to the entry just to the left of 'first'
    //  [-    -    -    -    -    -]
    //   ^    ^
    // prev first
    //
    //  [-    -    -    -    -    -]
    //        ^    ^
    //      prev first
    //
    //  [-    -    -    -    -    -]
    //             ^    ^
    //           prev first
    InputIterator prev( first );
    for ( ++first; first != last; ++prev, ++first ) 
      if ( *first < *prev  )    // Note: this is the same as *prev > *first,
           return false;        // but we only require op< to be defined.

    // If we haven't returned yet, it's sorted!
    return true;
    
    
    // A one-liner version using adjacent_find.  This doesn't work for
    // C-style arrays, since their pointers do not have a value_type.
    //
    // Works by checking to see if adjacent entries satisfy *i >
    // *(i+1) and returns the first one which does.  If 'last' is
    // returned, no such pair was found, and therefore the range must
    // be in non-decreasing order.
    //
    // return (last ==
    // std::adjacent_find(first, last,
    // std::greater< typename InputIterator::value_type >()));
    
    // A second one-linear attempt.  This one checks for a **strictly
    // increasing** (no duplicate entries) range.  Also doesn't work
    // with C-style arrays.
    //
    // return (last ==
    // std::adjacent_find(first, last,
    // std::not2(std::less<typename InputIterator::value_type>())));
  }
 

template<int N> Real Utility::pow (const Realx) [inline]An efficient template instantiation for raising to an arbitrary integer power.

Definition at line 144 of file utility.h.

Referenced by GetPot::__DBE_expand(), ContinuationSystem::continuation_solve(), FEHermite< Dim >::hermite_raw_shape_second_deriv(), VariationalMeshSmoother::maxE(), VariationalMeshSmoother::metr_data_gen(), VariationalMeshSmoother::minJ(), VariationalMeshSmoother::minJ_BC(), FE< Dim, T >::shape(), FE< Dim, T >::shape_deriv(), FE< Dim, T >::shape_second_deriv(), MeshTools::Modification::smooth(), TwostepTimeSolver::solve(), PatchRecoveryErrorEstimator::specpoly(), and VariationalMeshSmoother::vertex().

  { 
    libmesh_assert(N>1); 
    
    if (N%2) // odd exponent
      return x * pow<N-1>(x); 
    
    const Real xNover2 = pow<N/2>(x);

    return xNover2*xNover2;
  }
 

template<> Real Utility::pow< 0 > (const Real) [inline]

Definition at line 204 of file utility.h.

{ return 1.; }
 

template<> Real Utility::pow< 1 > (const Realx) [inline]

Definition at line 200 of file utility.h.

{ return x; }
 

template<> Real Utility::pow< 2 > (const Realx) [inline]

Definition at line 196 of file utility.h.

Referenced by FE< Dim, T >::shape(), FE< Dim, T >::shape_deriv(), FE< Dim, T >::shape_second_deriv(), and VariationalMeshSmoother::writegr().

{ return x*x; }
 

template<> Real Utility::pow< 3 > (const Realx) [inline]

Definition at line 192 of file utility.h.

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

{ return x*x*x; }
 

template<> Real Utility::pow< 4 > (const Realx) [inline]

Definition at line 182 of file utility.h.

Referenced by FEHermite< Dim >::hermite_raw_shape_second_deriv(), FE< Dim, T >::shape(), FE< Dim, T >::shape_deriv(), and FE< Dim, T >::shape_second_deriv().

  {
    const Real 
      x2 = x*x,
      x4 = x2*x2;
    return x4; 
  }
 

template<> Real Utility::pow< 6 > (const Realx) [inline]

Definition at line 170 of file utility.h.

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

  {
    const Real 
      x2 = x*x,
      x4 = x2*x2,
      x6 = x4*x2;

    return x6; 
  }
 

template<> Real Utility::pow< 8 > (const Realx) [inline]

Definition at line 158 of file utility.h.

  {
    const Real 
      x2 = x*x,
      x4 = x2*x2,
      x8 = x4*x4;

    return x8; 
  }
 

void 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 111 of file utility.C.

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

{
  const unsigned int len = source.size();
  
  real_part.resize(len);
  imag_part.resize(len);

  for (unsigned int i=0; i<len; i++)
    {
      real_part[i] = source[i].real();
      imag_part[i] = source[i].imag();
    }
}
 

template<typename T > T Utility::string_to_enum (const std::string &s)Takes the string s and returns the matching enumeration of type T.

 

template<> ElemType Utility::string_to_enum< ElemType > (const std::string &s)

Definition at line 412 of file string_to_enum.C.

  {
    init_elem_type_to_enum();

    std::string upper(s);
    std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
    
    if (!elem_type_to_enum.count(upper))
      libmesh_error();
    
    return elem_type_to_enum[upper];
  }
 

template<> FEFamily Utility::string_to_enum< FEFamily > (const std::string &s)

Definition at line 474 of file string_to_enum.C.

  {
    init_fefamily_to_enum();
    
    std::string upper(s);
    std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
    
    if (!fefamily_to_enum.count(upper))
      libmesh_error();
    
    return fefamily_to_enum[upper];
  }
 

template<> InfMapType Utility::string_to_enum< InfMapType > (const std::string &s)

Definition at line 505 of file string_to_enum.C.

  {
    init_inf_map_type_to_enum();
    
    std::string upper(s);
    std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
    
    if (!inf_map_type_to_enum.count(upper))
      libmesh_error();
    
    return inf_map_type_to_enum[upper];
  }
 

template<> Order Utility::string_to_enum< Order > (const std::string &s)

Definition at line 443 of file string_to_enum.C.

  {
    init_order_to_enum();
    
    std::string upper(s);
    std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
    
    if (!order_to_enum.count(upper))
      libmesh_error();
    
    return order_to_enum[upper];
  }
 

template<> PreconditionerType Utility::string_to_enum< PreconditionerType > (const std::string &s)

Definition at line 566 of file string_to_enum.C.

  {
    init_preconditioner_type_to_enum();
    
    std::string upper(s);
    std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
    
    if (!preconditioner_type_to_enum.count(upper))
      libmesh_error();
    
    return preconditioner_type_to_enum[upper];
  }
 

template<> QuadratureType Utility::string_to_enum< QuadratureType > (const std::string &s)

Definition at line 536 of file string_to_enum.C.

Referenced by QBase::build().

  {
    init_quadrature_type_to_enum();
    
    std::string upper(s);
    std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
    
    if (!quadrature_type_to_enum.count(upper))
      libmesh_error();
    
    return quadrature_type_to_enum[upper];
  }
 

std::string Utility::system_info ()The system_info function returns information about the system you are running on.

Definition at line 48 of file utility.C.

{
  OStringStream out;
  
#ifdef LIBMESH_HAVE_LOCALE
    
  typedef std::ostreambuf_iterator<char, std::char_traits<char> > TimeIter;
  typedef std::time_put<char, TimeIter>                           TimePut;
 
  std::locale loc;
  OStringStream dateStr;
  std::ostreambuf_iterator<char, std::char_traits<char> > begin(dateStr);
  time_t tm         = time(NULL);
  struct tm* tmb    = localtime(&tm);
  const TimePut& tp = std::use_facet<TimePut>(loc);
  tp.put(begin,
         dateStr,
         dateStr.fill(),
         tmb,
         'c');
  
  // Get system information
  struct utsname sysInfo;
  uname(&sysInfo);
  
  // Get user information
  struct passwd* p = getpwuid(getuid());
  out << '
      << ' ---------------------------------------------------------------------
      << '| Time:           ' << dateStr.str()    << '
      << '| OS:             ' << sysInfo.sysname  << '
      << '| HostName:       ' << sysInfo.nodename << '
      << '| OS Release      ' << sysInfo.release  << '
      << '| OS Version:     ' << sysInfo.version  << '
      << '| Machine:        ' << sysInfo.machine  << '
      << '| Username:       ' << p->pw_name       << ' 
      << ' ---------------------------------------------------------------------;

#endif
  
  return out.str();
}
 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Classes
Functions
Function Documentation
template<class ForwardIterator , class T > ForwardIterator Utility::binary_find (ForwardIteratorfirst, ForwardIteratorlast, const T &value)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.
std::string Utility::complex_filename (const std::string &basename, unsigned intr_o_c = 0)Returns:
template<typename T > void Utility::deallocate (std::vector< T > &vec)A convenient method to truly empty a vector using the 'swap trick'
template<typename T > std::string Utility::enum_to_string (const Te)Takes the enumeration e of type T and returns the matching string.
template<> std::string Utility::enum_to_string< ElemType > (const ElemTypee)
template<> std::string Utility::enum_to_string< FEFamily > (const FEFamilyf)
template<> std::string Utility::enum_to_string< InfMapType > (const InfMapTypei)
template<> std::string Utility::enum_to_string< Order > (const Ordero)
template<> std::string Utility::enum_to_string< PreconditionerType > (const PreconditionerTypei)
template<> std::string Utility::enum_to_string< QuadratureType > (const QuadratureTypei)
unsigned int Utility::factorial (unsigned intn) [inline]A simple implementation of the factorial.
template<typename ForwardIter , typename T > void Utility::iota (ForwardIterfirst, ForwardIterlast, Tvalue)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).
template<class InputIterator > bool Utility::is_sorted (InputIteratorfirst, InputIteratorlast)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).
template<int N> Real Utility::pow (const Realx) [inline]An efficient template instantiation for raising to an arbitrary integer power.
template<> Real Utility::pow< 0 > (const Real) [inline]
template<> Real Utility::pow< 1 > (const Realx) [inline]
template<> Real Utility::pow< 2 > (const Realx) [inline]
template<> Real Utility::pow< 3 > (const Realx) [inline]
template<> Real Utility::pow< 4 > (const Realx) [inline]
template<> Real Utility::pow< 6 > (const Realx) [inline]
template<> Real Utility::pow< 8 > (const Realx) [inline]
void Utility::prepare_complex_data (const std::vector< Complex > &source, std::vector< Real > &real_part, std::vector< Real > &imag_part)Prepare complex data for writing.
template<typename T > T Utility::string_to_enum (const std::string &s)Takes the string s and returns the matching enumeration of type T.
template<> ElemType Utility::string_to_enum< ElemType > (const std::string &s)
template<> FEFamily Utility::string_to_enum< FEFamily > (const std::string &s)
template<> InfMapType Utility::string_to_enum< InfMapType > (const std::string &s)
template<> Order Utility::string_to_enum< Order > (const std::string &s)
template<> PreconditionerType Utility::string_to_enum< PreconditionerType > (const std::string &s)
template<> QuadratureType Utility::string_to_enum< QuadratureType > (const std::string &s)
std::string Utility::system_info ()The system_info function returns information about the system you are running on.
Author

This document was created by man2html, using the manual pages.
Time: 21:58:00 GMT, April 16, 2011