mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improvements, modernization of matrix containers (#1220)
- add iterators, begin/end, empty() methods for STL behaviour.
Use standard algorithms where possible
* std::fill, std::copy
* std::min_element, std::max_element
- access methods consistent with other OpenFOAM containers:
* data(), cdata(), uniform()
- Use ListPolicy to impose output line breaks
- Can recover matrix storage for re-use elsewhere.
For example, to populate values with 2D i-j addressing and later
release it as flat linear storage.
- construct/assign moveable
- added minMax() function for Matrix
- additional inplace +=, -=, *=, /= operations
- add named methods at() and rowData() to Matrix.
Allows a better distinction between linear and row-based addressing
- low-level matrix solve on List/UList instead of Field
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
@ -40,44 +40,82 @@ using namespace Foam;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SquareMatrix<scalar> hmm(3);
|
||||
|
||||
hmm(0, 0) = -3.0;
|
||||
hmm(0, 1) = 10.0;
|
||||
hmm(0, 2) = -4.0;
|
||||
hmm(1, 0) = 2.0;
|
||||
hmm(1, 1) = 3.0;
|
||||
hmm(1, 2) = 10.0;
|
||||
hmm(2, 0) = 2.0;
|
||||
hmm(2, 1) = 6.0;
|
||||
hmm(2, 2) = 1.0;
|
||||
|
||||
//Info<< hmm << endl << hmm - 2.0*(-hmm) << endl;
|
||||
Info<< max(hmm) << endl;
|
||||
Info<< min(hmm) << endl;
|
||||
|
||||
SquareMatrix<scalar> hmm2(3, I);
|
||||
|
||||
hmm = hmm2;
|
||||
|
||||
Info<< hmm << endl;
|
||||
|
||||
//SquareMatrix<scalar> hmm3(Sin);
|
||||
|
||||
//Info<< hmm3 << endl;
|
||||
|
||||
SquareMatrix<scalar> hmm4;
|
||||
|
||||
hmm4 = hmm2;
|
||||
|
||||
Info<< hmm4 << endl;
|
||||
|
||||
SquareMatrix<scalar> hmm5;
|
||||
|
||||
hmm4 = hmm5;
|
||||
Info<< hmm5 << endl;
|
||||
|
||||
// SquareMatrix
|
||||
{
|
||||
Info<< nl << "Test SquareMatrix" << nl;
|
||||
|
||||
SquareMatrix<scalar> square1(3);
|
||||
|
||||
square1(0, 0) = -3.0;
|
||||
square1(0, 1) = 10.0;
|
||||
square1(0, 2) = -4.0;
|
||||
square1(1, 0) = 2.0;
|
||||
square1(1, 1) = 3.0;
|
||||
square1(1, 2) = 10.0;
|
||||
square1(2, 0) = 2.0;
|
||||
square1(2, 1) = 6.0;
|
||||
square1(2, 2) = 1.0;
|
||||
|
||||
Info<< "matrix: " << square1
|
||||
<< " begin: " << long(square1.cdata()) << nl;
|
||||
|
||||
//Info<< square1 - 2.0*(-square1) << nl;
|
||||
Info<< "min:" << min(square1) << " max:" << max(square1) << nl;
|
||||
Info<< "min/max: " << minMax(square1) << nl;
|
||||
|
||||
// Steal matrix contents
|
||||
|
||||
List<scalar> stole(square1.release());
|
||||
|
||||
Info<< "matrix: " << square1
|
||||
<< " begin: " << long(square1.cdata()) << nl;
|
||||
|
||||
Info<< "List: " << stole << nl;
|
||||
|
||||
Info<< "min/max: " << minMax(square1) << nl;
|
||||
|
||||
square1 = 100;
|
||||
|
||||
Info<< "matrix: " << square1
|
||||
<< " begin: " << long(square1.cdata()) << nl;
|
||||
|
||||
|
||||
SquareMatrix<scalar> square2(3, I);
|
||||
|
||||
square1 = square2;
|
||||
|
||||
Info<< nl << "After copy assign from Identity:" << nl << square1 << nl;
|
||||
|
||||
square1 += 1.25*square2;
|
||||
|
||||
Info<< nl << "After +=" << nl << square1 << nl;
|
||||
|
||||
square1 -= square2.T();
|
||||
|
||||
Info<< nl << "After -=" << nl << square1 << nl;
|
||||
|
||||
square1 *= 10;
|
||||
|
||||
Info<< nl << "After *=" << nl << square1 << nl;
|
||||
|
||||
square1 /= 8;
|
||||
|
||||
Info<< nl << "After /=" << nl << square1 << nl;
|
||||
|
||||
SquareMatrix<scalar> square4;
|
||||
square4 = square2;
|
||||
|
||||
Info<< nl << square4 << endl;
|
||||
|
||||
SquareMatrix<scalar> square5;
|
||||
square4 = square5;
|
||||
Info<< nl << square5 << endl;
|
||||
}
|
||||
|
||||
// RectangularMatrix
|
||||
{
|
||||
Info<< nl << "Test RectangularMatrix" << nl;
|
||||
|
||||
RectangularMatrix<scalar> rm1(5, 6, 3.1);
|
||||
rm1(0, 1) = 4.5;
|
||||
RectangularMatrix<scalar> rm1b(rm1.block(2, 2, 0, 0));
|
||||
|
||||
Reference in New Issue
Block a user