www.mooseframework.org
ConservedMaskedNoiseBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
11 
12 #include "libmesh/quadrature.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<ElementUserObject>();
19  params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_BEGIN;
20  params.addParam<MaterialPropertyName>("mask",
21  "Material property to multiply the random numbers with");
22  return params;
23 }
24 
25 ConservedMaskedNoiseBase::ConservedMaskedNoiseBase(const InputParameters & parameters)
26  : ConservedNoiseInterface(parameters), _mask(getMaterialProperty<Real>("mask"))
27 {
28 }
29 
30 void
32 {
33  _random_data.clear();
34  _integral = 0.0;
35  _volume = 0.0;
36 }
37 
38 void
40 {
41  // reserve space for each quadrature point in the element
42  std::vector<std::pair<Real, Real>> & me = _random_data[_current_elem->id()] =
43  std::vector<std::pair<Real, Real>>(_qrule->n_points());
44 
45  // store a random number for each quadrature point
46  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
47  {
48  me[_qp].first = getQpRandom();
49  me[_qp].second = _mask[_qp];
50  _integral += _JxW[_qp] * _coord[_qp] * me[_qp].first * me[_qp].second;
51  _volume += _JxW[_qp] * _coord[_qp] * me[_qp].second;
52  }
53 }
54 
55 void
57 {
58  const ConservedMaskedNoiseBase & uo = static_cast<const ConservedMaskedNoiseBase &>(y);
59 
60  _random_data.insert(uo._random_data.begin(), uo._random_data.end());
61  _integral += uo._integral;
62  _volume += uo._volume;
63 }
64 
65 void
67 {
68  gatherSum(_integral);
69  gatherSum(_volume);
70 
71  // TODO check that _volume is >0
73 }
74 
75 Real
76 ConservedMaskedNoiseBase::getQpValue(dof_id_type element_id, unsigned int qp) const
77 {
78  const auto it_pair = _random_data.find(element_id);
79 
80  if (it_pair == _random_data.end())
81  mooseError("Element not found.");
82  else
83  {
84  libmesh_assert_less(qp, it_pair->second.size());
85  return (it_pair->second[qp].first - _offset) * it_pair->second[qp].second;
86  }
87 }
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 >()
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
ConservedMaskedNoiseBase(const InputParameters &parameters)
Real getQpValue(dof_id_type element_id, unsigned int qp) const
virtual Real getQpRandom()=0