LCOV - code coverage report
Current view: top level - src/samplers - QuadratureSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: f45d79 Lines: 32 32 100.0 %
Date: 2025-07-25 05:00:46 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          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         718 : QuadratureSampler::validParams()
      21             : {
      22         718 :   InputParameters params = Sampler::validParams();
      23         718 :   params.addClassDescription("Quadrature sampler for Polynomial Chaos.");
      24        1436 :   params.addRequiredParam<unsigned int>(
      25             :       "order", "Specify the maximum order of the polynomials in the expansion.");
      26        1436 :   MooseEnum grid("none smolyak clenshaw-curtis", "none");
      27        1436 :   params.addParam<MooseEnum>(
      28             :       "sparse_grid", grid, "Type of sparse grid to use, if none, full tensor product is used.");
      29        1436 :   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         718 :   return params;
      34         718 : }
      35             : 
      36         416 : 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        2126 :   for (auto dname : getParam<std::vector<DistributionName>>("distributions"))
      41        2588 :     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         832 :   switch (getParam<MooseEnum>("sparse_grid"))
      45             :   {
      46         372 :     case 0:
      47             :     {
      48         372 :       _grid = std::make_unique<const PolynomialQuadrature::TensorGrid>(
      49         744 :           getParam<unsigned int>("order") + 1, poly_1d);
      50         372 :       break;
      51             :     }
      52          22 :     case 1:
      53             :     {
      54          66 :       _grid = std::make_unique<const PolynomialQuadrature::SmolyakGrid>(
      55          22 :           getParam<unsigned int>("order"), poly_1d);
      56          22 :       break;
      57             :     }
      58          22 :     case 2:
      59             :     {
      60          66 :       _grid = std::make_unique<const PolynomialQuadrature::ClenshawCurtisGrid>(
      61          22 :           getParam<unsigned int>("order"), poly_1d);
      62          22 :       break;
      63             :     }
      64             :       paramError("sparse_grid", "Unknown or unimplemented sparse grid type.");
      65             :   }
      66             : 
      67         416 :   setNumberOfRows(_grid->nPoints());
      68         416 :   setNumberOfCols(_grid->nDim());
      69         416 : }
      70             : 
      71             : Real
      72     2052400 : QuadratureSampler::computeSample(dof_id_type row_index, dof_id_type col_index)
      73             : {
      74     2052400 :   return _grid->quadraturePoint(row_index, col_index);
      75             : }
      76             : 
      77             : Real
      78      175180 : QuadratureSampler::getQuadratureWeight(dof_id_type row_index) const
      79             : {
      80      175180 :   return _grid->quadratureWeight(row_index);
      81             : }

Generated by: LCOV version 1.14