The BioCro C++ Library
poincare_clock.h
Go to the documentation of this file.
1#ifndef POINCARE_CLOCK_H
2#define POINCARE_CLOCK_H
3
4#include <cmath>
5#include "../framework/constants.h"
6#include "../framework/module.h"
7#include "../framework/state_map.h"
8
9namespace standardBML
10{
11class poincare_clock : public differential_module
12{
13 public:
14 poincare_clock(state_map const& input_quantities, state_map* output_quantities)
15 : differential_module{},
16
17 // Get pointers to input quantities
18 dawn_kick_ip{get_ip(input_quantities, "dawn_kick")},
19 dusk_kick_ip{get_ip(input_quantities, "dusk_kick")},
20 dawn_b_ip{get_ip(input_quantities, "dawn_b")},
21 dawn_a_ip{get_ip(input_quantities, "dawn_a")},
22 dusk_b_ip{get_ip(input_quantities, "dusk_b")},
23 dusk_a_ip{get_ip(input_quantities, "dusk_a")},
24 ref_b_ip{get_ip(input_quantities, "ref_b")},
25 ref_a_ip{get_ip(input_quantities, "ref_a")},
26 clock_gamma_ip{get_ip(input_quantities, "clock_gamma")},
27 clock_r0_ip{get_ip(input_quantities, "clock_r0")},
28 clock_period_ip{get_ip(input_quantities, "clock_period")},
29
30 // Get pointers to output quantities
31 dawn_b_op{get_op(output_quantities, "dawn_b")},
32 dawn_a_op{get_op(output_quantities, "dawn_a")},
33 dusk_b_op{get_op(output_quantities, "dusk_b")},
34 dusk_a_op{get_op(output_quantities, "dusk_a")},
35 ref_b_op{get_op(output_quantities, "ref_b")},
36 ref_a_op{get_op(output_quantities, "ref_a")}
37 {
38 }
39 static string_vector get_inputs();
40 static string_vector get_outputs();
41 static std::string get_name() { return "poincare_clock"; }
42
43 private:
44 // Pointers to input quantities
45 const double* dawn_kick_ip;
46 const double* dusk_kick_ip;
47 const double* dawn_b_ip;
48 const double* dawn_a_ip;
49 const double* dusk_b_ip;
50 const double* dusk_a_ip;
51 const double* ref_b_ip;
52 const double* ref_a_ip;
53 const double* clock_gamma_ip;
54 const double* clock_r0_ip;
55 const double* clock_period_ip;
56
57 // Pointers to output quantities
58 double* dawn_b_op;
59 double* dawn_a_op;
60 double* dusk_b_op;
61 double* dusk_a_op;
62 double* ref_b_op;
63 double* ref_a_op;
64
65 // Main operation
66 void do_operation() const;
67};
68
70{
71 return {
72 "dawn_kick",
73 "dusk_kick",
74 "dawn_b",
75 "dawn_a",
76 "dusk_b",
77 "dusk_a",
78 "ref_b",
79 "ref_a",
80 "clock_gamma",
81 "clock_r0",
82 "clock_period"};
83}
84
86{
87 return {
88 "dawn_b",
89 "dawn_a",
90 "dusk_b",
91 "dusk_a",
92 "ref_b",
93 "ref_a"};
94}
95
96void poincare_clock::do_operation() const
97{
99 // Collect inputs and make calculations //
101
102 using math_constants::pi;
103
104 // Get the current values of the dawn and dusk kicks
105 double dawn_kick = *dawn_kick_ip;
106 double dusk_kick = *dusk_kick_ip;
107
108 // Get the current state of the dawn tracking oscillator
109 double dawn_b = *dawn_b_ip;
110 double dawn_a = *dawn_a_ip;
111
112 // Get the current state of the dusk tracking oscillator
113 double dusk_b = *dusk_b_ip;
114 double dusk_a = *dusk_a_ip;
115
116 // Get the current state of the reference oscillator
117 double ref_b = *ref_b_ip;
118 double ref_a = *ref_a_ip;
119
120 // Define the constants for the tracking oscillators
121 const double natural_period = *clock_period_ip; // Natural period in hours
122 const double natural_freq = 2.0 * pi / natural_period; // Corresponding angular frequency in radians per hour
123 const double gamma = *clock_gamma_ip;
124 const double r_0 = *clock_r0_ip;
125
126 // Calculate the friction terms for the tracking oscillators
127 const double dawn_friction = gamma * (r_0 - sqrt(dawn_a * dawn_a + dawn_b * dawn_b));
128 const double dusk_friction = gamma * (r_0 - sqrt(dusk_a * dusk_a + dusk_b * dusk_b));
129 const double ref_friction = gamma * (r_0 - sqrt(ref_a * ref_a + ref_b * ref_b));
130
132 // Update the output quantity list //
134
135 // The dawn tracking oscillator is driven by a small kick at dawn
136 update(dawn_b_op, dawn_friction * dawn_b + natural_freq * dawn_a);
137 update(dawn_a_op, dawn_friction * dawn_a - natural_freq * dawn_b + dawn_kick);
138
139 // The dusk tracking oscillator is driven by a small kick at dusk
140 update(dusk_b_op, dusk_friction * dusk_b + natural_freq * dusk_a);
141 update(dusk_a_op, dusk_friction * dusk_a - natural_freq * dusk_b + dusk_kick);
142
143 // The reference oscillator is not driven
144 update(ref_b_op, ref_friction * ref_b + natural_freq * ref_a);
145 update(ref_a_op, ref_friction * ref_a - natural_freq * ref_b);
146}
147
148} // namespace standardBML
149#endif
static string_vector get_outputs()
static string_vector get_inputs()
static std::string get_name()
poincare_clock(state_map const &input_quantities, state_map *output_quantities)
This is the standard BioCro module library; it includes the essential modules used in typical BioCro ...
Definition: aba_decay.h:8