VPTissue Reference Manual
Sim.h
Go to the documentation of this file.
1 #ifndef SIMPT_SIM_H_
2 #define SIMPT_SIM_H_
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include "CoreData.h"
23 #include "bio/Mesh.h"
24 #include "math/RandomEngine.h"
25 #include "math/RandomEngineType.h"
27 #include "sim/event/SimEvent.h"
28 #include "sim/CoreData.h"
29 #include "sim/SimState.h"
30 #include "SimInterface.h"
31 #include "TimeSlicer.h"
32 
34 #include "util/misc/Subject.h"
35 
36 #include <boost/property_tree/ptree_fwd.hpp>
37 #include <functional>
38 #include <random>
39 #include <string>
40 #include <thread>
41 #include <mutex>
42 
43 namespace SimPT_Sim {
44 
45 class TimeSlicer;
46 
51  public SimPT_Sim::Util::Subject<SimPT_Sim::Event::SimEvent, std::weak_ptr<const void>>,
53 {
54 public:
56  Sim();
57 
59  Sim(const Sim& other) =delete;
60 
62  Sim& operator=(const Sim& other);
63 
65  virtual ~Sim();
66 
68  CoreData& GetCoreData() override final { return m_cd; }
69 
71  const boost::property_tree::ptree& GetParameters() const;
72 
74  std::string GetProjectName() const;
75 
77  std::string GetRunDate() const;
78 
80  int GetSimStep() const;
81 
83  double GetSimTime() const;
84 
86  SimState GetState() const;
87 
89  std::string GetStatusMessage() const;
90 
92  Timings GetTimings() const;
93 
96  void Initialize(const boost::property_tree::ptree& pt);
97 
100  void Initialize(const SimState& sim_state);
101 
103  bool IsAtTermination() const;
104 
106  bool IsStationary() const;
107 
109  void Reinitialize(const boost::property_tree::ptree& p);
110 
112  void ResetTimings();
113 
115  std::unique_ptr<TimeSlicer> TimeSlicing();
116 
118  void TimeStep();
119 
121  boost::property_tree::ptree ToPtree() const;
122 
123 private:
125  friend class TimeSlicer;
126 
128  void TimeSliceGo(const std::lock_guard<std::mutex>&, double time_slice, SimPhase phase = SimPhase::NONE);
129 
131  void TimeSliceSetup(const std::lock_guard<std::mutex>&);
132 
134  void TimeSliceWrapup(const std::lock_guard<std::mutex>&);
135 
136 private:
138  bool RandomEngineInitialize(const boost::property_tree::ptree& pt);
139 
141  bool RandomEngineInitialize(const SimState& sim_state);
142 
143 private:
144  bool m_is_stationary;
145  CoreData m_cd;
146  std::string m_project_name;
147  std::string m_run_date;
148  TimeEvolverComponent m_time_evolver;
149  std::mutex m_timestep_mutex;
150  Timings m_timings;
151 };
152 
153 } // namespace
154 
155 #endif // end_of_include_guard
void TimeStep()
Definition: Sim.cpp:360
Simulator interface.
Definition for SimEvent.
Core data with mesh, parameters, random engine and time data.
Definition: CoreData.h:38
bool IsStationary() const
Definition: Sim.cpp:222
Core data used during model execution.
Simulator: mesh & parameters, model & algorithms.
Definition: Sim.h:50
Interface of Model Components.
std::string GetRunDate() const
Definition: Sim.cpp:107
Sim()
Constructor does almost no initialization work (.
Definition: Sim.cpp:65
Interface of RandomEngine.
virtual ~Sim()
Destructor is virtual (.
Definition: Sim.cpp:93
std::unique_ptr< TimeSlicer > TimeSlicing()
Return a SimTimeSlicer to proceed through a time step using time slices.
Definition: Sim.cpp:355
double GetSimTime() const
Definition: Sim.cpp:117
Namespace for the core simulator.
Interface/Implementation of Subject.
void Initialize(const boost::property_tree::ptree &pt)
Initialize with full configuration (global info, parameters, random engine, mesh) i...
Simulator: mesh & parameters, model & algorithms.
Definition: TimeSlicer.h:33
Header for SimState.
std::string GetProjectName() const
Definition: Sim.cpp:102
Interface of RandomEngineType.
std::string GetStatusMessage() const
Return a status message (time, steps, cellcount).
Definition: Sim.cpp:141
Sim & operator=(const Sim &other)
Assignment operator rebuilds copy of mesh.
Definition: Sim.cpp:74
void Reinitialize(const boost::property_tree::ptree &p)
Definition: Sim.cpp:310
boost::property_tree::ptree ToPtree() const
Serialize into ptree.
Definition: Sim.cpp:368
Contains the state of the whole Simulator at a given simulation step.
Definition: SimState.h:33
Interface for Timeable.
bool IsAtTermination() const
Definition: Sim.cpp:202
const boost::property_tree::ptree & GetParameters() const
Definition: Sim.cpp:97
Subject in Observer pattern.
Definition: Subject.h:34
Simulator interface.
Definition: SimInterface.h:36
int GetSimStep() const
Definition: Sim.cpp:112
Timings GetTimings() const
Definition: Sim.cpp:151
void ResetTimings()
Resets the execution timings.
Definition: Sim.cpp:316
CoreData & GetCoreData() override final
Definition: Sim.h:68
Time slice propagation.
std::function< std::tuple< SimTimingTraits::CumulativeTimings, bool >(double, SimPhase)> TimeEvolverComponent
Time Evolver component interface.
see the online C++11 documentation
SimState GetState() const
Provide sim state in format suitable for i/o.
Definition: Sim.cpp:122
Interface for Mesh.