https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
29void
31{
32 _random_data.clear();
33 _integral = 0.0;
34 _volume = 0.0;
35}
36
37void
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
54void
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
64void
66{
69
70 // TODO check that _volume is >0
72}
73
74Real
75ConservedMaskedNoiseBase::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}
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...
static InputParameters validParams()
ConservedMaskedNoiseBase(const InputParameters &parameters)
virtual void threadJoin(const UserObject &y)
Real getQpValue(dof_id_type element_id, unsigned int qp) const
const MaterialProperty< Real > & _mask
std::unordered_map< dof_id_type, std::vector< std::pair< Real, Real > > > _random_data
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
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void mooseError(Args &&... args) const
void gatherSum(T &value)