/home/runner/work/amr-wind/amr-wind/amr-wind/utilities/io_utils.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/utilities/io_utils.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
io_utils.H
Go to the documentation of this file.
1#ifndef IO_UTILS_H
2#define IO_UTILS_H
3
4#include <chrono>
5#include <ctime>
6#include <string>
7#include <sstream>
8#include <unordered_set>
9#include "AMReX_Vector.H"
10
11namespace amrex {
12const char* buildInfoGetGitHash(int i);
13}
14
15namespace amr_wind::ioutils {
16
17inline std::string amr_wind_version()
18{
20}
21
22inline std::string timestamp()
23{
24 auto etime = std::chrono::system_clock::now();
25 auto etimet = std::chrono::system_clock::to_time_t(etime);
26 amrex::Array<char, 64> buf;
27 ctime_r(&etimet, buf.begin());
28 std::string tstamp(buf.begin());
29 return tstamp;
30}
31
39inline void add_var_names(
40 amrex::Vector<std::string>& vnames,
41 const std::string& fname,
42 const int ncomp)
43{
44 const amrex::Vector<std::string> comp{"x", "y", "z"};
45
46 switch (ncomp) {
47 case 1:
48 vnames.push_back(fname);
49 break;
50
51 case AMREX_SPACEDIM:
52 for (int i = 0; i < AMREX_SPACEDIM; ++i) {
53 vnames.push_back(fname + comp[i]);
54 }
55 break;
56
57 default:
58 for (int i = 0; i < ncomp; ++i) {
59 vnames.push_back(fname + std::to_string(i));
60 }
61 }
62}
63
64template <typename T>
65inline bool all_distinct(const amrex::Vector<T>& vec)
66{
67 std::unordered_set<T> s(vec.begin(), vec.end());
68 return static_cast<amrex::Long>(s.size()) == vec.size();
69}
70
71inline void assert_with_message(const bool val, const std::string& msg)
72{
73 if (!val) {
74 amrex::Abort(msg);
75 }
76}
77
84 const std::string& fname,
85 amrex::Vector<amrex::Real>& xs,
86 amrex::Vector<amrex::Real>& ys,
87 amrex::Vector<amrex::Real>& zs);
88
89} // namespace amr_wind::ioutils
90
91#endif /* IO_UTILS_H */
Definition io_utils.cpp:5
void read_flat_grid_file(const std::string &fname, amrex::Vector< amrex::Real > &xs, amrex::Vector< amrex::Real > &ys, amrex::Vector< amrex::Real > &zs)
Definition io_utils.cpp:7
std::string amr_wind_version()
Definition io_utils.H:17
bool all_distinct(const amrex::Vector< T > &vec)
Definition io_utils.H:65
void add_var_names(amrex::Vector< std::string > &vnames, const std::string &fname, const int ncomp)
Definition io_utils.H:39
std::string timestamp()
Definition io_utils.H:22
void assert_with_message(const bool val, const std::string &msg)
Definition io_utils.H:71
Definition console_io.cpp:25
const char * buildInfoGetGitHash(int i)