TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Schema_Cahn_Hilliard.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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#include <Schema_Cahn_Hilliard.h>
17#include <Probleme_base.h>
18
19Implemente_instanciable(Schema_Cahn_Hilliard,"Schema_Cahn_Hilliard|Scheme_Cahn_Hilliard",Schema_Euler_Semi_Implicite);
20// XD Schema_Cahn_Hilliard Schema_euler_semi_implicite Schema_Cahn_Hilliard INHERITS_BRACE Time-integration scheme for a
21// XD_CONT Cahn-Hilliard problem (semi-implicit Euler specialised for phase-field).
22
24{
26}
27
29{
31}
32
34{
35 Probleme_base& prob=pb_base();
36 Cahn_Hilliard& eqn = ref_cast(Cahn_Hilliard, prob.equation(0));
37
38 // Normalement, que l'équation de Cahn-Hilliard
40
41 converged = true;
42 return converged;
43}
44
45/*! @brief Effectue un pas de temps sur l'equation de Cahn-Hilliard, d'où le test sur le sub_type.
46 *
47 * Le pas de temps effectue n'est pas standard.
48 * Il se fait en plusieurs étapes avec le temps intermédiaire n+theta.
49 *
50 * @param (Equation_base& eqn) l'equation que l'on veut faire avancer d'un pas de temps
51 * @return (int) renvoie toujours 1
52 */
54{
55 // Ce schéma en temps ne s'applique que sur l'équation de Cahn-Hilliard
56 Cahn_Hilliard& eq_ch = ref_cast(Cahn_Hilliard, eqn);
57 int compteur = 0, ok = 1;
58 DoubleTab& passe = eq_ch.inconnue().passe();
59 DoubleTab& present = eq_ch.inconnue().valeurs();
60 DoubleTab& futur = eq_ch.inconnue().futur();
61
62 // C'est là que sont mises à jour les matrices pour le calcul en semi-implicite
63 // Initialisation appelée seulement une fois !
64 if (!eq_ch.matrices_initialisees())
66
67 // mutilde doit être mis à jour aussi ? Oui --> pour les CL
68 eq_ch.compute_mutilde();
69
70 eq_ch.update_terme_mobilite(present);
71
72 // Cas semi-implicite
73 if (!is_explicit())
74 {
75 // On veut les CL sur c^(n+1)
77 // On veut les CL sur mutilde^(n+1)
79
82
83 compteur=0;
84 Cout << finl;
85 Cout<<"==========================================================================================" << finl;
86 Cout<<"Schema_Cahn_Hilliard: Implicit solver on the "<<eq_ch.que_suis_je() << " equation of the problem "<< eq_ch.probleme().le_nom()<< " :" <<finl;
87 Cout<<"==========================================================================================" << finl;
88
89 eq_ch.inconnue().avancer(); // ===> present = futur, passe => present
90
91 // On résout pour un demi-pas de temps
92 le_solveur->iterer_eqn(eq_ch, passe, present, theta_*dt_, compteur, ok);
93
94 eq_ch.inconnue().reculer();
95
96 if (!ok)
97 {
98 Cerr << "[faire_un_pas_de_temps_eqn_base] Total fail: returns 0." << finl;
99 return 0; //si echec total
100 }
101
102 // Mise à jour : Valeurs au temps n+1
103 for (int elem = 0; elem < eq_ch.domaine_dis().nb_elem_tot(); elem++)
104 for (int p = 0; p < eq_ch.fermeture().nb_parametres_d_ordre(); p++)
105 {
106 // c(n+1) = [ c(n+theta) - (1-theta)*c(n) ] / theta
107 present(elem,p) = present(elem,p) - (1 - theta_) * passe(elem,p);
108 present(elem,p) /= theta_;
109 }
110
111 // Mise à jour de mutilde en fonction de c^(n+1)
112 eq_ch.compute_mutilde();
113
114 futur=present;
115
116 present -= passe;
117 present/=dt_;
118 update_critere_statio(present, eq_ch);
119 present = futur;
120 // On veut les CL sur c^(n+1)
122 // On veut les CL sur mutilde^(n+1)
124 }
125 else
126 {
127 Cout<<"==================================================================================" << finl;
128 Cout<<"Schema_Cahn_Hilliard: Explicit case on the "<<eq_ch.que_suis_je() << " equation of the problem "<< eq_ch.probleme().le_nom()<< " :" <<finl;
129 Cout<<"==================================================================================" << finl;
130
131 DoubleTrav dudt(futur); // just for initializing the array structure ... Trav is highly recommanded!! Otherwise we allocate at each time step!!
132
133 // Mise à jour des CL sur c
135 // Mise à jour des CL sur mutilde
137
138 eq_ch.inconnue().avancer();
139 eq_ch.derivee_en_temps_inco(dudt);
140 eq_ch.inconnue().reculer();
141
142 // Un+1=Un+dt_*dU/dt
143 futur = dudt;
144 futur *= dt_;
145 futur += eq_ch.inconnue().valeurs();
146
147 // Mise à jour des CL sur c
149 // Mise à jour des CL sur mutilde
151 update_critere_statio(dudt, eq_ch);
152
153 }
154
155 // set_stationnaire_atteint() = isStationary();
156 return 1;
157}
classe Cahn_Hilliard
void calculer_contribution_CL_concentration(const DoubleTab &)
Renvoie la contribution des conditions limites sur la concentration sous forme d'un vecteur (multi-co...
bool matrices_initialisees()
const Fermeture_Thermo_base & fermeture() const
void compute_mutilde()
Calcul de mutilde = beta*dW/dc - ∇. kappa ∇c.
void initialiser_matrices()
void calculer_contribution_CL_mutilde(const DoubleTab &)
Renvoie la contribution des conditions limites sur le potentiel chimique sous forme d'un vecteur (mul...
const Champ_Inc_base & mutilde() const
DoubleTab & derivee_en_temps_inco(DoubleTab &) override
Returns the time derivative of the unknown I of the equation: dI/dt = M-1*(sum(operators(I) + sources...
Domaine_Cl_dis_base & domaine_Cl_dis_mutilde()
void update_terme_mobilite(const DoubleTab &)
const Champ_Inc_base & inconnue() const override
Renvoie la concentration (champ inconnue de l'equation) (version const).
DoubleTab & futur(int i=1) override
Returns field values at instant t+i.
DoubleTab & passe(int i=1) override
Returns field values at instant t-i.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
Champ_Inc_base & avancer(int i=1)
Advances the current pointer by i time steps, in the list of kept temporal values.
Champ_Inc_base & reculer(int i=1)
Rewinds the current pointer by i time steps, in the list of kept temporal values.
virtual void imposer_cond_lim(Champ_Inc_base &, double)=0
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 Domaine_Cl_dis_base & domaine_Cl_dis()
Returns the discretized boundary condition domain associated with the equation.
Probleme_base & probleme()
Returns the problem associated with the equation.
Domaine_dis_base & domaine_dis()
Returns the discretized domain associated with the equation.
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
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Probleme_U.h:109
class Probleme_base It is a Probleme_U that is not a coupling.
virtual const Equation_base & equation(int) const =0
class Schema_Cahn_Hilliard. Il herite de schema Euler semi implicite et ne s'applique qu'à Cahn-Hilli...
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 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_Euler_Semi_Implicite Il herite de schema Euler implicite et porte un solveur,...
bool is_explicit()
Renvoie TRUE si le schéma semi-implicite est totalement explicite (important, car theta = 0 pose prob...
double temps_courant() const
Returns the current time.
double dt_
Computation time step.
Probleme_base & pb_base()
double pas_de_temps() const
Returns the current time step (delta_t).
void update_critere_statio(const DoubleTab &tab_critere, Equation_base &equation)
Updates stationnaire_atteint_ and residu_ (criterion: residu_ < seuil_statio_).
Base class for output streams.
Definition Sortie.h:52