LCOV - code coverage report
Current view: top level - src/postprocessors - InternalVolume.C (source / functions) Hit Total Coverage
Test: idaholab/moose misc: #31405 (292dce) with base fef103 Lines: 0 38 0.0 %
Date: 2025-09-04 07:54:05 Functions: 0 5 0.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 "InternalVolume.h"
      11             : 
      12             : #include "MooseMesh.h"
      13             : #include "Function.h"
      14             : 
      15             : registerMooseObject("MiscApp", InternalVolume);
      16             : 
      17             : InputParameters
      18           0 : InternalVolume::validParams()
      19             : {
      20           0 :   InputParameters params = SideIntegralPostprocessor::validParams();
      21           0 :   params.addClassDescription("Computes the volume of an enclosed area by "
      22             :                              "performing an integral over a user-supplied boundary.");
      23           0 :   params.addRangeCheckedParam<unsigned int>(
      24           0 :       "component", 0, "component<3", "The component to use in the integration");
      25           0 :   params.addParam<Real>(
      26           0 :       "scale_factor", 1, "A scale factor to be applied to the internal volume calculation");
      27           0 :   params.addParam<FunctionName>("addition",
      28           0 :                                 0,
      29             :                                 "An additional volume to be included in the "
      30             :                                 "internal volume calculation. A time-dependent "
      31             :                                 "function is expected.");
      32           0 :   params.set<bool>("use_displaced_mesh") = true;
      33           0 :   return params;
      34           0 : }
      35             : 
      36           0 : InternalVolume::InternalVolume(const InputParameters & parameters)
      37             :   : SideIntegralPostprocessor(parameters),
      38           0 :     _component(getParam<unsigned int>("component")),
      39           0 :     _scale(getParam<Real>("scale_factor")),
      40           0 :     _addition(getFunction("addition"))
      41             : {
      42           0 : }
      43             : 
      44             : //    /              /
      45             : //   |              |
      46             : //   |  div(F) dV = | F dot n dS
      47             : //   |              |
      48             : //  / V            / dS
      49             : //
      50             : // with
      51             : //   F = a field
      52             : //   n = the normal at the surface
      53             : //   V = the volume of the domain
      54             : //   S = the surface of the domain
      55             : //
      56             : // If we choose F as [x 0 0]^T, then
      57             : //   div(F) = 1.
      58             : // So,
      59             : //
      60             : //    /       /
      61             : //   |       |
      62             : //   |  dV = | x * n[0] dS
      63             : //   |       |
      64             : //  / V     / dS
      65             : //
      66             : // That is, the volume of the domain is the integral over the surface of the domain
      67             : // of the x position of the surface times the x-component of the normal of the
      68             : // surface.
      69             : 
      70             : void
      71           0 : InternalVolume::initialSetup()
      72             : {
      73           0 :   SideIntegralPostprocessor::initialSetup();
      74             : 
      75           0 :   const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
      76             :   std::set<SubdomainID>::const_iterator iter = subdomains.begin();
      77             :   const std::set<SubdomainID>::const_iterator iter_end = subdomains.end();
      78           0 :   for (; iter != iter_end; ++iter)
      79             :   {
      80           0 :     const std::set<BoundaryID> & boundaries = _mesh.getSubdomainBoundaryIds(*iter);
      81             :     std::set<BoundaryID>::const_iterator bnd = boundaries.begin();
      82             :     const std::set<BoundaryID>::const_iterator bnd_end = boundaries.end();
      83           0 :     for (; bnd != bnd_end; ++bnd)
      84             :     {
      85           0 :       const std::set<BoundaryID> & b = boundaryIDs();
      86             :       std::set<BoundaryID>::const_iterator bit = b.begin();
      87             :       const std::set<BoundaryID>::const_iterator bit_end = b.end();
      88           0 :       for (; bit != bit_end; ++bit)
      89           0 :         if (*bit == *bnd)
      90             :         {
      91           0 :           Moose::CoordinateSystemType coord_sys = _fe_problem.getCoordSystem(*iter);
      92           0 :           if (_component != 0 && coord_sys == Moose::COORD_RSPHERICAL)
      93           0 :             mooseError("With spherical coordinates, the component must be 0 in InternalVolume.");
      94             : 
      95           0 :           if (_component > 1 && coord_sys == Moose::COORD_RZ)
      96           0 :             mooseError(
      97             :                 "With cylindrical coordinates, the component must be 0 or 1 in InternalVolume.");
      98             :         }
      99             :     }
     100             :   }
     101           0 : }
     102             : 
     103             : Real
     104           0 : InternalVolume::computeQpIntegral()
     105             : {
     106             :   // Default scale factor is 1
     107             :   Real scale = 1.0;
     108           0 :   if (_coord_sys == Moose::COORD_RSPHERICAL)
     109             :   {
     110             :     // MOOSE will multiply by 4*pi*r*r
     111             :     scale = 1.0 / 3.0;
     112             :   }
     113           0 :   else if (_coord_sys == Moose::COORD_RZ && _component == 0)
     114             :   {
     115             :     // MOOSE will multiply by 2*pi*r
     116             :     // Will integrate over z giving 0.5*2*pi*r*r*height
     117             :     scale = 0.5;
     118             :   }
     119             :   else if (_coord_sys == Moose::COORD_RZ && _component == 1)
     120             :   {
     121             :     // MOOSE will multiply by 2*pi*r
     122             :     // Will integrate over r:
     123             :     // integral(2*pi*r*height) over r:
     124             :     // pi*r*r*height
     125             :     scale = 1.0;
     126             :   }
     127           0 :   return -scale * _q_point[_qp](_component) * _normals[_qp](_component);
     128             : }
     129             : 
     130             : Real
     131           0 : InternalVolume::getValue() const
     132             : {
     133           0 :   return _scale * SideIntegralPostprocessor::getValue() + _addition.value(_t);
     134             : }

Generated by: LCOV version 1.14