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