diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C index d66f2c7633bba77a713be2a0a92051def689e749..53a26f00ba328e93a55bbc163b719a9a16ee792a 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C @@ -123,6 +123,23 @@ void Foam::pointPatchField<Type>::write(Ostream& os) const } +template<class Type> +template<class EntryType> +void Foam::pointPatchField<Type>::writeEntryIfDifferent +( + Ostream& os, + const word& entryName, + const EntryType& value1, + const EntryType& value2 +) const +{ + if (value1 != value2) + { + os.writeKeyword(entryName) << value2 << token::END_STATEMENT << nl; + } +} + + template<class Type> Foam::tmp<Foam::Field<Type>> Foam::pointPatchField<Type>::patchInternalField() const diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H index 5db051b1dc0a6517545ce118f9abf389298d9ad4..34b0e6336ef4e310c967188e37ae1becd443033e 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H @@ -429,8 +429,21 @@ public: ); - //- Write - virtual void write(Ostream&) const; + // I-O + + //- Write + virtual void write(Ostream&) const; + + //- Helper function to write the keyword and entry only if the + // values are not equal. The value is then output as value2 + template<class EntryType> + void writeEntryIfDifferent + ( + Ostream& os, + const word& entryName, + const EntryType& value1, + const EntryType& value2 + ) const; // Member operators diff --git a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.C b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.C index d1b5f3288575beb960654719845ac82559043fef..3f53313f68d14b033cf32ef6ae898cb87cba6d67 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.C +++ b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.C @@ -27,6 +27,18 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +template<class Type> +Foam::Function1Types::Constant<Type>::Constant +( + const word& entryName, + const Type& val +) +: + Function1<Type>(entryName), + value_(val) +{} + + template<class Type> Foam::Function1Types::Constant<Type>::Constant ( diff --git a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H index 20b8a687084b9c98971e446c3c5bf58086725df7..ddfbcdf84b61752432d93b36842fee30ef4a4cce 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H +++ b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H @@ -78,6 +78,9 @@ public: // Constructors + //- Construct from entry name and value + Constant(const word& entryName, const Type& val); + //- Construct from entry name and dictionary Constant(const word& entryName, const dictionary& dict); diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 7862b70de251eab2b9fa2ba1ec559f1ff8dedf96..2f4ed7e376932df15105fa1acf64ef05f2b95bfe 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -180,7 +180,6 @@ $(derivedFvPatchFields)/supersonicFreestream/supersonicFreestreamFvPatchVectorFi $(derivedFvPatchFields)/surfaceNormalFixedValue/surfaceNormalFixedValueFvPatchVectorField.C $(derivedFvPatchFields)/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C $(derivedFvPatchFields)/syringePressure/syringePressureFvPatchScalarField.C -$(derivedFvPatchFields)/timeVaryingMappedFixedValue/AverageIOFields.C $(derivedFvPatchFields)/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchFields.C $(derivedFvPatchFields)/totalPressure/totalPressureFvPatchScalarField.C $(derivedFvPatchFields)/totalTemperature/totalTemperatureFvPatchScalarField.C diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.C similarity index 65% rename from src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOField.C rename to src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.C index c8099fe94bba6ebd4cebb2fb1661bd40ba8c7e9e..c631dfb1fda89ac4226844ebac924ce41d7814be 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.C @@ -23,65 +23,60 @@ License \*---------------------------------------------------------------------------*/ -#include "AverageIOField.H" +#include "AverageField.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type> -Foam::AverageIOField<Type>::AverageIOField -( - const IOobject& io -) +Foam::AverageField<Type>::AverageField(const label size) : - regIOobject(io) -{ - readStream(typeName) >> average_; - readStream(typeName) >> static_cast<Field<Type>&>(*this); - close(); -} - - -template<class Type> -Foam::AverageIOField<Type>::AverageIOField -( - const IOobject& io, - const label size -) -: - regIOobject(io), Field<Type>(size), average_(Zero) {} template<class Type> -Foam::AverageIOField<Type>::AverageIOField +Foam::AverageField<Type>::AverageField ( - const IOobject& io, - const Type& average, - const Field<Type>& f + const Field<Type>& f, + const Type& average ) : - regIOobject(io), Field<Type>(f), average_(average) +{} + + +template<class Type> +Foam::AverageField<Type>::AverageField(Istream& is) +: + Field<Type>(is), + average_(pTraits<Type>(is)) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +const Type& Foam::AverageField<Type>::average() const +{ + return average_; +} + + +template<class Type> +Type&Foam::AverageField<Type>::average() { - if (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - { - readStream(typeName) - >> average_ - >> static_cast<Field<Type>&>(*this); - close(); - } + return average_; } template<class Type> -bool Foam::AverageIOField<Type>::writeData(Ostream& os) const +bool Foam::AverageField<Type>::writeData(Ostream& os) const { - os << average_ + os << static_cast<const Field<Type>&>(*this) << token::NL - << static_cast<const Field<Type>&>(*this); + << average_; return os.good(); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOField.H b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.H similarity index 70% rename from src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOField.H rename to src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.H index bfac39700068a49cae5f973d38df8ece24acf4a4..818f2bdc1d2b79bef48b72b5c9415676259527fd 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.H @@ -22,20 +22,19 @@ License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Class - Foam::AverageIOField + Foam::AverageField Description - A primitive field + average with IO. + A primitive field with a separate average value. SourceFiles - AverageIOField.C + AverageField.C \*---------------------------------------------------------------------------*/ -#ifndef AverageIOField_H -#define AverageIOField_H +#ifndef AverageField_H +#define AverageField_H -#include "regIOobject.H" #include "Field.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -44,13 +43,12 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class AverageIOField Declaration + Class AverageField Declaration \*---------------------------------------------------------------------------*/ template<class Type> -class AverageIOField +class AverageField : - public regIOobject, public Field<Type> { // Private data @@ -61,44 +59,23 @@ class AverageIOField public: - TypeName("AverageField"); - - // Constructors - //- Construct from IOobject - AverageIOField - ( - const IOobject& - ); - - //- Construct from IOobject and size (does not set values) - AverageIOField - ( - const IOobject&, - const label size - ); + //- Construct from size (does not set values) + AverageField(const label size); //- Construct from components - AverageIOField - ( - const IOobject&, - const Type& average, - const Field<Type>& - ); + AverageField(const Field<Type>&, const Type& average); + + //- Construct from Istream + AverageField(Istream&); // Member functions - const Type& average() const - { - return average_; - } + const Type& average() const; - Type& average() - { - return average_; - } + Type& average(); bool writeData(Ostream& os) const; }; @@ -111,7 +88,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository - #include "AverageIOField.C" + #include "AverageField.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOFields.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOFields.C deleted file mode 100644 index 8c7f50481dd15bc8d72315f3133e3c3450cf9c54..0000000000000000000000000000000000000000 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageIOFields.C +++ /dev/null @@ -1,78 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011 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 <http://www.gnu.org/licenses/>. - -Description - -\*---------------------------------------------------------------------------*/ - -#include "AverageIOField.H" -#include "fieldTypes.H" - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -typedef AverageIOField<scalar> scalarAverageIOField; -typedef AverageIOField<vector> vectorAverageIOField; -typedef AverageIOField<sphericalTensor> sphericalTensorAverageIOField; -typedef AverageIOField<symmTensor> symmTensorAverageIOField; -typedef AverageIOField<tensor> tensorAverageIOField; - -defineTemplateTypeNameAndDebugWithName -( - scalarAverageIOField, - "scalarAverageField", - 0 -); -defineTemplateTypeNameAndDebugWithName -( - vectorAverageIOField, - "vectorAverageField", - 0 -); -defineTemplateTypeNameAndDebugWithName -( - sphericalTensorAverageIOField, - "sphericalTensorAverageField", - 0 -); -defineTemplateTypeNameAndDebugWithName -( - symmTensorAverageIOField, - "symmTensorAverageField", - 0 -); -defineTemplateTypeNameAndDebugWithName -( - tensorAverageIOField, - "tensorAverageField", - 0 -); - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C index 18fe4b4ea7d67063efdd824ccae4e8485d1ca8b5..df0623bde1c969e071059045e4808bd49e11204d 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C @@ -25,6 +25,7 @@ License #include "timeVaryingMappedFixedValueFvPatchField.H" #include "Time.H" +#include "AverageField.H" #include "IFstream.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -64,7 +65,7 @@ timeVaryingMappedFixedValueFvPatchField : fixedValueFvPatchField<Type>(p, iF), fieldTableName_(iF.name()), - setAverage_(readBool(dict.lookup("setAverage"))), + setAverage_(dict.lookupOrDefault("setAverage", false)), perturb_(dict.lookupOrDefault("perturb", 1e-5)), mapMethod_ ( @@ -82,8 +83,13 @@ timeVaryingMappedFixedValueFvPatchField endSampleTime_(-1), endSampledValues_(0), endAverage_(Zero), - offset_(Function1<Type>::New("offset", dict)) + offset_() { + if (dict.found("offset")) + { + offset_ = Function1<Type>::New("offset", dict); + } + if ( mapMethod_ != "planarInterpolation" @@ -97,7 +103,6 @@ timeVaryingMappedFixedValueFvPatchField << ", 'nearest'" << exit(FatalIOError); } - dict.readIfPresent("fieldTable", fieldTableName_); if (dict.found("value")) @@ -251,20 +256,6 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::checkTable() pointField samplePoints((IFstream(samplePointsFile)())); - // pointIOField samplePoints - // ( - // IOobject - // ( - // "points", - // this->db().time().constant(), - // "boundaryData"/this->patch().name(), - // this->db(), - // IOobject::MUST_READ, - // IOobject::AUTO_WRITE, - // false - // ) - // ); - if (debug) { Info<< "timeVaryingMappedFixedValueFvPatchField :" @@ -376,22 +367,18 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::checkTable() /fieldTableName_ ); - Field<Type> vals((IFstream(valsFile)())); - // IOField<Type> vals - // ( - // IOobject - // ( - // fieldTableName_, - // this->db().time().constant(), - // "boundaryData" - // /this->patch().name() - // /sampleTimes_[startSampleTime_].name(), - // this->db(), - // IOobject::MUST_READ, - // IOobject::AUTO_WRITE, - // false - // ) - // ); + Field<Type> vals; + + if (setAverage_) + { + AverageField<Type> avals((IFstream(valsFile)())); + vals = avals; + startAverage_ = avals.average(); + } + else + { + IFstream(valsFile)() >> vals; + } if (vals.size() != mapperPtr_().sourceSize()) { @@ -402,7 +389,6 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::checkTable() << ") in file " << valsFile << exit(FatalError); } - //startAverage_ = vals.average(); startSampledValues_ = mapperPtr_().interpolate(vals); } } @@ -432,32 +418,37 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::checkTable() } // Reread values and interpolate - IOField<Type> vals + fileName valsFile ( - IOobject - ( - fieldTableName_, - this->db().time().constant(), - "boundaryData" - /this->patch().name() - /sampleTimes_[endSampleTime_].name(), - this->db(), - IOobject::MUST_READ, - IOobject::AUTO_WRITE, - false - ) + this->db().time().constant() + /"boundaryData" + /this->patch().name() + /sampleTimes_[endSampleTime_].name() + /fieldTableName_ ); + Field<Type> vals; + + if (setAverage_) + { + AverageField<Type> avals((IFstream(valsFile)())); + vals = avals; + endAverage_ = avals.average(); + } + else + { + IFstream(valsFile)() >> vals; + } + if (vals.size() != mapperPtr_().sourceSize()) { FatalErrorInFunction << "Number of values (" << vals.size() << ") differs from the number of points (" << mapperPtr_().sourceSize() - << ") in file " << vals.objectPath() << exit(FatalError); + << ") in file " << valsFile << exit(FatalError); } - //endAverage_ = vals.average(); endSampledValues_ = mapperPtr_().interpolate(vals); } } @@ -481,7 +472,7 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::updateCoeffs() if (endSampleTime_ == -1) { - // only start value + // Only start value if (debug) { Pout<< "updateCoeffs : Sampled, non-interpolated values" @@ -554,9 +545,12 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::updateCoeffs() } } - // apply offset to mapped values - const scalar t = this->db().time().timeOutputValue(); - this->operator==(*this + offset_->value(t)); + // Apply offset to mapped values + if (offset_.valid()) + { + const scalar t = this->db().time().timeOutputValue(); + this->operator==(*this + offset_->value(t)); + } if (debug) { @@ -576,32 +570,32 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::write ) const { fvPatchField<Type>::write(os); - os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl; - if (perturb_ != 1e-5) - { - os.writeKeyword("perturb") << perturb_ << token::END_STATEMENT << nl; - } - if (fieldTableName_ != this->internalField().name()) - { - os.writeKeyword("fieldTable") << fieldTableName_ - << token::END_STATEMENT << nl; - } + this->writeEntryIfDifferent(os, "setAverage", Switch(false), setAverage_); - if + this->writeEntryIfDifferent(os, "perturb", 1e-5, perturb_); + + this->writeEntryIfDifferent ( - ( - !mapMethod_.empty() - && mapMethod_ != "planarInterpolation" - ) - ) + os, + "fieldTable", + this->internalField().name(), + fieldTableName_ + ); + + this->writeEntryIfDifferent + ( + os, + "mapMethod", + word("planarInterpolation"), + mapMethod_ + ); + + if (offset_.valid()) { - os.writeKeyword("mapMethod") << mapMethod_ - << token::END_STATEMENT << nl; + offset_->writeData(os); } - offset_->writeData(os); - this->writeEntry("value", os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H index 3b39993171028d30caa3352c406e9eb72c6b6293..3de912acf78cc4cbecf4405b548128b6aac09c8a 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H @@ -29,38 +29,36 @@ Group Description This boundary conditions interpolates the values from a set of supplied - points in space and time. Supplied data should be specified in - constant/boundaryData/\<patchname\> where: - - points : pointField with locations - - ddd : supplied values at time ddd - The default mode of operation (mapMethod planarInterpolation) is - to project the points onto a plane (constructed from the first threee - points) and construct a 2D triangulation and finds for the face centres - the triangle it is in and the weights to the 3 vertices. - - The optional mapMethod nearest will avoid all projection and - triangulation and just use the value at the nearest vertex. + points in space and time. + + Supplied data should be specified in constant/boundaryData/\<patchname\>/ + - points : pointField of locations + - \<time\>/\<field\> : field of values at time \<time\> + + The default mode of operation (mapMethod planarInterpolation) is to project + the points onto a plane (constructed from the first threee points) and + construct a 2D triangulation and finds for the face centres the triangle it + is in and the weights to the 3 vertices. + + The optional mapMethod nearest will avoid all projection and triangulation + and just use the value at the nearest vertex. Values are interpolated linearly between times. Usage \table - Property | Description | Required | Default value - setAverage | flag to activate setting of average value | yes | - perturb | perturb points for regular geometries | no | 1e-5 - fieldTableName | alternative field name to sample | no| this field name - mapMethod | type of mapping | no | planarInterpolation - offset | for applying offset to mapped values | no | constant 0.0 + Property | Description | Required | Default value + setAverage | Switch to activate setting of average value | no | false + perturb | Perturb points for regular geometries | no | 1e-5 + fieldTableName | Alternative field name to sample | no| this field name + mapMethod | Type of mapping | no | planarInterpolation + offset | Offset to mapped values | no | Zero \endtable \verbatim <patchName> { type timeVaryingMappedFixedValue; - setAverage false; - //perturb 0.0; - //fieldTableName samples; - //offset constant 0.2; } \endverbatim @@ -102,7 +100,7 @@ class timeVaryingMappedFixedValueFvPatchField word fieldTableName_; //- If true adjust the mapped field to maintain average value - bool setAverage_; + Switch setAverage_; //- Fraction of perturbation (fraction of bounding box) to add scalar perturb_; diff --git a/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.C b/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.C index 5fdac87571377dba85a468de2f89d3f3cdc96d5f..fac9f475b3e0ca93e784f350c56dbd8ba4bf14aa 100644 --- a/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.C +++ b/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.C @@ -25,13 +25,13 @@ License #include "timeVaryingMappedFixedValuePointPatchField.H" #include "Time.H" -#include "AverageIOField.H" +#include "AverageField.H" +#include "IFstream.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type> -Foam:: -timeVaryingMappedFixedValuePointPatchField<Type>:: +Foam::timeVaryingMappedFixedValuePointPatchField<Type>:: timeVaryingMappedFixedValuePointPatchField ( const pointPatch& p, @@ -55,41 +55,7 @@ timeVaryingMappedFixedValuePointPatchField template<class Type> -Foam:: -timeVaryingMappedFixedValuePointPatchField<Type>:: -timeVaryingMappedFixedValuePointPatchField -( - const timeVaryingMappedFixedValuePointPatchField<Type>& ptf, - const pointPatch& p, - const DimensionedField<Type, pointMesh>& iF, - const pointPatchFieldMapper& mapper -) -: - fixedValuePointPatchField<Type>(ptf, p, iF, mapper), - fieldTableName_(ptf.fieldTableName_), - setAverage_(ptf.setAverage_), - perturb_(ptf.perturb_), - mapMethod_(ptf.mapMethod_), - mapperPtr_(NULL), - sampleTimes_(0), - startSampleTime_(-1), - startSampledValues_(0), - startAverage_(Zero), - endSampleTime_(-1), - endSampledValues_(0), - endAverage_(Zero), - offset_ - ( - ptf.offset_.valid() - ? ptf.offset_().clone().ptr() - : NULL - ) -{} - - -template<class Type> -Foam:: -timeVaryingMappedFixedValuePointPatchField<Type>:: +Foam::timeVaryingMappedFixedValuePointPatchField<Type>:: timeVaryingMappedFixedValuePointPatchField ( const pointPatch& p, @@ -99,7 +65,7 @@ timeVaryingMappedFixedValuePointPatchField : fixedValuePointPatchField<Type>(p, iF), fieldTableName_(iF.name()), - setAverage_(readBool(dict.lookup("setAverage"))), + setAverage_(dict.lookupOrDefault("setAverage", false)), perturb_(dict.lookupOrDefault("perturb", 1e-5)), mapMethod_ ( @@ -124,6 +90,19 @@ timeVaryingMappedFixedValuePointPatchField offset_ = Function1<Type>::New("offset", dict); } + if + ( + mapMethod_ != "planarInterpolation" + && mapMethod_ != "nearest" + ) + { + FatalIOErrorInFunction + ( + dict + ) << "mapMethod should be one of 'planarInterpolation'" + << ", 'nearest'" << exit(FatalIOError); + } + dict.readIfPresent("fieldTableName", fieldTableName_); if (dict.found("value")) @@ -145,8 +124,34 @@ timeVaryingMappedFixedValuePointPatchField template<class Type> -Foam:: -timeVaryingMappedFixedValuePointPatchField<Type>:: +Foam::timeVaryingMappedFixedValuePointPatchField<Type>:: +timeVaryingMappedFixedValuePointPatchField +( + const timeVaryingMappedFixedValuePointPatchField<Type>& ptf, + const pointPatch& p, + const DimensionedField<Type, pointMesh>& iF, + const pointPatchFieldMapper& mapper +) +: + fixedValuePointPatchField<Type>(ptf, p, iF, mapper), + fieldTableName_(ptf.fieldTableName_), + setAverage_(ptf.setAverage_), + perturb_(ptf.perturb_), + mapMethod_(ptf.mapMethod_), + mapperPtr_(NULL), + sampleTimes_(0), + startSampleTime_(-1), + startSampledValues_(0), + startAverage_(Zero), + endSampleTime_(-1), + endSampledValues_(0), + endAverage_(Zero), + offset_(ptf.offset_, false) +{} + + +template<class Type> +Foam::timeVaryingMappedFixedValuePointPatchField<Type>:: timeVaryingMappedFixedValuePointPatchField ( const timeVaryingMappedFixedValuePointPatchField<Type>& ptf @@ -165,18 +170,12 @@ timeVaryingMappedFixedValuePointPatchField endSampleTime_(ptf.endSampleTime_), endSampledValues_(ptf.endSampledValues_), endAverage_(ptf.endAverage_), - offset_ - ( - ptf.offset_.valid() - ? ptf.offset_().clone().ptr() - : NULL - ) + offset_(ptf.offset_, false) {} template<class Type> -Foam:: -timeVaryingMappedFixedValuePointPatchField<Type>:: +Foam::timeVaryingMappedFixedValuePointPatchField<Type>:: timeVaryingMappedFixedValuePointPatchField ( const timeVaryingMappedFixedValuePointPatchField<Type>& ptf, @@ -196,12 +195,7 @@ timeVaryingMappedFixedValuePointPatchField endSampleTime_(ptf.endSampleTime_), endSampledValues_(ptf.endSampledValues_), endAverage_(ptf.endAverage_), - offset_ - ( - ptf.offset_.valid() - ? ptf.offset_().clone().ptr() - : NULL - ) + offset_(ptf.offset_, false) {} @@ -288,20 +282,17 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable() meshPts = pointField(points0, this->patch().meshPoints()); } - pointIOField samplePoints + // Reread values and interpolate + fileName samplePointsFile ( - IOobject - ( - "points", - this->db().time().constant(), - "boundaryData"/this->patch().name(), - this->db(), - IOobject::MUST_READ, - IOobject::AUTO_WRITE, - false - ) + this->db().time().constant() + /"boundaryData" + /this->patch().name() + /"points" ); + pointField samplePoints((IFstream(samplePointsFile)())); + // tbd: run-time selection bool nearestOnly = ( @@ -323,7 +314,6 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable() // Read the times for which data is available - const fileName samplePointsFile = samplePoints.filePath(); const fileName samplePointsDir = samplePointsFile.path(); sampleTimes_ = Time::findTimes(samplePointsDir); @@ -396,32 +386,37 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable() } // Reread values and interpolate - AverageIOField<Type> vals + fileName valsFile ( - IOobject - ( - fieldTableName_, - this->db().time().constant(), - "boundaryData" - /this->patch().name() - /sampleTimes_[startSampleTime_].name(), - this->db(), - IOobject::MUST_READ, - IOobject::AUTO_WRITE, - false - ) + this->db().time().constant() + /"boundaryData" + /this->patch().name() + /sampleTimes_[startSampleTime_].name() + /fieldTableName_ ); + Field<Type> vals; + + if (setAverage_) + { + AverageField<Type> avals((IFstream(valsFile)())); + vals = avals; + startAverage_ = avals.average(); + } + else + { + IFstream(valsFile)() >> vals; + } + if (vals.size() != mapperPtr_().sourceSize()) { FatalErrorInFunction << "Number of values (" << vals.size() << ") differs from the number of points (" << mapperPtr_().sourceSize() - << ") in file " << vals.objectPath() << exit(FatalError); + << ") in file " << valsFile << exit(FatalError); } - startAverage_ = vals.average(); startSampledValues_ = mapperPtr_().interpolate(vals); } } @@ -449,33 +444,39 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable() /sampleTimes_[endSampleTime_].name() << endl; } + // Reread values and interpolate - AverageIOField<Type> vals + fileName valsFile ( - IOobject - ( - fieldTableName_, - this->db().time().constant(), - "boundaryData" - /this->patch().name() - /sampleTimes_[endSampleTime_].name(), - this->db(), - IOobject::MUST_READ, - IOobject::AUTO_WRITE, - false - ) + this->db().time().constant() + /"boundaryData" + /this->patch().name() + /sampleTimes_[endSampleTime_].name() + /fieldTableName_ ); + Field<Type> vals; + + if (setAverage_) + { + AverageField<Type> avals((IFstream(valsFile)())); + vals = avals; + endAverage_ = avals.average(); + } + else + { + IFstream(valsFile)() >> vals; + } + if (vals.size() != mapperPtr_().sourceSize()) { FatalErrorInFunction << "Number of values (" << vals.size() << ") differs from the number of points (" << mapperPtr_().sourceSize() - << ") in file " << vals.objectPath() << exit(FatalError); + << ") in file " << valsFile << exit(FatalError); } - endAverage_ = vals.average(); endSampledValues_ = mapperPtr_().interpolate(vals); } } @@ -569,7 +570,7 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::updateCoeffs() } } - // apply offset to mapped values + // Apply offset to mapped values if (offset_.valid()) { const scalar t = this->db().time().timeOutputValue(); @@ -594,29 +595,26 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::write ) const { fixedValuePointPatchField<Type>::write(os); - os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl; - if (perturb_ != 1e-5) - { - os.writeKeyword("perturb") << perturb_ << token::END_STATEMENT << nl; - } - if (fieldTableName_ != this->internalField().name()) - { - os.writeKeyword("fieldTableName") << fieldTableName_ - << token::END_STATEMENT << nl; - } + this->writeEntryIfDifferent(os, "setAverage", Switch(false), setAverage_); - if + this->writeEntryIfDifferent(os, "perturb", 1e-5, perturb_); + + this->writeEntryIfDifferent ( - ( - !mapMethod_.empty() - && mapMethod_ != "planarInterpolation" - ) - ) - { - os.writeKeyword("mapMethod") << mapMethod_ - << token::END_STATEMENT << nl; - } + os, + "fieldTable", + this->internalField().name(), + fieldTableName_ + ); + + this->writeEntryIfDifferent + ( + os, + "mapMethod", + word("planarInterpolation"), + mapMethod_ + ); if (offset_.valid()) { diff --git a/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.H b/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.H index e1119ef29e36573d443afd669e6c2c3b82214164..547168fe61753f632f92bee61ab1d87ea95282a4 100644 --- a/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.H +++ b/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.H @@ -63,7 +63,7 @@ class timeVaryingMappedFixedValuePointPatchField word fieldTableName_; //- If true adjust the mapped field to maintain average value - bool setAverage_; + Switch setAverage_; //- Fraction of perturbation (fraction of bounding box) to add scalar perturb_; diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H index cae3793ac8bc9f763d33484cb6a85b46cc6bc1be..1f357fe1f1064be4c88ee9230f2cd262cd8b4c06 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H @@ -25,7 +25,8 @@ Class Foam::sampledCuttingPlane Description - A sampledSurface defined by a plane + A sampledSurface defined by a plane using the iso-surface algorithm + to 'cut' the mesh. SourceFiles sampledCuttingPlane.C diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.H b/src/sampling/sampledSurface/sampledPlane/sampledPlane.H index 02a4147a8140d697118c5c8c410c7fb2dc59102e..6746361c1ed6788bda0a175d89210737fcee8219 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.H +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.H @@ -25,7 +25,8 @@ Class Foam::sampledPlane Description - A sampledSurface defined by a cuttingPlane. Triangulated by default. + A sampledSurface defined by a plane which 'cuts' the mesh using the + cuttingPlane alorithm. The plane is triangulated by default. Note Does not actually cut until update() called.