TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Cahn_Hilliard_Convection.cpp
1/****************************************************************************
2* Copyright (c) 2021, 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 <Cahn_Hilliard_Convection.h>
17#include <Probleme_base.h>
18#include <Schema_Cahn_Hilliard_Navier_Stokes.h>
19
20Implemente_instanciable(Cahn_Hilliard_Convection,"Cahn_Hilliard_Convection",Cahn_Hilliard);
21
23{
24 return Cahn_Hilliard::printOn(os);
25}
26
28{
29 return Cahn_Hilliard::readOn(is);
30}
31
33{
35 // Spécifiques à l'équation de Cahn-Hilliard advective :
36 param.ajouter_non_std("convection",(this), Param::REQUIRED);
37 param.ajouter_condition("is_read_convection","The convection operator must be read, select negligeable type if you want to neglect it.");
38}
39
41{
42 if (mot=="convection")
43 {
44 Cerr << "Reading and typing of the convection operator : " << finl;
45 const Champ_base& vitesse_transportante = vitesse_pour_transport();
46 associer_vitesse(vitesse_transportante);
47 terme_convectif_.associer_vitesse(vitesse_transportante);
48 is >> terme_convectif_;
49 return 1;
50 }
51 else
53}
54
59
60/*! @brief Renvoie le nombre d'operateurs de l'equation: Pour Cahn-Hilliard c'est 3.
61 *
62 * @return (int) le nombre d'operateur de l'equation
63 */
65{
66 return 3;
67}
68
73
74/*! @brief Renvoie le i-eme operateur de l'equation:
75 *
76 * @param (int i) l'index de l'operateur a renvoyer
77 * @return (Operateur&) l'operateur indexe par i
78 */
80{
81 switch(i)
82 {
83 case 0:
84 return terme_mobilite_;
85 case 1:
86 return terme_kappa_;
87 case 2:
88 return terme_convectif_;
89 default :
90 Cerr << "Error for Cahn_Hilliard_Convection::operateur(int i)" << finl;
91 Cerr << "Cahn_Hilliard has " << nombre_d_operateurs() <<" operators "<<finl;
92 Cerr << "and you are trying to access the " << i <<" th one."<< finl;
93 exit();
94 }
95 // Pour les compilos!!
96 return terme_mobilite_;
97}
98
99/*! @brief Renvoie le i-eme operateur de l'equation:
100 * @param (int i) l'index de l'operateur a renvoyer
101 * @return (Operateur&) l'operateur indexe par i
102 */
104{
105 switch(i)
106 {
107 case 0:
108 return terme_mobilite_;
109 case 1:
110 return terme_kappa_;
111 case 2:
112 return terme_convectif_;
113 default :
114 Cerr << "Error for Cahn_Hilliard_Convection::operateur(int i)" << finl;
115 Cerr << "Cahn_Hilliard has " << nombre_d_operateurs() <<" operators "<<finl;
116 Cerr << "and you are trying to access the " << i <<" th one."<< finl;
117 exit();
118 }
119 // Pour les compilos!!
120 return terme_mobilite_;
121}
122
123/*! @brief Returns the time derivative of the unknown I of the equation: dI/dt = M-1*(sum(operators(I) + sources))
124 *
125 * In : derivee contains I (but immediatly set to 0)
126 * Out: derivee contains dI/dt
127 *
128 */
130{
131 derivee = 0.;
132
133 DoubleTrav secmem(derivee);
134 // secmem = sum(operators) + sources + equation specific terms
135
136 if (implicite_==0)
137 {
138 // On cherche à construire : dc/dt = M-1 * (D mutilde^n)
139 // avec mutilde^n = beta*dW/dc^n - Kc^n
140 // où D est la matrice de l'opérateur lié à mu (terme_mobilite_)
141 // et K est la matirce de l'opérateur lié à kappa (terme_kappa_)
142
143 // On calcule d'abord mutilde^n = beta*dW/dc^n - Kc^n (fonction compute_mutilde)
145 // Ici normalement les valeurs de mutilde (qui est l'inconnue de l'opérateur 0) sont mises à jour
146 operateur(0).calculer(secmem); // secmem = D mutilde^n
147 operateur(2).ajouter(secmem); // secmem += advection term
148 les_sources.ajouter(secmem); // secmem += sources
149 solveur_masse->appliquer(secmem); // M-1 * secmem
150 derivee = secmem;
151 derivee.echange_espace_virtuel();
152
153 }
154 else if (implicite_>0)
155 {
156 Cerr << "[Cahn_Hilliard_Convection] Warning: Be careful with implicit part in derivative computation." << finl;
158 }
159 else
160 {
161 Cerr << "Error in Cahn_Hilliard_Convection::derivee_en_temps_inco" << finl;
162 Cerr << "implicite_ = " << implicite_ << " has not been initialized!" << finl;
163 Cerr << "May be " << que_suis_je() << "::completer() method doesn't call Cahn_Hilliard::completer()" << finl;
165 }
166
167 return derivee;
168}
169
170DoubleTab Cahn_Hilliard_Convection::fonction_residu(const DoubleTab& c)
171{
172 DoubleTab residu = Cahn_Hilliard::fonction_residu(c);
173 //
174 const int nb_elem = domaine_dis().nb_elem();
175 const int nb_param = nb_parametres_d_ordre();
176 const double dt=schema_temps().pas_de_temps();
177 const double theta=ref_cast(Schema_Cahn_Hilliard_Navier_Stokes, schema_temps()).coeff_theta();
178 //
179 DoubleTrav advection(concentration_->valeurs());
180 terme_convectif_.calculer(c, advection);
181 solv_masse().appliquer(advection);
182 for (int elem = 0; elem < nb_elem; elem++)
183 for (int p = 0; p < nb_param; p++)
184 residu(elem, p) -= dt*theta*advection(elem,p);
185 //
186 residu.echange_espace_virtuel();
187 return residu;
188}
classe Cahn_Hilliard_Convection
const Champ_base & vitesse_pour_transport() const
int nombre_d_operateurs() const override
Renvoie le nombre d'operateurs de l'equation: Pour Cahn-Hilliard c'est 3.
const Operateur & operateur(int) const override
Renvoie le i-eme operateur de l'equation:
int lire_motcle_non_standard(const Motcle &, Entree &) override
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
DoubleTab fonction_residu(const DoubleTab &) override
Construit la fonction résidu pour un algorithme de Newton :
void associer_vitesse(const Champ_base &vit)
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...
int nombre_d_operateurs_tot() const override
void set_param(Param &) const override
classe Cahn_Hilliard
int nb_parametres_d_ordre()
virtual DoubleTab fonction_residu(const DoubleTab &)
Construit la fonction résidu pour un algorithme de Newton :
int lire_motcle_non_standard(const Motcle &, Entree &) override
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
void compute_mutilde()
Calcul de mutilde = beta*dW/dc - ∇. kappa ∇c.
void set_param(Param &) const override
Operateur_Diff terme_mobilite_
Operateur_Diff terme_kappa_
classe Champ_base Cette classe est la base de la hierarchie des champs.
Definition Champ_base.h:43
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Solveur_Masse_base & solv_masse()
Renvoie le solveur de masse associe a l'equation.
Sources les_sources
Probleme_base & probleme()
Renvoie le probleme associe a l'equation.
Schema_Temps_base & schema_temps()
Renvoie le schema en temps associe a l'equation.
Domaine_dis_base & domaine_dis()
Renvoie le domaine discretise associe a l'equation.
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
friend class Entree
Definition Objet_U.h:76
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
classe Operateur Classe generique de la hierarchie des operateurs.
Definition Operateur.h:39
virtual DoubleTab & calculer(const DoubleTab &, DoubleTab &) const =0
virtual DoubleTab & ajouter(const DoubleTab &, DoubleTab &) const =0
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter_condition(const char *condition, const char *message, const char *name=0)
Declare a post-read logical condition that must hold on the parameter values.
Definition Param.cpp:496
@ REQUIRED
Definition Param.h:115
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
const Champ_base & get_champ(const Motcle &nom) const override
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
double pas_de_temps() const
Renvoie le pas de temps (delta_t) courant.
virtual DoubleTab & appliquer(DoubleTab &) const
renvoie appliquer_impl(x/coeffient_temporelle) si on a un coefficient temporel sinon renvoie applique...
Classe de base des flux de sortie.
Definition Sortie.h:52
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")