https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ReporterPointSource.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
10#include "ReporterPointSource.h"
11#include "MooseUtils.h"
12
14
17{
19
20 params.addClassDescription("Apply a point load defined by Reporter.");
21
23 "value_name", "reporter value name. This uses the reporter syntax <reporter>/<name>.");
24 params.addParam<ReporterName>(
25 "x_coord_name",
26 "reporter x-coordinate name. This uses the reporter syntax <reporter>/<name>.");
27 params.addParam<ReporterName>(
28 "y_coord_name",
29 "reporter y-coordinate name. This uses the reporter syntax <reporter>/<name>.");
30 params.addParam<ReporterName>(
31 "z_coord_name",
32 "reporter z-coordinate name. This uses the reporter syntax <reporter>/<name>.");
33 params.addParam<ReporterName>("point_name",
34 "reporter point name. This uses the reporter syntax "
35 "<reporter>/<name>.");
36 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 params.set<bool>("drop_duplicate_points") = false;
42 params.suppressParameter<bool>("drop_duplicate_points");
43 return params;
44}
45
47 : DiracKernel(parameters),
49 _read_in_points(isParamValid("point_name")),
50 _values(getReporterValue<std::vector<Real>>("value_name", REPORTER_MODE_REPLICATED)),
51 _ones_vec(_values.size(), 1.0),
52 _zeros_vec(_values.size(), 0.0),
53 _zeros_pts(_values.size(), Point()),
54 _coordx(isParamValid("x_coord_name")
55 ? getReporterValue<std::vector<Real>>("x_coord_name", REPORTER_MODE_REPLICATED)
56 : _zeros_vec),
57 _coordy(isParamValid("y_coord_name")
58 ? getReporterValue<std::vector<Real>>("y_coord_name", REPORTER_MODE_REPLICATED)
59 : _zeros_vec),
60 _coordz(isParamValid("z_coord_name")
61 ? getReporterValue<std::vector<Real>>("z_coord_name", REPORTER_MODE_REPLICATED)
62 : _zeros_vec),
63 _point(_read_in_points
64 ? getReporterValue<std::vector<Point>>("point_name", REPORTER_MODE_REPLICATED)
65 : _zeros_pts),
66 _weight(isParamValid("weight_name")
67 ? getReporterValue<std::vector<Real>>("weight_name", REPORTER_MODE_REPLICATED)
68 : _ones_vec)
69{
70 if (isParamValid("point_name") == (isParamValid("x_coord_name") && isParamValid("y_coord_name") &&
71 isParamValid("z_coord_name")))
72 paramError("Either supply x,y, and z reporters or a point reporter.");
73}
74
75void
77{
78 const auto nval = _values.size();
79 if (nval == 0)
80 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 _ones_vec.resize(nval, 1.0);
85 _zeros_vec.resize(nval, 0.0);
86 _zeros_pts.resize(nval, Point());
87
88 errorCheck("x_coord_name", _coordx.size());
89 errorCheck("y_coord_name", _coordy.size());
90 errorCheck("z_coord_name", _coordz.size());
91 errorCheck("weight_name", _weight.size());
92 errorCheck("point_name", _point.size());
93
95 {
96 for (const auto & i : index_range(_point))
97 addPoint(_point[i], i, _values[i] * _weight[i]);
98 }
99 else
100 {
101 std::vector<Point> points(_coordx.size());
102 for (const auto i : index_range(_values))
103 {
104 const Point point = Point(_coordx[i], _coordy[i], _coordz[i]);
105 addPoint(point, i, _values[i] * _weight[i]);
106 }
107 }
108}
109
110Real
112{
113 // This is negative because it's a forcing function that has been brought over to the left side
114 return -_test[_i][_qp];
115}
116
117void
118ReporterPointSource::errorCheck(const std::string & input_name, std::size_t reporterSize)
119{
120 const auto nval = _values.size();
121 if (reporterSize != nval)
122 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}
const ReporterMode REPORTER_MODE_REPLICATED
registerMooseObject("MooseApp", ReporterPointSource)
unsigned int _i
i-th, j-th index for enumerating shape and test functions
unsigned int _qp
Quadrature point index.
void addPoint(const Elem *elem, Point p, unsigned id=libMesh::invalid_uint, Real value=1.0)
Add the physical x,y,z point located in the element "elem" to the list of points this DiracKernel wil...
A DiracKernel is used when you need to add contributions to the residual by means of multiplying some...
Definition DiracKernel.h:33
static InputParameters validParams()
Definition DiracKernel.C:24
const OutputTools< T >::VariableTestValue & _test
Values of test functions at QPs.
Definition DiracKernel.h:91
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn't required or valid in the derived class...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
Interface to allow object to consume Reporter values.
The Reporter system is comprised of objects that can contain any number of data values.
A ReporterPointSource DiracKernel is used to create variable valued point sources.
virtual Real computeQpResidual() override
This is the virtual that derived classes should override for computing the residual.
virtual void addPoints() override
This is where the DiracKernel should call addPoint() for each point it needs to have a value distribu...
ReporterPointSource(const InputParameters &parameters)
const std::vector< Point > & _point
xyz point
const std::vector< Real > & _coordx
x coordinate
static InputParameters validParams()
std::vector< Real > _ones_vec
convenience vectors (these are not const because reporters can change their size)
const std::vector< Real > & _coordz
z coordinate
const std::vector< Real > & _values
values at each xyz coordinate
void errorCheck(const std::string &input_name, std::size_t reporterSize)
const std::vector< Real > & _coordy
y coordinate
const bool _read_in_points
bool if data format read in is points
const std::vector< Real > & _weight
weights to scale value by
std::vector< Point > _zeros_pts
std::vector< Real > _zeros_vec