LandscapeDNDC 1.37.0
Loading...
Searching...
No Matches
synth-climate.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
15
16#ifndef LDNDC_DATASYNTH_CLIMATE_H_
17#define LDNDC_DATASYNTH_CLIMATE_H_
18
19#include "synthesizers/synth-base-streamdata.h"
20#include "climate/climatetypes.h"
21#include "time/cbm_date.h"
22
23#include "math/cbm_math.h"
24
25#define SYNTH_CLIMATE_REC_SIZE SYNTH_REC_SIZE_(climate)
26
27#define SYNTH_CLIMATE_INVALIDATE_BUFFER(__buf__) SYNTH_INVALIDATE_BUFFER_(climate,__buf__)
28
29#define SYNTH_CLIMATE_CHK_MATCHING(__item__) SYNTH_CHK_MATCHING_(climate,__item__)
30
31#define SYNTH_CLIMATE_RETURN_SUCCESS(__item__) SYNTH_RETURN_SUCCESS_(climate,__item__)
32
33#define SYNTH_CLIMATE_RECORD_ITEM_COMMON_DECL(__class__,__item_enum__) SYNTH_RECORD_ITEM_COMMON_DECL_(climate,__class__,__item_enum__)
34
35
36/* ??? */
37#define TSMIN (24.0)
38/* maximum overshoot pool */
39#define PRECIP_OVERSHOOT_MAX (70.0)
40/* stretching factor */
41#define PRECIP_STRETCHING_FACTOR (150.0)
42/* reduction rate for overshoot decrease calculation */
43#define PRECIP_OVERSHOOT_REDUCTION_RATE (0.3)
44/* probability of precipitation streching */
45#define PRECIP_STRETCHING_PROBABILITY (0.9)
46
47
48template < typename, unsigned int >
49class lvector_t;
50
51namespace ldndc{ namespace climate{ namespace synth
52{
53 typedef record::item_type record_item_t;
54 struct CBM_API scratch_t : public ldndc::synth::streamdata_scratch_base_t< streamdata_info_t >
55 {
56 /* shifted according to latitude */
57 unsigned int julian_day;
58
59 cbm::random::rng_uniform_t precip_rng;
60
61 record_item_t precip_generated;
62 record_item_t precip_overshoot;
63
64 record_item_t precip_d;
65 record_item_t precip_exp;
66
67 /* items of the current time step record that are given by the data (not synthesized) */
68 bool rec_s_given[record::RECORD_SIZE];
69 record_item_t precip_value_fact;
70
71 double fp_base(
72 double /* latitude */) const;
73
74 double precip_value_fact_fun(
75 double /* precipitation sum */,
76 unsigned int /* days in year */) const;
77
78 lerr_t initialize(
79 climate_info_t const * /* climate meta info */,
80 ltime_t const * /* input date */,
81 ltime_t const * /* output date */);
82
83 lerr_t configure(
84 climate_info_t const * /* climate meta info */,
85 ldate_t const * /* current date */,
86 unsigned int /* current target subday */);
87 };
88
89
90 struct CBM_API item_base_t : public ldndc::synth::streamdata_item_base_t< streamdata_info_t, scratch_t >
91 {
92 };
93
94
95 class CBM_API lsynth_climate_t : public ldndc::synth::streamdata_synth_base_t< streamdata_info_t >
96 {
97 public:
98 lsynth_climate_t();
99 lsynth_climate_t(
100 climate_info_t const * /* climate meta info */,
101 ltime_t const * /* input date */,
102 ltime_t const * /* output date */);
103
104
105 virtual ~lsynth_climate_t();
106
111 lerr_t configure(
112 ldate_t const * /* target date */,
113 unsigned int = ldndc::invalid_t< unsigned int >::value /* target subday */);
114
119 lerr_t synthesize_record(
120 record_item_t const * /* subday data buffer (input) */, record_item_t * /* subday data buffer (output) */,
121 record_item_t const * /* day data buffer (input) */, record_item_t * /* day data buffer (output) */,
122
123 ldate_t const * /* current date */,
124
125 lvector_t< unsigned int, 1 > * = NULL /* modification count */);
126
134 lerr_t check_record(
135 record_item_t const * /* subday data buffer (input) */,
136 record_item_t const * /* day data buffer (input) */) const;
137
138 inline
139 unsigned int subday()
140 const
141 {
142 return this->scratch_.subday;
143 }
144
145 inline
146 unsigned int time_resolution_inout()
147 const
148 {
149 return this->scratch_.t_res_inout;
150 }
151
152 private:
153 climate_info_t info_;
154 scratch_t scratch_;
155
156 /* default synthesizer execution order */
157 static record::record_item_e const SYNTH_ORDER[record::RECORD_SIZE];
158 /* (reordered) synthesizer execution order array for day timestep */
159 record::record_item_e synth_order_[record::RECORD_SIZE];
160 };
161 extern item_base_t const * climate_synthesizers[record::RECORD_SIZE];
162}}}
163
164
165#endif /* !LDNDC_DATASYNTH_CLIMATE_H_ */
166
Spatially explicit groundwater model.
Definition airchemistryput.h:21