LCOV - code coverage report
Current view: top level - src/postprocessors - LevelSetVolume.C (source / functions) Hit Total Coverage
Test: idaholab/moose level_set: #31405 (292dce) with base fef103 Lines: 32 35 91.4 %
Date: 2025-09-04 07:53:58 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 "LevelSetVolume.h"
      11             : 
      12             : registerMooseObject("LevelSetApp", LevelSetVolume);
      13             : 
      14             : InputParameters
      15         168 : LevelSetVolume::validParams()
      16             : {
      17         168 :   InputParameters params = ElementVariablePostprocessor::validParams();
      18         168 :   params.addClassDescription(
      19             :       "Compute the area or volume of the region inside or outside of a level set contour.");
      20         336 :   params.addParam<Real>(
      21         336 :       "threshold", 0.0, "The level set threshold to consider for computing area/volume.");
      22             : 
      23         336 :   MooseEnum loc("inside=0 outside=1", "inside");
      24         336 :   params.addParam<MooseEnum>("location", loc, "The location of the area/volume to be computed.");
      25         168 :   return params;
      26         168 : }
      27             : 
      28          96 : LevelSetVolume::LevelSetVolume(const InputParameters & parameters)
      29             :   : ElementVariablePostprocessor(parameters),
      30          96 :     _threshold(getParam<Real>("threshold")),
      31         288 :     _inside(getParam<MooseEnum>("location") == "inside")
      32             : {
      33          96 : }
      34             : 
      35             : void
      36         284 : LevelSetVolume::initialize()
      37             : {
      38         284 :   _volume = 0;
      39         284 : }
      40             : 
      41             : void
      42     1298432 : LevelSetVolume::execute()
      43             : {
      44             :   Real cnt = 0;
      45     1298432 :   Real n = _u.size();
      46             : 
      47             :   // Perform the check for inside/outside outside the qp loop for speed
      48     1298432 :   if (_inside)
      49             :   {
      50           0 :     for (_qp = 0; _qp < n; ++_qp)
      51           0 :       if (_u[_qp] <= _threshold)
      52           0 :         cnt++;
      53             :   }
      54             :   else
      55             :   {
      56     6492160 :     for (_qp = 0; _qp < n; ++_qp)
      57     5193728 :       if (_u[_qp] > _threshold)
      58      168824 :         cnt++;
      59             :   }
      60     1298432 :   _volume += cnt / n * _current_elem_volume;
      61     1298432 : }
      62             : 
      63             : void
      64         215 : LevelSetVolume::finalize()
      65             : {
      66         215 :   gatherSum(_volume);
      67         215 : }
      68             : 
      69             : Real
      70         215 : LevelSetVolume::getValue() const
      71             : {
      72         215 :   return _volume;
      73             : }
      74             : 
      75             : void
      76          69 : LevelSetVolume::threadJoin(const UserObject & y)
      77             : {
      78             :   const auto & pps = static_cast<const LevelSetVolume &>(y);
      79          69 :   _volume += pps._volume;
      80          69 : }

Generated by: LCOV version 1.14