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