TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Leap_frog.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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 <Domaine_Cl_dis_base.h>
17#include <Equation_base.h>
18#include <Leap_frog.h>
19
20Implemente_instanciable(Leap_frog,"Leap_frog",Schema_Temps_base);
21// XD leap_frog schema_temps_base leap_frog INHERITS_BRACE This is the leap-frog scheme.
22
24{
26}
27
29{
31}
32
33////////////////////////////////
34// //
35// Schema characteristics //
36// //
37////////////////////////////////
38
39
40/*! @brief Returns the number of temporal values to keep.
41 *
42 * Here: n-2, n-1, n, and n+1, so 4.
43 *
44 */
46{
47 return 4;
48}
49
50/*! @brief Returns the number of future temporal values.
51 *
52 * Here: n+1, so 1.
53 *
54 */
56{
57 return 1 ;
58}
59
60/*! @brief Returns the time at the i-th future value.
61 *
62 * Here: t(n+1)
63 *
64 */
65double Leap_frog::temps_futur(int i) const
66{
67 assert(i==1);
68 return temps_courant()+pas_de_temps();
69}
70
71/*! @brief Returns the time that fields must return when valeurs() is called.
72 *
73 * Here: t(n+1)
74 *
75 */
77{
78 return temps_courant()+pas_de_temps();
79}
80
81/////////////////////////////////////////
82// //
83// End of schema characteristics //
84// //
85/////////////////////////////////////////
86
87
88/*! @brief Performs a Leap_frog time step on the equation passed as parameter.
89 *
90 * @param (Equation_base& eq) the equation to advance by one time step
91 * @return (int) always returns 1
92 */
94{
95 // EXAMPLE FOR AN EXPLICIT SCHEME USING U(n) and U(n+1)
96 // Un+1=Un+dt*F
97 // Un
98 DoubleTab& present = eq.inconnue().valeurs();
99
100 // Un+1
101 DoubleTab& futur = eq.inconnue().futur();
102
103 // Un+1=F
104 eq.derivee_en_temps_inco(futur);
106
107 // WRITE HERE THE COMPUTATION OF U(n+1) AS A FUNCTION OF U(n) AND OF derivee
108 // futur*=dt; Un+1=dt*F
109 // futur+=present; Un+1=Un+dt*F
110 // IF IT WERE A SCHEME INVOLVING U(n-1)
111 // if ((nb_pas_dt_>4) && ((nb_pas_dt_ % 10) != 0)) {
112 // if (nb_pas_dt_>4) {
113 if ((nb_pas_dt_>4) && ((nb_pas_dt_ % 10) != 0))
114 {
115 DoubleTab& passe = eq.inconnue().passe();
116 double gamma=0.2;
117 DoubleTab& passe2 = eq.inconnue().passe(2);
118 DoubleTab& correcteur=passe;
119 correcteur*=(1.-2.*gamma);
120 correcteur.ajoute(gamma, present, VECT_REAL_ITEMS);
121 correcteur.ajoute(gamma, passe2, VECT_REAL_ITEMS);
122 futur*=(2*dt_);
123 futur+=correcteur;
124 }
125 else
126 {
127 futur*=dt_;
128 futur+=present;
129 }
130
132 DoubleTab tmp(futur);
133 tmp -= present;
134 tmp /= dt_;
135 update_critere_statio(tmp, eq);
137
138 return 1;
139}
140
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.
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 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.
Leap_frog This class represents a Leap_Frog time scheme.
Definition Leap_frog.h:33
double temps_defaut() const override
Returns the time that fields must return when valeurs() is called.
Definition Leap_frog.cpp:76
int nb_valeurs_futures() const override
Returns the number of future temporal values.
Definition Leap_frog.cpp:55
int faire_un_pas_de_temps_eqn_base(Equation_base &) override
Performs a Leap_frog time step on the equation passed as parameter.
Definition Leap_frog.cpp:93
double temps_futur(int i) const override
Returns the time at the i-th future value.
Definition Leap_frog.cpp:65
int nb_valeurs_temporelles() const override
Returns the number of temporal values to keep.
Definition Leap_frog.cpp:45
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
class Schema_Temps_base
double temps_courant() const
Returns the current time.
double dt_
Computation time step.
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
void ajoute(_SCALAR_TYPE_ alpha, const TRUSTVect &y, Mp_vect_options opt=VECT_ALL_ITEMS)
Definition TRUSTVect.tpp:52
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")