From a9863d9a3fe44953d1aff48514d43e2e05d01075 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 27 Mar 2025 13:26:24 +0100
Subject: [PATCH] ENH: add size_type to Matrix and VectorSpace

- easier to create type-specific looping in templated code

STYLE: pass 'direction' and 'label' by value instead of reference

COMP: qualify Foam::min() in dense matrix classes
---
 applications/test/IjkField/Make/files         |  2 +-
 .../{Test-IjkField.C => Test-IjkField.cxx}    |  0
 .../test/matrices/DiagonalMatrix/Make/files   |  2 +-
 ...agonalMatrix.C => Test-DiagonalMatrix.cxx} |  0
 .../test/matrices/EigenMatrix/Make/files      |  2 +-
 ...est-EigenMatrix.C => Test-EigenMatrix.cxx} |  0
 applications/test/matrices/Matrix/Make/files  |  2 +-
 .../Matrix/{Test-Matrix.C => Test-Matrix.cxx} |  0
 .../test/matrices/QRMatrix/Make/files         |  2 +-
 .../{Test-QRMatrix.C => Test-QRMatrix.cxx}    |  0
 .../matrices/RectangularMatrix/Make/files     |  2 +-
 ...larMatrix.C => Test-RectangularMatrix.cxx} |  0
 .../test/matrices/SquareMatrix/Make/files     |  2 +-
 ...t-SquareMatrix.C => Test-SquareMatrix.cxx} |  0
 .../matrices/SymmetricSquareMatrix/Make/files |  2 +-
 ...atrix.C => Test-SymmetricSquareMatrix.cxx} |  0
 .../matrices/DiagonalMatrix/DiagonalMatrix.C  | 16 ++---
 .../matrices/DiagonalMatrix/DiagonalMatrix.H  |  8 +--
 .../matrices/EigenMatrix/EigenMatrix.C        | 48 ++++----------
 .../matrices/EigenMatrix/EigenMatrix.H        |  6 ++
 src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C   |  5 --
 src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H   |  4 +-
 src/OpenFOAM/matrices/Matrix/Matrix.C         | 18 +++---
 src/OpenFOAM/matrices/Matrix/Matrix.H         | 41 ++++++------
 src/OpenFOAM/matrices/Matrix/MatrixI.H        |  6 +-
 .../matrices/MatrixBlock/MatrixBlock.H        | 45 ++++++++++---
 .../matrices/MatrixBlock/MatrixBlockI.H       | 28 +++------
 src/OpenFOAM/matrices/QRMatrix/QRMatrix.C     |  4 +-
 src/OpenFOAM/matrices/QRMatrix/QRMatrix.H     | 18 ++++--
 src/OpenFOAM/matrices/QRMatrix/QRMatrixI.H    |  2 +-
 .../RectangularMatrix/RectangularMatrix.H     |  6 +-
 .../RectangularMatrix/RectangularMatrixI.H    | 10 +--
 .../matrices/SquareMatrix/SquareMatrix.H      |  9 ++-
 .../matrices/SquareMatrix/SquareMatrixI.H     |  8 +--
 .../SymmetricSquareMatrix.C                   |  4 +-
 .../SymmetricSquareMatrix.H                   |  4 +-
 .../SymmetricSquareMatrixI.H                  |  4 +-
 .../matrices/simpleMatrix/simpleMatrix.C      | 10 ++-
 .../matrices/simpleMatrix/simpleMatrix.H      | 63 ++++++++-----------
 src/OpenFOAM/meshes/ijkMesh/IjkField.H        | 16 ++---
 src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H       | 32 +---------
 src/OpenFOAM/meshes/ijkMesh/ijkAddressing.H   | 12 ++--
 src/OpenFOAM/meshes/ijkMesh/ijkAddressingI.H  | 22 ++-----
 .../primitives/MatrixSpace/MatrixSpace.H      | 42 ++++---------
 .../primitives/MatrixSpace/MatrixSpaceI.H     | 16 ++---
 .../primitives/VectorSpace/VectorSpace.H      |  3 +
 .../field/DMD/DMDModels/derived/STDMD/STDMD.C |  4 +-
 47 files changed, 238 insertions(+), 292 deletions(-)
 rename applications/test/IjkField/{Test-IjkField.C => Test-IjkField.cxx} (100%)
 rename applications/test/matrices/DiagonalMatrix/{Test-DiagonalMatrix.C => Test-DiagonalMatrix.cxx} (100%)
 rename applications/test/matrices/EigenMatrix/{Test-EigenMatrix.C => Test-EigenMatrix.cxx} (100%)
 rename applications/test/matrices/Matrix/{Test-Matrix.C => Test-Matrix.cxx} (100%)
 rename applications/test/matrices/QRMatrix/{Test-QRMatrix.C => Test-QRMatrix.cxx} (100%)
 rename applications/test/matrices/RectangularMatrix/{Test-RectangularMatrix.C => Test-RectangularMatrix.cxx} (100%)
 rename applications/test/matrices/SquareMatrix/{Test-SquareMatrix.C => Test-SquareMatrix.cxx} (100%)
 rename applications/test/matrices/SymmetricSquareMatrix/{Test-SymmetricSquareMatrix.C => Test-SymmetricSquareMatrix.cxx} (100%)

