LCOV - code coverage report
Current view: top level - src/hdgkernels - AdvectionIPHDGAssemblyHelper.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 67 68 98.5 %
Date: 2025-07-17 01:28:37 Functions: 7 7 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 "AdvectionIPHDGAssemblyHelper.h"
      11             : #include "MooseTypes.h"
      12             : #include "MooseObject.h"
      13             : #include "MaterialPropertyInterface.h"
      14             : 
      15             : using namespace libMesh;
      16             : 
      17             : InputParameters
      18       43794 : AdvectionIPHDGAssemblyHelper::validParams()
      19             : {
      20       43794 :   auto params = IPHDGAssemblyHelper::validParams();
      21       43794 :   params.addRequiredParam<MaterialPropertyName>("velocity", "Velocity vector");
      22      131382 :   params.addParam<Real>(
      23       87588 :       "coeff", 1, "A constant coefficient. This could be something like a density");
      24      131382 :   params.addParam<bool>("self_advection",
      25       87588 :                         true,
      26             :                         "Whether this kernel should advect its variables, e.g. its "
      27             :                         "variable/side_variable pair. If false, we will advect "
      28             :                         "unity (possibly multiplied by the 'coeff' parameter");
      29       43794 :   return params;
      30           0 : }
      31             : 
      32         501 : AdvectionIPHDGAssemblyHelper::AdvectionIPHDGAssemblyHelper(
      33             :     const MooseObject * const moose_obj,
      34             :     MooseVariableDependencyInterface * const mvdi,
      35             :     const TransientInterface * const ti,
      36             :     SystemBase & sys,
      37             :     const Assembly & assembly,
      38             :     const THREAD_ID tid,
      39             :     const std::set<SubdomainID> & block_ids,
      40         501 :     const std::set<BoundaryID> & boundary_ids)
      41             :   : IPHDGAssemblyHelper(moose_obj, mvdi, ti, sys, assembly, tid, block_ids, boundary_ids),
      42         501 :     _velocity(getADMaterialProperty<RealVectorValue>("velocity")),
      43         501 :     _face_velocity(getFaceADMaterialProperty<RealVectorValue>("velocity")),
      44         501 :     _coeff(moose_obj->getParam<Real>("coeff")),
      45        1002 :     _self_advection(moose_obj->getParam<bool>("self_advection"))
      46             : {
      47         501 : }
      48             : 
      49             : void
      50      516084 : AdvectionIPHDGAssemblyHelper::scalarVolume()
      51             : {
      52     2579940 :   for (const auto qp : make_range(_ip_qrule->n_points()))
      53             :   {
      54     2063856 :     ADReal adv_quant = _coeff;
      55     2063856 :     if (_self_advection)
      56     2063856 :       adv_quant *= _u_sol[qp];
      57     2063856 :     const auto qp_term = _ip_JxW[qp] * _velocity[qp] * adv_quant;
      58     9172224 :     for (const auto i : index_range(_scalar_re))
      59     7108368 :       _scalar_re(i) -= _grad_scalar_phi[i][qp] * qp_term;
      60     2063856 :   }
      61      516084 : }
      62             : 
      63             : void
      64     1844592 : AdvectionIPHDGAssemblyHelper::scalarFace()
      65             : {
      66     5533320 :   for (const auto qp : make_range(_ip_qrule_face->n_points()))
      67             :   {
      68     3688728 :     const auto vdotn = _face_velocity[qp] * _ip_normals[qp];
      69     3688728 :     ADReal adv_quant = _coeff;
      70     3688728 :     if (_self_advection)
      71     3688728 :       adv_quant *= (MetaPhysicL::raw_value(vdotn) >= 0 ? _u_sol[qp] : _lm_u_sol[qp]);
      72     3688728 :     const auto qp_term = _ip_JxW_face[qp] * vdotn * adv_quant;
      73    16546680 :     for (const auto i : index_range(_scalar_re))
      74    12857952 :       _scalar_re(i) += _scalar_phi_face[i][qp] * qp_term;
      75     3688728 :   }
      76     1844592 : }
      77             : 
      78             : void
      79     1844568 : AdvectionIPHDGAssemblyHelper::lmFace()
      80             : {
      81     5533272 :   for (const auto qp : make_range(_ip_qrule_face->n_points()))
      82             :   {
      83     3688704 :     const auto vdotn = _face_velocity[qp] * _ip_normals[qp];
      84     3688704 :     ADReal adv_quant = _coeff;
      85     3688704 :     if (_self_advection)
      86     3688704 :       adv_quant *= (MetaPhysicL::raw_value(vdotn) >= 0 ? _u_sol[qp] : _lm_u_sol[qp]);
      87     3688704 :     const auto qp_term = _ip_JxW_face[qp] * vdotn * adv_quant;
      88    31195872 :     for (const auto i : index_range(_lm_re))
      89    27507168 :       _lm_re(i) -= _lm_phi_face[i][qp] * qp_term;
      90     3688704 :   }
      91     1844568 : }
      92             : 
      93             : void
      94       47400 : AdvectionIPHDGAssemblyHelper::scalarDirichlet(const Moose::Functor<Real> & dirichlet_functor)
      95             : {
      96      142176 :   for (const auto qp : make_range(_ip_qrule_face->n_points()))
      97             :   {
      98       94776 :     const auto vdotn = _face_velocity[qp] * _ip_normals[qp];
      99             :     mooseAssert(_self_advection, "This shouldn't be called if we are not self-advecting");
     100      284328 :     const auto dirichlet_value = dirichlet_functor(
     101       94776 :         Moose::ElemSideQpArg{
     102       94776 :             _ip_current_elem, _ip_current_side, qp, _ip_qrule_face, _ip_q_point_face[qp]},
     103       94776 :         _ti.determineState());
     104       94776 :     const auto adv_quant = dirichlet_value * _coeff;
     105       94776 :     const auto qp_term = _ip_JxW_face[qp] * vdotn * adv_quant;
     106      421416 :     for (const auto i : index_range(_scalar_re))
     107      326640 :       _scalar_re(i) += _scalar_phi_face[i][qp] * qp_term;
     108       94776 :   }
     109       47400 : }
     110             : 
     111             : void
     112          24 : AdvectionIPHDGAssemblyHelper::lmOutflow()
     113             : {
     114          48 :   for (const auto qp : make_range(_ip_qrule_face->n_points()))
     115             :   {
     116             : #ifndef NDEBUG
     117             :     const auto vdotn = _face_velocity[qp] * _ip_normals[qp];
     118             :     mooseAssert(MetaPhysicL::raw_value(vdotn) >= 0, "The velocity must create outflow conditions");
     119             :     mooseAssert(_self_advection, "This shouldn't be called if we are not self-advecting");
     120             : #endif
     121          24 :     const auto qp_term = _ip_JxW_face[qp] * _coeff * (_lm_u_sol[qp] - _u_sol[qp]);
     122          72 :     for (const auto i : index_range(_lm_re))
     123             :       // Force the LM solution to be equivalent to the internal solution
     124          48 :       _lm_re(i) += _lm_phi_face[i][qp] * qp_term;
     125          24 :   }
     126          24 : }

Generated by: LCOV version 1.14