LCOV - code coverage report
Current view: top level - src/materials - ReporterOffsetFunctionMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose optimization: #31405 (292dce) with base fef103 Lines: 36 38 94.7 %
Date: 2025-09-04 07:54:57 Functions: 8 8 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 "ReporterOffsetFunctionMaterial.h"
      11             : 
      12             : registerMooseObject("OptimizationApp", ReporterOffsetFunctionMaterial);
      13             : registerMooseObject("OptimizationApp", ADReporterOffsetFunctionMaterial);
      14             : 
      15             : template <bool is_ad>
      16             : InputParameters
      17         242 : ReporterOffsetFunctionMaterialTempl<is_ad>::validParams()
      18             : {
      19         242 :   InputParameters params = Material::validParams();
      20         242 :   params.addClassDescription("Compute the sum of a function offset by a set of points.");
      21         484 :   params.addRequiredParam<FunctionName>("function", "The weighting function.");
      22             : 
      23         484 :   params.addParam<ReporterName>("x_coord_name", "Reporter with x-coordinate data.");
      24         484 :   params.addParam<ReporterName>("y_coord_name", "Reporter with y-coordinate data.");
      25         484 :   params.addParam<ReporterName>("z_coord_name", "Reporter with z-coordinate data.");
      26         484 :   params.addParam<ReporterName>("point_name",
      27             :                                 "Reporter with point data. "
      28             :                                 "<reporter>/<name>.");
      29         484 :   params.addRequiredParam<std::string>("property_name", "Material property base name");
      30         484 :   params.addParamNamesToGroup("point_name x_coord_name y_coord_name z_coord_name",
      31             :                               "Offset locations for function evaluations");
      32         242 :   return params;
      33           0 : }
      34             : 
      35             : template <bool is_ad>
      36         186 : ReporterOffsetFunctionMaterialTempl<is_ad>::ReporterOffsetFunctionMaterialTempl(
      37             :     const InputParameters & parameters)
      38             :   : Material(parameters),
      39             :     ReporterInterface(this),
      40         186 :     _prop_name(getParam<std::string>("property_name")),
      41         186 :     _material(declareGenericProperty<Real, is_ad>(_prop_name)),
      42         372 :     _read_in_points(isParamValid("point_name")),
      43         186 :     _coordx(isParamValid("x_coord_name")
      44         744 :                 ? getReporterValue<std::vector<Real>>("x_coord_name", REPORTER_MODE_REPLICATED)
      45             :                 : _zeros_vec),
      46         186 :     _coordy(isParamValid("y_coord_name")
      47         744 :                 ? getReporterValue<std::vector<Real>>("y_coord_name", REPORTER_MODE_REPLICATED)
      48             :                 : _zeros_vec),
      49         186 :     _coordz(isParamValid("z_coord_name")
      50         744 :                 ? getReporterValue<std::vector<Real>>("z_coord_name", REPORTER_MODE_REPLICATED)
      51             :                 : _zeros_vec),
      52         372 :     _points(_read_in_points
      53         186 :                 ? getReporterValue<std::vector<Point>>("point_name", REPORTER_MODE_REPLICATED)
      54             :                 : _zeros_pts),
      55         372 :     _func(getFunction("function"))
      56             : {
      57         930 :   if (isParamValid("point_name") == (isParamValid("x_coord_name") && isParamValid("y_coord_name") &&
      58         558 :                                      isParamValid("z_coord_name")))
      59           0 :     paramError("Either supply x,y, and z reporters or a point reporter.");
      60         186 : }
      61             : 
      62             : template <bool is_ad>
      63             : void
      64      360000 : ReporterOffsetFunctionMaterialTempl<is_ad>::computeQpProperties()
      65             : {
      66      360000 :   _material[_qp] = 0;
      67      360000 :   auto num_pts = _read_in_points ? _points.size() : _coordx.size();
      68             :   if (!_read_in_points)
      69             :     mooseAssert((_coordx.size() == _coordy.size()) && (_coordx.size() == _coordz.size()),
      70             :                 "Size of the coordinate offsets don't match.");
      71             : 
      72     1800000 :   for (const auto idx : make_range(num_pts))
      73             :   {
      74             : 
      75     1440000 :     Point offset = _read_in_points ? _points[idx] : Point(_coordx[idx], _coordy[idx], _coordz[idx]);
      76             : 
      77     1440000 :     _material[_qp] += computeOffsetFunction(offset);
      78             :   }
      79      360000 : }
      80             : 
      81             : template <bool is_ad>
      82             : Real
      83     6333840 : ReporterOffsetFunctionMaterialTempl<is_ad>::computeOffsetFunction(const Point & point_offset)
      84             : {
      85     6333840 :   return _func.value(_t, _q_point[_qp] - point_offset);
      86             : }
      87             : 
      88             : template class ReporterOffsetFunctionMaterialTempl<true>;
      89             : template class ReporterOffsetFunctionMaterialTempl<false>;

Generated by: LCOV version 1.14