Skip to content

Commit 1af1a65

Browse files
committed
code beautification...
1 parent f3514d7 commit 1af1a65

7 files changed

Lines changed: 83 additions & 87 deletions

File tree

demo/regulatory_networks/src/bdm_ex1.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ struct ODE_system {
2727
const std::map<std::string, DiffusionGrid*>& mdg;
2828
const std::vector<real_t> param;
2929

30-
ODE_system(std::map<std::string, DiffusionGrid*>& m, const std::vector<real_t>& p)
31-
: mdg(m), param(p) {}
30+
ODE_system(std::map<std::string, DiffusionGrid*>& m,
31+
const std::vector<real_t>& p)
32+
: mdg(m), param(p) {}
3233

3334
void operator()(const b_vector_t& x, b_vector_t& dxdt, real_t t,
3435
Agent* agent) const {
@@ -46,11 +47,12 @@ struct ODE_jacobian {
4647
const std::map<std::string, DiffusionGrid*>& mdg;
4748
const std::vector<real_t> param;
4849

49-
ODE_jacobian(std::map<std::string, DiffusionGrid*>& m, const std::vector<real_t>& p)
50-
: mdg(m), param(p) {}
50+
ODE_jacobian(std::map<std::string, DiffusionGrid*>& m,
51+
const std::vector<real_t>& p)
52+
: mdg(m), param(p) {}
5153

52-
void operator()(const b_vector_t& x, b_matrix_t& jac, real_t t, b_vector_t& dfdt,
53-
Agent* agent) const {
54+
void operator()(const b_vector_t& x, b_matrix_t& jac, real_t t,
55+
b_vector_t& dfdt, Agent* agent) const {
5456
// auto& xyz = agent->GetPosition();
5557
// auto dg = mdg.find("protein")->second;
5658
// const real_t protein = dg->GetValue(xyz);
@@ -70,8 +72,7 @@ struct ODE_jacobian {
7072
};
7173

7274
struct ODE_output {
73-
void operator()(const b_vector_t& x, real_t t,
74-
const Agent* agent) {
75+
void operator()(const b_vector_t& x, real_t t, const Agent* agent) {
7576
auto& xyz = agent->GetPosition();
7677
std::clog << agent->GetUid()
7778
<< ',' << xyz[0] << ',' << xyz[1] << ',' << xyz[2]
@@ -95,14 +96,14 @@ inline int Simulate(int argc, const char** argv) {
9596
param->output_dir = "ex1";
9697
param->use_progress_bar = false;
9798
param->bound_space = Param::BoundSpaceMode::kOpen;
98-
param->min_bound = 0.0;
99-
param->max_bound = +100.0;
99+
param->min_bound = 0.0;
100+
param->max_bound = 100.0;
100101
param->export_visualization = false;
101102
param->visualization_interval = 1;
102-
param->visualize_agents["Cell"] = { "diameter_", "volume_" };
103+
param->visualize_agents["Cell"] = {"diameter_", "volume_"};
103104
param->statistics = false;
104105
param->simulation_time_step = 1.0;
105-
param->visualize_diffusion = { Param::VisualizeDiffusion{"cytokine", true, true} };
106+
param->visualize_diffusion = {Param::VisualizeDiffusion{"cytokine", true, true}};
106107
param->calculate_gradients = false;
107108
param->diffusion_method = "euler";
108109
};
@@ -118,7 +119,7 @@ inline int Simulate(int argc, const char** argv) {
118119
// BioDynaMo's diffusion grid sample points in each dimension
119120
int n_DG = 51;
120121

121-
ModelInitializer::DefineSubstance(kProtein, "protein", 0.0/dt_BDM, 0.0/dt_BDM, n_DG);
122+
ModelInitializer::DefineSubstance(kProtein, "protein", 0.0, 0.0, n_DG);
122123
ModelInitializer::AddBoundaryConditions(
123124
kProtein, BoundaryConditionType::kNeumann,
124125
std::make_unique<ConstantBoundaryCondition>(0));
@@ -133,21 +134,22 @@ inline int Simulate(int argc, const char** argv) {
133134
c->SetMass(1.0);
134135
c->SetPosition(xyz);
135136
#ifndef __ROOTCLING__
136-
c->AddBehavior(new RegulatoryNetwork(dt_RN, 1000, {1., 5., 7.},
137-
//ODE_solver::Euler,
138-
//ODE_solver::Rosenbrock,
139-
ODE_solver::RungeKutta,
140-
ODE_system(dg_map,{0.2,0.1,3.0}),
141-
ODE_jacobian(dg_map,{0.2,0.1,3.0}),
142-
ODE_output()));
137+
c->AddBehavior(new RegulatoryNetwork(
138+
dt_RN, 1000, {1., 5., 7.},
139+
// ODE_solver::Euler,
140+
// ODE_solver::Rosenbrock,
141+
ODE_solver::RungeKutta,
142+
ODE_system(dg_map,{0.2,0.1,3.0}),
143+
ODE_jacobian(dg_map,{0.2,0.1,3.0}),
144+
ODE_output()));
143145
#endif
144146
return c;
145147
};
146148

147149
int n_cells = 1;
148150
ModelInitializer::CreateAgentsRandom(0.0, 0.0001, n_cells, generate_cells);
149151

150-
for (int s=0; s<10; s++)
152+
for (int s = 0; s < 10; s++)
151153
sim.GetScheduler()->Simulate(1);
152154

153155
// restore the original buffer of std::clog
@@ -156,8 +158,8 @@ inline int Simulate(int argc, const char** argv) {
156158
return 0;
157159
}
158160

159-
} // namespace ex1
161+
} // namespace ex1
160162

161-
} // namespace bdm
163+
} // namespace bdm
162164

163-
#endif // BDM_EX1_H_
165+
#endif // BDM_EX1_H_

demo/regulatory_networks/src/bdm_ex2.h

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@
1616

1717
#include "biodynamo.h"
1818

19-
#include "core/behavior/regulatory_network.h"
2019
#include "core/agent/agent.h"
20+
#include "core/behavior/regulatory_network.h"
2121

2222
namespace bdm {
2323

2424
class MyCell : public Cell {
2525
BDM_AGENT_HEADER(MyCell, Cell, 1);
2626

27-
public:
28-
MyCell() {}
29-
explicit MyCell(const Real3& position) : Base(position), trail_(0.0) {}
30-
virtual ~MyCell() {}
27+
public:
28+
MyCell() {}
29+
explicit MyCell(const Real3& position) : Base(position), trail_(0.0) {}
30+
virtual ~MyCell() {}
3131

32-
void Initialize(const NewAgentEvent& event) override {
33-
Base::Initialize(event);
32+
void Initialize(const NewAgentEvent& event) override {
33+
Base::Initialize(event);
3434

35-
if (auto* mother = dynamic_cast<MyCell*>(event.existing_agent)) {
36-
if (event.GetUid() == CellDivisionEvent::kUid) {
37-
// copy properties from mother to daughter
38-
}
35+
if (auto* mother = dynamic_cast<MyCell*>(event.existing_agent)) {
36+
if (event.GetUid() == CellDivisionEvent::kUid) {
37+
// copy properties from mother to daughter
3938
}
4039
}
40+
}
4141

42-
real_t GetTrail() const { return trail_; }
43-
void SetTrail(real_t t) { trail_ += t; }
42+
real_t GetTrail() const { return trail_; }
43+
void SetTrail(real_t t) { trail_ += t; }
4444

45-
private:
46-
/// keep track of the trail of the agent
47-
real_t trail_;
45+
private:
46+
/// keep track of the trail of the agent
47+
real_t trail_;
4848
};
4949

5050
#ifndef __ROOTCLING__
@@ -62,12 +62,12 @@ struct Lorenz_rhs_ {
6262
};
6363

6464
struct Lorenz_jac_ {
65-
void operator()(const b_vector_t& x, b_matrix_t& jac, double t, b_vector_t& dfdt,
66-
Agent* agent) const {
65+
void operator()(const b_vector_t& x, b_matrix_t& jac, double t,
66+
b_vector_t& dfdt, Agent* agent) const {
6767
jac(0, 0) = -sigma;
6868
jac(0, 1) = sigma;
6969
jac(0, 2) = 0.0;
70-
jac(1, 0) = rho - x[2];
70+
jac(1, 0) = rho - x[2];
7171
jac(1, 1) = -1.0;
7272
jac(1, 2) = -x[0];
7373
jac(2, 0) = x[1];
@@ -83,8 +83,7 @@ struct Lorenz_jac_ {
8383
};
8484

8585
struct Lorenz_out_ {
86-
void operator()(const b_vector_t& x, real_t t, const
87-
Agent* agent) {
86+
void operator()(const b_vector_t& x, real_t t, const Agent* agent) {
8887
auto& xyz = agent->GetPosition();
8988
std::clog << agent->GetUid()
9089
<< ',' << xyz[0] << ',' << xyz[1] << ',' << xyz[2]
@@ -101,8 +100,8 @@ class Trajectory : public RegulatoryNetwork {
101100
Trajectory() { AlwaysCopyToNew(); }
102101
#ifndef __ROOTCLING__
103102
Trajectory(real_t dt, int n_dt, const std::vector<real_t>& x)
104-
: RegulatoryNetwork(dt, n_dt, x, ODE_solver::Rosenbrock,
105-
Lorenz_rhs_(), Lorenz_jac_(), Lorenz_out_()) {}
103+
: RegulatoryNetwork(dt, n_dt, x, ODE_solver::Rosenbrock,
104+
Lorenz_rhs_(), Lorenz_jac_(), Lorenz_out_()) {}
106105
#endif
107106
virtual ~Trajectory() = default;
108107

@@ -113,7 +112,7 @@ class Trajectory : public RegulatoryNetwork {
113112
void Run(Agent* agent) override {
114113
#ifndef __ROOTCLING__
115114
Real3 xyz;
116-
for (int i=0; i<3; i++)
115+
for (int i = 0; i < 3; i++)
117116
xyz[i] = this->GetSpecie(i);
118117

119118
if (auto* cell = dynamic_cast<MyCell*>(agent)) {
@@ -127,7 +126,6 @@ class Trajectory : public RegulatoryNetwork {
127126
}
128127
#endif
129128
}
130-
131129
};
132130

133131
namespace ex2 {
@@ -144,11 +142,11 @@ inline int Simulate(int argc, const char** argv) {
144142
param->output_dir = "ex2";
145143
param->use_progress_bar = false;
146144
param->bound_space = Param::BoundSpaceMode::kOpen;
147-
param->min_bound = 0.0;
148-
param->max_bound = +100.0;
145+
param->min_bound = 0.0;
146+
param->max_bound = 100.0;
149147
param->export_visualization = true;
150148
param->visualization_interval = 10;
151-
param->visualize_agents["MyCell"] = { "diameter_", "volume_", "trail_" };
149+
param->visualize_agents["MyCell"] = {"diameter_", "volume_", "trail_"};
152150
param->statistics = false;
153151
param->simulation_time_step = 1.0;
154152
};
@@ -173,7 +171,7 @@ inline int Simulate(int argc, const char** argv) {
173171
sim.GetExecutionContext()->AddAgent(c);
174172
}
175173

176-
for (int s=0; s<3000; s++)
174+
for (int s = 0; s < 3000; s++)
177175
sim.GetScheduler()->Simulate(1);
178176

179177
// restore the original buffer of std::clog
@@ -182,8 +180,8 @@ inline int Simulate(int argc, const char** argv) {
182180
return 0;
183181
}
184182

185-
} // namespace ex2
183+
} // namespace ex2
186184

187-
} // namespace bdm
185+
} // namespace bdm
188186

189-
#endif // BDM_EX2_H_
187+
#endif // BDM_EX2_H_

demo/regulatory_networks/src/lorenz.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#ifndef LORENZ_H_
1616
#define LORENZ_H_
1717

18-
#include <iostream>
1918
#include <fstream>
19+
#include <iostream>
2020

2121
#ifndef __ROOTCLING__
2222
#include <boost/array.hpp>
@@ -26,8 +26,8 @@
2626
#endif
2727

2828
#ifndef __ROOTCLING__
29-
typedef boost::numeric::ublas::vector<double> b_vector_t;
30-
typedef boost::numeric::ublas::matrix<double> b_matrix_t;
29+
typedef boost::numeric::ublas::vector<double> b_vector_t;
30+
typedef boost::numeric::ublas::matrix<double> b_matrix_t;
3131
#endif
3232

3333
namespace lorenz {
@@ -46,7 +46,8 @@ struct ODE_system {
4646
};
4747

4848
struct ODE_jacobian {
49-
void operator()(const b_vector_t& x, b_matrix_t& jac, double t, b_vector_t& dfdt) const {
49+
void operator()(const b_vector_t& x, b_matrix_t& jac, double t,
50+
b_vector_t& dfdt) const {
5051
jac(0, 0) = -sigma;
5152
jac(0, 1) = sigma;
5253
jac(0, 2) = 0.0;
@@ -88,12 +89,10 @@ inline int Simulate(int argc, const char** argv) {
8889
typedef boost::numeric::odeint::rosenbrock4<double> ode_int;
8990

9091
// set-up the Rosenbrock integrator
91-
auto stepper =
92-
boost::numeric::odeint::make_dense_output<ode_int>(1e-6,1e-6);
92+
auto stepper = boost::numeric::odeint::make_dense_output<ode_int>(1e-6, 1e-6);
9393

9494
// perform the time-integration
95-
integrate_const(stepper,
96-
std::make_pair(ODE_system(), ODE_jacobian()), xyz,
95+
integrate_const(stepper, std::make_pair(ODE_system(), ODE_jacobian()), xyz,
9796
0.0, 30.0, 0.01, ODE_output());
9897
#endif
9998

@@ -103,6 +102,6 @@ inline int Simulate(int argc, const char** argv) {
103102
return 0;
104103
}
105104

106-
} // namespace lorenz
105+
} // namespace lorenz
107106

108-
#endif // LORENZ_H_
107+
#endif // LORENZ_H_

demo/regulatory_networks/src/oscillator.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#ifndef OSCILLATOR_H_
1616
#define OSCILLATOR_H_
1717

18-
#include <iostream>
1918
#include <fstream>
19+
#include <iostream>
2020

2121
#ifndef __ROOTCLING__
2222
#include <boost/array.hpp>
@@ -26,8 +26,8 @@
2626
#endif
2727

2828
#ifndef __ROOTCLING__
29-
typedef boost::numeric::ublas::vector<double> b_vector_t;
30-
typedef boost::numeric::ublas::matrix<double> b_matrix_t;
29+
typedef boost::numeric::ublas::vector<double> b_vector_t;
30+
typedef boost::numeric::ublas::matrix<double> b_matrix_t;
3131
#endif
3232

3333
namespace oscillator {
@@ -43,7 +43,8 @@ struct ODE_system {
4343
};
4444

4545
struct ODE_jacobian {
46-
void operator()(const b_vector_t& x, b_matrix_t& jac, double t, b_vector_t& dfdt) const {
46+
void operator()(const b_vector_t& x, b_matrix_t& jac, double t,
47+
b_vector_t& dfdt) const {
4748
jac(0, 0) = 0.0;
4849
jac(0, 1) = 1.0;
4950
jac(1, 0) = -2.0 * mu * x[0] * x[1] - 1.0;
@@ -77,12 +78,10 @@ inline int Simulate(int argc, const char** argv) {
7778
typedef boost::numeric::odeint::rosenbrock4<double> ode_int;
7879

7980
// set-up the Rosenbrock integrator
80-
auto stepper =
81-
boost::numeric::odeint::make_dense_output<ode_int>(1e-6,1e-6);
81+
auto stepper = boost::numeric::odeint::make_dense_output<ode_int>(1e-6, 1e-6);
8282

8383
// perform the time-integration
84-
integrate_const(stepper,
85-
std::make_pair(ODE_system(), ODE_jacobian()), xy,
84+
integrate_const(stepper, std::make_pair(ODE_system(), ODE_jacobian()), xy,
8685
0.0, 500.0, 1.0e-2, ODE_output());
8786
#endif
8887

@@ -92,6 +91,6 @@ inline int Simulate(int argc, const char** argv) {
9291
return 0;
9392
}
9493

95-
} // namespace oscillator
94+
} // namespace oscillator
9695

97-
#endif // OSCILLATOR_H_
96+
#endif // OSCILLATOR_H_

demo/regulatory_networks/src/regulatory_networks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
namespace bdm {
3131

3232
inline int Simulate(int argc, const char** argv) {
33-
3433
if (sine::Simulate(argc, argv))
3534
return 1;
3635
if (lorenz::Simulate(argc, argv))

0 commit comments

Comments
 (0)