Commit 2bdcd5b8 authored by Kutalmis Bercin's avatar Kutalmis Bercin Committed by Andrew Heather
Browse files

STYLE: prefix indexing, loop spacing in Matrix types

parent 46bc8082
......@@ -53,9 +53,9 @@ void Foam::LLTMatrix<Type>::decompose(const SquareMatrix<Type>& mat)
const label m = LLT.m();
for (label i=0; i<m; ++i)
for (label i = 0; i < m; ++i)
{
for (label j=0; j<m; ++j)
for (label j = 0; j < m; ++j)
{
if (j > i)
{
......@@ -65,7 +65,7 @@ void Foam::LLTMatrix<Type>::decompose(const SquareMatrix<Type>& mat)
Type sum = LLT(i, j);
for (label k=0; k<j; ++k)
for (label k = 0; k < j; ++k)
{
sum -= LLT(i, k)*LLT(j, k);
}
......@@ -106,11 +106,11 @@ void Foam::LLTMatrix<Type>::solve
const SquareMatrix<Type>& LLT = *this;
const label m = LLT.m();
for (label i=0; i<m; ++i)
for (label i = 0; i < m; ++i)
{
Type sum = source[i];
for (label j=0; j<i; ++j)
for (label j = 0; j < i; ++j)
{
sum = sum - LLT(i, j)*x[j];
}
......@@ -118,11 +118,11 @@ void Foam::LLTMatrix<Type>::solve
x[i] = sum/LLT(i, i);
}
for (label i=m - 1; i >= 0; --i)
for (label i = m - 1; i >= 0; --i)
{
Type sum = x[i];
for (label j=i + 1; j<m; ++j)
for (label j = i + 1; j < m; ++j)
{
sum = sum - LLT(j, i)*x[j];
}
......
......@@ -205,9 +205,9 @@ inline Foam::Matrix<Form, Type>::Matrix
{
doAlloc();
for (label i=0; i < mRows_; ++i)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j < nCols_; ++j)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = Mb(i,j);
}
......@@ -227,9 +227,9 @@ inline Foam::Matrix<Form, Type>::Matrix
{
doAlloc();
for (label i=0; i < mRows_; ++i)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j<nCols_; ++j)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = Mb(i, j);
}
......@@ -322,9 +322,9 @@ void Foam::Matrix<Form, Type>::resize(const label m, const label n)
const label mrow = min(m, mRows_);
const label ncol = min(n, nCols_);
for (label i=0; i < mrow; ++i)
for (label i = 0; i < mrow; ++i)
{
for (label j=0; j < ncol; ++j)
for (label j = 0; j < ncol; ++j)
{
newMatrix(i, j) = (*this)(i, j);
}
......@@ -339,9 +339,9 @@ Form Foam::Matrix<Form, Type>::T() const
{
Form At(n(), m());
for (label i=0; i < m(); ++i)
for (label i = 0; i < m(); ++i)
{
for (label j=0; j < n(); ++j)
for (label j = 0; j < n(); ++j)
{
At(j, i) = (*this)(i, j);
}
......@@ -399,9 +399,9 @@ void Foam::Matrix<Form, Type>::operator=
const ConstMatrixBlock<MatrixType>& Mb
)
{
for (label i=0; i < mRows_; ++i)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j < nCols_; ++j)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = Mb(i, j);
}
......@@ -464,7 +464,7 @@ void Foam::Matrix<Form, Type>::operator+=(const Matrix<Form, Type>& other)
const label len = this->size();
for (label idx=0; idx < len; ++idx)
for (label idx = 0; idx < len; ++idx)
{
out[idx] += in[idx];
}
......@@ -603,7 +603,7 @@ Form Foam::operator+(const Matrix<Form, Type>& A, const Matrix<Form, Type>& B)
const label len = A.size();
for (label idx=0; idx < len; ++idx)
for (label idx = 0; idx < len; ++idx)
{
ABv[idx] = Av[idx] + Bv[idx];
}
......@@ -653,7 +653,7 @@ Form Foam::operator*(const scalar s, const Matrix<Form, Type>& mat)
Type* out = result.data();
const Type* in = mat.cdata();
for (label idx=0; idx < len; ++idx)
for (label idx = 0; idx < len; ++idx)
{
out[idx] = s * in[idx];
}
......
......@@ -160,7 +160,7 @@ inline bool Foam::Matrix<Form, Type>::uniform() const
return false;
}
for (label idx=1; idx<len; ++idx)
for (label idx = 1; idx < len; ++idx)
{
if (v_[0] != v_[idx])
{
......
......@@ -80,11 +80,11 @@ bool Foam::Matrix<Form, Type>::readMatrix(Istream& is)
label idx = 0;
// Loop over rows
for (label i=0; i < mRows_; ++i)
for (label i = 0; i < mRows_; ++i)
{
listDelimiter = is.readBeginList("MatrixRow");
for (label j=0; j < nCols_; ++j)
for (label j = 0; j < nCols_; ++j)
{
is >> v_[idx++];
......@@ -167,12 +167,12 @@ Foam::Ostream& Foam::Matrix<Form, Type>::writeMatrix
label idx = 0;
// Loop over rows
for (label i=0; i < mat.m(); ++i)
for (label i = 0; i < mat.m(); ++i)
{
os << token::BEGIN_LIST;
// Write row
for (label j=0; j < mat.n(); ++j)
for (label j = 0; j < mat.n(); ++j)
{
if (j) os << token::SPACE;
os << v[idx++];
......
......@@ -89,9 +89,9 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (label i=0; i<mRows_; i++)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j<nCols_; j++)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = Mb(i, j);
}
......@@ -116,9 +116,9 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (label i=0; i<mRows_; i++)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j<nCols_; j++)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = Mb(i, j);
}
......@@ -144,9 +144,9 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (label i=0; i<mRows_; i++)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j<nCols_; j++)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = Mb(i, j);
}
......@@ -173,9 +173,9 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (label i=0; i<mRows_; i++)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j<nCols_; j++)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = Mb(i, j);
}
......@@ -202,9 +202,9 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (label i=0; i<mRows_; i++)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j<nCols_; j++)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = Mb(i, j);
}
......@@ -235,9 +235,9 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (direction i=0; i<mRows_; ++i)
for (direction i = 0; i < mRows_; ++i)
{
for (direction j=0; j<nCols_; ++j)
for (direction j = 0; j < nCols_; ++j)
{
operator()(i, j) = Mb(i, j);
}
......@@ -266,7 +266,7 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (direction i=0; i<mRows_; ++i)
for (direction i = 0; i < mRows_; ++i)
{
operator()(i, 0) = Mb[i];
}
......@@ -289,9 +289,9 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (label i=0; i<mRows_; i++)
for (label i = 0; i < mRows_; ++i)
{
for (label j=0; j<nCols_; j++)
for (label j = 0; j < nCols_; ++j)
{
(*this)(i, j) = ms(i, j);
}
......@@ -315,7 +315,7 @@ void Foam::MatrixBlock<MatrixType>::operator=
<< abort(FatalError);
}
for (direction i=0; i<Ncmpts; ++i)
for (direction i = 0; i < Ncmpts; ++i)
{
operator()(i, 0) = ms[i];
}
......
......@@ -166,11 +166,11 @@ void Foam::QRMatrix<MatrixType>::solvex
{
const label n = R_.n();
for (int i=n-1; i>=0; i--)
for (label i = n - 1; i >= 0; --i)
{
cmptType sum = x[i];
for (label j=i+1; j<n; j++)
for (label j = i + 1; j < n; ++j)
{
sum -= x[j]*R_(i, j);
}
......@@ -197,11 +197,11 @@ void Foam::QRMatrix<MatrixType>::solve
// Assert (&x != &source) ?
const label m = Q_.m();
// x = Q_.T()*source;
for (label i=0; i<m; i++)
// x = Q_.T()*source; ie, Q_.Tmul(source)
for (label i = 0; i < m; ++i)
{
x[i] = 0;
for (label j=0; j<m; j++)
for (label j = 0; j < m; ++j)
{
x[i] += Q_(j, i)*source[j];
}
......@@ -235,9 +235,9 @@ Foam::QRMatrix<MatrixType>::inv() const
Field<cmptType> x(m);
QMatrixType inv(m);
for (label i=0; i<m; i++)
for (label i = 0; i < m; ++i)
{
for (label j=0; j<m; j++)
for (label j = 0; j < m; ++j)
{
x[j] = Q_(i, j);
}
......
......@@ -39,15 +39,15 @@ Foam::SymmetricSquareMatrix<Type> Foam::invDecomposed
SymmetricSquareMatrix<Type> inv(n, Zero);
for (label i=0; i<n; i++)
for (label i = 0; i < n; ++i)
{
inv(i, i) = 1.0/matrix(i, i);
for (label j=0; j<i; j++)
for (label j = 0; j < i; ++j)
{
Type sum = Zero;
for (label k=j; k<i; k++)
for (label k = j; k < i; ++k)
{
sum -= matrix(i, k)*inv(k, j);
}
......@@ -58,11 +58,11 @@ Foam::SymmetricSquareMatrix<Type> Foam::invDecomposed
SymmetricSquareMatrix<Type> result(n, Zero);
for (label k=0; k<n; k++)
for (label k = 0; k < n; ++k)
{
for (label i=0; i <= k; i++)
for (label i = 0; i <= k; ++i)
{
for (label j=0; j <= k; j++)
for (label j = 0; j <= k; ++j)
{
result(i, j) += inv(k, i)*inv(k, j);
}
......@@ -91,7 +91,7 @@ Type Foam::detDecomposed(const SymmetricSquareMatrix<Type>& matrix)
{
Type diagProduct = pTraits<Type>::one;
for (label i=0; i<matrix.m(); i++)
for (label i = 0; i < matrix.m(); ++i)
{
diagProduct *= matrix(i, i);
}
......
......@@ -52,13 +52,13 @@ void Foam::LUDecompose
scalar vv[m];
sign = 1;
for (label i=0; i<m; i++)
for (label i = 0; i < m; ++i)
{
scalar largestCoeff = 0.0;
scalar temp;
const scalar* __restrict__ matrixi = matrix[i];
for (label j=0; j<m; j++)
for (label j = 0; j < m; ++j)
{
if ((temp = mag(matrixi[j])) > largestCoeff)
{
......@@ -75,16 +75,16 @@ void Foam::LUDecompose
vv[i] = 1.0/largestCoeff;
}
for (label j=0; j<m; j++)
for (label j = 0; j < m; ++j)
{
scalar* __restrict__ matrixj = matrix[j];
for (label i=0; i<j; i++)
for (label i = 0; i < j; ++i)
{
scalar* __restrict__ matrixi = matrix[i];
scalar sum = matrixi[j];
for (label k=0; k<i; k++)
for (label k = 0; k < i; ++k)
{
sum -= matrixi[k]*matrix(k, j);
}
......@@ -94,12 +94,12 @@ void Foam::LUDecompose
label iMax = 0;
scalar largestCoeff = 0.0;
for (label i=j; i<m; i++)
for (label i = j; i < m; ++i)
{
scalar* __restrict__ matrixi = matrix[i];
scalar sum = matrixi[j];
for (label k=0; k<j; k++)
for (label k = 0; k < j; ++k)
{
sum -= matrixi[k]*matrix(k, j);
}
......@@ -120,7 +120,7 @@ void Foam::LUDecompose
{
scalar* __restrict__ matrixiMax = matrix[iMax];
for (label k=0; k<m; k++)
for (label k = 0; k < m; ++k)
{
Swap(matrixj[k], matrixiMax[k]);
}
......@@ -138,7 +138,7 @@ void Foam::LUDecompose
{
scalar rDiag = 1.0/matrixj[j];
for (label i=j+1; i<m; i++)
for (label i = j + 1; i < m; ++i)
{
matrix(i, j) *= rDiag;
}
......@@ -153,23 +153,23 @@ void Foam::LUDecompose(scalarSymmetricSquareMatrix& matrix)
label size = matrix.m();
// Set upper triangular parts to zero.
for (label j=0; j<size; j++)
for (label j = 0; j < size; ++j)
{
for (label k=j + 1; k<size; k++)
for (label k = j + 1; k < size; ++k)
{
matrix(j, k) = 0.0;
}
}
for (label j=0; j<size; j++)
for (label j = 0; j < size; ++j)
{
scalar d = 0.0;
for (label k=0; k<j; k++)
for (label k = 0; k < j; ++k)
{
scalar s = 0.0;
for (label i=0; i<k; i++)
for (label i = 0; i < k; ++i)
{
s += matrix(i, k)*matrix(i, j);
}
......@@ -225,14 +225,14 @@ void Foam::multiply
ans = scalarRectangularMatrix(A.m(), C.n(), Zero);
for (label i=0; i<A.m(); i++)
for (label i = 0; i < A.m(); ++i)
{
for (label g = 0; g < C.n(); g++)
for (label g = 0; g < C.n(); ++g)
{
for (label l=0; l<C.m(); l++)
for (label l = 0; l < C.m(); ++l)
{
scalar ab = 0;
for (label j=0; j<A.n(); j++)
for (label j = 0; j < A.n(); ++j)
{
ab += A(i, j)*B(j, l);
}
......@@ -269,11 +269,11 @@ void Foam::multiply
ans = scalarRectangularMatrix(A.m(), C.n(), Zero);
for (label i=0; i<A.m(); i++)
for (label i = 0; i < A.m(); ++i)
{
for (label g=0; g<C.n(); g++)
for (label g = 0; g < C.n(); ++g)
{
for (label l=0; l<C.m(); l++)
for (label l = 0; l < C.m(); ++l)
{
ans(i, g) += C(l, g) * A(i, l)*B[l];
}
......@@ -310,11 +310,11 @@ void Foam::multiply
ans = scalarSquareMatrix(size, Zero);
for (label i=0; i<size; i++)
for (label i = 0; i < size; ++i)
{
for (label g=0; g<size; g++)
for (label g = 0; g < size; ++g)
{
for (label l=0; l<size; l++)
for (label l = 0; l < size; ++l)
{
ans(i, g) += C(l, g)*A(i, l)*B[l];
}
......
......@@ -41,13 +41,13 @@ void Foam::solve
label m = tmpMatrix.m();
// Elimination
for (label i=0; i<m; i++)
for (label i = 0; i < m; ++i)
{
label iMax = i;
scalar largestCoeff = mag(tmpMatrix(iMax, i));
// Swap elements around to find a good pivot
for (label j=i+1; j<m; j++)
for (label j = i + 1; j < m; ++j)
{
if (mag(tmpMatrix(j, i)) > largestCoeff)
{
......@@ -58,7 +58,7 @@ void Foam::solve
if (i != iMax)
{
for (label k=i; k<m; k++)
for (label k = i; k < m; ++k)
{
Swap(tmpMatrix(i, k), tmpMatrix(iMax, k));
}
......@@ -74,11 +74,11 @@ void Foam::solve
}
// Reduce to upper triangular form
for (label j=i+1; j<m; j++)
for (label j = i + 1; j < m; ++j)
{
sourceSol[j] -= sourceSol[i]*(tmpMatrix(j, i)/tmpMatrix(i, i));
for (label k=m-1; k>=i; k--)
for (label k = m - 1; k >= i; --k)
{
tmpMatrix(j, k) -=
tmpMatrix(i, k)*tmpMatrix(j, i)/tmpMatrix(i, i);
......@@ -87,11 +87,11 @@ void Foam::solve
}
// Back-substitution
for (label j=m-1; j>=0; j--)
for (label j = m - 1; j >= 0; --j)
{
Type ntempvec = Zero;
for (label k=j+1; k<m; k++)
for (label k = j + 1; k < m; ++k)
{
ntempvec += tmpMatrix(j, k)*sourceSol[k];
}
......@@ -127,7 +127,7 @@ void Foam::LUBacksubstitute
label ii = 0;
for (label i=0; i<m; i++)
for (label i = 0; i < m; ++i)
{
label ip = pivotIndices[i];
Type sum = sourceSol[ip];
......@@ -136,25 +136,25 @@ void Foam::LUBacksubstitute
if (ii != 0)
{
for (label j=ii-1; j<i; j++)
for (label j = ii - 1; j < i; ++j)
{
sum -= luMatrixi[j]*sourceSol[j];
}
}
else if (sum != Type(Zero))
{
ii = i+1;
ii = i + 1;
}
sourceSol[i] = sum;
}
for (label i=m-1; i>=0; i--)
for (label i = m - 1; i >= 0; --i)
{