diff --git a/applications/test/IjkField/Make/files b/applications/test/IjkField/Make/files
index 8e1017d41d8..d0a905bc00b 100644
--- a/applications/test/IjkField/Make/files
+++ b/applications/test/IjkField/Make/files
@@ -1,3 +1,3 @@
-Test-IjkField.C
+Test-IjkField.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-IjkField
diff --git a/applications/test/IjkField/Test-IjkField.C b/applications/test/IjkField/Test-IjkField.cxx
similarity index 100%
rename from applications/test/IjkField/Test-IjkField.C
rename to applications/test/IjkField/Test-IjkField.cxx
diff --git a/applications/test/matrices/DiagonalMatrix/Make/files b/applications/test/matrices/DiagonalMatrix/Make/files
index 0f5877472a3..e8338d6d544 100644
--- a/applications/test/matrices/DiagonalMatrix/Make/files
+++ b/applications/test/matrices/DiagonalMatrix/Make/files
@@ -1,3 +1,3 @@
-Test-DiagonalMatrix.C
+Test-DiagonalMatrix.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-DiagonalMatrix
diff --git a/applications/test/matrices/DiagonalMatrix/Test-DiagonalMatrix.C b/applications/test/matrices/DiagonalMatrix/Test-DiagonalMatrix.cxx
similarity index 100%
rename from applications/test/matrices/DiagonalMatrix/Test-DiagonalMatrix.C
rename to applications/test/matrices/DiagonalMatrix/Test-DiagonalMatrix.cxx
diff --git a/applications/test/matrices/EigenMatrix/Make/files b/applications/test/matrices/EigenMatrix/Make/files
index 1bd5722a5f4..f652095c4f8 100644
--- a/applications/test/matrices/EigenMatrix/Make/files
+++ b/applications/test/matrices/EigenMatrix/Make/files
@@ -1,3 +1,3 @@
-Test-EigenMatrix.C
+Test-EigenMatrix.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-EigenMatrix
diff --git a/applications/test/matrices/EigenMatrix/Test-EigenMatrix.C b/applications/test/matrices/EigenMatrix/Test-EigenMatrix.cxx
similarity index 100%
rename from applications/test/matrices/EigenMatrix/Test-EigenMatrix.C
rename to applications/test/matrices/EigenMatrix/Test-EigenMatrix.cxx
diff --git a/applications/test/matrices/Matrix/Make/files b/applications/test/matrices/Matrix/Make/files
index e167e86cdc3..09565ca38a3 100644
--- a/applications/test/matrices/Matrix/Make/files
+++ b/applications/test/matrices/Matrix/Make/files
@@ -1,3 +1,3 @@
-Test-Matrix.C
+Test-Matrix.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-Matrix
diff --git a/applications/test/matrices/Matrix/Test-Matrix.C b/applications/test/matrices/Matrix/Test-Matrix.cxx
similarity index 100%
rename from applications/test/matrices/Matrix/Test-Matrix.C
rename to applications/test/matrices/Matrix/Test-Matrix.cxx
diff --git a/applications/test/matrices/QRMatrix/Make/files b/applications/test/matrices/QRMatrix/Make/files
index 9825bbfcf35..55c6d30e687 100644
--- a/applications/test/matrices/QRMatrix/Make/files
+++ b/applications/test/matrices/QRMatrix/Make/files
@@ -1,3 +1,3 @@
-Test-QRMatrix.C
+Test-QRMatrix.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-QRMatrix
diff --git a/applications/test/matrices/QRMatrix/Test-QRMatrix.C b/applications/test/matrices/QRMatrix/Test-QRMatrix.cxx
similarity index 100%
rename from applications/test/matrices/QRMatrix/Test-QRMatrix.C
rename to applications/test/matrices/QRMatrix/Test-QRMatrix.cxx
diff --git a/applications/test/matrices/RectangularMatrix/Make/files b/applications/test/matrices/RectangularMatrix/Make/files
index 49b520d0798..ad7d6863176 100644
--- a/applications/test/matrices/RectangularMatrix/Make/files
+++ b/applications/test/matrices/RectangularMatrix/Make/files
@@ -1,3 +1,3 @@
-Test-RectangularMatrix.C
+Test-RectangularMatrix.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-RectangularMatrix
diff --git a/applications/test/matrices/RectangularMatrix/Test-RectangularMatrix.C b/applications/test/matrices/RectangularMatrix/Test-RectangularMatrix.cxx
similarity index 100%
rename from applications/test/matrices/RectangularMatrix/Test-RectangularMatrix.C
rename to applications/test/matrices/RectangularMatrix/Test-RectangularMatrix.cxx
diff --git a/applications/test/matrices/SquareMatrix/Make/files b/applications/test/matrices/SquareMatrix/Make/files
index e64b858cd6b..37b022136fc 100644
--- a/applications/test/matrices/SquareMatrix/Make/files
+++ b/applications/test/matrices/SquareMatrix/Make/files
@@ -1,3 +1,3 @@
-Test-SquareMatrix.C
+Test-SquareMatrix.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-SquareMatrix
diff --git a/applications/test/matrices/SquareMatrix/Test-SquareMatrix.C b/applications/test/matrices/SquareMatrix/Test-SquareMatrix.cxx
similarity index 100%
rename from applications/test/matrices/SquareMatrix/Test-SquareMatrix.C
rename to applications/test/matrices/SquareMatrix/Test-SquareMatrix.cxx
diff --git a/applications/test/matrices/SymmetricSquareMatrix/Make/files b/applications/test/matrices/SymmetricSquareMatrix/Make/files
index da88933c249..d0e7b1173e8 100644
--- a/applications/test/matrices/SymmetricSquareMatrix/Make/files
+++ b/applications/test/matrices/SymmetricSquareMatrix/Make/files
@@ -1,3 +1,3 @@
-Test-SymmetricSquareMatrix.C
+Test-SymmetricSquareMatrix.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-SymmetricSquareMatrix
diff --git a/applications/test/matrices/SymmetricSquareMatrix/Test-SymmetricSquareMatrix.C b/applications/test/matrices/SymmetricSquareMatrix/Test-SymmetricSquareMatrix.cxx
similarity index 100%
rename from applications/test/matrices/SymmetricSquareMatrix/Test-SymmetricSquareMatrix.C
rename to applications/test/matrices/SymmetricSquareMatrix/Test-SymmetricSquareMatrix.cxx
diff --git a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C
index 60aee73efc1..d9a888049ab 100644
--- a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C
+++ b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019-2022 OpenCFD Ltd.
+    Copyright (C) 2019-2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -38,7 +38,7 @@ Foam::DiagonalMatrix<Type>::DiagonalMatrix(const label n)
 
 
 template<class Type>
-Foam::DiagonalMatrix<Type>::DiagonalMatrix(const label n, const Foam::zero)
+Foam::DiagonalMatrix<Type>::DiagonalMatrix(const label n, Foam::zero)
 :
     List<Type>(n, Foam::zero{})
 {}
@@ -55,7 +55,7 @@ template<class Type>
 template<class Form>
 Foam::DiagonalMatrix<Type>::DiagonalMatrix(const Matrix<Form, Type>& mat)
 :
