www.mooseframework.org
ConservedNoiseBase.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "ConservedNoiseBase.h"
9 
10 #include "libmesh/quadrature.h"
11 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<ElementUserObject>();
17 
18  MultiMooseEnum setup_options(SetupInterface::getExecuteOptions());
19  setup_options = "timestep_begin";
20  params.set<MultiMooseEnum>("execute_on") = setup_options;
21  return params;
22 }
23 
24 ConservedNoiseBase::ConservedNoiseBase(const InputParameters & parameters)
25  : ConservedNoiseInterface(parameters)
26 {
27 }
28 
29 void
31 {
32  _random_data.clear();
33  _integral = 0.0;
34  _volume = 0.0;
35 }
36 
37 void
39 {
40  // reserve space for each quadrature point in the element
41  std::vector<Real> & me = _random_data[_current_elem->id()] =
42  std::vector<Real>(_qrule->n_points());
43 
44  // store a random number for each quadrature point
45  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
46  {
47  me[_qp] = getQpRandom();
48  _integral += _JxW[_qp] * _coord[_qp] * me[_qp];
49  _volume += _JxW[_qp] * _coord[_qp];
50  }
51 }
52 
53 void
54 ConservedNoiseBase::threadJoin(const UserObject & y)
55 {
56  const ConservedNoiseBase & uo = static_cast<const ConservedNoiseBase &>(y);
57 
58  _random_data.insert(uo._random_data.begin(), uo._random_data.end());
59  _integral += uo._integral;
60  _volume += uo._volume;
61 }
62 
63 void
65 {
66  gatherSum(_integral);
67  gatherSum(_volume);
68 
70 }
71 
72 Real
73 ConservedNoiseBase::getQpValue(dof_id_type element_id, unsigned int qp) const
74 {
75  const auto it_pair = _random_data.find(element_id);
76 
77  if (it_pair == _random_data.end())
78  mooseError("Element not found.");
79  else
80  {
81  libmesh_assert_less(qp, it_pair->second.size());
82  return it_pair->second[qp] - _offset;
83  }
84 }
virtual void threadJoin(const UserObject &y)
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
InputParameters validParams< ConservedNoiseBase >()
virtual void finalize()
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
virtual void execute()
ConservedNoiseBase(const InputParameters &parameters)
Real getQpValue(dof_id_type element_id, unsigned int qp) const
std::unordered_map< dof_id_type, std::vector< Real > > _random_data
virtual void initialize()
virtual Real getQpRandom()=0