https://mooseframework.inl.gov
ReporterOffsetFunctionMaterial.C
Go to the documentation of this file.
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 
11 
14 
15 template <bool is_ad>
18 {
20  params.addClassDescription("Compute the sum of a function offset by a set of points.");
21  params.addRequiredParam<FunctionName>("function", "The weighting function.");
22 
23  params.addParam<ReporterName>("x_coord_name", "Reporter with x-coordinate data.");
24  params.addParam<ReporterName>("y_coord_name", "Reporter with y-coordinate data.");
25  params.addParam<ReporterName>("z_coord_name", "Reporter with z-coordinate data.");
26  params.addParam<ReporterName>("point_name",
27  "Reporter with point data. "
28  "<reporter>/<name>.");
29  params.addRequiredParam<std::string>("property_name", "Material property base name");
30  params.addParamNamesToGroup("point_name x_coord_name y_coord_name z_coord_name",
31  "Offset locations for function evaluations");
32  return params;
33 }
34 
35 template <bool is_ad>
37  const InputParameters & parameters)
38  : Material(parameters),
39  ReporterInterface(this),
40  _prop_name(getParam<std::string>("property_name")),
41  _material(declareGenericProperty<Real, is_ad>(_prop_name)),
42  _read_in_points(isParamValid("point_name")),
43  _coordx(isParamValid("x_coord_name")
44  ? getReporterValue<std::vector<Real>>("x_coord_name", REPORTER_MODE_REPLICATED)
45  : _zeros_vec),
46  _coordy(isParamValid("y_coord_name")
47  ? getReporterValue<std::vector<Real>>("y_coord_name", REPORTER_MODE_REPLICATED)
48  : _zeros_vec),
49  _coordz(isParamValid("z_coord_name")
50  ? getReporterValue<std::vector<Real>>("z_coord_name", REPORTER_MODE_REPLICATED)
51  : _zeros_vec),
52  _points(_read_in_points
53  ? getReporterValue<std::vector<Point>>("point_name", REPORTER_MODE_REPLICATED)
54  : _zeros_pts),
55  _func(getFunction("function"))
56 {
57  if (isParamValid("point_name") == (isParamValid("x_coord_name") && isParamValid("y_coord_name") &&
58  isParamValid("z_coord_name")))
59  paramError("Either supply x,y, and z reporters or a point reporter.");
60 }
61 
62 template <bool is_ad>
63 void
65 {
66  _material[_qp] = 0;
67  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  for (const auto idx : make_range(num_pts))
73  {
74 
75  Point offset = _read_in_points ? _points[idx] : Point(_coordx[idx], _coordy[idx], _coordz[idx]);
76 
77  _material[_qp] += computeOffsetFunction(offset);
78  }
79 }
80 
81 template <bool is_ad>
82 Real
84 {
85  return _func.value(_t, _q_point[_qp] - point_offset);
86 }
87 
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
This class defines a material with an associated offset function.
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool isParamValid(const std::string &name) const
Real computeOffsetFunction(const Point &point_offset)
Calculates the value of the function at the given offset point.
static InputParameters validParams()
ReporterOffsetFunctionMaterialTempl(const InputParameters &parameters)
void paramError(const std::string &param, Args... args) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
void addClassDescription(const std::string &doc_string)
const ReporterMode REPORTER_MODE_REPLICATED
registerMooseObject("OptimizationApp", ReporterOffsetFunctionMaterial)
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)