LCOV - code coverage report
Current view: top level - src/samplers - QuadratureSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose stochastic_tools: #31405 (292dce) with base fef103 Lines: 32 32 100.0 %
Date: 2025-09-04 07:57:52 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         758 : QuadratureSampler::validParams()
      21             : {
      22         758 :   InputParameters params = Sampler::validParams();
      23         758 :   params.addClassDescription("Quadrature sampler for Polynomial Chaos.");
      24        1516 :   params.addRequiredParam<unsigned int>(
      25             :       "order", "Specify the maximum order of the polynomials in the expansion.");
      26        1516 :   MooseEnum grid("none smolyak clenshaw-curtis", "none");
      27        1516 :   params.addParam<MooseEnum>(
      28             :       "sparse_grid", grid, "Type of sparse grid to use, if none, full tensor product is used.");
      29        1516 :   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         758 :   return params;
      34         758 : }
      35             : 
      36         436 : 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        2227 :   for (auto dname : getParam<std::vector<DistributionName>>("distributions"))
      41        2710 :     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         872 :   switch (getParam<MooseEnum>("sparse_grid"))
      45             :   {
      46         390 :     case 0:
      47             :     {
      48         390 :       _grid = std::make_unique<const PolynomialQuadrature::TensorGrid>(
      49         780 :           getParam<unsigned int>("order") + 1, poly_1d);
      50         390 :       break;
      51             :     }
      52          23 :     case 1:
      53             :     {
      54          69 :       _grid = std::make_unique<const PolynomialQuadrature::SmolyakGrid>(
      55          23 :           getParam<unsigned int>("order"), poly_1d);
      56          23 :       break;
      57             :     }
      58          23 :     case 2:
      59             :     {
      60          69 :       _grid = std::make_unique<const PolynomialQuadrature::ClenshawCurtisGrid>(
      61          23 :           getParam<unsigned int>("order"), poly_1d);
      62          23 :       break;
      63             :     }
      64             :       paramError("sparse_grid", "Unknown or unimplemented sparse grid type.");
      65             :   }
      66             : 
      67         436 :   setNumberOfRows(_grid->nPoints());
      68         436 :   setNumberOfCols(_grid->nDim());
      69         436 : }
      70             : 
      71             : Real
      72     2257640 : QuadratureSampler::computeSample(dof_id_type row_index, dof_id_type col_index)
      73             : {
      74     2257640 :   return _grid->quadraturePoint(row_index, col_index);
      75             : }
      76             : 
      77             : Real
      78      192698 : QuadratureSampler::getQuadratureWeight(dof_id_type row_index) const
      79             : {
      80      192698 :   return _grid->quadratureWeight(row_index);
      81             : }

Generated by: LCOV version 1.14