www.mooseframework.org
ConservedNoiseBase.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 
10 #include "ConservedNoiseBase.h"
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  return params;
21 }
22 
23 ConservedNoiseBase::ConservedNoiseBase(const InputParameters & parameters)
24  : ConservedNoiseInterface(parameters)
25 {
26 }
27 
28 void
30 {
31  _random_data.clear();
32  _integral = 0.0;
33  _volume = 0.0;
34 }
35 
36 void
38 {
39  // reserve space for each quadrature point in the element
40  std::vector<Real> & me = _random_data[_current_elem->id()] =
41  std::vector<Real>(_qrule->n_points());
42 
43  // store a random number for each quadrature point
44  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
45  {
46  me[_qp] = getQpRandom();
47  _integral += _JxW[_qp] * _coord[_qp] * me[_qp];
48  _volume += _JxW[_qp] * _coord[_qp];
49  }
50 }
51 
52 void
53 ConservedNoiseBase::threadJoin(const UserObject & y)
54 {
55  const ConservedNoiseBase & uo = static_cast<const ConservedNoiseBase &>(y);
56 
57  _random_data.insert(uo._random_data.begin(), uo._random_data.end());
58  _integral += uo._integral;
59  _volume += uo._volume;
60 }
61 
62 void
64 {
65  gatherSum(_integral);
66  gatherSum(_volume);
67 
69 }
70 
71 Real
72 ConservedNoiseBase::getQpValue(dof_id_type element_id, unsigned int qp) const
73 {
74  const auto it_pair = _random_data.find(element_id);
75 
76  if (it_pair == _random_data.end())
77  mooseError("Element not found.");
78  else
79  {
80  libmesh_assert_less(qp, it_pair->second.size());
81  return it_pair->second[qp] - _offset;
82  }
83 }
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)
std::unordered_map< dof_id_type, std::vector< Real > > _random_data
virtual void initialize()
Real getQpValue(dof_id_type element_id, unsigned int qp) const
virtual Real getQpRandom()=0