LCOV - code coverage report
Current view: top level - src/userobjects - NearestPointReceiver.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: be601f Lines: 28 31 90.3 %
Date: 2025-07-15 20:50:38 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /********************************************************************/
       2             : /*                  SOFTWARE COPYRIGHT NOTIFICATION                 */
       3             : /*                             Cardinal                             */
       4             : /*                                                                  */
       5             : /*                  (c) 2021 UChicago Argonne, LLC                  */
       6             : /*                        ALL RIGHTS RESERVED                       */
       7             : /*                                                                  */
       8             : /*                 Prepared by UChicago Argonne, LLC                */
       9             : /*               Under Contract No. DE-AC02-06CH11357               */
      10             : /*                With the U. S. Department of Energy               */
      11             : /*                                                                  */
      12             : /*             Prepared by Battelle Energy Alliance, LLC            */
      13             : /*               Under Contract No. DE-AC07-05ID14517               */
      14             : /*                With the U. S. Department of Energy               */
      15             : /*                                                                  */
      16             : /*                 See LICENSE for full restrictions                */
      17             : /********************************************************************/
      18             : 
      19             : #include "NearestPointReceiver.h"
      20             : 
      21             : registerMooseObject("MooseApp", NearestPointReceiver);
      22             : 
      23             : InputParameters
      24          60 : NearestPointReceiver::validParams()
      25             : {
      26          60 :   auto params = GeneralUserObject::validParams();
      27             : 
      28         120 :   params.addRequiredParam<std::vector<Point>>("positions",
      29             :                                               "The positions the data will be associated with");
      30             : 
      31         120 :   params.addParam<std::vector<Real>>("default_data",
      32             :                                      {},
      33             :                                      "The default values of the data.  The number of entries must "
      34             :                                      "be the same as the number of positions");
      35             : 
      36          60 :   return params;
      37           0 : }
      38             : 
      39          30 : NearestPointReceiver::NearestPointReceiver(const InputParameters & parameters)
      40             :   : GeneralUserObject(parameters),
      41          30 :     _positions(getParam<std::vector<Point>>("positions")),
      42         120 :     _data(getParam<std::vector<Real>>("default_data"))
      43             : {
      44          30 :   if (_data.size() && (_data.size() != _positions.size()))
      45           0 :     paramError("default_data",
      46             :                "If default_data is specified then it should be the same length as the number of "
      47             :                "positions.");
      48             : 
      49             :   // Resize the data
      50          30 :   if (_data.empty())
      51          30 :     _data.resize(_positions.size());
      52          30 : }
      53             : 
      54          60 : NearestPointReceiver::~NearestPointReceiver() {}
      55             : 
      56             : void
      57          90 : NearestPointReceiver::execute()
      58             : {
      59          90 : }
      60             : 
      61             : Real
      62      255852 : NearestPointReceiver::spatialValue(const Point & p) const
      63             : {
      64      255852 :   auto nearest_pos = nearestPosition(p);
      65             : 
      66      255852 :   return _data[nearest_pos];
      67             : }
      68             : 
      69             : void
      70          90 : NearestPointReceiver::setValues(const std::vector<Real> & values)
      71             : {
      72          90 :   if (values.size() != _data.size())
      73           0 :     mooseError("Setting values must be the same size as the number of points");
      74             : 
      75          90 :   _data = values;
      76          90 : }
      77             : 
      78             : unsigned int
      79      255852 : NearestPointReceiver::nearestPosition(const Point & p) const
      80             : {
      81             :   unsigned int closest = 0;
      82             :   Real closest_distance = std::numeric_limits<Real>::max();
      83             : 
      84     1023408 :   for (auto i = beginIndex(_positions); i < _positions.size(); i++)
      85             :   {
      86             :     const auto & current_point = _positions[i];
      87             : 
      88      767556 :     Real current_distance = (p - current_point).norm();
      89             : 
      90      767556 :     if (current_distance < closest_distance)
      91             :     {
      92             :       closest_distance = current_distance;
      93      511704 :       closest = i;
      94             :     }
      95             :   }
      96             : 
      97      255852 :   return closest;
      98             : }

Generated by: LCOV version 1.14