ModelInstance.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 ModelInstance.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_MACHINE_MODELINSTANCE_HPP__
41 #define __OPENFLUID_MACHINE_MODELINSTANCE_HPP__
42 
43 
44 #include <list>
45 
46 #include <openfluid/dllexport.hpp>
51 
52 
53 namespace openfluid { namespace ware {
54 class PluggableSimulator;
55 } }
56 
57 
58 namespace openfluid { namespace machine {
59 
60 class MachineListener;
61 class SimulationBlob;
62 class ModelItemInstance;
63 
64 
66 {
67  private:
68 
69  std::list<ModelItemInstance*> m_ModelItems;
70 
72 
74 
76 
77  openfluid::machine::SimulationBlob& m_SimulationBlob;
78 
79  std::list<ExecutionTimePoint> m_TimePointList;
80 
81  openfluid::ware::WareParams_t m_GlobalParams;
82 
83  bool m_Initialized;
84 
85  void appendItemToTimePoint(openfluid::core::TimeIndex_t TimeIndex, openfluid::machine::ModelItemInstance* Item);
86 
87  void checkDeltaTMode(openfluid::base::SchedulingRequest& SReq, const openfluid::ware::WareID_t& ID);
88 
89 
90  protected:
91 
92  openfluid::ware::WareParams_t mergeParamsWithGlobalParams(const openfluid::ware::WareParams_t& Params) const;
93 
94 
95  public:
96 
99 
100  ~ModelInstance();
101 
102  void appendItem(ModelItemInstance* ItemInstance);
103 
104  /**
105  Insert a ModelItemInstance before the given postion (positions starts at index 0)
106  @param[in] ItemInstance the ModelItemInstance to insert
107  @param[in] Position the position
108  */
109  void insertItem(ModelItemInstance* ItemInstance, unsigned int Position);
110 
111  /**
112  Delete the ModelItemInstance located at the given postion (positions starts at index 0),
113  and remove it from the ModelInstance
114  @param[in] Position the position
115  */
116  void deleteItem(unsigned int Position);
117 
118  void clear();
119 
120  unsigned int getItemsCount() const
121  {
122  return m_ModelItems.size();
123  }
124 
126  {
127  return m_GlobalParams;
128  }
129 
130  void setGlobalParameter(const openfluid::ware::WareParamKey_t& Key, const openfluid::ware::WareParamValue_t& Value);
131 
133  {
134  m_GlobalParams = Params;
135  }
136 
137  const std::list<ModelItemInstance*>& items() const
138  {
139  return m_ModelItems;
140  }
141 
142  void initialize(openfluid::base::SimulationLogger* SimLogger);
143 
144  void finalize();
145 
146  void call_initParams() const;
147 
148  void call_prepareData() const;
149 
150  void call_checkConsistency() const;
151 
152  void call_initializeRun();
153 
154  inline bool hasTimePointToProcess() const
155  {
156  return !m_TimePointList.empty();
157  }
158 
159  void processNextTimePoint();
160 
162  {
163  if (m_TimePointList.empty())
164  {
165  return -2;
166  }
167  return m_TimePointList.front().getTimeIndex();
168  }
169 
170  void call_finalizeRun() const;
171 
173  {
174  m_Initialized = false;
175  }
176 
177 };
178 
179 
180 } } //namespaces
181 
182 
183 #endif /* __OPENFLUID_MACHINE_MODELINSTANCE_HPP__ */
unsigned int getItemsCount() const
Definition: ModelInstance.hpp:120
std::uint64_t TimeIndex_t
Definition: TypeDefs.hpp:298
bool hasTimePointToProcess() const
Definition: ModelInstance.hpp:154
void setGlobalParameters(const openfluid::ware::WareParams_t &Params)
Definition: ModelInstance.hpp:132
std::string WareID_t
Definition: TypeDefs.hpp:49
void resetInitialized()
Definition: ModelInstance.hpp:172
Definition: SimulationBlob.hpp:53
std::string WareParamKey_t
Definition: TypeDefs.hpp:124
Abstract class for simulator plugin.
Definition: PluggableSimulator.hpp:105
Definition: StringValue.hpp:76
std::uint64_t Duration_t
Definition: TypeDefs.hpp:312
Definition: SimulationLogger.hpp:57
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:128
Definition: SchedulingRequest.hpp:53
Definition: SimulationProfiler.hpp:56
const std::list< ModelItemInstance * > & items() const
Definition: ModelInstance.hpp:137
Definition: ModelInstance.hpp:65
Definition: ApplicationException.hpp:47
Definition: MachineListener.hpp:54
openfluid::core::Duration_t getNextTimePointIndex() const
Definition: ModelInstance.hpp:161
#define OPENFLUID_API
Definition: dllexport.hpp:86
Definition: ModelItemInstance.hpp:98
openfluid::ware::WareParams_t & globalParameters()
Definition: ModelInstance.hpp:125