/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd 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 "mixedFaPatchField.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template bool Foam::mixedFaPatchField::readMixedEntries ( const dictionary& dict, IOobjectOption::readOption readOpt ) { if (!IOobjectOption::isAnyRead(readOpt)) return false; const auto& p = faPatchFieldBase::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::mixedFaPatchField::mixedFaPatchField ( const faPatch& p, const DimensionedField& iF ) : faPatchField(p, iF), refValue_(p.size()), refGrad_(p.size()), valueFraction_(p.size()) {} template Foam::mixedFaPatchField::mixedFaPatchField ( const faPatch& p, const DimensionedField& iF, const Foam::zero ) : faPatchField(p, iF), refValue_(p.size(), Zero), refGrad_(p.size(), Zero), valueFraction_(p.size(), Zero) {} template Foam::mixedFaPatchField::mixedFaPatchField ( const faPatch& p, const DimensionedField& iF, const dictionary& dict, IOobjectOption::readOption requireMixed ) : // The "value" entry is not required faPatchField(p, iF, dict, IOobjectOption::NO_READ), refValue_(p.size()), refGrad_(p.size()), valueFraction_(p.size()) { 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::mixedFaPatchField::mixedFaPatchField ( const mixedFaPatchField& ptf, const faPatch& p, const DimensionedField& iF, const faPatchFieldMapper& mapper ) : faPatchField(ptf, p, iF, mapper), refValue_(ptf.refValue_, mapper), refGrad_(ptf.refGrad_, mapper), valueFraction_(ptf.valueFraction_, mapper) {} template Foam::mixedFaPatchField::mixedFaPatchField ( const mixedFaPatchField& ptf ) : faPatchField(ptf), refValue_(ptf.refValue_), refGrad_(ptf.refGrad_), valueFraction_(ptf.valueFraction_) {} template Foam::mixedFaPatchField::mixedFaPatchField ( const mixedFaPatchField& ptf, const DimensionedField& iF ) : faPatchField(ptf, iF), refValue_(ptf.refValue_), refGrad_(ptf.refGrad_), valueFraction_(ptf.valueFraction_) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template void Foam::mixedFaPatchField::autoMap ( const faPatchFieldMapper& m ) { Field::autoMap(m); refValue_.autoMap(m); refGrad_.autoMap(m); valueFraction_.autoMap(m); } template void Foam::mixedFaPatchField::rmap ( const faPatchField& ptf, const labelList& addr ) { faPatchField::rmap(ptf, addr); const auto& mptf = refCast>(ptf); refValue_.rmap(mptf.refValue_, addr); refGrad_.rmap(mptf.refGrad_, addr); valueFraction_.rmap(mptf.valueFraction_, addr); } template void Foam::mixedFaPatchField::evaluate(const Pstream::commsTypes) { if (!this->updated()) { this->updateCoeffs(); } Field::operator= ( lerp ( this->patchInternalField() + refGrad_/this->patch().deltaCoeffs(), refValue_, valueFraction_ ) ); faPatchField::evaluate(); } template Foam::tmp> Foam::mixedFaPatchField::snGrad() const { return lerp ( refGrad_, (refValue_ - this->patchInternalField())*this->patch().deltaCoeffs(), valueFraction_ ); } template Foam::tmp> Foam::mixedFaPatchField::valueInternalCoeffs ( const tmp& ) const { return Type(pTraits::one)*(1.0 - valueFraction_); } template Foam::tmp> Foam::mixedFaPatchField::valueBoundaryCoeffs ( const tmp& ) const { return lerp ( refGrad_/this->patch().deltaCoeffs(), refValue_, valueFraction_ ); } template Foam::tmp> Foam::mixedFaPatchField::gradientInternalCoeffs() const { return -Type(pTraits::one)*valueFraction_*this->patch().deltaCoeffs(); } template Foam::tmp> Foam::mixedFaPatchField::gradientBoundaryCoeffs() const { return lerp ( refGrad_, this->patch().deltaCoeffs()*refValue_, valueFraction_ ); } template void Foam::mixedFaPatchField::write(Ostream& os) const { faPatchField::write(os); refValue_.writeEntry("refValue", os); refGrad_.writeEntry("refGradient", os); valueFraction_.writeEntry("valueFraction", os); faPatchField::writeValueEntry(os); } // ************************************************************************* //