60 ans(i,
g) +=
C(l,
g)*
A(i, l)*
B[l];
69template<
class MatrixType,
class DiagMatrixType,
class WorkArrayType>
70static std::pair<label, bool>
SVDcomp
76 const scalar minCondition,
92 bool converged_(
true);
98 const label Un = U_.n();
99 const label Um = U_.m();
108 const auto sign = [](scalar a, scalar
b) -> scalar
111 return b >= 0 ? a : -a;
115 for (label i=0; i<Un; i++)
123 for (label
k=i;
k<Um;
k++)
125 scale +=
mag(U_(
k, i));
130 for (label
k=i;
k<Um;
k++)
133 s += U_(
k, i)*U_(
k, i);
141 for (label j=l-1; j<Un; j++)
144 for (label
k=i;
k<Um;
k++)
146 s += U_(
k, i)*U_(
k, j);
150 for (label
k=i;
k<Um;
k++)
152 U_(
k, j) +=
f*U_(
k, i);
156 for (label
k=i;
k<Um;
k++)
167 if (i+1 <= Um && i != Un)
169 for (label
k=l-1;
k<Un;
k++)
171 scale +=
mag(U_(i,
k));
176 for (label
k=l-1;
k<Un;
k++)
179 s += U_(i,
k)*U_(i,
k);
182 scalar
f = U_(i, l-1);
187 for (label
k=l-1;
k<Un;
k++)
192 for (label j=l-1; j<Um; j++)
195 for (label
k=l-1;
k<Un;
k++)
197 s += U_(j,
k)*U_(i,
k);
200 for (label
k=l-1;
k<Un;
k++)
202 U_(j,
k) +=
s*rv1[
k];
205 for (label
k=l-1;
k<Un;
k++)
212 anorm =
max(anorm,
mag(S_[i]) +
mag(rv1[i]));
217 for (label i=Un-1; i >= 0; i--)
223 for (label j=l; j<Un; j++)
225 V_(j, i) = (U_(i, j)/U_(i, l))/
g;
228 for (label j=l; j<Un; j++)
231 for (label
k=l;
k<Un;
k++)
233 s += U_(i,
k)*V_(
k, j);
236 for (label
k=l;
k<Un;
k++)
238 V_(
k, j) +=
s*V_(
k, i);
243 for (label j=l; j<Un;j++)
245 V_(i, j) = V_(j, i) = 0;
254 for (label i=
min(Un, Um) - 1; i>=0; i--)
259 for (label j=l; j<Un; j++)
268 for (label j=l; j<Un; j++)
271 for (label
k=l;
k<Um;
k++)
273 s += U_(
k, i)*U_(
k, j);
276 scalar
f = (
s/U_(i, i))*
g;
278 for (label
k=i;
k<Um;
k++)
280 U_(
k, j) +=
f*U_(
k, i);
284 for (label j=i; j<Um; j++)
291 for (label j=i; j<Um; j++)
300 for (label
k=Un-1;
k >= 0;
k--)
302 for (label its = 0; its < 30; its++)
307 for (l =
k; l >= 0; l--)
311 if (l == 0 ||
mag(rv1[l]) <= anorm)
317 if (
mag(S_[mn]) <= anorm)
327 for (label i=l; i<
k+1; i++)
344 for (label j=0; j<Um; j++)
346 scalar
y = U_(j, mn);
348 U_(j, mn) =
y*
c + z*
s;
349 U_(j, i) = z*
c -
y*
s;
361 for (label j=0; j<Un; j++)
363 V_(j,
k) = -V_(j,
k);
379 scalar
f = ((
y - z)*(
y + z) + (
g -
h)*(
g +
h))/(2*
h*
y);
385 for (label j=l; j <= mn; j++)
401 for (label jj = 0; jj < Un; jj++)
405 V_(jj, j) =
x*
c + z*
s;
406 V_(jj, i) = z*
c -
x*
s;
420 for (label jj=0; jj < Um; jj++)
424 U_(jj, j) =
y*
c + z*
s;
425 U_(jj, i) = z*
c -
y*
s;
435 const scalar minS = minCondition*S_[
findMax(S_)];
445 return { nZeros_, converged_ };
453Foam::SVD::SVD(
const scalarRectangularMatrix&
A,
const scalar minCondition)
465 auto status =
SVDcomp(
A, minCondition, U_, V_, S_, rv1);
467 nZeros_ = status.first;
468 converged_ = status.second;
477 for (label i=1; i<S_.size(); i++)
480 if (
s > VSMALL &&
s < minS) minS =
s;
499 const scalar minCondition
502 SVD svd(
A, minCondition);
517 SVDcomp(
A, minCondition, U_, V_, S_, rv1);
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)
Various functions to operate on Lists.
const uniformDimensionedVectorField & g
Graphite solid properties.
A 1D vector of objects of type <T> with a fixed length <N>.
scalarRectangularMatrix VSinvUt() const
Return the matrix product V S^(-1) U^T (the pseudo inverse).
scalar minNonZeroS() const
Return the minimum non-zero singular value.
SVD(const SVD &)=delete
No copy construct.
static scalarRectangularMatrix pinv(const scalarRectangularMatrix &A, const scalar minCondition=0)
Return the pseudo inverse of the given matrix.
A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
Tensor< Cmpt > T() const
Return non-Hermitian transpose.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
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))
const dimensionedScalar c
Speed of light in a vacuum.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
DiagTensor< scalar > diagTensor
DiagTensor of scalars, i.e. DiagTensor<scalar>.
dimensionedScalar sign(const dimensionedScalar &ds)
RectangularMatrix< scalar > scalarRectangularMatrix
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
static tensor do_multiply(const tensor &A, const diagTensor &B, const tensor &C)
static std::pair< label, bool > SVDcomp(const MatrixType &A, const scalar minCondition, MatrixType &U_, MatrixType &V_, DiagMatrixType &S_, WorkArrayType &rv1)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
label findMax(const ListType &input, label start=0)
Linear search for the index of the max element, similar to std::max_element but for lists and returns...
void multiply(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
List< scalar > scalarList
List of scalar.
Scalar sqrtSumSqr(const Scalar a, const Scalar b)