-    List<Type>(min(mat.m(), mat.n()))
+    List<Type>(Foam::min(mat.m(), mat.n()))
 {
     label i = 0;
 
@@ -86,9 +86,9 @@ void Foam::DiagonalMatrix<Type>::invert()
 
 template<class Type>
 template<class CompOp>
-Foam::List<Foam::label> Foam::DiagonalMatrix<Type>::sortPermutation
+Foam::labelList Foam::DiagonalMatrix<Type>::sortPermutation
 (
-    CompOp& compare
+    const CompOp& compare
 ) const
 {
     List<label> p(this->size());
@@ -105,7 +105,7 @@ Foam::List<Foam::label> Foam::DiagonalMatrix<Type>::sortPermutation
 
 
 template<class Type>
-void Foam::DiagonalMatrix<Type>::applyPermutation(const List<label>& p)
+void Foam::DiagonalMatrix<Type>::applyPermutation(const labelUList& p)
 {
     #ifdef FULLDEBUG
     if (this->size() != p.size())
@@ -153,7 +153,7 @@ DiagonalMatrix<Type> inv(const DiagonalMatrix<Type>& mat)
 {
     // Construct with fall-back value conditional calculation
     // of invert to avoid over-eager compiler optimisation
-    DiagonalMatrix<Type> Ainv(mat.size(), Zero);
+    DiagonalMatrix<Type> Ainv(mat.size(), Foam::zero{});
 
     Type* iter = Ainv.begin();
 
@@ -177,7 +177,7 @@ template<class Type>
 DiagonalMatrix<Type> applyPermutation
 (
     const DiagonalMatrix<Type>& mat,
-    const List<label>& p
+    const labelUList& p
 )
 {
     #ifdef FULLDEBUG
diff --git a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.H b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.H
index ea9adb37a06..60e985a25e1 100644
--- a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.H
+++ b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019-2022 OpenCFD Ltd.
+    Copyright (C) 2019-2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -82,7 +82,7 @@ public:
         explicit DiagonalMatrix(const label n);
 
         //- Construct from size and initialise all elems to zero
-        DiagonalMatrix(const label n, const Foam::zero);
+        DiagonalMatrix(const label n, Foam::zero);
 
         //- Construct from size and initialise all elems to value
         DiagonalMatrix(const label n, const Type& val);
@@ -100,11 +100,11 @@ public:
         //- Return a sort permutation labelList according to
         //- a given comparison on the diagonal entries
         template<class CompOp>
-        List<label> sortPermutation(CompOp& compare) const;
+        labelList sortPermutation(const CompOp& compare) const;
 
         //- Column-reorder this Matrix according to
         //- a given permutation labelList
-        void applyPermutation(const List<label>& p);
+        void applyPermutation(const labelUList& p);
 };
 
 
diff --git a/src/OpenFOAM/matrices/EigenMatrix/EigenMatrix.C b/src/OpenFOAM/matrices/EigenMatrix/EigenMatrix.C
index 30f28d72106..21012eb0b74 100644
--- a/src/OpenFOAM/matrices/EigenMatrix/EigenMatrix.C
+++ b/src/OpenFOAM/matrices/EigenMatrix/EigenMatrix.C
@@ -204,7 +204,7 @@ void Foam::EigenMatrix<cmptType>::symmTridiagonalQL()
     for (label l = 0; l < n_; l++)
     {
         // Find SMALL subdiagonal element
-        tst1 = max(tst1, mag(EValsRe_[l]) + mag(EValsIm_[l]));
+        tst1 = Foam::max(tst1, mag(EValsRe_[l]) + mag(EValsIm_[l]));
         label m = l;
 
         // Original while-loop from Java code
@@ -462,7 +462,7 @@ void Foam::EigenMatrix<cmptType>::realSchur()
             EValsIm_[i] = Zero;
         }
 
-        for (label j = max(i - 1, 0); j < nn; ++j)
+        for (label j = Foam::max(i - 1, 0); j < nn; ++j)
         {
             norm += mag(H_[i][j]);
         }
@@ -745,7 +745,7 @@ void Foam::EigenMatrix<cmptType>::realSchur()
                     }
 
                     // Column modification
-                    for (label i = 0; i <= min(n, k + 3); ++i)
+                    for (label i = 0; i <= Foam::min(n, k + 3); ++i)
                     {
                         p = x*H_[i][k] + y*H_[i][k + 1];
 
@@ -952,7 +952,7 @@ void Foam::EigenMatrix<cmptType>::realSchur()
                     }
 
                     // Overflow control
-                    t = max(mag(H_[i][n - 1]), mag(H_[i][n]));
+                    t = Foam::max(mag(H_[i][n - 1]), mag(H_[i][n]));
 
                     if ((eps*t)*t > 1)
                     {
@@ -986,7 +986,7 @@ void Foam::EigenMatrix<cmptType>::realSchur()
         {
             z = Zero;
 
-            for (label k = low; k <= min(j, high); ++k)
+            for (label k = low; k <= Foam::min(j, high); ++k)
             {
                 z = z + EVecs_[i][k]*H_[k][j];
             }
@@ -999,37 +999,6 @@ void Foam::EigenMatrix<cmptType>::realSchur()
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-template<class cmptType>
-Foam::EigenMatrix<cmptType>::EigenMatrix(const SquareMatrix<cmptType>& A)
-:
-    n_(A.n()),
-    EValsRe_(n_, Zero),
-    EValsIm_(n_, Zero),
-    EVecs_(n_, Zero),
-    H_()
-{
-    if (n_ <= 0)
-    {
-        FatalErrorInFunction
-            << "Input matrix has zero size."
-            << abort(FatalError);
-    }
-
-    if (A.symmetric())
-    {
-        EVecs_ = A;
-        tridiagonaliseSymmMatrix();
-        symmTridiagonalQL();
-    }
-    else
-    {
-        H_ = A;
-        Hessenberg();
-        realSchur();
-    }
-}
-
-
 template<class cmptType>
 Foam::EigenMatrix<cmptType>::EigenMatrix
 (
@@ -1065,6 +1034,13 @@ Foam::EigenMatrix<cmptType>::EigenMatrix
 }
 
 
+template<class cmptType>
+Foam::EigenMatrix<cmptType>::EigenMatrix(const SquareMatrix<cmptType>& A)
+:
+    EigenMatrix<cmptType>(A, A.symmetric())
+{}
+
+
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class cmptType>
diff --git a/src/OpenFOAM/matrices/EigenMatrix/EigenMatrix.H b/src/OpenFOAM/matrices/EigenMatrix/EigenMatrix.H
index e88db3f55b7..1eaf79699f6 100644
--- a/src/OpenFOAM/matrices/EigenMatrix/EigenMatrix.H
+++ b/src/OpenFOAM/matrices/EigenMatrix/EigenMatrix.H
@@ -200,6 +200,12 @@ class EigenMatrix
 
 public:
 
+    // Typedefs
+
+        //- The value type the Matrix contains
+        typedef cmptType value_type;
+
+
     // Generated Methods
 
         //- No default construct
diff --git a/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C b/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C
index 8abbce4eab5..7d849313db9 100644
--- a/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C
+++ b/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C
@@ -30,11 +30,6 @@ License
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-template<class Type>
-Foam::LLTMatrix<Type>::LLTMatrix()
-{}
-
-
 template<class Type>
 Foam::LLTMatrix<Type>::LLTMatrix(const SquareMatrix<Type>& mat)
 {
diff --git a/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H b/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H
index 62749e5f329..92e62c2b19d 100644
--- a/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H
+++ b/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H
@@ -77,8 +77,8 @@ public:
 
     // Constructors
 
-        //- Construct null
-        LLTMatrix();
+        //- Default construct
+        LLTMatrix() = default;
 
         //- Construct and perform the decomposition on input square matrix
         LLTMatrix(const SquareMatrix<Type>& mat);
diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.C b/src/OpenFOAM/matrices/Matrix/Matrix.C
index f98ad1849f8..bb1251cf62f 100644
--- a/src/OpenFOAM/matrices/Matrix/Matrix.C
+++ b/src/OpenFOAM/matrices/Matrix/Matrix.C
@@ -51,7 +51,7 @@ Foam::tmp<Foam::Field<Type>> Foam::Matrix<Form, Type>::AmulImpl
     }
     #endif
 
-    auto tresult = tmp<Field<Type>>::New(mat.m(), Zero);
+    auto tresult = tmp<Field<Type>>::New(mat.m(), Foam::zero{});
     auto& result = tresult.ref();
 
     for (label i = 0; i < mat.m(); ++i)
@@ -86,7 +86,7 @@ Foam::tmp<Foam::Field<Type>> Foam::Matrix<Form, Type>::TmulImpl
     }
     #endif
 
-    auto tresult = tmp<Field<Type>>::New(mat.n(), Zero);
+    auto tresult = tmp<Field<Type>>::New(mat.n(), Foam::zero{});
     auto& result = tresult.ref();
 
     for (label i = 0; i < mat.m(); ++i)
@@ -118,7 +118,7 @@ Foam::Matrix<Form, Type>::Matrix(const label m, const label n)
 
 
 template<class Form, class Type>
-Foam::Matrix<Form, Type>::Matrix(const label m, const label n, const Foam::zero)
+Foam::Matrix<Form, Type>::Matrix(const label m, const label n, Foam::zero)
 :
     mRows_(m),
     nCols_(n),
@@ -326,10 +326,10 @@ void Foam::Matrix<Form, Type>::resize(const label m, const label n)
         return;
     }
 
-    Matrix<Form, Type> newMatrix(m, n, Zero);
+    Matrix<Form, Type> newMatrix(m, n, Foam::zero{});
 
-    const label mrow = min(m, mRows_);
-    const label ncol = min(n, nCols_);
+    const label mrow = Foam::min(m, mRows_);
+    const label ncol = Foam::min(n, nCols_);
 
     for (label i = 0; i < mrow; ++i)
     {
@@ -480,7 +480,7 @@ Foam::scalar Foam::Matrix<Form, Type>::columnNorm
     const bool noSqrt
 ) const
 {
-    scalar result = Zero;
+    scalar result(0);
 
     for (label i=0; i < mRows_; ++i)
     {
@@ -494,7 +494,7 @@ Foam::scalar Foam::Matrix<Form, Type>::columnNorm
 template<class Form, class Type>
 Foam::scalar Foam::Matrix<Form, Type>::norm(const bool noSqrt) const
 {
-    scalar result = Zero;
+    scalar result(0);
 
     for (const Type& val : *this)
     {
@@ -596,7 +596,7 @@ void Foam::Matrix<Form, Type>::operator=(const Type& val)
 
 
 template<class Form, class Type>
-void Foam::Matrix<Form, Type>::operator=(const Foam::zero)
+void Foam::Matrix<Form, Type>::operator=(Foam::zero)
 {
     std::fill_n(begin(), size(), Zero);
 }
diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.H b/src/OpenFOAM/matrices/Matrix/Matrix.H
index 7099fd52a49..6b9e5cce6fa 100644
--- a/src/OpenFOAM/matrices/Matrix/Matrix.H
+++ b/src/OpenFOAM/matrices/Matrix/Matrix.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019-2022 OpenCFD Ltd.
+    Copyright (C) 2019-2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -105,11 +105,25 @@ class Matrix
 
 public:
 
-    //- Matrix type
-    typedef Matrix<Form, Type> mType;
+    // Typedefs
 
-    //- Component type
-    typedef Type cmptType;
+        //- Matrix type
+        typedef Matrix<Form, Type> mType;
+
+        //- The value type the Matrix contains
+        typedef Type cmptType;
+
+        //- The value type the Matrix contains
+        typedef Type value_type;
+
+        //- The type to represent the size of a Matrix
+        typedef label size_type;
+
+        //- Random access iterator for traversing a Matrix
+        typedef Type* iterator;
+
+        //- Random access iterator for traversing a Matrix
+        typedef const Type* const_iterator;
 
 
     // Static Member Functions
@@ -122,15 +136,6 @@ public:
         }
 
 
-    // Iterators
-
-        //- Random access iterator for traversing a Matrix
-        typedef Type* iterator;
-
-        //- Random access iterator for traversing a Matrix
-        typedef const Type* const_iterator;
-
-
     // Constructors
 
         //- Default construct (empty matrix)
@@ -141,7 +146,7 @@ public:
 
         //- Construct with given number of rows/columns
         //- initializing all elements to zero
-        Matrix(const label m, const label n, const Foam::zero);
+        Matrix(const label m, const label n, Foam::zero);
 
         //- Construct with given number of rows/columns
         //- initializing all elements to the given value
@@ -152,7 +157,7 @@ public:
 
         //- Construct given number of rows/columns
         //- initializing all elements to zero
-        inline Matrix(const labelPair& dims, const Foam::zero);
+        inline Matrix(const labelPair& dims, Foam::zero);
 
         //- Construct with given number of rows/columns
         //- initializing all elements to the given value
@@ -213,7 +218,7 @@ public:
         inline label size() const noexcept;
 
         //- Return row/column sizes
-        inline labelPair sizes() const;
+        inline labelPair sizes() const noexcept;
 
         //- Return const pointer to the first data element, which can also
         //- be used to address into Matrix contents
@@ -462,7 +467,7 @@ public:
         void operator=(const MatrixBlock<MatrixType>& Mb);
 
         //- Assignment of all elements to zero
-        void operator=(const Foam::zero);
+        void operator=(Foam::zero);
 
         //- Assignment of all elements to the given value
         void operator=(const Type& val);
diff --git a/src/OpenFOAM/matrices/Matrix/MatrixI.H b/src/OpenFOAM/matrices/Matrix/MatrixI.H
index ff6768b14f1..e16f30b694d 100644
--- a/src/OpenFOAM/matrices/Matrix/MatrixI.H
+++ b/src/OpenFOAM/matrices/Matrix/MatrixI.H
@@ -62,7 +62,7 @@ inline Foam::Matrix<Form, Type>::Matrix(const labelPair& dims)
 
 
 template<class Form, class Type>
-inline Foam::Matrix<Form, Type>::Matrix(const labelPair& dims, const Foam::zero)
+inline Foam::Matrix<Form, Type>::Matrix(const labelPair& dims, Foam::zero)
 :
     Matrix<Form, Type>(dims.first(), dims.second(), Foam::zero{})
 {}
@@ -88,12 +88,12 @@ Foam::Matrix<Form, Type>::clone() const
 template<class Form, class Type>
 inline Foam::label Foam::Matrix<Form, Type>::size() const noexcept
 {
-    return mRows_ * nCols_;
+    return (mRows_ * nCols_);
 }
 
 
 template<class Form, class Type>
-inline Foam::labelPair Foam::Matrix<Form, Type>::sizes() const
+inline Foam::labelPair Foam::Matrix<Form, Type>::sizes() const noexcept
 {
     return labelPair(mRows_, nCols_);
 }
diff --git a/src/OpenFOAM/matrices/MatrixBlock/MatrixBlock.H b/src/OpenFOAM/matrices/MatrixBlock/MatrixBlock.H
index e2d005f0188..51a5edfc066 100644
--- a/src/OpenFOAM/matrices/MatrixBlock/MatrixBlock.H
+++ b/src/OpenFOAM/matrices/MatrixBlock/MatrixBlock.H
@@ -83,7 +83,17 @@ class ConstMatrixBlock
 
 public:
 
-    typedef typename MatrixType::cmptType cmptType;
+    // Typedefs
+
+        //- The value type the Matrix contains
+        typedef typename MatrixType::cmptType cmptType;
+
+        //- The value type the Matrix contains
+        typedef typename MatrixType::value_type value_type;
+
+        //- The type to represent the size of a Matrix
+        typedef typename MatrixType::size_type size_type;
+
 
     // Constructors
 
@@ -101,13 +111,16 @@ public:
     // Member Functions
 
         //- Return the number of rows in the block
-        inline label m() const;
+        label m() const noexcept { return mRows_; }
 
         //- Return the number of columns in the block
-        inline label n() const;
+        label n() const noexcept { return nCols_; }
+
+        //- The number of elements in the block (m*n)
+        inline label size() const noexcept;
 
-        //- Return row/column sizes
-        inline labelPair sizes() const;
+        //- Return row/column sizes of the block
+        inline labelPair sizes() const noexcept;
 
         //- (i, j) const element access operator
         inline const cmptType& operator()
@@ -153,7 +166,16 @@ class MatrixBlock
 
 public:
 
-    typedef typename MatrixType::cmptType cmptType;
+    // Typedefs
+
+        //- The value type the Matrix contains
+        typedef typename MatrixType::cmptType cmptType;
+
+        //- The value type the Matrix contains
+        typedef typename MatrixType::value_type value_type;
+
+        //- The type to represent the size of a Matrix
+        typedef typename MatrixType::size_type size_type;
 
 
     // Generated Methods
@@ -178,13 +200,16 @@ public:
     // Member Functions
 
         //- Return the number of rows in the block
-        inline label m() const;
+        label m() const noexcept { return mRows_; }
 
         //- Return the number of columns in the block
-        inline label n() const;
+        label n() const noexcept { return nCols_; }
+
+        //- The number of elements in the block (m*n)
+        inline label size() const noexcept;
 
-        //- Return row/column sizes
-        inline labelPair sizes() const;
+        //- Return row/column sizes of the block
+        inline labelPair sizes() const noexcept;
 
         //- (i, j) const element access operator
         inline const cmptType& operator()
diff --git a/src/OpenFOAM/matrices/MatrixBlock/MatrixBlockI.H b/src/OpenFOAM/matrices/MatrixBlock/MatrixBlockI.H
index 2fc1a0b96e3..83a1c10abdf 100644
--- a/src/OpenFOAM/matrices/MatrixBlock/MatrixBlockI.H
+++ b/src/OpenFOAM/matrices/MatrixBlock/MatrixBlockI.H
@@ -87,42 +87,30 @@ Foam::MatrixBlock<MatrixType>::MatrixBlock
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class MatrixType>
-inline Foam::label Foam::ConstMatrixBlock<MatrixType>::m() const
+inline Foam::label Foam::ConstMatrixBlock<MatrixType>::size() const noexcept
 {
-    return mRows_;
+    return (mRows_ * nCols_);
 }
 
 
 template<class MatrixType>
-inline Foam::label Foam::ConstMatrixBlock<MatrixType>::n() const
+inline Foam::label Foam::MatrixBlock<MatrixType>::size() const noexcept
 {
-    return nCols_;
+    return (mRows_ * nCols_);
 }
 
 
 template<class MatrixType>
-inline Foam::label Foam::MatrixBlock<MatrixType>::m() const
-{
-    return mRows_;
-}
-
-
-template<class MatrixType>
-inline Foam::label Foam::MatrixBlock<MatrixType>::n() const
-{
-    return nCols_;
-}
-
-
-template<class MatrixType>
-inline Foam::labelPair Foam::ConstMatrixBlock<MatrixType>::sizes() const
+inline Foam::labelPair
+Foam::ConstMatrixBlock<MatrixType>::sizes() const noexcept
 {
     return labelPair(mRows_, nCols_);
 }
 
 
 template<class MatrixType>
-inline Foam::labelPair Foam::MatrixBlock<MatrixType>::sizes() const
+inline Foam::labelPair
+Foam::MatrixBlock<MatrixType>::sizes() const noexcept
 {
     return labelPair(mRows_, nCols_);
 }
diff --git a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C
index b9a80150191..abf0d664e79 100644
--- a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C
+++ b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C
@@ -42,7 +42,7 @@ Foam::label Foam::QRMatrix<MatrixType>::calcShapeFactor
     }
     else if (mode_ == modes::ECONOMY)
     {
-        return min(A.m(), A.n());
+        return Foam::min(A.m(), A.n());
     }
 
     return 0;
@@ -127,7 +127,7 @@ void Foam::QRMatrix<MatrixType>::decompose
 {
     const label n = AT.m();
     const label m = AT.n();
-    const label sz = min(m,n);
+    const label sz = Foam::min(m, n);
 
     // Initialise permutation vector, and column norm vector
     p_ = identity(n);
diff --git a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H
index 1e6a8d2a0dd..b70fc7ca669 100644
--- a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H
+++ b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H
@@ -154,6 +154,9 @@ class QRMatrix
 public:
 
     typedef typename MatrixType::cmptType cmptType;
+    typedef typename MatrixType::size_type size_type;
+    typedef typename MatrixType::value_type value_type;
+
     typedef SquareMatrix<cmptType> SMatrix;
     typedef RectangularMatrix<cmptType> RMatrix;
 
@@ -241,6 +244,13 @@ private:
         ) const;
 
 
+public:
+
+    // Generated Methods
+
+        //- No default construct
+        QRMatrix() = delete;
+
         //- No copy construct
         QRMatrix(const QRMatrix&) = delete;
 
@@ -248,13 +258,8 @@ private:
         QRMatrix& operator=(const QRMatrix&) = delete;
 
 
-public:
-
     // Constructors
 
-        //- No default construct
-        QRMatrix() = delete;
-
         //- Construct with a matrix and perform QR decomposition
         explicit QRMatrix
         (
@@ -360,6 +365,9 @@ public:
         SMatrix inv() const;
 };
 
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
 namespace MatrixTools
 {
 
diff --git a/src/OpenFOAM/matrices/QRMatrix/QRMatrixI.H b/src/OpenFOAM/matrices/QRMatrix/QRMatrixI.H
index bf61a6b4e90..32d85a15036 100644
--- a/src/OpenFOAM/matrices/QRMatrix/QRMatrixI.H
+++ b/src/OpenFOAM/matrices/QRMatrix/QRMatrixI.H
@@ -32,7 +32,7 @@ template<class MatrixType>
 inline Foam::SquareMatrix<typename MatrixType::cmptType>
 Foam::QRMatrix<MatrixType>::P() const
 {
-    SquareMatrix<cmptType> P(p_.size(), Zero);
+    SquareMatrix<cmptType> P(p_.size(), Foam::zero{});
 
     forAll(p_, jcol)
     {
diff --git a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H
index 179e5a1339c..ffe8ea74be6 100644
--- a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H
+++ b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H
@@ -87,7 +87,7 @@ public:
         (
             const label m,
             const label n,
-            const Foam::zero
+            Foam::zero
         );
 
         //- Construct given number of rows/columns
@@ -108,7 +108,7 @@ public:
 
         //- Construct given number of rows/columns by using a label pair
         //- and initializing all elements to zero
-        inline RectangularMatrix(const labelPair& dims, const Foam::zero);
+        inline RectangularMatrix(const labelPair& dims, Foam::zero);
 
         //- Construct given number of rows/columns by using a label pair
         //- and initializing all elements to the given value
@@ -138,7 +138,7 @@ public:
         inline void operator=(RectangularMatrix<Type>&& mat);
 
         //- Assign all elements to zero
-        inline void operator=(const Foam::zero);
+        inline void operator=(Foam::zero);
 
         //- Assign all elements to value
         inline void operator=(const Type& val);
diff --git a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H
index 3033c1dc4d2..b514e5d4a27 100644
--- a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H
+++ b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H
@@ -54,7 +54,7 @@ inline Foam::RectangularMatrix<Type>::RectangularMatrix
 (
     const label m,
     const label n,
-    const Foam::zero
+    Foam::zero
 )
 :
     Matrix<RectangularMatrix<Type>, Type>(m, n, Foam::zero{})
@@ -83,7 +83,9 @@ inline Foam::RectangularMatrix<Type>::RectangularMatrix
 :
     RectangularMatrix<Type>(dims.first(), dims.second(), Foam::zero{})
 {
-    for (label i = 0; i < min(dims.first(), dims.second()); ++i)
+    const label len = Foam::min(dims.first(), dims.second());
+
+    for (label i = 0; i < len; ++i)
     {
         this->operator()(i, i) = pTraits<Type>::one;
     }
@@ -104,7 +106,7 @@ template<class Type>
 inline Foam::RectangularMatrix<Type>::RectangularMatrix
 (
     const labelPair& dims,
-    const Foam::zero
+    Foam::zero
 )
 :
     RectangularMatrix<Type>(dims.first(), dims.second(), Foam::zero{})
@@ -182,7 +184,7 @@ inline void Foam::RectangularMatrix<Type>::operator=
 
 
 template<class Type>
-inline void Foam::RectangularMatrix<Type>::operator=(const Foam::zero)
+inline void Foam::RectangularMatrix<Type>::operator=(Foam::zero)
 {
     Matrix<RectangularMatrix<Type>, Type>::operator=(Foam::zero{});
 }
diff --git a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H
index 8ccaeed3419..0ef3cd52a11 100644
--- a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H
+++ b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H
@@ -55,7 +55,6 @@ namespace Foam
 // Forward Declarations
 template<class Type> class RectangularMatrix;
 
-
 /*---------------------------------------------------------------------------*\
                         Class SquareMatrix Declaration
 \*---------------------------------------------------------------------------*/
@@ -86,7 +85,7 @@ public:
 
         //- Construct for given size (rows == cols)
         //- initializing all elements to zero
-        inline SquareMatrix(const label n, const Foam::zero);
+        inline SquareMatrix(const label n, Foam::zero);
 
         //- Construct for given size (rows == cols)
         //- initializing all elements to the given value
@@ -111,7 +110,7 @@ public:
         //- by using a labelPair (checked to be equal)
         //- and initializing all elements to zero
         //  For constructor consistency with rectangular matrices
-        inline SquareMatrix(const labelPair& dims, const Foam::zero);
+        inline SquareMatrix(const labelPair& dims, Foam::zero);
 
         //- Construct given number of rows/columns
         //- by using a labelPair (checked to be equal)
@@ -121,7 +120,7 @@ public:
 
         //- Construct given number of rows/columns (checked to be equal)
         //- initializing all elements to zero
-        inline SquareMatrix(const label m, const label n, const Foam::zero);
+        inline SquareMatrix(const label m, const label n, Foam::zero);
 
         //- Construct from const sub-matrix block
         template<class MatrixType>
@@ -186,7 +185,7 @@ public:
         inline void operator=(SquareMatrix<Type>&& mat);
 
         //- Assign all elements to zero
-        inline void operator=(const Foam::zero);
+        inline void operator=(Foam::zero);
 
         //- Assign all elements to value
         inline void operator=(const Type& val);
diff --git a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H
index 28c8b15742a..8004330e98d 100644
--- a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H
+++ b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H
@@ -48,7 +48,7 @@ template<class Type>
 inline Foam::SquareMatrix<Type>::SquareMatrix
 (
     const label n,
-    const Foam::zero
+    Foam::zero
 )
 :
     Matrix<SquareMatrix<Type>, Type>(n, n, Foam::zero{})
@@ -118,7 +118,7 @@ template<class Type>
 inline Foam::SquareMatrix<Type>::SquareMatrix
 (
     const labelPair& dims,
-    const Foam::zero
+    Foam::zero
 )
 :
     Matrix<SquareMatrix<Type>, Type>(dims, Foam::zero{})
@@ -145,7 +145,7 @@ inline Foam::SquareMatrix<Type>::SquareMatrix
 (
     const label m,
     const label n,
-    const Foam::zero
+    Foam::zero
 )
 :
     Matrix<SquareMatrix<Type>, Type>(m, n, Foam::zero{})
@@ -305,7 +305,7 @@ inline void Foam::SquareMatrix<Type>::operator=(SquareMatrix<Type>&& mat)
 
 
 template<class Type>
-inline void Foam::SquareMatrix<Type>::operator=(const Foam::zero)
+inline void Foam::SquareMatrix<Type>::operator=(Foam::zero)
 {
     Matrix<SquareMatrix<Type>, Type>::operator=(Foam::zero{});
 }
diff --git a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.C b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.C
index be0457bfbf1..bf46edeb8a0 100644
--- a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.C
+++ b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.C
@@ -38,7 +38,7 @@ Foam::SymmetricSquareMatrix<Type> Foam::invDecomposed
 {
     const label n = matrix.n();
 
-    SymmetricSquareMatrix<Type> inv(n, Zero);
+    SymmetricSquareMatrix<Type> inv(n, Foam::zero{});
 
     for (label i = 0; i < n; ++i)
     {
@@ -57,7 +57,7 @@ Foam::SymmetricSquareMatrix<Type> Foam::invDecomposed
         }
     }
 
-    SymmetricSquareMatrix<Type> result(n, Zero);
+    SymmetricSquareMatrix<Type> result(n, Foam::zero{});
 
     for (label k = 0; k < n; ++k)
     {
diff --git a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.H b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.H
index 4475f12d49c..84924e5aca1 100644
--- a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.H
+++ b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrix.H
@@ -81,7 +81,7 @@ public:
 
         //- Construct for given size (rows == cols)
         //- initializing all elements to zero
-        inline SymmetricSquareMatrix(const label n, const Foam::zero);
+        inline SymmetricSquareMatrix(const label n, Foam::zero);
 
         //- Construct for given size (rows == cols)
         //- initializing all elements to the given value
@@ -102,7 +102,7 @@ public:
     // Member Operators
 
         //- Assign all elements to zero
-        inline void operator=(const Foam::zero);
+        inline void operator=(Foam::zero);
 
         //- Assign all elements to value
         inline void operator=(const Type& val);
diff --git a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrixI.H b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrixI.H
index 008db20346c..3e14354cf44 100644
--- a/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrixI.H
+++ b/src/OpenFOAM/matrices/SymmetricSquareMatrix/SymmetricSquareMatrixI.H
@@ -48,7 +48,7 @@ template<class Type>
 inline Foam::SymmetricSquareMatrix<Type>::SymmetricSquareMatrix
 (
     const label n,
-    const Foam::zero
+    Foam::zero
 )
 :
     Matrix<SymmetricSquareMatrix<Type>, Type>(n, n, Foam::zero{})
@@ -103,7 +103,7 @@ Foam::SymmetricSquareMatrix<Type>::clone() const
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
 template<class Type>
-inline void Foam::SymmetricSquareMatrix<Type>::operator=(const Foam::zero)
+inline void Foam::SymmetricSquareMatrix<Type>::operator=(Foam::zero)
 {
     Matrix<SymmetricSquareMatrix<Type>, Type>::operator=(Foam::zero{});
 }
diff --git a/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C b/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C
index 693a33ff015..d5e1075bbde 100644
--- a/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C
+++ b/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -51,6 +51,14 @@ Foam::simpleMatrix<Type>::simpleMatrix
 {}
 
 
+template<class Type>
+Foam::simpleMatrix<Type>::simpleMatrix(const label n, Foam::zero)
+:
+    scalarSquareMatrix(n, Foam::zero{}),
+    source_(n, Foam::zero{})
+{}
+
+
 template<class Type>
 Foam::simpleMatrix<Type>::simpleMatrix
 (
diff --git a/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.H b/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.H
index f68304397c2..460e2c941cc 100644
--- a/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.H
+++ b/src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -34,8 +35,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef simpleMatrix_H
-#define simpleMatrix_H
+#ifndef Foam_simpleMatrix_H
+#define Foam_simpleMatrix_H
 
 #include "scalarMatrices.H"
 
@@ -44,18 +45,9 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declaration of friend functions and operators
-
-template<class Type>
-class simpleMatrix;
-
-template<class Type>
-Ostream& operator<<
-(
-    Ostream&,
-    const simpleMatrix<Type>&
-);
-
+// Forward Declarations
+template<class Type> class simpleMatrix;
+template<class Type> Ostream& operator<<(Ostream&, const simpleMatrix<Type>&);
 
 /*---------------------------------------------------------------------------*\
                            Class simpleMatrix Declaration
@@ -66,60 +58,55 @@ class simpleMatrix
 :
     public scalarSquareMatrix
 {
-    // Private data
+    // Private Data
 
         Field<Type> source_;
 
-
 public:
 
     // Constructors
 
         //- Construct given size
         //  Note: this does not initialise the coefficients or the source.
-        simpleMatrix(const label);
+        explicit simpleMatrix(const label n);
 
         //- Construct given size and initial values for coefficients and source
-        simpleMatrix(const label, const scalar, const Type&);
+        simpleMatrix(const label n, const scalar, const Type&);
+
+        //- Construct given size, zero values for coefficients and source
+        simpleMatrix(const label n, Foam::zero);
 
         //- Construct from components
         simpleMatrix(const scalarSquareMatrix&, const Field<Type>&);
 
-        //- Construct from Istream
-        simpleMatrix(Istream&);
+        //- Copy construct
+        simpleMatrix(const simpleMatrix<Type>&) = default;
 
-        //- Construct as copy
-        simpleMatrix(const simpleMatrix<Type>&);
+        //- Construct from Istream
+        explicit simpleMatrix(Istream&);
 
 
     // Member Functions
 
-        // Access
+        //- Return access to the source
+        Field<Type>& source() noexcept { return source_; }
 
-            //- Return access to the source
-            Field<Type>& source()
-            {
-                return source_;
-            }
-
-            //- Return const-access to the source
-            const Field<Type>& source() const
-            {
-                return source_;
-            }
+        //- Return const-access to the source
+        const Field<Type>& source() const noexcept { return source_; }
 
 
         //- Solve the matrix using Gaussian elimination with pivoting
-        //  and return the solution
+        //- and return the solution
         Field<Type> solve() const;
 
         //- Solve the matrix using LU decomposition with pivoting
-        //  and return the solution
+        //- and return the solution
         Field<Type> LUsolve() const;
 
 
     // Member Operators
 
+        //- Copy assignment
         void operator=(const simpleMatrix<Type>&);
 
 
@@ -133,7 +120,9 @@ public:
 };
 
 
-// Global operators
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// Global Operators
 
 template<class Type>
 simpleMatrix<Type> operator+
diff --git a/src/OpenFOAM/meshes/ijkMesh/IjkField.H b/src/OpenFOAM/meshes/ijkMesh/IjkField.H
index 26a2ca348dd..f7e0b284495 100644
--- a/src/OpenFOAM/meshes/ijkMesh/IjkField.H
+++ b/src/OpenFOAM/meshes/ijkMesh/IjkField.H
@@ -35,8 +35,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef IjkField_H
-#define IjkField_H
+#ifndef Foam_IjkField_H
+#define Foam_IjkField_H
 
 #include "ijkAddressing.H"
 #include "Field.H"
@@ -95,22 +95,22 @@ public:
     // Access
 
         //- Return i,j,k addressing
-        inline const ijkAddressing& ijk() const;
+        const ijkAddressing& ijk() const noexcept { return ijk_; }
 
         //- Return i,j,k addressing for modification
-        inline ijkAddressing& ijk();
+        ijkAddressing& ijk() noexcept { return ijk_; }
 
         //- Return i,j,k addressing sizes
-        inline const labelVector& sizes() const;
+        const labelVector& sizes() const noexcept { return ijk_.sizes(); }
 
         //- Return i,j,k addressing sizes for modification
-        inline labelVector& sizes();
+        labelVector& sizes() noexcept { return ijk_.sizes(); }
 
         //- The field size
         using Field<Type>::size;
 
         //- The addressing dimension in the given direction
-        inline const label& size(const vector::components cmpt) const;
+        inline label size(const vector::components cmpt) const;
 
 
     // Edit
@@ -161,7 +161,7 @@ public:
 
         //- Value assignment
         inline void operator=(const Type& val);
-        inline void operator=(const Foam::zero);
+        inline void operator=(Foam::zero);
 
 };
 
diff --git a/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H b/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H
index 67a6fcc5d4d..45c9afade78 100644
--- a/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H
+++ b/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H
@@ -132,35 +132,7 @@ inline Foam::IjkField<Type>::IjkField
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 template<class Type>
-inline const Foam::ijkAddressing& Foam::IjkField<Type>::ijk() const
-{
-    return ijk_;
-}
-
-
-template<class Type>
-inline Foam::ijkAddressing& Foam::IjkField<Type>::ijk()
-{
-    return ijk_;
-}
-
-
-template<class Type>
-inline const Foam::labelVector& Foam::IjkField<Type>::sizes() const
-{
-    return ijk_.sizes();
-}
-
-
-template<class Type>
-inline Foam::labelVector& Foam::IjkField<Type>::sizes()
-{
-    return ijk_.sizes();
-}
-
-
-template<class Type>
-inline const Foam::label& Foam::IjkField<Type>::size
+inline Foam::label Foam::IjkField<Type>::size
 (
     const vector::components cmpt
 ) const
@@ -245,7 +217,7 @@ inline void Foam::IjkField<Type>::operator=(const Type& val)
 
 
 template<class Type>
-inline void Foam::IjkField<Type>::operator=(const Foam::zero)
+inline void Foam::IjkField<Type>::operator=(Foam::zero)
 {
     Field<Type>::operator=(Foam::zero{});
 }
diff --git a/src/OpenFOAM/meshes/ijkMesh/ijkAddressing.H b/src/OpenFOAM/meshes/ijkMesh/ijkAddressing.H
index 1409d3b967d..cc221f3acfc 100644
--- a/src/OpenFOAM/meshes/ijkMesh/ijkAddressing.H
+++ b/src/OpenFOAM/meshes/ijkMesh/ijkAddressing.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -76,19 +76,19 @@ public:
     // Access
 
         //- Addressing is considered empty if any component is zero
-        inline bool empty() const;
+        inline bool empty() const noexcept;
 
         //- The (i,j,k) addressing dimensions
-        inline const labelVector& sizes() const;
+        const labelVector& sizes() const noexcept { return sizes_; }
 
         //- Return the (i,j,k) dimensions for modification
-        inline labelVector& sizes();
+        labelVector& sizes() noexcept { return sizes_; }
 
         //- Return the total i*j*k size
-        inline label size() const;
+        inline label size() const noexcept;
 
         //- The addressing dimension in the given direction
-        inline const label& size(const vector::components cmpt) const;
+        inline label size(const vector::components cmpt) const;
 
         //- Reset to (0,0,0) sizing
         inline void clear();
diff --git a/src/OpenFOAM/meshes/ijkMesh/ijkAddressingI.H b/src/OpenFOAM/meshes/ijkMesh/ijkAddressingI.H
index 5f238e3584e..28685cdefdc 100644
--- a/src/OpenFOAM/meshes/ijkMesh/ijkAddressingI.H
+++ b/src/OpenFOAM/meshes/ijkMesh/ijkAddressingI.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -60,32 +60,20 @@ inline Foam::ijkAddressing::ijkAddressing
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-inline bool Foam::ijkAddressing::empty() const
+inline bool Foam::ijkAddressing::empty() const noexcept
 {
     return (!sizes_.x() || !sizes_.y() || !sizes_.z());
 }
 
 
-inline const Foam::labelVector& Foam::ijkAddressing::sizes() const
-{
-    return sizes_;
-}
-
-
-inline Foam::labelVector& Foam::ijkAddressing::sizes()
-{
-    return sizes_;
-}
-
-
-inline Foam::label Foam::ijkAddressing::size() const
+inline Foam::label Foam::ijkAddressing::size() const noexcept
 {
     // Could also use cmptProduct(sizes_);
     return (sizes_.x() * sizes_.y() * sizes_.z());
 }
 
 
-inline const Foam::label& Foam::ijkAddressing::size
+inline Foam::label Foam::ijkAddressing::size
 (
     const vector::components cmpt
 ) const
@@ -96,7 +84,7 @@ inline const Foam::label& Foam::ijkAddressing::size
 
 inline void Foam::ijkAddressing::clear()
 {
-    sizes_ = Zero;
+    sizes_ = Foam::zero{};
 }
 
 
diff --git a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H
index 2e62323e78c..da045df4894 100644
--- a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H
+++ b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2016 OpenFOAM Foundation
-    Copyright (C) 2019-2022 OpenCFD Ltd.
+    Copyright (C) 2019-2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -77,16 +77,10 @@ public:
     // Static Member Functions
 
         //- The number of rows
-        static direction m() noexcept
-        {
-            return Mrows;
-        }
+        static direction m() noexcept { return Mrows; }
 
         //- The number of columns
-        static direction n() noexcept
-        {
-            return Ncols;
-        }
+        static direction n() noexcept { return Ncols; }
 
         //- An identity matrix for square matrix-spaces
         inline static msType identity();
@@ -107,16 +101,10 @@ public:
             static const direction nCols = SubTensor::nCols;
 
             //- Return the number of rows in the block
-            static direction m()
-            {
-                return mRows;
-            }
+            static direction m() noexcept { return mRows; }
 
             //- Return the number of columns in the block
-            static direction n()
-            {
-                return nCols;
-            }
+            static direction n() noexcept { return nCols; }
 
             //- Construct for the given matrix
             inline ConstBlock(const msType& matrix);
@@ -151,16 +139,10 @@ public:
             static const direction nCols = SubTensor::nCols;
 
             //- The number of rows in the block
-            static direction m()
-            {
-                return mRows;
-            }
+            static direction m() noexcept { return mRows; }
 
             //- The number of columns in the block
-            static direction n()
-            {
-                return nCols;
-            }
+            static direction n() noexcept { return nCols; }
 
             //- Construct for the given matrix
             inline Block(msType& matrix);
@@ -209,7 +191,7 @@ public:
     // Constructors
 
         //- Construct initialized to zero
-        inline MatrixSpace(const Foam::zero);
+        inline MatrixSpace(Foam::zero);
 
         //- Construct as copy of a VectorSpace with the same size
         template<class Form2, class Cmpt2>
@@ -289,18 +271,18 @@ public:
         //- (i, j) const element access operator
         inline const Cmpt& operator()
         (
-            const direction& i,
-            const direction& j
+            const direction i,
+            const direction j
         ) const;
 
         //- (i, j) element access operator
-        inline Cmpt& operator()(const direction& i, const direction& j);
+        inline Cmpt& operator()(const direction i, const direction j);
 
 
     // Member Operators
 
         //- Assignment to zero
-        inline void operator=(const Foam::zero);
+        inline void operator=(Foam::zero);
 
         //- Assignment to a block of another matrix space
         template
diff --git a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
index f9061dd9bf6..f1698368ed2 100644
--- a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
+++ b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
@@ -32,10 +32,10 @@ License
 template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
 inline Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::MatrixSpace
 (
-    const Foam::zero
+    Foam::zero
 )
 :
-    MatrixSpace::vsType(Zero)
+    MatrixSpace::vsType(Foam::zero{})
 {}
 
 
@@ -213,8 +213,8 @@ Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::block()
 template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
 inline const Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::operator()
 (
-    const direction& i,
-    const direction& j
+    const direction i,
+    const direction j
 ) const
 {
     #ifdef FULLDEBUG
@@ -233,8 +233,8 @@ inline const Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::operator()
 template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
 inline Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::operator()
 (
-    const direction& i,
-    const direction& j
+    const direction i,
+    const direction j
 )
 {
     #ifdef FULLDEBUG
@@ -318,10 +318,10 @@ operator()(const direction i, const direction j)
 template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
 inline void Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::operator=
 (
-    const Foam::zero
+    Foam::zero
 )
 {
-    MatrixSpace::vsType::operator=(Zero);
+    MatrixSpace::vsType::operator=(Foam::zero{});
 }
 
 
diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H
index c3f7163c4b7..d9035c7250d 100644
--- a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H
+++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H
@@ -92,6 +92,9 @@ public:
     //- Magnitude type
     typedef Cmpt magType;
 
+    //- The type to represent the size of a VectorSpace
+    typedef direction size_type;
+
 
     // Static Constants
 
diff --git a/src/functionObjects/field/DMD/DMDModels/derived/STDMD/STDMD.C b/src/functionObjects/field/DMD/DMDModels/derived/STDMD/STDMD.C
index 5f503d8646f..094a93d64d2 100644
--- a/src/functionObjects/field/DMD/DMDModels/derived/STDMD/STDMD.C
+++ b/src/functionObjects/field/DMD/DMDModels/derived/STDMD/STDMD.C
@@ -173,8 +173,8 @@ void Foam::DMDModels::STDMD::compress()
         DiagonalMatrix<scalar> EVals(EM.EValsRe());
 
         // Sort eigenvalues in descending order, and track indices
-        const auto descend = [&](scalar a, scalar b){ return a > b; };
-        const List<label> permutation(EVals.sortPermutation(descend));
+        const auto descend = [](scalar a, scalar b){ return a > b; };
+        const labelList permutation(EVals.sortPermutation(descend));
         EVals.applyPermutation(permutation);
         EVals.resize(EVals.size() - 1);
 
-- 
GitLab