Skip to content

Commit

Permalink
Add event tree Initiating Event
Browse files Browse the repository at this point in the history
Issue #150
  • Loading branch information
rakhimov committed Apr 30, 2017
1 parent b52adaa commit 6b2d8bf
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 3 deletions.
16 changes: 16 additions & 0 deletions share/input.rng
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<choice>
<ref name="model-data"/>
<ref name="event-tree-definition"/>
<ref name="initiating-event-definition"/>
<ref name="fault-tree-definition"/>
<ref name="CCF-group-definition"/>
</choice>
Expand Down Expand Up @@ -92,6 +93,21 @@
<!-- II.1. Initiating events, Initiating event Groups -->
<!-- ============================================================= -->

<define name="initiating-event-definition">
<element name="define-initiating-event">
<ref name="name"/>
<optional>
<attribute name="event-tree"> <ref name="Identifier"/> </attribute>
</optional>
<optional>
<ref name="label"/>
</optional>
<optional>
<ref name="attributes"/>
</optional>
</element>
</define>


<!-- ============================================================= -->
<!-- II.2. Event Trees -->
Expand Down
29 changes: 28 additions & 1 deletion src/event_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,34 @@ class EventTree : public Element, private boost::noncopyable {
std::vector<std::unique_ptr<Fork>> forks_; ///< Lifetime management of forks.
};

using EventTreePtr = std::unique_ptr<EventTree>; ///< Unique trees in models.
using EventTreePtr = std::unique_ptr<EventTree>; ///< Unique trees in a model.

/// Event-tree Initiating Event.
class InitiatingEvent : public Element {
public:
using Element::Element;

/// Associates an event tree to the initiating event.
///
/// @param[in] event_tree Fully initialized event tree container.
void event_tree(EventTree* event_tree) {
assert(!event_tree_ && event_tree && "Resetting or un-setting event tree.");
event_tree_ = event_tree;
}

/// @returns The event tree of the initiating event.
/// nullptr if the event tree is not set.
/// @{
EventTree* event_tree() const { return event_tree_; }
EventTree* event_tree() { return event_tree_; }
/// @}

private:
EventTree* event_tree_ = nullptr; ///< The optional event tree specification.
};

/// Unique initiating events in a model.
using InitiatingEventPtr = std::unique_ptr<InitiatingEvent>;

} // namespace mef
} // namespace scram
Expand Down
23 changes: 23 additions & 0 deletions src/initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,15 @@ void Initializer::ProcessInputFile(const std::string& xml_file) {
model_->mission_time()->value(settings_.mission_time());
}

for (const xmlpp::Node* node : root->find("./define-initiating-event")) {
const xmlpp::Element* xml_node = XmlElement(node);
InitiatingEventPtr initiating_event =
ConstructElement<InitiatingEvent>(xml_node);
auto* ref_ptr = initiating_event.get();
Register(std::move(initiating_event), xml_node);
tbd_.emplace_back(ref_ptr, xml_node);
}

for (const xmlpp::Node* node : root->find("./define-event-tree")) {
DefineEventTree(XmlElement(node));
}
Expand Down Expand Up @@ -449,6 +458,20 @@ void Initializer::Define(const xmlpp::Element* et_node, EventTree* event_tree) {
DefineBranch(state_node.front()->find("./*"), event_tree, &initial_state);
event_tree->initial_state(std::move(initial_state));
}

template <>
void Initializer::Define(const xmlpp::Element* xml_node,
InitiatingEvent* initiating_event) {
std::string event_tree_name = GetAttributeValue(xml_node, "event-tree");
if (!event_tree_name.empty()) {
if (auto it = ext::find(model_->event_trees(), event_tree_name)) {
initiating_event->event_tree(it->get());
} else {
throw ValidationError(GetLine(xml_node) + "Event tree " +
event_tree_name + " is not defined in model.");
}
}
}
/// @}

