55 scalar largestCoeff = 0.0;
57 const scalar* __restrict__ matrixi = matrix[i];
61 if ((temp =
mag(matrixi[j])) > largestCoeff)
67 if (largestCoeff == 0.0)
72 "(scalarSquareMatrix& matrix, labelList& rowIndices)" 76 vv[i] = 1.0/largestCoeff;
81 scalar* __restrict__ matrixj = matrix[j];
83 for (
label i=0; i<j; i++)
85 scalar* __restrict__ matrixi = matrix[i];
87 scalar
sum = matrixi[j];
90 sum -= matrixi[
k]*matrix[
k][j];
97 scalar largestCoeff = 0.0;
100 scalar* __restrict__ matrixi = matrix[i];
101 scalar
sum = matrixi[j];
105 sum -= matrixi[
k]*matrix[
k][j];
111 if ((temp = vv[i]*
mag(sum)) >= largestCoeff)
118 pivotIndices[j] = iMax;
122 scalar* __restrict__ matrixiMax = matrix[iMax];
126 Swap(matrixj[
k], matrixiMax[k]);
133 if (matrixj[j] == 0.0)
140 scalar rDiag = 1.0/matrixj[j];
142 for (
label i=j+1; i<
n; i++)
144 matrix[i][j] *= rDiag;
157 for (
label j = 0; j < size; j++)
159 for (
label k = j + 1;
k < size;
k++)
165 for (
label j = 0; j < size; j++)
173 for (
label i = 0; i <
k; i++)
175 s += matrix[i][
k]*matrix[i][j];
178 s = (matrix[j][
k] -
s)/matrix[k][k];
186 d = matrix[j][j] - d;
190 FatalErrorIn(
"Foam::LUDecompose(scalarSymmetricSquareMatrix&)")
191 <<
"Matrix is not symmetric positive-definite. Unable to " 196 matrix[j][j] =
sqrt(d);
216 "const scalarRectangularMatrix& A, " 217 "const scalarRectangularMatrix& B, " 218 "const scalarRectangularMatrix& C, " 219 "scalarRectangularMatrix& answer)" 220 ) <<
"A and B must have identical inner dimensions but A.m = " 221 << A.
m() <<
" and B.n = " << B.
n()
230 "const scalarRectangularMatrix& A, " 231 "const scalarRectangularMatrix& B, " 232 "const scalarRectangularMatrix& C, " 233 "scalarRectangularMatrix& answer)" 234 ) <<
"B and C must have identical inner dimensions but B.m = " 235 << B.
m() <<
" and C.n = " << C.
n()
241 for (
label i = 0; i < A.
n(); i++)
245 for (
label l = 0; l < C.
n(); l++)
248 for (
label j = 0; j < A.
m(); j++)
250 ab += A[i][j]*B[j][l];
252 ans[i][
g] += C[l][
g] * ab;
267 if (A.
m() != B.
size())
272 "const scalarRectangularMatrix& A, " 273 "const DiagonalMatrix<scalar>& B, " 274 "const scalarRectangularMatrix& C, " 275 "scalarRectangularMatrix& answer)" 276 ) <<
"A and B must have identical inner dimensions but A.m = " 277 << A.
m() <<
" and B.n = " << B.
size()
281 if (B.
size() != C.
n())
286 "const scalarRectangularMatrix& A, " 287 "const DiagonalMatrix<scalar>& B, " 288 "const scalarRectangularMatrix& C, " 289 "scalarRectangularMatrix& answer)" 290 ) <<
"B and C must have identical inner dimensions but B.m = " 291 << B.
size() <<
" and C.n = " << C.
n()
297 for (
label i = 0; i < A.
n(); i++)
301 for (
label l = 0; l < C.
n(); l++)
303 ans[i][
g] += C[l][
g] * A[i][l]*B[l];
316 SVD svd(A, minCondition);
dimensionedScalar sqrt(const dimensionedScalar &ds)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject( name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE ))
dimensioned< scalar > mag(const dimensioned< Type > &)
RectangularMatrix< scalar > scalarRectangularMatrix
scalarRectangularMatrix SVDinv(const scalarRectangularMatrix &A, scalar minCondition=0)
Return the inverse of matrix A using SVD.
label n() const
Return the number of rows.
A templated 2D square symmetric matrix of objects of <T>, where the n x n matrix dimension is known a...
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void size(const label)
Override size to be inconsistent with allocated storage.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensionedScalar sign(const dimensionedScalar &ds)
Singular value decomposition of a rectangular matrix.
label k
Boltzmann constant.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
errorManip< error > abort(error &err)
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
const dimensionedVector & g
const scalarRectangularMatrix & VSinvUt() const
Return VSinvUt (the pseudo inverse)
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
label m() const
Return the number of columns.