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 : #pragma once 11 : 12 : // Moose includes 13 : #include "RhieChowMassFlux.h" 14 : #include "SIMPLESolveBase.h" 15 : #include "CHTHandler.h" 16 : 17 : /** 18 : * Common base class for segregated solvers for the Navier-Stokes 19 : * equations with linear FV assembly routines. Once the nonlinear 20 : * assembly-based routines are retired, this will be the primary base class 21 : * instead of SIMPLESolveBase. 22 : */ 23 : class LinearAssemblySegregatedSolve : public SIMPLESolveBase 24 : { 25 : public: 26 : LinearAssemblySegregatedSolve(Executioner & ex); 27 : 28 : static InputParameters validParams(); 29 : 30 : virtual void linkRhieChowUserObject() override; 31 : 32 : virtual void initialSetup() override; 33 : 34 : /** 35 : * Performs the momentum pressure coupling. 36 : * @return True if solver is converged. 37 : */ 38 : virtual bool solve() override; 39 : 40 : /// Return pointers to the systems which are solved for within this object 41 1002 : const std::vector<LinearSystem *> systemsToSolve() const { return _systems_to_solve; } 42 : 43 : protected: 44 : virtual std::vector<std::pair<unsigned int, Real>> solveMomentumPredictor() override; 45 : virtual std::pair<unsigned int, Real> solvePressureCorrector() override; 46 : 47 : /// Computes new velocity field based on computed pressure gradients 48 : /// @param subtract_updated_pressure If we need to subtract the updated 49 : /// pressure gradient from the right hand side of the system 50 : /// @param recompute_face_mass_flux If we want to recompute the face flux too 51 : /// @param solver_params Dummy solver parameter object for the linear solve 52 : virtual std::pair<unsigned int, Real> correctVelocity(const bool subtract_updated_pressure, 53 : const bool recompute_face_mass_flux, 54 : const SolverParams & solver_params); 55 : 56 : /// Solve an equation which contains an advection term that depends 57 : /// on the solution of the segregated Navier-Stokes equations. 58 : /// @param system_num The number of the system which is solved 59 : /// @param system Reference to the system which is solved 60 : /// @param relaxation_factor The relaxation factor for matrix relaxation 61 : /// @param solver_config The solver configuration object for the linear solve 62 : /// @param abs_tol The scaled absolute tolerance for the linear solve 63 : /// @param field_relaxation (optional) The relaxation factor for fields if relax_fields is true. Default value is 1.0. 64 : /// @param min_value_limiter (optional) The minimum value for the solution field 65 : /// @return The normalized residual norm of the equation. 66 : std::pair<unsigned int, Real> 67 : solveAdvectedSystem(const unsigned int system_num, 68 : LinearSystem & system, 69 : const Real relaxation_factor, 70 : libMesh::SolverConfiguration & solver_config, 71 : const Real abs_tol, 72 : const Real field_relaxation = 1.0, 73 : const Real min_value_limiter = std::numeric_limits<Real>::min()); 74 : 75 : /// Aggregated storage for residuals, tolerances, and indices used in convergence checks 76 : struct ResidualStorage 77 : { 78 : /// (linear iterations, normalized residual) entries in the order used by NS::FV::converged() 79 : std::vector<std::pair<unsigned int, Real>> ns_residuals; 80 : /// Absolute tolerances matching ns_residuals 81 : std::vector<Real> ns_abs_tols; 82 : /// Indices of momentum equations in ns_residuals 83 : std::vector<std::size_t> momentum_indices; 84 : /// Index of the pressure equation in ns_residuals 85 : std::size_t pressure_index = Moose::invalid_size_t; 86 : /// Index of the energy equation in ns_residuals 87 : std::size_t energy_index = Moose::invalid_size_t; 88 : /// Index of the solid energy equation in ns_residuals 89 : std::size_t solid_energy_index = Moose::invalid_size_t; 90 : /// Indices of active scalar equations in ns_residuals 91 : std::vector<std::size_t> active_scalar_indices; 92 : /// Indices of turbulence surrogate equations in ns_residuals 93 : std::vector<std::size_t> turbulence_indices; 94 : /// Indices of participating media radiation equations in ns_residuals 95 : std::vector<std::size_t> pm_radiation_indices; 96 : /// This will be an initial indicator if we have something to solve. 97 : /// If we dont have anything we just set this to true. 98 : bool converged = false; 99 : }; 100 : 101 : /** 102 : * Build residual/tolerance vectors and associated indices for all enabled systems. 103 : */ 104 : ResidualStorage setupResidualStorage() const; 105 : 106 : /// Solve an equation which contains the solid energy conservation. 107 : std::pair<unsigned int, Real> solveSolidEnergy(); 108 : 109 : /// The number(s) of the system(s) corresponding to the momentum equation(s) 110 : std::vector<unsigned int> _momentum_system_numbers; 111 : 112 : /// Pointer(s) to the system(s) corresponding to the momentum equation(s) 113 : std::vector<LinearSystem *> _momentum_systems; 114 : 115 : /// The number of the system corresponding to the pressure equation 116 : const unsigned int _pressure_sys_number; 117 : 118 : /// Reference to the linear system corresponding to the pressure equation 119 : LinearSystem & _pressure_system; 120 : 121 : /// The number of the system corresponding to the energy equation 122 : const unsigned int _energy_sys_number; 123 : 124 : /// Pointer to the linear system corresponding to the fluid energy equation 125 : LinearSystem * _energy_system; 126 : 127 : /// The number of the system corresponding to the solid energy equation 128 : const unsigned int _solid_energy_sys_number; 129 : 130 : /// Pointer to the linear system corresponding to the solid energy equation 131 : LinearSystem * _solid_energy_system; 132 : 133 : /// Pointer(s) to the system(s) corresponding to the passive scalar equation(s) 134 : std::vector<LinearSystem *> _passive_scalar_systems; 135 : 136 : /// Pointer(s) to the system(s) corresponding to the participting media radiation equation(s) 137 : std::vector<LinearSystem *> _pm_radiation_systems; 138 : 139 : /// Pointer(s) to the system(s) corresponding to the active scalar equation(s) 140 : std::vector<LinearSystem *> _active_scalar_systems; 141 : 142 : /// Pointer(s) to the system(s) corresponding to the turbulence equation(s) 143 : std::vector<LinearSystem *> _turbulence_systems; 144 : 145 : /// Pointer to the segregated RhieChow interpolation object 146 : RhieChowMassFlux * _rc_uo; 147 : 148 : /// Shortcut to every linear system that we solve for here 149 : std::vector<LinearSystem *> _systems_to_solve; 150 : 151 : /// Flags controlling which systems are actively solved (can be used with restart to freeze flow) 152 : const bool _should_solve_momentum; 153 : const bool _should_solve_pressure; 154 : const bool _should_solve_energy; 155 : const bool _should_solve_solid_energy; 156 : const bool _should_solve_turbulence; 157 : const bool _should_solve_passive_scalars; 158 : const bool _should_solve_active_scalars; 159 : const bool _should_solve_pm_radiation; 160 : 161 : // ************************ Active Scalar Variables ************************ // 162 : 163 : /// The names of the active scalar systems 164 : const std::vector<SolverSystemName> & _active_scalar_system_names; 165 : 166 : /// Boolean for easy check if a active scalar systems shall be solved or not 167 : const bool _has_active_scalar_systems; 168 : 169 : // The number(s) of the system(s) corresponding to the active scalar equation(s) 170 : std::vector<unsigned int> _active_scalar_system_numbers; 171 : 172 : /// The user-defined relaxation parameter(s) for the active scalar equation(s) 173 : const std::vector<Real> _active_scalar_equation_relaxation; 174 : 175 : /// Options which hold the petsc settings for the active scalar equation(s) 176 : Moose::PetscSupport::PetscOptions _active_scalar_petsc_options; 177 : 178 : /// Options for the linear solver of the active scalar equation(s) 179 : SIMPLESolverConfiguration _active_scalar_linear_control; 180 : 181 : /// Absolute linear tolerance for the active scalar equation(s). We need to store this, because 182 : /// it needs to be scaled with a representative flux. 183 : const Real _active_scalar_l_abs_tol; 184 : 185 : /// The user-defined absolute tolerance for determining the convergence in active scalars 186 : const std::vector<Real> _active_scalar_absolute_tolerance; 187 : 188 : /// ********************** Conjugate heat transfer variables ************** // 189 : 190 : // Handler object for CHT problems 191 : NS::FV::CHTHandler _cht; 192 : };