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 3315 : ReporterPointSource::validParams()
17 : {
18 3315 : InputParameters params = DiracKernel::validParams();
19 :
20 6630 : params.addClassDescription("Apply a point load defined by Reporter.");
21 :
22 13260 : params.addRequiredParam<ReporterName>(
23 : "value_name", "reporter value name. This uses the reporter syntax <reporter>/<name>.");
24 13260 : params.addParam<ReporterName>(
25 : "x_coord_name",
26 : "reporter x-coordinate name. This uses the reporter syntax <reporter>/<name>.");
27 13260 : params.addParam<ReporterName>(
28 : "y_coord_name",
29 : "reporter y-coordinate name. This uses the reporter syntax <reporter>/<name>.");
30 13260 : params.addParam<ReporterName>(
31 : "z_coord_name",
32 : "reporter z-coordinate name. This uses the reporter syntax <reporter>/<name>.");
33 13260 : params.addParam<ReporterName>("point_name",
34 : "reporter point name. This uses the reporter syntax "
35 : "<reporter>/<name>.");
36 13260 : 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 : // Duplicate points are combined internally by adding their weighted values at the same location.
40 : // We therefore need the Dirac assembly path to use the stored point values.
41 6630 : params.set<bool>("drop_duplicate_points") = false;
42 3315 : params.suppressParameter<bool>("drop_duplicate_points");
43 3315 : return params;
44 0 : }
45 :
46 134 : ReporterPointSource::ReporterPointSource(const InputParameters & parameters)
47 : : DiracKernel(parameters),
48 : ReporterInterface(this),
49 134 : _read_in_points(isParamValid("point_name")),
50 402 : _values(getReporterValue<std::vector<Real>>("value_name", REPORTER_MODE_REPLICATED)),
51 268 : _ones_vec(_values.size(), 1.0),
52 268 : _zeros_vec(_values.size(), 0.0),
53 268 : _zeros_pts(_values.size(), Point()),
54 268 : _coordx(isParamValid("x_coord_name")
55 402 : ? getReporterValue<std::vector<Real>>("x_coord_name", REPORTER_MODE_REPLICATED)
56 : : _zeros_vec),
57 268 : _coordy(isParamValid("y_coord_name")
58 402 : ? getReporterValue<std::vector<Real>>("y_coord_name", REPORTER_MODE_REPLICATED)
59 : : _zeros_vec),
60 268 : _coordz(isParamValid("z_coord_name")
61 402 : ? getReporterValue<std::vector<Real>>("z_coord_name", REPORTER_MODE_REPLICATED)
62 : : _zeros_vec),
63 268 : _point(_read_in_points
64 134 : ? getReporterValue<std::vector<Point>>("point_name", REPORTER_MODE_REPLICATED)
65 : : _zeros_pts),
66 268 : _weight(isParamValid("weight_name")
67 202 : ? getReporterValue<std::vector<Real>>("weight_name", REPORTER_MODE_REPLICATED)
68 134 : : _ones_vec)
69 : {
70 1206 : if (isParamValid("point_name") == (isParamValid("x_coord_name") && isParamValid("y_coord_name") &&
71 536 : isParamValid("z_coord_name")))
72 0 : paramError("Either supply x,y, and z reporters or a point reporter.");
73 134 : }
74 :
75 : void
76 5445 : ReporterPointSource::addPoints()
77 : {
78 5445 : const auto nval = _values.size();
79 5445 : if (nval == 0)
80 0 : paramError("value_name", "Value vector must not be empty.");
81 :
82 : // resize these incase the values reporters changed size
83 : // this will only change data constructed to reference these
84 5445 : _ones_vec.resize(nval, 1.0);
85 5445 : _zeros_vec.resize(nval, 0.0);
86 5445 : _zeros_pts.resize(nval, Point());
87 :
88 10890 : errorCheck("x_coord_name", _coordx.size());
89 10884 : errorCheck("y_coord_name", _coordy.size());
90 10884 : errorCheck("z_coord_name", _coordz.size());
91 10884 : errorCheck("weight_name", _weight.size());
92 10884 : errorCheck("point_name", _point.size());
93 :
94 5442 : if (_read_in_points)
95 : {
96 0 : for (const auto & i : index_range(_point))
97 0 : addPoint(_point[i], i, _values[i] * _weight[i]);
98 : }
99 : else
100 : {
101 5442 : std::vector<Point> points(_coordx.size());
102 19926 : for (const auto i : index_range(_values))
103 : {
104 14487 : const Point point = Point(_coordx[i], _coordy[i], _coordz[i]);
105 14487 : addPoint(point, i, _values[i] * _weight[i]);
106 : }
107 5439 : }
108 5439 : }
109 :
110 : Real
111 34848 : ReporterPointSource::computeQpResidual()
112 : {
113 : // This is negative because it's a forcing function that has been brought over to the left side
114 34848 : return -_test[_i][_qp];
115 : }
116 :
117 : void
118 27213 : ReporterPointSource::errorCheck(const std::string & input_name, std::size_t reporterSize)
119 : {
120 27213 : const auto nval = _values.size();
121 27213 : if (reporterSize != nval)
122 3 : paramError(input_name,
123 : "Number of ",
124 : input_name,
125 : " entries (",
126 : reporterSize,
127 : ") does not match number of entries read for value_name (",
128 : nval,
129 : ").");
130 27210 : }
|