55 for (label i = 0; i < m; ++i)
57 scalar largestCoeff = 0.0;
59 const scalar* __restrict__ matrixi = matrix[i];
61 for (label j = 0; j < m; ++j)
63 if ((temp =
mag(matrixi[j])) > largestCoeff)
69 if (largestCoeff == 0.0)
75 vv[i] = 1.0/largestCoeff;
78 for (label j = 0; j < m; ++j)
80 scalar* __restrict__ matrixj = matrix[j];
82 for (label i = 0; i < j; ++i)
84 scalar* __restrict__ matrixi = matrix[i];
86 scalar
sum = matrixi[j];
87 for (label
k = 0;
k < i; ++
k)
89 sum -= matrixi[
k]*matrix(
k, j);
96 scalar largestCoeff = 0.0;
97 for (label i = j; i < m; ++i)
99 scalar* __restrict__ matrixi = matrix[i];
100 scalar
sum = matrixi[j];
102 for (label
k = 0;
k < j; ++
k)
104 sum -= matrixi[
k]*matrix(
k, j);
110 if ((temp = vv[i]*
mag(
sum)) >= largestCoeff)
117 pivotIndices[j] = iMax;
121 scalar* __restrict__ matrixiMax = matrix[iMax];
123 for (label
k = 0;
k < m; ++
k)
125 Swap(matrixj[
k], matrixiMax[
k]);
132 if (matrixj[j] == 0.0)
139 scalar rDiag = 1.0/matrixj[j];
141 for (label i = j + 1; i < m; ++i)
143 matrix(i, j) *= rDiag;
153 label size = matrix.
m();
156 for (label j = 0; j < size; ++j)
158 for (label
k = j + 1;
k < size; ++
k)
164 for (label j = 0; j < size; ++j)
168 for (label
k = 0;
k < j; ++
k)
172 for (label i = 0; i <
k; ++i)
174 s += matrix(i,
k)*matrix(i, j);
177 s = (matrix(j,
k) -
s)/matrix(
k,
k);
185 d = matrix(j, j) - d;
190 <<
"Matrix is not symmetric positive-definite. Unable to "
195 matrix(j, j) =
sqrt(d);
213 <<
"A and B must have identical inner dimensions but A.n = "
214 <<
A.n() <<
" and B.m = " <<
B.m()
221 <<
"B and C must have identical inner dimensions but B.n = "
222 <<
B.n() <<
" and C.m = " <<
C.m()
228 for (label i = 0; i <
A.m(); ++i)
230 for (label
g = 0;
g <
C.n(); ++
g)
232 for (label l = 0; l <
C.m(); ++l)
235 for (label j = 0; j <
A.n(); ++j)
237 ab +=
A(i, j)*
B(j, l);
239 ans(i,
g) +=
C(l,
g) * ab;
254 if (
A.n() !=
B.size())
257 <<
"A and B must have identical inner dimensions but A.n = "
258 <<
A.n() <<
" and B.m = " <<
B.size()
262 if (
B.size() !=
C.m())
265 <<
"B and C must have identical inner dimensions but B.n = "
266 <<
B.size() <<
" and C.m = " <<
C.m()
272 for (label i = 0; i <
A.m(); ++i)
274 for (label
g = 0;
g <
C.n(); ++
g)
276 for (label l = 0; l <
C.m(); ++l)
278 ans(i,
g) +=
C(l,
g) *
A(i, l)*
B[l];
293 if (
A.m() !=
B.size())
296 <<
"A and B must have identical dimensions but A.m = "
297 <<
A.m() <<
" and B.m = " <<
B.size()
301 if (
B.size() !=
C.m())
304 <<
"B and C must have identical dimensions but B.m = "
305 <<
B.size() <<
" and C.m = " <<
C.m()
309 const label size =
A.m();
313 for (label i = 0; i < size; ++i)
315 for (label
g = 0;
g < size; ++
g)
317 for (label l = 0; l < size; ++l)
319 ans(i,
g) +=
C(l,
g)*
A(i, l)*
B[l];
333 SVD svd(
A, minCondition);
static const Foam::dimensionedScalar C("", Foam::dimTemperature, 234.5)
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
const uniformDimensionedVectorField & g
Graphite solid properties.
A templated (N x N) diagonal matrix of objects of <Type>, effectively containing N elements,...
label m() const noexcept
The number of rows.
Singular value decomposition of a rectangular matrix.
scalarRectangularMatrix VSinvUt() const
Return the matrix product V S^(-1) U^T (the pseudo inverse)
A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
dimensionedScalar sign(const dimensionedScalar &ds)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
scalarRectangularMatrix SVDinv(const scalarRectangularMatrix &A, scalar minCondition=0)
Return the inverse of matrix A using SVD.
errorManip< error > abort(error &err)
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
errorManipArg< error, int > exit(error &err, const int errNo=1)