LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - VariableValueVolumeHistogram.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 40 42 95.2 %
Date: 2025-07-17 01:28:37 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 "VariableValueVolumeHistogram.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseVariableFE.h"
      14             : 
      15             : #include "libmesh/quadrature.h"
      16             : 
      17             : registerMooseObject("MooseApp", VariableValueVolumeHistogram);
      18             : registerMooseObjectRenamed("MooseApp",
      19             :                            VolumeHistogram,
      20             :                            "06/30/2022 24:00",
      21             :                            VariableValueVolumeHistogram);
      22             : 
      23             : InputParameters
      24       28555 : VariableValueVolumeHistogram::validParams()
      25             : {
      26       28555 :   InputParameters params = ElementVectorPostprocessor::validParams();
      27       28555 :   params.addClassDescription(
      28             :       "Compute a histogram of volume fractions binned according to variable values.");
      29       28555 :   params.addParam<unsigned int>("bin_number", 50, "Number of histogram bins");
      30       28555 :   params.addCoupledVar("variable", "Variable to bin the volume of");
      31       28555 :   params.addRequiredParam<Real>("min_value", "Minimum variable value");
      32       28555 :   params.addRequiredParam<Real>("max_value", "Maximum variable value");
      33       28555 :   return params;
      34           0 : }
      35             : 
      36          13 : VariableValueVolumeHistogram::VariableValueVolumeHistogram(const InputParameters & parameters)
      37             :   : ElementVectorPostprocessor(parameters),
      38          13 :     _nbins(getParam<unsigned int>("bin_number")),
      39          13 :     _min_value(getParam<Real>("min_value")),
      40          13 :     _max_value(getParam<Real>("max_value")),
      41          13 :     _deltaV((_max_value - _min_value) / _nbins),
      42          13 :     _value(coupledValue("variable")),
      43          13 :     _bin_center(declareVector(coupledName("variable"))),
      44          26 :     _volume(declareVector("n"))
      45             : {
      46          13 :   if (coupledComponents("variable") != 1)
      47           0 :     mooseError("VariableValueVolumeHistogram works on exactly one coupled variable");
      48             : 
      49             :   // initialize the bin center value vector
      50          13 :   _bin_center.resize(_nbins);
      51         663 :   for (unsigned i = 0; i < _nbins; ++i)
      52         650 :     _bin_center[i] = (i + 0.5) * _deltaV + _min_value;
      53          13 : }
      54             : 
      55             : void
      56          36 : VariableValueVolumeHistogram::initialize()
      57             : {
      58             :   // reset the histogram
      59          36 :   _volume.assign(_nbins, 0.0);
      60          36 : }
      61             : 
      62             : void
      63        4800 : VariableValueVolumeHistogram::execute()
      64             : {
      65             :   // loop over quadrature points
      66       14400 :   for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
      67             :   {
      68             :     // compute target bin
      69        9600 :     int bin = (_value[_qp] - _min_value) / _deltaV;
      70             : 
      71             :     // add the volume contributed by the current quadrature point
      72        9600 :     if (bin >= 0 && static_cast<unsigned int>(bin) < _nbins)
      73        9600 :       _volume[bin] += computeVolume();
      74             :   }
      75        4800 : }
      76             : 
      77             : void
      78          33 : VariableValueVolumeHistogram::finalize()
      79             : {
      80          33 :   gatherSum(_volume);
      81          33 : }
      82             : 
      83             : void
      84           3 : VariableValueVolumeHistogram::threadJoin(const UserObject & y)
      85             : {
      86           3 :   const auto & uo = static_cast<const VariableValueVolumeHistogram &>(y);
      87             :   mooseAssert(uo._volume.size() == _volume.size(),
      88             :               "Inconsistent volume vector lengths across threads.");
      89             : 
      90         153 :   for (unsigned int i = 0; i < _volume.size(); ++i)
      91         150 :     _volume[i] += uo._volume[i];
      92           3 : }
      93             : 
      94             : Real
      95        9600 : VariableValueVolumeHistogram::computeVolume()
      96             : {
      97             :   // overwrite this method to multiply with phase fraction order parameters etc.
      98        9600 :   return _JxW[_qp] * _coord[_qp];
      99             : }

Generated by: LCOV version 1.14