Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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  params.addParam<bool>("combine_duplicates",
40  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  params.set<bool>("drop_duplicate_points") = true;
50  params.suppressParameter<bool>("drop_duplicate_points");
51  return params;
52 }
53 
55  : DiracKernel(parameters),
56  ReporterInterface(this),
57  _combine_duplicates(getParam<bool>("combine_duplicates")),
58  _read_in_points(isParamValid("point_name")),
59  _values(getReporterValue<std::vector<Real>>("value_name", REPORTER_MODE_REPLICATED)),
60  _ones_vec(_values.size(), 1.0),
61  _zeros_vec(_values.size(), 0.0),
62  _zeros_pts(_values.size(), Point()),
63  _coordx(isParamValid("x_coord_name")
64  ? getReporterValue<std::vector<Real>>("x_coord_name", REPORTER_MODE_REPLICATED)
65  : _zeros_vec),
66  _coordy(isParamValid("y_coord_name")
67  ? getReporterValue<std::vector<Real>>("y_coord_name", REPORTER_MODE_REPLICATED)
68  : _zeros_vec),
69  _coordz(isParamValid("z_coord_name")
70  ? getReporterValue<std::vector<Real>>("z_coord_name", REPORTER_MODE_REPLICATED)
71  : _zeros_vec),
72  _point(_read_in_points
73  ? getReporterValue<std::vector<Point>>("point_name", REPORTER_MODE_REPLICATED)
74  : _zeros_pts),
75  _weight(isParamValid("weight_name")
76  ? getReporterValue<std::vector<Real>>("weight_name", REPORTER_MODE_REPLICATED)
77  : _ones_vec)
78 {
79  if (isParamValid("point_name") == (isParamValid("x_coord_name") && isParamValid("y_coord_name") &&
80  isParamValid("z_coord_name")))
81  paramError("Either supply x,y, and z reporters or a point reporter.");
82 }
83 
84 void
86 {
88 
89  const auto nval = _values.size();
90  if (nval == 0)
91  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  _ones_vec.resize(nval, 1.0);
96  _zeros_vec.resize(nval, 0.0);
97  _zeros_pts.resize(nval, Point());
98 
99  errorCheck("x_coord_name", _coordx.size());
100  errorCheck("y_coord_name", _coordy.size());
101  errorCheck("z_coord_name", _coordz.size());
102  errorCheck("weight_name", _weight.size());
103  errorCheck("point_name", _point.size());
104 
105  if (_read_in_points)
106  {
107  for (const auto & i : index_range(_point))
108  fillPoint(_point[i], i);
109  }
110  else
111  {
112  std::vector<Point> points(_coordx.size());
113  for (const auto i : index_range(_values))
114  {
115  const Point point = Point(_coordx[i], _coordy[i], _coordz[i]);
116  fillPoint(point, i);
117  }
118  }
119 }
120 
121 Real
123 {
124  // This is negative because it's a forcing function that has been brought over to the left side
125  return -_test[_i][_qp] * libmesh_map_find(_point_to_weightedValue, _current_point);
126 }
127 
128 void
129 ReporterPointSource::fillPoint(const Point & point, const dof_id_type id)
130 {
131  auto it = _point_to_weightedValue.find(point);
132  if (it == _point_to_weightedValue.end())
133  {
134  addPoint(point, id);
135  it = _point_to_weightedValue.emplace(point, 0).first;
136  }
137  else if (!_combine_duplicates)
138  paramError("combine_duplicates",
139  "combine_duplicates must be true if reporter has duplicate points. Found "
140  "duplicate point (",
141  point,
142  ").");
143 
144  auto & value = it->second;
145  value += _values[id] * _weight[id];
146 }
147 
148 void
149 ReporterPointSource::errorCheck(const std::string & input_name, std::size_t reporterSize)
150 {
151  const auto nval = _values.size();
152  if (reporterSize != nval)
153  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 }
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
void addPoint(const Elem *elem, Point p, unsigned id=libMesh::invalid_uint)
Add the physical x,y,z point located in the element "elem" to the list of points this DiracKernel wil...
const OutputTools< T >::VariableTestValue & _test
Values of test functions at QPs.
Definition: DiracKernel.h:91
ReporterPointSource(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::vector< Point > & _point
xyz point
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...
virtual void addPoints() override
This is where the DiracKernel should call addPoint() for each point it needs to have a value distribu...
std::unordered_map< Point, Real > _point_to_weightedValue
map from an added point to it&#39;s weighted value
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn&#39;t required or valid in the derived class...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
virtual Real computeQpResidual() override
This is the virtual that derived classes should override for computing the residual.
const std::vector< Real > & _coordx
x coordinate
registerMooseObject("MooseApp", ReporterPointSource)
A ReporterPointSource DiracKernel is used to create variable valued point sources.
Interface to allow object to consume Reporter values.
std::vector< Real > _ones_vec
convenience vectors (these are not const because reporters can change their size) ...
std::vector< Point > _zeros_pts
virtual const OutputTools< T >::VariableValue & value()
The value of the variable this object is operating on.
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 ...
std::vector< Real > _zeros_vec
void errorCheck(const std::string &input_name, std::size_t reporterSize)
A DiracKernel is used when you need to add contributions to the residual by means of multiplying some...
Definition: DiracKernel.h:19
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::vector< Real > & _coordy
y coordinate
unsigned int _qp
Quadrature point index.
const bool _read_in_points
bool if data format read in is points
const std::vector< Real > & _values
values at each xyz coordinate
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...
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...
const ReporterMode REPORTER_MODE_REPLICATED
const bool _combine_duplicates
bool if duplicate points values and weights should be combined
unsigned int _i
i-th, j-th index for enumerating shape and test functions
void fillPoint(const Point &point, const dof_id_type id)
Add points and check for duplicate points.
const std::vector< Real > & _weight
weights to scale value by
auto index_range(const T &sizable)
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30
uint8_t dof_id_type
Point _current_point
The current point.
static InputParameters validParams()
Definition: DiracKernel.C:24
const std::vector< Real > & _coordz
z coordinate