The BioCro C++ Library
phase_clock.h
Go to the documentation of this file.
1#ifndef PHASE_CLOCK_H
2#define PHASE_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 phase_clock : public differential_module
12{
13 public:
14 phase_clock(state_map const& input_quantities, state_map* output_quantities)
15 : differential_module{},
16
17 // Get pointers to input quantities
18 phi_ip{get_ip(input_quantities, "phi")},
19 light_ip{get_ip(input_quantities, "light")},
20 clock_dead_width_ip{get_ip(input_quantities, "clock_dead_width")},
21 clock_width_asymm_ip{get_ip(input_quantities, "clock_width_asymm")},
22 clock_area_asymm_ip{get_ip(input_quantities, "clock_area_asymm")},
23 clock_r_scale_ip{get_ip(input_quantities, "clock_r_scale")},
24 clock_period_ip{get_ip(input_quantities, "clock_period")},
25
26 // Get pointers to output quantities
27 phi_op{get_op(output_quantities, "phi")}
28 {
29 }
30 static string_vector get_inputs();
31 static string_vector get_outputs();
32 static std::string get_name() { return "phase_clock"; }
33
34 private:
35 // Pointers to input quantities
36 const double* phi_ip;
37 const double* light_ip;
38 const double* clock_dead_width_ip;
39 const double* clock_width_asymm_ip;
40 const double* clock_area_asymm_ip;
41 const double* clock_r_scale_ip;
42 const double* clock_period_ip;
43
44 // Pointers to output quantities
45 double* phi_op;
46
47 // Main operation
48 void do_operation() const;
49};
50
52{
53 return {
54 "phi",
55 "light",
56 "clock_dead_width",
57 "clock_width_asymm",
58 "clock_area_asymm",
59 "clock_r_scale",
60 "clock_period"};
61}
62
64{
65 return {
66 "phi"};
67}
68
69void phase_clock::do_operation() const
70{
72 // Collect inputs and make calculations //
74
75 using math_constants::pi;
76
77 // Get the current phase value
78 const double phi = *phi_ip;
79
80 // Bring phi back to the [0, 2*pi) range
81 const double phi_mod = phi - 2.0 * pi * floor(phi / (2.0 * pi));
82
83 // Get the current light value
84 const double light = *light_ip;
85
86 // Get the response function parameters
87 const double d = *clock_dead_width_ip;
88 const double delta = *clock_width_asymm_ip;
89 const double epsilon = *clock_area_asymm_ip;
90 const double s = *clock_r_scale_ip;
91
92 // Determine a, b, alpha, and beta for the response function
93 const double a = pi * (1.0 - d + delta);
94 const double b = pi * (1.0 - d - delta);
95 ;
96 const double alpha = s * (1.0 + 0.5 * epsilon);
97 const double beta = s * (1.0 - 0.5 * epsilon);
98
99 // Calculate the response
100 const double R =
101 (0.0 <= phi_mod && phi_mod < a) ? -6.0 * alpha * phi_mod * (phi_mod - a) / (a * a * a)
102 : (phi_mod < 2.0 * pi - b) ? 0.0
103 : (phi_mod < 2.0 * pi) ? 6.0 * beta * (phi_mod - 2.0 * pi) * (phi_mod - 2.0 * pi + b) / (b * b * b)
104 : throw std::logic_error(std::string("Thrown by phase_clock: something is wrong with phi_mod!\n"));
105
106 // Get the intrinsic clock period
107 const double natural_period = *clock_period_ip; // Natural period in hours
108 const double natural_freq = 2.0 * pi / natural_period; // Corresponding angular frequency in radians per hour
109
111 // Update the output quantity list //
113
114 update(phi_op, natural_freq * (1 + R * light));
115}
116
117} // namespace standardBML
118#endif
phase_clock(state_map const &input_quantities, state_map *output_quantities)
Definition: phase_clock.h:14
static string_vector get_outputs()
Definition: phase_clock.h:63
static string_vector get_inputs()
Definition: phase_clock.h:51
static std::string get_name()
Definition: phase_clock.h:32
This is the standard BioCro module library; it includes the essential modules used in typical BioCro ...
Definition: aba_decay.h:8