TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Schema_Adams_Bashforth_order_3.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 <Schema_Adams_Bashforth_order_3.h>
17#include <Equation_base.h>
18#include <TRUSTTrav.h>
19
20Implemente_instanciable(Schema_Adams_Bashforth_order_3,"Schema_Adams_Bashforth_order_3",Schema_Adams_Bashforth_base);
21// XD schema_adams_bashforth_order_3 schema_temps_base schema_adams_bashforth_order_3 INHERITS_BRACE not_set
22
24{
26}
27
29{
31}
32
33////////////////////////////////
34// //
35// Caracteristiques du schema //
36// //
37////////////////////////////////
38
39/*! @brief Renvoie le nombre de valeurs temporelles a conserver.
40 *
41 * Ici : n-2, n-1, n et n+1 donc 4.
42 *
43 */
48
49/*! @brief Renvoie le nombre de pas de temps strictement au dela duquel on applique le schema d Adams-Bahshforth.
50 *
51 * Ici : on a besoin d'au moins 2 temps du passe donc 1
52 *
53 */
55{
56 return 1 ;
57}
58
59/*! @brief Renvoie le nombre de valeurs temporelles du passe.
60 *
61 * Ici : n-2 et n-1 donc 1.
62 *
63 */
65{
66 return 2 ;
67}
68
69/////////////////////////////////////////
70// //
71// Fin des caracteristiques du schema //
72// //
73/////////////////////////////////////////
74
75static double Ln02(const double time_n_plus_1, const double time_n, const double time_n_minus_1, const double time_n_minus_2)
76{
77 //Integration of first degree-2 lagrangian polynomial with Simpson's formulae
78 //Ln02(time_n_minus_2) = 0
79 //Ln02(time_n_minus_1) = 0
80 //Ln02(time_n) = 1
81 //Integration bound : time_n and time_n_plus_1
82 double result = 0.;
83
84 double midpoint = (time_n_plus_1+time_n);
85 midpoint *= 0.5;
86
87 double scaling_coeff = (time_n_plus_1-time_n);
88 scaling_coeff /= 6.;
89
90 double denominator = (time_n-time_n_minus_1);
91 denominator *= (time_n-time_n_minus_2);
92 denominator = 1./denominator;
93
94 double numerator = (time_n-time_n_minus_1)*(time_n-time_n_minus_2);
95 numerator += 4*(midpoint-time_n_minus_1)*(midpoint-time_n_minus_2);
96 numerator += (time_n_plus_1-time_n_minus_1)*(time_n_plus_1-time_n_minus_2);
97
98 result = scaling_coeff * numerator * denominator;
99 return result;
100}
101
102static double Ln12(const double time_n_plus_1, const double time_n, const double time_n_minus_1, const double time_n_minus_2)
103{
104 //Integration of second degree-2 lagrangian polynomial with Simpson's formulae
105 //Ln12(time_n_minus_2) = 0
106 //Ln12(time_n_minus_1) = 1
107 //Ln12(time_n) = 0
108 //Integration bound : time_n and time_n_plus_1
109 double result = 0.;
110
111 double midpoint = (time_n_plus_1+time_n);
112 midpoint *= 0.5;
113
114 double scaling_coeff = (time_n_plus_1-time_n);
115 scaling_coeff /= 6.;
116
117 double denominator = (time_n_minus_1-time_n);
118 denominator *= (time_n_minus_1-time_n_minus_2);
119 denominator = 1./denominator;
120
121 double numerator = 0.;
122 numerator += 4*(midpoint-time_n)*(midpoint-time_n_minus_2);
123 numerator += (time_n_plus_1-time_n)*(time_n_plus_1-time_n_minus_2);
124
125 result = scaling_coeff * numerator * denominator;
126 return result;
127}
128
130{
131 if (nb_pas_dt()<100 && limpr() && facteur_securite_pas()==1.0)
132 {
133 Cerr << finl;
134 Cerr << "********************* Warning (printed only on the first 100 time steps) **********************"<< finl;
135 Cerr << "The Adams Bashforth order 3 scheme is recommended with a facsec lower than 1.0 for example 0.5."<< finl;
136 Cerr << "***********************************************************************************************"<< finl;
137 // See $TRUST_ROOT/tests/Reference/Schema_Adams_Bashforth_order_3 test case.
138 }
139
140 assert(times.size_array() == 4); //2 past times, present and future times, stored in ascending order inside "times" table
141
142 if (coefficients().size_array() != 3)
143 {
144 coefficients().resize(3,RESIZE_OPTIONS::NOCOPY_NOINIT);
145 }
146
147 double inv_time_step = 1./time_step;
148 double time_n_minus_2 = times[0];
149 double time_n_minus_1 = times[1];
150 double time_n = times[2];
151 double time_n_plus_1 = times[3];
152
153 coefficients()[2] = Ln02(time_n_plus_1,time_n,time_n_minus_1,time_n_minus_2) * inv_time_step;
154 coefficients()[1] = Ln12(time_n_plus_1,time_n,time_n_minus_1,time_n_minus_2) * inv_time_step;
155 coefficients()[0] = 1-coefficients()[2]-coefficients()[1];
156}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
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 Schema_Adams_Bashforth_base
const DoubleTab & coefficients() const override
classe Schema_Adams_Bashforth_order_3 Cette classe represente un schema en temps d'Adams-Bashforth d'...
int nb_valeurs_passees() const override
Renvoie le nombre de valeurs temporelles du passe.
int nb_pas_dt_seuil() const override
Renvoie le nombre de pas de temps strictement au dela duquel on applique le schema d Adams-Bahshforth...
int nb_valeurs_temporelles() const override
Renvoie le nombre de valeurs temporelles a conserver.
void compute_adams_bashforth_coefficients(double time_step, const DoubleTab &times) override
int limpr() const
Renvoie 1 s'il y a lieu d'effectuer une impression (cf dt_impr) Renvoie 0 sinon.
int nb_pas_dt() const
Renvoie le nombre de pas de temps effectues.
double facteur_securite_pas() const
Renvoie le facteur de securite ou multiplicateur de delta_t.
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ size_array() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469