void Initializer::ProcessTbdElements() {
Expand Down
5 changes: 4 additions & 1 deletion src/initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,12 @@ class Initializer : private boost::noncopyable {
/// Gates rely on gate, basic event, and house event registrations.
/// CCF groups rely on both parameter and basic event registrations.
/// Event tree branches and instructions have complex interdependencies.
/// Initiating events may reference their associated event trees.
///
/// Elements are assumed to be unique.
TbdContainer<Parameter, BasicEvent, Gate, CcfGroup, Sequence, EventTree> tbd_;
TbdContainer<Parameter, BasicEvent, Gate, CcfGroup, Sequence, EventTree,
InitiatingEvent>
tbd_;

/// Container of defined expressions for later validation due to cycles.
std::vector<std::pair<Expression*, const xmlpp::Element*>> expressions_;
Expand Down
6 changes: 6 additions & 0 deletions src/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Model::Model(std::string name)
: Element(name.empty() ? kDefaultName : std::move(name)),
mission_time_(std::make_shared<MissionTime>()) {}

void Model::Add(InitiatingEventPtr initiating_event) {
mef::AddElement<RedefinitionError>(std::move(initiating_event),
&initiating_events_,
"Redefinition of initiating event: ");
}

void Model::Add(EventTreePtr event_tree) {
mef::AddElement<RedefinitionError>(std::move(event_tree), &event_trees_,
"Redefinition of event tree: ");
Expand Down
5 changes: 5 additions & 0 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class Model : public Element, private boost::noncopyable {

/// @returns Defined constructs in the model.
/// @{
const ElementTable<InitiatingEventPtr>& initiating_events() const {
return initiating_events_;
}
const ElementTable<EventTreePtr>& event_trees() const { return event_trees_; }
const ElementTable<SequencePtr>& sequences() const { return sequences_; }
const ElementTable<FaultTreePtr>& fault_trees() const { return fault_trees_; }
Expand All @@ -85,6 +88,7 @@ class Model : public Element, private boost::noncopyable {
/// @throws RedefinitionError The element is already defined in the model.
///
/// @{
void Add(InitiatingEventPtr element);
void Add(EventTreePtr element);
void Add(const FunctionalEventPtr& element);
void Add(const SequencePtr& element);
Expand Down Expand Up @@ -175,6 +179,7 @@ class Model : public Element, private boost::noncopyable {

/// A collection of defined constructs in the model.
/// @{
ElementTable<InitiatingEventPtr> initiating_events_;
ElementTable<EventTreePtr> event_trees_;
ElementTable<SequencePtr> sequences_;
ElementTable<FaultTreePtr> fault_trees_;
Expand Down
1 change: 1 addition & 0 deletions src/reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ void Reporter::ReportModelFeatures(const mef::Model& model,
model_features.AddChild("functional-events").AddText(num_functional_events);

feature("sequences", model.sequences());
feature("initiating-events", model.initiating_events());
}

void Reporter::ReportPerformance(const core::RiskAnalysis& risk_an,
Expand Down
5 changes: 4 additions & 1 deletion tests/initializer_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ TEST(InitializerTest, EmptyAttributeElementText) {
TEST(InitializerTest, CorrectEtaInputs) {
std::string dir = "./share/scram/input/eta/";
const char* correct_inputs[] = {"simplest_correct.xml",
"public_sequence.xml"};
"public_sequence.xml",
"initiating_event.xml"};
for (const auto& input : correct_inputs) {
EXPECT_NO_THROW(Initializer({dir + input}, core::Settings()))
<< " Filename: " << input;
Expand All @@ -95,10 +96,12 @@ TEST(InitializerTest, CorrectEtaInputs) {
TEST(InitializerTest, IncorrectEtaInputs) {
std::string dir = "./share/scram/input/eta/";
const char* incorrect_inputs[] = {
"doubly_defined_initiating_event.xml",
"doubly_defined_event_tree.xml",
"doubly_defined_sequence.xml",
"doubly_defined_functional_event.xml",
"doubly_defined_branch.xml",
"undefined_event_tree.xml",
"undefined_sequence.xml",
"undefined_branch.xml",
"undefined_functional_event.xml",
Expand Down
5 changes: 5 additions & 0 deletions tests/input/eta/doubly_defined_initiating_event.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<opsa-mef>
<define-initiating-event name="I"/>
<define-initiating-event name="I"/>
</opsa-mef>
4 changes: 4 additions & 0 deletions tests/input/eta/initiating_event.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<opsa-mef>
<define-initiating-event name="I"/>
</opsa-mef>
4 changes: 4 additions & 0 deletions tests/input/eta/undefined_event_tree.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<opsa-mef>
<define-initiating-event name="I" event-tree="E"/>
</opsa-mef>

0 comments on commit 6b2d8bf

Please sign in to comment.