LCOV - code coverage report
Current view: top level - src/functormaterials - MixingLengthTurbulentViscosityFunctorMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: ba1ead Lines: 32 35 91.4 %
Date: 2025-08-13 06:50:25 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         166 : MixingLengthTurbulentViscosityFunctorMaterial::validParams()
      21             : {
      22         166 :   InputParameters params = FunctorMaterial::validParams();
      23         166 :   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         332 :   params.addRequiredParam<MooseFunctorName>("u", "The x-velocity");
      27         332 :   params.addParam<MooseFunctorName>("v", 0, "y-velocity"); // only required in 2D and 3D
      28         332 :   params.addParam<MooseFunctorName>("w", 0, "z-velocity"); // only required in 3D
      29         332 :   params.addRequiredParam<MooseFunctorName>("mixing_length", "Turbulent eddy mixing length.");
      30         332 :   params.addRequiredParam<MooseFunctorName>("mu", "The viscosity");
      31         332 :   params.addRequiredParam<MooseFunctorName>("rho", "The value for the density");
      32         166 :   return params;
      33           0 : }
      34             : 
      35          89 : MixingLengthTurbulentViscosityFunctorMaterial::MixingLengthTurbulentViscosityFunctorMaterial(
      36          89 :     const InputParameters & parameters)
      37             :   : FunctorMaterial(parameters),
      38         178 :     _mesh_dimension(_mesh.dimension()),
      39         178 :     _u_vel(getFunctor<ADReal>("u")),
      40         356 :     _v_vel(isParamValid("v") ? &getFunctor<ADReal>("v") : nullptr),
      41         356 :     _w_vel(isParamValid("w") ? &getFunctor<ADReal>("v") : nullptr),
      42          89 :     _mixing_len(getFunctor<ADReal>(NS::mixing_length)),
      43         178 :     _mu(getFunctor<ADReal>("mu")),
      44         267 :     _rho(getFunctor<ADReal>("rho"))
      45             : {
      46         267 :   addFunctorProperty<ADReal>(
      47             :       NS::total_viscosity,
      48      201372 :       [this](const auto & r, const auto & t) -> ADReal
      49             :       {
      50             :         constexpr Real offset = 1e-15; // prevents explosion of sqrt(x) derivative to infinity
      51             : 
      52      201372 :         const auto grad_u = _u_vel.gradient(r, t);
      53             : 
      54      402744 :         ADReal symmetric_strain_tensor_norm = 2.0 * Utility::pow<2>(grad_u(0));
      55      201372 :         if (_mesh_dimension >= 2)
      56             :         {
      57      201372 :           const auto grad_v = _v_vel->gradient(r, t);
      58             : 
      59      201372 :           symmetric_strain_tensor_norm +=
      60      201372 :               2.0 * Utility::pow<2>(grad_v(1)) + Utility::pow<2>(grad_v(0) + grad_u(1));
      61      201372 :           if (_mesh_dimension >= 3)
      62             :           {
      63           0 :             const auto grad_w = _w_vel->gradient(r, t);
      64             : 
      65           0 :             symmetric_strain_tensor_norm += 2.0 * Utility::pow<2>(grad_w(2)) +
      66             :                                             Utility::pow<2>(grad_u(2) + grad_w(0)) +
      67             :                                             Utility::pow<2>(grad_v(2) + grad_w(1));
      68             :           }
      69             :         }
      70      201372 :         symmetric_strain_tensor_norm = std::sqrt(symmetric_strain_tensor_norm + offset);
      71             : 
      72             :         // Return the sum of turbulent viscosity and dynamic viscosity
      73      201372 :         return _mu(r, t) +
      74      604116 :                _rho(r, t) * symmetric_strain_tensor_norm * Utility::pow<2>(_mixing_len(r, t));
      75             :       });
      76         178 : }

Generated by: LCOV version 1.14