https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ConservedNoiseBase.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
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
26
27void
29{
30 _random_data.clear();
31 _integral = 0.0;
32 _volume = 0.0;
33}
34
35void
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
51void
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
61void
69
70Real
71ConservedNoiseBase::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}
const std::vector< double > y
const ExecFlagType EXEC_TIMESTEP_BEGIN
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
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 void finalize()
static InputParameters validParams()
ConservedNoiseBase(const InputParameters &parameters)
virtual void threadJoin(const UserObject &y)
This Userobject is the base class of Userobjects that generate one random number per timestep and qua...
virtual Real getQpRandom()=0
static InputParameters validParams()
const QBase *const & _qrule
const Elem *const & _current_elem
const MooseArray< Real > & _coord
const MooseArray< Real > & _JxW
T & set(const std::string &name, bool quiet_mode=false)
void mooseError(Args &&... args) const
void gatherSum(T &value)