-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCouplingManager.hpp
124 lines (99 loc) · 3.88 KB
/
CouplingManager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* CouplingManager.hpp
*
* Created on: Jun 15, 2021
* Author: sunelma
*/
#ifndef _COUPLINGMANAGER_HPP_
#define _COUPLINGMANAGER_HPP_
#include"ca2D.hpp"
#include"BaseTypes.hpp"
#include"Box.hpp"
#include<string>
#include<vector>
//! Structure with the configuration value that define an inflow of
//! water event in the CA2D model. The time is in seconds and the
//! inflow is in cubic meters per second. The specific inflow at a
//! specific time is given by linear interpolation between the
//! previous and next values.
struct ICoupling
{
public:
std::string name; //!< Coupling component.
CA::Real x; //!< X coordinate of the coupling point
CA::Real y; //!< Y coordinate of the coupling point
CA::Unsigned w; //!< Width of the coupling point
CA::Unsigned h; //!< Height of the coupling point
CA::Real elv; //!< Elevation of the coupling point
CA::Real head; //!< CAFLOOD simulated head
CA::Real depth; //!< CAFLOOD simulated depth
CA::Real flow; //!< Net flow calculated by the hydraulic simulator (+ to surface, - to network)
CA::Real prevFlow; //!< Net flow calculated by the hydraulic simulator (+ to surface, - to network)
CA::Real actualFlow;//!< The realized flow calculated by the 2D simulator (+ to surface, - to network)
CA::Box box_area; //!< The box of the area where the flow is set.
CA::Unsigned offset; //!< Offset to this coupling point's data in the common buffer
ICoupling():
box_area(CA::Box::Empty()) {
}
~ICoupling() {
}
};
//! Initialise the inflow event structure usign a CSV file.
//! Each row represents a new "variable" where the
//! first column is the name of the element
//! and the following columns have the multiple/single values.
//! \attention The order of elements is not important.
//! \param[in] filename This is the file where the data is read.
//! \param[out] setup The structure containing the read data.
//! \return A non zero value if there was an error.
int initICouplingsFromCSV(const std::string& filename, std::vector<ICoupling>& couplings);
class CouplingManager {
private:
//! Reference to the grid.
CA::Grid& grid;
//! Reference to the list of coupling locations events
std::vector<ICoupling>& coupling;
//! PointList for the coupling locations for reading the water depths efficiently.
CA::PointList points;
//! Reference to the water depth memory for the coupled points
CA::Real *waterDepthBuffer;
CA::Unsigned bufferSize;
int port;
int sockfd;
CA::Real time_start;
CA::Real time_end;
CA::Real readValuesUntil;
CA::Real previousValuesUntil;
CA::Real networkWaitingUntil;
double coupledVolume = 0.0;
bool inputEnded = false;
bool stopped = false;
public:
CouplingManager(CA::Grid& GRID, CA::CellBuffReal& ELV, std::vector<ICoupling>& aCoupling, CA::Real time_start, CA::Real time_end, int port);
~CouplingManager();
void addDomain(CA::BoxList& compdomain);
inline bool isStopped() { return stopped; }
void input(CA::Real t);
void output(CA::Real time, CA::CellBuffReal& WD, CA::CellBuffReal& ELV);
void add(CA::CellBuffReal& WD, CA::CellBuffState& MASK, CA::Real area, CA::Real t, CA::Real dt);
void end();
void close();
CA::Real potentialVA(CA::Real t, CA::Real period_time_dt);
CA::Real volume() {
return getAndResetCoupledVolume();
}
CA::Real endTime();
CA::Real getAndResetCoupledVolume() {
CA::Real ret = (CA::Real)coupledVolume;
coupledVolume = 0.0;
return ret;
}
private:
double calculateAverage(ICoupling& point);
double updateFlow(ICoupling& point, double depth, double avg, double &newAvg);
CA::Unsigned createBoxes();
void readElevations(CA::CellBuffReal& ELV);
void write(const std::string& line) const;
std::string read() const;
};
#endif