LCOV - code coverage report
Current view: top level - src/bcs - INSFEFluidEnergyBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 61 70 87.1 %
Date: 2025-08-14 10:14:56 Functions: 5 5 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 "INSFEFluidEnergyBC.h"
      11             : 
      12             : registerMooseObject("NavierStokesApp", INSFEFluidEnergyBC);
      13             : registerMooseObjectRenamed("NavierStokesApp",
      14             :                            MDFluidEnergyBC,
      15             :                            "02/01/2024 00:00",
      16             :                            INSFEFluidEnergyBC);
      17             : 
      18             : InputParameters
      19          82 : INSFEFluidEnergyBC::validParams()
      20             : {
      21          82 :   InputParameters params = INSFEFluidIntegratedBCBase::validParams();
      22          82 :   params.addClassDescription("Specifies flow of energy through a boundary");
      23         164 :   params.addParam<FunctionName>("v_fn", "Velocity function with time at the boundary");
      24         164 :   params.addParam<FunctionName>("T_fn", "Temperature function with time at the boundary");
      25         164 :   params.addCoupledVar("porosity_elem", "Element averaged porosity");
      26         164 :   params.addCoupledVar("T_branch", "Coupled scalar branch temperature");
      27          82 :   return params;
      28           0 : }
      29             : 
      30          44 : INSFEFluidEnergyBC::INSFEFluidEnergyBC(const InputParameters & parameters)
      31             :   : INSFEFluidIntegratedBCBase(parameters),
      32          44 :     _cp(getMaterialProperty<Real>("cp_fluid")),
      33          44 :     _has_vbc(parameters.isParamValid("v_fn")),
      34          44 :     _has_Tbc(parameters.isParamValid("T_fn")),
      35          44 :     _v_fn(_has_vbc ? &getFunction("v_fn") : NULL),
      36          44 :     _T_fn(_has_Tbc ? &getFunction("T_fn") : NULL),
      37          88 :     _k_elem(getMaterialProperty<Real>("k_fluid_elem")),
      38          88 :     _has_porosity_elem(isParamValid("porosity_elem")),
      39          44 :     _porosity_elem(_has_porosity_elem ? coupledValue("porosity_elem")
      40          88 :                                       : (_has_porosity ? coupledValue("porosity") : _zero)),
      41          44 :     _has_Tbranch(parameters.isParamValid("T_branch")),
      42          44 :     _T_branch(_has_Tbranch ? coupledScalarValue("T_branch") : _zero),
      43          88 :     _T_branch_var_number(_has_Tbranch ? coupledScalar("T_branch") : libMesh::invalid_uint)
      44             : {
      45          44 :   if (_has_vbc && !_has_Tbc)
      46           0 :     mooseError("For an inlet condition ('v_fn' is given), a boundary temperature ('T_fn') is also "
      47             :                "needed.");
      48          44 :   if (_has_Tbc && _has_Tbranch)
      49           0 :     mooseError("Temperature function and branch temperature cannot be BOTH specified in "
      50             :                "INSFEFluidEnergyBC.");
      51          44 : }
      52             : 
      53             : Real
      54      576800 : INSFEFluidEnergyBC::computeQpResidual()
      55             : {
      56      576800 :   RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
      57             : 
      58      576800 :   Real v_bc = _has_vbc ? -_v_fn->value(_t, _q_point[_qp]) : vec_vel * _normals[_qp];
      59      576800 :   Real T_bc = _u[_qp];
      60             :   // A more restrict condition might be needed here
      61             :   // For an inlet or reverse outlet flow condition, a T_bc or a T_branch should be required.
      62      576800 :   if (v_bc < 0)
      63             :   {
      64      288400 :     if (_has_Tbc)
      65      288400 :       T_bc = _T_fn->value(_t, _q_point[_qp]);
      66      288400 :     if (_has_Tbranch)
      67           0 :       T_bc = _T_branch[0];
      68             :   }
      69      576800 :   Real enthalpy = _eos.h_from_p_T(_pressure[_qp], T_bc);
      70             : 
      71      576800 :   Real convection_term = _rho[_qp] * v_bc * enthalpy * _test[_i][_qp];
      72             :   Real diffusion_term =
      73      576800 :       -_porosity_elem[_qp] * _k_elem[_qp] * _grad_u[_qp] * _normals[_qp] * _test[_i][_qp];
      74             : 
      75      576800 :   return convection_term + diffusion_term;
      76             : }
      77             : 
      78             : Real
      79       12160 : INSFEFluidEnergyBC::computeQpJacobian()
      80             : {
      81       12160 :   RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
      82       12160 :   Real v_bc = _has_vbc ? -_v_fn->value(_t, _q_point[_qp]) : vec_vel * _normals[_qp];
      83             : 
      84             :   Real convection_term = 0;
      85       12160 :   if (v_bc < 0) // Inlet
      86             :     convection_term = 0;
      87             :   else // Outlet or not a real boundary
      88             :   {
      89             :     Real rho, drho_dp, drho_dT;
      90        6080 :     _eos.rho_from_p_T(_pressure[_qp], _u[_qp], rho, drho_dp, drho_dT);
      91        6080 :     Real enthalpy = _eos.h_from_p_T(_pressure[_qp], _u[_qp]);
      92             : 
      93        6080 :     convection_term =
      94        6080 :         (_rho[_qp] * _cp[_qp] + drho_dT * enthalpy) * v_bc * _phi[_j][_qp] * _test[_i][_qp];
      95             :   }
      96             : 
      97             :   Real diffusion_term =
      98       12160 :       -_porosity_elem[_qp] * _k_elem[_qp] * _grad_phi[_j][_qp] * _normals[_qp] * _test[_i][_qp];
      99             : 
     100       12160 :   return convection_term + diffusion_term;
     101             : }
     102             : 
     103             : Real
     104       36480 : INSFEFluidEnergyBC::computeQpOffDiagJacobian(unsigned int jvar)
     105             : {
     106             :   // this is jocabian term w.r.t branch temperature
     107       36480 :   if (jvar == _T_branch_var_number)
     108             :   {
     109           0 :     RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
     110           0 :     Real v_bc = _has_vbc ? -_v_fn->value(_t, _q_point[_qp]) : vec_vel * _normals[_qp];
     111           0 :     if (v_bc < 0)
     112             :     {
     113           0 :       return _rho[_qp] * v_bc * _eos.cp_from_p_T(1e5, _T_branch[0]) * _test[_i][_qp];
     114             :     }
     115             :   }
     116             : 
     117             :   Real jac = 0;
     118       36480 :   unsigned m = this->mapVarNumber(jvar);
     119       36480 :   switch (m)
     120             :   {
     121       24320 :     case 1:
     122             :     case 2:
     123             :     case 3:
     124       24320 :       if (!_has_vbc) // if has_vbc, Jacobians are zero
     125             :       {
     126       24320 :         RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
     127       24320 :         Real v_bc = vec_vel * _normals[_qp];
     128       24320 :         Real T_bc = _u[_qp];
     129       24320 :         if (v_bc < 0)
     130             :         {
     131       12160 :           if (_has_Tbc)
     132       12160 :             T_bc = _T_fn->value(_t, _q_point[_qp]);
     133       12160 :           if (_has_Tbranch)
     134           0 :             T_bc = _T_branch[0];
     135             :         }
     136       24320 :         Real enthalpy = _eos.h_from_p_T(_pressure[_qp], T_bc);
     137       24320 :         jac = _rho[_qp] * _phi[_j][_qp] * enthalpy * _normals[_qp](m - 1) * _test[_i][_qp];
     138             :       }
     139             :       break;
     140             : 
     141             :     default:
     142             :       jac = 0;
     143             :   }
     144             :   return jac;
     145             : }

Generated by: LCOV version 1.14