diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H index d7d52def0b..5924157ad2 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H @@ -37,7 +37,7 @@ Description - points : pointField of locations - \/\ : field of values at time \ - The default mode of operation (mapMethod planarInterpolation) is to project + The default mode of operation (mapMethod = planar) is to project the points onto a plane (constructed from the first three points) and construct a 2D triangulation and finds for the face centres the triangle it is in and the weights to the 3 vertices. @@ -50,12 +50,12 @@ Description Usage \table Property | Description | Required | Default - setAverage | Use average value | no | false + setAverage | Use average value | no | false perturb | Perturb points for regular geometries | no | 1e-5 - points | Name of points file | no | points + 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 | planar + offset | Offset to mapped values | no | Zero \endtable \verbatim @@ -74,8 +74,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef timeVaryingMappedFixedValueFvPatchField_H -#define timeVaryingMappedFixedValueFvPatchField_H +#ifndef Foam_timeVaryingMappedFixedValueFvPatchField_H +#define Foam_timeVaryingMappedFixedValueFvPatchField_H #include "fixedValueFvPatchFields.H" #include "MappedFile.H" @@ -94,7 +94,7 @@ class timeVaryingMappedFixedValueFvPatchField : public fixedValueFvPatchField { - // Private data + // Private Data autoPtr> uniformValue_; diff --git a/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.C b/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.C index bd1473953a..c98b89a3e2 100644 --- a/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.C +++ b/src/fvMotionSolver/pointPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValuePointPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,18 +41,20 @@ timeVaryingMappedFixedValuePointPatchField ) : fixedValuePointPatchField(p, iF), - fieldTableName_(iF.name()), setAverage_(false), perturb_(0), + fieldTableName_(iF.name()), + pointsName_("points"), + mapMethod_(), mapperPtr_(nullptr), - sampleTimes_(0), - startSampleTime_(-1), - startSampledValues_(0), - startAverage_(Zero), - endSampleTime_(-1), - endSampledValues_(0), + sampleTimes_(), + begSampleIndex_(-1), + endSampleIndex_(-1), + begAverage_(Zero), endAverage_(Zero), - offset_() + begSampledValues_(), + endSampledValues_(), + offset_(nullptr) {} @@ -66,25 +68,19 @@ timeVaryingMappedFixedValuePointPatchField ) : fixedValuePointPatchField(p, iF, dict, false), - fieldTableName_(iF.name()), setAverage_(dict.getOrDefault("setAverage", false)), perturb_(dict.getOrDefault("perturb", 1e-5)), - mapMethod_ - ( - dict.getOrDefault - ( - "mapMethod", - "planarInterpolation" - ) - ), + fieldTableName_(iF.name()), + pointsName_(dict.getOrDefault("points", "points")), + mapMethod_(), mapperPtr_(nullptr), - sampleTimes_(0), - startSampleTime_(-1), - startSampledValues_(0), - startAverage_(Zero), - endSampleTime_(-1), - endSampledValues_(0), + sampleTimes_(), + begSampleIndex_(-1), + endSampleIndex_(-1), + begAverage_(Zero), endAverage_(Zero), + begSampledValues_(), + endSampledValues_(), offset_ ( Function1::NewIfPresent("offset", dict, word::null, &this->db()) @@ -92,16 +88,24 @@ timeVaryingMappedFixedValuePointPatchField { if ( - mapMethod_ != "planarInterpolation" + dict.readIfPresent("mapMethod", mapMethod_) + && !mapMethod_.empty() && mapMethod_ != "nearest" + && !mapMethod_.starts_with("planar") ) { FatalIOErrorInFunction(dict) - << "mapMethod should be one of 'planarInterpolation'" - << ", 'nearest'" << exit(FatalIOError); + << "Unknown mapMethod type " << mapMethod_ + << "\n\nValid mapMethod types :\n" + << "(nearest planar)" << nl + << exit(FatalIOError); } - dict.readIfPresent("fieldTableName", fieldTableName_); + dict.readIfPresentCompat + ( + "fieldTable", {{"fieldTableName", 2206}}, + fieldTableName_ + ); if (dict.found("value")) { @@ -132,18 +136,19 @@ timeVaryingMappedFixedValuePointPatchField ) : fixedValuePointPatchField(ptf, p, iF, mapper), - fieldTableName_(ptf.fieldTableName_), setAverage_(ptf.setAverage_), perturb_(ptf.perturb_), + fieldTableName_(ptf.fieldTableName_), + pointsName_(ptf.pointsName_), mapMethod_(ptf.mapMethod_), mapperPtr_(nullptr), - sampleTimes_(0), - startSampleTime_(-1), - startSampledValues_(0), - startAverage_(Zero), - endSampleTime_(-1), - endSampledValues_(0), + sampleTimes_(), + begSampleIndex_(-1), + endSampleIndex_(-1), + begAverage_(Zero), endAverage_(Zero), + begSampledValues_(), + endSampledValues_(), offset_(ptf.offset_.clone()) {} @@ -156,18 +161,19 @@ timeVaryingMappedFixedValuePointPatchField ) : fixedValuePointPatchField(ptf), - fieldTableName_(ptf.fieldTableName_), setAverage_(ptf.setAverage_), perturb_(ptf.perturb_), + fieldTableName_(ptf.fieldTableName_), + pointsName_(ptf.pointsName_), mapMethod_(ptf.mapMethod_), mapperPtr_(ptf.mapperPtr_), sampleTimes_(ptf.sampleTimes_), - startSampleTime_(ptf.startSampleTime_), - startSampledValues_(ptf.startSampledValues_), - startAverage_(ptf.startAverage_), - endSampleTime_(ptf.endSampleTime_), - endSampledValues_(ptf.endSampledValues_), + begSampleIndex_(ptf.begSampleIndex_), + endSampleIndex_(ptf.endSampleIndex_), + begAverage_(ptf.begAverage_), endAverage_(ptf.endAverage_), + begSampledValues_(ptf.begSampledValues_), + endSampledValues_(ptf.endSampledValues_), offset_(ptf.offset_.clone()) {} @@ -181,18 +187,19 @@ timeVaryingMappedFixedValuePointPatchField ) : fixedValuePointPatchField(ptf, iF), - fieldTableName_(ptf.fieldTableName_), setAverage_(ptf.setAverage_), perturb_(ptf.perturb_), + fieldTableName_(ptf.fieldTableName_), + pointsName_(ptf.pointsName_), mapMethod_(ptf.mapMethod_), mapperPtr_(ptf.mapperPtr_), sampleTimes_(ptf.sampleTimes_), - startSampleTime_(ptf.startSampleTime_), - startSampledValues_(ptf.startSampledValues_), - startAverage_(ptf.startAverage_), - endSampleTime_(ptf.endSampleTime_), - endSampledValues_(ptf.endSampledValues_), + begSampleIndex_(ptf.begSampleIndex_), + endSampleIndex_(ptf.endSampleIndex_), + begAverage_(ptf.begAverage_), endAverage_(ptf.endAverage_), + begSampledValues_(ptf.begSampledValues_), + endSampledValues_(ptf.endSampledValues_), offset_(ptf.offset_.clone()) {} @@ -206,15 +213,21 @@ void Foam::timeVaryingMappedFixedValuePointPatchField::autoMap ) { fixedValuePointPatchField::autoMap(m); - if (startSampledValues_.size()) + + if (begSampledValues_.size()) + { + begSampledValues_.autoMap(m); + } + + if (endSampledValues_.size()) { - startSampledValues_.autoMap(m); endSampledValues_.autoMap(m); } + // Clear interpolator - mapperPtr_.clear(); - startSampleTime_ = -1; - endSampleTime_ = -1; + mapperPtr_.reset(nullptr); + begSampleIndex_ = -1; + endSampleIndex_ = -1; } @@ -230,23 +243,100 @@ void Foam::timeVaryingMappedFixedValuePointPatchField::rmap const timeVaryingMappedFixedValuePointPatchField& tiptf = refCast>(ptf); - startSampledValues_.rmap(tiptf.startSampledValues_, addr); + begSampledValues_.rmap(tiptf.begSampledValues_, addr); endSampledValues_.rmap(tiptf.endSampledValues_, addr); // Clear interpolator - mapperPtr_.clear(); - startSampleTime_ = -1; - endSampleTime_ = -1; + mapperPtr_.reset(nullptr); + begSampleIndex_ = -1; + endSampleIndex_ = -1; } template -void Foam::timeVaryingMappedFixedValuePointPatchField::checkTable() +void Foam::timeVaryingMappedFixedValuePointPatchField::updateSampledValues +( + const int whichEnd // (0|1) +) +{ + // Update sampled data fields + const Time& time = this->db().time(); + + const word& sampleTimeName = + sampleTimes_[(whichEnd ? endSampleIndex_ : begSampleIndex_)].name(); + + if (debug) + { + Pout<< "checkTable : Reading values from " + << + ( + "boundaryData" + / this->patch().name() + / sampleTimeName + / fieldTableName_ + ) << endl; + } + + // Reread values and interpolate + const fileName valsFile + ( + time.caseConstant() + /"boundaryData" + /this->patch().name() + /sampleTimeName + /fieldTableName_ + ); + + IOobject io + ( + valsFile, // absolute path + time, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false, // no need to register + true // is global object (currently not used) + ); + + const rawIOField vals(io, setAverage_); + + if (vals.size() != mapperPtr_().sourceSize()) + { + FatalErrorInFunction + << "Number of values (" << vals.size() + << ") differs from the number of points (" + << mapperPtr_().sourceSize() + << ") in file " << valsFile << exit(FatalError); + } + + if (whichEnd) + { + if (setAverage_) // or vals.hasAverage() + { + endAverage_ = vals.average(); + } + endSampledValues_ = mapperPtr_().interpolate(vals); + } + else + { + if (setAverage_) // or vals.hasAverage() + { + begAverage_ = vals.average(); + } + begSampledValues_ = mapperPtr_().interpolate(vals); + } +} + + +template +void Foam::timeVaryingMappedFixedValuePointPatchField::checkTable +( + const scalar t +) { const Time& time = this->db().time(); // Initialise - if (startSampleTime_ == -1 && endSampleTime_ == -1) + if (begSampleIndex_ == -1 && endSampleIndex_ == -1) { const polyMesh& pMesh = this->patch().boundaryMesh().mesh()(); @@ -288,7 +378,7 @@ void Foam::timeVaryingMappedFixedValuePointPatchField::checkTable() time.caseConstant() /"boundaryData" /this->patch().name() - /"points" + /pointsName_ ); IOobject io @@ -301,14 +391,13 @@ void Foam::timeVaryingMappedFixedValuePointPatchField::checkTable() true // is global object (currently not used) ); - // Read data + // Read data (no average value!) const rawIOField samplePoints(io, false); // tbd: run-time selection - bool nearestOnly = + const bool nearestOnly = ( - !mapMethod_.empty() - && mapMethod_ != "planarInterpolation" + !mapMethod_.empty() && !mapMethod_.starts_with("planar") ); // Allocate the interpolator @@ -323,26 +412,24 @@ void Foam::timeVaryingMappedFixedValuePointPatchField::checkTable() ) ); - // Read the times for which data is available + // Read the times for which data is available const fileName samplePointsDir = samplePointsFile.path(); sampleTimes_ = Time::findTimes(samplePointsDir); - if (debug) - { - Info<< "timeVaryingMappedFixedValuePointPatchField : In directory " - << samplePointsDir << " found times " - << pointToPointPlanarInterpolation::timeNames(sampleTimes_) - << endl; - } + DebugInfo + << "timeVaryingMappedFixedValuePointPatchField : In directory " + << samplePointsDir << " found times " + << pointToPointPlanarInterpolation::timeNames(sampleTimes_) + << endl; } // Find range of current time indices in sampleTimes Pair