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