Loading...
Searching...
No Matches
system_solvers_small.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25// ========================================================================== //
26// LINEAR ALGEBRA PACKAGE //
27// //
28// Functions for basic linear algebra computations. //
29// ========================================================================== //
30// INFO //
31// ========================================================================== //
32// Author : Alessandro Alaia //
33// Data : Sept 26, 2014 //
34// Version : v2.0 //
35// //
36// All rights reserved. //
37// ========================================================================== //
38# ifndef __BITPIT_SYSTEM_SOLVERS_SMALL_HPP__
39# define __BITPIT_SYSTEM_SOLVERS_SMALL_HPP__
40
41// ========================================================================== //
42// INCLUDES //
43// ========================================================================== //
44
45// Standard template library
46# include <vector>
47# include <cmath>
48# include <array>
49# include <iostream>
50
51# include "bitpit_operators.hpp"
52
53namespace bitpit{
54
58namespace linearalgebra{
59
60namespace constants{
61
62extern const int ROW_MAJOR;
63extern const int COL_MAJOR;
64
65}
66
67template <class T>
68void cramer( // Solve linear system using Cramer's rule
69 std::vector< std::vector < T > > &, // (input) coeff. matrix
70 std::vector< T > &, // (input) source term
71 std::vector< T > & // (input/output) solution
72);
73
74template <class T, size_t m, size_t n>
75void cramer( // Solve linear system using Cramer's rule
76 std::array< std::array < T, n >, m > &, // (input) coeff. matrix
77 std::array< T, m > &, // (input) source term
78 std::array< T, n > & // (input/output) solution
79);
80
81unsigned int factorizeLU( // LU decomposition of matrix
82 std::vector<std::vector<double>> &, // (input) Input matrix
83 std::vector<std::vector<double>> &, // (input/output) L factor
84 std::vector<std::vector<double>> &, // (input/output) U factor
85 std::vector<std::vector<double>> * // (input/optional) permutation matrix
86);
87
88template<size_t m>
89unsigned int factorizeLU( // LU decomposition of matrix
90 std::array<std::array<double, m>, m> &, // (input) Input matrix
91 std::array<std::array<double, m>, m> &, // (input/output) L factor
92 std::array<std::array<double, m>, m> &, // (input/output) U factor
93 std::array<std::array<double, m>, m> * // (input/optional) permutation matrix
94);
95
96void backwardSubstitution( // Backward substitution algorithm
97 std::vector<std::vector<double>> &, // (input) Coeffs. matrix
98 std::vector<double> &, // (input) Source term
99 std::vector<double> & // (input/output) Solution
100);
101
102template<size_t m>
103void backwardSubstitution( // Backward substitution algorithm
104 std::array<std::array<double, m>, m> &, // (input) Coeffs. matrix
105 std::array<double, m> &, // (input) Source term
106 std::array<double, m> & // (input/output) Solution
107);
108
109void forwardSubstitution( // Forward substitution algorithm
110 std::vector<std::vector<double>> &, // (input) Coeffs. matrix
111 std::vector<double> &, // (input) Source term
112 std::vector<double> & // (input/output) Solution
113);
114
115template<size_t m>
116void forwardSubstitution( // Forward substitution algorithm
117 std::array<std::array<double, m>, m> &, // (input) Coeffs. matrix
118 std::array<double, m> &, // (input) Source term
119 std::array<double, m> & // (input/output) Solution
120);
121
122void solveLU( // Solve linear system using LU factorization
123 std::vector<std::vector<double>> &, // (input) Input coeffs. matrix
124 std::vector<double> &, // (input) Source term
125 std::vector<double> & // (input/output) Solution
126);
127
128template<size_t m>
129void solveLU( // Solve linear system using LU factorization
130 std::array<std::array<double, m>, m> &, // (input) Input coeffs. matrix
131 std::array<double, m> &, // (input) Source term
132 std::array<double, m> & // (input/output) Solution
133);
134
135int solveLU( // Solve linear system using Lapack DGESV
136 int , // (input) Matrix layout
137 std::vector<double> &, // (input) Input coeffs. matrix (linear)
138 std::vector<double> & // (input/output) Source term / Solution
139);
140
141int solveLU( // Solve linear system using Lapack DGESV
142 int , // (input) Matrix layout
143 int , // (input) Matrix order
144 double *, // (input) Pointer to input coeffs. matrix (linear)
145 double *, // (input/output) Pointer to source term / solution
146 int * // (output) Pivot indeces of the permutation matrix
147);
148
149}
150
151}
152
153// =================================================================================== //
154// TEMPLATES //
155// =================================================================================== //
156# include "system_solvers_small.tpp"
157
158# endif
void forwardSubstitution(std::vector< std::vector< double > > &A, std::vector< double > &B, std::vector< double > &x)
void backwardSubstitution(std::vector< std::vector< double > > &A, std::vector< double > &B, std::vector< double > &x)
unsigned int factorizeLU(std::vector< std::vector< double > > &A, std::vector< std::vector< double > > &L, std::vector< std::vector< double > > &U, std::vector< std::vector< double > > *P)
void solveLU(std::vector< std::vector< double > > &A, std::vector< double > &B, std::vector< double > &x)
void cramer(std::vector< std::vector< T > > &, std::vector< T > &, std::vector< T > &)
--- layout: doxygen_footer ---