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::VERSION_FULL); \
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  */
278  { return m_MaxThreads; };
279 
280  /**
281  Sets the maximum number of threads that can be concurrently run in threaded spatial loops
282  @param[in] MaxNumThreads the number of threads
283  */
284  void OPENFLUID_SetSimulatorMaxThreads(const int& MaxNumThreads);
285 
286  /**
287  Returns a scheduling request to a single scheduling at the end
288  Return the corresponding scheduling request
289  */
292 
293  /**
294  Returns a scheduling request to never be scheduled again
295  Return the corresponding scheduling request
296  */
299 
300  /**
301  Returns a scheduling request for the default DeltaT value
302  Return the corresponding scheduling request
303  */
305  { return openfluid::base::SchedulingRequest(OPENFLUID_GetDefaultDeltaT()); };
306 
307  /**
308  Returns a scheduling request for the default DeltaT value multiplied by a factor
309  @param[in] Mult the multiplication factor
310  Return the corresponding scheduling request
311  */
313  { return openfluid::base::SchedulingRequest(Mult * OPENFLUID_GetDefaultDeltaT()); };
314 
315  /**
316  Returns a scheduling request for a given duration
317  @param[in] D a duration in seconds
318  Return the corresponding scheduling request
319  */
321  { return openfluid::base::SchedulingRequest(D); };
322 
323 
324  public:
325  /**
326  Constructor
327  */
329 
330  /**
331  Virtual destructor
332  */
333  virtual ~PluggableSimulator();
334 
335  /**
336  Internally called by the framework.
337  */
338  void initializeWare(const WareID_t& SimID,const unsigned int& MaxThreads);
339 
340  /**
341  Initializes simulator parameters of the simulator, given as a hash map. Internally called by the framework.
342  */
343  virtual void initParams(const openfluid::ware::WareParams_t& Params)=0;
344 
345  /**
346  Prepares data. Internally called by the framework.
347  */
348  virtual void prepareData()=0;
349 
350  /**
351  Checks the simulator consistency. Internally called by the framework.
352  */
353  virtual void checkConsistency()=0;
354 
355  /**
356  Internally called by the framework.
357  */
358  virtual openfluid::base::SchedulingRequest initializeRun()=0;
359 
360  /**
361  Internally called by the framework.
362  */
363  virtual openfluid::base::SchedulingRequest runStep()=0;
364 
365  /**
366  Internally called by the framework.
367  */
368  virtual void finalizeRun()=0;
369 
370 };
371 
372 
373 typedef PluggableSimulator* (*GetPluggableSimulatorBodyProc)();
374 
375 typedef SimulatorSignature* (*GetPluggableSimulatorSignatureProc)();
376 
377 
378 } } // namespaces
379 
380 
381 #endif /* __OPENFLUID_WARE_PLUGGABLESIMULATOR_HPP__ */
Definition: SchedulingRequest.hpp:56
openfluid::base::SchedulingRequest MultipliedDefaultDeltaT(const double &Mult) const
Definition: PluggableSimulator.hpp:312
Definition: MatrixValue.hpp:114
openfluid::base::SchedulingRequest Never() const
Definition: PluggableSimulator.hpp:297
unsigned long long Duration_t
Definition: DateTime.hpp:68
int OPENFLUID_GetSimulatorMaxThreads() const
Definition: PluggableSimulator.hpp:277
Definition: StringValue.hpp:91
openfluid::base::SchedulingRequest Duration(const openfluid::core::Duration_t &D) const
Definition: PluggableSimulator.hpp:320
#define OPENFLUID_API
Definition: dllexport.hpp:87
openfluid::base::SchedulingRequest DefaultDeltaT() const
Definition: PluggableSimulator.hpp:304
std::string WareID_t
Definition: TypeDefs.hpp:50
Abstract class for simulator plugin.
Definition: PluggableSimulator.hpp:105
Definition: SchedulingRequest.hpp:56
Definition: ApplicationException.hpp:47
Definition: SimulationContributorWare.hpp:50
std::string WareParamKey_t
Definition: TypeDefs.hpp:126
Definition: VectorValue.hpp:118
Definition: SchedulingRequest.hpp:52
Definition: SimulatorSignature.hpp:307
openfluid::base::SchedulingRequest AtTheEnd() const
Definition: PluggableSimulator.hpp:290
Definition: DoubleValue.hpp:102
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:130