diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.H index 5935fa8344..cfd9b93ab6 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,10 +34,10 @@ Description Usage \table - Property | Description | Required | Default value - field | name of field to be mapped | no | this field name - setAverage | flag to activate setting of average value | yes | - average | average value to apply if \c setAverage = yes | yes | + Property | Description | Required | Default + field | Name of field to be mapped | no | this field name + setAverage | Use average value | no | false | + average | Average value to use if \c setAverage = yes | partly | \endtable Example of the boundary condition specification: diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C index 11349a08ca..11062dff84 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,15 +27,28 @@ License #include "mappedPatchBase.H" #include "interpolationCell.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -namespace Foam +template +Type Foam::mappedPatchFieldBase::getAverage +( + const dictionary& dict, + const bool mandatory +) { + if (mandatory) + { + return dict.get("average"); + } + + return Zero; +} + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -mappedPatchFieldBase::mappedPatchFieldBase +Foam::mappedPatchFieldBase::mappedPatchFieldBase ( const mappedPatchBase& mapper, const fvPatchField& patchField, @@ -55,7 +68,7 @@ mappedPatchFieldBase::mappedPatchFieldBase template -mappedPatchFieldBase::mappedPatchFieldBase +Foam::mappedPatchFieldBase::mappedPatchFieldBase ( const mappedPatchBase& mapper, const fvPatchField& patchField, @@ -72,19 +85,19 @@ mappedPatchFieldBase::mappedPatchFieldBase patchField_.internalField().name() ) ), - setAverage_(readBool(dict.lookup("setAverage"))), - average_(pTraits(dict.lookup("average"))), + setAverage_(dict.lookupOrDefault("setAverage", false)), + average_(getAverage(dict, setAverage_)), interpolationScheme_(interpolationCell::typeName) { if (mapper_.mode() == mappedPatchBase::NEARESTCELL) { - dict.lookup("interpolationScheme") >> interpolationScheme_; + dict.read("interpolationScheme", interpolationScheme_); } } template -mappedPatchFieldBase::mappedPatchFieldBase +Foam::mappedPatchFieldBase::mappedPatchFieldBase ( const mappedPatchBase& mapper, const fvPatchField& patchField @@ -100,7 +113,7 @@ mappedPatchFieldBase::mappedPatchFieldBase template -mappedPatchFieldBase::mappedPatchFieldBase +Foam::mappedPatchFieldBase::mappedPatchFieldBase ( const mappedPatchFieldBase& mapper ) @@ -115,7 +128,7 @@ mappedPatchFieldBase::mappedPatchFieldBase template -mappedPatchFieldBase::mappedPatchFieldBase +Foam::mappedPatchFieldBase::mappedPatchFieldBase ( const mappedPatchBase& mapper, const fvPatchField& patchField, @@ -134,13 +147,11 @@ mappedPatchFieldBase::mappedPatchFieldBase // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -const GeometricField& -mappedPatchFieldBase::sampleField() const +const Foam::GeometricField& +Foam::mappedPatchFieldBase::sampleField() const { typedef GeometricField fieldType; - const fvMesh& nbrMesh = refCast(mapper_.sampleMesh()); - if (mapper_.sameRegion()) { if (fieldName_ == patchField_.internalField().name()) @@ -158,15 +169,15 @@ mappedPatchFieldBase::sampleField() const return thisMesh.template lookupObject(fieldName_); } } - else - { - return nbrMesh.template lookupObject(fieldName_); - } + + const fvMesh& nbrMesh = refCast(mapper_.sampleMesh()); + return nbrMesh.template lookupObject(fieldName_); } template -tmp> mappedPatchFieldBase::mappedField() const +Foam::tmp> +Foam::mappedPatchFieldBase::mappedField() const { typedef GeometricField fieldType; @@ -179,8 +190,8 @@ tmp> mappedPatchFieldBase::mappedField() const const fvMesh& nbrMesh = refCast(mapper_.sampleMesh()); // Result of obtaining remote values - tmp> tnewValues(new Field(0)); - Field& newValues = tnewValues.ref(); + auto tnewValues = tmp>::New(); + auto& newValues = tnewValues.ref(); switch (mapper_.mode()) { @@ -203,15 +214,14 @@ tmp> mappedPatchFieldBase::mappedField() const samples ); - autoPtr> interpolator - ( + auto interpolator = interpolation::New ( interpolationScheme_, sampleField() - ) - ); - const interpolation& interp = interpolator(); + ); + + const auto& interp = *interpolator; newValues.setSize(samples.size(), pTraits::max); forAll(samples, celli) @@ -263,10 +273,8 @@ tmp> mappedPatchFieldBase::mappedField() const const fieldType& nbrField = sampleField(); - forAll(nbrField.boundaryField(), patchi) + for (const fvPatchField& pf : nbrField.boundaryField()) { - const fvPatchField& pf = - nbrField.boundaryField()[patchi]; label faceStart = pf.patch().start(); forAll(pf, facei) @@ -283,8 +291,8 @@ tmp> mappedPatchFieldBase::mappedField() const default: { FatalErrorInFunction - << "Unknown sampling mode: " << mapper_.mode() - << nl << abort(FatalError); + << "Unknown sampling mode: " << mapper_.mode() << nl + << abort(FatalError); } } @@ -312,17 +320,18 @@ tmp> mappedPatchFieldBase::mappedField() const template -void mappedPatchFieldBase::write(Ostream& os) const +void Foam::mappedPatchFieldBase::write(Ostream& os) const { os.writeEntry("field", fieldName_); - os.writeEntry("setAverage", setAverage_); - os.writeEntry("average", average_); + + if (setAverage_) + { + os.writeEntry("setAverage", "true"); + os.writeEntry("average", average_); + } + os.writeEntry("interpolationScheme", interpolationScheme_); } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.H index 9b01540315..d5a6f05edf 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.H @@ -38,6 +38,14 @@ Description interpolationScheme cellPoint; // default is cell } + \table + Property | Description | Required | Default + field | name of field to be mapped | no | this field name + setAverage | use average value | no | false | + average | average value to apply if \c setAverage = yes | partly | + interpolationScheme | interpolation scheme | partly | cell | + \endtable + SourceFiles mappedPatchFieldBase.C @@ -54,6 +62,7 @@ SourceFiles namespace Foam { +// Forward declarations class mappedPatchBase; template class interpolation; @@ -64,6 +73,10 @@ template class interpolation; template class mappedPatchFieldBase { + // Private Member Functions + + //- Selective retrieval of "average" entry from the dictionary + static Type getAverage(const dictionary& dict, bool mandatory); protected: @@ -82,7 +95,7 @@ protected: const bool setAverage_; //- Average value the mapped field is adjusted to maintain if - // setAverage_ is set true + //- setAverage_ is set true const Type average_; //- Interpolation scheme to use for nearestcell mode @@ -135,11 +148,10 @@ public: //- Destructor - virtual ~mappedPatchFieldBase() - {} + virtual ~mappedPatchFieldBase() = default; - // Member functions + // Member Functions //- Field to sample. Either on my or nbr mesh const GeometricField& sampleField() const; @@ -148,7 +160,7 @@ public: virtual tmp> mappedField() const; //- Write - virtual void write(Ostream&) const; + virtual void write(Ostream& os) const; }; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.H index 1f03082b36..4d04d91407 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,10 +33,10 @@ Description Usage \table - Property | Description | Required | Default value - field | name of field to be mapped | no | this field name - setAverage | flag to activate setting of average value | yes | - average | average value to apply if \c setAverage = yes | yes | + Property | Description | Required | Default + field | name of field to be mapped | no | this field name + setAverage | Use average value | no | false + average | Average value to use if \c setAverage = yes | partly | \endtable \verbatim @@ -44,7 +44,7 @@ Usage { type mappedFixedInternalValue; field T; - setAverage no; + setAverage false; average 0; value uniform 0; } @@ -155,13 +155,11 @@ public: // Member functions - // Evaluation functions - - //- Update the coefficients associated with the patch field - virtual void updateCoeffs(); + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); //- Write - virtual void write(Ostream&) const; + virtual void write(Ostream& os) const; }; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedPushedInternalValue/mappedFixedPushedInternalValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedPushedInternalValue/mappedFixedPushedInternalValueFvPatchField.H index 5518aed14b..de26d8fc26 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedPushedInternalValue/mappedFixedPushedInternalValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedPushedInternalValue/mappedFixedPushedInternalValueFvPatchField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,10 +33,10 @@ Description Usage \table - Property | Description | Required | Default value - field | name of field to be mapped | no | this field name - setAverage | flag to activate setting of average value | yes | - average | average value to apply if \c setAverage = yes | yes | + Property | Description | Required | Default + field | name of field to be mapped | no | this field name + setAverage | Use average value | no | false | + average | Average value to use if \c setAverage = yes | partly | \endtable Example of the boundary condition specification: diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.H index 56201907d8..c7e2b61543 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,11 +36,11 @@ Description Usage \table - Property | Description | Required | Default value - field | name of field to be mapped | no | this field name - setAverage | flag to activate setting of average value | yes | - average | average value to apply if \c setAverage = yes | yes | - interpolationScheme | type of interpolation scheme | no | + Property | Description | Required | Default + field | Field name to be mapped | no | this field name + setAverage | Use average value | no | false + average | Average value to use if \c setAverage = yes | partly | + interpolationScheme | type of interpolation scheme | partly | \endtable Example of the boundary condition specification: diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C index ed865e049a..5f0ae2eee0 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C @@ -580,7 +580,10 @@ void Foam::timeVaryingMappedFixedValueFvPatchField::write fieldTableName_ ); - os.writeEntryIfDifferent("setAverage", Switch(false), setAverage_); + if (setAverage_) + { + os.writeEntry("setAverage", setAverage_); + } os.writeEntryIfDifferent("perturb", 1e-5, perturb_); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H index 46f720a723..d832ee1ae8 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H @@ -47,13 +47,13 @@ Description Usage \table - Property | Description | Required | Default value - setAverage | Switch to activate setting of average value | no | false - perturb | Perturb points for regular geometries | no | 1e-5 - points | Name of points file | no | points + Property | Description | Required | Default + setAverage | Use average value | no | false + perturb | Perturb points for regular geometries | no | 1e-5 + points | Name of points file | no | points fieldTable | Alternative field name to sample | no | this field name - mapMethod | Type of mapping | no | planarInterpolation - offset | Offset to mapped values | no | Zero + mapMethod | Type of mapping | no | planarInterpolation + offset | Offset to mapped values | no | Zero \endtable \verbatim