LandscapeDNDC 1.37.0
cmfcolumn-fluxes.h
1
9#ifndef INTEGRATABLES_H_
10#define INTEGRATABLES_H_
11
12#define CMFCOLUMN_DBKEY_MAXLEN 64
13
14#include "mbe_legacymodel.h"
15
16#include <memory>
17#ifdef CMFCOLUMN_HAVE_INTEGRATABLES
18# include <map>
19# include <vector>
20#endif
21
22struct CMFConfig;
23struct CMFObjects;
24namespace cmf
25{
26 namespace math
27 {
28 class Integrator;
29 class integratable;
30 class Time;
31 }
32 namespace upslope
33 {
34 class Cell;
35 }
36 namespace water
37 {
38 class flux_connection;
39 class flux_node;
40 }
41}
42
43
44struct cmfcolumn_dbkeygen_t
45{
46 static char const * solute_key(
47 char * /*keybuffer*/, char const * /*key basename*/,
48 char const * /*solute*/);
49};
50
51enum integratable_e
52{
53 ITG_rainthroughfall = 0,
54 ITG_canopythroughfall,
55 ITG_infiltration,
56 ITG_exfiltration,
57 ITG_canopyevaporation,
58 ITG_surfacewaterevaporation,
59 ITG_soilevaporation,
60// sk:unused ITG_snowmelt,
61 ITG_snowthroughfall,
62 ITG_snowevaporation,
63 ITG_groundwaterdischarge,
64 ITG_streamdischarge,
65 ITG_rainsource,
66 ITG_transpiration,
67 ITG_evaporation,
68 ITG_surfacewater,
69 ITG_runoff,
70 ITG_percolation,
71 ITG_lateralflow,
72 ITG_surfaceflow,
73
74 ITG_count
75};
76extern char const * const itg_names[ITG_count];
77
78#define noID CMFIntegratables::IPos::NOID
79struct CMFIntegratables
80{
81 struct IPos
82 {
83 static const int NOID = -1;
84 IPos( int _id = NOID, size_t _layer = 0)
85 : id( _id), layer( _layer) { }
86
87 int id;
88 size_t layer;
89
90 bool operator<( IPos const & _rhs)
91 { return this->id < _rhs.id; };
92 bool operator<( IPos const & _rhs) const
93 { return this->id < _rhs.id; };
94 };
95
96 double query( integratable_e _fx, IPos const & _i) const
97 { return this->m_query( _fx, _i); }
98 int initialize( CMFConfig const & _cfg,
99 CMFObjects & _cmf_objects)
100 { return this->m_initialize( _cfg, _cmf_objects); }
101
102 private:
103 struct CMFIntegratableInfo
104 {
105 CMFIntegratableInfo() : I( NULL), n_queries( 0) { }
106 cmf::math::integratable * I;
107 mutable int n_queries;
108 };
109#ifdef CMFCOLUMN_HAVE_INTEGRATABLES
110 double m_query( integratable_e, IPos const &) const;
111 int m_initialize( CMFConfig const &, CMFObjects &);
112
113 typedef std::vector< CMFIntegratableInfo > CMFVerticalIntegratables;
114 typedef std::map< IPos, CMFVerticalIntegratables > CMFHorizontalIntegratables;
115 CMFHorizontalIntegratables m_integratables[ITG_count];
116
117 typedef std::shared_ptr< cmf::water::flux_connection > CMFFluxConnection;
118 lerr_t add_cmf_integratable( cmf::math::Integrator * _solver,
119 integratable_e, IPos, CMFFluxConnection);
120 typedef std::shared_ptr< cmf::water::flux_node > CMFFluxNode;
121 lerr_t add_cmf_integratable( cmf::math::Integrator * _solver,
122 integratable_e, IPos, CMFFluxNode);
123 lerr_t add_cmf_integratable( cmf::math::Integrator * _solver,
124 integratable_e, IPos, CMFFluxNode, CMFFluxNode);
125 typedef std::shared_ptr< cmf::math::integratable > CMFIntegratable;
126 lerr_t add_cmf_integratable( cmf::math::Integrator * _solver,
127 integratable_e, IPos, CMFIntegratable);
128#else
129 double m_query( integratable_e, IPos const &) const
130 { return 0.0; };
131 int m_initialize( CMFConfig const &, CMFObjects &)
132 { return 0; }
133#endif /* CMFCOLUMN_HAVE_INTEGRATABLES */
134};
135
136class CMFFluxes
137{
138 CMFIntegratables m_itg;
139 public:
140 CMFFluxes( cbm::io_kcomm_t * _io_kcomm = NULL)
141 : io_kcomm( _io_kcomm)
142 { }
143 private:
144 cbm::io_kcomm_t * io_kcomm;
145
146 public:
147 typedef char keybuffer_t[CMFCOLUMN_DBKEY_MAXLEN];
148 /* db */
149 void db_set( double /*value*/,
150 char const * /*key*/, char const * = NULL /*solute*/);
151 void db_add( double /*value*/,
152 char const * /*key*/, char const * = NULL /*solute*/);
153 double db_get( char const * /*key*/, char const * = NULL /*solute*/);
154 double db_getdel( char const * /*key*/, char const * = NULL /*solute*/);
155
156 /* integratables */
157 double query( integratable_e _fx) const
158 {
159 CMFIntegratables::IPos const i;
160 return this->m_itg.query( _fx, i);
161 }
162 double query( integratable_e _fx, int _id /*cell id*/) const
163 {
164 CMFIntegratables::IPos const i( _id);
165 return this->m_itg.query( _fx, i);
166 }
167 double query( integratable_e _fx,
168 int _id /*cell id*/, size_t _layer /*layer*/) const
169 {
170 CMFIntegratables::IPos const i( _id, _layer);
171 return this->m_itg.query( _fx, i);
172 }
173
174 int initialize( CMFConfig const & _conf,
175 CMFObjects & _cmf_objects)
176 {
177 return this->m_itg.initialize(
178 _conf, _cmf_objects);
179 }
180
181 private:
182 std::map< uintptr_t, double > watervolumes;
183 public:
184 void set_watervolume( double, void * /*source*/);
185 double get_watervolume( void * /*source*/);
186 void get_watervolumes( double * /*buffer*/, size_t /*buffer size*/);
187 size_t watervolumes_count() const
188 { return this->watervolumes.size(); }
189};
190
191#endif /* !INTEGRATABLES_H_ */
192