LCOV - code coverage report
Current view: top level - src/userobjects - ConservedNoiseBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 32 34 94.1 %
Date: 2025-09-04 07:55:36 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      14             : InputParameters
      15          62 : ConservedNoiseBase::validParams()
      16             : {
      17          62 :   InputParameters params = ElementUserObject::validParams();
      18          62 :   params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_BEGIN;
      19          62 :   return params;
      20           0 : }
      21             : 
      22          33 : ConservedNoiseBase::ConservedNoiseBase(const InputParameters & parameters)
      23          33 :   : ConservedNoiseInterface(parameters)
      24             : {
      25          33 : }
      26             : 
      27             : void
      28         149 : ConservedNoiseBase::initialize()
      29             : {
      30             :   _random_data.clear();
      31         149 :   _integral = 0.0;
      32         149 :   _volume = 0.0;
      33         149 : }
      34             : 
      35             : void
      36       11100 : ConservedNoiseBase::execute()
      37             : {
      38             :   // reserve space for each quadrature point in the element
      39       11100 :   std::vector<Real> & me = _random_data[_current_elem->id()] =
      40       22200 :       std::vector<Real>(_qrule->n_points());
      41             : 
      42             :   // store a random number for each quadrature point
      43       55500 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      44             :   {
      45       44400 :     me[_qp] = getQpRandom();
      46       44400 :     _integral += _JxW[_qp] * _coord[_qp] * me[_qp];
      47       44400 :     _volume += _JxW[_qp] * _coord[_qp];
      48             :   }
      49       11100 : }
      50             : 
      51             : void
      52          18 : ConservedNoiseBase::threadJoin(const UserObject & y)
      53             : {
      54             :   const auto & uo = static_cast<const ConservedNoiseBase &>(y);
      55             : 
      56          18 :   _random_data.insert(uo._random_data.begin(), uo._random_data.end());
      57          18 :   _integral += uo._integral;
      58          18 :   _volume += uo._volume;
      59          18 : }
      60             : 
      61             : void
      62         131 : ConservedNoiseBase::finalize()
      63             : {
      64         131 :   gatherSum(_integral);
      65         131 :   gatherSum(_volume);
      66             : 
      67         131 :   _offset = _integral / _volume;
      68         131 : }
      69             : 
      70             : Real
      71     4217600 : ConservedNoiseBase::getQpValue(dof_id_type element_id, unsigned int qp) const
      72             : {
      73             :   const auto it_pair = _random_data.find(element_id);
      74             : 
      75     4217600 :   if (it_pair == _random_data.end())
      76           0 :     mooseError("Element not found.");
      77             :   else
      78             :   {
      79             :     libmesh_assert_less(qp, it_pair->second.size());
      80     4217600 :     return it_pair->second[qp] - _offset;
      81             :   }
      82             : }

Generated by: LCOV version 1.14