TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Schema_Cahn_Hilliard_Navier_Stokes.cpp
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
17#include <Schema_Cahn_Hilliard_Navier_Stokes.h>
18
19// XD schema_cahn_hilliard_navier_stokes schema_cahn_hilliard schema_cahn_hilliard_navier_stokes INHERITS_BRACE
20// XD_CONT Time-integration scheme coupling the semi-implicit Cahn-Hilliard step with a dedicated convection sub-scheme
21// XD_CONT for the Navier-Stokes equation.
22Implemente_instanciable( Schema_Cahn_Hilliard_Navier_Stokes, "Schema_Cahn_Hilliard_Navier_Stokes", Schema_Cahn_Hilliard ) ;
23
25{
27 return os;
28}
29
31{
32 param.ajouter_non_std("Schema_convection", this); // XD_ADD_P schema_temps_base
33 // XD_CONT Time sub-scheme used to advance the Navier-Stokes convection (e.g. Runge_Kutta_ordre_3,
34 // XD_CONT Schema_Euler_implicite).
36}
37
39{
40 if (mot == "Schema_convection")
41 {
42 Nom type_sch;
43 is >> type_sch;
44 schema_convection_.typer(type_sch);
45 is >> schema_convection_.valeur();
46 }
47 else
49 return 1;
50}
51
53{
54 Schema_Temps_base& sch = schema_convection_.valeur();
55 sch.set_temps_init() = temps_init();
56 sch.set_temps_max() = temps_max();
58 sch.set_nb_pas_dt() = nb_pas_dt();
60 sch.set_dt_min() = pas_temps_min();
61 sch.set_dt_max() = pas_temps_max();
62 sch.set_dt_sauv() = temps_sauv();
63 sch.set_dt_impr() = temps_impr();
67 //sch.set_diffusion_implicite() = diffusion_implicite();
68 //sch.set_seuil_diffusion_implicite() = seuil_diffusion_implicite();
69 //sch.set_niter_max_diffusion_implicite() = niter_max_diffusion_implicite();
70 sch.set_dt() = pas_de_temps();
74 sch.set_lu() = lu();
75 sch.schema_impr() = 0; // in such a way that schema_ does not write in dt_ev output file
77}
78
80{
81 schema_convection_->associer_pb(un_probleme);
83}
84
86{
88 return is;
89}
90
92{
93 schema_convection_->initialize();
95}
96
98{
99 schema_convection_->initTimeStep(dt);
101
102}
103
105{
106 schema_convection_->changer_temps_courant(t);
108}
109
111{
112 Probleme_base& prob = pb_base();
113 double temps = temps_courant_ + dt_;
114 int nb_eqn = prob.nombre_d_equations();
115 for (int i = nb_eqn - 1; i > -1; i--) // Cahn-Hilliard equation first, Navier-Stokes equation afterwards
116 {
117 Equation_base& eqn_i = prob.equation(i);
118 if (eqn_i.equation_non_resolue())
119 {
120 Cout << "====================================================" << finl;
121 Cout << eqn_i.que_suis_je() << " equation is not solved." << finl;
122 Cout << "====================================================" << finl;
123 if (eqn_i.schema_temps().nb_pas_dt() == 0)
124 {
125 DoubleTab inconnue_valeurs(eqn_i.inconnue().valeurs());
126 eqn_i.derivee_en_temps_inco(inconnue_valeurs);
127 }
128 }
129 else
130 {
131 eqn_i.domaine_Cl_dis().mettre_a_jour(temps);
133 }
134 }
135 converged = true;
136 return true;
137}
138
140{
141 if (eqn.que_suis_je() == "Cahn_Hilliard_Convection")
142 {
144 }
145 else
146 {
147 eqn.milieu().mettre_a_jour(eqn.inconnue().temps());
148 schema_convection_->set_dt() = pas_de_temps();
149 schema_convection_->faire_un_pas_de_temps_eqn_base(eqn);
150 set_stationnaire_atteint() = schema_convection_->isStationary();
151 return 1;
152 }
153}
154
156{
157 bool ok = schema_convection_->corriger_dt_calcule(dt);
159 return ok;
160}
161
163{
164 schema_convection_->mettre_a_jour();
166}
167
169{
170 return (schema_convection_->stop() | Schema_Cahn_Hilliard::stop());
171}
172
174{
175 schema_convection_->imprimer(os);
177}
DoubleTab & valeurs() override
Returns the array of field values at the current time.
double temps() const
Returns the time of the field.
virtual void mettre_a_jour(double temps)
Performs a time update of all boundary conditions.
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....
virtual int equation_non_resolue() const
virtual const Milieu_base & milieu() const =0
virtual const Champ_Inc_base & inconnue() const =0
virtual DoubleTab & derivee_en_temps_inco(DoubleTab &)
Returns the time derivative of the unknown I of the equation: dI/dt = M-1*(sum(operators(I) + sources...
virtual Domaine_Cl_dis_base & domaine_Cl_dis()
Returns the discretized boundary condition domain associated with the equation.
Schema_Temps_base & schema_temps()
Returns the time scheme associated with the equation.
virtual void mettre_a_jour(double temps)
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter_non_std(const char *keyword, const Objet_U *value, Param::Nature nat=Param::OPTIONAL)
Register a keyword handled by Objet_U::lire_motcle_non_standard.
Definition Param.cpp:489
class Probleme_base It is a Probleme_U that is not a coupling.
virtual int nombre_d_equations() const =0
virtual const Equation_base & equation(int) const =0
void associer_pb(const Probleme_base &) override
int faire_un_pas_de_temps_eqn_base(Equation_base &) override
Effectue un pas de temps sur l'equation de Cahn-Hilliard, d'où le test sur le sub_type.
bool iterateTimeStep(bool &converged) override
Calculate the U(n+1) unknown for each equation (if solved) of the problem with the selected time sche...
int mettre_a_jour() override
Updates the current time (t+=dt) and the number of time steps performed (nb_pas_dt_++).
int stop() const override
Returns 1 if it is necessary to stop the computation for various reasons:
void changer_temps_courant(const double t) override
Changes the current time.
bool corriger_dt_calcule(double &dt) const override
Corrects the computed time step passed as parameter and verifies it is not "too" small (< dt_min_).
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
void imprimer(Sortie &os) const override
Prints the time step to an output stream if appropriate.
class Schema_Cahn_Hilliard. Il herite de schema Euler semi implicite et ne s'applique qu'à Cahn-Hilli...
int faire_un_pas_de_temps_eqn_base(Equation_base &) override
Effectue un pas de temps sur l'equation de Cahn-Hilliard, d'où le test sur le sub_type.
class Schema_Temps_base
bool & set_indice_nb_pas_dt_max_atteint()
virtual bool isStationary() const
Returns 1 if during the last time step, the problem has not evolved.
double temps_courant() const
Returns the current time.
virtual bool corriger_dt_calcule(double &dt) const
Corrects the computed time step passed as parameter and verifies it is not "too" small (< dt_min_).
double temps_sauv() const
Returns a reference to the checkpoint time interval.
double temps_impr() const
Returns a reference to the output time interval.
virtual void set_param(Param &titi) const override
double dt_
Computation time step.
double pas_temps_max() const
Returns the maximum time step.
virtual void associer_pb(const Probleme_base &)
double temps_max() const
Returns a reference to the maximum time.
virtual void changer_temps_courant(const double)
Changes the current time.
int indice_tps_final_atteint() const
virtual int stop() const
Returns 1 if it is necessary to stop the computation for various reasons:
Probleme_base & pb_base()
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
double pas_temps_min() const
Returns the minimum time step.
double pas_de_temps() const
Returns the current time step (delta_t).
virtual void imprimer(Sortie &os) const
Prints the time step to an output stream if appropriate.
virtual void initialize()
virtual bool initTimeStep(double dt)
double seuil_statio() const
Returns a reference to the stationarity threshold.
int nb_pas_dt() const
Returns the number of time steps performed.
double mode_dt_start() const
double temps_init() const
Returns the initial time.
virtual int mettre_a_jour()
Updates the current time (t+=dt) and the number of time steps performed (nb_pas_dt_++).
int indice_nb_pas_dt_max_atteint() const
bool & set_indice_tps_final_atteint()
int nb_pas_dt_max() const
Returns a reference to the maximum number of time steps.
double facteur_securite_pas() const
Returns the safety factor or multiplier of delta_t.
virtual void completer()=0
Base class for output streams.
Definition Sortie.h:52