ware/PluggableSimulator.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 
00033 /**
00034   \file PluggableSimulator.hpp
00035   \brief Header of ...
00036 
00037   \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00038  */
00039 
00040 
00041 #ifndef __PLUGGABLESIMULATOR_HPP__
00042 #define __PLUGGABLESIMULATOR_HPP__
00043 
00044 
00045 #include <string>
00046 
00047 #include <openfluid/dllexport.hpp>
00048 #include <openfluid/ware/SimulatorSignature.hpp>
00049 #include <openfluid/core/TypeDefs.hpp>
00050 #include <openfluid/base/SchedulingRequest.hpp>
00051 #include <openfluid/base/LoopMacros.hpp>
00052 #include <openfluid/core/DateTime.hpp>
00053 #include <openfluid/core/Unit.hpp>
00054 #include <openfluid/core/CoreRepository.hpp>
00055 #include <openfluid/core/Event.hpp>
00056 #include <openfluid/core/EventsColl.hpp>
00057 #include <openfluid/ware/SimulationContributorWare.hpp>
00058 
00059 
00060 // =====================================================================
00061 // =====================================================================
00062 
00063 
00064 /**
00065   Macro for declaration of simulator and signature hooks
00066 */
00067 #define DECLARE_SIMULATOR_PLUGIN \
00068   extern "C" \
00069   { \
00070     DLLEXPORT std::string WAREABIVERSION_PROC_DECL(); \
00071     DLLEXPORT openfluid::ware::PluggableSimulator* WAREBODY_PROC_DECL(); \
00072     DLLEXPORT openfluid::ware::SimulatorSignature* WARESIGNATURE_PROC_DECL(); \
00073   }
00074 
00075 
00076 // =====================================================================
00077 // =====================================================================
00078 
00079 
00080 /**
00081   Macro for definition of simulator hook
00082   @param[in] pluginclassname The name of the class to instantiate
00083 */
00084 #define DEFINE_SIMULATOR_CLASS(pluginclassname) \
00085   std::string WAREABIVERSION_PROC_DECL() \
00086   { \
00087     return std::string(openfluid::config::FULL_VERSION); \
00088   } \
00089   \
00090   openfluid::ware::PluggableSimulator* WAREBODY_PROC_DECL() \
00091   { \
00092     return new pluginclassname(); \
00093   }
00094 
00095 
00096 
00097 // =====================================================================
00098 // =====================================================================
00099 
00100 
00101 namespace openfluid { namespace ware {
00102 
00103 
00104 /**
00105   @brief Abstract class for simulator plugin
00106 
00107   Abstract class for simulator plugin interface,
00108   defining the minimal structure for a simulator. \n
00109   All simulators must inherit from this class.
00110 
00111   @author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00112 */
00113 class DLLEXPORT PluggableSimulator : public SimulationContributorWare
00114 {
00115 
00116   private:
00117 
00118     /**
00119       Pointer to the core repository, for internal use only
00120     */
00121     // TODO check here
00122    // openfluid::core::CoreRepository* mp_InternalCoreData;
00123 
00124 
00125     unsigned int m_MaxThreads;
00126 
00127 
00128   protected:
00129 
00130     /**
00131       Gets a simulator parameter from the parameters set, as a StringValue
00132       @param[in] Params the parameters set for the simulator
00133       @param[in] ParamName the name of the requested parameter
00134       @param[out] Val the value of the requested parameter
00135     */
00136     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00137                                         const openfluid::ware::WareParamKey_t& ParamName,
00138                                         openfluid::core::StringValue& Val) const;
00139 
00140     /**
00141       Gets a simulator parameter from the parameters set, as a DoubleValue
00142       @param[in] Params the parameters set for the simulator
00143       @param[in] ParamName the name of the requested parameter
00144       @param[out] Val the value of the requested parameter
00145     */
00146     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00147                                         const openfluid::ware::WareParamKey_t& ParamName,
00148                                         openfluid::core::DoubleValue& Val) const;
00149 
00150     /**
00151       Gets a simulator parameter from the parameters set, as a VectorValue
00152       @param[in] Params the parameters set for the simulator
00153       @param[in] ParamName the name of the requested parameter
00154       @param[out] Val the value of the requested parameter
00155     */
00156     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00157                                         const openfluid::ware::WareParamKey_t& ParamName,
00158                                         openfluid::core::VectorValue& Val) const;
00159 
00160     /**
00161       Gets a simulator parameter from the parameters set, as a MatrixValue
00162       @param[in] Params the parameters set for the simulator
00163       @param[in] ParamName the name of the requested parameter
00164       @param[out] Val the value of the requested parameter
00165     */
00166     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00167                                         const openfluid::ware::WareParamKey_t& ParamName,
00168                                         openfluid::core::MatrixValue& Val) const;
00169 
00170     /**
00171       Gets a simulator parameter from the parameters set, as a double
00172       @param[in] Params the parameters set for the simulator
00173       @param[in] ParamName the name of the requested parameter
00174       @param[out] Val the value of the requested parameter
00175     */
00176     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00177                                         const openfluid::ware::WareParamKey_t& ParamName,
00178                                         double& Val) const;
00179 
00180     /**
00181       Gets a simulator parameter value from the parameters set, as a long int
00182       @param[in] Params the parameters set for the simulator
00183       @param[in] ParamName the name of the requested parameter
00184       @param[out] Val the value of the requested parameter
00185     */
00186     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00187                                         const openfluid::ware::WareParamKey_t& ParamName,
00188                                         long& Val) const;
00189 
00190     /**
00191       Gets a simulator parameter from the parameters set, as a float
00192       @param[in] Params the parameters set for the simulator
00193       @param[in] ParamName the name of the requested parameter
00194       @param[out] Val the value of the requested parameter
00195     */
00196     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00197                                         const openfluid::ware::WareParamKey_t& ParamName,
00198                                         float& Val) const;
00199 
00200     /**
00201       Gets a simulator parameter value from the parameters set, as an int
00202       @param[in] Params the parameters set for the simulator
00203       @param[in] ParamName the name of the requested parameter
00204       @param[out] Val the value of the requested parameter
00205     */
00206     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00207                                         const openfluid::ware::WareParamKey_t& ParamName,
00208                                         int& Val) const;
00209 
00210     /**
00211       Gets a simulator parameter value from the parameters set, as a string
00212       @param[in] Params the parameters set for the simulator
00213       @param[in] ParamName the name of the requested parameter
00214       @param[out] Val the value of the requested parameter
00215     */
00216     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00217                                         const openfluid::ware::WareParamKey_t& ParamName,
00218                                         std::string& Val) const;
00219 
00220     /**
00221       Gets a simulator parameter vector of values from the parameters set, as a vector of strings
00222       @param[in] Params the parameters set for the simulator
00223       @param[in] ParamName the name of the requested parameter
00224       @param[out] Vals the vector of values of the requested parameter
00225     */
00226     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00227                                         const openfluid::ware::WareParamKey_t& ParamName,
00228                                         std::vector<std::string>& Vals) const;
00229 
00230     /**
00231       Gets a simulator parameter vector of values from the parameters set, as a vector of doubles
00232       @param[in] Params the parameters set for the simulator
00233       @param[in] ParamName the name of the requested parameter
00234       @param[out] Vals the vector of values of the requested parameter
00235     */
00236     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00237                                         const openfluid::ware::WareParamKey_t& ParamName,
00238                                         std::vector<double>& Vals) const;
00239 
00240     /**
00241       Gets a simulator parameter vector of values from the parameters set, as a vector of long ints
00242       @param[in] Params the parameters set for the simulator
00243       @param[in] ParamName the name of the requested parameter
00244       @param[out] Vals the vector of values of the requested parameter
00245     */
00246     bool OPENFLUID_GetSimulatorParameter(const openfluid::ware::WareParams_t& Params,
00247                                         const openfluid::ware::WareParamKey_t& ParamName,
00248                                         std::vector<long>& Vals) const;
00249 
00250     /**
00251       Returns the maximum number of threads that can be concurrently run in threaded spatial loops
00252       @return the number of threads
00253     */
00254     inline unsigned int OPENFLUID_GetSimulatorMaxThreads() const { return m_MaxThreads; };
00255 
00256     /**
00257       Sets the maximum number of threads that can be concurrently run in threaded spatial loops
00258       @param[in] MaxNumThreads the number of threads
00259     */
00260     void OPENFLUID_SetSimulatorMaxThreads(const unsigned int& MaxNumThreads);
00261 
00262 
00263     inline openfluid::base::SchedulingRequest AtTheEnd() const
00264     { return openfluid::base::SchedulingRequest(openfluid::base::SchedulingRequest::ATTHEEND); };
00265 
00266     inline openfluid::base::SchedulingRequest Never() const
00267     { return openfluid::base::SchedulingRequest(openfluid::base::SchedulingRequest::NEVER); };
00268 
00269     inline openfluid::base::SchedulingRequest DefaultDeltaT() const
00270     { return openfluid::base::SchedulingRequest(OPENFLUID_GetDefaultDeltaT()); };
00271 
00272     inline openfluid::base::SchedulingRequest MultipliedDefaultDeltaT(const double& Mult) const
00273         { return openfluid::base::SchedulingRequest(Mult * OPENFLUID_GetDefaultDeltaT()); };
00274 
00275     inline openfluid::base::SchedulingRequest Duration(const openfluid::core::Duration_t& D) const
00276         { return openfluid::base::SchedulingRequest(D); };
00277 
00278 
00279   public:
00280     /**
00281       Constructor
00282     */
00283     PluggableSimulator();
00284 
00285     /**
00286       Virtual destructor
00287     */
00288     virtual ~PluggableSimulator();
00289 
00290     /**
00291       Internally called by the framework.
00292     */
00293     void initializeWare(const WareID_t& SimID,const unsigned int& MaxThreads);
00294 
00295     /**
00296       Initializes simulator parameters of the simulator, given as a hash map. Internally called by the framework.
00297     */
00298     virtual void initParams(const openfluid::ware::WareParams_t& Params)=0;
00299 
00300     /**
00301       Prepares data. Internally called by the framework.
00302     */
00303     virtual void prepareData()=0;
00304 
00305     /**
00306       Checks the simulator consistency. Internally called by the framework.
00307     */
00308     virtual void checkConsistency()=0;
00309 
00310     /**
00311       Internally called by the framework.
00312     */
00313     virtual openfluid::base::SchedulingRequest initializeRun()=0;
00314 
00315     /**
00316       Internally called by the framework.
00317     */
00318     virtual openfluid::base::SchedulingRequest runStep()=0;
00319 
00320     /**
00321       Internally called by the framework.
00322     */
00323     virtual void finalizeRun()=0;
00324 
00325 };
00326 
00327 typedef PluggableSimulator* (*GetPluggableSimulatorBodyProc)();
00328 
00329 typedef SimulatorSignature* (*GetPluggableSimulatorSignatureProc)();
00330 
00331 } } // namespaces
00332 
00333 
00334 #endif /* __PLUGGABLESIMULATOR_HPP__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines