LandscapeDNDC 1.37.0
Loading...
Searching...
No Matches
speciestypes.h
1
10
11#ifndef LDNDC_INPUT_SPECIESTYPES_H_
12#define LDNDC_INPUT_SPECIESTYPES_H_
13
14#include "crabmeat-common.h"
15#include "memory/cbm_mem.h"
16#include "time/cbm_date.h"
17#include "string/cbm_string.h"
18#include "species/speciesgroups.h"
19#include "speciesparameters/speciesparameterstypes.h"
20
21
22#include "containers/lstack.h"
23
24namespace ldndc{ namespace species
25{
27#define IS_SPECIE(__name1__,__name2__) cbm::is_equal_i( __name1__, __name2__)
29#define MATCH_SPECIE(__type1__,__type2__) cbm::is_equal_i( __type1__, __type2__)
30
31typedef ldndc::stack< unsigned int > replace_index_t;
32
33struct species_properties_t;
34struct CBM_API specie_properties_factory_base_t
35{
36 specie_properties_factory_base_t() {}
37 virtual ~specie_properties_factory_base_t() = 0;
38
39 virtual species_properties_t * new_instance() const = 0;
40 virtual void delete_instance( species_properties_t *) const = 0;
41 virtual species_properties_t * clone( species_properties_t *, species_properties_t const *) const = 0;
42};
43template < typename _G >
44struct CBM_API specie_properties_factory_t : public specie_properties_factory_base_t
45{
46 specie_properties_factory_t()
47 : specie_properties_factory_base_t()
48 {
49 }
50 species_properties_t * new_instance()
51 const
52 {
53 return CBM_DefaultAllocator->construct< _G >();
54 }
55 void delete_instance( species_properties_t * _props)
56 const
57 {
58 if ( _props)
59 {
60 CBM_DefaultAllocator->destroy( static_cast< _G * >( _props));
61 }
62 }
63
64 species_properties_t * clone(
65 species_properties_t * _props_dst, species_properties_t const * _props_src)
66 const
67 {
68 crabmeat_assert( _props_src);
69
70 _G * this_props_dst = static_cast< _G * >( _props_dst);
71 if ( !this_props_dst)
72 {
73 this_props_dst = static_cast< _G * >( this->new_instance());
74 if ( !this_props_dst)
75 {
76 return NULL;
77 }
78 }
79 *this_props_dst = *static_cast< _G const * >( _props_src);
80
81 return this_props_dst;
82 }
83};
84
85struct CBM_API species_properties_t
86{
88 species_group_e group;
89
91 bool cover_crop;
92
94 double dbh;
95
97 double fractional_cover;
98
100 double height_max;
101
103 double height_min;
104
106 double initial_biomass;
107
109 double number;
110
112 double reduc_fac_c;
113
115 double root_depth;
116
118 int seedbed_duration;
119
121 double seedling_number;
122
124 double volume;
125
126 void initialize( species_group_e _group)
127 {
128 group = _group;
129 dbh = invalid_dbl;
130 fractional_cover = 1.0;
131 height_max = invalid_dbl;
132 height_min = invalid_dbl;
133 initial_biomass = invalid_dbl;
134 number = invalid_dbl;
135 reduc_fac_c = invalid_dbl;
136 root_depth = invalid_dbl;
137 seedbed_duration = 0;
138 seedling_number = invalid_dbl;
139 volume = invalid_dbl;
140 }
141};
142
143struct CBM_API any_properties_t : public species_properties_t
144{
145 any_properties_t & initialize()
146 {
147 species_properties_t::initialize( SPECIES_GROUP_ANY);
148 dbh = invalid_dbl;
149 fractional_cover = 1.0;
150 height_max = invalid_dbl;
151 height_min = invalid_dbl;
152 initial_biomass = invalid_dbl;
153 number = invalid_dbl;
154 reduc_fac_c = invalid_dbl;
155 root_depth = invalid_dbl;
156 seedbed_duration = 0;
157 seedling_number = invalid_dbl;
158 volume = invalid_dbl;
159
160 return *this;
161 }
162};
163extern any_properties_t CBM_API const any_properties_default;
164extern specie_properties_factory_t< any_properties_t > CBM_API const any_properties_factory;
165
166struct CBM_API crop_properties_t : public species_properties_t
167{
168 crop_properties_t & initialize()
169 {
170 species_properties_t::initialize( SPECIES_GROUP_CROP);
171 cover_crop = false;
172 seedbed_duration = 0;
173 seedling_number = invalid_dbl;
174
175 return *this;
176 }
177};
178extern crop_properties_t CBM_API const crop_properties_default;
179extern specie_properties_factory_t< crop_properties_t > CBM_API const crop_properties_factory;
180
181struct CBM_API grass_properties_t : public species_properties_t
182{
183 grass_properties_t & initialize()
184 {
185 species_properties_t::initialize( SPECIES_GROUP_GRASS);
186 height_max = invalid_dbl;
187 height_min = invalid_dbl;
188 root_depth = invalid_dbl;
189 cover_crop = false;
190
191 return *this;
192 }
193};
194extern grass_properties_t CBM_API const grass_properties_default;
195extern specie_properties_factory_t< grass_properties_t > CBM_API const grass_properties_factory;
196
197struct CBM_API wood_properties_t : public species_properties_t
198{
199 wood_properties_t & initialize()
200 {
201 species_properties_t::initialize( SPECIES_GROUP_WOOD);
202 dbh = invalid_dbl;
203 height_max = invalid_dbl;
204 height_min = invalid_dbl;
205 reduc_fac_c = invalid_dbl;
206 root_depth = invalid_dbl;
207 number = invalid_dbl;
208 volume = invalid_dbl;
209
210 return *this;
211 }
212};
213extern wood_properties_t CBM_API const wood_properties_default;
214extern specie_properties_factory_t< wood_properties_t > CBM_API const wood_properties_factory;
215
216extern species_properties_t CBM_API const * species_properties_default[SPECIES_GROUP_CNT];
217extern specie_properties_factory_base_t CBM_API const * species_properties_factories[SPECIES_GROUP_CNT];
218struct CBM_API species_properties_factory_t
219{
220 species_properties_factory_t() {}
221
222 species_properties_t * new_properties( species_group_e) const;
223 void delete_properties( species_properties_t *) const;
224
225 species_properties_t * clone( species_properties_t *, species_properties_t const *) const;
226};
227extern species_properties_factory_t CBM_API const species_properties_factory;
228
229
230class CBM_API species_t
231{
232 public:
233 species_t();
234 ~species_t();
235
236 private:
237 /* species parameter set */
238 speciesparameters::speciesparameters_set_t par_;
239 public:
240 speciesparameters::speciesparameters_set_t const & get_parameters()
241 const
242 {
243 return this->par_;
244 }
245 void set_parameters(
246 speciesparameters::speciesparameters_set_t const & _par)
247 {
248 this->par_ = _par;
249 }
250 speciesparameters::speciesparameters_set_t const * operator->()
251 const
252 {
253 return &this->par_;
254 }
255
256 /* convenience wrapper for group of species */
257 species_group_e group()
258 const
259 {
260 return ( this->have_group_properties_) ? this->par_.GROUP() : SPECIES_GROUP_NONE;
261 }
262 /* convenience wrapper for groupname of species */
263 char const * groupname()
264 const
265 {
266 return SPECIES_GROUP_NAMES[this->have_group_properties_ ? this->par_.GROUP() : SPECIES_GROUP_NONE];
267 }
268 /* convenience wrapper for type of species */
269 char const * type()
270 const
271 {
272 return this->par_.TYPE();
273 }
274 private:
275 std::string name_;
276 public:
277 /* name of species */
278 char const * name()
279 const
280 {
281 return this->name_.c_str();
282 }
283 char const * name( char const * _name)
284 {
285 this->name_ = _name;
286 return this->name_.c_str();
287 }
288
289 private:
290 ldate_t plant_date_;
291 public:
292 ldate_t const & plant_date()
293 const
294 {
295 return this->plant_date_;
296 }
297 ldate_t const & plant_date( ldate_t const & _pd)
298 {
299 this->plant_date_ = _pd;
300 return this->plant_date_;
301 }
302
303 private:
304 /* additional group specific properties for species */
305 bool have_group_properties_;
306 union group_properties_t
307 {
308 crop_properties_t crop;
309 grass_properties_t grass;
310 wood_properties_t wood;
311 } group_properties_;
312 public:
313 bool properties_exist()
314 const
315 {
316 return this->have_group_properties_;
317 }
318
319 species_properties_t * get_properties()
320 {
321 return static_cast< species_properties_t * >( &this->group_properties_.wood);
322 }
323 species_properties_t const * get_properties()
324 const
325 {
326 return static_cast< species_properties_t const * >( &this->group_properties_.wood);
327 }
328
329 // crop properties
330 crop_properties_t const* crop() const {
331 crabmeat_assert(this->properties_exist());
332 crabmeat_assert(this->group() == SPECIES_GROUP_CROP);
333 return static_cast<crop_properties_t const*>(&this->group_properties_.crop);
334 }
335
336 // grass properties
337 grass_properties_t const* grass() const {
338 crabmeat_assert(this->properties_exist());
339 crabmeat_assert(this->group() == SPECIES_GROUP_GRASS);
340 return static_cast<grass_properties_t const*>(&this->group_properties_.grass);
341 }
342
343 // wood properties
344 wood_properties_t const* wood() const {
345 crabmeat_assert(this->properties_exist());
346 crabmeat_assert(this->group() == SPECIES_GROUP_WOOD);
347 return static_cast<wood_properties_t const*>(&this->group_properties_.wood);
348 }
349
350 public:
351 /* reset species properties */
352 lerr_t set_properties(
353 species_group_e _group,
354 species_properties_t const * _props);
355
356};
357
358}}
359
360#endif /* !LDNDC_INPUT_SPECIESTYPES_H_ */
361
Spatially explicit groundwater model.
Definition airchemistryput.h:15