/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
17void goto_next_line(std::istream& is);
18
19inline std::string amr_wind_version()
20{
22}
23
24inline std::string timestamp()
25{
26 auto etime = std::chrono::system_clock::now();
27 auto etimet = std::chrono::system_clock::to_time_t(etime);
28 amrex::Array<char, 64> buf;
29 ctime_r(&etimet, buf.begin());
30 std::string tstamp(buf.begin());
31 return tstamp;
32}
33
41inline void add_var_names(
42 amrex::Vector<std::string>& vnames,
43 const std::string& fname,
44 const int ncomp)
45{
46 const amrex::Vector<std::string> comp{"x", "y", "z"};
47
48 switch (ncomp) {
49 case 1:
50 vnames.push_back(fname);
51 break;
52
53 case AMREX_SPACEDIM:
54 for (int i = 0; i < AMREX_SPACEDIM; ++i) {
55 vnames.push_back(fname + comp[i]);
56 }
57 break;
58
59 default:
60 for (int i = 0; i < ncomp; ++i) {
61 vnames.push_back(fname + std::to_string(i));
62 }
63 }
64}
65
66template <typename T>
67inline bool all_distinct(const amrex::Vector<T>& vec)
68{
69 std::unordered_set<T> s(vec.begin(), vec.end());
70 return static_cast<amrex::Long>(s.size()) == vec.size();
71}
72
73inline void assert_with_message(const bool val, const std::string& msg)
74{
75 if (!val) {
76 amrex::Abort(msg);
77 }
78}
79
86 const std::string& fname,
87 amrex::Vector<amrex::Real>& xs,
88 amrex::Vector<amrex::Real>& ys,
89 amrex::Vector<amrex::Real>& zs);
90
91} // namespace amr_wind::ioutils
92
93#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:13
std::string amr_wind_version()
Definition io_utils.H:19
bool all_distinct(const amrex::Vector< T > &vec)
Definition io_utils.H:67
void add_var_names(amrex::Vector< std::string > &vnames, const std::string &fname, const int ncomp)
Definition io_utils.H:41
std::string timestamp()
Definition io_utils.H:24
void goto_next_line(std::istream &is)
Definition io_utils.cpp:7
void assert_with_message(const bool val, const std::string &msg)
Definition io_utils.H:73
Definition console_io.cpp:25
const char * buildInfoGetGitHash(int i)