diff --git a/src/finiteVolume/fields/fvPatchFields/derived/freestream/freestreamFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/freestream/freestreamFvPatchField.C index eac0fe4feb..8dcccfd422 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/freestream/freestreamFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/freestream/freestreamFvPatchField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,7 +34,8 @@ Foam::freestreamFvPatchField::freestreamFvPatchField const DimensionedField& iF ) : - inletOutletFvPatchField(p, iF) + inletOutletFvPatchField(p, iF), + freestreamBCPtr_() {} @@ -46,25 +47,43 @@ Foam::freestreamFvPatchField::freestreamFvPatchField const dictionary& dict ) : - inletOutletFvPatchField(p, iF) + inletOutletFvPatchField(p, iF), + freestreamBCPtr_() { this->patchType() = dict.lookupOrDefault("patchType", word::null); this->phiName_ = dict.lookupOrDefault("phi","phi"); - freestreamValue() = Field("freestreamValue", dict, p.size()); - - if (dict.found("value")) + if (dict.found("freestreamValue")) { + freestreamValue() = + Field("freestreamValue", dict, p.size()); + + if (dict.found("value")) + { + fvPatchField::operator= + ( + Field("value", dict, p.size()) + ); + } + else + { + fvPatchField::operator=(freestreamValue()); + } + } + else + { + // Freestream value provided by another patch + freestreamBCPtr_ = + fvPatchField::New(p, iF, dict.subDict("freestreamBC")); + + // Force user to supply an initial value + // - we do not know if the supplied BC has all dependencies available fvPatchField::operator= ( Field("value", dict, p.size()) ); } - else - { - fvPatchField::operator=(freestreamValue()); - } } @@ -77,8 +96,15 @@ Foam::freestreamFvPatchField::freestreamFvPatchField const fvPatchFieldMapper& mapper ) : - inletOutletFvPatchField(ptf, p, iF, mapper) -{} + inletOutletFvPatchField(ptf, p, iF, mapper), + freestreamBCPtr_() +{ + if (ptf.freestreamBCPtr_.valid()) + { + freestreamBCPtr_ = + fvPatchField::New(ptf.freestreamBCPtr_(), p, iF, mapper); + } +} template @@ -87,8 +113,14 @@ Foam::freestreamFvPatchField::freestreamFvPatchField const freestreamFvPatchField& ptf ) : - inletOutletFvPatchField(ptf) -{} + inletOutletFvPatchField(ptf), + freestreamBCPtr_() +{ + if (ptf.freestreamBCPtr_.valid()) + { + freestreamBCPtr_ = ptf.freestreamBCPtr_->clone(); + } +} template @@ -98,18 +130,81 @@ Foam::freestreamFvPatchField::freestreamFvPatchField const DimensionedField& iF ) : - inletOutletFvPatchField(ptf, iF) -{} + inletOutletFvPatchField(ptf, iF), + freestreamBCPtr_() +{ + if (ptf.freestreamBCPtr_.valid()) + { + freestreamBCPtr_ = ptf.freestreamBCPtr_->clone(); + } +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::freestreamFvPatchField::autoMap(const fvPatchFieldMapper& m) +{ + inletOutletFvPatchField::autoMap(m); + if (freestreamBCPtr_.valid()) + { + freestreamBCPtr_->autoMap(m); + } +} + + +template +void Foam::freestreamFvPatchField::rmap +( + const fvPatchField& ptf, + const labelList& addr +) +{ + inletOutletFvPatchField::rmap(ptf, addr); + + const auto& fsptf = refCast>(ptf); + + if (fsptf.freestreamBCPtr_.valid()) + { + freestreamBCPtr_->rmap(fsptf.freestreamBCPtr_(), addr); + } +} + + +template +void Foam::freestreamFvPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + if (freestreamBCPtr_.valid()) + { + freestreamBCPtr_->evaluate(); + freestreamValue() = freestreamBCPtr_(); + } + + inletOutletFvPatchField::updateCoeffs(); +} + + template void Foam::freestreamFvPatchField::write(Ostream& os) const { fvPatchField::write(os); os.writeEntryIfDifferent("phi", "phi", this->phiName_); - freestreamValue().writeEntry("freestreamValue", os); + + if (freestreamBCPtr_.valid()) + { + os.beginBlock("freestreamBC"); + freestreamBCPtr_->write(os); + os.endBlock(); + } + else + { + freestreamValue().writeEntry("freestreamValue", os); + } this->writeEntry("value", os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/freestream/freestreamFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/freestream/freestreamFvPatchField.H index 15757c90cf..ff860522d8 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/freestream/freestreamFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/freestream/freestreamFvPatchField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,12 +35,14 @@ Description Usage \table - Property | Description | Required | Default value - freestreamValue | freestream velocity | yes | - phi | flux field name | no | phi + Property | Description | Required | Default value + freestreamValue | freestream velocity | no | + freestreamBC | patchField providing the inlet field | no | + phi | flux field name | no | phi \endtable - Example of the boundary condition specification: + Example of the boundary condition specification using a fixed value + inlet condition: \verbatim { @@ -49,6 +51,26 @@ Usage } \endverbatim + Example of the boundary condition specification using a separate condition + to proveide the inlet condition: + \verbatim + + { + type freestream; + freestreamBC + { + type atmBoundaryLayerInletVelocity; + flowDir (1 0 0); + zDir (0 0 1); + Uref 20; + Zref 20; + z0 uniform 0.1; + zGround uniform 935; + } + } + \endverbatim + + See also Foam::mixedFvPatchField Foam::inletOutletFvPatchField @@ -77,6 +99,11 @@ class freestreamFvPatchField : public inletOutletFvPatchField { + // Private data + + //- BC to supply the freestream value + tmp> freestreamBCPtr_; + public: @@ -147,6 +174,22 @@ public: // Member functions + // Mapping functions + + //- Map (and resize as needed) from self given a mapping object + virtual void autoMap(const fvPatchFieldMapper& mapper); + + //- Reverse map the given fvPatchField onto this fvPatchField + virtual void rmap + ( + const fvPatchField& ptf, + const labelList& addr + ); + + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + // Return defining fields const Field& freestreamValue() const