Loading...
Searching...
No Matches
simpleMatrix.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::simpleMatrix
29
30Description
31 A simple square matrix solver with scalar coefficients.
32
33SourceFiles
34 simpleMatrix.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_simpleMatrix_H
39#define Foam_simpleMatrix_H
40
41#include "scalarMatrices.H"
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45namespace Foam
46{
47
48// Forward Declarations
49template<class Type> class simpleMatrix;
50template<class Type> Ostream& operator<<(Ostream&, const simpleMatrix<Type>&);
51
52/*---------------------------------------------------------------------------*\
53 Class simpleMatrix Declaration
54\*---------------------------------------------------------------------------*/
55
56template<class Type>
57class simpleMatrix
58:
60{
61 // Private Data
62
63 Field<Type> source_;
64
65public:
66
67 // Constructors
68
69 //- Construct given size
70 // Note: this does not initialise the coefficients or the source.
71 explicit simpleMatrix(const label n);
72
73 //- Construct given size and initial values for coefficients and source
74 simpleMatrix(const label n, const scalar, const Type&);
75
76 //- Construct given size, zero values for coefficients and source
77 simpleMatrix(const label n, Foam::zero);
78
79 //- Construct from components
81
82 //- Copy construct
83 simpleMatrix(const simpleMatrix<Type>&) = default;
84
85 //- Construct from Istream
86 explicit simpleMatrix(Istream&);
87
88
89 // Member Functions
90
91 //- Return access to the source
92 Field<Type>& source() noexcept { return source_; }
93
94 //- Return const-access to the source
95 const Field<Type>& source() const noexcept { return source_; }
96
97
98 //- Solve the matrix using Gaussian elimination with pivoting
99 //- and return the solution
100 Field<Type> solve() const;
101
102 //- Solve the matrix using LU decomposition with pivoting
103 //- and return the solution
104 Field<Type> LUsolve() const;
105
106
107 // Member Operators
108
109 //- Copy assignment
110 void operator=(const simpleMatrix<Type>&);
111
112
113 // Ostream Operator
114
115 friend Ostream& operator<< <Type>
116 (
117 Ostream&,
118 const simpleMatrix<Type>&
119 );
120};
121
122
123// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124
125// Global Operators
126
127template<class Type>
128simpleMatrix<Type> operator+
129(
130 const simpleMatrix<Type>&,
131 const simpleMatrix<Type>&
132);
134template<class Type>
135simpleMatrix<Type> operator-
136(
137 const simpleMatrix<Type>&,
138 const simpleMatrix<Type>&
139);
140
141template<class Type>
142simpleMatrix<Type> operator*
143(
144 const scalar,
145 const simpleMatrix<Type>&
147
148
149// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
151} // End namespace Foam
152
153// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154
155#ifdef NoRepository
156 #include "simpleMatrix.C"
157#endif
158
159// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161#endif
162
163// ************************************************************************* //
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
label n() const noexcept
The number of columns.
Definition Matrix.H:271
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A simple square matrix solver with scalar coefficients.
void operator=(const simpleMatrix< Type > &)
Copy assignment.
const Field< Type > & source() const noexcept
Return const-access to the source.
simpleMatrix(const label n)
Construct given size.
Field< Type > solve() const
Solve the matrix using Gaussian elimination with pivoting and return the solution.
simpleMatrix(const simpleMatrix< Type > &)=default
Copy construct.
Field< Type > LUsolve() const
Solve the matrix using LU decomposition with pivoting and return the solution.
Field< Type > & source() noexcept
Return access to the source.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
SquareMatrix< scalar > scalarSquareMatrix
const direction noexcept
Definition scalarImpl.H:265