https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SobolSampler.C
Go to the documentation of this file.
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#include "SobolSampler.h"
11#include "Distribution.h"
12
13registerMooseObjectAliased("StochasticToolsApp", SobolSampler, "Sobol");
14registerMooseObjectReplaced("StochasticToolsApp", SobolSampler, "07/01/2020 00:00", Sobol);
15
18{
20 params.addClassDescription("Sobol variance-based sensitivity analysis Sampler.");
21 params.addParam<bool>("resample", true, "Create the re-sample matrix for second-order indices.");
22 params.addRequiredParam<SamplerName>("sampler_a", "The 'sample' matrix.");
23 params.addRequiredParam<SamplerName>("sampler_b", "The 're-sample' matrix.");
24 return params;
25}
26
28 : Sampler(parameters),
29 _sampler_a(getSampler("sampler_a")),
30 _sampler_b(getSampler("sampler_b")),
31 _resample(getParam<bool>("resample")),
32 _num_matrices(_resample ? 2 * _sampler_a.getNumberOfCols() + 2
33 : _sampler_a.getNumberOfCols() + 2)
34{
36 paramError("sampler_a", "The supplied Sampler objects must have the same number of columns.");
37
39 paramError("sampler_a", "The supplied Sampler objects must have the same number of rows.");
40
41 if (_sampler_a.name() == _sampler_b.name())
42 paramError("sampler_a", "The supplied sampler matrices must not be the same.");
43
44 // Initialize this object
47}
48
49Real
50SobolSampler::computeSample(dof_id_type row_index, dof_id_type col_index) const
51{
52 const dof_id_type base_row = row_index / _num_matrices;
53 const dof_id_type matrix_index = row_index % _num_matrices;
54
55 // M2 Matrix
56 if (matrix_index == 0)
57 return _sampler_b.getSample(base_row, col_index);
58
59 // M1 Matrix
60 else if (matrix_index == _num_matrices - 1)
61 return _sampler_a.getSample(base_row, col_index);
62
63 // N_-i Matrices
64 else if (matrix_index > getNumberOfCols())
65 {
66 if (col_index == (matrix_index - getNumberOfCols() - 1))
67 return _sampler_b.getSample(base_row, col_index);
68 else
69 return _sampler_a.getSample(base_row, col_index);
70 }
71
72 // N_i Matrices
73 else
74 {
75 if (col_index == matrix_index - 1)
76 return _sampler_a.getSample(base_row, col_index);
77 else
78 return _sampler_b.getSample(base_row, col_index);
79 }
80}
81
84{
85 std::vector<LocalRankConfig> all_rc(processor_id() + 1);
86 for (processor_id_type r = 0; r <= processor_id(); ++r)
87 all_rc[r] = rankConfig(r,
92 batch_mode);
93 LocalRankConfig & rc = all_rc.back();
94
96 bool found_first = false;
97 for (auto it = all_rc.rbegin(); it != all_rc.rend(); ++it)
98 if (it->is_first_local_rank)
99 {
100 if (found_first)
101 rc.first_local_sim_index += it->num_local_sims * (_num_matrices - 1);
102 else
103 found_first = true;
104 }
105
106 if (!batch_mode)
107 {
110 }
111
112 return rc;
113}
LocalRankConfig rankConfig(processor_id_type rank, processor_id_type nprocs, dof_id_type napps, processor_id_type min_app_procs, processor_id_type max_app_procs, bool batch_mode=false)
registerMooseObjectAliased("StochasticToolsApp", SobolSampler, "Sobol")
registerMooseObjectReplaced("StochasticToolsApp", SobolSampler, "07/01/2020 00:00", Sobol)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
const std::string & name() const
void paramError(const std::string &param, Args... args) const
void setNumberOfCols(dof_id_type n_cols)
Real getSample(dof_id_type row_index, dof_id_type col_index) const
const dof_id_type _max_procs_per_row
dof_id_type getNumberOfRows() const
static InputParameters validParams()
dof_id_type getNumberOfCols() const
void setNumberOfRows(dof_id_type n_rows)
const dof_id_type _min_procs_per_row
A class used to perform Monte Carlo sampling for performing Sobol sensitivity analysis.
virtual Real computeSample(dof_id_type row_index, dof_id_type col_index) const override
SobolSampler(const InputParameters &parameters)
Sampler & _sampler_a
Sampler matrix.
virtual LocalRankConfig constructRankConfig(bool batch_mode) const override
Sobol sampling should have a slightly different partitioning in order to keep the sample and resample...
Sampler & _sampler_b
Re-sample matrix.
const dof_id_type _num_matrices
Number of matrices.
static InputParameters validParams()
processor_id_type processor_id() const
processor_id_type n_processors() const
dof_id_type num_local_sims
dof_id_type first_local_sim_index
dof_id_type num_local_apps
dof_id_type first_local_app_index