Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
PluggableSimulator.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
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@inra.fr>
37 */
38
39
40#ifndef __OPENFLUID_WARE_PLUGGABLESIMULATOR_HPP__
41#define __OPENFLUID_WARE_PLUGGABLESIMULATOR_HPP__
42
43
44#include <string>
45
48#include <openfluid/core/TypeDefs.hpp>
57
58
59// =====================================================================
60// =====================================================================
61
62
63/**
64 @deprecated This declaration is not needed anymore since version 2.1.0
65*/
66#define DECLARE_SIMULATOR_PLUGIN
67
68
69/**
70 Macro for definition of simulator hook
71 @param[in] pluginclassname The name of the class to instantiate
72*/
73#define DEFINE_SIMULATOR_CLASS(pluginclassname) \
74 extern "C" \
75 { \
76 OPENFLUID_PLUGIN const std::string* WAREABIVERSION_PROC_DECL() \
77 { \
78 return new std::string(openfluid::config::VERSION_FULL); \
79 } \
80 \
81 OPENFLUID_PLUGIN openfluid::ware::PluggableSimulator* WAREBODY_PROC_DECL() \
82 { \
83 return new pluginclassname(); \
84 } \
85 }
86
87
88// =====================================================================
89// =====================================================================
90
91
92namespace openfluid { namespace ware {
93
94
95/**
96 @brief Abstract class for simulator plugin
97
98 Abstract class for simulator plugin interface,
99 defining the minimal structure for a simulator. \n
100 All simulators must inherit from this class.
101
102 @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
103*/
105{
106
107 private:
108
109 /**
110 Pointer to the spatial graph, for internal use only
111 */
112 // TODO check here
113 // openfluid::core::SpatialGraph* mp_InternalSpatialGraph;
114
115
116 int m_MaxThreads;
117
118
119 protected:
120
121 /**
122 Returns true if the parameter exists
123 @param[in] Params the parameters set for the simulator
124 @param[in] ParamName the name of the requested parameter
125 @return true if the parameter exists, false otherwise
126 */
128 const openfluid::ware::WareParamKey_t& ParamName) const;
129
130 /**
131 Returns 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 @return the value of the requested parameter
135 */
137 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 */
149 const openfluid::ware::WareParamKey_t& ParamName,
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 */
160 const openfluid::ware::WareParamKey_t& ParamName,
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 */
171 const openfluid::ware::WareParamKey_t& ParamName,
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 */
182 const openfluid::ware::WareParamKey_t& ParamName,
184
185 /**
186 Gets a simulator parameter from the parameters set, as a boolean
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 */
193 const openfluid::ware::WareParamKey_t& ParamName,
194 bool& Val) const;
195
196 /**
197 Gets a simulator parameter from the parameters set, as a double
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 */
204 const openfluid::ware::WareParamKey_t& ParamName,
205 double& Val) const;
206
207 /**
208 Gets a simulator parameter value from the parameters set, as a long int
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 */
215 const openfluid::ware::WareParamKey_t& ParamName,
216 long& Val) const;
217
218 /**
219 Gets a simulator parameter from the parameters set, as a float
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 */
226 const openfluid::ware::WareParamKey_t& ParamName,
227 float& Val) const;
228
229 /**
230 Gets a simulator parameter value from the parameters set, as an int
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 */
237 const openfluid::ware::WareParamKey_t& ParamName,
238 int& Val) const;
239
240 /**
241 Gets a simulator parameter value from the parameters set, as a string
242 @param[in] Params the parameters set for the simulator
243 @param[in] ParamName the name of the requested parameter
244 @param[out] Val the value of the requested parameter
245 @return true if the parameter exists, false otherwise
246 */
248 const openfluid::ware::WareParamKey_t& ParamName,
249 std::string& Val) const;
250
251 /**
252 Gets a simulator parameter vector of values from the parameters set, as a vector of strings
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 */
259 const openfluid::ware::WareParamKey_t& ParamName,
260 std::vector<std::string>& Vals) const;
261
262 /**
263 Gets a simulator parameter vector of values from the parameters set, as a vector of doubles
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 */
270 const openfluid::ware::WareParamKey_t& ParamName,
271 std::vector<double>& Vals) const;
272
273 /**
274 Gets a simulator parameter vector of values from the parameters set, as a vector of long ints
275 @param[in] Params the parameters set for the simulator
276 @param[in] ParamName the name of the requested parameter
277 @param[out] Vals the vector of values of the requested parameter
278 @return true if the parameter exists, false otherwise
279 */
281 const openfluid::ware::WareParamKey_t& ParamName,
282 std::vector<long>& Vals) const;
283
284 /**
285 Returns the maximum number of threads that can be concurrently run in threaded spatial loops
286 @return the number of threads
287
288 @cond OpenFLUID:completion
289 {
290 "contexts" : ["SIMULATOR"],
291 "menupath" : ["Threading"],
292 "title" : "Get maximum number of threads",
293 "text" : "OPENFLUID_GetSimulatorMaxThreads()"
294 }
295 @endcond
296 */
298 {
299 return m_MaxThreads;
300 }
301
302 /**
303 Sets the maximum number of threads that can be concurrently run in threaded spatial loops
304 @param[in] MaxNumThreads the number of threads
305
306 @cond OpenFLUID:completion
307 {
308 "contexts" : ["SIMULATOR"],
309 "menupath" : ["Threading"],
310 "title" : "Set maximum number of threads",
311 "text" : "OPENFLUID_SetSimulatorMaxThreads(%%SEL_START%%Number%%SEL_END%%)"
312 }
313 @endcond
314 */
315 void OPENFLUID_SetSimulatorMaxThreads(const int& MaxNumThreads);
316
317 /**
318 Returns a scheduling request to a single scheduling at the end
319 Return the corresponding scheduling request
320
321 @cond OpenFLUID:completion
322 {
323 "contexts" : ["SIMULATOR"],
324 "menupath" : ["Sheduling"],
325 "title" : "Run once at the end",
326 "text" : "AtTheEnd()"
327 }
328 @endcond
329 */
334
335 /**
336 Returns a scheduling request to never be scheduled again
337 Return the corresponding scheduling request
338
339 @cond OpenFLUID:completion
340 {
341 "contexts" : ["SIMULATOR"],
342 "menupath" : ["Sheduling"],
343 "title" : "Never run again",
344 "text" : "Never()"
345 }
346 @endcond
347 */
352
353 /**
354 Returns a scheduling request for the default DeltaT value
355 Return the corresponding scheduling request
356
357 @cond OpenFLUID:completion
358 {
359 "contexts" : ["SIMULATOR"],
360 "menupath" : ["Sheduling"],
361 "title" : "Run in default deltaT",
362 "text" : "DefaultDeltaT()"
363 }
364 @endcond
365 */
367 {
368 return openfluid::base::SchedulingRequest(OPENFLUID_GetDefaultDeltaT());
369 }
370
371 /**
372 Returns a scheduling request for the default DeltaT value multiplied by a factor
373 @param[in] Mult the multiplication factor
374 Return the corresponding scheduling request
375
376 @cond OpenFLUID:completion
377 {
378 "contexts" : ["SIMULATOR"],
379 "menupath" : ["Sheduling"],
380 "title" : "Run in X default deltaT",
381 "text" : "MultipliedDefaultDeltaT(%%SEL_START%%X%%SEL_END%%)"
382 }
383 @endcond
384 */
386 {
387 return openfluid::base::SchedulingRequest(Mult * OPENFLUID_GetDefaultDeltaT());
388 }
389
390 /**
391 Returns a scheduling request for a given duration
392 @param[in] D a duration in seconds
393 Return the corresponding scheduling request
394
395 @cond OpenFLUID:completion
396 {
397 "contexts" : ["SIMULATOR"],
398 "menupath" : ["Sheduling"],
399 "title" : "Run in a duration in seconds",
400 "text" : "Duration(%%SEL_START%%Seconds%%SEL_END%%)"
401 }
402 @endcond
403 */
408
409
410 public:
411 /**
412 Constructor
413 */
415
416 /**
417 Virtual destructor
418 */
420
421 using SimulationContributorWare::initializeWare;
422
423 /**
424 Internally called by the framework.
425 */
426 void initializeWare(const WareID_t& SimID,const unsigned int& MaxThreads);
427
428 /**
429 Initializes simulator parameters of the simulator, given as a hash map. Internally called by the framework.
430 */
431 virtual void initParams(const openfluid::ware::WareParams_t& Params) = 0;
432
433 /**
434 Prepares data. Internally called by the framework.
435 */
436 virtual void prepareData() = 0;
437
438 /**
439 Checks the simulator consistency. Internally called by the framework.
440 */
441 virtual void checkConsistency() = 0;
442
443 /**
444 Internally called by the framework.
445 */
447
448 /**
449 Internally called by the framework.
450 */
452
453 /**
454 Internally called by the framework.
455 */
456 virtual void finalizeRun() = 0;
457
458};
459
460
461typedef PluggableSimulator* (*GetPluggableSimulatorBodyProc)();
462
463typedef SimulatorSignature* (*GetPluggableSimulatorSignatureProc)();
464
465
466} } // namespaces
467
468
469#endif /* __OPENFLUID_WARE_PLUGGABLESIMULATOR_HPP__ */
Definition SchedulingRequest.hpp:54
@ NEVER
Definition SchedulingRequest.hpp:57
@ ATTHEEND
Definition SchedulingRequest.hpp:57
Definition DoubleValue.hpp:81
Definition MatrixValue.hpp:85
Definition StringValue.hpp:83
Definition VectorValue.hpp:85
Abstract class for simulator plugin.
Definition PluggableSimulator.hpp:105
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, openfluid::core::DoubleValue &Val) const
void initializeWare(const WareID_t &SimID, const unsigned int &MaxThreads)
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, std::vector< std::string > &Vals) const
virtual openfluid::base::SchedulingRequest runStep()=0
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, float &Val) const
virtual openfluid::base::SchedulingRequest initializeRun()=0
openfluid::base::SchedulingRequest DefaultDeltaT() const
Definition PluggableSimulator.hpp:366
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, std::vector< long > &Vals) const
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, bool &Val) const
int OPENFLUID_GetSimulatorMaxThreads() const
Definition PluggableSimulator.hpp:297
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, openfluid::core::StringValue &Val) const
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, int &Val) const
openfluid::core::StringValue OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName) const
openfluid::base::SchedulingRequest MultipliedDefaultDeltaT(const double &Mult) const
Definition PluggableSimulator.hpp:385
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, long &Val) const
openfluid::base::SchedulingRequest Duration(const openfluid::core::Duration_t &D) const
Definition PluggableSimulator.hpp:404
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, std::vector< double > &Vals) const
openfluid::base::SchedulingRequest AtTheEnd() const
Definition PluggableSimulator.hpp:330
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, double &Val) const
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, openfluid::core::VectorValue &Val) const
openfluid::base::SchedulingRequest Never() const
Definition PluggableSimulator.hpp:348
void OPENFLUID_SetSimulatorMaxThreads(const int &MaxNumThreads)
bool OPENFLUID_IsSimulatorParameterExist(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName) const
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, openfluid::core::MatrixValue &Val) const
bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t &Params, const openfluid::ware::WareParamKey_t &ParamName, std::string &Val) const
virtual void initParams(const openfluid::ware::WareParams_t &Params)=0
Definition SimulationContributorWare.hpp:52
Definition SimulatorSignature.hpp:262
#define OPENFLUID_API
Definition dllexport.hpp:86
std::uint64_t Duration_t
Definition TypeDefs.hpp:312
std::string WareID_t
Definition TypeDefs.hpp:49
std::string WareParamKey_t
Definition TypeDefs.hpp:142
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition TypeDefs.hpp:146
Definition ApplicationException.hpp:47