Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "Sampler.h" 13 : #include "ReporterInterface.h" 14 : 15 : /** 16 : * A class used to perform Parallel Subset Simulation Sampling 17 : */ 18 : class ParallelSubsetSimulation : public Sampler 19 : { 20 : public: 21 : static InputParameters validParams(); 22 : 23 : ParallelSubsetSimulation(const InputParameters & parameters); 24 : 25 : /// Access the number samples per subset 26 : const unsigned int & getNumSamplesSub() const; 27 : 28 : /// Access use absolute value bool 29 : const bool & getUseAbsoluteValue() const; 30 : 31 : /// Access the subset probability 32 : const Real & getSubsetProbability() const; 33 : 34 : /** 35 : * Returns true if the adaptive sampling is completed 36 : */ 37 96 : virtual bool isAdaptiveSamplingCompleted() const override { return _is_sampling_completed; } 38 : 39 : protected: 40 : virtual void sampleSetUp(const Sampler::SampleMode mode) override; 41 : virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) override; 42 : 43 : /// Number of samples per subset 44 : const unsigned int & _num_samplessub; 45 : 46 : /// Number of subsets 47 : const unsigned int & _num_subsets; 48 : 49 : /// Absolute value of the model result. Use this when failure is defined as a non-exceedance rather than an exceedance. 50 : const bool & _use_absolute_value; 51 : 52 : /// The subset conditional failure probability 53 : const Real & _subset_probability; 54 : 55 : /// Initialize a certain number of random seeds. Change from the default only if you have to. 56 : const unsigned int & _num_random_seeds; 57 : 58 : /// Reporter value containing calculated outputs 59 : const std::vector<Real> & _outputs; 60 : 61 : /// Reporter value containing input values from decision reporter 62 : const std::vector<std::vector<Real>> & _inputs; 63 : 64 : /// Track the current step of the main App 65 : const int & _step; 66 : 67 : /// Maximum length of markov chains based on subset probability 68 : const unsigned int _count_max; 69 : 70 : /// Ensure that the MCMC algorithm proceeds in a sequential fashion 71 : int _check_step; 72 : 73 : /// Track the current subset index 74 : unsigned int _subset; 75 : 76 : /// Storage for distribution objects to be utilized 77 : std::vector<Distribution const *> _distributions; 78 : 79 : /// True if the sampling is completed 80 : bool _is_sampling_completed; 81 : 82 : private: 83 : /// Storage for the previously accepted sample inputs across all the subsets 84 : std::vector<std::vector<Real>> _inputs_sto; 85 : 86 : /// Storage for previously accepted sample outputs across all the subsets 87 : std::vector<Real> _outputs_sto; 88 : 89 : /// Store the sorted input samples according to their corresponding outputs 90 : std::vector<std::vector<Real>> _inputs_sorted; 91 : 92 : /// Mean input vector for the next proposed sample inputs across several processors 93 : std::vector<std::vector<Real>> _markov_seed; 94 : };