LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - LineFunctionSampler.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 38 39 97.4 %
Date: 2025-07-17 01:28:37 Functions: 5 5 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 "LineFunctionSampler.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "Function.h"
      14             : #include "LineValueSampler.h"
      15             : 
      16             : registerMooseObject("MooseApp", LineFunctionSampler);
      17             : 
      18             : InputParameters
      19       14649 : LineFunctionSampler::validParams()
      20             : {
      21       14649 :   InputParameters params = GeneralVectorPostprocessor::validParams();
      22       14649 :   params.addClassDescription("Sample one or more functions along a line.");
      23       14649 :   params += SamplerBase::validParams();
      24             : 
      25       14649 :   params.addRequiredParam<Point>("start_point", "The beginning of the line");
      26       14649 :   params.addRequiredParam<Point>("end_point", "The ending of the line");
      27             : 
      28       14649 :   params.addRequiredParam<unsigned int>("num_points",
      29             :                                         "The number of points to sample along the line");
      30             : 
      31       14649 :   params.addRequiredParam<std::vector<FunctionName>>("functions",
      32             :                                                      "The Functions to sample along the line");
      33             : 
      34       14649 :   return params;
      35           0 : }
      36             : 
      37         192 : LineFunctionSampler::LineFunctionSampler(const InputParameters & parameters)
      38             :   : GeneralVectorPostprocessor(parameters),
      39             :     SamplerBase(parameters, this, _communicator),
      40         192 :     _start_point(getParam<Point>("start_point")),
      41         192 :     _end_point(getParam<Point>("end_point")),
      42         192 :     _num_points(getParam<unsigned int>("num_points")),
      43         192 :     _function_names(getParam<std::vector<FunctionName>>("functions")),
      44         192 :     _num_funcs(_function_names.size()),
      45         192 :     _functions(_num_funcs),
      46         384 :     _values(_num_funcs)
      47             : {
      48             :   // Get the Functions
      49         528 :   for (unsigned int i = 0; i < _num_funcs; i++)
      50         336 :     _functions[i] = &getFunctionByName(_function_names[i]);
      51             : 
      52             :   // Unfortunately, std::vector<FunctionName> can't be cast to std::vector<std::string>...
      53         192 :   std::vector<std::string> function_name_strings(_num_funcs);
      54         528 :   for (unsigned int i = 0; i < _num_funcs; i++)
      55         336 :     function_name_strings[i] = _function_names[i];
      56             : 
      57             :   // Initialize the datastructions in SamplerBase
      58         192 :   SamplerBase::setupVariables(function_name_strings);
      59             : 
      60             :   // Generate points along the line
      61         192 :   LineValueSampler::generatePointsAndIDs(_start_point, _end_point, _num_points, _points, _ids);
      62         192 : }
      63             : 
      64             : void
      65         374 : LineFunctionSampler::initialize()
      66             : {
      67         374 :   SamplerBase::initialize();
      68         374 : }
      69             : 
      70             : void
      71         374 : LineFunctionSampler::execute()
      72             : {
      73         374 :   if (processor_id() == 0) // Only sample on processor zero for now
      74             :   {
      75             :     // TODO: Thread this when we finally move to C++11
      76        1808 :     for (unsigned int p = 0; p < _num_points; p++)
      77             :     {
      78        4032 :       for (unsigned int i = 0; i < _num_funcs; i++)
      79        2496 :         _values[i] = _functions[i]->value(_t, _points[p]);
      80             : 
      81        1536 :       SamplerBase::addSample(_points[p], _ids[p], _values);
      82             :     }
      83             :   }
      84         374 : }
      85             : 
      86             : void
      87         374 : LineFunctionSampler::finalize()
      88             : {
      89         374 :   SamplerBase::finalize();
      90         374 : }

Generated by: LCOV version 1.14