Skip to content

packages/engine/scram/src/risk_analysis.h

Contains the main system for performing analysis.

Namespaces

Name
scram
scram::core

Classes

Name
classscram::core::RiskAnalysis <br>Main system that performs analyses.
structscram::core::RiskAnalysis::Context <br>Provides the optional context of the analysis.
structscram::core::RiskAnalysis::Result <br>The analysis results binding to the unique analysis target.
structscram::core::RiskAnalysis::Result::Id <br>The analysis target type as a unique identifier.
structscram::core::RiskAnalysis::EtaResult <br>The analysis results grouped by an event-tree.
structscram::core::RiskAnalysis::RuntimeMetrics <br>Captures high-level runtime diagnostics for the overall analysis pass.

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 <utility>
#include <variant>
#include <vector>
#include <unordered_set>

#include "alignment.h"
#include "analysis.h"
#include "event.h"
#include "event_tree_analysis.h"
#include "fault_tree_analysis.h"
#include "importance_analysis.h"
#include "model.h"
#include "probability_analysis.h"
#include "settings.h"
#include "uncertainty_analysis.h"

namespace scram::core {

class RiskAnalysis : public Analysis {
 public:
  struct Context {
    const mef::Alignment& alignment;  
    const mef::Phase& phase;  
  };

  struct Result {
    struct Id {
      std::variant<const mef::Gate*, std::pair<const mef::InitiatingEvent&, const mef::Sequence&>> target;  
      std::optional<Context> context;  
    };

    const Id id;  

    std::unique_ptr<const FaultTreeAnalysis> fault_tree_analysis;
    std::unique_ptr<const ProbabilityAnalysis> probability_analysis;
    std::unique_ptr<const ImportanceAnalysis> importance_analysis;
    std::unique_ptr<const UncertaintyAnalysis> uncertainty_analysis;
    
    std::optional<double> preprocessing_seconds;  
    std::optional<double> report_generation_seconds;  
  };

  struct EtaResult {
    const mef::InitiatingEvent& initiating_event;  
    std::optional<Context> context;  
    std::unique_ptr<const EventTreeAnalysis> event_tree_analysis;
  };

  struct RuntimeMetrics {
    double analysis_seconds = 0.0;  
    std::optional<double> total_runtime_seconds;  
    std::optional<double> post_analysis_rss_mib;  
    std::optional<double> post_analysis_peak_rss_mib;  
    std::optional<double> post_run_rss_mib;  
    std::optional<double> post_run_peak_rss_mib;  
  };

  RiskAnalysis(mef::Model* model, const Settings& settings);

  const mef::Model& model() const { return *model_; }

  void Analyze();

  const std::vector<Result>& results() const { return results_; }

  const std::vector<EtaResult>& event_tree_results() const {
    return event_tree_results_;
  }

  void set_runtime_metrics(RuntimeMetrics metrics);

  const std::optional<RuntimeMetrics>& runtime_metrics() const {
    return runtime_metrics_;
  }

 private:
  void RunAnalysis(const std::optional<Context> &context = {}) ;

  void RunAnalysis(const mef::Gate& target, Result* result, double initiating_frequency = 1.0) ;

  template <class Algorithm>
  void RunAnalysis(const mef::Gate& target, Result* result, double initiating_frequency = 1.0) ;

  template <class Algorithm, class Calculator>
  void RunAnalysis(FaultTreeAnalyzer<Algorithm>* fta, Result* result) ;

  mef::Model* model_;  
  std::vector<Result> results_;  
  std::vector<EtaResult> event_tree_results_;  

  std::optional<RuntimeMetrics> runtime_metrics_;
};

}  // namespace scram::core

Updated on 2026-01-09 at 21:59:13 +0000