TrioCFD 1.9.9_beta
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 intermediate vectors
22 DoubleVect my; //solution vector of the system L.y=F
23 int i;
24 malpha.resize(M);
25 mbeta.resize(M);
26 my.resize(M);
27
28 //The Thomas algorithm (TDMA) relies on the LU decomposition of the tridiagonal
29 //matrix to be inverted. Let A.x = y be the linear system to solve with A = LU.
30 //We first solve by forward substitution the system L.z = y with z = U.x, then
31 //solve by back substitution the system U.x = z.
32
33 // The 3 diagonals of the matrix are each stored as a vector:
34 // ma: main diagonal; mb: lower sub-diagonal
35 // mc: upper super-diagonal
36 // M is the order of matrix A
37
38 //Matrix L has a main diagonal (malpha) and a lower sub-diagonal (mb).
39 //Matrix U has a main diagonal (all elements equal to 1) and an upper
40 //super-diagonal (mbeta).
41
42 //Verified solution of an antisymmetric 3x3 linear system (23.05.2003)
43
44 //Fill malpha and mbeta
45
46 malpha(0) = ma(0);
47 mbeta(0) = mc(0)/ma(0);
48
49 for (i = 1 ; i<M-1 ; i++)
50 {
51 malpha(i) = ma(i) - mb(i-1)*mbeta(i-1);
52 mbeta(i) = mc(i)/malpha(i);
53 }
54 malpha(M-1) = ma(M-1) - mb(M-2)*mbeta(M-2);
55
56 //Forward substitution to solve the first system
57
58 my(0) = sm(0)/malpha(0);
59
60 for (i = 1 ; i<M ; i++)
61 my(i) = (sm(i)-mb(i-1)*my(i-1))/malpha(i);
62
63 //Back substitution to solve the second system
64
65 vi(M-1) = my(M-1);
66
67 for (i = M-2 ; i>=0 ; i--)
68 vi(i) = my(i) - mbeta(i)*vi(i+1);
69}
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