The BioCro C++ Library
nr_ex.h
Go to the documentation of this file.
1#ifndef NR_EX_H
2#define NR_EX_H
3
4#include "../framework/module.h"
5#include "../framework/state_map.h"
6
7// This module is an example in Chapter 16 of Numerical Recipes in C
8// The analytical solution is:
9// u = 2 * exp(-x) - exp(-1000x)
10// v = -exp(-x) + exp(-1000x)
11// For u(0) = 1, v(0) = 0
12
13namespace standardBML
14{
15class nr_ex : public differential_module
16{
17 public:
18 nr_ex(state_map const& input_quantities, state_map* output_quantities)
19 : differential_module{},
20
21 // Get input pointers
22 u_ip{get_ip(input_quantities, "u")},
23 v_ip{get_ip(input_quantities, "v")},
24
25 // Get output pointers for time derivatives
26 u_op{get_op(output_quantities, "u")},
27 v_op{get_op(output_quantities, "v")}
28 {
29 }
30 static string_vector get_inputs();
31 static string_vector get_outputs();
32 static std::string get_name() { return "nr_ex"; }
33
34 private:
35 // Input pointers
36 const double* u_ip;
37 const double* v_ip;
38
39 // Output pointers for time derivatives
40 double* u_op;
41 double* v_op;
42
43 // Main operation
44 void do_operation() const;
45};
46
47string_vector nr_ex::get_inputs()
48{
49 return {
50 "u", //
51 "v" //
52 };
53}
54
55string_vector nr_ex::get_outputs()
56{
57 return {
58 "u", //
59 "v" //
60 };
61}
62
63void nr_ex::do_operation() const
64{
65 // Calculate the time derivatives and modify the module output map
66 update(u_op, +998.0 * (*u_ip) + 1998.0 * (*v_ip));
67 update(v_op, -999.0 * (*u_ip) - 1999.0 * (*v_ip));
68}
69
70} // namespace standardBML
71#endif
nr_ex(state_map const &input_quantities, state_map *output_quantities)
Definition: nr_ex.h:18
static string_vector get_outputs()
Definition: nr_ex.h:55
static string_vector get_inputs()
Definition: nr_ex.h:47
static std::string get_name()
Definition: nr_ex.h:32
This is the standard BioCro module library; it includes the essential modules used in typical BioCro ...
Definition: aba_decay.h:8