Skip to content

Commit

Permalink
Add alignment & phase info into event tree reports
Browse files Browse the repository at this point in the history
Issue #153
  • Loading branch information
rakhimov committed Aug 12, 2017
1 parent 7e19aa8 commit 636dab4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 14 deletions.
6 changes: 6 additions & 0 deletions input/EventTrees/attack_alignment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<opsa-mef>
<define-alignment name="Default">
<define-phase name="Normal" time-fraction="1"/>
</define-alignment>
</opsa-mef>
6 changes: 6 additions & 0 deletions share/report.rng
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@
<define name="initiating-event">
<element name="initiating-event">
<attribute name="name"> <data type="NCName"/> </attribute>
<optional>
<group>
<attribute name="alignment"> <data type="NCName"/> </attribute>
<attribute name="phase"> <data type="NCName"/> </attribute>
</group>
</optional>
<optional>
<attribute name="description"> <text/> </attribute>
</optional>
Expand Down
18 changes: 13 additions & 5 deletions src/reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ void Reporter::Report(const core::RiskAnalysis& risk_an, std::ostream& out) {
TIMER(DEBUG1, "Reporting analysis results");
XmlStreamElement results = report.AddChild("results");
if (risk_an.settings().probability_analysis()) {
for (const std::unique_ptr<core::EventTreeAnalysis>& result :
for (const core::RiskAnalysis::EtaResult& result :
risk_an.event_tree_results()) {
ReportResults(*result, &results);
ReportResults(result, &results);
}
}

Expand Down Expand Up @@ -336,11 +336,19 @@ void Reporter::ReportUnusedElements(const T& container,
information->AddChild("warning").AddText(header + out);
}

void Reporter::ReportResults(const core::EventTreeAnalysis& eta,
void Reporter::ReportResults(const core::RiskAnalysis::EtaResult& eta_result,
XmlStreamElement* results) {
const core::EventTreeAnalysis& eta = *eta_result.event_tree_analysis;
XmlStreamElement initiating_event = results->AddChild("initiating-event");
initiating_event.SetAttribute("name", eta.initiating_event().name())
.SetAttribute("sequences", eta.sequences().size());
initiating_event.SetAttribute("name", eta.initiating_event().name());

if (eta_result.context) {
initiating_event
.SetAttribute("alignment", eta_result.context->alignment.name())
.SetAttribute("phase", eta_result.context->phase.name());
}

initiating_event.SetAttribute("sequences", eta.sequences().size());
for (const core::EventTreeAnalysis::Result& result_sequence :
eta.sequences()) {
initiating_event.AddChild("sequence")
Expand Down
4 changes: 2 additions & 2 deletions src/reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ class Reporter {
/// Reports the results of event tree analysis
/// to a specified output destination.
///
/// @param[in] eta Event Tree Analysis with sequence results.
/// @param[in] eta_result Event Tree Analysis with sequence results.
/// @param[in,out] results XML element to for all results.
///
/// @pre The probability analysis has been performed.
void ReportResults(const core::EventTreeAnalysis& eta,
void ReportResults(const core::RiskAnalysis::EtaResult& eta_result,
XmlStreamElement* results);

/// Reports the results of fault tree analysis
Expand Down
3 changes: 2 additions & 1 deletion src/risk_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ void RiskAnalysis::RunAnalysis(boost::optional<Context> context) {
result.p_sequence = results_.back().probability_analysis->p_total();
LOG(INFO) << "Finished analysis for sequence: " << sequence.name();
}
event_tree_results_.push_back(std::move(eta));
event_tree_results_.push_back(
{*initiating_event, context, std::move(eta)});
LOG(INFO) << "Finished event tree analysis: " << initiating_event->name();
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/risk_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ class RiskAnalysis : public Analysis {
/// @}
};

/// The analysis results grouped by an event-tree.
///
/// @todo Replace with query (group_by).
struct EtaResult {
const mef::InitiatingEvent& initiating_event; ///< Unique event per tree.
boost::optional<Context> context; ///< The alignment context.
/// The holder of the analysis.
std::unique_ptr<const EventTreeAnalysis> event_tree_analysis;
};

/// @param[in] model An analysis model with fault trees, events, etc.
/// @param[in] settings Analysis settings for the given model.
///
Expand Down Expand Up @@ -99,8 +109,7 @@ class RiskAnalysis : public Analysis {
const std::vector<Result>& results() const { return results_; }

/// @returns The results of the event tree analysis.
const std::vector<std::unique_ptr<EventTreeAnalysis>>& event_tree_results()
const {
const std::vector<EtaResult>& event_tree_results() const {
return event_tree_results_;
}

Expand Down Expand Up @@ -146,9 +155,7 @@ class RiskAnalysis : public Analysis {

mef::Model* model_; ///< The model with constructs.
std::vector<Result> results_; ///< The analysis result storage.
/// Event tree analysis of sequences.
/// @todo Incorporate into the main results container.
std::vector<std::unique_ptr<EventTreeAnalysis>> event_tree_results_;
std::vector<EtaResult> event_tree_results_; ///< Grouping of sequences.
};

} // namespace core
Expand Down
11 changes: 10 additions & 1 deletion tests/risk_analysis_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ RiskAnalysisTest::product_probability() {
}

std::map<std::string, double> RiskAnalysisTest::sequences() {
assert(model->alignments().empty());
assert(analysis->event_tree_results().size() == 1);
std::map<std::string, double> results;
for (const core::EventTreeAnalysis::Result& result :
analysis->event_tree_results().front()->sequences()) {
analysis->event_tree_results()
.front()
.event_tree_analysis->sequences()) {
results.emplace(result.sequence.name(), result.p_sequence);
}
return results;
Expand Down Expand Up @@ -581,6 +584,12 @@ TEST_F(RiskAnalysisTest, ReportAlignment) {
CheckReport({tree_input});
}

TEST_F(RiskAnalysisTest, ReportAlignmentEventTree) {
std::string dir = "./share/scram/input/EventTrees/";
settings.probability_analysis(true);
CheckReport({dir + "attack_alignment.xml", dir + "attack.xml"});
}

// NAND and NOR as a child cases.
TEST_P(RiskAnalysisTest, ChildNandNorGates) {
std::string tree_input = "./share/scram/input/fta/children_nand_nor.xml";
Expand Down

0 comments on commit 636dab4

Please sign in to comment.