LCOV - code coverage report
Current view: top level - src/bcs - ConservativeAdvectionBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 49 53 92.5 %
Date: 2026-05-29 20:35:17 Functions: 9 9 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 "ConservativeAdvectionBC.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("MooseApp", ConservativeAdvectionBC);
      14             : registerMooseObject("MooseApp", ADConservativeAdvectionBC);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18        6285 : ConservativeAdvectionBCTempl<is_ad>::validParams()
      19             : {
      20        6285 :   InputParameters params = GenericIntegratedBC<is_ad>::validParams();
      21       25140 :   params.addParam<MaterialPropertyName>(
      22             :       "velocity_mat_prop",
      23             :       "Velocity vector as a material property. Should be provided when we want the velocity value "
      24             :       "to be determined implicitly (e.g. we don't have a Dirichlet condition)");
      25       25140 :   params.addParam<FunctionName>("velocity_function",
      26             :                                 "Function describing the values of velocity on the boundary.");
      27       12570 :   params.addClassDescription(
      28             :       "Boundary condition for advection when it is integrated by parts. Supports Dirichlet "
      29             :       "(inlet-like) and implicit (outlet-like) conditions.");
      30       25140 :   params.addParam<MaterialPropertyName>("advected_quantity",
      31             :                                         "An optional material property to be advected. If not "
      32             :                                         "supplied, then the variable will be used.");
      33       25140 :   params.addParam<FunctionName>("primal_dirichlet_value",
      34             :                                 "The value of the primal variable on the boundary.");
      35       12570 :   params.addParam<MaterialPropertyName>(
      36             :       "primal_coefficient",
      37       12570 :       1.0,
      38             :       "If a primal Dirichlet value is supplied, then a coefficient may be optionally multiplied "
      39             :       "that multiples the Dirichlet value");
      40        6285 :   return params;
      41           0 : }
      42             : 
      43             : InputParameters
      44        3174 : ConservativeAdvectionBC::validParams()
      45             : {
      46        3174 :   return ConservativeAdvectionBCTempl<false>::validParams();
      47             : }
      48             : 
      49             : template <bool is_ad>
      50          85 : ConservativeAdvectionBCTempl<is_ad>::ConservativeAdvectionBCTempl(
      51             :     const InputParameters & parameters)
      52             :   : GenericIntegratedBC<is_ad>(parameters),
      53          85 :     _velocity_mat_prop(isParamValid("velocity_mat_prop")
      54         157 :                            ? &this->template getGenericMaterialProperty<RealVectorValue, is_ad>(
      55             :                                  "velocity_mat_prop")
      56             :                            : nullptr),
      57         268 :     _velocity_function(isParamValid("velocity_function") ? &getFunction("velocity_function")
      58             :                                                          : nullptr),
      59         170 :     _user_supplied_adv_quant(isParamValid("advected_quantity")),
      60          85 :     _adv_quant(
      61          85 :         _user_supplied_adv_quant
      62          85 :             ? this->template getGenericMaterialProperty<Real, is_ad>("advected_quantity").get()
      63             :             : _u),
      64          85 :     _primal_dirichlet(
      65         242 :         isParamValid("primal_dirichlet_value") ? &getFunction("primal_dirichlet_value") : nullptr),
      66         255 :     _primal_coeff(this->template getGenericMaterialProperty<Real, is_ad>("primal_coefficient"))
      67             : {
      68         255 :   if (isParamSetByUser("primal_coefficient") && !_primal_dirichlet)
      69           0 :     paramError("primal_coefficient",
      70             :                "This parameter should only be provided when 'primal_dirichlet_value' is provided");
      71         255 :   if (static_cast<bool>(_primal_dirichlet) + isParamValid("advected_quantity") > 1)
      72           0 :     mooseError("Only one of 'primal_dirichlet_value' or 'advected_quantity' should be provided");
      73          85 :   if (static_cast<bool>(_velocity_mat_prop) + static_cast<bool>(_velocity_function) != 1)
      74           0 :     mooseError("Exactly one of 'velocity_mat_prop' or 'velocity_function' should be provided");
      75          85 : }
      76             : 
      77          59 : ConservativeAdvectionBC::ConservativeAdvectionBC(const InputParameters & parameters)
      78          59 :   : ConservativeAdvectionBCTempl<false>(parameters)
      79             : {
      80          59 : }
      81             : 
      82             : template <bool is_ad>
      83             : GenericReal<is_ad>
      84      126336 : ConservativeAdvectionBCTempl<is_ad>::computeQpResidual()
      85             : {
      86        2688 :   const auto vdotn =
      87      126336 :       (_velocity_mat_prop
      88       42624 :            ? (*_velocity_mat_prop)[_qp]
      89      160896 :            : GenericRealVectorValue<is_ad>(_velocity_function->vectorValue(_t, _q_point[_qp]))) *
      90      126336 :       this->_normals[_qp];
      91             : 
      92      126336 :   if (_primal_dirichlet)
      93       37248 :     return _test[_i][_qp] * vdotn * _primal_dirichlet->value(_t, _q_point[_qp]) *
      94       38592 :            _primal_coeff[_qp];
      95             :   else
      96       89088 :     return _test[_i][_qp] * vdotn * _adv_quant[_qp];
      97        2688 : }
      98             : 
      99             : Real
     100      108000 : ConservativeAdvectionBC::computeQpJacobian()
     101             : {
     102      108000 :   if (!_user_supplied_adv_quant && !_primal_dirichlet)
     103      105840 :     return _test[_i][_qp] *
     104      105840 :            (_velocity_mat_prop
     105      108000 :                 ? (*_velocity_mat_prop)[_qp]
     106      211680 :                 : RealVectorValue(_velocity_function->vectorValue(_t, _q_point[_qp]))) *
     107      211680 :            this->_normals[_qp] * _phi[_j][_qp];
     108        2160 :   return 0.0;
     109             : }
     110             : 
     111             : template class ConservativeAdvectionBCTempl<false>;
     112             : template class ConservativeAdvectionBCTempl<true>;

Generated by: LCOV version 1.14