The BioCro C++ Library
fake_solar.h
Go to the documentation of this file.
1#ifndef FAKE_SOLAR_H
2#define FAKE_SOLAR_H
3
4#include "../framework/module.h"
5#include "../framework/state_map.h"
6#include <cmath>
7
8namespace standardBML
9{
16class fake_solar : public direct_module
17{
18 public:
20 state_map const& input_quantities,
21 state_map* output_quantities)
22 : direct_module{},
23
24 // Get pointers to input quantities
25 time_ip{get_ip(input_quantities, "time")},
26 target_time_ip{get_ip(input_quantities, "target_time")},
27
28 // Get pointers to output quantities
29 solar_op{get_op(output_quantities, "solar")}
30 {
31 }
32 static string_vector get_inputs();
33 static string_vector get_outputs();
34 static std::string get_name() { return "fake_solar"; }
35
36 private:
37 // Pointers to input quantities
38 const double* time_ip;
39 const double* target_time_ip;
40
41 // Pointers to output quantities
42 double* solar_op;
43
44 // Main operation
45 void do_operation() const;
46};
47
49{
50 return {
51 "time",
52 "target_time"};
53}
54
56{
57 return {
58 "solar"};
59}
60
61void fake_solar::do_operation() const
62{
64 // Collect inputs and make calculations //
66
67 // Get the current time
68 double time = *time_ip;
69
70 // Calculate the radiation in a way that's good for testing different day lengths, and the switch to dark conditions
71
72 // Extract out the DOY and hour
73 int d = std::floor(time / 24);
74 int doy = 1 + d;
75 double hour = time - 24 * d;
76
77 // Define the parameters for calculating the solar radiation
78 int min_doy = 91; // The first day to shine light (min in dataset is 91) (mean is 196)
79 int max_doy = 301; // The last day to shine light (max in dataset is 301) (mean is 196)
80 double max_solar = 1000.0; // Maximum intensity from sun
81 double bkg = 0.0; // Background intensity
82
83 double ss_dawn = 4.7; // Start of civil twilight in Chicago on summer solstice 2019
84 double ss_dusk = 21.0; // End of civil twilight in Chicago on summer solstice 2019 (length = 16.3)
85
86 double ws_dawn = 6.7; // Start of civil twilight in Chicago on winter solstice 2018
87 double ws_dusk = 17.0; // End of civil twilight in Chicago on winter solstice 2018 (length = 10.3)
88
89 //double se_dawn = 6.5; // Start of civil twilight in Chicago on spring equinox 2019
90 //double se_dusk = 19.5; // End of civil twilight in Chicago on spring equinox 2019 (length = 13.0)
91
92 double dawn = ss_dawn + (doy - min_doy) * (ws_dawn - ss_dawn) / (max_doy - min_doy);
93 double dusk = ss_dusk + (doy - min_doy) * (ws_dusk - ss_dusk) / (max_doy - min_doy);
94
95 //double dawn = se_dawn;
96 //double dusk = se_dusk;
97
98 // Calculate the Gaussian parameters
99 double mean = 0.5 * (dawn + dusk);
100 double sigma = (dusk - dawn) / 4.0; // Situate dawn and dusk at mean -/+ 2 * sigma, so that 95% of the light is emitted between these times
101
102 // Calculate the radiation intensity
103 double solar = bkg;
104 if (doy >= min_doy && doy <= max_doy) solar += max_solar * exp(-(hour - mean) * (hour - mean) / (sigma * sigma));
105
106 /*
107 // Calculate the radiation in a way that's good for calculating a phase response curve
108
109 // Get the target doy to apply the sun
110 double target_time = *target_time_ip;
111
112 // Calculate the radiation
113 double max_solar = 1000.0;
114 double day_length = 12.0; // In hours
115 double sigma = day_length / 4.0; // In hours
116 sigma /= 24.0; // In days
117 double solar = max_solar * exp(-(time - target_time) * (time - target_time) / (sigma * sigma));
118 */
119
121 // Update the output quantity list //
123
124 update(solar_op, solar);
125}
126
127} // namespace standardBML
128#endif
Class created by EBL for testing and experimentation ... not meant for real simulations!
Definition: fake_solar.h:17
fake_solar(state_map const &input_quantities, state_map *output_quantities)
Definition: fake_solar.h:19
static string_vector get_outputs()
Definition: fake_solar.h:55
static string_vector get_inputs()
Definition: fake_solar.h:48
static std::string get_name()
Definition: fake_solar.h:34
This is the standard BioCro module library; it includes the essential modules used in typical BioCro ...
Definition: aba_decay.h:8