LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - SamplerData.C (source / functions) Hit Total Coverage
Test: stochastic_tools Test Coverage Lines: 33 33 100.0 %
Date: 2017-11-21 14:52:30 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /****************************************************************/
       2             : /* MOOSE - Multiphysics Object Oriented Simulation Environment  */
       3             : /*                                                              */
       4             : /*          All contents are licensed under LGPL V2.1           */
       5             : /*             See LICENSE for full restrictions                */
       6             : /****************************************************************/
       7             : 
       8             : // Stocastic Tools Includes
       9             : #include "SamplerData.h"
      10             : 
      11             : // MOOSE includes
      12             : #include "Sampler.h"
      13             : 
      14             : template <>
      15             : InputParameters
      16           5 : validParams<SamplerData>()
      17             : {
      18           5 :   InputParameters params = validParams<GeneralVectorPostprocessor>();
      19          10 :   params.addClassDescription(
      20           5 :       "Tool for extracting Sampler object data and storing in VectorPostprocessor vectors.");
      21           5 :   params += validParams<SamplerInterface>();
      22          15 :   params.addRequiredParam<SamplerName>("sampler",
      23           5 :                                        "The sample from which to extract distribution data.");
      24          15 :   params.addParam<bool>("output_column_and_row_sizes",
      25             :                         false,
      26             :                         "Whether to output the number of "
      27             :                         "columns and rows in the matrix in "
      28           5 :                         "the first two rows of output");
      29           5 :   return params;
      30             : }
      31             : 
      32           5 : SamplerData::SamplerData(const InputParameters & parameters)
      33             :   : GeneralVectorPostprocessor(parameters),
      34             :     SamplerInterface(this),
      35          10 :     _sampler(getSampler("sampler")),
      36          25 :     _output_col_row_sizes(getParam<bool>("output_column_and_row_sizes"))
      37             : {
      38           5 : }
      39             : 
      40             : void
      41          10 : SamplerData::initialize()
      42             : {
      43          15 :   for (auto ptr : _sample_vectors)
      44             :     ptr->clear();
      45          10 : }
      46             : 
      47             : void
      48          10 : SamplerData::execute()
      49             : {
      50          20 :   std::vector<DenseMatrix<Real>> data = _sampler.getSamples();
      51             :   auto n = data.size();
      52          10 :   if (_sample_vectors.empty())
      53             :   {
      54           5 :     _sample_vectors.resize(n);
      55          31 :     for (auto i = beginIndex(data); i < n; ++i)
      56             :     {
      57          26 :       std::string name = "mat_" + std::to_string(i);
      58          13 :       _sample_vectors[i] = &declareVector(name);
      59             :     }
      60             :   }
      61             : 
      62          46 :   for (auto i = beginIndex(data); i < n; ++i)
      63             :   {
      64          18 :     const std::size_t offset = _output_col_row_sizes ? 2 : 0;
      65          18 :     const std::size_t vec_size = data[i].get_values().size() + offset;
      66          18 :     _sample_vectors[i]->resize(vec_size);
      67          18 :     if (_output_col_row_sizes)
      68             :     {
      69          10 :       (*_sample_vectors[i])[0] = data[i].n(); // number of columns
      70           5 :       (*_sample_vectors[i])[1] = data[i].m(); // number of rows
      71             :     }
      72             :     std::copy(data[i].get_values().begin(),
      73             :               data[i].get_values().end(),
      74          18 :               _sample_vectors[i]->begin() + offset);
      75             :   }
      76        1822 : }

Generated by: LCOV version 1.11