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 : #include "QuadratureSampler.h" 11 : #include "Distribution.h" 12 : 13 : registerMooseObjectAliased("StochasticToolsApp", QuadratureSampler, "Quadrature"); 14 : registerMooseObjectReplaced("StochasticToolsApp", 15 : QuadratureSampler, 16 : "07/01/2020 00:00", 17 : Quadrature); 18 : 19 : InputParameters 20 288 : QuadratureSampler::validParams() 21 : { 22 288 : InputParameters params = Sampler::validParams(); 23 288 : params.addClassDescription("Quadrature sampler for Polynomial Chaos."); 24 576 : params.addRequiredParam<unsigned int>( 25 : "order", "Specify the maximum order of the polynomials in the expansion."); 26 576 : MooseEnum grid("none smolyak clenshaw-curtis", "none"); 27 576 : params.addParam<MooseEnum>( 28 : "sparse_grid", grid, "Type of sparse grid to use, if none, full tensor product is used."); 29 576 : params.addRequiredParam<std::vector<DistributionName>>( 30 : "distributions", 31 : "The distribution names to be sampled, the number of distributions provided defines the " 32 : "number of columns per matrix and their type defines the quadrature."); 33 288 : return params; 34 288 : } 35 : 36 154 : QuadratureSampler::QuadratureSampler(const InputParameters & parameters) : Sampler(parameters) 37 : { 38 : // For each distribution, get the 1-D quadrature 39 : std::vector<std::unique_ptr<const PolynomialQuadrature::Polynomial>> poly_1d; 40 784 : for (auto dname : getParam<std::vector<DistributionName>>("distributions")) 41 952 : poly_1d.push_back(PolynomialQuadrature::makePolynomial(&getDistributionByName(dname))); 42 : 43 : // Here, we take the 1-D quadratures and perform a tensor product for multi-D integration 44 308 : switch (getParam<MooseEnum>("sparse_grid")) 45 : { 46 138 : case 0: 47 : { 48 138 : _grid = std::make_unique<const PolynomialQuadrature::TensorGrid>( 49 276 : getParam<unsigned int>("order") + 1, poly_1d); 50 138 : break; 51 : } 52 8 : case 1: 53 : { 54 24 : _grid = std::make_unique<const PolynomialQuadrature::SmolyakGrid>( 55 8 : getParam<unsigned int>("order"), poly_1d); 56 8 : break; 57 : } 58 8 : case 2: 59 : { 60 24 : _grid = std::make_unique<const PolynomialQuadrature::ClenshawCurtisGrid>( 61 8 : getParam<unsigned int>("order"), poly_1d); 62 8 : break; 63 : } 64 : paramError("sparse_grid", "Unknown or unimplemented sparse grid type."); 65 : } 66 : 67 154 : setNumberOfRows(_grid->nPoints()); 68 154 : setNumberOfCols(_grid->nDim()); 69 154 : } 70 : 71 : Real 72 1026200 : QuadratureSampler::computeSample(dof_id_type row_index, dof_id_type col_index) 73 : { 74 1026200 : return _grid->quadraturePoint(row_index, col_index); 75 : } 76 : 77 : Real 78 87590 : QuadratureSampler::getQuadratureWeight(dof_id_type row_index) const 79 : { 80 87590 : return _grid->quadratureWeight(row_index); 81 : }