LCOV - code coverage report
Current view: top level - src/hdgkernels - AdvectionHDGAssemblyHelper.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 329044 Lines: 55 56 98.2 %
Date: 2026-08-03 21:12:22 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 "AdvectionHDGAssemblyHelper.h"
      11             : #include "MooseFunctor.h"
      12             : #include "MooseObject.h"
      13             : #include "TransientInterface.h"
      14             : 
      15             : using namespace libMesh;
      16             : 
      17             : InputParameters
      18       12975 : AdvectionHDGAssemblyHelper::validParams()
      19             : {
      20       12975 :   auto params = ElementAndTraceScalarHDGAssemblyHelper::validParams();
      21       51900 :   params.addRequiredParam<MaterialPropertyName>(
      22             :       "velocity", "The cell-interior velocity material property used in the volume advection term");
      23       38925 :   params.addRequiredParam<Real>(
      24             :       "coeff", "Constant coefficient multiplying the advected scalar, such as density");
      25       12975 :   return params;
      26           0 : }
      27             : 
      28         303 : AdvectionHDGAssemblyHelper::AdvectionHDGAssemblyHelper(
      29             :     const MooseObject * const moose_obj,
      30             :     MooseVariableDependencyInterface * const mvdi,
      31             :     const TransientInterface * const ti,
      32             :     SystemBase & sys,
      33             :     const Assembly & assembly,
      34             :     const THREAD_ID tid,
      35             :     const std::set<SubdomainID> & block_ids,
      36         303 :     const std::set<BoundaryID> & boundary_ids)
      37             :   : ElementAndTraceScalarHDGAssemblyHelper(
      38             :         moose_obj, mvdi, ti, sys, assembly, tid, block_ids, boundary_ids),
      39         303 :     _velocity(getADMaterialProperty<RealVectorValue>("velocity")),
      40         909 :     _coeff(moose_obj->getParam<Real>("coeff"))
      41             : {
      42         303 : }
      43             : 
      44             : void
      45       56629 : AdvectionHDGAssemblyHelper::scalarVolume()
      46             : {
      47      282413 :   for (const auto qp : make_range(_qrule->n_points()))
      48             :   {
      49      225784 :     const auto advected_quantity = _coeff * _u_sol[qp];
      50      225784 :     const auto qp_term = _JxW[qp] * _velocity[qp] * advected_quantity;
      51     1000768 :     for (const auto i : index_range(_scalar_re))
      52      774984 :       _scalar_re(i) -= _grad_scalar_phi[i][qp] * qp_term;
      53      225784 :   }
      54       56629 : }
      55             : 
      56             : ADReal
      57      802680 : AdvectionHDGAssemblyHelper::computeFlux(const unsigned int qp, const ADReal & face_value) const
      58             : {
      59      802680 :   const auto vdotn = faceVelocity(qp) * _normals[qp];
      60      802680 :   const auto face_phi = _coeff * face_value;
      61      802680 :   const auto internal_phi = _coeff * _u_sol[qp];
      62             :   // If velocity points out of the element, use the interior value; otherwise use the face value.
      63     1605360 :   return 0.5 * vdotn * (internal_phi + face_phi) + 0.5 * abs(vdotn) * (internal_phi - face_phi);
      64      802680 : }
      65             : 
      66             : void
      67      195906 : AdvectionHDGAssemblyHelper::scalarFace()
      68             : {
      69      587122 :   for (const auto qp : make_range(_qrule_face->n_points()))
      70             :   {
      71      391216 :     const auto qp_term = _JxW_face[qp] * computeFlux(qp, _lm_u_sol[qp]);
      72     1751616 :     for (const auto i : index_range(_scalar_re))
      73     1360400 :       _scalar_re(i) += _scalar_phi_face[i][qp] * qp_term;
      74      391216 :   }
      75      195906 : }
      76             : 
      77             : void
      78      195826 : AdvectionHDGAssemblyHelper::lmFace()
      79             : {
      80      586934 :   for (const auto qp : make_range(_qrule_face->n_points()))
      81             :   {
      82      391108 :     const auto qp_term = _JxW_face[qp] * computeFlux(qp, _lm_u_sol[qp]);
      83     1861752 :     for (const auto i : index_range(_lm_re))
      84     1470644 :       _lm_re(i) -= _lm_phi_face[i][qp] * qp_term;
      85      391108 :   }
      86      195826 : }
      87             : 
      88             : void
      89       10204 : AdvectionHDGAssemblyHelper::scalarDirichlet(const Moose::Functor<Real> & dirichlet_functor)
      90             : {
      91       30560 :   for (const auto qp : make_range(_qrule_face->n_points()))
      92             :   {
      93       61068 :     const auto dirichlet_value = dirichlet_functor(
      94       20356 :         Moose::ElemSideQpArg{_current_elem, _current_side, qp, _qrule_face, _q_point_face[qp]},
      95       20356 :         _ti.determineState());
      96       20356 :     const auto qp_term = _JxW_face[qp] * computeFlux(qp, dirichlet_value);
      97       90416 :     for (const auto i : index_range(_scalar_re))
      98       70060 :       _scalar_re(i) += _scalar_phi_face[i][qp] * qp_term;
      99       20356 :   }
     100       10204 : }
     101             : 
     102             : void
     103          52 : AdvectionHDGAssemblyHelper::lmOutflow()
     104             : {
     105         104 :   for (const auto qp : make_range(_qrule_face->n_points()))
     106             :   {
     107             : #ifndef NDEBUG
     108             :     const auto vdotn = faceVelocity(qp) * _normals[qp];
     109             :     mooseAssert(MetaPhysicL::raw_value(vdotn) >= 0, "The velocity must create outflow conditions");
     110             : #endif
     111          52 :     const auto qp_term = _JxW_face[qp] * _coeff * (_lm_u_sol[qp] - _u_sol[qp]);
     112         156 :     for (const auto i : index_range(_lm_re))
     113             :       // Force the facet solution to be equivalent to the interior solution.
     114         104 :       _lm_re(i) += _lm_phi_face[i][qp] * qp_term;
     115          52 :   }
     116          52 : }

Generated by: LCOV version 1.14