Skip to content

packages/engine/scram-node/src/ccf_group.h ​

Functional containers for basic events grouped by common cause failure. More...

Namespaces ​

Name
scram
scram::mef

Classes ​

Name
classscram::mef::CcfEvent <br>A basic event that represents a multiple failure of a group of events due to a common cause.
classscram::mef::CcfGroup <br>Abstract base class for all common cause failure models.
classscram::mef::BetaFactorModel <br>Common cause failure model that assumes, if common cause failure occurs, then all components or members fail simultaneously or within short time.
classscram::mef::MglModel <br>Multiple Greek Letters model characterizes failure of sub-groups of the group due to common cause.
classscram::mef::AlphaFactorModel <br>Alpha factor model characterizes failure of exactly k members of the group due to common cause.
classscram::mef::PhiFactorModel <br>Phi factor model is a simplification, where fractions of k-member group failure is given directly.

Detailed Description ​

Functional containers for basic events grouped by common cause failure.

Common cause failure can be modeled with alpha, beta, MGL, or direct parameter assignment in phi model.

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 <optional>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

#include "element.h"
#include "event.h"
#include "expression.h"

namespace scram::mef {

class CcfGroup;  // CCF Events know their own groups.

class CcfEvent : public BasicEvent {
 public:
  CcfEvent(std::vector<Gate*> members, const CcfGroup* ccf_group);

  const CcfGroup& ccf_group() const { return ccf_group_; }

  const std::vector<Gate*>& members() const { return members_; }

 private:
  static std::string MakeName(const std::vector<Gate*>& members);

  const CcfGroup& ccf_group_;  
  std::vector<Gate*> members_;  
};

class CcfGroup : public Id {
 public:
  static constexpr const char* kTypeString = "CCF group";

  using Id::Id;

  virtual ~CcfGroup() = default;

  const std::vector<BasicEvent*>& members() const { return members_; }

  void AddMember(BasicEvent* basic_event);

  void AddDistribution(Expression* distr);

  void AddFactor(Expression* factor, std::optional<int> level = {});

  void Validate() const;

  void ApplyModel();

 protected:
  using ExpressionMap = std::vector<std::pair<int, Expression*>>;

  Expression* distribution() const { return distribution_; }

  const ExpressionMap& factors() const { return factors_; }

  template <class T, typename... Ts>
  Expression* Register(Ts&&... args) {
    expressions_.emplace_back(std::make_unique<T>(std::forward<Ts>(args)...));
    return expressions_.back().get();
  }
  template <class T>
  Expression* Register(std::initializer_list<Expression*> args) {
    expressions_.emplace_back(std::make_unique<T>(args));
    return expressions_.back().get();
  }

 private:
  virtual int min_level() const { return 1; }

  virtual void DoValidate() const {}

  virtual ExpressionMap CalculateProbabilities() = 0;

  int prev_level_ = 0;  
  Expression* distribution_ = nullptr;  
  std::vector<BasicEvent*> members_;  
  ExpressionMap factors_;  
  std::vector<std::unique_ptr<Expression>> expressions_;
  std::vector<std::unique_ptr<CcfEvent>> ccf_events_;
};

class BetaFactorModel : public CcfGroup {
 public:
  using CcfGroup::CcfGroup;

 private:
  int min_level() const override { return CcfGroup::members().size(); }

  ExpressionMap CalculateProbabilities() override;
};

class MglModel : public CcfGroup {
 public:
  using CcfGroup::CcfGroup;

 private:
  int min_level() const override { return 2; }

  ExpressionMap CalculateProbabilities() override;
};

class AlphaFactorModel : public CcfGroup {
 public:
  using CcfGroup::CcfGroup;

 private:
  ExpressionMap CalculateProbabilities() override;
};

class PhiFactorModel : public CcfGroup {
 public:
  using CcfGroup::CcfGroup;

 private:
  void DoValidate() const override;

  ExpressionMap CalculateProbabilities() override;
};

}  // namespace scram::mef

Updated on 2025-12-19 at 21:56:46 +0000