LCOV - code coverage report
Current view: top level - src/postprocessors - LevelSetVolume.C (source / functions) Hit Total Coverage
Test: idaholab/moose level_set: #32971 (54bef8) with base c6cf66 Lines: 32 35 91.4 %
Date: 2026-05-29 20:37:11 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         120 : LevelSetVolume::validParams()
      16             : {
      17         120 :   InputParameters params = ElementVariablePostprocessor::validParams();
      18         120 :   params.addClassDescription(
      19             :       "Compute the area or volume of the region inside or outside of a level set contour.");
      20         240 :   params.addParam<Real>(
      21         240 :       "threshold", 0.0, "The level set threshold to consider for computing area/volume.");
      22             : 
      23         240 :   MooseEnum loc("inside=0 outside=1", "inside");
      24         240 :   params.addParam<MooseEnum>("location", loc, "The location of the area/volume to be computed.");
      25         120 :   return params;
      26         120 : }
      27             : 
      28          64 : LevelSetVolume::LevelSetVolume(const InputParameters & parameters)
      29             :   : ElementVariablePostprocessor(parameters),
      30          64 :     _threshold(getParam<Real>("threshold")),
      31         192 :     _inside(getParam<MooseEnum>("location") == "inside")
      32             : {
      33          64 : }
      34             : 
      35             : void
      36         192 : LevelSetVolume::initialize()
      37             : {
      38         192 :   _volume = 0;
      39         192 : }
      40             : 
      41             : void
      42     1093632 : LevelSetVolume::execute()
      43             : {
      44             :   Real cnt = 0;
      45     1093632 :   Real n = _u.size();
      46             : 
      47             :   // Perform the check for inside/outside outside the qp loop for speed
      48     1093632 :   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     5468160 :     for (_qp = 0; _qp < n; ++_qp)
      57     4374528 :       if (_u[_qp] > _threshold)
      58      142230 :         cnt++;
      59             :   }
      60     1093632 :   _volume += cnt / n * _current_elem_volume;
      61     1093632 : }
      62             : 
      63             : void
      64         169 : LevelSetVolume::finalize()
      65             : {
      66         169 :   gatherSum(_volume);
      67         169 : }
      68             : 
      69             : Real
      70         169 : LevelSetVolume::getValue() const
      71             : {
      72         169 :   return _volume;
      73             : }
      74             : 
      75             : void
      76          23 : LevelSetVolume::threadJoin(const UserObject & y)
      77             : {
      78             :   const auto & pps = static_cast<const LevelSetVolume &>(y);
      79          23 :   _volume += pps._volume;
      80          23 : }

Generated by: LCOV version 1.14