Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions demo/analytic_continuum/src/continuum_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace bdm {
class AnalyticContinuum final : public ScalarField {
public:
AnalyticContinuum() = default;
explicit AnalyticContinuum(const TRootIOCtor *) {}
~AnalyticContinuum() final = default;

void Initialize() final {}
Expand Down Expand Up @@ -58,8 +57,6 @@ class AnalyticContinuum final : public ScalarField {
return {0, 0, 0};
};

BDM_CLASS_DEF_OVERRIDE(AnalyticContinuum, 1); // NOLINT

private:
real_t time_ = 0.0;
};
Expand Down
2 changes: 1 addition & 1 deletion demo/analytic_continuum/src/my_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace bdm {
/// A simple agent that can sense the continuum value and stores the value in
/// a member variable.
class ContinuumRetrieverAgent : public SphericalAgent {
BDM_AGENT_HEADER(ContinuumRetrieverAgent, SphericalAgent, 1);
BDM_AGENT_HEADER(ContinuumRetrieverAgent, SphericalAgent);

public:
ContinuumRetrieverAgent() {}
Expand Down
2 changes: 1 addition & 1 deletion demo/analytic_continuum/src/my_behavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace bdm {
/// Behavior that allows agents to sense the continuum value and stores the
/// value in its member variable.
struct RetrieveContinuumValue : public Behavior {
BDM_BEHAVIOR_HEADER(RetrieveContinuumValue, Behavior, 1);
BDM_BEHAVIOR_HEADER(RetrieveContinuumValue, Behavior);

RetrieveContinuumValue() {}
virtual ~RetrieveContinuumValue() {}
Expand Down
2 changes: 1 addition & 1 deletion demo/cell_division_enhanced/src/cell_division_enhanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ inline int signum(const T& x) {
namespace bdm {

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

public:
MyCell() : Cell() { UpdateVolume(); }
Expand Down
6 changes: 3 additions & 3 deletions demo/flocking/src/boid.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ real_t FluctuateCoefficient(real_t coefficient, real_t fluctuation_strength,
////////////////////////////////////////////////////////////////////////////////

class Boid : public Agent {
BDM_AGENT_HEADER(Boid, Agent, 1);
BDM_AGENT_HEADER(Boid, Agent);

public:
Boid() {}
Expand Down Expand Up @@ -171,13 +171,13 @@ class Boid : public Agent {
////////////////////////////////////////////////////////////////////////////////

struct Flocking : public Behavior {
BDM_BEHAVIOR_HEADER(Flocking, Behavior, 1);
BDM_BEHAVIOR_HEADER(Flocking, Behavior);

void Run(Agent* agent) override;
};

struct RandomPerturbation : public Behavior {
BDM_BEHAVIOR_HEADER(RandomPerturbation, Behavior, 1);
BDM_BEHAVIOR_HEADER(RandomPerturbation, Behavior);

public:
RandomPerturbation(real_t v = 1) : velocity_(v) { AlwaysCopyToNew(); }
Expand Down
6 changes: 3 additions & 3 deletions demo/mars/src/CelestialObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace astrophysics {
// creating the custom agent that
// defines celestial objects
class CelestialObject : public Cell {
BDM_AGENT_HEADER(CelestialObject, Cell, 1);
BDM_AGENT_HEADER(CelestialObject, Cell);

public:
// constructors
Expand Down Expand Up @@ -51,7 +51,7 @@ class CelestialObject : public Cell {

// Planet subclass
class Planet : public CelestialObject {
BDM_AGENT_HEADER(Planet, CelestialObject, 1);
BDM_AGENT_HEADER(Planet, CelestialObject);

public:
Planet() : CelestialObject() {}
Expand All @@ -65,7 +65,7 @@ class Planet : public CelestialObject {

// Satellite subclass
class Satellite : public CelestialObject {
BDM_AGENT_HEADER(Satellite, CelestialObject, 1);
BDM_AGENT_HEADER(Satellite, CelestialObject);

public:
Satellite() : CelestialObject() {}
Expand Down
2 changes: 1 addition & 1 deletion demo/monolayer_growth/src/behaviours.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace bdm {

// Define growth behaviour
struct GrowthAndCellCycle : public Behavior {
BDM_BEHAVIOR_HEADER(GrowthAndCellCycle, Behavior, 1);
BDM_BEHAVIOR_HEADER(GrowthAndCellCycle, Behavior);

GrowthAndCellCycle() { AlwaysCopyToNew(); }
virtual ~GrowthAndCellCycle() {}
Expand Down
6 changes: 5 additions & 1 deletion demo/monolayer_growth/src/cell_cell_force.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

namespace bdm {

namespace {
constexpr real_t kCoincidentCenterTolerance = 1e-8;
} // namespace

/// Custom force. Changed adhesive and repulsive parameters compared to standard
/// force to achieve quick separation of mother and daughter cells after
/// division.
Expand Down Expand Up @@ -52,7 +56,7 @@ Real4 CellCellForce::Calculate(const Agent* lhs, const Agent* rhs) const {
}
// to avoid a division by 0 if the centers are (almost) at the same
// location
if (center_distance < 0.00000001) {
if (center_distance < kCoincidentCenterTolerance) {
auto* random = Simulation::GetActive()->GetRandom();
auto force2on1 = random->template UniformArray<3>(-3.0, 3.0);
return {force2on1[0], force2on1[1], force2on1[2], 0};
Expand Down
2 changes: 1 addition & 1 deletion demo/monolayer_growth/src/cycling_cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum CellState { kG1, kS, kG2, kM };

class CyclingCell : public Cell { // our object extends the Cell object
// create the header with our new data member
BDM_AGENT_HEADER(CyclingCell, Cell, 1);
BDM_AGENT_HEADER(CyclingCell, Cell);

public:
CyclingCell() {}
Expand Down
60 changes: 19 additions & 41 deletions demo/monolayer_growth/src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
#ifndef EVALUATE_H_
#define EVALUATE_H_

#include <TAxis.h>
#include <TLegend.h>
#include <TMultiGraph.h>
#include <cmath>
#include <fstream>
#include <string>
#include <vector>
#include "biodynamo.h"
#include "sim_param.h"

using namespace bdm::experimental;

namespace bdm {

inline void SetupResultCollection(Simulation* sim) {
Expand Down Expand Up @@ -56,46 +53,27 @@ inline void SetupResultCollection(Simulation* sim) {
ts->AddCollector("env_dims", get_env_dims, get_time);
}

inline void ExportResults(const bool plot_legend = true,
const std::string& filename = "result") {
// Prerequisites
inline void ExportResults(const std::string& filename = "result.csv") {
const std::string folder = Simulation::GetActive()->GetOutputDir();
auto* ts = Simulation::GetActive()->GetTimeSeries();
TimeSeries allts;
std::vector<real_t> times, sizes;

// Add simulated data
allts.Add(*ts, Concat("i", 0));
times = ts->GetXValues("env_dims");
sizes = ts->GetYValues("env_dims");

// Add experimental data from Figure 1 from Drasdo and Hoehme (2005)
allts.Add("experimental_data",
{336 / 24., 386 / 24., 408 / 24., 481 / 24., 506 / 24., 646 / 24.},
{1140, 1400, 1590, 2040, 2250, 3040});

// Initialize line graph
LineGraph lg(&allts, "", "Time [days]", "2D Monolayer size (um)", plot_legend,
nullptr, 350, 250);

// Add simulated data
lg.Add(Concat("env_dims-i", 0), "Sim data ", "LP", kBlue, 0.2, kSolid, 2,
kBlue, 0.7, kFullCircle, 0.5);

// Add style for exp data
lg.Add("experimental_data", "Exp data ", "LP", kBlack, 0.2, kSolid, 2, kBlack,
0.7, kFullCircle, 0.5);

// Add legend
if (plot_legend) {
lg.SetLegendPosNDC(0.1, 0.7, 0.3, 0.9);
const auto& times = ts->GetXValues("env_dims");
const auto& sizes = ts->GetYValues("env_dims");
std::ofstream output(Concat(folder, "/", filename));
output << "source,time_days,size_um\n";
for (size_t i = 0; i < times.size(); ++i) {
output << "simulation," << times[i] << ',' << sizes[i] << '\n';
}

// Save plot
lg.SaveAs(Concat(folder, "/", filename), {".svg", ".png"});

// Save data
ts->SaveJson(Concat(folder, "/monolayer_growth.json"));
constexpr real_t kHoursPerDay = 24.0;
const std::vector<real_t> experimental_times = {
336 / kHoursPerDay, 386 / kHoursPerDay, 408 / kHoursPerDay,
481 / kHoursPerDay, 506 / kHoursPerDay, 646 / kHoursPerDay};
const std::vector<real_t> experimental_sizes = {1140, 1400, 1590,
2040, 2250, 3040};
for (size_t i = 0; i < experimental_times.size(); ++i) {
output << "experiment," << experimental_times[i] << ','
<< experimental_sizes[i] << '\n';
}
}

} // namespace bdm
Expand Down
2 changes: 1 addition & 1 deletion demo/newtons_law_test/src/CelestialObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace astrophysics {
// creating the custom agent that
// defines celestial objects
class CelestialObject : public Cell {
BDM_AGENT_HEADER(CelestialObject, Cell, 1);
BDM_AGENT_HEADER(CelestialObject, Cell);

public:
// constructors
Expand Down
7 changes: 7 additions & 0 deletions demo/parameters/src/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ struct SimParam : public ParamGroup {

real_t foo = 3.14;
int bar = -42;

protected:
void AssignFromConfig(
const std::shared_ptr<cpptoml::table>& config) override {
BDM_ASSIGN_CONFIG_VALUE(foo, "parameters.foo");
BDM_ASSIGN_CONFIG_VALUE(bar, "parameters.bar");
}
};

inline int Simulate(int argc, const char** argv) {
Expand Down
4 changes: 2 additions & 2 deletions demo/pyramidal_cell/src/pyramidal_cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace bdm {
enum Substances { kApical, kBasal };

struct ApicalDendriteGrowth : public Behavior {
BDM_BEHAVIOR_HEADER(ApicalDendriteGrowth, Behavior, 1);
BDM_BEHAVIOR_HEADER(ApicalDendriteGrowth, Behavior);
ApicalDendriteGrowth() { AlwaysCopyToNew(); }
virtual ~ApicalDendriteGrowth() {}

Expand Down Expand Up @@ -83,7 +83,7 @@ struct ApicalDendriteGrowth : public Behavior {
};

struct BasalDendriteGrowth : public Behavior {
BDM_BEHAVIOR_HEADER(BasalDendriteGrowth, Behavior, 1);
BDM_BEHAVIOR_HEADER(BasalDendriteGrowth, Behavior);
BasalDendriteGrowth() { AlwaysCopyToNew(); }
virtual ~BasalDendriteGrowth() {}

Expand Down
6 changes: 0 additions & 6 deletions demo/regulatory_networks/src/bdm_ex1.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace bdm {

enum Substances { kProtein };

#ifndef __ROOTCLING__
struct ODE_system {
const std::map<std::string, DiffusionGrid*>& mdg;
const std::vector<real_t> param;
Expand Down Expand Up @@ -80,8 +79,6 @@ struct ODE_output {
std::clog << std::endl;
}
};
#endif

namespace ex1 {

inline int Simulate(int argc, const char** argv) {
Expand Down Expand Up @@ -136,15 +133,12 @@ inline int Simulate(int argc, const char** argv) {
c->SetAdherence(0.4);
c->SetMass(1.0);
c->SetPosition(xyz);
#ifndef __ROOTCLING__
c->AddBehavior(new RegulatoryNetwork(
dt_RN, 1000, {1., 5., 7.},
// ODE_solver::Euler,
// ODE_solver::Rosenbrock,
ODE_solver::RungeKutta, ODE_system(dg_map, {0.2, 0.1, 3.0}),
ODE_jacobian(dg_map, {0.2, 0.1, 3.0}), ODE_output()));
#endif

sim.GetExecutionContext()->AddAgent(c);
}

Expand Down
24 changes: 11 additions & 13 deletions demo/regulatory_networks/src/bdm_ex2.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace bdm {

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

public:
MyCell() {}
Expand All @@ -42,12 +42,20 @@ class MyCell : public Cell {
real_t GetTrail() const { return trail_; }
void SetTrail(real_t t) { trail_ += t; }

bool GetVisualizationData(const std::string& name,
VisualizationData* values) const override {
if (name == "trail_") {
*values = std::vector<real_t>{trail_};
return true;
}
return Base::GetVisualizationData(name, values);
}

private:
/// keep track of the trail of the agent
real_t trail_;
};

#ifndef __ROOTCLING__
struct Lorenz_rhs_ {
void operator()(const b_vector_t& x, b_vector_t& dxdt, double t,
Agent* agent) const {
Expand Down Expand Up @@ -91,18 +99,14 @@ struct Lorenz_out_ {
std::clog << std::endl;
}
};
#endif

class Trajectory : public RegulatoryNetwork {
BDM_BEHAVIOR_HEADER(Trajectory, RegulatoryNetwork, 1);
BDM_BEHAVIOR_HEADER(Trajectory, RegulatoryNetwork);

public:
Trajectory() { AlwaysCopyToNew(); }
#ifndef __ROOTCLING__
Trajectory(real_t dt, int n_dt, const std::vector<real_t>& x)
: RegulatoryNetwork(dt, n_dt, x, ODE_solver::Rosenbrock, Lorenz_rhs_(),
Lorenz_jac_(), Lorenz_out_()) {}
#endif
virtual ~Trajectory() = default;

void Initialize(const NewAgentEvent& event) override {
Expand All @@ -112,7 +116,6 @@ class Trajectory : public RegulatoryNetwork {
void Run(Agent* agent) override {
Base::Run(agent);

#ifndef __ROOTCLING__
Real3 xyz;
for (int i = 0; i < 3; i++)
xyz[i] = this->GetSpecie(i);
Expand All @@ -126,7 +129,6 @@ class Trajectory : public RegulatoryNetwork {
} else {
Log::Fatal("Trajectory::Run", "agent is not of 'MyCell' type");
}
#endif
}
};

Expand Down Expand Up @@ -164,11 +166,7 @@ inline int Simulate(int argc, const char** argv) {
MyCell* c = new MyCell();
c->SetDiameter(1.0);
c->SetPosition(xyz);
#ifndef __ROOTCLING__
c->AddBehavior(new Trajectory(dt_RN, 222, {xyz[0], xyz[1], xyz[2]}));
#else
c->AddBehavior(new Trajectory());
#endif

sim.GetExecutionContext()->AddAgent(c);
}
Expand Down
Loading
Loading