TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
TRUSTSchema_RK.tpp
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#ifndef TRUSTSchema_RK_TPP_included
17#define TRUSTSchema_RK_TPP_included
18
19template <Ordre_RK _ORDRE_ > template<Ordre_RK _O_>
20std::enable_if_t<_O_ == Ordre_RK::DEUX_WILLIAMSON || _O_ == Ordre_RK::TROIS_WILLIAMSON || _O_ == Ordre_RK::QUATRE_WILLIAMSON, int>
21TRUSTSchema_RK<_ORDRE_>::faire_un_pas_de_temps_eqn_base_generique(Equation_base& eqn)
22{
23 static constexpr int NB_PTS = (_ORDRE_ == Ordre_RK::DEUX_WILLIAMSON) ? 2 : 3;
24
25 // Warning on the first 100 time steps if facsec equals 1 to prompt the user to reconsider
26 if (nb_pas_dt() >= 0 && nb_pas_dt() <= NW && facsec_ == 1) print_warning(NW);
27
28 DoubleTab& xi = eqn.inconnue().valeurs(), &xip1 = eqn.inconnue().futur();
29 DoubleTrav present(xi), qi(xi);
30 present = xi;
31 qi = xi;
32
33 for (int i = 0; i < NB_PTS; i++)
34 {
35 // compute: q_i = a_{i-1} * q_{i-1} + dt * f(x_{i-1})
36 qi *= get_a<_ORDRE_,NB_PTS>()[i];
37 qi.ajoute(dt_, eqn.derivee_en_temps_inco(xip1));
38
39 // compute: x_i = x_{i-1} + b_i * q_i
40 xi.ajoute(get_b<_ORDRE_,NB_PTS>()[i], qi);
41 }
42
43 xip1 = xi;
44 xi -= present;
45 xi /= dt_;
46 update_critere_statio(xi, eqn);
47
48 // Update boundary condition on futur:
49 eqn.domaine_Cl_dis().imposer_cond_lim(eqn.inconnue(), temps_courant() + pas_de_temps());
50 xip1.echange_espace_virtuel();
51
52 // xi = x0;
53 xi = present;
54
55 return 1;
56}
57
58template <Ordre_RK _ORDRE_ > template<Ordre_RK _O_>
59std::enable_if_t<_O_ == Ordre_RK::DEUX_CLASSIQUE || _O_ == Ordre_RK::TROIS_CLASSIQUE || _O_ == Ordre_RK::QUATRE_CLASSIQUE || _O_ == Ordre_RK::QUATRE_CLASSIQUE_3_8, int>
60TRUSTSchema_RK<_ORDRE_>::faire_un_pas_de_temps_eqn_base_generique(Equation_base& eqn)
61{
62 // Warning on the first 100 time steps if facsec equals 1 to prompt the user to reconsider
63 if (nb_pas_dt() >= 0 && nb_pas_dt() <= NW && facsec_ == 1) print_warning(NW);
64
65 static constexpr bool IS_DEUX = (_O_ == Ordre_RK::DEUX_CLASSIQUE) , IS_TROIS = (_O_ == Ordre_RK::TROIS_CLASSIQUE), IS_QUATRE = (_O_ == Ordre_RK::QUATRE_CLASSIQUE);
66 static constexpr int NB_PTS = IS_DEUX ? 2 : ( IS_TROIS ? 3 : 4);
67 static constexpr int NB_BUTCHER = IS_DEUX ? 0 : ( IS_TROIS ? 1 : ( IS_QUATRE ? 2 : 3 ));
68
69 DoubleTab& present = eqn.inconnue().valeurs(), &futur = eqn.inconnue().futur();
70 if (ki_.size()!=NB_PTS)
71 {
72 ki_.resize(NB_PTS);
73 // just for initializing the array structure ...
74 for (int i = 0; i < NB_PTS; i++) ki_[i] = present;
75 }
76
77 DoubleTrav sauv(present);
78 sauv = present; // sauv = y0
79
80 // Step 1
81 eqn.derivee_en_temps_inco(ki_[0]); // ki[0] = f(y0)
82 ki_[0] *= dt_; // ki[0] = h * f(y0)
83
84 for (int step = 1; step < NB_PTS; step++ ) // ATTENTION : ne touche pas !
85 {
86 present = sauv; // back to y0
87 for (int i = 0; i < step; i++) present.ajoute(get_butcher_coeff<_ORDRE_,NB_PTS-1>().at(step-1).at(i), ki_[i]); // Et ouiiiiiiii :-)
88
89 eqn.derivee_en_temps_inco(ki_[step]);
90 ki_[step] *= dt_;
91 }
92
93 futur = sauv; // futur = y1 = y0
94 for (int i = 0; i < NB_PTS; i++) futur.ajoute(BUTCHER_TAB.at(NB_BUTCHER).at(i), ki_[i]);
95
96 update_critere_statio(futur, eqn);
97
98 // Update boundary condition on futur:
99 eqn.domaine_Cl_dis().imposer_cond_lim(eqn.inconnue(), temps_courant() + pas_de_temps());
100 futur.echange_espace_virtuel();
101
102 present = sauv; // back to y0
103
104 return 1;
105}
106
107#endif /* TRUSTSchema_RK_TPP_included */
DoubleTab & futur(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 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.
void ajoute(_SCALAR_TYPE_ alpha, const TRUSTVect &y, Mp_vect_options opt=VECT_ALL_ITEMS)
Definition TRUSTVect.tpp:52