ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_WakeLines.H
Go to the documentation of this file.
1 #ifndef ERF_WAKE_LINES_H
2 #define ERF_WAKE_LINES_H
3 
4 /** Wake sampling lines behind one rotor and their running time average. */
5 
6 #include <array>
7 #include <string>
8 #include <vector>
9 
10 #include <AMReX_REAL.H>
11 
12 namespace erf_actuator {
13 
14 /**
15  * Wake sampling lines behind one rotor: at each downstream distance x/D along the horizontal
16  * projection of the rotor axis through the hub (a wake follows the wind at hub height, not a
17  * tilted shaft), one lateral line (horizontal, normal to that direction) and one vertical
18  * line, each of num_points points spanning +-half_width diameters about the center. The
19  * sampled velocities are written as they are and accumulated into a running time average.
20  *
21  * Point order: for each x/D, the lateral line then the vertical line, each from -half_width
22  * to +half_width; the vertical line is clipped at z_min (the ground), so its lowest point may
23  * sit above -half_width. Every point's offset s (in diameters) is recorded in the files. The
24  * lateral line runs along (-axis_y, axis_x, 0), from the right of the downstream direction to
25  * its left; the vertical line runs up. Positions in m, ERF domain coordinates; velocities in m/s.
26  */
27 class WakeLines
28 {
29 public:
30  /**
31  * Build the sampling points.
32  *
33  * @param hub the rotor's hub (m)
34  * @param axis the rotor axis (any non-vertical vector; its horizontal projection is used)
35  * @param diameter the rotor diameter (m, > 0)
36  * @param lines_xD downstream distances of the lines, in diameters (at least one)
37  * @param half_width half the length of each line, in diameters (> 0)
38  * @param num_points points per line (>= 2)
39  * @param z_min the ground under the hub (m, finite): the vertical line starts no lower
40  */
41  WakeLines (std::string name, std::string output_root,
42  const std::array<amrex::Real,3>& hub, const std::array<amrex::Real,3>& axis,
43  amrex::Real diameter, const std::vector<amrex::Real>& lines_xD,
44  amrex::Real half_width, int num_points, amrex::Real z_min);
45 
46  /**
47  * The same with one ground height per downstream distance (z_min[n] under the center of
48  * the lines at lines_xD[n], from terrain_heights), so that on terrain rising or falling
49  * downstream each vertical line stops at its own ground. z_min must have lines_xD's size.
50  */
51  WakeLines (std::string name, std::string output_root,
52  const std::array<amrex::Real,3>& hub, const std::array<amrex::Real,3>& axis,
53  amrex::Real diameter, const std::vector<amrex::Real>& lines_xD,
54  amrex::Real half_width, int num_points, const std::vector<amrex::Real>& z_min);
55 
56  const std::string& name () const { return m_name; }
57  int num_points () const { return static_cast<int>(m_pos.size() / 3); }
58  /** 3*n positions of the sampling points (m). */
59  const std::vector<amrex::Real>& positions () const { return m_pos; }
60  const std::array<amrex::Real,3>& hub () const { return m_hub; }
61  /** The unit downstream direction: the rotor axis projected on the horizontal plane. */
62  const std::array<amrex::Real,3>& axis () const { return m_axis; }
63  amrex::Real diameter () const { return m_diameter; }
64  int num_samples () const { return m_count; }
65 
66  /** Add one set of sampled velocities (3*n, m/s, finite) to the running average. */
67  void accumulate (const std::vector<amrex::Real>& vel);
68  /** The running mean velocities (3*n); zeros before the first sample. */
69  std::vector<amrex::Real> average () const;
70 
71  /**
72  * Write the sampled velocities to <output_root>_wake.csv, one row per point: truncate starts
73  * the file afresh, otherwise the rows are appended; the header is written when open_log()
74  * asks for one. Units: time s, x y z m, u v w m/s.
75  */
76  void write_instantaneous (double time, const std::vector<amrex::Real>& vel, bool truncate) const;
77  /** Rewrite <output_root>_wake_avg.csv with the running average (the file always holds the current mean). */
78  void write_average () const;
79 
80  /**
81  * The lines' state for a checkpoint, <dir>/<name>_wake_avg.dat: the sampling geometry
82  * (hub, axis, diameter, the points) and the running sums. The geometry is stored because a
83  * body model may rebuild the hub and diameter from lower-precision data after a restart and
84  * land a few ulps away; the stored points keep the average on the same positions.
85  */
86  void write_state (const std::string& dir) const;
87  /**
88  * Restore the state written by write_state(), geometry included; false when there is none.
89  * Aborts, changing nothing, when the file is malformed: a negative count, a diameter that is
90  * not positive, an axis that is not a horizontal unit vector, or a non-finite value.
91  */
92  bool read_state (const std::string& dir);
93 
94 private:
95  void write_rows (std::ofstream& out, const std::vector<amrex::Real>& vel, const std::string& prefix) const;
96 
97  std::string m_name, m_output_root;
98  std::array<amrex::Real,3> m_hub, m_axis, m_lateral;
99  amrex::Real m_diameter{0.0};
100  std::vector<amrex::Real> m_xD;
101  amrex::Real m_half_width{1.5};
102  int m_npts{0};
103  std::vector<amrex::Real> m_s; //!< n offsets along the lines, in diameters
104  std::vector<amrex::Real> m_pos; //!< 3*n
105  std::vector<double> m_sum; //!< 3*n running sums, in double whatever Real is
106  int m_count{0};
107 };
108 
109 } // namespace erf_actuator
110 
111 #endif
Definition: ERF_WakeLines.H:28
std::vector< amrex::Real > m_xD
Definition: ERF_WakeLines.H:100
void write_instantaneous(double time, const std::vector< amrex::Real > &vel, bool truncate) const
Definition: ERF_WakeLines.cpp:120
std::string m_name
Definition: ERF_WakeLines.H:97
WakeLines(std::string name, std::string output_root, const std::array< amrex::Real, 3 > &hub, const std::array< amrex::Real, 3 > &axis, amrex::Real diameter, const std::vector< amrex::Real > &lines_xD, amrex::Real half_width, int num_points, const std::vector< amrex::Real > &z_min)
int m_npts
Definition: ERF_WakeLines.H:102
std::vector< amrex::Real > m_s
n offsets along the lines, in diameters
Definition: ERF_WakeLines.H:103
WakeLines(std::string name, std::string output_root, const std::array< amrex::Real, 3 > &hub, const std::array< amrex::Real, 3 > &axis, amrex::Real diameter, const std::vector< amrex::Real > &lines_xD, amrex::Real half_width, int num_points, amrex::Real z_min)
const std::string & name() const
Definition: ERF_WakeLines.H:56
bool read_state(const std::string &dir)
Definition: ERF_WakeLines.cpp:160
const std::array< amrex::Real, 3 > & hub() const
Definition: ERF_WakeLines.H:60
amrex::Real m_half_width
Definition: ERF_WakeLines.H:101
std::vector< amrex::Real > average() const
Definition: ERF_WakeLines.cpp:94
const std::array< amrex::Real, 3 > & axis() const
Definition: ERF_WakeLines.H:62
amrex::Real diameter() const
Definition: ERF_WakeLines.H:63
const std::vector< amrex::Real > & positions() const
Definition: ERF_WakeLines.H:59
void write_average() const
Definition: ERF_WakeLines.cpp:135
int num_points() const
Definition: ERF_WakeLines.H:57
std::array< amrex::Real, 3 > m_axis
Definition: ERF_WakeLines.H:98
std::array< amrex::Real, 3 > m_lateral
Definition: ERF_WakeLines.H:98
std::string m_output_root
Definition: ERF_WakeLines.H:97
void accumulate(const std::vector< amrex::Real > &vel)
Definition: ERF_WakeLines.cpp:81
void write_state(const std::string &dir) const
Definition: ERF_WakeLines.cpp:145
int num_samples() const
Definition: ERF_WakeLines.H:64
std::vector< double > m_sum
3*n running sums, in double whatever Real is
Definition: ERF_WakeLines.H:105
std::vector< amrex::Real > m_pos
3*n
Definition: ERF_WakeLines.H:104
std::array< amrex::Real, 3 > m_hub
Definition: ERF_WakeLines.H:98
amrex::Real m_diameter
Definition: ERF_WakeLines.H:99
void write_rows(std::ofstream &out, const std::vector< amrex::Real > &vel, const std::string &prefix) const
Definition: ERF_WakeLines.cpp:105
int m_count
Definition: ERF_WakeLines.H:106
Definition: ERF_ActuatorDeviceBuffers.H:14