LCOV - code coverage report
Current view: top level - src/dirackernels - ReporterPointSource.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 71 76 93.4 %
Date: 2025-07-17 01:28:37 Functions: 6 6 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 "ReporterPointSource.h"
      11             : #include "MooseUtils.h"
      12             : 
      13             : registerMooseObject("MooseApp", ReporterPointSource);
      14             : 
      15             : InputParameters
      16       14517 : ReporterPointSource::validParams()
      17             : {
      18       14517 :   InputParameters params = DiracKernel::validParams();
      19             : 
      20       14517 :   params.addClassDescription("Apply a point load defined by Reporter.");
      21             : 
      22       14517 :   params.addRequiredParam<ReporterName>(
      23             :       "value_name", "reporter value name.  This uses the reporter syntax <reporter>/<name>.");
      24       14517 :   params.addParam<ReporterName>(
      25             :       "x_coord_name",
      26             :       "reporter x-coordinate name.  This uses the reporter syntax <reporter>/<name>.");
      27       14517 :   params.addParam<ReporterName>(
      28             :       "y_coord_name",
      29             :       "reporter y-coordinate name.  This uses the reporter syntax <reporter>/<name>.");
      30       14517 :   params.addParam<ReporterName>(
      31             :       "z_coord_name",
      32             :       "reporter z-coordinate name.  This uses the reporter syntax <reporter>/<name>.");
      33       14517 :   params.addParam<ReporterName>("point_name",
      34             :                                 "reporter point name.  This uses the reporter syntax "
      35             :                                 "<reporter>/<name>.");
      36       14517 :   params.addParam<ReporterName>("weight_name",
      37             :                                 "Name of vector-postprocessor or reporter vector containing "
      38             :                                 "weights to scale value, default is assumed to be all 1s.");
      39       43551 :   params.addParam<bool>("combine_duplicates",
      40       29034 :                         true,
      41             :                         "Whether or not to combine duplicates internally by summing their values "
      42             :                         "times their weights");
      43             :   // Values and weights for duplicates need to be combined with combine_duplicates=true
      44             :   // Duplicate points are never actually applied as separate dirac points, instead they are combined
      45             :   // and computeQpResidual can be multiplied by the number of points found at a single location by
      46             :   // setting drop_duplicate_points=false.  This will not work for our case where each point may have
      47             :   // a different value and weight so we must combine the weights and values ourself and apply them
      48             :   // as a single point with a single value
      49       14517 :   params.set<bool>("drop_duplicate_points") = true;
      50       14517 :   params.suppressParameter<bool>("drop_duplicate_points");
      51       14517 :   return params;
      52           0 : }
      53             : 
      54         134 : ReporterPointSource::ReporterPointSource(const InputParameters & parameters)
      55             :   : DiracKernel(parameters),
      56             :     ReporterInterface(this),
      57         134 :     _combine_duplicates(getParam<bool>("combine_duplicates")),
      58         134 :     _read_in_points(isParamValid("point_name")),
      59         134 :     _values(getReporterValue<std::vector<Real>>("value_name", REPORTER_MODE_REPLICATED)),
      60         134 :     _ones_vec(_values.size(), 1.0),
      61         134 :     _zeros_vec(_values.size(), 0.0),
      62         134 :     _zeros_pts(_values.size(), Point()),
      63         268 :     _coordx(isParamValid("x_coord_name")
      64         134 :                 ? getReporterValue<std::vector<Real>>("x_coord_name", REPORTER_MODE_REPLICATED)
      65             :                 : _zeros_vec),
      66         268 :     _coordy(isParamValid("y_coord_name")
      67         134 :                 ? getReporterValue<std::vector<Real>>("y_coord_name", REPORTER_MODE_REPLICATED)
      68             :                 : _zeros_vec),
      69         268 :     _coordz(isParamValid("z_coord_name")
      70         134 :                 ? getReporterValue<std::vector<Real>>("z_coord_name", REPORTER_MODE_REPLICATED)
      71             :                 : _zeros_vec),
      72         268 :     _point(_read_in_points
      73         134 :                ? getReporterValue<std::vector<Point>>("point_name", REPORTER_MODE_REPLICATED)
      74             :                : _zeros_pts),
      75         268 :     _weight(isParamValid("weight_name")
      76         134 :                 ? getReporterValue<std::vector<Real>>("weight_name", REPORTER_MODE_REPLICATED)
      77         268 :                 : _ones_vec)
      78             : {
      79         402 :   if (isParamValid("point_name") == (isParamValid("x_coord_name") && isParamValid("y_coord_name") &&
      80         268 :                                      isParamValid("z_coord_name")))
      81           0 :     paramError("Either supply x,y, and z reporters or a point reporter.");
      82         134 : }
      83             : 
      84             : void
      85        5239 : ReporterPointSource::addPoints()
      86             : {
      87        5239 :   _point_to_weightedValue.clear();
      88             : 
      89        5239 :   const auto nval = _values.size();
      90        5239 :   if (nval == 0)
      91           0 :     paramError("value_name", "Value vector must not be empty.");
      92             : 
      93             :   // resize these incase the values reporters changed size
      94             :   // this will only change data constructed to reference these
      95        5239 :   _ones_vec.resize(nval, 1.0);
      96        5239 :   _zeros_vec.resize(nval, 0.0);
      97        5239 :   _zeros_pts.resize(nval, Point());
      98             : 
      99        5239 :   errorCheck("x_coord_name", _coordx.size());
     100        5235 :   errorCheck("y_coord_name", _coordy.size());
     101        5235 :   errorCheck("z_coord_name", _coordz.size());
     102        5235 :   errorCheck("weight_name", _weight.size());
     103        5235 :   errorCheck("point_name", _point.size());
     104             : 
     105        5235 :   if (_read_in_points)
     106             :   {
     107           0 :     for (const auto & i : index_range(_point))
     108           0 :       fillPoint(_point[i], i);
     109             :   }
     110             :   else
     111             :   {
     112        5235 :     std::vector<Point> points(_coordx.size());
     113       19552 :     for (const auto i : index_range(_values))
     114             :     {
     115       14325 :       const Point point = Point(_coordx[i], _coordy[i], _coordz[i]);
     116       14325 :       fillPoint(point, i);
     117             :     }
     118        5227 :   }
     119        5227 : }
     120             : 
     121             : Real
     122       34352 : ReporterPointSource::computeQpResidual()
     123             : {
     124             :   // This is negative because it's a forcing function that has been brought over to the left side
     125       34352 :   return -_test[_i][_qp] * libmesh_map_find(_point_to_weightedValue, _current_point);
     126             : }
     127             : 
     128             : void
     129       14325 : ReporterPointSource::fillPoint(const Point & point, const dof_id_type id)
     130             : {
     131       14325 :   auto it = _point_to_weightedValue.find(point);
     132       14325 :   if (it == _point_to_weightedValue.end())
     133             :   {
     134       13625 :     addPoint(point, id);
     135       13621 :     it = _point_to_weightedValue.emplace(point, 0).first;
     136             :   }
     137         700 :   else if (!_combine_duplicates)
     138           4 :     paramError("combine_duplicates",
     139             :                "combine_duplicates must be true if reporter has duplicate points.  Found "
     140             :                "duplicate point (",
     141             :                point,
     142             :                ").");
     143             : 
     144       14317 :   auto & value = it->second;
     145       14317 :   value += _values[id] * _weight[id];
     146       14317 : }
     147             : 
     148             : void
     149       26179 : ReporterPointSource::errorCheck(const std::string & input_name, std::size_t reporterSize)
     150             : {
     151       26179 :   const auto nval = _values.size();
     152       26179 :   if (reporterSize != nval)
     153           4 :     paramError(input_name,
     154             :                "Number of ",
     155             :                input_name,
     156             :                " entries (",
     157             :                reporterSize,
     158             :                ") does not match number of entries read for value_name (",
     159             :                nval,
     160             :                ").");
     161       26175 : }

Generated by: LCOV version 1.14