/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 "mixedFvPatchField.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template bool Foam::mixedFvPatchField::readMixedEntries ( const dictionary& dict, IOobjectOption::readOption readOpt ) { if (!IOobjectOption::isAnyRead(readOpt)) return false; const auto& p = fvPatchFieldBase::patch(); // If there is a 'refValue', also require all others const auto* hasValue = dict.findEntry("refValue", keyType::LITERAL); if (!hasValue && IOobjectOption::isReadOptional(readOpt)) { return false; } const auto* hasGrad = dict.findEntry("refGradient", keyType::LITERAL); const auto* hasFrac = dict.findEntry("valueFraction", keyType::LITERAL); // Combined error message on failure if (!hasValue || !hasGrad || !hasFrac) { FatalIOErrorInFunction(dict) << "Required entries:"; if (!hasValue) FatalIOError << " 'refValue'"; if (!hasGrad) FatalIOError << " 'refGradient'"; if (!hasFrac) FatalIOError << " 'valueFraction'"; FatalIOError << " : missing for patch " << p.name() << " : in dictionary " << dict.relativeName() << nl << exit(FatalIOError); } // Everything verified - can assign refValue_.assign(*hasValue, p.size()); refGrad_.assign(*hasGrad, p.size()); valueFraction_.assign(*hasFrac, p.size()); return true; } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::mixedFvPatchField::mixedFvPatchField ( const fvPatch& p, const DimensionedField& iF ) : fvPatchField(p, iF), refValue_(p.size()), refGrad_(p.size()), valueFraction_(p.size()), source_(p.size(), Zero) {} template Foam::mixedFvPatchField::mixedFvPatchField ( const fvPatch& p, const DimensionedField& iF, const Foam::zero ) : fvPatchField(p, iF), refValue_(p.size(), Zero), refGrad_(p.size(), Zero), valueFraction_(p.size(), Zero), source_(p.size(), Zero) {} template Foam::mixedFvPatchField::mixedFvPatchField ( const fvPatch& p, const DimensionedField& iF, const dictionary& dict, IOobjectOption::readOption requireMixed ) : // The "value" entry is not required fvPatchField(p, iF, dict, IOobjectOption::NO_READ), refValue_(p.size()), refGrad_(p.size()), valueFraction_(p.size()), source_(p.size(), Zero) { if (!readMixedEntries(dict, requireMixed)) { // Not read (eg, optional and missing): no evaluate possible/need return; } // Could also check/clamp fraction to 0-1 range evaluate(); } template Foam::mixedFvPatchField::mixedFvPatchField ( const mixedFvPatchField& ptf, const fvPatch& p, const DimensionedField& iF, const fvPatchFieldMapper& mapper ) : fvPatchField(ptf, p, iF, mapper), refValue_(ptf.refValue_, mapper), refGrad_(ptf.refGrad_, mapper), valueFraction_(ptf.valueFraction_, mapper), source_(ptf.source_, mapper) { if (notNull(iF) && mapper.hasUnmapped()) { WarningInFunction << "On field " << iF.name() << " patch " << p.name() << " patchField " << this->type() << " : mapper does not map all values." << nl << " To avoid this warning fully specify the mapping in derived" << " patch fields." << endl; } } template Foam::mixedFvPatchField::mixedFvPatchField ( const mixedFvPatchField& ptf ) : fvPatchField(ptf), refValue_(ptf.refValue_), refGrad_(ptf.refGrad_), valueFraction_(ptf.valueFraction_), source_(ptf.source_) {} template Foam::mixedFvPatchField::mixedFvPatchField ( const mixedFvPatchField& ptf, const DimensionedField& iF ) : fvPatchField(ptf, iF), refValue_(ptf.refValue_), refGrad_(ptf.refGrad_), valueFraction_(ptf.valueFraction_), source_(ptf.source_) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template void Foam::mixedFvPatchField::autoMap ( const fvPatchFieldMapper& m ) { fvPatchField::autoMap(m); refValue_.autoMap(m); refGrad_.autoMap(m); valueFraction_.autoMap(m); source_.autoMap(m); } template void Foam::mixedFvPatchField::rmap ( const fvPatchField& ptf, const labelList& addr ) { fvPatchField::rmap(ptf, addr); const mixedFvPatchField& mptf = refCast>(ptf); refValue_.rmap(mptf.refValue_, addr); refGrad_.rmap(mptf.refGrad_, addr); valueFraction_.rmap(mptf.valueFraction_, addr); source_.rmap(mptf.source_, addr); } template void Foam::mixedFvPatchField::evaluate(const Pstream::commsTypes) { if (!this->updated()) { this->updateCoeffs(); } Field::operator= ( lerp ( this->patchInternalField() + refGrad_/this->patch().deltaCoeffs(), refValue_, valueFraction_ ) ); fvPatchField::evaluate(); } template Foam::tmp> Foam::mixedFvPatchField::snGrad() const { return lerp ( refGrad_, (refValue_ - this->patchInternalField())*this->patch().deltaCoeffs(), valueFraction_ ); } template Foam::tmp> Foam::mixedFvPatchField::valueInternalCoeffs ( const tmp& ) const { return Type(pTraits::one)*(1.0 - valueFraction_); } template Foam::tmp> Foam::mixedFvPatchField::valueBoundaryCoeffs ( const tmp& ) const { return lerp ( refGrad_/this->patch().deltaCoeffs(), refValue_, valueFraction_ ); } template Foam::tmp> Foam::mixedFvPatchField::gradientInternalCoeffs() const { return -Type(pTraits::one)*valueFraction_*this->patch().deltaCoeffs(); } template Foam::tmp> Foam::mixedFvPatchField::gradientBoundaryCoeffs() const { return lerp ( refGrad_, this->patch().deltaCoeffs()*refValue_, valueFraction_ ); } template void Foam::mixedFvPatchField::write(Ostream& os) const { fvPatchField::write(os); refValue_.writeEntry("refValue", os); refGrad_.writeEntry("refGradient", os); valueFraction_.writeEntry("valueFraction", os); source_.writeEntry("source", os); fvPatchField::writeValueEntry(os); } // ************************************************************************* //