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 /** 00035 @file 00036 00037 @author Jean-Christophe FABRE <fabrejc@supagro.inra.fr> 00038 */ 00039 00040 00041 #ifndef __MODELINSTANCE_HPP__ 00042 #define __MODELINSTANCE_HPP__ 00043 00044 #include <list> 00045 00046 #include <openfluid/dllexport.hpp> 00047 #include <openfluid/ware/PluggableWare.hpp> 00048 #include <openfluid/machine/ExecutionTimePoint.hpp> 00049 #include <openfluid/base/SimulationLogger.hpp> 00050 #include <openfluid/machine/SimulationProfiler.hpp> 00051 00052 00053 00054 namespace openfluid { namespace ware { 00055 00056 class PluggableSimulator; 00057 00058 } } 00059 00060 00061 namespace openfluid { namespace machine { 00062 00063 class MachineListener; 00064 class SimulationBlob; 00065 class ModelItemInstance; 00066 00067 00068 class DLLEXPORT ModelInstance 00069 { 00070 private: 00071 00072 std::list<ModelItemInstance*> m_ModelItems; 00073 00074 openfluid::machine::MachineListener* mp_Listener; 00075 00076 openfluid::base::SimulationLogger* mp_SimLogger; 00077 00078 openfluid::machine::SimulationProfiler* mp_SimProfiler; 00079 00080 openfluid::machine::SimulationBlob& m_SimulationBlob; 00081 00082 std::list<ExecutionTimePoint> m_TimePointList; 00083 00084 openfluid::ware::WareParams_t m_GlobalParams; 00085 00086 bool m_Initialized; 00087 00088 void appendItemToTimePoint(openfluid::core::TimeIndex_t TimeIndex, openfluid::machine::ModelItemInstance* Item); 00089 00090 void checkDeltaTMode(openfluid::base::SchedulingRequest& SReq, const openfluid::ware::WareID_t& ID); 00091 00092 protected: 00093 00094 openfluid::ware::WareParams_t mergeParamsWithGlobalParams(const openfluid::ware::WareParams_t& Params) const; 00095 00096 00097 public: 00098 00099 ModelInstance(openfluid::machine::SimulationBlob& SimulationBlob, 00100 openfluid::machine::MachineListener* Listener); 00101 00102 ~ModelInstance(); 00103 00104 void appendItem(ModelItemInstance* ItemInstance); 00105 00106 /** 00107 Insert a ModelItemInstance before the given postion (positions starts at index 0) 00108 @param[in] ItemInstance the ModelItemInstance to insert 00109 @param[in] Position the position 00110 */ 00111 void insertItem(ModelItemInstance* ItemInstance, unsigned int Position); 00112 00113 /** 00114 Delete the ModelItemInstance located at the given postion (positions starts at index 0), and remove it from the ModelInstance 00115 @param[in] Position the position 00116 */ 00117 void deleteItem(unsigned int Position); 00118 00119 void clear(); 00120 00121 unsigned int getItemsCount() const { return m_ModelItems.size(); }; 00122 00123 openfluid::ware::WareParams_t& getGlobalParameters() { return m_GlobalParams; }; 00124 00125 void setGlobalParameter(const openfluid::ware::WareParamKey_t& Key, const openfluid::ware::WareParamValue_t& Value); 00126 00127 void setGlobalParameters(const openfluid::ware::WareParams_t& Params) { m_GlobalParams = Params; }; 00128 00129 const std::list<ModelItemInstance*>& getItems() const { return m_ModelItems; }; 00130 00131 void initialize(openfluid::base::SimulationLogger* SimLogger); 00132 00133 void finalize(); 00134 00135 void call_initParams() const; 00136 00137 void call_prepareData() const; 00138 00139 void call_checkConsistency() const; 00140 00141 void call_initializeRun(); 00142 00143 inline bool hasTimePointToProcess() const 00144 { return !m_TimePointList.empty(); }; 00145 00146 void processNextTimePoint(); 00147 00148 inline openfluid::core::Duration_t getNextTimePointIndex() const 00149 { 00150 if (m_TimePointList.empty()) return -2; 00151 return m_TimePointList.front().getTimeIndex(); 00152 } 00153 00154 void call_finalizeRun() const; 00155 00156 void resetInitialized() { m_Initialized = false; } 00157 00158 }; 00159 00160 00161 } } //namespaces 00162 00163 00164 #endif /* __MODELINSTANCE_H__ */