LCOV - code coverage report
Current view: top level - src/fvkernels - WCNSFV2PMomentumDriftFlux.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 70 79 88.6 %
Date: 2026-05-29 20:37:52 Functions: 4 5 80.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 "WCNSFV2PMomentumDriftFlux.h"
      11             : #include "INSFVRhieChowInterpolator.h"
      12             : #include "NS.h"
      13             : #include "SystemBase.h"
      14             : #include "RelationshipManager.h"
      15             : #include "Factory.h"
      16             : 
      17             : registerMooseObject("NavierStokesApp", WCNSFV2PMomentumDriftFlux);
      18             : 
      19             : InputParameters
      20         152 : WCNSFV2PMomentumDriftFlux::validParams()
      21             : {
      22         152 :   auto params = INSFVFluxKernel::validParams();
      23         152 :   params.addClassDescription("Implements the drift momentum flux source.");
      24         304 :   params.addRequiredParam<MooseFunctorName>("u_slip", "The slip velocity in the x direction.");
      25         304 :   params.addParam<MooseFunctorName>("v_slip", "The slip velocity in the y direction.");
      26         304 :   params.addParam<MooseFunctorName>("w_slip", "The slip velocity in the z direction.");
      27         304 :   params.addRequiredParam<MooseFunctorName>("rho_d", "Dispersed phase density.");
      28         304 :   params.addParam<MooseFunctorName>("fd", 0.0, "Fraction dispersed phase.");
      29             : 
      30         304 :   params.renameParam("fd", "fraction_dispersed", "");
      31             : 
      32         304 :   MooseEnum coeff_interp_method("average harmonic", "harmonic");
      33         304 :   params.addParam<MooseEnum>("density_interp_method",
      34             :                              coeff_interp_method,
      35             :                              "Switch that can select face interpolation method for the density.");
      36             : 
      37         152 :   return params;
      38         152 : }
      39             : 
      40          80 : WCNSFV2PMomentumDriftFlux::WCNSFV2PMomentumDriftFlux(const InputParameters & params)
      41             :   : INSFVFluxKernel(params),
      42          80 :     _dim(_subproblem.mesh().dimension()),
      43         160 :     _rho_d(getFunctor<ADReal>("rho_d")),
      44         160 :     _f_d(getFunctor<ADReal>("fd")),
      45         160 :     _u_slip(getFunctor<ADReal>("u_slip")),
      46         320 :     _v_slip(isParamValid("v_slip") ? &getFunctor<ADReal>("v_slip") : nullptr),
      47         160 :     _w_slip(isParamValid("w_slip") ? &getFunctor<ADReal>("w_slip") : nullptr),
      48          80 :     _density_interp_method(
      49         320 :         Moose::FV::selectInterpolationMethod(getParam<MooseEnum>("density_interp_method")))
      50             : {
      51          80 :   if (_dim >= 2 && !_v_slip)
      52           0 :     mooseError("In two or more dimensions, the v_slip velocity must be supplied using the 'v_slip' "
      53             :                "parameter");
      54          80 :   if (_dim >= 3 && !_w_slip)
      55           0 :     mooseError(
      56             :         "In three dimensions, the w_slip velocity must be supplied using the 'w_slip' parameter");
      57             : 
      58             :   // Phase fraction could be a nonlinear variable
      59          80 :   const auto & fraction_name = getParam<MooseFunctorName>("fraction_dispersed");
      60         240 :   if (isParamValid("fraction_dispersed") && _fe_problem.hasVariable(fraction_name))
      61         160 :     addMooseVariableDependency(&_fe_problem.getVariable(_tid, fraction_name));
      62          80 : }
      63             : 
      64             : ADReal
      65      331420 : WCNSFV2PMomentumDriftFlux::computeStrongResidual(const bool populate_a_coeffs)
      66             : {
      67      331420 :   _normal = _face_info->normal();
      68      331420 :   const auto state = determineState();
      69             : 
      70             :   Moose::FaceArg face_arg;
      71      331420 :   if (onBoundary(*_face_info))
      72       52622 :     face_arg = singleSidedFaceArg();
      73             :   else
      74      278798 :     face_arg = makeCDFace(*_face_info);
      75             : 
      76             :   ADRealVectorValue u_slip_vel_vec;
      77      331420 :   if (_dim == 1)
      78           0 :     u_slip_vel_vec = ADRealVectorValue(_u_slip(face_arg, state), 0.0, 0.0);
      79      331420 :   else if (_dim == 2)
      80      662840 :     u_slip_vel_vec = ADRealVectorValue(_u_slip(face_arg, state), (*_v_slip)(face_arg, state), 0.0);
      81             :   else
      82           0 :     u_slip_vel_vec = ADRealVectorValue(
      83           0 :         _u_slip(face_arg, state), (*_v_slip)(face_arg, state), (*_w_slip)(face_arg, state));
      84             : 
      85      331420 :   const auto uslipdotn = _normal * u_slip_vel_vec;
      86             : 
      87             :   ADReal face_rho_fd;
      88      331420 :   if (onBoundary(*_face_info))
      89      105244 :     face_rho_fd = _rho_d(makeCDFace(*_face_info), state) * _f_d(makeCDFace(*_face_info), state);
      90             :   else
      91      278798 :     Moose::FV::interpolate(_density_interp_method,
      92             :                            face_rho_fd,
      93      278798 :                            _rho_d(elemArg(), state) * _f_d(elemArg(), state),
      94      557596 :                            _rho_d(neighborArg(), state) * _f_d(neighborArg(), state),
      95      278798 :                            *_face_info,
      96             :                            true);
      97             : 
      98      331420 :   if (populate_a_coeffs)
      99             :   {
     100      331420 :     if (_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
     101             :         _face_type == FaceInfo::VarFaceNeighbors::BOTH)
     102             :     {
     103      331420 :       const auto dof_number = _face_info->elem().dof_number(_sys.number(), _var.number(), 0);
     104      331420 :       if (_index == 0)
     105      331420 :         _ae = (uslipdotn * _u_slip(elemArg(), state)).derivatives()[dof_number];
     106      165710 :       else if (_index == 1)
     107      331420 :         _ae = (uslipdotn * (*_v_slip)(elemArg(), state)).derivatives()[dof_number];
     108             :       else
     109           0 :         _ae = (uslipdotn * (*_w_slip)(elemArg(), state)).derivatives()[dof_number];
     110      331420 :       _ae *= -face_rho_fd;
     111             :     }
     112      331420 :     if (_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR ||
     113             :         _face_type == FaceInfo::VarFaceNeighbors::BOTH)
     114             :     {
     115      278798 :       const auto dof_number = _face_info->neighbor().dof_number(_sys.number(), _var.number(), 0);
     116      278798 :       if (_index == 0)
     117      278798 :         _an = (uslipdotn * _u_slip(neighborArg(), state)).derivatives()[dof_number];
     118      139399 :       else if (_index == 1)
     119      278798 :         _an = (uslipdotn * (*_v_slip)(neighborArg(), state)).derivatives()[dof_number];
     120             :       else
     121           0 :         _an = (uslipdotn * (*_w_slip)(neighborArg(), state)).derivatives()[dof_number];
     122      278798 :       _an *= face_rho_fd;
     123             :     }
     124             :   }
     125             : 
     126      662840 :   return -face_rho_fd * uslipdotn * u_slip_vel_vec(_index);
     127             : }
     128             : 
     129             : void
     130      366482 : WCNSFV2PMomentumDriftFlux::gatherRCData(const FaceInfo & fi)
     131             : {
     132      366482 :   if (skipForBoundary(fi))
     133             :     return;
     134             : 
     135      331420 :   _face_info = &fi;
     136      331420 :   _normal = fi.normal();
     137      331420 :   _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
     138             : 
     139      662840 :   addResidualAndJacobian(computeStrongResidual(true) * (fi.faceArea() * fi.faceCoord()));
     140             : 
     141      331420 :   if (_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
     142             :       _face_type == FaceInfo::VarFaceNeighbors::BOTH)
     143      662840 :     _rc_uo.addToA(&fi.elem(), _index, _ae * (fi.faceArea() * fi.faceCoord()));
     144      331420 :   if (_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR ||
     145             :       _face_type == FaceInfo::VarFaceNeighbors::BOTH)
     146      836394 :     _rc_uo.addToA(fi.neighborPtr(), _index, _an * (fi.faceArea() * fi.faceCoord()));
     147             : }
     148             : 
     149             : ADReal
     150           0 : WCNSFV2PMomentumDriftFlux::computeSegregatedContribution()
     151             : {
     152           0 :   return computeStrongResidual(false);
     153             : }

Generated by: LCOV version 1.14