LCOV - code coverage report
Current view: top level - src/functormaterials - MixingLengthTurbulentViscosityFunctorMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 32 35 91.4 %
Date: 2026-05-29 20:37:52 Functions: 3 8 37.5 %
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 "MixingLengthTurbulentViscosityFunctorMaterial.h"
      11             : #include "NS.h"
      12             : 
      13             : registerMooseObject("NavierStokesApp", MixingLengthTurbulentViscosityFunctorMaterial);
      14             : registerMooseObjectRenamed("NavierStokesApp",
      15             :                            MixingLengthTurbulentViscosityMaterial,
      16             :                            "08/01/2024 00:00",
      17             :                            MixingLengthTurbulentViscosityFunctorMaterial);
      18             : 
      19             : InputParameters
      20         138 : MixingLengthTurbulentViscosityFunctorMaterial::validParams()
      21             : {
      22         138 :   InputParameters params = FunctorMaterial::validParams();
      23         138 :   params.addClassDescription("Computes the material property corresponding to the total viscosity"
      24             :                              "comprising the mixing length model turbulent total_viscosity"
      25             :                              "and the molecular viscosity.");
      26         276 :   params.addRequiredParam<MooseFunctorName>("u", "The x-velocity");
      27         276 :   params.addParam<MooseFunctorName>("v", 0, "y-velocity"); // only required in 2D and 3D
      28         276 :   params.addParam<MooseFunctorName>("w", 0, "z-velocity"); // only required in 3D
      29         276 :   params.addRequiredParam<MooseFunctorName>("mixing_length", "Turbulent eddy mixing length.");
      30         276 :   params.addRequiredParam<MooseFunctorName>("mu", "The viscosity");
      31         276 :   params.addRequiredParam<MooseFunctorName>("rho", "The value for the density");
      32         138 :   return params;
      33           0 : }
      34             : 
      35          75 : MixingLengthTurbulentViscosityFunctorMaterial::MixingLengthTurbulentViscosityFunctorMaterial(
      36          75 :     const InputParameters & parameters)
      37             :   : FunctorMaterial(parameters),
      38         150 :     _mesh_dimension(_mesh.dimension()),
      39         150 :     _u_vel(getFunctor<ADReal>("u")),
      40         300 :     _v_vel(isParamValid("v") ? &getFunctor<ADReal>("v") : nullptr),
      41         300 :     _w_vel(isParamValid("w") ? &getFunctor<ADReal>("v") : nullptr),
      42          75 :     _mixing_len(getFunctor<ADReal>(NS::mixing_length)),
      43         150 :     _mu(getFunctor<ADReal>("mu")),
      44         225 :     _rho(getFunctor<ADReal>("rho"))
      45             : {
      46         225 :   addFunctorProperty<ADReal>(
      47             :       NS::total_viscosity,
      48      191292 :       [this](const auto & r, const auto & t) -> ADReal
      49             :       {
      50             :         using std::sqrt;
      51             : 
      52             :         constexpr Real offset = 1e-15; // prevents explosion of sqrt(x) derivative to infinity
      53             : 
      54      191292 :         const auto grad_u = _u_vel.gradient(r, t);
      55             : 
      56      382584 :         ADReal symmetric_strain_tensor_norm = 2.0 * Utility::pow<2>(grad_u(0));
      57      191292 :         if (_mesh_dimension >= 2)
      58             :         {
      59      191292 :           const auto grad_v = _v_vel->gradient(r, t);
      60             : 
      61      191292 :           symmetric_strain_tensor_norm +=
      62      191292 :               2.0 * Utility::pow<2>(grad_v(1)) + Utility::pow<2>(grad_v(0) + grad_u(1));
      63      191292 :           if (_mesh_dimension >= 3)
      64             :           {
      65           0 :             const auto grad_w = _w_vel->gradient(r, t);
      66             : 
      67           0 :             symmetric_strain_tensor_norm += 2.0 * Utility::pow<2>(grad_w(2)) +
      68             :                                             Utility::pow<2>(grad_u(2) + grad_w(0)) +
      69             :                                             Utility::pow<2>(grad_v(2) + grad_w(1));
      70             :           }
      71             :         }
      72      191292 :         symmetric_strain_tensor_norm = sqrt(symmetric_strain_tensor_norm + offset);
      73             : 
      74             :         // Return the sum of turbulent viscosity and dynamic viscosity
      75      191292 :         return _mu(r, t) +
      76      573876 :                _rho(r, t) * symmetric_strain_tensor_norm * Utility::pow<2>(_mixing_len(r, t));
      77             :       });
      78         150 : }

Generated by: LCOV version 1.14