LCOV - code coverage report
Current view: top level - src/postprocessors - CFLTimeStepSize.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 41 42 97.6 %
Date: 2025-08-14 10:14:56 Functions: 7 14 50.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             : // Navier-Stokes includes
      11             : #include "CFLTimeStepSize.h"
      12             : 
      13             : // MOOSE includes
      14             : #include "libmesh/quadrature.h"
      15             : #include "metaphysicl/raw_type.h"
      16             : 
      17             : #include <algorithm>
      18             : #include <limits>
      19             : 
      20             : registerMooseObject("NavierStokesApp", CFLTimeStepSize);
      21             : registerMooseObject("NavierStokesApp", ADCFLTimeStepSize);
      22             : 
      23             : template <bool is_ad>
      24             : InputParameters
      25         103 : CFLTimeStepSizeTempl<is_ad>::validParams()
      26             : {
      27         103 :   InputParameters params = ElementPostprocessor::validParams();
      28             : 
      29         206 :   params.addParam<Real>("CFL", 0.5, "The CFL number to use in computing time step size");
      30         206 :   params.addRequiredParam<std::vector<MaterialPropertyName>>("vel_names",
      31             :                                                              "Velocity material property name(s)");
      32         206 :   params.addRequiredParam<std::vector<MaterialPropertyName>>(
      33             :       "c_names", "Sound speed material property name(s)");
      34             : 
      35             :   // Because this post-processor is meant to be used with PostprocessorDT, it
      36             :   // should be executed on initial (not included by default) and timestep end.
      37         412 :   params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
      38         103 :   params.suppressParameter<ExecFlagEnum>("execute_on");
      39             : 
      40         103 :   params.addClassDescription("Computes a time step size based on a user-specified CFL number");
      41             : 
      42         103 :   return params;
      43         103 : }
      44             : 
      45             : template <bool is_ad>
      46          56 : CFLTimeStepSizeTempl<is_ad>::CFLTimeStepSizeTempl(const InputParameters & parameters)
      47             :   : ElementPostprocessor(parameters),
      48          56 :     _CFL(getParam<Real>("CFL")),
      49         112 :     _vel_names(getParam<std::vector<MaterialPropertyName>>("vel_names")),
      50         112 :     _c_names(getParam<std::vector<MaterialPropertyName>>("c_names")),
      51          56 :     _n_phases(_vel_names.size()),
      52          56 :     _dt(std::numeric_limits<Real>::max())
      53             : {
      54          56 :   if (_vel_names.size() != _c_names.size())
      55           0 :     mooseError("The number of elements in the parameters 'vel_names' and 'c_names' must be equal.");
      56             : 
      57         112 :   for (unsigned int k = 0; k < _n_phases; ++k)
      58             :   {
      59          56 :     _vel.push_back(&getGenericMaterialPropertyByName<Real, is_ad>(_vel_names[k]));
      60          56 :     _c.push_back(&getGenericMaterialPropertyByName<Real, is_ad>(_c_names[k]));
      61             :   }
      62          56 : }
      63             : 
      64             : template <bool is_ad>
      65             : void
      66         239 : CFLTimeStepSizeTempl<is_ad>::initialize()
      67             : {
      68             :   // start with the max
      69         239 :   _dt = std::numeric_limits<Real>::max();
      70         239 : }
      71             : 
      72             : template <bool is_ad>
      73             : Real
      74         197 : CFLTimeStepSizeTempl<is_ad>::getValue() const
      75             : {
      76         197 :   return _dt;
      77             : }
      78             : 
      79             : template <bool is_ad>
      80             : void
      81         197 : CFLTimeStepSizeTempl<is_ad>::finalize()
      82             : {
      83         197 :   gatherMin(_dt);
      84         197 : }
      85             : 
      86             : template <bool is_ad>
      87             : void
      88          42 : CFLTimeStepSizeTempl<is_ad>::threadJoin(const UserObject & y)
      89             : {
      90             :   const auto & pps = static_cast<const CFLTimeStepSizeTempl<is_ad> &>(y);
      91             : 
      92          42 :   _dt = std::min(_dt, pps._dt);
      93          42 : }
      94             : 
      95             : template <bool is_ad>
      96             : void
      97        7620 : CFLTimeStepSizeTempl<is_ad>::execute()
      98             : {
      99             :   // get minimum element diameter for element
     100        7620 :   const Real h_min_element = _current_elem->hmin();
     101             : 
     102             :   // loop over quadrature points
     103       15240 :   for (unsigned int qp = 0; qp < _qrule->n_points(); qp++)
     104             :   {
     105             :     // determine minimum time step size over all phases
     106       15240 :     for (unsigned int k = 0; k < _n_phases; ++k)
     107             :     {
     108        7620 :       const Real dt_phase = _CFL * h_min_element /
     109        7620 :                             (std::fabs(MetaPhysicL::raw_value((*_vel[k])[qp])) +
     110        7620 :                              MetaPhysicL::raw_value((*_c[k])[qp]));
     111        9111 :       _dt = std::min(_dt, dt_phase);
     112             :     }
     113             :   }
     114        7620 : }

Generated by: LCOV version 1.14