29 #include <boost/circular_buffer.hpp>
36 namespace TimeEvolver {
49 assert( cd.
Check() &&
"CoreData not ok.");
52 const auto& p = m_cd.m_parameters;
53 m_mc_cell_step_size = p->get<
double>(
"cell_mechanics.mc_cell_stepsize");
55 m_mc_retry_limit = p->get<
unsigned int>(
"cell_mechanics.mc_retry_limit");
56 m_mc_sliding_window = p->get<
unsigned int>(
"cell_mechanics.mc_sliding_window");
57 m_mc_step_size = p->get<
double>(
"cell_mechanics.mc_stepsize");
58 m_mc_sweep_limit = p->get<
double>(
"cell_mechanics.mc_sweep_limit");
59 m_mc_temperature = p->get<
double>(
"cell_mechanics.mc_temperature");
60 m_stationarity_check = p->get<
bool>(
"termination.stationarity_check");
62 const double abs_tol = abs(p->get<
double>(
"cell_mechanics.mc_abs_tolerance"));
63 m_mc_abs_tolerance = abs_tol;
64 const double rel_tol = abs(p->get<
double>(
"cell_mechanics.mc_rel_tolerance"));
65 const bool stringent = p->get<
bool>(
"cell_mechanics.mc_stringent_tolerance",
false);
67 m_within_tolerance = [abs_tol, rel_tol](
double dh,
double e) {
68 return (dh <= 0.0) && (abs(dh) < min(abs_tol, abs(e * rel_tol)));
71 m_within_tolerance = [abs_tol, rel_tol](
double dh,
double e) {
72 return (dh <= 0.0) && (abs(dh) < max(abs_tol, abs(e * rel_tol)));
77 std::tuple<SimTimingTraits::CumulativeTimings, bool>
Grow::operator()(
double, SimPhase)
89 const unsigned int nodes_inserted = node_inserter.
InsertNodes();
96 double temperature = m_mc_temperature;
97 const double alpha_temperature = 0.95;
101 boost::circular_buffer<double> cb(m_mc_sliding_window);
102 double mean_dh = 0.0;
103 unsigned int sweep_count = 0U;
104 unsigned int retry_count = 0U;
105 unsigned int total_move_down_count = 0U;
137 total_move_down_count += info.down_count;
138 cb.push_back(info.down_dh + info.up_dh);
139 mean_dh = std::accumulate(cb.begin(), cb.end(), 0.0) / cb.size();
143 retry_count = mean_dh < -abs(m_mc_abs_tolerance) ? 0U : retry_count;
152 go_on = (sweep_count < m_mc_sliding_window) || (! m_within_tolerance(mean_dh, e_tissue_before))
153 || (mean_dh > 0.0 && retry_count < m_mc_retry_limit);
156 temperature *= alpha_temperature;
158 }
while (go_on && sweep_count < m_mc_sweep_limit);
160 const bool is_stationary = (nodes_inserted == 0U) && (total_move_down_count == 0U);
167 return make_tuple(timings, is_stationary);
void Initialize(const CoreData &cd)
Initializes based on values in property tree.
Core data with mesh, parameters, random engine and time data.
void Initialize(const CoreData &cd)
Initialize or re-initialize.
Namespace for miscellaneous utilities.
double GetTissueEnergy() const
Get current energy for the whole tissue.
std::string GetName() const
Return name of this stopwatch.
MetropolisInfo SweepOverNodes(double step_size, double temperature)
Sweep over all nodes, do metropolis move for each of them.
Cell mechanics by displacement and insertion of nodes.
Namespace for components of the Default model group.
std::tuple< SimTimingTraits::CumulativeTimings, bool > operator()(double time_slice=0.0, SimPhase phase=SimPhase::NONE)
Take a time evolution step.
Utility class to record durations in a cumulative manner.
Insertion of nodes in existing edges (contributes to the cell mechanics).
T::duration Get() const
Returns the accumulated value without altering the stopwatch state.
void Initialize(const CoreData &cd)
Initializes based on values in property tree.
unsigned int InsertNodes()
Insert nodes in those edges that have been stretched.
Provides a stopwatch interface to time: it accumulates time between start/stop pairs.
Interface for NodeInserter.
Time evolver for Grow only.
void Record(const std::string &name, const std::chrono::duration< R, P > &duration)
Record the duration for the given name.
Grow(const CoreData &cd)
Initializing constructor.
Information gathered to evaluat effects of Metropolis Algorithm.
bool Check() const
Verify all pointers non-null.