LandscapeDNDC 1.37.0
Loading...
Searching...
No Matches
speciesparameterstypes.h
1
10
11#ifndef LDNDC_INPUT_SPECIESPARAMETERSTYPES_H_
12#define LDNDC_INPUT_SPECIESPARAMETERSTYPES_H_
13
14#include "crabmeat-common.h"
15#include "containers/cbm_typewrap.h"
16
17#include "species/speciesgroups.h"
18#include "string/cbm_string.h"
19#include "constants/cbm_const.h"
20
21#ifdef _DEBUG
22# include "utils/cbm_utils.h"
23#endif
24#ifndef __SPECIESPARAMETER_VALUE__
25# define __SPECIESPARAMETER_VALUE__(__name__,__type__) this->s.p[__SPECIESPARAMETER_index_ ## __name__].get_value<__type__>()
26#endif
27#define SPECIESPARAMETER_(__name__,__type__) \
28public: \
29 __type__ __name__() \
30 const \
31 { \
32 /*CBM_LogInfo( "requesting parameter .. " #__name__);*/ \
33 crabmeat_assert( cbm::is_valid( __SPECIESPARAMETER_VALUE__(__name__,__type__))); \
34 return __SPECIESPARAMETER_VALUE__(__name__,__type__); \
35 } \
36 static __type__ __name__##_##MIN() \
37 { \
38 return SPECIESPARAMETER_##__name__##_MINVALUE; \
39 } \
40 static __type__ __name__##_##MAX() \
41 { \
42 return SPECIESPARAMETER_##__name__##_MAXVALUE; \
43 } \
44 void __name__##_##UPDATE( __type__ __value__) \
45 { \
46 this->s.p[__SPECIESPARAMETER_index_ ## __name__] = __value__; \
47 } \
48private:
49
50
51#define SPECIESPARAMETER_BOOL(__name__) SPECIESPARAMETER_(__name__,speciesparameter_t::bool_type)
52#define SPECIESPARAMETER_FLT(__name__) SPECIESPARAMETER_(__name__,speciesparameter_t::float_type)
53#define SPECIESPARAMETER_INT(__name__) SPECIESPARAMETER_(__name__,speciesparameter_t::int_type)
54#define SPECIESPARAMETER_UINT(__name__) SPECIESPARAMETER_(__name__,speciesparameter_t::uint_type)
55
56#define SPECIESPARAMETER_INVALID_BOOL false
57#define SPECIESPARAMETER_INVALID_FLT ldndc::invalid_t< speciesparameter_t::float_type >::value
58#define SPECIESPARAMETER_INVALID_INT ldndc::invalid_t< speciesparameter_t::int_type >::value
59#define SPECIESPARAMETER_INVALID_UINT ldndc::invalid_t< speciesparameter_t::uint_type >::value
60
61
62#include "io/outputtypes.h"
63namespace ldndc{ namespace speciesparameters
64{
65#define LTYPEWRAP_SPECIES_PARAM_MAGIC 4
66typedef ltypewrap_t< ldndc_flt64_t, ldndc_int32_t, ldndc_uint32_t, LTYPEWRAP_SPECIES_PARAM_MAGIC > speciesparameter_t;
67#define SPECIESPARAMETERS_bool_type LDNDC_BOOL
68#define SPECIESPARAMETERS_float_type LDNDC_FLOAT64
69#define SPECIESPARAMETERS_int_type LDNDC_INT32
70#define SPECIESPARAMETERS_uint_type LDNDC_UINT32
71
72#include "speciesparameters.h.inc"
73
74struct CBM_API speciesparameters_meta_t
75{
76 speciesparameters_meta_t();
77
78 speciesparameters_meta_t(
79 char const * /*mnemonic*/,
80 char const * /*parent*/,
81 species::species_group_e /*group*/);
82
83 speciesparameters_meta_t(
84 speciesparameters_meta_t const &);
85 speciesparameters_meta_t & operator=(
86 speciesparameters_meta_t const &);
87
88 /* identifier for species parameter set */
89 ldndc_string_t mnemonic;
90 /* direct parent in inheritance tree */
91 ldndc_string_t parent;
92 /* species group */
93 species::species_group_e group;
94};
95
96
97struct CBM_API parameterized_species_t
98{
99 parameterized_species_t();
100
101 speciesparameters_meta_t m;
102 speciesparameter_t p[SPECIESPARAMETERS_CNT];
103
104 int parent_index;
105 int merge_count;
106};
107
108class CBM_API speciesparameters_set_t
109{
110 public:
111 speciesparameters_set_t();
112 speciesparameters_set_t(
113 speciesparameters_meta_t const *);
114 speciesparameters_set_t(
115 parameterized_species_t const *);
116 speciesparameters_set_t(
117 speciesparameters_set_t const &);
118 speciesparameters_set_t & operator=(
119 speciesparameters_set_t const &);
120
121 /* checks if all parameters have a valid value, i.e. were explicitly set */
122 bool is_valid() const;
123
124 size_t size() const { return SPECIESPARAMETERS_CNT; }
125
126 /* meta info */
127 char const * PARENT() const { return this->s.m.parent; }
128 char const * TYPE() const { return this->s.m.mnemonic; }
129 char const * GROUPNAME() const { return species::SPECIES_GROUP_NAMES[this->s.m.group]; }
130 species::species_group_e GROUP() const { return this->s.m.group; }
131
132 bool IS_CROP() const { return this->s.m.group == species::SPECIES_GROUP_CROP; }
133 bool IS_GRASS() const { return this->s.m.group == species::SPECIES_GROUP_GRASS; }
134 bool IS_WOOD() const { return this->s.m.group == species::SPECIES_GROUP_WOOD; }
135
136 /* expands to getters for all species parameters */
137 SPECIESPARAMETERS_GETTERS
138
139 public:
140 int copy_valid(
141 speciesparameters_set_t const *);
142 int copy_valid(
143 speciesparameter_t const *);
144 std::string parametervalue_as_string(
145 char const *) const;
146 std::string to_string( char const * = ";" /*delimiter*/) const;
147
148 public:
149 speciesparameter_t::float_type GDD_GRAIN()
150 const
151 {
152 if ( this->GDD_GRAIN_FILLING() > 0.0)
153 { return this->GDD_GRAIN_FILLING(); }
154 else
155 { return 0.5 * this->GDD_MATURITY(); }
156 }
157
158 speciesparameter_t::float_type FALEAF()
159 const
160 {
161 return this->FRACTION_FOLIAGE() / (1.0 - this->FRACTION_FRUIT() - this->FRACTION_ROOT());
162 }
163
164 private:
165 parameterized_species_t s;
166};
167
168}}
169
170#endif /* !LDNDC_INPUT_SPECIESPARAMETERSTYPES_H_ */
171
Spatially explicit groundwater model.
Definition airchemistryput.h:15