← Documentation
ADS-IDAC Engine 5.0.0
ControlState.cpp
Go to the documentation of this file.
1// ControlState.cpp: implementation of the ControlState class.
2//
4
5#include "ControlState.h"
6#include "../Global/TermConversions.h"
7#include "../Branch/BranchRecord.h"
8#include <boost/serialization/export.hpp>
9#include "../Global/SimulationContext.h"
10#include <boost/archive/binary_oarchive.hpp>
11#include <boost/archive/binary_iarchive.hpp>
12BOOST_CLASS_EXPORT_IMPLEMENT(ControlState)
13using namespace std;
14
16// Construction/Destruction
18
20{
22 displyed_control_state_when_fail = sim::State::Auto; // deterministic default, overwritten by readInfoFromFile
24}
25
27{
28
29}
35 string str;
37 fin >> str;
38 if (str == "ON"){
40 else if (str == "OFF"){
42 else if (str == "OPEN"){
44 else if(str == "CLOSE"){
46 else if (str == "NONE"){
48 }
49 else{
50 ofstream fout("err messages.txt", ios::app);
51 cout << "ControlState::readInfoFromFile Control " << SystemControl::getDisplayName() << " whose displayed_control_state_when_fail "
52 << displyed_control_state_when_fail << " can not be recognized." << endl;
53 fout << r5pars_.timesno << " ControlState::readInfoFromFile Control " << SystemControl::getDisplayName() << " whose displayed_control_state_when_fail "
54 << displyed_control_state_when_fail << " can not be recognized.\n";
55 fout.close();
56 r5pars_.sim_err = true;
57 g_sim.Branch_center.setTempESMessage("ControlState::readInfoFromFile err.");
59 }
60}
62 InteractiveVariable *iv_ptr;
64 if(iv_ptr == 0){
67 }
68 if(iv_ptr != 0){
70 switch (_control_state){
74 break;
78 break;
79 case sim::State::On:
82 break;
83 case sim::State::Off:
86 break;
87 default:
88 break;
89 ofstream fout("err messages.txt", ios::app);
90 cout << " ControlState::updateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
91 << "whose control state " << _control_state << " can not be recognized." << endl;
92 fout << r5pars_.timesno << " ControlState::updateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
93 << "whose control state " << _control_state << " can not be recognized.\n";
94 fout.close();
95 r5pars_.sim_err = true;
96 g_sim.Branch_center.setTempESMessage("ControlState::updateDisplayedControlState err.");
98 }
99 }
100 else{//control fails
103 }
104 }
105 }
106 else{
107 ofstream fout("err messages.txt", ios::app);
108 cout << " ControlState::updateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
109 << " can not be located." << endl;
110 fout << r5pars_.timesno << " ControlState::updateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
111 << " can not be located.\n";
112 fout.close();
113 r5pars_.sim_err = true;
114 g_sim.Branch_center.setTempESMessage("ControlState::updateDisplayedControlState err.");
116 }
117}
118void ControlState::performValueControl(SystemModule &_th, double _control_value){
119 InteractiveVariable *iv_ptr;
121 if(iv_ptr == 0){
124 }
125 if(iv_ptr != 0){
126 iv_ptr->setInputValue(_control_value);
127 iv_ptr->setNeedToInteract(true);
128 // update control value
129 this->setControlValue(_control_value);
130 this->setDisplayedControlState(_control_value);
131 //
132 }
133 else{
134 ofstream fout("err messages.txt", ios::app);
135 cout << " ControlState::performValueControl InteractiveVariable: " << this->getCorrespondingComponentNameOfControl() << " could not be found" << endl;
136 fout << r5pars_.timesno << " ControlState::performValueControl InteractiveVariable: " << this->getCorrespondingComponentNameOfControl() << " could not be found.\n";
137 fout.close();
138 r5pars_.sim_err = true;
139 g_sim.Branch_center.setTempESMessage("ControlState::performValueControl err.");
141 }
142}
143
145 InteractiveVariable *iv_ptr;
147 if(iv_ptr == 0){
150 }
151 if(iv_ptr != 0){
153 switch (_control_state){
154 case sim::State::Open:
156 iv_ptr->setNeedToInteract(true);
158 break;
161 iv_ptr->setNeedToInteract(true);
163 break;
164 case sim::State::On:
166 iv_ptr->setNeedToInteract(true);
168 break;
169 case sim::State::Off:
171 iv_ptr->setNeedToInteract(true);
173 break;
174 default:
175 break;
176 ofstream fout("err messages.txt", ios::app);
177 cout << " ControlState::updateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
178 << "whose control state " << _control_state << " can not be recognized." << endl;
179 fout << r5pars_.timesno << " ControlState::updateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
180 << "whose control state " << _control_state << " can not be recognized.\n";
181 fout.close();
182 r5pars_.sim_err = true;
183 g_sim.Branch_center.setTempESMessage("ControlState::performDisplayedControlState err.");
185 }
186 }
187 else{//control fails
190 }
191 }
192 }
193 else{
194 ofstream fout("err messages.txt", ios::app);
195 cout << " ControlState::updateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
196 << " can not be located." << endl;
197 fout << r5pars_.timesno << " ControlState::updateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
198 << " can not be located.\n";
199 fout.close();
200 r5pars_.sim_err = true;
201 g_sim.Branch_center.setTempESMessage("ControlState::performDisplayedControlState err.");
203 }
204}
206 InteractiveVariable *iv_ptr;
207 double iv_value;
209 if(iv_ptr == 0){
212 }
213 if(iv_ptr != 0){
214 iv_value = iv_ptr->getDisplayValue();
217 if (fabs(iv_value - SystemControl::getValueForOnOrFullyOpen()) < 1.0E-6) {
219 }
220 else if (fabs(iv_value - SystemControl::getValueForOffOrFullyClose()) < 1.0E-6){
222 }
223 else{
225 }
226 break;
228 if (fabs(iv_value - SystemControl::getValueForOnOrFullyOpen()) < 1.0E-6) {
230 }
231 else if (fabs(iv_value - SystemControl::getValueForOffOrFullyClose()) < 1.0E-6){
233 }
234 else{
236 }
237 break;
238 default:
239 break;
240 ofstream fout("err messages.txt", ios::app);
241 cout << " ControlState::initiateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
242 << "whose displyed_control_state_when_fail " << displyed_control_state_when_fail << " can not be recognized." << endl;
243 fout << r5pars_.timesno << " ControlState::initiateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
244 << "whose displyed_control_state_when_fail " << displyed_control_state_when_fail << " can not be recognized.\n";
245 fout.close();
246 r5pars_.sim_err = true;
247 g_sim.Branch_center.setTempESMessage("ControlState::initiateDisplayedControlState err.");
249 }
250 }
251 else{
252 ofstream fout("err messages.txt", ios::app);
253 cout << " ControlState::initiateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
254 << " can not be located." << endl;
255 fout << r5pars_.timesno << " ControlState::initiateDisplayedControlState Component " << SystemControl::getCorrespondingComponentNameOfControl()
256 << " can not be located.\n";
257 fout.close();
258 r5pars_.sim_err = true;
259 g_sim.Branch_center.setTempESMessage("ControlState::initiateDisplayedControlState err.");
261 }
262}
264 string c_state;
265 switch (displyed_control_state){
266 case sim::State::Open:
267 c_state = "OPEN";
268 break;
270 c_state = "CLOSE";
271 break;
272 case sim::State::On:
273 c_state = "ON";
274 break;
275 case sim::State::Off:
276 c_state = "OFF";
277 break;
278 default:
279 c_state = "UNKNOWN";
280 break;
281 }
282 return c_state;
283}
284
289}
291 this->saveSystemControlToFile(fout);
293}
297}
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
std::string getDisplayName()
void setControlValue(double)
std::string getCorrespondingComponentNameOfControl()
double getValueForOnOrFullyOpen()
double getValueForOffOrFullyClose()
void readInfoFromFile(std::ifstream &)
int displyed_control_state_when_fail
Definition: ControlState.h:39
std::string getDisplayedControlStateString()
void retrieveControlStateFromFile(std::ifstream &)
void updateDisplayedControlState(SystemModule &, int)
int displyed_control_state
Definition: ControlState.h:39
void initiateDisplayedControlState(SystemModule &)
void readInfoFromFile(std::ifstream &)
void performValueControl(SystemModule &, double)
void performDisplayedControlState(SystemModule &, int)
int getDisplayedControlStateWhenFail()
int getDisplayedControlState()
void saveControlStateToFile(std::ofstream &)
void setDisplayedControlState(int)
virtual ~ControlState()
void copyControlState(ControlState &)
void setDisplayedControlStateWhenFail(int)
void setInputValue(double val)
void setNeedToInteract(bool flag)
InteractiveVariable * getPtrToCorrespondingInteractiveVariable()
void setPtrToCorrespondingInteractiveVariable(InteractiveVariable *)
void setTypeOfControl(DisplayType)
void saveSystemControlToFile(std::ofstream &)
int getFunctionalState()
void retrieveSystemControlFromFile(std::ifstream &)
void copySystemControl(SystemControl &)
THElement * getComponentFromSystemMap(std::string)
struct @0 r5pars_
constexpr int On
Definition: SimConstants.h:105
constexpr int Off
Definition: SimConstants.h:106
constexpr int Succeed
Definition: SimConstants.h:104
constexpr int Open
Definition: SimConstants.h:116
constexpr int Auto
Definition: SimConstants.h:112
constexpr int Close
Definition: SimConstants.h:117
constexpr int None
Definition: SimConstants.h:75
BranchRecord Branch_center
Dynamic event tree state.