/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "expressions.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "calculatedFvPatchFields.H"
#include "extrapolatedCalculatedFvPatchFields.H"
#include "coupledFvPatchFields.H"
#include "UIndirectList.H"
#include "UCompactListList.H"
#include "solutionControl.H"
#include "fvmDdt.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template
template
void Foam::fvMatrix::addToInternalField
(
const labelUList& addr,
const Field& pf,
Field& intf
) const
{
if (addr.size() != pf.size())
{
FatalErrorInFunction
<< "sizes of addressing and field are different"
<< abort(FatalError);
}
forAll(addr, facei)
{
intf[addr[facei]] += pf[facei];
}
}
template
template
void Foam::fvMatrix::addToInternalField
(
const labelUList& addr,
const tmp>& tpf,
Field& intf
) const
{
addToInternalField(addr, tpf(), intf);
tpf.clear();
}
template
template
void Foam::fvMatrix::subtractFromInternalField
(
const labelUList& addr,
const Field& pf,
Field& intf
) const
{
if (addr.size() != pf.size())
{
FatalErrorInFunction
<< "sizes of addressing and field are different"
<< abort(FatalError);
}
forAll(addr, facei)
{
intf[addr[facei]] -= pf[facei];
}
}
template
template
void Foam::fvMatrix::subtractFromInternalField
(
const labelUList& addr,
const tmp>& tpf,
Field& intf
) const
{
subtractFromInternalField(addr, tpf(), intf);
tpf.clear();
}
template
void Foam::fvMatrix::addBoundaryDiag
(
scalarField& diag,
const direction solveCmpt
) const
{
forAll(internalCoeffs_, patchi)
{
addToInternalField
(
lduAddr().patchAddr(patchi),
eval(internalCoeffs_[patchi].component(solveCmpt)),
diag
);
}
}
template
void Foam::fvMatrix::addCmptAvBoundaryDiag(scalarField& diag) const
{
forAll(internalCoeffs_, patchi)
{
addToInternalField
(
lduAddr().patchAddr(patchi),
eval(cmptAv(internalCoeffs_[patchi])),
diag
);
}
}
template
void Foam::fvMatrix::addBoundarySource
(
Field& source,
const bool couples
) const
{
forAll(psi_.boundaryField(), patchi)
{
const fvPatchField& ptf = psi_.boundaryField()[patchi];
const Field& pbc = boundaryCoeffs_[patchi];
if (!ptf.coupled())
{
addToInternalField(lduAddr().patchAddr(patchi), pbc, source);
}
else if (couples)
{
const tmp> tpnf = ptf.patchNeighbourField();
const Field& pnf = tpnf();
const labelUList& addr = lduAddr().patchAddr(patchi);
forAll(addr, facei)
{
source[addr[facei]] += cmptMultiply(pbc[facei], pnf[facei]);
}
}
}
}
template
void Foam::fvMatrix::setValue
(
const label celli,
const Type& value
)
{
const fvMesh& mesh = this->mesh();
const cellList& cells = mesh.cells();
const labelUList& own = mesh.owner();
const labelUList& nei = mesh.neighbour();
scalarField& Diag = diag();
Field& psi =
const_cast&>(psi_)
.primitiveFieldRef();
psi[celli] = value;
source_[celli] = value*Diag[celli];
if (symmetric() || asymmetric())
{
const cell& c = cells[celli];
forAll(c, j)
{
const label facei = c[j];
if (mesh.isInternalFace(facei))
{
if (symmetric())
{
if (celli == own[facei])
{
source_[nei[facei]] -= upper()[facei]*value;
}
else
{
source_[own[facei]] -= upper()[facei]*value;
}
upper()[facei] = 0.0;
}
else
{
if (celli == own[facei])
{
source_[nei[facei]] -= lower()[facei]*value;
}
else
{
source_[own[facei]] -= upper()[facei]*value;
}
upper()[facei] = 0.0;
lower()[facei] = 0.0;
}
}
else
{
const label bFacei = facei - mesh.nInternalFaces();
const labelUList patches =
mesh.polyBFacePatches()[bFacei];
const labelUList patchFaces =
mesh.polyBFacePatchFaces()[bFacei];
forAll(patches, i)
{
internalCoeffs_[patches[i]][patchFaces[i]] = Zero;
boundaryCoeffs_[patches[i]][patchFaces[i]] = Zero;
}
}
}
}
}
template
void Foam::fvMatrix::setValue
(
const label celli,
const Type& value,
const scalar fraction,
const scalarField& ddtDiag
)
{
Field& psi =
const_cast&>(psi_)
.primitiveFieldRef();
psi[celli] = (1 - fraction)*psi[celli] + fraction*value;
const scalar coeff =
fraction/(1 - fraction)
*(diag()[celli] - ddtDiag[celli]);
diag()[celli] += coeff;
source()[celli] += coeff*value;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::fvMatrix::fvMatrix
(
const VolField& psi,
const dimensionSet& ds
)
:
lduMatrix(psi.mesh()),
psi_(psi),
dimensions_(ds),
source_(psi.size(), Zero),
internalCoeffs_(psi.mesh().boundary().size()),
boundaryCoeffs_(psi.mesh().boundary().size()),
faceFluxCorrectionPtr_(nullptr)
{
if (debug)
{
InfoInFunction
<< "Constructing fvMatrix for field " << psi_.name() << endl;
}
// Initialise coupling coefficients
forAll(psi.mesh().boundary(), patchi)
{
internalCoeffs_[patchi].setSize
(
psi.mesh().boundary()[patchi].size(),
Zero
);
boundaryCoeffs_[patchi].setSize
(
psi.mesh().boundary()[patchi].size(),
Zero
);
}
// Update the boundary coefficients of psi without changing its event No.
VolField& psiRef = const_cast&>(psi_);
const uint64_t currentStatePsi = psiRef.eventNo();
psiRef.boundaryRef().updateCoeffs();
psiRef.eventNo() = currentStatePsi;
}
template
Foam::fvMatrix::fvMatrix(const fvMatrix& fvm)
:
tmp>::refCount(),
lduMatrix(fvm),
psi_(fvm.psi_),
dimensions_(fvm.dimensions_),
source_(fvm.source_),
internalCoeffs_(fvm.internalCoeffs_),
boundaryCoeffs_(fvm.boundaryCoeffs_),
faceFluxCorrectionPtr_(nullptr)
{
if (debug)
{
InfoInFunction
<< "Copying fvMatrix for field " << psi_.name() << endl;
}
if (fvm.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ = new
SurfaceField
(
*(fvm.faceFluxCorrectionPtr_)
);
}
}
template
Foam::fvMatrix::fvMatrix(const tmp>& tfvm)
:
lduMatrix
(
const_cast&>(tfvm()),
tfvm.isTmp()
),
psi_(tfvm().psi_),
dimensions_(tfvm().dimensions_),
source_
(
const_cast&>(tfvm()).source_,
tfvm.isTmp()
),
internalCoeffs_
(
const_cast&>(tfvm()).internalCoeffs_,
tfvm.isTmp()
),
boundaryCoeffs_
(
const_cast&>(tfvm()).boundaryCoeffs_,
tfvm.isTmp()
),
faceFluxCorrectionPtr_(nullptr)
{
if (debug)
{
InfoInFunction
<< "Copying fvMatrix for field " << psi_.name() << endl;
}
if (tfvm().faceFluxCorrectionPtr_)
{
if (tfvm.isTmp())
{
faceFluxCorrectionPtr_ = tfvm().faceFluxCorrectionPtr_;
tfvm().faceFluxCorrectionPtr_ = nullptr;
}
else
{
faceFluxCorrectionPtr_ = new
SurfaceField
(
*(tfvm().faceFluxCorrectionPtr_)
);
}
}
tfvm.clear();
}
template
Foam::fvMatrix::fvMatrix
(
const VolField& psi,
Istream& is
)
:
lduMatrix(psi.mesh()),
psi_(psi),
dimensions_(is),
source_(is),
internalCoeffs_(psi.mesh().boundary().size()),
boundaryCoeffs_(psi.mesh().boundary().size()),
faceFluxCorrectionPtr_(nullptr)
{
if (debug)
{
InfoInFunction
<< "Constructing fvMatrix for field " << psi_.name() << endl;
}
// Initialise coupling coefficients
forAll(psi.mesh().boundary(), patchi)
{
internalCoeffs_.set
(
patchi,
new Field
(
psi.mesh().boundary()[patchi].size(),
Zero
)
);
boundaryCoeffs_.set
(
patchi,
new Field
(
psi.mesh().boundary()[patchi].size(),
Zero
)
);
}
}
template
Foam::tmp> Foam::fvMatrix::clone() const
{
return tmp>
(
new fvMatrix(*this)
);
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * * //
template
Foam::fvMatrix::~fvMatrix()
{
if (debug)
{
InfoInFunction
<< "Destroying fvMatrix for field " << psi_.name() << endl;
}
if (faceFluxCorrectionPtr_)
{
delete faceFluxCorrectionPtr_;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
template class ListType>
void Foam::fvMatrix::setValues
(
const labelUList& cellLabels,
const ListType& values
)
{
// Fix the values
forAll(cellLabels, i)
{
setValue(cellLabels[i], values[i]);
}
}
template
template class ListType>
void Foam::fvMatrix::setValues
(
const labelUList& cellLabels,
const ListType& values,
const scalarList& fractions,
const bool hasDdt
)
{
// Get the proportion of the diagonal associated with iterative update
scalarField ddtDiag(diag().size(), 0);
const scalar alpha = relaxationFactor();
if (alpha > 0)
{
ddtDiag += (1 - alpha)*diag();
}
if (hasDdt)
{
const fvMatrix ddtEqn(fvm::ddt(psi_));
if (ddtEqn.hasDiag())
{
ddtDiag += ddtEqn.diag();
}
}
forAll(cellLabels, i)
{
if (- rootSmall < fractions[i] && fractions[i] < rootSmall)
{
// Do nothing
}
else if (1 - rootSmall < fractions[i] && fractions[i] < 1 + rootSmall)
{
// Fix the values
setValue(cellLabels[i], values[i]);
}
else
{
// Fractionally fix the values
setValue(cellLabels[i], values[i], fractions[i], ddtDiag);
}
}
}
template
void Foam::fvMatrix::setReference
(
const label celli,
const Type& value,
const bool forceReference
)
{
if ((forceReference || psi_.needReference()) && celli >= 0)
{
source()[celli] += diag()[celli]*value;
diag()[celli] += diag()[celli];
}
}
template
Foam::scalar Foam::fvMatrix::relaxationFactor() const
{
if
(
solutionControl::finalIteration(mesh())
&& mesh().solution().relaxEquation(psi_.name() + "Final")
)
{
return mesh().solution().equationRelaxationFactor
(
psi_.name() + "Final"
);
}
else if (mesh().solution().relaxEquation(psi_.name()))
{
return mesh().solution().equationRelaxationFactor(psi_.name());
}
else
{
return 0;
}
}
template
void Foam::fvMatrix::relax(const scalar alpha)
{
if (alpha <= 0)
{
return;
}
if (debug)
{
InfoInFunction
<< "Relaxing " << psi_.name() << " by " << alpha << endl;
}
Field& S = source();
scalarField& D = diag();
// Store the current unrelaxed diagonal for use in updating the source
scalarField D0(D);
// Calculate the sum-mag off-diagonal from the interior faces
scalarField sumOff(D.size(), 0.0);
sumMagOffDiag(sumOff);
// Handle the boundary contributions to the diagonal
forAll(psi_.boundaryField(), patchi)
{
const fvPatchField& ptf = psi_.boundaryField()[patchi];
if (ptf.size())
{
const labelUList& pa = lduAddr().patchAddr(patchi);
Field& iCoeffs = internalCoeffs_[patchi];
if (ptf.coupled())
{
const Field& pCoeffs = boundaryCoeffs_[patchi];
// For coupled boundaries add the diagonal and
// off-diagonal contributions
forAll(pa, face)
{
D[pa[face]] += component(iCoeffs[face], 0);
sumOff[pa[face]] += mag(component(pCoeffs[face], 0));
}
}
else
{
// For non-coupled boundaries add the maximum magnitude diagonal
// contribution to ensure stability
forAll(pa, face)
{
D[pa[face]] += cmptMax(cmptMag(iCoeffs[face]));
}
}
}
}
if (debug)
{
// Calculate amount of non-dominance.
label nNon = 0;
scalar maxNon = 0.0;
scalar sumNon = 0.0;
forAll(D, celli)
{
scalar d = (sumOff[celli] - D[celli])/mag(D[celli]);
if (d > 0)
{
nNon++;
maxNon = max(maxNon, d);
sumNon += d;
}
}
reduce(nNon, sumOp(), UPstream::msgType(), mesh().comm());
reduce
(
maxNon,
maxOp(),
UPstream::msgType(),
mesh().comm()
);
reduce
(
sumNon,
sumOp(),
UPstream::msgType(),
mesh().comm()
);
sumNon /= returnReduce
(
D.size(),
sumOp(),
UPstream::msgType(),
mesh().comm()
);
InfoInFunction
<< "Matrix dominance test for " << psi_.name() << nl
<< " number of non-dominant cells : " << nNon << nl
<< " maximum relative non-dominance : " << maxNon << nl
<< " average relative non-dominance : " << sumNon << nl
<< endl;
}
// Ensure the matrix is diagonally dominant...
// Assumes that the central coefficient is positive and ensures it is
forAll(D, celli)
{
D[celli] = max(mag(D[celli]), sumOff[celli]);
}
// ... then relax
D /= alpha;
// Now remove the diagonal contribution from coupled boundaries
forAll(psi_.boundaryField(), patchi)
{
const fvPatchField& ptf = psi_.boundaryField()[patchi];
if (ptf.size())
{
const labelUList& pa = lduAddr().patchAddr(patchi);
Field& iCoeffs = internalCoeffs_[patchi];
if (ptf.coupled())
{
forAll(pa, face)
{
D[pa[face]] -= component(iCoeffs[face], 0);
}
}
else
{
forAll(pa, face)
{
D[pa[face]] -= cmptMin(iCoeffs[face]);
}
}
}
}
// Finally add the relaxation contribution to the source.
S += (D - D0)*psi_.primitiveField();
}
template
void Foam::fvMatrix::relax()
{
relax(relaxationFactor());
}
template
void Foam::fvMatrix::boundaryManipulate
(
typename VolField::Boundary& bFields
)
{
forAll(bFields, patchi)
{
bFields[patchi].manipulateMatrix(*this);
}
}
template
Foam::tmp Foam::fvMatrix::D() const
{
tmp tdiag(new scalarField(diag()));
addCmptAvBoundaryDiag(tdiag.ref());
return tdiag;
}
template
Foam::tmp> Foam::fvMatrix::DD() const
{
tmp> tdiag(pTraits::one*diag());
forAll(psi_.boundaryField(), patchi)
{
const fvPatchField& ptf = psi_.boundaryField()[patchi];
if (!ptf.coupled() && ptf.size())
{
addToInternalField
(
lduAddr().patchAddr(patchi),
internalCoeffs_[patchi],
tdiag.ref()
);
}
}
return tdiag;
}
template
Foam::tmp Foam::fvMatrix::A() const
{
tmp tAphi
(
volScalarField::New
(
word("A(", psi_.name(), ')'),
mesh(),
dimensions_/psi_.dimensions()/dimensions::volume,
extrapolatedCalculatedFvPatchScalarField::typeName
)
);
tAphi.ref().primitiveFieldRef() = D()/mesh().V().primitiveField();
tAphi.ref().correctBoundaryConditions();
return tAphi;
}
template
Foam::tmp> Foam::fvMatrix::Su() const
{
tmp> tSu
(
VolInternalField::New
(
word("Su(", psi_.name(), ')'),
mesh(),
dimensions_/dimensions::volume,
-source()/mesh().V().primitiveField()
)
);
return tSu;
}
template
Foam::tmp Foam::fvMatrix::Sp() const
{
tmp tSp
(
volInternalScalarField::New
(
word("Sp(", psi_.name(), ')'),
mesh(),
dimensions_/psi_.dimensions()/dimensions::volume,
hasDiag()
? diag()/mesh().V().primitiveField()
: tmp(new scalarField(lduAddr().size(), scalar(0)))
)
);
return tSp;
}
template
Foam::tmp>
Foam::fvMatrix::H() const
{
tmp> tHphi
(
VolField::New
(
word("H(", psi_.name(), ')'),
mesh(),
dimensions_/dimensions::volume,
extrapolatedCalculatedFvPatchScalarField::typeName
)
);
VolField& Hphi = tHphi.ref();
// Loop over field components
for (direction cmpt=0; cmpt()
);
for (direction cmpt=0; cmpt
Foam::tmp Foam::fvMatrix::H1() const
{
tmp tH1
(
volScalarField::New
(
"H(1)",
mesh(),
dimensions_/(dimensions::volume*psi_.dimensions()),
extrapolatedCalculatedFvPatchScalarField::typeName
)
);
volScalarField& H1_ = tH1.ref();
H1_.primitiveFieldRef() = lduMatrix::H1();
forAll(psi_.boundaryField(), patchi)
{
const fvPatchField& ptf = psi_.boundaryField()[patchi];
if (ptf.coupled() && ptf.size())
{
addToInternalField
(
lduAddr().patchAddr(patchi),
eval(boundaryCoeffs_[patchi].component(0)),
H1_
);
}
}
H1_.primitiveFieldRef() /= mesh().V().primitiveField();
H1_.correctBoundaryConditions();
return tH1;
}
template
Foam::tmp>
Foam::fvMatrix::
flux() const
{
if (!mesh().schemes().fluxRequired(psi_.name()))
{
FatalErrorInFunction
<< "flux requested but " << psi_.name()
<< " not specified in the fluxRequired sub-dictionary"
" of fvSchemes."
<< abort(FatalError);
}
// construct SurfaceField
tmp> tfieldFlux
(
SurfaceField::New
(
word("flux(", psi_.name(), ')'),
mesh(),
dimensions()
)
);
SurfaceField& fieldFlux =
tfieldFlux.ref();
for (direction cmpt=0; cmpt::nComponents; cmpt++)
{
fieldFlux.primitiveFieldRef().replace
(
cmpt,
lduMatrix::faceH(eval(psi_.primitiveField().component(cmpt)))
);
}
Field> InternalContrib = internalCoeffs_;
forAll(InternalContrib, patchi)
{
InternalContrib[patchi] =
cmptMultiply
(
InternalContrib[patchi],
psi_.boundaryField()[patchi].patchInternalField()
);
}
Field> NeighbourContrib = boundaryCoeffs_;
forAll(NeighbourContrib, patchi)
{
if (psi_.boundaryField()[patchi].coupled())
{
NeighbourContrib[patchi] =
cmptMultiply
(
NeighbourContrib[patchi],
psi_.boundaryField()[patchi].patchNeighbourField()
);
}
}
typename SurfaceField::BoundaryField& ffbf =
fieldFlux.boundaryFieldRef();
forAll(ffbf, patchi)
{
ffbf[patchi] = InternalContrib[patchi] - NeighbourContrib[patchi];
}
if (faceFluxCorrectionPtr_)
{
fieldFlux += *faceFluxCorrectionPtr_;
}
return tfieldFlux;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template
void Foam::fvMatrix::operator=(const fvMatrix& fvmv)
{
if (this == &fvmv)
{
FatalErrorInFunction
<< "attempted assignment to self"
<< abort(FatalError);
}
if (&psi_ != &(fvmv.psi_))
{
FatalErrorInFunction
<< "different fields"
<< abort(FatalError);
}
dimensions_ = fvmv.dimensions_;
lduMatrix::operator=(fvmv);
source_ = fvmv.source_;
internalCoeffs_ = fvmv.internalCoeffs_;
boundaryCoeffs_ = fvmv.boundaryCoeffs_;
if (faceFluxCorrectionPtr_ && fvmv.faceFluxCorrectionPtr_)
{
*faceFluxCorrectionPtr_ = *fvmv.faceFluxCorrectionPtr_;
}
else if (fvmv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ =
new SurfaceField
(*fvmv.faceFluxCorrectionPtr_);
}
}
template
void Foam::fvMatrix::operator=(const tmp>& tfvmv)
{
operator=(tfvmv());
tfvmv.clear();
}
template
void Foam::fvMatrix::negate()
{
lduMatrix::negate();
source_.negate();
internalCoeffs_.negate();
boundaryCoeffs_.negate();
if (faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_->negate();
}
}
template
void Foam::fvMatrix::operator+=(const fvMatrix& fvmv)
{
checkMethod(*this, fvmv, "+=");
dimensions_ += fvmv.dimensions_;
lduMatrix::operator+=(fvmv);
source_ += fvmv.source_;
internalCoeffs_ += fvmv.internalCoeffs_;
boundaryCoeffs_ += fvmv.boundaryCoeffs_;
if (faceFluxCorrectionPtr_ && fvmv.faceFluxCorrectionPtr_)
{
*faceFluxCorrectionPtr_ += *fvmv.faceFluxCorrectionPtr_;
}
else if (fvmv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ = new
SurfaceField
(
*fvmv.faceFluxCorrectionPtr_
);
}
}
template
void Foam::fvMatrix::operator+=(const tmp>& tfvmv)
{
operator+=(tfvmv());
tfvmv.clear();
}
template
void Foam::fvMatrix::operator-=(const fvMatrix& fvmv)
{
checkMethod(*this, fvmv, "-=");
dimensions_ -= fvmv.dimensions_;
lduMatrix::operator-=(fvmv);
source_ -= fvmv.source_;
internalCoeffs_ -= fvmv.internalCoeffs_;
boundaryCoeffs_ -= fvmv.boundaryCoeffs_;
if (faceFluxCorrectionPtr_ && fvmv.faceFluxCorrectionPtr_)
{
*faceFluxCorrectionPtr_ -= *fvmv.faceFluxCorrectionPtr_;
}
else if (fvmv.faceFluxCorrectionPtr_)
{
faceFluxCorrectionPtr_ =
new SurfaceField
(-*fvmv.faceFluxCorrectionPtr_);
}
}
template
void Foam::fvMatrix::operator-=(const tmp>& tfvmv)
{
operator-=(tfvmv());
tfvmv.clear();
}
template
void Foam::fvMatrix::operator+=
(
const VolInternalField& su
)
{
checkMethod(*this, su, "+=");
source() -= su.mesh().V().primitiveField()*su.primitiveField();
}
template
template
void Foam::fvMatrix::operator+=(const Expression& su)
{
checkMethod(*this, su, "+=");
source() -=
mesh().V().primitiveField()
*expression::access
(
su,
expression::Value(),
expression::Base()
);
}
template
void Foam::fvMatrix::operator+=
(
const tmp>& tsu
)
{
operator+=(tsu());
tsu.clear();
}
template
void Foam::fvMatrix::operator+=
(
const tmp>& tsu
)
{
operator+=(tsu());
tsu.clear();
}
template
void Foam::fvMatrix::operator-=
(
const VolInternalField& su
)
{
checkMethod(*this, su, "-=");
source() += su.mesh().V().primitiveField()*su.primitiveField();
}
template
template
void Foam::fvMatrix::operator-=(const Expression& su)
{
checkMethod(*this, su, "-=");
source() +=
mesh().V().primitiveField()
*expression::access
(
su,
expression::Value(),
expression::Base()
);
}
template
void Foam::fvMatrix::operator-=
(
const tmp>& tsu
)
{
operator-=(tsu());
tsu.clear();
}
template
void Foam::fvMatrix::operator-=
(
const tmp>& tsu
)
{
operator-=(tsu());
tsu.clear();
}
template
void Foam::fvMatrix::operator+=
(
const dimensioned& su
)
{
source() -= psi().mesh().V().primitiveField()*su.value();
}
template
void Foam::fvMatrix::operator-=
(
const dimensioned& su
)
{
source() += psi().mesh().V().primitiveField()*su.value();
}
template
void Foam::fvMatrix::operator+=
(
const zero&
)
{}
template
void Foam::fvMatrix::operator-=
(
const zero&
)
{}
template
void Foam::fvMatrix::operator*=
(
const volInternalScalarField& dsf
)
{
dimensions_ *= dsf.dimensions();
lduMatrix::operator*=(dsf.primitiveField());
source_ *= dsf.primitiveField();
forAll(boundaryCoeffs_, patchi)
{
scalarField pisf
(
dsf.mesh().boundary()[patchi].patchInternalField
(
dsf.primitiveField()
)
);
internalCoeffs_[patchi] *= pisf;
boundaryCoeffs_[patchi] *= pisf;
}
if (faceFluxCorrectionPtr_)
{
FatalErrorInFunction
<< "cannot scale a matrix containing a faceFluxCorrection"
<< abort(FatalError);
}
}
template
template
void Foam::fvMatrix::operator*=(const Expression& e)
{
dimensions_ *= expression::access(e, dimensions::invalid);
const scalarField sf
(
expression::access
(
e,
expression::Value(),
expression::Base()
)
);
lduMatrix::operator*=(sf);
source_ *= sf;
forAll(boundaryCoeffs_, patchi)
{
const scalarField pisf
(
mesh().boundary()[patchi].patchInternalField(sf)
);
internalCoeffs_[patchi] *= pisf;
boundaryCoeffs_[patchi] *= pisf;
}
if (faceFluxCorrectionPtr_)
{
FatalErrorInFunction
<< "cannot scale a matrix containing a faceFluxCorrection"
<< abort(FatalError);
}
}
template
void Foam::fvMatrix::operator*=
(
const tmp& tdsf
)
{
operator*=(tdsf());
tdsf.clear();
}
template
void Foam::fvMatrix::operator*=
(
const tmp& tvsf
)
{
operator*=(tvsf());
tvsf.clear();
}
template
void Foam::fvMatrix::operator*=
(
const dimensioned& ds
)
{
dimensions_ *= ds.dimensions();
lduMatrix::operator*=(ds.value());
source_ *= ds.value();
internalCoeffs_ *= ds.value();
boundaryCoeffs_ *= ds.value();
if (faceFluxCorrectionPtr_)
{
*faceFluxCorrectionPtr_ *= ds.value();
}
}
template
void Foam::fvMatrix::operator/=
(
const volInternalScalarField& dsf
)
{
dimensions_ /= dsf.dimensions();
lduMatrix::operator/=(dsf.primitiveField());
source_ /= dsf.primitiveField();
forAll(boundaryCoeffs_, patchi)
{
scalarField pisf
(
dsf.mesh().boundary()[patchi].patchInternalField
(
dsf.primitiveField()
)
);
internalCoeffs_[patchi] /= pisf;
boundaryCoeffs_[patchi] /= pisf;
}
if (faceFluxCorrectionPtr_)
{
FatalErrorInFunction
<< "cannot scale a matrix containing a faceFluxCorrection"
<< abort(FatalError);
}
}
template
template
void Foam::fvMatrix::operator/=(const Expression& e)
{
dimensions_ /= expression::access(e, dimensions::invalid);
const scalarField sf
(
expression::access
(
e,
expression::Value(),
expression::Base()
)
);
lduMatrix::operator/=(sf);
source_ /= sf;
forAll(boundaryCoeffs_, patchi)
{
const scalarField pisf
(
mesh().boundary()[patchi].patchInternalField(sf)
);
internalCoeffs_[patchi] /= pisf;
boundaryCoeffs_[patchi] /= pisf;
}
if (faceFluxCorrectionPtr_)
{
FatalErrorInFunction
<< "cannot scale a matrix containing a faceFluxCorrection"
<< abort(FatalError);
}
}
template
void Foam::fvMatrix::operator/=
(
const tmp& tdsf
)
{
operator/=(tdsf());
tdsf.clear();
}
template
void Foam::fvMatrix::operator/=
(
const tmp& tvsf
)
{
operator/=(tvsf());
tvsf.clear();
}
template
void Foam::fvMatrix::operator/=
(
const dimensioned& ds
)
{
dimensions_ /= ds.dimensions();
lduMatrix::operator/=(ds.value());
source_ /= ds.value();
internalCoeffs_ /= ds.value();
boundaryCoeffs_ /= ds.value();
if (faceFluxCorrectionPtr_)
{
*faceFluxCorrectionPtr_ /= ds.value();
}
}
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template
void Foam::checkMethod
(
const fvMatrix& fvm1,
const fvMatrix& fvm2,
const char* op
)
{
if (&fvm1.psi() != &fvm2.psi())
{
FatalErrorInFunction
<< "incompatible fields for operation "
<< endl << " "
<< "[" << fvm1.psi().name() << "] "
<< op
<< " [" << fvm2.psi().name() << "]"
<< abort(FatalError);
}
if (dimensionSet::debug && fvm1.dimensions() != fvm2.dimensions())
{
FatalErrorInFunction
<< "incompatible dimensions for operation "
<< endl << " "
<< "[" << fvm1.psi().name()
<< fvm1.dimensions()/dimensions::volume << " ] "
<< op
<< " [" << fvm2.psi().name()
<< fvm2.dimensions()/dimensions::volume << " ]"
<< abort(FatalError);
}
}
template
void Foam::checkMethod
(
const fvMatrix& fvm,
const VolInternalField& df,
const char* op
)
{
if
(
dimensionSet::debug
&& fvm.dimensions()/dimensions::volume != df.dimensions()
)
{
FatalErrorInFunction
<< endl << " "
<< "[" << fvm.psi().name()
<< fvm.dimensions()/dimensions::volume << " ] "
<< op
<< " [" << df.name() << df.dimensions() << " ]"
<< abort(FatalError);
}
}
template
void Foam::checkMethod
(
const fvMatrix& fvm,
const Expression& e,
const char* op
)
{
if
(
dimensionSet::debug
&& fvm.dimensions()/dimensions::volume
!= expression::access(e, dimensions::invalid)
)
{
FatalErrorInFunction
<< "incompatible dimensions for operation "
<< endl << " "
<< "[" << fvm.psi().name()
<< fvm.dimensions()/dimensions::volume << " ] "
<< op
<< " ["
<< expression::name(e)
<< expression::access(e, dimensions::invalid)
<< " ]"
<< abort(FatalError);
}
}
template
void Foam::checkMethod
(
const fvMatrix& fvm,
const dimensioned& dt,
const char* op
)
{
if (dimensionSet::debug && fvm.dimensions()/dimVolume != dt.dimensions())
{
FatalErrorInFunction
<< "incompatible dimensions for operation "
<< endl << " "
<< "[" << fvm.psi().name() << fvm.dimensions()/dimVolume << " ] "
<< op
<< " [" << dt.name() << dt.dimensions() << " ]"
<< abort(FatalError);
}
}
template
Foam::tmp> Foam::correction
(
const fvMatrix& A
)
{
tmp> tAcorr = A - (A & A.psi());
// Delete the faceFluxCorrection from the correction matrix
// as it does not have a clear meaning or purpose
deleteDemandDrivenData(tAcorr.ref().faceFluxCorrectionPtr());
return tAcorr;
}
template
Foam::tmp> Foam::correction
(
const tmp>& tA
)
{
tmp> tAcorr = tA - (tA() & tA().psi());
// Delete the faceFluxCorrection from the correction matrix
// as it does not have a clear meaning or purpose
deleteDemandDrivenData(tAcorr.ref().faceFluxCorrectionPtr());
return tAcorr;
}
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
template
Foam::tmp> Foam::operator==
(
const fvMatrix& A,
const fvMatrix