Skip to content

packages/engine/scram-node/src/fault_tree.h

Fault Tree and Component containers.

Namespaces

Name
scram
scram::mef

Classes

Name
classscram::mef::Component <br>Component is for logical grouping of events, gates, and other components.
classscram::mef::FaultTree <br>Fault tree representation as a container of gates, basic and house events, and other information.

Source code

cpp
/*
 * Copyright (C) 2014-2018 Olzhas Rakhimov
 * Copyright (C) 2023 OpenPRA ORG Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#pragma once

#include <memory>
#include <string>
#include <unordered_set>
#include <vector>

#include "ccf_group.h"
#include "element.h"
#include "event.h"
#include "parameter.h"

namespace scram::mef {

class Component
    : public Element,
      public Role,
      public Composite<Container<Component, Component, true, false>,
                       Container<Component, BasicEvent, false, false>,
                       Container<Component, HouseEvent, false, false>,
                       Container<Component, Gate, false, false>,
                       Container<Component, Parameter, false, false>,
                       Container<Component, CcfGroup, false, false>> {
 public:
  static constexpr const char* kTypeString = "component/fault tree";

  explicit Component(std::string name, std::string base_path = "",
                     RoleSpecifier role = RoleSpecifier::kPublic);

  virtual ~Component() = default;

  auto gates() const { return table<Gate>(); }
  auto basic_events() const { return table<BasicEvent>(); }
  auto house_events() const { return table<HouseEvent>(); }
  auto parameters() const { return table<Parameter>(); }
  auto ccf_groups() const { return table<CcfGroup>(); }
  auto components() const { return table<Component>(); }

  using Composite::Add;
  using Composite::Remove;

  void Add(Gate* element) { AddEvent(element); }
  void Add(BasicEvent* element) { AddEvent(element); }
  void Add(HouseEvent* element) { AddEvent(element); }
  void Add(CcfGroup* element);

 protected:
  void GatherGates(std::unordered_set<Gate*>* gates);

 private:
  template <class T>
  void AddEvent(T* element) {
    CheckDuplicateEvent(*element);
    Composite::Add(element);
  }

  void CheckDuplicateEvent(const Event& event);
};

class FaultTree : public Component {
 public:
  static constexpr const char* kTypeString = "fault tree";

  explicit FaultTree(const std::string& name);

  const std::vector<const Gate*>& top_events() const { return top_events_; }

  void CollectTopEvents();

 private:
  void MarkNonTopGates(Gate* gate, const std::unordered_set<Gate*>& gates);

  std::vector<const Gate*> top_events_;  
};

}  // namespace scram::mef

Updated on 2025-11-11 at 16:51:08 +0000