LCOV - code coverage report
Current view: top level - src/fvkernels - NSFVPhaseChangeSource.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: ba1ead Lines: 26 27 96.3 %
Date: 2025-08-13 06:50:25 Functions: 3 3 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 "NSFVPhaseChangeSource.h"
      11             : #include "NS.h"
      12             : 
      13             : registerMooseObject("NavierStokesApp", NSFVPhaseChangeSource);
      14             : 
      15             : InputParameters
      16          80 : NSFVPhaseChangeSource::validParams()
      17             : {
      18          80 :   auto params = FVElementalKernel::validParams();
      19          80 :   params.addClassDescription("Computes the energy source due to solidification/melting.");
      20         160 :   params.addRequiredParam<MooseFunctorName>("liquid_fraction", "Liquid Fraction Functor.");
      21         160 :   params.addRequiredParam<MooseFunctorName>("L", "Latent heat.");
      22          80 :   params.addRequiredParam<MooseFunctorName>(NS::density, "The mixture density.");
      23         160 :   params.addRequiredParam<MooseFunctorName>("T_solidus", "The solidus temperature.");
      24         160 :   params.addRequiredParam<MooseFunctorName>("T_liquidus", "The liquidus temperature.");
      25          80 :   return params;
      26           0 : }
      27             : 
      28          42 : NSFVPhaseChangeSource::NSFVPhaseChangeSource(const InputParameters & parameters)
      29             :   : FVElementalKernel(parameters),
      30          42 :     _liquid_fraction(getFunctor<ADReal>("liquid_fraction")),
      31          84 :     _L(getFunctor<ADReal>("L")),
      32          42 :     _rho(getFunctor<ADReal>(NS::density)),
      33          84 :     _T_solidus(getFunctor<ADReal>("T_solidus")),
      34         126 :     _T_liquidus(getFunctor<ADReal>("T_liquidus"))
      35             : {
      36          42 : }
      37             : 
      38             : ADReal
      39      186950 : NSFVPhaseChangeSource::computeQpResidual()
      40             : {
      41             :   using namespace MetaPhysicL;
      42             : 
      43      186950 :   const auto elem_arg = makeElemArg(_current_elem);
      44      186950 :   const auto state = determineState();
      45             : 
      46      186950 :   const auto T_sol = _T_solidus(elem_arg, state);
      47      186950 :   const auto T_liq = _T_liquidus(elem_arg, state);
      48      186950 :   const auto T = _var(elem_arg, state);
      49             : 
      50             :   // This is necessary to have a bounded derivative
      51             :   // Otherwise the nonlinear solve won't converge!
      52      186950 :   const auto fl = (T - T_sol) / (T_liq - T_sol);
      53             : 
      54             :   // The (6.0) comes from the integral of x*(1-x) between 0 and 1.
      55      560850 :   const auto source_index = std::max(6.0 * fl * (1 - fl), (ADReal)0);
      56      186950 :   const auto pre_factor = (_L(elem_arg, state) * _rho(elem_arg, state)) / (T_liq - T_sol);
      57             : 
      58      373900 :   return source_index * pre_factor * _var.dot(elem_arg, state);
      59             : }

Generated by: LCOV version 1.14