TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Solv_TDMA.cpp
1/****************************************************************************
2* Copyright (c) 2022, 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 <Solv_TDMA.h>
17#include <TRUSTVect.h>
18
19void Solv_TDMA::resoudre(const DoubleVect& ma, const DoubleVect& mb, const DoubleVect& mc, const DoubleVect& sm, DoubleVect& vi, int M)
20{
21 DoubleVect malpha, mbeta; //2 vecteurs intermediares
22 DoubleVect my; //vecteur solution du systeme L.y=F
23 int i;
24 malpha.resize(M);
25 mbeta.resize(M);
26 my.resize(M);
27
28 //L'algorithme de Thomas (TDMA) repose sur la decomposition LU de la matrice
29 //tridiagonale a inverser. Soit A.x = y le systeme lineaire a inverser avec A = LU.
30 //On resoud d'abord par descente le syteme L.z = y avec z = U.x et on resoud ensuite
31 //par remontee le systeme U.x = z.
32
33 // Les 3 diagonales de la matrice sont chacune conservees sous forme de vecteur
34 // ma : diagonale principale ; mb : diagonale secondaire inferieure
35 // mc : diagonale secondaire superieure
36 // M est l'ordre de la matrice A
37
38 //La matrice L est composee d'une diagonale principale (malpha) et d'une diagonale
39 //secondaire inferieure (mb). La matrice U est composee d'une diagonale principale
40 //(dont tous les elements sont egaux a 1) et d'une diagonale secondaire superieure
41 //(mbeta).
42
43 //Resolution correcte d'un systeme lineaire 3*3 antisymetrique, le 23.05.2003
44
45 //Remplissage de malpha et mbeta
46
47 malpha(0) = ma(0);
48 mbeta(0) = mc(0)/ma(0);
49
50 for (i = 1 ; i<M-1 ; i++)
51 {
52 malpha(i) = ma(i) - mb(i-1)*mbeta(i-1);
53 mbeta(i) = mc(i)/malpha(i);
54 }
55 malpha(M-1) = ma(M-1) - mb(M-2)*mbeta(M-2);
56
57 //Resolution du premier systeme par descente
58
59 my(0) = sm(0)/malpha(0);
60
61 for (i = 1 ; i<M ; i++)
62 my(i) = (sm(i)-mb(i-1)*my(i-1))/malpha(i);
63
64 //Resolution du premier systeme par remontee
65
66 vi(M-1) = my(M-1);
67
68 for (i = M-2 ; i>=0 ; i--)
69 vi(i) = my(i) - mbeta(i)*vi(i+1);
70}
static void resoudre(const DoubleVect &ma, const DoubleVect &mb, const DoubleVect &mc, const DoubleVect &sm, DoubleVect &vi, int M)
Definition Solv_TDMA.cpp:19
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91