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 
16 {
18  params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_BEGIN;
19  return params;
20 }
21 
23  : ConservedNoiseInterface(parameters)
24 {
25 }
26 
27 void
29 {
30  _random_data.clear();
31  _integral = 0.0;
32  _volume = 0.0;
33 }
34 
35 void
37 {
38  // reserve space for each quadrature point in the element
39  std::vector<Real> & me = _random_data[_current_elem->id()] =
40  std::vector<Real>(_qrule->n_points());
41 
42  // store a random number for each quadrature point
43  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
44  {
45  me[_qp] = getQpRandom();
46  _integral += _JxW[_qp] * _coord[_qp] * me[_qp];
47  _volume += _JxW[_qp] * _coord[_qp];
48  }
49 }
50 
51 void
53 {
54  const auto & uo = static_cast<const ConservedNoiseBase &>(y);
55 
56  _random_data.insert(uo._random_data.begin(), uo._random_data.end());
57  _integral += uo._integral;
58  _volume += uo._volume;
59 }
60 
61 void
63 {
66 
68 }
69 
70 Real
71 ConservedNoiseBase::getQpValue(dof_id_type element_id, unsigned int qp) const
72 {
73  const auto it_pair = _random_data.find(element_id);
74 
75  if (it_pair == _random_data.end())
76  mooseError("Element not found.");
77  else
78  {
79  libmesh_assert_less(qp, it_pair->second.size());
80  return it_pair->second[qp] - _offset;
81  }
82 }
static InputParameters validParams()
virtual void threadJoin(const UserObject &y)
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
const MooseArray< Real > & _coord
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
virtual void finalize()
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
const std::vector< double > y
virtual void execute()
void gatherSum(T &value)
const ExecFlagType EXEC_TIMESTEP_BEGIN
ConservedNoiseBase(const InputParameters &parameters)
std::unordered_map< dof_id_type, std::vector< Real > > _random_data
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
const Elem *const & _current_elem
const MooseArray< Real > & _JxW
void mooseError(Args &&... args) const
virtual void initialize()
Real getQpValue(dof_id_type element_id, unsigned int qp) const
virtual Real getQpRandom()=0
uint8_t dof_id_type