TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
SETS.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef SETS_included
17#define SETS_included
18
19#include <Interface_blocs.h>
20#include <Solv_Petsc.h>
21#include <Simpler.h>
22#include <utility>
23#include <vector>
24#include <set>
25
26/*! @brief SETS scheme (semi-implicit + stabilisation steps, TRACE-style).
27 *
28 * SETS ("Stability-Enhancing Two-Step")
29 *
30 * Ref : J. H. MAHAFFY, "A stability-enhancing two-step method for fluid flow calculations," Journal of Computational Physics, 46, 3, 329 (1982).
31 *
32 * @sa Simpler Piso
33 */
34class SETS: public Simpler
35{
36 Declare_instanciable_sans_constructeur(SETS);
37public:
38 SETS();
39 Entree& lire(const Motcle&, Entree&) override; /* keyword "criteres_convergence" */
40 int nb_valeurs_temporelles_pression() const override /* number of temporal values for the pressure field */
41 {
42 return 3; /* same as other variables */
43 }
44
45 bool iterer_eqn(Equation_base& equation, const DoubleTab& inconnue, DoubleTab& result, double dt, int numero_iteration, int& ok) override;
46 void iterer_NS(Equation_base&, DoubleTab& current, DoubleTab& pression, double, Matrice_Morse&, double, DoubleTrav&, int nb_iter, int& converge, int& ok) override;
47
48 /* block elimination of a linear system */
49 // input : order -> groups of (variables, block index) to be successively eliminated: e.g. { { {"vitesse", 0 } }, { {"alpha", 0 }, {"temperature", 0 } } }
50 // inco_p -> name of the principal unknown (e.g.: "pression")
51 // mats, sec : matrices / right-hand sides of the linear system mats.d{incos} = {secs}
52 //
53 //
54 // output : A_p / b_p s.t. d{inco} = A_p.d{inco_p} + b_p
55 // return value -> 1 if elimination succeeded, 0 if singularity encountered
56 // constraints: - unknowns in the same block must share a common MD_Vector
57 // - for each block { i_1, i_2 }, the matrix { mats[i_j][i_k] } must be block-diagonal w.r.t. this MD_Vector
58 // - outside this diagonal, unknowns in a block may only depend on preceding blocks and on inco_p
59 static int eliminer(const std::vector<std::set<std::pair<std::string, int>>> ordre, const std::string inco_p, const std::map<std::string, matrices_t>& mats, const ptabs_t& sec,
60 std::map<std::string, Matrice_Morse>& A_p, tabs_t& b_p);
61
62 /* assembly of a system in inco_p from the expressions d.{inco} : A_p[inco].d{inco_p} + b_p[inco] */
63 // input : - inco_p -> the principal unknown
64 // - A_p, b_p -> expressions for the other unknowns computed by eliminer()
65 // - mats, sec -> linear system containing an equation on inco_p (right-hand side in sec[inco_p], Jacobian in mats[inco_p])
66 //
67 // output : system matrice.d{inco_p} = secmem
68 //
69 // constraints : all other unknowns must be expressed in A_p / b_p
70 static void assembler(const std::string inco_p, const std::map<std::string, Matrice_Morse>& A_p, const tabs_t& b_p, const std::map<std::string, matrices_t>& mats, const ptabs_t& sec,
71 Matrice_Morse& matrice, DoubleTab& secmem, int p_degen);
72
73 double get_default_growth_factor() const override /* time step growth factor */
74 {
75 return 1.2; /* in case of a failed time step, we recover slowly */
76 }
77
78 int iteration_ = 0; // current iteration number (for evanescence operators)
79 int p_degen_ = -1; // 1 if pressure is degenerate (incompressible medium + no imposed pressure BCs)
80 int sets_; // 1 if the velocity prediction step is performed
81
82 double unknown_positivation(const DoubleTab& uk, DoubleTab& incr); // brings to 0 unknowns that should stay positive
83
84#ifdef PETSCKSP_H
85 /* context for the convergence test */
86 struct cv_test_t
87 {
88 void *defctx; // context of the standard convergence test
89 SETS *obj; // the object
90 double eps_alpha; // convergence criterion in alpha
91 Vec t, v; // Petsc vectors
92 };
93 DoubleVect norm, residu; // each line equals norm * sum alpha, storage for the residual
94 ArrOfTID ix; // indices to retrieve the residual
95 cv_test_t *cv_ctx = nullptr;
96 void init_cv_ctx(const DoubleTab& secmem, const DoubleVect& norm);
97#if PETSC_VERSION_GE(3,24,0)
98 static PetscErrorCode destroy_cvctx(void **mctx);
99#else
100 static PetscErrorCode destroy_cvctx(void *mctx);
101#endif
102 static PetscErrorCode convergence_test(KSP ksp, PetscInt it, PetscReal rnorm, KSPConvergedReason *reason,void *mctx);
103#endif
104
106 {
108 }
109
110protected:
111
112 int iter_min_ = 1, iter_max_ = 10; // min/max number of iterations for the nonlinear step
113 int first_call_ = 1; // at the very first call, P can be very poor -> velocity is not predicted in SETS
114 int pressure_reduction_ = 1; // do we perform pressure reduction?
115
116 /* convergence criteria per unknown (in Linf norm), modifiable via the "criteres_convergence" keyword */
117 std::map<std::string, double> crit_conv_;
118
119 /* matrices of the semi-implicit solve */
120 std::map<std::string, matrices_t> mats_; // matrices: mats[equation unknown name][other unknown name] = matrix
121 Matrice_Bloc mat_semi_impl_; // storage for the mats matrices
122 MD_Vector mdv_semi_impl_; // associated MD_Vector
123 std::map<std::string, Matrice_Morse> mat_pred_; // prediction matrices
124
125 /* pressure elimination: dv = A_p[variable name]. dp + b_p[variable name] */
126 std::map<std::string, Matrice_Morse> A_p_;
127
128 /* pressure matrix */
130
131 /* Newton out file */
132 bool header_written_ = false;
133 std::vector<double> incr_var_convergence_;
134};
135
136/*! @brief ICE scheme (semi-implicit ICE, CATHARE 3D style).
137 *
138 * @sa SETS
139 */
140class ICE: public SETS
141{
142 Declare_instanciable(ICE);
143public:
144 bool est_compatible_avec_th_mono() const override /* is this solver compatible with a monolithic thermal solve? */
145 {
146 return 0; /* no: ICE is explicit in the thermal part */
147 }
148 double get_default_facsec_max() const override /* recommended facsec_max */
149 {
150 return 1; /* SETS is semi-implicit */
151 }
152};
153
154#endif /* SETS_included */
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
ICE scheme (semi-implicit ICE, CATHARE 3D style).
Definition SETS.h:141
double get_default_facsec_max() const override
Definition SETS.h:148
bool est_compatible_avec_th_mono() const override
Definition SETS.h:144
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
A character string (Nom) in uppercase.
Definition Motcle.h:26
int sets_
Definition SETS.h:80
Entree & lire(const Motcle &, Entree &) override
Definition SETS.cpp:108
Matrice_Bloc mat_semi_impl_
Definition SETS.h:121
SETS()
Definition SETS.cpp:81
int pressure_reduction_
Definition SETS.h:114
double facsec_diffusion_for_sets() const
Definition SETS.h:105
int p_degen_
Definition SETS.h:79
std::map< std::string, Matrice_Morse > A_p_
Definition SETS.h:126
MD_Vector mdv_semi_impl_
Definition SETS.h:122
int iter_min_
Definition SETS.h:112
static int eliminer(const std::vector< std::set< std::pair< std::string, int > > > ordre, const std::string inco_p, const std::map< std::string, matrices_t > &mats, const ptabs_t &sec, std::map< std::string, Matrice_Morse > &A_p, tabs_t &b_p)
Definition SETS.cpp:695
void iterer_NS(Equation_base &, DoubleTab &current, DoubleTab &pression, double, Matrice_Morse &, double, DoubleTrav &, int nb_iter, int &converge, int &ok) override
Definition SETS.cpp:366
double unknown_positivation(const DoubleTab &uk, DoubleTab &incr)
Definition SETS.cpp:189
std::map< std::string, double > crit_conv_
Definition SETS.h:117
double get_default_growth_factor() const override
Definition SETS.h:73
static void assembler(const std::string inco_p, const std::map< std::string, Matrice_Morse > &A_p, const tabs_t &b_p, const std::map< std::string, matrices_t > &mats, const ptabs_t &sec, Matrice_Morse &matrice, DoubleTab &secmem, int p_degen)
Definition SETS.cpp:1001
int iteration_
Definition SETS.h:78
bool header_written_
Definition SETS.h:132
std::map< std::string, matrices_t > mats_
Definition SETS.h:120
int first_call_
Definition SETS.h:113
std::vector< double > incr_var_convergence_
Definition SETS.h:133
std::map< std::string, Matrice_Morse > mat_pred_
Definition SETS.h:123
int nb_valeurs_temporelles_pression() const override
Definition SETS.h:40
Matrice_Morse matrice_pression_
Definition SETS.h:129
bool iterer_eqn(Equation_base &equation, const DoubleTab &inconnue, DoubleTab &result, double dt, int numero_iteration, int &ok) override
Definition SETS.cpp:286
int iter_max_
Definition SETS.h:112
double facsec_diffusion_for_sets_