https://mooseframework.inl.gov
ConservedMaskedNoiseBase.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 
11 
12 #include "libmesh/quadrature.h"
13 
16 {
18  params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_BEGIN;
19  params.addParam<MaterialPropertyName>("mask",
20  "Material property to multiply the random numbers with");
21  return params;
22 }
23 
25  : ConservedNoiseInterface(parameters), _mask(getMaterialProperty<Real>("mask"))
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<std::pair<Real, Real>> & me = _random_data[_current_elem->id()] =
42  std::vector<std::pair<Real, 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].first = getQpRandom();
48  me[_qp].second = _mask[_qp];
49  _integral += _JxW[_qp] * _coord[_qp] * me[_qp].first * me[_qp].second;
50  _volume += _JxW[_qp] * _coord[_qp] * me[_qp].second;
51  }
52 }
53 
54 void
56 {
57  const auto & uo = static_cast<const ConservedMaskedNoiseBase &>(y);
58 
59  _random_data.insert(uo._random_data.begin(), uo._random_data.end());
60  _integral += uo._integral;
61  _volume += uo._volume;
62 }
63 
64 void
66 {
69 
70  // TODO check that _volume is >0
72 }
73 
74 Real
75 ConservedMaskedNoiseBase::getQpValue(dof_id_type element_id, unsigned int qp) const
76 {
77  const auto it_pair = _random_data.find(element_id);
78 
79  if (it_pair == _random_data.end())
80  mooseError("Element not found.");
81  else
82  {
83  libmesh_assert_less(qp, it_pair->second.size());
84  return (it_pair->second[qp].first - _offset) * it_pair->second[qp].second;
85  }
86 }
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
virtual void threadJoin(const UserObject &y)
const MooseArray< Real > & _coord
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
std::unordered_map< dof_id_type, std::vector< std::pair< Real, Real > > > _random_data
const std::vector< double > y
const MaterialProperty< Real > & _mask
void gatherSum(T &value)
const ExecFlagType EXEC_TIMESTEP_BEGIN
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
ConservedMaskedNoiseBase(const InputParameters &parameters)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
const Elem *const & _current_elem
Real getQpValue(dof_id_type element_id, unsigned int qp) const
const MooseArray< Real > & _JxW
void mooseError(Args &&... args) const
static InputParameters validParams()
virtual Real getQpRandom()=0
uint8_t dof_id_type