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 53 : CFLTimeStepSizeTempl<is_ad>::validParams() 26 : { 27 53 : InputParameters params = ElementPostprocessor::validParams(); 28 : 29 106 : params.addParam<Real>("CFL", 0.5, "The CFL number to use in computing time step size"); 30 106 : params.addRequiredParam<std::vector<MaterialPropertyName>>("vel_names", 31 : "Velocity material property name(s)"); 32 106 : 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 212 : params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END}; 38 53 : params.suppressParameter<ExecFlagEnum>("execute_on"); 39 : 40 53 : params.addClassDescription("Computes a time step size based on a user-specified CFL number"); 41 : 42 53 : return params; 43 53 : } 44 : 45 : template <bool is_ad> 46 28 : CFLTimeStepSizeTempl<is_ad>::CFLTimeStepSizeTempl(const InputParameters & parameters) 47 : : ElementPostprocessor(parameters), 48 28 : _CFL(getParam<Real>("CFL")), 49 56 : _vel_names(getParam<std::vector<MaterialPropertyName>>("vel_names")), 50 56 : _c_names(getParam<std::vector<MaterialPropertyName>>("c_names")), 51 28 : _n_phases(_vel_names.size()), 52 28 : _dt(std::numeric_limits<Real>::max()) 53 : { 54 28 : 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 56 : for (unsigned int k = 0; k < _n_phases; ++k) 58 : { 59 28 : _vel.push_back(&getGenericMaterialPropertyByName<Real, is_ad>(_vel_names[k])); 60 28 : _c.push_back(&getGenericMaterialPropertyByName<Real, is_ad>(_c_names[k])); 61 : } 62 28 : } 63 : 64 : template <bool is_ad> 65 : void 66 127 : CFLTimeStepSizeTempl<is_ad>::initialize() 67 : { 68 : // start with the max 69 127 : _dt = std::numeric_limits<Real>::max(); 70 127 : } 71 : 72 : template <bool is_ad> 73 : Real 74 113 : CFLTimeStepSizeTempl<is_ad>::getValue() const 75 : { 76 113 : return _dt; 77 : } 78 : 79 : template <bool is_ad> 80 : void 81 113 : CFLTimeStepSizeTempl<is_ad>::finalize() 82 : { 83 113 : gatherMin(_dt); 84 113 : } 85 : 86 : template <bool is_ad> 87 : void 88 14 : CFLTimeStepSizeTempl<is_ad>::threadJoin(const UserObject & y) 89 : { 90 : const auto & pps = static_cast<const CFLTimeStepSizeTempl<is_ad> &>(y); 91 : 92 14 : _dt = std::min(_dt, pps._dt); 93 14 : } 94 : 95 : template <bool is_ad> 96 : void 97 5100 : CFLTimeStepSizeTempl<is_ad>::execute() 98 : { 99 : // get minimum element diameter for element 100 5100 : const Real h_min_element = _current_elem->hmin(); 101 : 102 : // loop over quadrature points 103 10200 : for (unsigned int qp = 0; qp < _qrule->n_points(); qp++) 104 : { 105 : // determine minimum time step size over all phases 106 10200 : for (unsigned int k = 0; k < _n_phases; ++k) 107 : { 108 5100 : const Real dt_phase = _CFL * h_min_element / 109 5100 : (std::fabs(MetaPhysicL::raw_value((*_vel[k])[qp])) + 110 5100 : MetaPhysicL::raw_value((*_c[k])[qp])); 111 6013 : _dt = std::min(_dt, dt_phase); 112 : } 113 : } 114 5100 : }