diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C index d66f2c7633..53a26f00ba 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C @@ -123,6 +123,23 @@ void Foam::pointPatchField::write(Ostream& os) const } +template +template +void Foam::pointPatchField::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 Foam::tmp> Foam::pointPatchField::patchInternalField() const diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H index 5db051b1dc..34b0e6336e 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 + 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 d1b5f32885..3f53313f68 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 +Foam::Function1Types::Constant::Constant +( + const word& entryName, + const Type& val +) +: + Function1(entryName), + value_(val) +{} + + template Foam::Function1Types::Constant::Constant ( diff --git a/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H b/src/OpenFOAM/primitives/functions/Function1/Constant/Constant.H index 20b8a68708..ddfbcdf84b 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 7862b70de2..2f4ed7e376 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 c8099fe94b..c631dfb1fd 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 -Foam::AverageIOField::AverageIOField -( - const IOobject& io -) +Foam::AverageField::AverageField(const label size) : - regIOobject(io) -{ - readStream(typeName) >> average_; - readStream(typeName) >> static_cast&>(*this); - close(); -} - - -template -Foam::AverageIOField::AverageIOField -( - const IOobject& io, - const label size -) -: - regIOobject(io), Field(size), average_(Zero) {} template -Foam::AverageIOField::AverageIOField +Foam::AverageField::AverageField ( - const IOobject& io, - const Type& average, - const Field& f + const Field& f, + const Type& average ) : - regIOobject(io), Field(f), average_(average) +{} + + +template +Foam::AverageField::AverageField(Istream& is) +: + Field(is), + average_(pTraits(is)) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +const Type& Foam::AverageField::average() const { - if (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - { - readStream(typeName) - >> average_ - >> static_cast&>(*this); - close(); - } + return average_; } template -bool Foam::AverageIOField::writeData(Ostream& os) const +Type&Foam::AverageField::average() { - os << average_ + return average_; +} + + +template +bool Foam::AverageField::writeData(Ostream& os) const +{ + os << static_cast&>(*this) << token::NL - << static_cast&>(*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 bfac397000..818f2bdc1d 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 . 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 AverageIOField +class AverageField : - public regIOobject, public Field { // 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& - ); + AverageField(const Field&, 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 8c7f50481d..0000000000 --- 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 . - -Description - -\*---------------------------------------------------------------------------*/ - -#include "AverageIOField.H" -#include "fieldTypes.H" - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -typedef AverageIOField scalarAverageIOField; -typedef AverageIOField vectorAverageIOField; -typedef AverageIOField sphericalTensorAverageIOField; -typedef AverageIOField symmTensorAverageIOField; -typedef AverageIOField 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 18fe4b4ea7..df0623bde1 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(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::New("offset", dict)) + offset_() { + if (dict.found("offset")) + { + offset_ = Function1::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::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::checkTable() /fieldTableName_ ); - Field vals((IFstream(valsFile)())); - // IOField vals - // ( - // IOobject - // ( - // fieldTableName_, - // this->db().time().constant(), - // "boundaryData" - // /this->patch().name() - // /sampleTimes_[startSampleTime_].name(), - // this->db(), - // IOobject::MUST_READ, - // IOobject::AUTO_WRITE, - // false - // ) - // ); + Field vals; + + if (setAverage_) + { + AverageField avals((IFstream(valsFile)())); + vals = avals; + startAverage_ = avals.average(); + } + else + { + IFstream(valsFile)() >> vals; + } if (vals.size() != mapperPtr_().sourceSize()) { @@ -402,7 +389,6 @@ void Foam::timeVaryingMappedFixedValueFvPatchField::checkTable() << ") in file " << valsFile << exit(FatalError); } - //startAverage_ = vals.average(); startSampledValues_ = mapperPtr_().interpolate(vals); } } @@ -432,32 +418,37 @@ void Foam::timeVaryingMappedFixedValueFvPatchField::checkTable() } // Reread values and interpolate - IOField 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 vals; + + if (setAverage_) + { + AverageField 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::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::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,31 +570,31 @@ void Foam::timeVaryingMappedFixedValueFvPatchField::write ) const { fvPatchField::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.writeKeyword("mapMethod") << mapMethod_ - << token::END_STATEMENT << nl; - } + os, + "fieldTable", + this->internalField().name(), + fieldTableName_ + ); - offset_->writeData(os); + this->writeEntryIfDifferent + ( + os, + "mapMethod", + word("planarInterpolation"), + mapMethod_ + ); + + if (offset_.valid()) + { + 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 3b39993171..3de912acf7 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/\ 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. + points in space and time. - The optional mapMethod nearest will avoid all projection and - triangulation and just use the value at the nearest vertex. + Supplied data should be specified in constant/boundaryData/\/ + - points : pointField of locations + - \/\ : field of values at 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 { 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 5fdac87571..fac9f475b3 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 -Foam:: -timeVaryingMappedFixedValuePointPatchField:: +Foam::timeVaryingMappedFixedValuePointPatchField:: timeVaryingMappedFixedValuePointPatchField ( const pointPatch& p, @@ -55,41 +55,7 @@ timeVaryingMappedFixedValuePointPatchField template -Foam:: -timeVaryingMappedFixedValuePointPatchField:: -timeVaryingMappedFixedValuePointPatchField -( - const timeVaryingMappedFixedValuePointPatchField& ptf, - const pointPatch& p, - const DimensionedField& iF, - const pointPatchFieldMapper& mapper -) -: - fixedValuePointPatchField(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 -Foam:: -timeVaryingMappedFixedValuePointPatchField:: +Foam::timeVaryingMappedFixedValuePointPatchField:: timeVaryingMappedFixedValuePointPatchField ( const pointPatch& p, @@ -99,7 +65,7 @@ timeVaryingMappedFixedValuePointPatchField : fixedValuePointPatchField(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::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 -Foam:: -timeVaryingMappedFixedValuePointPatchField:: +Foam::timeVaryingMappedFixedValuePointPatchField:: +timeVaryingMappedFixedValuePointPatchField +( + const timeVaryingMappedFixedValuePointPatchField& ptf, + const pointPatch& p, + const DimensionedField& iF, + const pointPatchFieldMapper& mapper +) +: + fixedValuePointPatchField(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 +Foam::timeVaryingMappedFixedValuePointPatchField:: timeVaryingMappedFixedValuePointPatchField ( const timeVaryingMappedFixedValuePointPatchField& 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 -Foam:: -timeVaryingMappedFixedValuePointPatchField:: +Foam::timeVaryingMappedFixedValuePointPatchField:: timeVaryingMappedFixedValuePointPatchField ( const timeVaryingMappedFixedValuePointPatchField& 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::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::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::checkTable() } // Reread values and interpolate - AverageIOField 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 vals; + + if (setAverage_) + { + AverageField 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::checkTable() /sampleTimes_[endSampleTime_].name() << endl; } + // Reread values and interpolate - AverageIOField 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 vals; + + if (setAverage_) + { + AverageField 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::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::write ) const { fixedValuePointPatchField::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 e1119ef29e..547168fe61 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 cae3793ac8..1f357fe1f1 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 02a4147a81..6746361c1e 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.