← Documentation
ADS-IDAC Engine 5.0.0
SupportSystemReliabilityModule.cpp
Go to the documentation of this file.
2#include "../Branch/BranchRecord.h"
3#include "../ControlPanel/ControlPanel.h"
4#include "../ControlPanel/DisplaySupportSystemState.h"
5#include "../Global/TermConversions.h"
6#include <boost/serialization/export.hpp>
7#include "../Global/SimulationContext.h"
8using namespace std;
9#include <boost/archive/binary_oarchive.hpp>
10#include <boost/archive/binary_iarchive.hpp>
11//BOOST_CLASS_EXPORT_IMPLEMENT(SupportSystemReliabilityModule)
12
13
15}
16
18 this->clearForRestart();
19}
20
22// TODO: Instead of checking for control state:
23// TODO: 1. saveFTMap()
24// TODO: 2. create control state objects automatically
25// TODO: 3. compute probability
26// or
27// TODO: get topNodes from ControlPanel.txt
28// TODO: for each topNode create new SupportSystemReliabilityUnit(topNode);
29// TODO: set probability and other properties
30
31
32 const auto&
33 support_systems_state_array = g_sim.Indicator.indicators.getSupport_systems_state_array();
34
35 for (int j = 0; j < support_systems_state_array.size(); ++j) {
36 std::string topNode = support_systems_state_array[j]->getDisplayName();
37 auto ssu_pt = make_unique<SupportSystemReliabilityUnit>(topNode);
38 ssu_pt->setDisplayName(topNode);
39 ssu_pt->updateFailureProbability();
40 int initialSupportSystemState = support_systems_state_array[j]->getDisplayedSupportSystemOperationalState();
41 ssu_pt->setInitialSupportSystemState(initialSupportSystemState);
42 ssu_pt->setBothTotalTimeRequiredAndRemainingTime(0.0);
43 ssu_pt->setSender(sim::Source::Reliability);
44 ssu_pt->setIntendedReceiver(sim::Source::Plant);
45 ssu_pt->setCorrespondingSupportSystemPt(support_systems_state_array[j].get());
46 std::vector<string> nodes = ssu_pt->getBasicNodes();
47 supportSystemReliabilityUnit.push_back(std::move(ssu_pt));
48 for (std::vector<string>::iterator it = nodes.begin(); it != nodes.end(); ++it) {
49// std::cout << "**Basic Event:** " << *it
50// << std::endl;
51 }
52// std::cout << "Created SupportSystemReliabilityUnit: " << ssu_pt->getDisplayName()
53// << " with initial probability: " << ssu_pt->getProbability()
54// << " of type: " << support_systems_state_array[j]->getTypeOfDisplay()
55// << " with DisplaySupportSystemState: " << support_systems_state_array[j]->getDisplayName()
56// << std::endl;
57 }
58}
59
61 for (auto& unit : supportSystemReliabilityUnit) {
62 unit->updateDisplayState();
63 }
64}
65
67 bool need_to_check = false;
68 int activation_state;
69 BranchSupportSystemAction *bssa_success, *bssa_fail;
71 return;
72 for (auto& ssu : supportSystemReliabilityUnit) {
73 activation_state = ssu->checkAndActivateSupportSystemFailure();
74 if (activation_state == sim::None)
75 need_to_check = true;
76 if (activation_state == sim::State::Active) {
77 bssa_fail = new BranchSupportSystemAction();
78 bssa_fail->copyBranchSupportSystemAction(*ssu);
81 bssa_fail->setTimerAndProbability(-1.0, ssu->getProbability());
82 //
83 bssa_success = new BranchSupportSystemAction();
84 bssa_success->copyBranchSupportSystemAction(*ssu);
87 bssa_success->setTimerAndProbability(-1.0, 1.0 - bssa_fail->getProbability());
88 //
89 g_sim.Branch_center.addSSReliabilityBranch(bssa_success, bssa_fail);
90 }
91 }
92 if (!need_to_check)
94}
95
98 for (auto& src : _ssu.supportSystemReliabilityUnit) {
99 auto ptr = make_unique<SupportSystemReliabilityUnit>(src->getTopNode());
100 ptr->setDisplayName(src->getTopNode());
101 ptr->copySupportSystemUnit(*src);
102 supportSystemReliabilityUnit.push_back(std::move(ptr));
103 }
104}
105
109}
110
112 int i, num;
113 num = supportSystemReliabilityUnit.size();
114 fout << "SupportSystemReliabilityModule\n" << num << '\n';
115 for (i = 0; i < num; i++) {
116 supportSystemReliabilityUnit.at(i)->saveSupportSystemUnitToFile(fout);
117 }
118 this->saveStateOfActivationToFile(fout);
119}
120
122 int i, num;
123 string str;
124 fin >> str >> num;
125 if (str != "SupportSystemReliabilityModule") {
126 ofstream fout("err messages.txt", ios::app);
127 cout
128 << "SupportSystemReliabilityModule::retrieveSupportSystemModuleFromFile in previous function"
129 << endl;
130 fout << r5pars_.timesno
131 << "SupportSystemReliabilityModule::retrieveSupportSystemModuleFromFile error in previous function\n";
132 fout.close();
133 r5pars_.sim_err = true;
135 "SupportSystemReliabilityModule::retrieveSupportSystemModuleFromFile Prior error.");
137 return;
138 }
139 for (i = 0; i < num; i++) {
140 fin >> str;
141 auto ssu_pt = make_unique<SupportSystemReliabilityUnit>(str);
142 ssu_pt->retrieveSupportSystemUnitFromFile(fin);
143 supportSystemReliabilityUnit.push_back(std::move(ssu_pt));
144 }
146}
147const vector<unique_ptr<SupportSystemReliabilityUnit>> &SupportSystemReliabilityModule::getSupportSystemReliabilityUnit() const {
149}
151 for(auto& p : supportSystemReliabilityUnit){
152 if(p->getTopNode() == name){
153 return p.get();
154 }
155 }
156 ofstream fout("err messages.txt", ios::app);
157 cout << "SupportSystemReliabilityModule::getSupportSystemReliabilityUnit "
158 << name
159 << " can not be found." << endl;
160 fout << r5pars_.timesno << " SupportSystemReliabilityModule::getSupportSystemReliabilityUnit "
161 << name
162 << " can not be found.\n";
163 fout.close();
164 r5pars_.sim_err = true;
165 g_sim.Branch_center.setTempESMessage("SupportSystemReliabilityModule::getSupportSystemReliabilityUnit err.");
167 return nullptr;
168}
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
Support system reliability — models auxiliary system failures (power, cooling, instrumentation).
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
void addSSReliabilityBranch(BranchSupportSystemAction *, BranchSupportSystemAction *)
Registers a support system reliability fork with two alternatives (index 0 first)....
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
void copyBranchSupportSystemAction(BranchSupportSystemAction &)
void setSenderAndReceiver(int, int)
const std::vector< std::unique_ptr< DisplaySupportSystemState > > & getSupport_systems_state_array() const
ControlPanelDisplay indicators
Definition: ControlPanel.h:53
double getProbability()
Definition: Probability.cpp:27
void setStateOfActivation(int)
void saveStateOfActivationToFile(std::ofstream &)
void retrieveStateOfActivationFromFile(std::ifstream &)
void copyStateOfActivation(StateOfActivation &)
std::vector< std::unique_ptr< SupportSystemReliabilityUnit > > supportSystemReliabilityUnit
const std::vector< std::unique_ptr< SupportSystemReliabilityUnit > > & getSupportSystemReliabilityUnit() const
void copySupportSystemModule(SupportSystemReliabilityModule &)
void setTimerAndProbability(double, double)
struct @0 r5pars_
constexpr int Plant
Definition: SimConstants.h:135
constexpr int Reliability
Definition: SimConstants.h:139
constexpr int Failed
Definition: SimConstants.h:103
constexpr int Succeed
Definition: SimConstants.h:104
constexpr int Done
Definition: SimConstants.h:123
constexpr int Active
Definition: SimConstants.h:118
constexpr int None
Definition: SimConstants.h:75
ControlPanel Indicator
Control room panel state.
BranchRecord Branch_center
Dynamic event tree state.