utility.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 // library configuration
20 #include "libmesh/libmesh_config.h"
21 
22 // System includes
23 #include <sys/time.h>
24 #include <pwd.h>
25 #include <unistd.h>
26 #include <sys/utsname.h>
27 #include <sstream>
28 
29 // Local includes
30 #include "libmesh/utility.h"
31 #include "libmesh/timestamp.h"
32 
33 namespace libMesh
34 {
35 
36 
37 //-----------------------------------------------------------------------
38 // Utility members
39 
40 
41 // The system_info function duplicates some of the
42 // functionality found in the perf_log function.
43 // This way you can get information about a user's
44 // system without creating a perf_log object.
45 std::string Utility::system_info()
46 {
47  std::ostringstream oss;
48 
49  std::string date = Utility::get_timestamp();
50 
51  // Get system information
52  struct utsname sysInfo;
53  uname(&sysInfo);
54 
55  // Get user information
56 #ifdef LIBMESH_HAVE_GETPWUID
57  struct passwd* p = getpwuid(getuid());
58 #endif
59 
60 
61  oss << '\n'
62  << " ---------------------------------------------------------------------\n"
63  << "| Time: " << date << '\n'
64  << "| OS: " << sysInfo.sysname << '\n'
65  << "| HostName: " << sysInfo.nodename << '\n'
66  << "| OS Release " << sysInfo.release << '\n'
67  << "| OS Version: " << sysInfo.version << '\n'
68  << "| Machine: " << sysInfo.machine << '\n'
69 #ifdef LIBMESH_HAVE_GETPWUID
70  << "| Username: " << p->pw_name << '\n'
71 #else
72  << "| Username: " << "Unknown" << '\n'
73 #endif
74  << " ---------------------------------------------------------------------\n";
75 
76  return oss.str();
77 }
78 
79 
80 
81 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
82 
83 std::string Utility::complex_filename (const std::string& basename,
84  const unsigned int r_o_c)
85 {
86  std::string name(basename);
87 
88  if (r_o_c == 0)
89  name.append(".real");
90 
91  else
92  name.append(".imag");
93 
94  return name;
95 }
96 
97 
98 
99 void Utility::prepare_complex_data(const std::vector<Complex>& source,
100  std::vector<Real>& real_part,
101  std::vector<Real>& imag_part)
102 {
103  const unsigned int len = source.size();
104 
105  real_part.resize(len);
106  imag_part.resize(len);
107 
108  for (unsigned int i=0; i<len; i++)
109  {
110  real_part[i] = source[i].real();
111  imag_part[i] = source[i].imag();
112  }
113 }
114 
115 #endif // #ifdef LIBMESH_USE_COMPLEX_NUMBERS
116 
117 } // namespace libMesh

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo