$extrastylesheet
utility.C
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 // library configuration
00020 #include "libmesh/libmesh_config.h"
00021 
00022 // System includes
00023 #include <sys/time.h>
00024 #include <pwd.h>
00025 #include <unistd.h>
00026 #include <sys/utsname.h>
00027 #include <sstream>
00028 
00029 // Local includes
00030 #include "libmesh/utility.h"
00031 #include "libmesh/timestamp.h"
00032 
00033 namespace libMesh
00034 {
00035 
00036 
00037 //-----------------------------------------------------------------------
00038 // Utility members
00039 
00040 
00041 // The system_info function duplicates some of the
00042 // functionality found in the perf_log function.
00043 // This way you can get information about a user's
00044 // system without creating a perf_log object.
00045 std::string Utility::system_info()
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 }
00078 
00079 
00080 
00081 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
00082 
00083 std::string Utility::complex_filename (const std::string& basename,
00084                                        const unsigned int r_o_c)
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 }
00096 
00097 
00098 
00099 void Utility::prepare_complex_data(const std::vector<Complex>& source,
00100                                    std::vector<Real>& real_part,
00101                                    std::vector<Real>& imag_part)
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 }
00114 
00115 #endif // #ifdef LIBMESH_USE_COMPLEX_NUMBERS
00116 
00117 } // namespace libMesh