TrioCFD 1.9.9_beta
TrioCFD documentation
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// Schema characteristics //
36// //
37////////////////////////////////
38
39/*! @brief Returns the number of temporal values to keep.
40 *
41 * Here: n-2, n-1, n and n+1, so 4.
42 *
43 */
48
49/*! @brief Returns the number of time steps strictly beyond which the Adams-Bashforth scheme is applied.
50 *
51 * Here: we need at least 2 past times, so 1.
52 *
53 */
55{
56 return 1 ;
57}
58
59/*! @brief Returns the number of past temporal values.
60 *
61 * Here: n-2 and n-1, so 2.
62 *
63 */
65{
66 return 2 ;
67}
68
69/////////////////////////////////////////
70// //
71// End of schema characteristics //
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 &)
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 DoubleTab & coefficients() const override
class Schema_Adams_Bashforth_order_3 This class represents a variable time-step third-order Adams-Bas...
int nb_valeurs_passees() const override
Returns the number of past temporal values.
int nb_pas_dt_seuil() const override
Returns the number of time steps strictly beyond which the Adams-Bashforth scheme is applied.
int nb_valeurs_temporelles() const override
Returns the number of temporal values to keep.
void compute_adams_bashforth_coefficients(double time_step, const DoubleTab &times) override
int limpr() const
Returns 1 if there is a need to perform a print (cf dt_impr) Returns 0 otherwise.
int nb_pas_dt() const
Returns the number of time steps performed.
double facteur_securite_pas() const
Returns the safety factor or multiplier of delta_t.
Base class for output streams.
Definition Sortie.h:52
_SIZE_ size_array() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469