LCOV - code coverage report
Current view: top level - src/linearfvbcs - LinearFVAdvectionDiffusionExtrapolatedBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 28 43 65.1 %
Date: 2025-07-17 01:28:37 Functions: 5 8 62.5 %
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 "LinearFVAdvectionDiffusionExtrapolatedBC.h"
      11             : 
      12             : registerMooseObject("MooseApp", LinearFVAdvectionDiffusionExtrapolatedBC);
      13             : 
      14             : InputParameters
      15       29286 : LinearFVAdvectionDiffusionExtrapolatedBC::validParams()
      16             : {
      17       29286 :   InputParameters params = LinearFVAdvectionDiffusionBC::validParams();
      18       29286 :   params.addClassDescription(
      19             :       "Adds a boundary condition which calculates the face values and face gradients assuming one "
      20             :       "or two term expansions from the cell centroid. This kernel is only compatible "
      21             :       "with advection-diffusion problems.");
      22       87858 :   params.addParam<bool>(
      23             :       "use_two_term_expansion",
      24       58572 :       false,
      25             :       "If an approximate linear expansion should be used to compute the face value.");
      26       29286 :   return params;
      27           0 : }
      28             : 
      29         378 : LinearFVAdvectionDiffusionExtrapolatedBC::LinearFVAdvectionDiffusionExtrapolatedBC(
      30         378 :     const InputParameters & parameters)
      31             :   : LinearFVAdvectionDiffusionBC(parameters),
      32         378 :     _two_term_expansion(getParam<bool>("use_two_term_expansion"))
      33             : {
      34         378 :   if (_two_term_expansion)
      35         252 :     _var.computeCellGradients();
      36         378 : }
      37             : 
      38             : Real
      39       42084 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryValue() const
      40             : {
      41             :   // We allow internal boundaries too so we need to check which side we are on
      42       42084 :   const auto elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM
      43       42084 :                              ? _current_face_info->elemInfo()
      44           0 :                              : _current_face_info->neighborInfo();
      45             : 
      46             :   // By default we approximate the boundary value with the neighboring cell value
      47       42084 :   auto boundary_value = _var.getElemValue(*elem_info, determineState());
      48             : 
      49             :   // If we request linear extrapolation, we add the gradient term as well
      50       42084 :   if (_two_term_expansion)
      51       42084 :     boundary_value += _var.gradSln(*elem_info) * computeCellToFaceVector();
      52             : 
      53       42084 :   return boundary_value;
      54             : }
      55             : 
      56             : Real
      57           0 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryNormalGradient() const
      58             : {
      59             :   // By default we assume that the face value is the same as the cell center value so we
      60             :   // have a zero gradient.
      61           0 :   Real normal_gradient = 0.0;
      62             : 
      63             :   // If we request linear extrapolation, we will have a gradient. We use
      64           0 :   if (_two_term_expansion)
      65             :   {
      66           0 :     const auto elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM
      67           0 :                                ? _current_face_info->elemInfo()
      68           0 :                                : _current_face_info->neighborInfo();
      69           0 :     normal_gradient = _var.gradSln(*elem_info) * _current_face_info->normal();
      70             :   }
      71           0 :   return normal_gradient;
      72             : }
      73             : 
      74             : Real
      75       22890 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryValueMatrixContribution() const
      76             : {
      77       22890 :   return 1.0;
      78             : }
      79             : 
      80             : Real
      81       22890 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryValueRHSContribution() const
      82             : {
      83             :   // If we approximate the face value with the cell value, we
      84             :   // don't need to add anything to the right hand side
      85       22890 :   Real contribution = 0.0;
      86             : 
      87             :   // If we have linear extrapolation, we chose to add the linear term to
      88             :   // the right hand side instead of the system matrix.
      89       22890 :   if (_two_term_expansion)
      90             :   {
      91       21042 :     const auto elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM
      92       21042 :                                ? _current_face_info->elemInfo()
      93           0 :                                : _current_face_info->neighborInfo();
      94       21042 :     contribution = _var.gradSln(*elem_info) * computeCellToFaceVector();
      95             :   }
      96             : 
      97       22890 :   return contribution;
      98             : }
      99             : 
     100             : Real
     101           0 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryGradientMatrixContribution() const
     102             : {
     103           0 :   return 1.0 / computeCellToFaceDistance();
     104             : }
     105             : 
     106             : Real
     107           0 : LinearFVAdvectionDiffusionExtrapolatedBC::computeBoundaryGradientRHSContribution() const
     108             : {
     109           0 :   return computeBoundaryValue() / computeCellToFaceDistance();
     110             : }

Generated by: LCOV version 1.14