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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::simpleMatrix
29 
30 Description
31  A simple square matrix solver with scalar coefficients.
32 
33 SourceFiles
34  simpleMatrix.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_simpleMatrix_H
39 #define Foam_simpleMatrix_H
40 
41 #include "scalarMatrices.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward Declarations
49 template<class Type> class simpleMatrix;
50 template<class Type> Ostream& operator<<(Ostream&, const simpleMatrix<Type>&);
51 
52 /*---------------------------------------------------------------------------*\
53  Class simpleMatrix Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 template<class Type>
57 class simpleMatrix
58 :
59  public scalarSquareMatrix
60 {
61  // Private Data
62 
63  Field<Type> source_;
64 
65 public:
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 
127 template<class Type>
128 simpleMatrix<Type> operator+
129 (
130  const simpleMatrix<Type>&,
131  const simpleMatrix<Type>&
132 );
133 
134 template<class Type>
135 simpleMatrix<Type> operator-
136 (
137  const simpleMatrix<Type>&,
138  const simpleMatrix<Type>&
139 );
140 
141 template<class Type>
142 simpleMatrix<Type> operator*
143 (
144  const scalar,
145  const simpleMatrix<Type>&
146 );
147 
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 } // End namespace Foam
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #ifdef NoRepository
156  #include "simpleMatrix.C"
157 #endif
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #endif
162 
163 // ************************************************************************* //
simpleMatrix(const label n)
Construct given size.
Definition: simpleMatrix.C:27
Field< Type > & source() noexcept
Return access to the source.
Definition: simpleMatrix.H:102
void operator=(const simpleMatrix< Type > &)
Copy assignment.
Definition: simpleMatrix.C:104
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
label n() const noexcept
The number of columns.
Definition: Matrix.H:271
Field< Type > LUsolve() const
Solve the matrix using LU decomposition with pivoting and return the solution.
Definition: simpleMatrix.C:90
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition: Field.H:69
A simple square matrix solver with scalar coefficients.
Definition: simpleMatrix.H:44
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: scalarImpl.H:265
Field< Type > solve() const
Solve the matrix using Gaussian elimination with pivoting and return the solution.
Definition: simpleMatrix.C:78
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Namespace for OpenFOAM.