Documentation for OpenFLUID 2.2.0
Engine.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file Engine.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 */
38 
39 
40 #ifndef __OPENFLUID_MACHINE_ENGINE_HPP__
41 #define __OPENFLUID_MACHINE_ENGINE_HPP__
42 
43 
44 #include <memory>
45 
46 #include <openfluid/dllexport.hpp>
48 #include <openfluid/core/TypeDefs.hpp>
50 
51 
52 namespace openfluid {
53 namespace base {
54 class SimulationStatus;
55 }
56 namespace core {
57 class Value;
58 class DateTime;
59 }
60 }
61 
62 
63 namespace openfluid { namespace machine {
64 
65 class ModelInstance;
66 class MonitoringInstance;
67 class MachineListener;
68 class SimulationBlob;
69 
70 
71 // =====================================================================
72 // =====================================================================
73 
74 
75 /**
76  Computation engine class
77 */
79 {
80 
81  private:
82 
83  SimulationBlob& m_SimulationBlob;
84 
86 
87  MachineListener* mp_MachineListener;
88 
89  ModelInstance& m_ModelInstance;
90 
91  MonitoringInstance& m_MonitoringInstance;
92 
93  std::unique_ptr<openfluid::base::SimulationLogger> mp_SimLogger;
94 
95 
96  void checkSimulationVarsProduction(int ExpectedVarsCount);
97 
98  void checkParametersConsistency();
99 
100  void checkModelConsistency();
101 
102  void checkAttributesConsistency();
103 
104  void checkExtraFilesConsistency();
105 
106  void checkExistingVariable(const openfluid::core::VariableName_t& VarName,
107  const openfluid::core::Value::Type& VarType,
108  const openfluid::core::UnitsClass_t& ClassName,
109  const std::string& SimulatorID);
110 
111  void createVariable(const openfluid::core::VariableName_t& VarName,
112  const openfluid::core::Value::Type& VarType,
113  const openfluid::core::UnitsClass_t& ClassName,
114  bool UpdateMode,
115  const std::string& SimulatorID);
116 
117  void checkExistingAttribute(const openfluid::core::AttributeName_t AttrName,
118  const openfluid::core::UnitsClass_t ClassName,
119  const std::string& SimulatorID);
120 
121  void createAttribute(const openfluid::core::AttributeName_t AttrName,
122  const openfluid::core::UnitsClass_t ClassName,
123  const std::string& SimulatorID);
124 
125  void prepareOutputDir();
126 
127 
128  public:
129 
130  Engine() = delete;
131 
132  /**
133  Constructor
134  */
136  ModelInstance& MInstance, MonitoringInstance& OLInstance,
138 
139  /**
140  Destructor
141  */
143  { }
144 
146  const openfluid::core::Duration_t DeltaT)
147  {
148  return (Duration/DeltaT)+2;
149  }
150 
151  /**
152  Initializes the simulation engine
153  */
154  void initialize();
155 
156  /**
157  Executes the initParams() method of each item of the model
158  */
159  void initParams();
160 
161  /**
162  Executes the prepareData() method of each item of the model
163  */
164  void prepareData();
165 
166  /**
167  Executes the checkConsistency() method of each item of the model
168  */
170 
171  /**
172  Executes the initializeRun(), runStep() and finalizeRun() methods of each item of the model
173  */
174  void run();
175 
176  /**
177  Finalizes the simulation engine
178  */
179  void finalize();
180 
182  {
183  return mp_SimStatus;
184  }
185 
187  {
188  return &m_SimulationBlob;
189  }
190 
192  {
193  return mp_MachineListener;
194  }
195 
197  {
198  return &m_ModelInstance;
199  }
200 
201  unsigned int getWarningsCount() const
202  {
203  return mp_SimLogger->getWarningsCount();
204  }
205 };
206 
207 
208 } } //namespaces
209 
210 
211 #endif /* __OPENFLUID_MACHINE_ENGINE_HPP__ */
212 
Definition: SimulationStatus.hpp:56
Type
Definition: Value.hpp:66
Definition: Engine.hpp:79
SimulationBlob * simulationBlob()
Definition: Engine.hpp:186
MachineListener * machineListener()
Definition: Engine.hpp:191
unsigned int getWarningsCount() const
Definition: Engine.hpp:201
ModelInstance * modelInstance()
Definition: Engine.hpp:196
Engine(SimulationBlob &SimBlob, ModelInstance &MInstance, MonitoringInstance &OLInstance, openfluid::machine::MachineListener *MachineListener)
const openfluid::base::SimulationStatus * simulationStatus()
Definition: Engine.hpp:181
~Engine()
Definition: Engine.hpp:142
static std::size_t computeValuesBuffersDefaultSize(const openfluid::core::Duration_t Duration, const openfluid::core::Duration_t DeltaT)
Definition: Engine.hpp:145
Definition: MachineListener.hpp:55
Definition: ModelInstance.hpp:66
Definition: MonitoringInstance.hpp:59
Definition: SimulationBlob.hpp:54
#define OPENFLUID_API
Definition: dllexport.hpp:86
std::uint64_t Duration_t
Definition: TypeDefs.hpp:312
std::string VariableName_t
Definition: TypeDefs.hpp:131
std::string UnitsClass_t
Definition: TypeDefs.hpp:98
std::string AttributeName_t
Definition: TypeDefs.hpp:117
Definition: ApplicationException.hpp:47