https://mooseframework.inl.gov
InterWrapper1PhaseProblem.h
Go to the documentation of this file.
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 #include "ExternalProblem.h"
12 #include "SubChannelApp.h"
13 #include "InterWrapperMesh.h"
14 #include "SolutionHandle.h"
16 #include <petscdm.h>
17 #include <petscdmda.h>
18 #include <petscksp.h>
19 #include <petscsys.h>
20 #include <petscvec.h>
21 #include <petscsnes.h>
22 
24 
29 {
30 public:
33 
34  virtual void externalSolve() override;
35  virtual void syncSolutions(Direction direction) override;
36  virtual bool solverSystemConverged(const unsigned int) override;
37  virtual void initialSetup() override;
38 
39 protected:
42  {
43  Mat A;
44  Vec x;
45  };
46 
48  virtual Real computeFrictionFactor(Real Re) = 0;
51  virtual void computeWijFromSolve(int iblock);
53  virtual void computeSumWij(int iblock);
55  virtual void computeMdot(int iblock);
57  virtual void computeWijPrime(int iblock);
59  virtual void computeDP(int iblock);
61  virtual void computeP(int iblock);
63  virtual void computeh(int iblock);
65  virtual void computeT(int iblock);
67  virtual void computeRho(int iblock);
69  virtual void computeMu(int iblock);
71  virtual void computeWij(int iblock);
73  virtual Real computeAddedHeat(unsigned int i_ch, unsigned int iz);
78  virtual PetscErrorCode petscSnesSolver(int iblock,
79  const libMesh::DenseVector<Real> & solution,
81  friend PetscErrorCode formFunctionIW(SNES snes, Vec x, Vec f, void * info);
82 
84  virtual PetscErrorCode implicitPetscSolve(int iblock);
86  virtual void initializeSolution();
87 
89  virtual PetscScalar computeInterpolationCoefficients(PetscScalar Peclet = 0.0);
90  virtual PetscScalar
91  computeInterpolatedValue(PetscScalar topValue, PetscScalar botValue, PetscScalar Peclet = 0.0);
92  PetscErrorCode cleanUp();
95  unsigned int _n_blocks;
100  const Real _g_grav;
101  const Real & _kij;
102  const unsigned int _n_cells;
103  const unsigned int _n_gaps;
104  const unsigned int _n_assemblies;
105  const unsigned int _n_channels;
106  const unsigned int _block_size;
108  std::vector<Real> _z_grid;
113  const bool _compute_density;
115  const bool _compute_viscosity;
117  const bool _compute_power;
119  const bool _pin_mesh_exist;
123  const Real & _dt;
125  const Real & _P_out;
127  const Real & _beta;
129  const Real & _CT;
131  const Real & _P_tol;
133  const Real & _T_tol;
135  const int & _T_maxit;
137  const PetscReal & _rtol;
139  const PetscReal & _atol;
141  const PetscReal & _dtol;
143  const PetscInt & _maxit;
147  const bool _implicit_bool;
151  const bool _segregated_bool;
154 
157  std::unique_ptr<SolutionHandle> _mdot_soln;
158  std::unique_ptr<SolutionHandle> _SumWij_soln;
159  std::unique_ptr<SolutionHandle> _P_soln;
160  std::unique_ptr<SolutionHandle> _DP_soln;
161  std::unique_ptr<SolutionHandle> _h_soln;
162  std::unique_ptr<SolutionHandle> _T_soln;
163  std::unique_ptr<SolutionHandle> _Tpin_soln;
164  std::unique_ptr<SolutionHandle> _rho_soln;
165  std::unique_ptr<SolutionHandle> _mu_soln;
166  std::unique_ptr<SolutionHandle> _S_flow_soln;
167  std::unique_ptr<SolutionHandle> _w_perim_soln;
168  std::unique_ptr<SolutionHandle> _q_prime_soln;
169 
171  virtual PetscErrorCode createPetscVector(Vec & v, PetscInt n);
172  virtual PetscErrorCode createPetscMatrix(Mat & M, PetscInt n, PetscInt m);
173  template <class T>
174  PetscErrorCode populateVectorFromDense(Vec & x,
175  const T & solution,
176  const unsigned int first_axial_level,
177  const unsigned int last_axial_level,
178  const unsigned int cross_dimension);
179  template <class T>
180  PetscErrorCode populateDenseFromVector(const Vec & x,
181  T & solution,
182  const unsigned int first_axial_level,
183  const unsigned int last_axial_level,
184  const unsigned int cross_dimension);
185  template <class T>
186  PetscErrorCode populateVectorFromHandle(Vec & x,
187  const T & solution,
188  const unsigned int first_axial_level,
189  const unsigned int last_axial_level,
190  const unsigned int cross_dimension);
191  template <class T>
192  PetscErrorCode populateSolutionChan(const Vec & x,
193  T & solution,
194  const unsigned int first_axial_level,
195  const unsigned int last_axial_level,
196  const unsigned int cross_dimension);
197 
198  template <class T>
199  PetscErrorCode populateSolutionGap(const Vec & x,
200  T & solution,
201  const unsigned int first_axial_level,
202  const unsigned int last_axial_level,
203  const unsigned int cross_dimension);
204 
206 
210  Vec _Wij_vec;
211  Vec _prod;
212  Vec _prodp;
218 
244 
262 
279  PetscInt _global_counter = 0;
280 
282  PetscScalar _added_K = 0.0;
283  PetscScalar _added_K_old = 1000.0;
284  PetscScalar _max_sumWij;
285  PetscScalar _max_sumWij_new;
286  PetscScalar _correction_factor = 1.0;
287 
288 public:
289  static InputParameters validParams();
290 };
291 
292 template <class T>
293 PetscErrorCode
295  T & loc_solution,
296  const unsigned int first_axial_level,
297  const unsigned int last_axial_level,
298  const unsigned int cross_dimension)
299 {
300  PetscErrorCode ierr;
301  PetscScalar * xx;
302 
304  ierr = VecGetArray(x, &xx);
305  CHKERRQ(ierr);
306  for (unsigned int iz = first_axial_level; iz < last_axial_level + 1; iz++)
307  {
308  unsigned int iz_ind = iz - first_axial_level;
309  for (unsigned int i_l = 0; i_l < cross_dimension; i_l++)
310  {
311  loc_solution(i_l, iz) = xx[iz_ind * cross_dimension + i_l];
312  }
313  }
314  ierr = VecRestoreArray(x, &xx);
315  CHKERRQ(ierr);
316  PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
317 }
virtual PetscScalar computeInterpolatedValue(PetscScalar topValue, PetscScalar botValue, PetscScalar Peclet=0.0)
Mat _amc_turbulent_cross_flows_mat
Mass conservation - density time derivative No implicit matrix.
const bool _compute_density
Flag that activates or deactivates the calculation of density.
Mat _cmc_friction_force_mat
Cross momentum conservation - friction force.
std::unique_ptr< SolutionHandle > _w_perim_soln
const bool _segregated_bool
Segregated solve.
virtual void externalSolve() override
Real _TR
Flag that activates or deactivates the transient parts of the equations we solve by multiplication...
std::unique_ptr< SolutionHandle > _S_flow_soln
std::unique_ptr< SolutionHandle > _P_soln
Mat _amc_advective_derivative_mat
Axial momentum conservation - advective (Eulerian) derivative.
virtual void computeSumWij(int iblock)
Computes net diversion crossflow per channel for block iblock.
const int & _T_maxit
Maximum iterations for the inner temperature loop.
const Real & _P_tol
Convergence tolerance for the pressure loop in external solve.
virtual void computeh(int iblock)
Computes Enthalpy per channel for block iblock.
virtual void computeDP(int iblock)
Computes Pressure Drop per channel for block iblock.
PetscErrorCode populateVectorFromHandle(Vec &x, const T &solution, const unsigned int first_axial_level, const unsigned int last_axial_level, const unsigned int cross_dimension)
virtual void syncSolutions(Direction direction) override
std::unique_ptr< SolutionHandle > _Tpin_soln
MPI_Info info
Base class for inter-wrapper meshes.
virtual void computeRho(int iblock)
Computes Density per channel for block iblock.
PetscScalar _added_K
Added resistances for monolithic convergence.
virtual void computeWijPrime(int iblock)
Computes turbulent crossflow per gap for block iblock.
virtual void computeT(int iblock)
Computes Temperature per channel for block iblock.
const bool _implicit_bool
Flag to define the usage of a implicit or explicit solution.
std::unique_ptr< SolutionHandle > _SumWij_soln
Mat _cmc_pressure_force_mat
Cross momentum conservation - pressure force.
const Real & _P_out
Outlet Pressure.
Mat _mc_sumWij_mat
Mass conservation Mass conservation - sum of cross fluxes.
static InputParameters validParams()
const PetscReal & _dtol
The divergence tolerance for the ksp linear solver.
PetscFunctionBegin
Base class for the 1-phase steady-state/transient interwrapper solver.
virtual PetscErrorCode createPetscVector(Vec &v, PetscInt n)
Petsc Functions.
virtual PetscErrorCode implicitPetscSolve(int iblock)
Computes implicit solve using PetSc.
std::unique_ptr< SolutionHandle > _rho_soln
const PetscReal & _rtol
The relative convergence tolerance, (relative decrease) for the ksp linear solver.
Mat _mc_axial_convection_mat
Mass conservation - axial convection.
std::unique_ptr< SolutionHandle > _mdot_soln
virtual void computeMdot(int iblock)
Computes mass flow per channel for block iblock.
const SinglePhaseFluidProperties * _fp
Solutions handles and link to TH tables properties.
PetscErrorCode populateDenseFromVector(const Vec &x, T &solution, const unsigned int first_axial_level, const unsigned int last_axial_level, const unsigned int cross_dimension)
const Real & _beta
Thermal diffusion coefficient used in turbulent crossflow.
Mat _hc_time_derivative_mat
Enthalpy Enthalpy conservation - time derivative.
const PetscInt & _maxit
The maximum number of iterations to use for the ksp linear solver.
std::vector< Real > _z_grid
axial location of nodes
const MooseEnum _interpolation_scheme
The interpolation method used in constructing the systems.
Standard return structure for reusing in implicit/explicit formulations.
const bool _staggered_pressure_bool
Flag to define the usage of staggered or collocated pressure.
PetscErrorCode populateSolutionGap(const Vec &x, T &solution, const unsigned int first_axial_level, const unsigned int last_axial_level, const unsigned int cross_dimension)
Mat _amc_cross_derivative_mat
Axial momentum conservation - cross flux derivative.
virtual PetscErrorCode petscSnesSolver(int iblock, const libMesh::DenseVector< Real > &solution, libMesh::DenseVector< Real > &root)
Computes solution of nonlinear equation using snes.
std::unique_ptr< SolutionHandle > _T_soln
const std::vector< double > x
Real f(Real x)
Test function for Brents method.
Mat _hc_advective_derivative_mat
Enthalpy conservation - advective (Eulerian) derivative;.
virtual void computeP(int iblock)
Computes Pressure per channel for block iblock.
virtual void initialSetup() override
virtual PetscErrorCode createPetscMatrix(Mat &M, PetscInt n, PetscInt m)
Real root(std::function< Real(Real)> const &f, Real x1, Real x2, Real tol=1.0e-12)
Finds the root of a function using Brent&#39;s method.
Definition: BrentsMethod.C:66
Mat _amc_time_derivative_mat
Axial momentum conservation - time derivative.
const bool _monolithic_thermal_bool
Thermal monolithic bool.
Common class for single phase fluid properties.
auto Peclet(const T1 &volume_fraction, const T2 &cp, const T3 &rho, const T4 &vel, const T5 &D_h, const T6 &k)
Compute Peclet number.
Definition: Numerics.h:153
virtual void computeWij(int iblock)
Computes cross fluxes for block iblock.
unsigned int _n_blocks
number of axial blocks
const InterWrapperMesh & _subchannel_mesh
virtual PetscScalar computeInterpolationCoefficients(PetscScalar Peclet=0.0)
Functions that computes the interpolation scheme given the Peclet number.
std::unique_ptr< SolutionHandle > _mu_soln
Mat _cmc_advective_derivative_mat
Cross momentum conservation - advective (Eulerian) derivative.
Vec _hc_added_heat_rhs
Enthalpy conservation - source and sink.
std::unique_ptr< SolutionHandle > _DP_soln
const bool _compute_viscosity
Flag that activates or deactivates the calculation of viscosity.
PetscErrorCode populateSolutionChan(const Vec &x, T &solution, const unsigned int first_axial_level, const unsigned int last_axial_level, const unsigned int cross_dimension)
virtual bool solverSystemConverged(const unsigned int) override
virtual void computeWijFromSolve(int iblock)
Computes diversion crossflow per gap for block with index iblock Block is a partition of the whole do...
const Real & _T_tol
Convergence tolerance for the temperature loop in external solve.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
std::unique_ptr< SolutionHandle > _q_prime_soln
virtual void initializeSolution()
Function to initialize the solution fields.
Mat _cmc_sys_Wij_mat
Lateral momentum system matrix.
Mat _amc_pressure_force_mat
Axial momentum conservation - pressure force.
const bool _pin_mesh_exist
Flag that informs if there is a pin mesh or not.
virtual Real computeFrictionFactor(Real Re)=0
Returns friction factor.
PetscInt _global_counter
No implicit matrix.
virtual void computeMu(int iblock)
Computes Viscosity per channel for block iblock.
PetscErrorCode populateVectorFromDense(Vec &x, const T &solution, const unsigned int first_axial_level, const unsigned int last_axial_level, const unsigned int cross_dimension)
std::unique_ptr< SolutionHandle > _h_soln
virtual Real computeAddedHeat(unsigned int i_ch, unsigned int iz)
Computes added heat for channel i_ch and cell iz.
libMesh::DenseMatrix< Real > _Wij_old
const bool _compute_power
Flag that informs if we need to solve the Enthalpy/Temperature equations or not.
libMesh::DenseMatrix< Real > & _Wij
bool _converged
Variable that informs whether we exited external solve with a converged solution or not...
libMesh::DenseMatrix< Real > _WijPrime
PetscFunctionReturn(LIBMESH_PETSC_SUCCESS)
Mat _hc_cross_derivative_mat
Enthalpy conservation - cross flux derivative.
libMesh::DenseMatrix< Real > _Wij_residual_matrix
InterWrapper1PhaseProblem(const InputParameters &params)
virtual libMesh::DenseVector< Real > residualFunction(int iblock, libMesh::DenseVector< Real > solution)
Computes Residual per gap for block iblock.
friend PetscErrorCode formFunctionIW(SNES snes, Vec x, Vec f, void *info)
creates the residual function to be used in the PETCs snes context
Vec _amc_gravity_rhs
Axial momentum conservation - buoyancy force No implicit matrix.
Mat _cmc_time_derivative_mat
Cross momentum Cross momentum conservation - time derivative.
const Real & _CT
Turbulent modeling parameter used in axial momentum equation.
Mat _amc_sys_mdot_mat
Axial momentum system matrix.
Mat _amc_friction_force_mat
Axial momentum conservation - friction force.
const PetscReal & _atol
The absolute convergence tolerance for the ksp linear solver.