All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PluggableSimulator.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 PluggableSimulator.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_WARE_PLUGGABLESIMULATOR_HPP__
41 #define __OPENFLUID_WARE_PLUGGABLESIMULATOR_HPP__
42 
43 
44 #include <string>
45 
46 #include <openfluid/dllexport.hpp>
49 #include <openfluid/core/TypeDefs.hpp>
53 #include <openfluid/core/Event.hpp>
58 
59 
60 // =====================================================================
61 // =====================================================================
62 
63 
64 /**
65  @deprecated This declaration is not needed anymore since version 2.1.0
66 */
67 #define DECLARE_SIMULATOR_PLUGIN
68 
69 
70 /**
71  Macro for definition of simulator hook
72  @param[in] pluginclassname The name of the class to instantiate
73 */
74 #define DEFINE_SIMULATOR_CLASS(pluginclassname) \
75  extern "C" \
76  { \
77  OPENFLUID_PLUGIN std::string WAREABIVERSION_PROC_DECL() \
78  { \
79  return std::string(openfluid::config::FULL_VERSION); \
80  } \
81  \
82  OPENFLUID_PLUGIN openfluid::ware::PluggableSimulator* WAREBODY_PROC_DECL() \
83  { \
84  return new pluginclassname(); \
85  } \
86  }
87 
88 
89 // =====================================================================
90 // =====================================================================
91 
92 
93 namespace openfluid { namespace ware {
94 
95 
96 /**
97  @brief Abstract class for simulator plugin
98 
99  Abstract class for simulator plugin interface,
100  defining the minimal structure for a simulator. \n
101  All simulators must inherit from this class.
102 
103  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
104 */
106 {
107 
108  private:
109 
110  /**
111  Pointer to the spatial graph, for internal use only
112  */
113  // TODO check here
114  // openfluid::core::SpatialGraph* mp_InternalSpatialGraph;
115 
116 
117  int m_MaxThreads;
118 
119 
120  protected:
121 
122  /**
123  Returns true if the parameter exists
124  @param[in] Params the parameters set for the simulator
125  @param[in] ParamName the name of the requested parameter
126  @return true if the parameter exists, false otherwise
127  */
128  bool OPENFLUID_IsSimulatorParameterExist(const openfluid::ware::WareParams_t& Params,
129  const openfluid::ware::WareParamKey_t& ParamName) const;
130 
131  /**
132  Returns a simulator parameter from the parameters set, as a StringValue
133  @param[in] Params the parameters set for the simulator
134  @param[in] ParamName the name of the requested parameter
135  @return the value of the requested parameter
136  */
137  openfluid::core::StringValue OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
138  const openfluid::ware::WareParamKey_t& ParamName)
139  const;
140 
141  /**
142  Gets a simulator parameter from the parameters set, as a StringValue
143  @param[in] Params the parameters set for the simulator
144  @param[in] ParamName the name of the requested parameter
145  @param[out] Val the value of the requested parameter
146  @return true if the parameter exists, false otherwise
147  */
148  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
149  const openfluid::ware::WareParamKey_t& ParamName,
150  openfluid::core::StringValue& Val) const;
151 
152  /**
153  Gets a simulator parameter from the parameters set, as a DoubleValue
154  @param[in] Params the parameters set for the simulator
155  @param[in] ParamName the name of the requested parameter
156  @param[out] Val the value of the requested parameter
157  @return true if the parameter exists, false otherwise
158  */
159  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
160  const openfluid::ware::WareParamKey_t& ParamName,
161  openfluid::core::DoubleValue& Val) const;
162 
163  /**
164  Gets a simulator parameter from the parameters set, as a VectorValue
165  @param[in] Params the parameters set for the simulator
166  @param[in] ParamName the name of the requested parameter
167  @param[out] Val the value of the requested parameter
168  @return true if the parameter exists, false otherwise
169  */
170  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
171  const openfluid::ware::WareParamKey_t& ParamName,
172  openfluid::core::VectorValue& Val) const;
173 
174  /**
175  Gets a simulator parameter from the parameters set, as a MatrixValue
176  @param[in] Params the parameters set for the simulator
177  @param[in] ParamName the name of the requested parameter
178  @param[out] Val the value of the requested parameter
179  @return true if the parameter exists, false otherwise
180  */
181  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
182  const openfluid::ware::WareParamKey_t& ParamName,
183  openfluid::core::MatrixValue& Val) const;
184 
185  /**
186  Gets a simulator parameter from the parameters set, as a double
187  @param[in] Params the parameters set for the simulator
188  @param[in] ParamName the name of the requested parameter
189  @param[out] Val the value of the requested parameter
190  @return true if the parameter exists, false otherwise
191  */
192  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
193  const openfluid::ware::WareParamKey_t& ParamName,
194  double& Val) const;
195 
196  /**
197  Gets a simulator parameter value from the parameters set, as a long int
198  @param[in] Params the parameters set for the simulator
199  @param[in] ParamName the name of the requested parameter
200  @param[out] Val the value of the requested parameter
201  @return true if the parameter exists, false otherwise
202  */
203  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
204  const openfluid::ware::WareParamKey_t& ParamName,
205  long& Val) const;
206 
207  /**
208  Gets a simulator parameter from the parameters set, as a float
209  @param[in] Params the parameters set for the simulator
210  @param[in] ParamName the name of the requested parameter
211  @param[out] Val the value of the requested parameter
212  @return true if the parameter exists, false otherwise
213  */
214  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
215  const openfluid::ware::WareParamKey_t& ParamName,
216  float& Val) const;
217 
218  /**
219  Gets a simulator parameter value from the parameters set, as an int
220  @param[in] Params the parameters set for the simulator
221  @param[in] ParamName the name of the requested parameter
222  @param[out] Val the value of the requested parameter
223  @return true if the parameter exists, false otherwise
224  */
225  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
226  const openfluid::ware::WareParamKey_t& ParamName,
227  int& Val) const;
228 
229  /**
230  Gets a simulator parameter value from the parameters set, as a string
231  @param[in] Params the parameters set for the simulator
232  @param[in] ParamName the name of the requested parameter
233  @param[out] Val the value of the requested parameter
234  @return true if the parameter exists, false otherwise
235  */
236  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
237  const openfluid::ware::WareParamKey_t& ParamName,
238  std::string& Val) const;
239 
240  /**
241  Gets a simulator parameter vector of values from the parameters set, as a vector of strings
242  @param[in] Params the parameters set for the simulator
243  @param[in] ParamName the name of the requested parameter
244  @param[out] Vals the vector of values of the requested parameter
245  @return true if the parameter exists, false otherwise
246  */
247  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
248  const openfluid::ware::WareParamKey_t& ParamName,
249  std::vector<std::string>& Vals) const;
250 
251  /**
252  Gets a simulator parameter vector of values from the parameters set, as a vector of doubles
253  @param[in] Params the parameters set for the simulator
254  @param[in] ParamName the name of the requested parameter
255  @param[out] Vals the vector of values of the requested parameter
256  @return true if the parameter exists, false otherwise
257  */
258  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
259  const openfluid::ware::WareParamKey_t& ParamName,
260  std::vector<double>& Vals) const;
261 
262  /**
263  Gets a simulator parameter vector of values from the parameters set, as a vector of long ints
264  @param[in] Params the parameters set for the simulator
265  @param[in] ParamName the name of the requested parameter
266  @param[out] Vals the vector of values of the requested parameter
267  @return true if the parameter exists, false otherwise
268  */
269  bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
270  const openfluid::ware::WareParamKey_t& ParamName,
271  std::vector<long>& Vals) const;
272 
273  /**
274  Returns the maximum number of threads that can be concurrently run in threaded spatial loops
275  @return the number of threads
276  */
277  inline int OPENFLUID_GetSimulatorMaxThreads() const { return m_MaxThreads; };
278 
279  /**
280  Sets the maximum number of threads that can be concurrently run in threaded spatial loops
281  @param[in] MaxNumThreads the number of threads
282  */
283  void OPENFLUID_SetSimulatorMaxThreads(const int& MaxNumThreads);
284 
285 
288 
291 
293  { return openfluid::base::SchedulingRequest(OPENFLUID_GetDefaultDeltaT()); };
294 
296  { return openfluid::base::SchedulingRequest(Mult * OPENFLUID_GetDefaultDeltaT()); };
297 
299  { return openfluid::base::SchedulingRequest(D); };
300 
301 
302  public:
303  /**
304  Constructor
305  */
307 
308  /**
309  Virtual destructor
310  */
311  virtual ~PluggableSimulator();
312 
313  /**
314  Internally called by the framework.
315  */
316  void initializeWare(const WareID_t& SimID,const unsigned int& MaxThreads);
317 
318  /**
319  Initializes simulator parameters of the simulator, given as a hash map. Internally called by the framework.
320  */
321  virtual void initParams(const openfluid::ware::WareParams_t& Params)=0;
322 
323  /**
324  Prepares data. Internally called by the framework.
325  */
326  virtual void prepareData()=0;
327 
328  /**
329  Checks the simulator consistency. Internally called by the framework.
330  */
331  virtual void checkConsistency()=0;
332 
333  /**
334  Internally called by the framework.
335  */
336  virtual openfluid::base::SchedulingRequest initializeRun()=0;
337 
338  /**
339  Internally called by the framework.
340  */
341  virtual openfluid::base::SchedulingRequest runStep()=0;
342 
343  /**
344  Internally called by the framework.
345  */
346  virtual void finalizeRun()=0;
347 
348 };
349 
350 
351 typedef PluggableSimulator* (*GetPluggableSimulatorBodyProc)();
352 
353 typedef SimulatorSignature* (*GetPluggableSimulatorSignatureProc)();
354 
355 
356 } } // namespaces
357 
358 
359 #endif /* __OPENFLUID_WARE_PLUGGABLESIMULATOR_HPP__ */
Definition: VectorValue.hpp:118
unsigned long long Duration_t
Definition: DateTime.hpp:68
std::string WareParamKey_t
Definition: TypeDefs.hpp:89
openfluid::base::SchedulingRequest MultipliedDefaultDeltaT(const double &Mult) const
Definition: PluggableSimulator.hpp:295
Definition: SimulationContributorWare.hpp:50
Definition: SchedulingRequest.hpp:52
openfluid::base::SchedulingRequest Never() const
Definition: PluggableSimulator.hpp:289
Definition: DoubleValue.hpp:102
Definition: SchedulingRequest.hpp:56
openfluid::base::SchedulingRequest Duration(const openfluid::core::Duration_t &D) const
Definition: PluggableSimulator.hpp:298
Definition: StringValue.hpp:91
int OPENFLUID_GetSimulatorMaxThreads() const
Definition: PluggableSimulator.hpp:277
openfluid::base::SchedulingRequest AtTheEnd() const
Definition: PluggableSimulator.hpp:286
openfluid::base::SchedulingRequest DefaultDeltaT() const
Definition: PluggableSimulator.hpp:292
Abstract class for simulator plugin.
Definition: PluggableSimulator.hpp:105
Definition: MatrixValue.hpp:114
#define OPENFLUID_API
Definition: dllexport.hpp:87
Definition: SimulatorSignature.hpp:307
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:93
Definition: SchedulingRequest.hpp:56
std::string WareID_t
Definition: TypeDefs.hpp:50