6#include "../Branch/BranchRecord.h"
7#include "../Scheduler/Scheduler.h"
8#include "../ControlPanel/ControlPanel.h"
9#include <boost/serialization/export.hpp>
10#include "../Global/SimulationContext.h"
11#include <boost/archive/binary_oarchive.hpp>
12#include <boost/archive/binary_iarchive.hpp>
27 string file_name, str;
31 file_name +=
"SystemReliability.txt";
32 ifstream fin(file_name.c_str(), ios::in);
34 cout <<
"File: " << file_name <<
" cound not be found" << endl;
35 ofstream fout(
"err messages.txt", ios::app);
36 fout <<
r5pars_.timesno <<
" File: " << file_name <<
" cound not be found\n";
46 int num = 0, i, failed_state, initial_state = 0;
47 string str, display_name, control_name;
48 double probability, control_value;
49 double failure_alpha_parameter, failure_beta_parameter;
50 double recovery_alpha_parameter, recovery_beta_parameter;
53 vector<unique_ptr<ControlState>>::iterator cs_itr;
54 vector<unique_ptr<ControlValue>>::iterator cv_itr;
64 std::cout <<
"WARNING: SystemReliability.txt: malformed or unexpected content where "
65 << __func__ <<
" expected a section header — remaining failure models NOT loaded."
67 std::ofstream ferr(
"err messages.txt", std::ios::app);
68 ferr <<
r5pars_.timesno <<
" WARNING: SystemReliability.txt malformed in " << __func__ <<
"\n";
71 for (i = 0; i < num; i++) {
74 auto hwr_pt = make_unique<HWReliabilityUnit>();
77 >> failure_alpha_parameter
78 >> failure_beta_parameter
79 >> recovery_alpha_parameter
80 >> recovery_beta_parameter;
82 hwr_pt->setDisplayName(display_name);
83 hwr_pt->setCorrespondingComponentNameOfControl(control_name);
84 hwr_pt->setAlpha_Parameter(failure_alpha_parameter);
85 hwr_pt->setBeta_Parameter(failure_beta_parameter);
87 probability = hwr_pt->calculateProbability();
88 hwr_pt->setProbability(probability);
93 ofstream fout(
"err messages.txt", ios::app);
94 cout <<
"HWReliabilityModule::readSystemReliabilityInfoFromFile: could not find display name: " << display_name
97 <<
" HWReliabilityModule::readSystemReliabilityInfoFromFile: could not find display name: "
98 << display_name <<
'\n';
119 hwr_pt->setInitialComponentState(initial_state);
126 if (control_name == (*cs_itr)->getDisplayName()) {
135 if (control_name == (*cv_itr)->getDisplayName()) {
154 }
else if (found_value) {
162 ofstream fout(
"err messages.txt", ios::app);
163 cout <<
"HWReliabilityModule::readSystemReliabilityInfoFromFile: could not find control name: " << control_name
166 <<
" HWReliabilityModule::readSystemReliabilityInfoFromFile: could not find control name: "
167 << control_name <<
'\n';
174 hwr_pt->setControlValue(control_value);
175 hwr_pt->setBothTotalTimeRequiredAndRemainingTime(0.0);
178 hwr_pt->setCorrespondingComponentPt(dcs_pt);
187 int num = 0, i, failed_state, initial_state = 0, numberOfIntervals;
188 string str, display_name, control_name;
189 double probability, control_value;
190 double deltaT, failure_rate, recovery_alpha_parameter, recovery_beta_parameter;
193 vector<unique_ptr<ControlState>>::iterator cs_itr;
194 vector<unique_ptr<ControlValue>>::iterator cv_itr;
204 std::cout <<
"WARNING: SystemReliability.txt: malformed or unexpected content where "
205 << __func__ <<
" expected a section header — remaining failure models NOT loaded."
207 std::ofstream ferr(
"err messages.txt", std::ios::app);
208 ferr <<
r5pars_.timesno <<
" WARNING: SystemReliability.txt malformed in " << __func__ <<
"\n";
211 for (i = 0; i < num; i++) {
214 auto hwr_pt = make_unique<HWReliabilityUnit>();
220 >> recovery_alpha_parameter
221 >> recovery_beta_parameter;
222 hwr_pt->setDisplayName(display_name);
223 hwr_pt->setCorrespondingComponentNameOfControl(control_name);
224 hwr_pt->setFailureRate(failure_rate);
225 hwr_pt->setT_Minimum(deltaT);
226 hwr_pt->setNumberOfIntervals(numberOfIntervals);
228 probability = hwr_pt->calculateSurvivalProbability(hwr_pt->getT_Minimum());
229 hwr_pt->setProbability(1 - probability);
234 ofstream fout(
"err messages.txt", ios::app);
235 cout <<
"HWReliabilityModule::readSystemOperationReliabilityInfoFromFile: could not find display name: "
236 << display_name << endl;
238 <<
" HWReliabilityModule::readSystemOperationReliabilityInfoFromFile: could not find display name: "
239 << display_name <<
'\n';
246 hwr_pt->setInitialComponentState(initial_state);
253 if (control_name == (*cs_itr)->getDisplayName()) {
262 if (control_name == (*cv_itr)->getDisplayName()) {
280 }
else if (found_value) {
288 ofstream fout(
"err messages.txt", ios::app);
289 cout <<
"HWReliabilityModule::readSystemOperationReliabilityInfoFromFile: could not find control name: "
290 << control_name << endl;
292 <<
" HWReliabilityModule::readSystemOperationReliabilityInfoFromFile: could not find control name: "
293 << control_name <<
'\n';
300 hwr_pt->setControlValue(control_value);
301 hwr_pt->setBothTotalTimeRequiredAndRemainingTime(0.0);
304 hwr_pt->setCorrespondingComponentPt(dcs_pt);
309 int num = 0, i, failed_state, initial_state = 0;
310 string str, display_name, control_name, top_node_name;
311 double control_value = 0.0;
314 vector<unique_ptr<ControlState>>::iterator cs_itr;
315 vector<unique_ptr<ControlValue>>::iterator cv_itr;
325 std::cout <<
"WARNING: SystemReliability.txt: malformed or unexpected content where "
326 << __func__ <<
" expected a section header — remaining failure models NOT loaded."
328 std::ofstream ferr(
"err messages.txt", std::ios::app);
329 ferr <<
r5pars_.timesno <<
" WARNING: SystemReliability.txt malformed in " << __func__ <<
"\n";
332 for (i = 0; i < num; i++) {
338 auto hwr_pt = make_unique<HWReliabilityFTUnit>(top_node_name);
339 hwr_pt->setDisplayName(display_name);
340 hwr_pt->setCorrespondingComponentNameOfControl(control_name);
341 hwr_pt->updateFailureProbability();
344 ofstream fout(
"err messages.txt", ios::app);
345 cout <<
"HWReliabilityModule::readSystemReliabilityInfoFromFile: could not find display name: " << display_name
348 <<
" HWReliabilityModule::readSystemReliabilityInfoFromFile: could not find display name: "
349 << display_name <<
'\n';
358 hwr_pt->setInitialComponentState(initial_state);
361 if (control_name == (*cs_itr)->getDisplayName()) {
368 if (control_name == (*cv_itr)->getDisplayName()) {
385 std::vector<string> nodes = hwr_pt->getBasicNodes();
386 for (std::vector<string>::iterator it = nodes.begin(); it != nodes.end(); ++it) {
395 }
else if (found_value) {
400 std::vector<string> nodes = hwr_pt->getBasicNodes();
401 for (std::vector<string>::iterator it = nodes.begin(); it != nodes.end(); ++it) {
411 ofstream fout(
"err messages.txt", ios::app);
412 cout <<
"HWReliabilityModule::readSystemReliabilityFTInfoFromFile: could not find control name: " << control_name
415 <<
" HWReliabilityModule::readSystemReliabilityFTInfoFromFile: could not find control name: "
416 << control_name <<
'\n';
423 hwr_pt->setControlValue(control_value);
424 hwr_pt->setBothTotalTimeRequiredAndRemainingTime(0.0);
427 hwr_pt->setCorrespondingComponentPt(dcs_pt);
432 bool need_to_check =
false;
433 int activation_state;
434 double probability, waiting_time;
438 activation_state = cr->checkAndActivateComponentFailure();
439 if (activation_state ==
sim::None) need_to_check =
true;
453 if (cr->getDisplayName() == cor->getDisplayName()) {
454 cor->setTimeAtDemand(
r5pars_.timesno);
462 activation_state = crft->checkAndActivateComponentFailure();
463 if (activation_state ==
sim::None) need_to_check =
true;
477 if (crft->getDisplayName() == cor->getDisplayName()) {
478 cor->setTimeAtDemand(
r5pars_.timesno);
486 activation_state = cor->checkAndActivateComponentFailure();
487 if (activation_state ==
sim::None) need_to_check =
true;
491 if (cor->getNumberOfIntervalsPassed() <= cor->getNumberOfIntervals()) need_to_check =
true;
493 cor->getTimeAtDemand() + cor->getNumberOfIntervalsPassed() * cor->getT_Minimum();
495 r5pars_.timesno > waiting_time &&
496 cor->getNumberOfIntervalsPassed() <= cor->getNumberOfIntervals()) {
497 probability = cor->calculateSurvivalProbability(
498 cor->getNumberOfIntervalsPassed() * cor->getT_Minimum());
499 cor->setProbability(1 - probability);
511 cor->setNumberOfIntervalsPassed(cor->getNumberOfIntervalsPassed() + 1);
521 auto ptr = make_unique<HWReliabilityUnit>();
522 ptr->copyHWReliabilityUnit(*src);
526 auto ptr = make_unique<HWReliabilityUnit>();
527 ptr->copyHWReliabilityUnit(*src);
531 auto ptr = make_unique<HWReliabilityFTUnit>();
532 ptr->setDisplayName(src->getTopNode());
533 ptr->copyHWReliabilityFTUnit(*src);
546 fout <<
"HWReliabilityModule\n"
548 for (i = 0; i < num; i++) {
552 fout <<
"HWOperationReliabilityModule\n"
554 for (i = 0; i < num; i++) {
563 if (str !=
"HWReliabilityModule") {
564 ofstream fout(
"err messages.txt", ios::app);
565 cout <<
"HWReliabilityModule::retrieveHWReliabilityModuleFromFile in previous function" << endl;
567 <<
" HWReliabilityModule::retrieveHWReliabilityModuleFromFile errir in previous function\n";
575 if (str !=
"HWOperationReliabilityModule") {
576 ofstream fout(
"err messages.txt", ios::app);
577 cout <<
"HWReliabilityModule::retrieveHWReliabilityModuleFromFile in previous function" << endl;
579 <<
" HWReliabilityModule::retrieveHWReliabilityModuleFromFile errir in previous function\n";
586 for (i = 0; i < num; i++) {
587 auto ptr = make_unique<HWReliabilityUnit>();
588 ptr->retrieveHWReliabilityUnitFromFile(fin);
595 if(p->getTopNode() == name){
599 ofstream fout(
"err messages.txt", ios::app);
600 cout <<
"HWReliabilityModule::getHWReliabilityFTUnit "
602 <<
" can not be found." << endl;
603 fout <<
r5pars_.timesno <<
" HWReliabilityModule::getHWReliabilityFTUnit "
605 <<
" can not be found.\n";
Hardware reliability model: failure on demand, fault tree failure on demand and failure while running...
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 addHWReliabilityBranch(BranchSystemAction *, BranchSystemAction *)
Registers a hardware reliability fork with two alternatives (index 0 first). The record takes ownersh...
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
void setFunctionalState(int)
void copyBranchSystemAction(BranchSystemAction &)
void setSenderAndReceiver(int, int)
double getValueForNeutralState()
double getValueForOnOrFullyOpen()
double getValueForOffOrFullyClose()
std::vector< std::unique_ptr< ControlValue > > control_value_array
SystemControl * getControlFromMap(std::string)
std::vector< std::unique_ptr< ControlState > > control_state_array
SystemDisplay * getDisplayFromMap(std::string)
ControlPanelDisplay indicators
ControlPanelControl controls
int getDisplayedControlStateWhenFail()
double getDisplayedControlValueWhenFail()
int getDisplayedComponentOperationalState()
void checkAndActiveComponentFailure()
Registers the hardware forks that are due at the current evaluation point.
std::vector< std::unique_ptr< HWReliabilityUnit > > component_reliability
Failure on demand units (alpha/beta probability model).
void readSystemOperationReliabilityInfoFromFile(std::ifstream &)
Reads the failure while running section into component_operation_reliability.
void copyHWReliabilityModule(HWReliabilityModule &)
Appends deep copies of the units of another module and copies its state of activation....
virtual ~HWReliabilityModule()
void readSystemReliabilityFTInfoFromFile(std::ifstream &)
Reads the fault tree failure on demand section into component_reliability_FT.
std::vector< std::unique_ptr< HWReliabilityUnit > > component_operation_reliability
Failure while running units (constant failure rate, evaluated per interval).
std::vector< std::unique_ptr< HWReliabilityFTUnit > > component_reliability_FT
Failure on demand units whose probability comes from a fault tree top node.
void readSystemReliabilityInfoFromFile(std::ifstream &)
Reads the failure on demand section into component_reliability.
void clearForRestart()
Removes all units and resets the state of activation.
void retrieveHWReliabilityModuleFromFile(std::ifstream &)
Reads a text restart stream: checks the two section labels, loads the failure while running units and...
HWReliabilityFTUnit * getHWReliabilityFTUnit(const std::string)
Finds the fault tree unit whose top node has the given name.
void saveHWReliabilityModuleToFile(std::ofstream &)
Writes the failure on demand units and the failure while running units, each under its own label and ...
void readInfoFromFile()
Loads SystemReliability.txt from the hardware reliability directory (Scheduler::getHardwareReliabilit...
void setBeta_Parameter(double)
void setAlpha_Parameter(double)
std::string getHardwareReliabilityDirectory()
void setStateOfActivation(int)
void saveStateOfActivationToFile(std::ofstream &)
int getStateOfActivation()
void retrieveStateOfActivationFromFile(std::ifstream &)
void copyStateOfActivation(StateOfActivation &)
void resetStateOfActivation()
void setTimerAndProbability(double, double)
constexpr int Reliability
Scheduler SScheduler
Simulation scheduling, parses CLI options.
ControlPanel Indicator
Control room panel state.
BranchRecord Branch_center
Dynamic event tree state.