www.mooseframework.org
ConservedMaskedNoiseBase.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 
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  params.addParam<MaterialPropertyName>("mask",
22  "Material property to multiply the random numbers with");
23  return params;
24 }
25 
26 ConservedMaskedNoiseBase::ConservedMaskedNoiseBase(const InputParameters & parameters)
27  : ConservedNoiseInterface(parameters), _mask(getMaterialProperty<Real>("mask"))
28 {
29 }
30 
31 void
33 {
34  _random_data.clear();
35  _integral = 0.0;
36  _volume = 0.0;
37 }
38 
39 void
41 {
42  // reserve space for each quadrature point in the element
43  std::vector<std::pair<Real, Real>> & me = _random_data[_current_elem->id()] =
44  std::vector<std::pair<Real, Real>>(_qrule->n_points());
45 
46  // store a random number for each quadrature point
47  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
48  {
49  me[_qp].first = getQpRandom();
50  me[_qp].second = _mask[_qp];
51  _integral += _JxW[_qp] * _coord[_qp] * me[_qp].first * me[_qp].second;
52  _volume += _JxW[_qp] * _coord[_qp] * me[_qp].second;
53  }
54 }
55 
56 void
58 {
59  const ConservedMaskedNoiseBase & uo = static_cast<const ConservedMaskedNoiseBase &>(y);
60 
61  _random_data.insert(uo._random_data.begin(), uo._random_data.end());
62  _integral += uo._integral;
63  _volume += uo._volume;
64 }
65 
66 void
68 {
69  gatherSum(_integral);
70  gatherSum(_volume);
71 
72  // TODO check that _volume is >0
74 }
75 
76 Real
77 ConservedMaskedNoiseBase::getQpValue(dof_id_type element_id, unsigned int qp) const
78 {
79  const auto it_pair = _random_data.find(element_id);
80 
81  if (it_pair == _random_data.end())
82  mooseError("Element not found.");
83  else
84  {
85  libmesh_assert_less(qp, it_pair->second.size());
86  return (it_pair->second[qp].first - _offset) * it_pair->second[qp].second;
87  }
88 }
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
virtual void threadJoin(const UserObject &y)
std::unordered_map< dof_id_type, std::vector< std::pair< Real, Real > > > _random_data
const MaterialProperty< Real > & _mask
InputParameters validParams< ConservedMaskedNoiseBase >()
Real getQpValue(dof_id_type element_id, unsigned int qp) const
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
ConservedMaskedNoiseBase(const InputParameters &parameters)
virtual Real getQpRandom()=0