diff --git a/applications/test/PatchFunction1/Make/files b/applications/test/PatchFunction1/Make/files
new file mode 100644
index 0000000000..71ad583351
--- /dev/null
+++ b/applications/test/PatchFunction1/Make/files
@@ -0,0 +1,3 @@
+Test-PatchFunction1.C
+
+EXE = $(FOAM_USER_APPBIN)/Test-PatchFunction1
diff --git a/applications/test/PatchFunction1/Make/options b/applications/test/PatchFunction1/Make/options
new file mode 100644
index 0000000000..b8e72a86c6
--- /dev/null
+++ b/applications/test/PatchFunction1/Make/options
@@ -0,0 +1,15 @@
+EXE_INC = \
+ -DFULLDEBUG -g -O0 \
+ -I$(LIB_SRC)/lagrangian/intermediate/lnInclude \
+ -I$(LIB_SRC)/thermophysicalModels/radiation/lnInclude \
+ -I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude \
+ -I$(LIB_SRC)/finiteVolume/lnInclude \
+ -I$(LIB_SRC)/meshTools/lnInclude
+
+EXE_LIBS = \
+ -llagrangianIntermediate \
+ -lradiationModels \
+ -lregionModels \
+ -lfiniteVolume \
+ -lmeshTools \
+ -lsampling
diff --git a/applications/test/PatchFunction1/MappedField.C b/applications/test/PatchFunction1/MappedField.C
new file mode 100644
index 0000000000..591a488546
--- /dev/null
+++ b/applications/test/PatchFunction1/MappedField.C
@@ -0,0 +1,401 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\/ 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 .
+
+\*---------------------------------------------------------------------------*/
+
+#include "polyMesh.H"
+#include "IFstream.H"
+#include "AverageField.H"
+
+// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
+
+template
+Foam::PatchFunction1Types::MappedField::MappedField
+(
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict
+)
+:
+ PatchFunction1(pp, entryName, dict),
+ fieldTableName_(entryName),
+ setAverage_(dict.lookupOrDefault("setAverage", false)),
+ perturb_(dict.lookupOrDefault("perturb", 1e-5)),
+ pointsName_(dict.lookupOrDefault("points", "points")),
+ mapMethod_
+ (
+ dict.lookupOrDefault
+ (
+ "mapMethod",
+ "planarInterpolation"
+ )
+ ),
+ mapperPtr_(nullptr),
+ sampleTimes_(0),
+ startSampleTime_(-1),
+ startSampledValues_(0),
+ startAverage_(Zero),
+ endSampleTime_(-1),
+ endSampledValues_(0),
+ endAverage_(Zero),
+ offset_()
+{
+ if (dict.found("offset"))
+ {
+ offset_ = Function1::New("offset", dict);
+ }
+
+ if
+ (
+ mapMethod_ != "planarInterpolation"
+ && mapMethod_ != "nearest"
+ )
+ {
+ FatalIOErrorInFunction(dict)
+ << "mapMethod should be one of 'planarInterpolation'"
+ << ", 'nearest'" << exit(FatalIOError);
+ }
+
+ dict.readIfPresent("fieldTable", fieldTableName_);
+}
+
+
+template
+Foam::PatchFunction1Types::MappedField::MappedField
+(
+ const MappedField& ut
+)
+:
+ PatchFunction1(ut),
+ fieldTableName_(ut.fieldTableName_),
+ setAverage_(ut.setAverage_),
+ perturb_(ut.perturb_),
+ pointsName_(ut.pointsName_),
+ mapMethod_(ut.mapMethod_),
+ mapperPtr_(nullptr),
+ sampleTimes_(ut.sampleTimes_),
+ startSampleTime_(ut.startSampleTime_),
+ startSampledValues_(ut.startSampledValues_),
+ startAverage_(ut.startAverage_),
+ endSampleTime_(ut.endSampleTime_),
+ endSampledValues_(ut.endSampledValues_),
+ endAverage_(ut.endAverage_),
+ offset_(ut.offset_.clone())
+{}
+
+
+template
+Foam::PatchFunction1Types::MappedField::MappedField
+(
+ const MappedField& ut,
+ const polyPatch& pp
+)
+:
+ PatchFunction1(ut, pp),
+ fieldTableName_(ut.fieldTableName_),
+ setAverage_(ut.setAverage_),
+ perturb_(ut.perturb_),
+ pointsName_(ut.pointsName_),
+ mapMethod_(ut.mapMethod_),
+ mapperPtr_(nullptr),
+ sampleTimes_(ut.sampleTimes_),
+ startSampleTime_(ut.startSampleTime_),
+ startSampledValues_(ut.startSampledValues_),
+ startAverage_(ut.startAverage_),
+ endSampleTime_(ut.endSampleTime_),
+ endSampledValues_(ut.endSampledValues_),
+ endAverage_(ut.endAverage_),
+ offset_(ut.offset_.clone())
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+template
+void Foam::PatchFunction1Types::MappedField::autoMap
+(
+ const FieldMapper& mapper
+)
+{
+ if (startSampledValues_.size())
+ {
+ startSampledValues_.autoMap(mapper);
+ endSampledValues_.autoMap(mapper);
+ }
+ // Clear interpolator
+ mapperPtr_.clear();
+ startSampleTime_ = -1;
+ endSampleTime_ = -1;
+}
+
+
+template
+void Foam::PatchFunction1Types::MappedField::rmap
+(
+ const PatchFunction1& pf1,
+ const labelList& addr
+)
+{
+ const PatchFunction1Types::MappedField& tiptf =
+ refCast>(pf1);
+
+ startSampledValues_.rmap(tiptf.startSampledValues_, addr);
+ endSampledValues_.rmap(tiptf.endSampledValues_, addr);
+
+ // Clear interpolator
+ mapperPtr_.clear();
+ startSampleTime_ = -1;
+ endSampleTime_ = -1;
+}
+
+
+template
+void Foam::PatchFunction1Types::MappedField::checkTable() const
+{
+ const polyMesh& mesh = this->patch_.boundaryMesh().mesh();
+
+ // Initialise
+ if (mapperPtr_.empty())
+ {
+ // Reread values and interpolate
+ fileName samplePointsFile
+ (
+ mesh.time().path()
+ /mesh.time().caseConstant()
+ /"boundaryData"
+ /this->patch_.name()
+ /pointsName_
+ );
+
+ pointField samplePoints((IFstream(samplePointsFile)()));
+
+ DebugInfo
+ << " Read " << samplePoints.size() << " sample points from "
+ << samplePointsFile << endl;
+
+
+ // tbd: run-time selection
+ bool nearestOnly =
+ (
+ !mapMethod_.empty()
+ && mapMethod_ != "planarInterpolation"
+ );
+
+ // Allocate the interpolator
+ mapperPtr_.reset
+ (
+ new pointToPointPlanarInterpolation
+ (
+ samplePoints,
+ this->patch_.faceCentres(),
+ perturb_,
+ nearestOnly
+ )
+ );
+
+ // Read the times for which data is available
+ const fileName samplePointsDir = samplePointsFile.path();
+ sampleTimes_ = Time::findTimes(samplePointsDir);
+
+ DebugInfo
+ << "In directory "
+ << samplePointsDir << " found times "
+ << pointToPointPlanarInterpolation::timeNames(sampleTimes_)
+ << endl;
+ }
+
+
+ // Find current time in sampleTimes
+ label lo = -1;
+ label hi = -1;
+
+ bool foundTime = mapperPtr_().findTime
+ (
+ sampleTimes_,
+ startSampleTime_,
+ mesh.time().value(),
+ lo,
+ hi
+ );
+
+ if (!foundTime)
+ {
+ FatalErrorInFunction
+ << "Cannot find starting sampling values for current time "
+ << mesh.time().value() << nl
+ << "Have sampling values for times "
+ << pointToPointPlanarInterpolation::timeNames(sampleTimes_) << nl
+ << "In directory "
+ << mesh.time().constant()/"boundaryData"/this->patch_.name()
+ << "\n on patch " << this->patch_.name()
+ << " of field " << fieldTableName_
+ << exit(FatalError);
+ }
+
+
+ // Update sampled data fields.
+
+ if (lo != startSampleTime_)
+ {
+ startSampleTime_ = lo;
+
+ if (startSampleTime_ == endSampleTime_)
+ {
+ // No need to reread since are end values
+ if (debug)
+ {
+ Pout<< "checkTable : Setting startValues to (already read) "
+ << "boundaryData"
+ /this->patch_.name()
+ /sampleTimes_[startSampleTime_].name()
+ << endl;
+ }
+ startSampledValues_ = endSampledValues_;
+ startAverage_ = endAverage_;
+ }
+ else
+ {
+ if (debug)
+ {
+ Pout<< "checkTable : Reading startValues from "
+ << "boundaryData"
+ /this->patch_.name()
+ /sampleTimes_[lo].name()
+ << endl;
+ }
+
+
+ // Reread values and interpolate
+ fileName valsFile
+ (
+ mesh.time().path()
+ /mesh.time().caseConstant()
+ /"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 " << valsFile << exit(FatalError);
+ }
+
+ startSampledValues_ = mapperPtr_().interpolate(vals);
+ }
+ }
+
+ if (hi != endSampleTime_)
+ {
+ endSampleTime_ = hi;
+
+ if (endSampleTime_ == -1)
+ {
+ // endTime no longer valid. Might as well clear endValues.
+ if (debug)
+ {
+ Pout<< "checkTable : Clearing endValues" << endl;
+ }
+ endSampledValues_.clear();
+ }
+ else
+ {
+ if (debug)
+ {
+ Pout<< "checkTable : Reading endValues from "
+ << "boundaryData"
+ /this->patch_.name()
+ /sampleTimes_[endSampleTime_].name()
+ << endl;
+ }
+
+ // Reread values and interpolate
+ fileName valsFile
+ (
+ mesh.time().path()
+ /mesh.time().caseConstant()
+ /"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 " << valsFile << exit(FatalError);
+ }
+
+ endSampledValues_ = mapperPtr_().interpolate(vals);
+ }
+ }
+}
+
+
+template
+void Foam::PatchFunction1Types::MappedField::writeData
+(
+ Ostream& os
+) const
+{
+ PatchFunction1::writeData(os);
+ //os << token::END_STATEMENT << nl;
+// uniformValuePtr_->writeData(os);
+ //os << endl;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/PatchFunction1/MappedField.H b/applications/test/PatchFunction1/MappedField.H
new file mode 100644
index 0000000000..741481bda3
--- /dev/null
+++ b/applications/test/PatchFunction1/MappedField.H
@@ -0,0 +1,219 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\/ 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 .
+
+Class
+ Foam::PatchFunction1Types::MappedField
+
+Description
+
+SourceFiles
+ MappedField.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef PatchFunction1Types_MappedField_H
+#define PatchFunction1Types_MappedField_H
+
+#include "PatchFunction1.H"
+#include "pointToPointPlanarInterpolation.H"
+#include "Function1.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace PatchFunction1Types
+{
+
+/*---------------------------------------------------------------------------*\
+ Class MappedField Declaration
+\*---------------------------------------------------------------------------*/
+
+template
+class MappedField
+:
+ public PatchFunction1
+{
+ // Private data
+
+ //- Name of the field data table, defaults to the name of the field
+ word fieldTableName_;
+
+ //- If true adjust the mapped field to maintain average value
+ Switch setAverage_;
+
+ //- Fraction of perturbation (fraction of bounding box) to add
+ scalar perturb_;
+
+ //- Name of points file; default = "points"
+ word pointsName_;
+
+ //- Interpolation scheme to use
+ word mapMethod_;
+
+ //- 2D interpolation (for 'planarInterpolation' mapMethod)
+ mutable autoPtr mapperPtr_;
+
+ //- List of boundaryData time directories
+ mutable instantList sampleTimes_;
+
+ //- Current starting index in sampleTimes
+ mutable label startSampleTime_;
+
+ //- Interpolated values from startSampleTime
+ mutable Field startSampledValues_;
+
+ //- If setAverage: starting average value
+ mutable Type startAverage_;
+
+ //- Current end index in sampleTimes
+ mutable label endSampleTime_;
+
+ //- Interpolated values from endSampleTime
+ mutable Field endSampledValues_;
+
+ //- If setAverage: end average value
+ mutable Type endAverage_;
+
+ //- Time varying offset values to interpolated data
+ autoPtr> offset_;
+
+
+ // Private Member Functions
+
+ void checkTable() const;
+
+ //- No copy assignment
+ void operator=(const MappedField&) = delete;
+
+
+public:
+
+ // Runtime type information
+ TypeName("mapped");
+
+
+ // Constructors
+
+ //- Construct from components
+ MappedField
+ (
+ const polyPatch& pp,
+ const word& entryName,
+ const Field& value
+ );
+
+ //- Construct from entry name and dictionary
+ MappedField
+ (
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict
+ );
+
+ //- Copy constructor
+ explicit MappedField(const MappedField& ut);
+
+ //- Copy constructor setting patch
+ explicit MappedField
+ (
+ const MappedField& ut,
+ const polyPatch& pp
+ );
+
+ //- Construct and return a clone
+ virtual tmp> clone() const
+ {
+ return tmp>
+ (
+ new MappedField(*this)
+ );
+ }
+
+ //- Construct and return a clone setting patch
+ virtual tmp> clone(const polyPatch& pp) const
+ {
+ return tmp>
+ (
+ new MappedField(*this, pp)
+ );
+ }
+
+
+ //- Destructor
+ virtual ~MappedField() = default;
+
+
+ // Member Functions
+
+ // Evaluation
+
+ //- Return MappedField value
+ virtual inline tmp> value(const scalar) const;
+
+ //- Integrate between two values
+ virtual inline tmp> integrate
+ (
+ const scalar x1,
+ const scalar x2
+ ) const;
+
+
+ // Mapping
+
+ //- Map (and resize as needed) from self given a mapping object
+ virtual void autoMap(const FieldMapper& mapper);
+
+ //- Reverse map the given PatchFunction1 onto this PatchFunction1
+ virtual void rmap
+ (
+ const PatchFunction1& pf1,
+ const labelList& addr
+ );
+
+
+ // I-O
+
+ //- Write in dictionary format
+ virtual void writeData(Ostream& os) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace PatchFunction1Types
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#include "MappedFieldI.H"
+
+#ifdef NoRepository
+ #include "MappedField.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/applications/test/PatchFunction1/MappedFieldI.H b/applications/test/PatchFunction1/MappedFieldI.H
new file mode 100644
index 0000000000..4e91655817
--- /dev/null
+++ b/applications/test/PatchFunction1/MappedFieldI.H
@@ -0,0 +1,148 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\/ 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 .
+
+\*---------------------------------------------------------------------------*/
+
+#include "MappedField.H"
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+template
+inline Foam::tmp>
+Foam::PatchFunction1Types::MappedField::value
+(
+ const scalar x
+) const
+{
+ const polyMesh& mesh = this->patch_.boundaryMesh().mesh();
+ checkTable();
+
+ tmp> tfld(new Field(this->patch_.size()));
+ Field& fld = tfld.ref();
+ Type wantedAverage;
+
+ if (endSampleTime_ == -1)
+ {
+ // Only start value
+ if (debug)
+ {
+ Pout<< "updateCoeffs : Sampled, non-interpolated values"
+ << " from start time:"
+ << sampleTimes_[startSampleTime_].name() << nl;
+ }
+
+ fld = startSampledValues_;
+ wantedAverage = startAverage_;
+ }
+ else
+ {
+ scalar start = sampleTimes_[startSampleTime_].value();
+ scalar end = sampleTimes_[endSampleTime_].value();
+
+ scalar s = (mesh.time().value() - start)/(end - start);
+
+ if (debug)
+ {
+ Pout<< "updateCoeffs : Sampled, interpolated values"
+ << " between start time:"
+ << sampleTimes_[startSampleTime_].name()
+ << " and end time:" << sampleTimes_[endSampleTime_].name()
+ << " with weight:" << s << endl;
+ }
+
+ fld = ((1 - s)*startSampledValues_ + s*endSampledValues_);
+ wantedAverage = (1 - s)*startAverage_ + s*endAverage_;
+ }
+
+ // Enforce average. Either by scaling (if scaling factor > 0.5) or by
+ // offsetting.
+ if (setAverage_)
+ {
+ const scalarField magSf(mag(this->patch_.faceAreas()));
+
+ Type averagePsi = gSum(magSf*fld)/gSum(magSf);
+
+ if (debug)
+ {
+ Pout<< "updateCoeffs :"
+ << " actual average:" << averagePsi
+ << " wanted average:" << wantedAverage
+ << endl;
+ }
+
+ if (mag(averagePsi) < VSMALL)
+ {
+ // Field too small to scale. Offset instead.
+ const Type offset = wantedAverage - averagePsi;
+ if (debug)
+ {
+ Pout<< "updateCoeffs :"
+ << " offsetting with:" << offset << endl;
+ }
+ fld += offset;
+ }
+ else
+ {
+ const scalar scale = mag(wantedAverage)/mag(averagePsi);
+
+ if (debug)
+ {
+ Pout<< "updateCoeffs :"
+ << " scaling with:" << scale << endl;
+ }
+ fld *= scale;
+ }
+ }
+
+ // Apply offset to mapped values
+ if (offset_.valid())
+ {
+ const scalar t = mesh.time().timeOutputValue();
+ fld += offset_->value(t);
+ }
+
+ if (debug)
+ {
+ Pout<< "updateCoeffs : set fixedValue to min:" << gMin(fld)
+ << " max:" << gMax(fld)
+ << " avg:" << gAverage(fld) << endl;
+ }
+
+ return this->transform(tfld);
+}
+
+
+template
+inline Foam::tmp>
+Foam::PatchFunction1Types::MappedField::integrate
+(
+ const scalar x1,
+ const scalar x2
+) const
+{
+ NotImplemented;
+ return tmp>(nullptr);
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/PatchFunction1/Test-PatchFunction1.C b/applications/test/PatchFunction1/Test-PatchFunction1.C
new file mode 100644
index 0000000000..59c6b7c378
--- /dev/null
+++ b/applications/test/PatchFunction1/Test-PatchFunction1.C
@@ -0,0 +1,107 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\/ 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 .
+
+Application
+ Test-Function1
+
+Description
+ Tests Function1
+
+\*---------------------------------------------------------------------------*/
+
+#include "fvCFD.H"
+#include "PatchFunction1.H"
+#include "IOdictionary.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+int main(int argc, char *argv[])
+{
+ #include "setRootCase.H"
+ #include "createTime.H"
+ #include "createMesh.H"
+
+ IOdictionary function1Properties
+ (
+ IOobject
+ (
+ "function1Properties",
+ runTime.constant(),
+ mesh,
+ IOobject::MUST_READ_IF_MODIFIED,
+ IOobject::NO_WRITE
+ )
+ );
+
+ autoPtr> function1
+ (
+ PatchFunction1::New
+ (
+ mesh.boundaryMesh()[0],
+ "function1",
+ function1Properties
+ )
+ );
+
+ scalar x0 = function1Properties.get("x0");
+ scalar x1 = function1Properties.get("x1");
+
+ Info<< "Data entry type: " << function1().type() << nl << endl;
+
+ Info<< "Inputs" << nl
+ << " x0 = " << x0 << nl
+ << " x1 = " << x1 << nl
+ << endl;
+
+ Info<< "Interpolation" << nl
+ << " f(x0) = " << function1().value(x0) << nl
+ << " f(x1) = " << function1().value(x1) << nl
+ << endl;
+
+ Info<< "Integration" << nl
+ << " int(f(x)) lim(x0->x1) = " << function1().integrate(x0, x1) << nl
+ << endl;
+
+ volVectorField fld
+ (
+ IOobject
+ (
+ "value",
+ runTime.timeName(),
+ mesh,
+ IOobject::NO_READ,
+ IOobject::AUTO_WRITE,
+ false
+ ),
+ mesh,
+ dimensionedVector(vector::zero)
+ );
+
+ fld.boundaryFieldRef()[0] == function1().value(x0);
+ fld.write();
+
+ return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/PatchFunction1/function1Properties b/applications/test/PatchFunction1/function1Properties
new file mode 100644
index 0000000000..516011069e
--- /dev/null
+++ b/applications/test/PatchFunction1/function1Properties
@@ -0,0 +1,38 @@
+/*--------------------------------*- C++ -*----------------------------------*\
+| ========= | |
+| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
+| \\ / O peration | Version: v1806 |
+| \\ / A nd | Web: www.OpenFOAM.com |
+| \\/ M anipulation | |
+\*---------------------------------------------------------------------------*/
+FoamFile
+{
+ version 2.0;
+ format ascii;
+ class dictionary;
+ location "constant";
+ object function1Properties;
+}
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+x0 0.5;
+x1 1;
+
+
+//- Dictionary notation
+function1 uniformValue;
+
+function1Coeffs
+{
+ function1 (0 1 0); //table ((0 (0 0 0))(1 (1 1 1)));
+ coordinateSystem
+ {
+ type cylindrical;
+ origin (0.05 0.1 0.05);
+ e3 (0 1 0);
+ e1 (1 0 0);
+ }
+ scale1 table ((0 (0 0 0))(1 (1 1 1)));
+}
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/Table.H b/src/OpenFOAM/primitives/functions/Function1/Table/Table.H
index d46a53e00b..2ce790a79d 100644
--- a/src/OpenFOAM/primitives/functions/Function1/Table/Table.H
+++ b/src/OpenFOAM/primitives/functions/Function1/Table/Table.H
@@ -47,8 +47,7 @@ SourceFiles
#ifndef Table_H
#define Table_H
-#include "Function1.H"
-#include "Tuple2.H"
+#include "TableBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C
index 5f0ae2eee0..491c501365 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.C
@@ -39,20 +39,7 @@ timeVaryingMappedFixedValueFvPatchField
)
:
fixedValueFvPatchField(p, iF),
- fieldTableName_(iF.name()),
- setAverage_(false),
- perturb_(0),
- pointsName_("points"),
- mapMethod_("planarInterpolation"),
- mapperPtr_(nullptr),
- sampleTimes_(0),
- startSampleTime_(-1),
- startSampledValues_(0),
- startAverage_(Zero),
- endSampleTime_(-1),
- endSampledValues_(0),
- endAverage_(Zero),
- offset_()
+ uniformValue_()
{}
@@ -66,46 +53,18 @@ timeVaryingMappedFixedValueFvPatchField
)
:
fixedValueFvPatchField(p, iF, dict, false),
- fieldTableName_(iF.name()),
- setAverage_(dict.lookupOrDefault("setAverage", false)),
- perturb_(dict.lookupOrDefault("perturb", 1e-5)),
- pointsName_(dict.lookupOrDefault("points", "points")),
- mapMethod_
+ uniformValue_
(
- dict.lookupOrDefault
+ new PatchFunction1Types::MappedFile
(
- "mapMethod",
- "planarInterpolation"
+ p.patch(),
+ "uniformValue",
+ dict,
+ iF.name(), // field table name
+ true // face values
)
- ),
- mapperPtr_(nullptr),
- sampleTimes_(0),
- startSampleTime_(-1),
- startSampledValues_(0),
- startAverage_(Zero),
- endSampleTime_(-1),
- endSampledValues_(0),
- endAverage_(Zero),
- offset_()
-{
- if (dict.found("offset"))
- {
- offset_ = Function1::New("offset", dict);
- }
-
- if
- (
- mapMethod_ != "planarInterpolation"
- && mapMethod_ != "nearest"
)
- {
- FatalIOErrorInFunction(dict)
- << "mapMethod should be one of 'planarInterpolation'"
- << ", 'nearest'" << exit(FatalIOError);
- }
-
- dict.readIfPresent("fieldTable", fieldTableName_);
-
+{
if (dict.found("value"))
{
fvPatchField::operator==(Field("value", dict, p.size()));
@@ -132,20 +91,14 @@ timeVaryingMappedFixedValueFvPatchField
)
:
fixedValueFvPatchField(ptf, p, iF, mapper),
- fieldTableName_(ptf.fieldTableName_),
- setAverage_(ptf.setAverage_),
- perturb_(ptf.perturb_),
- pointsName_(ptf.pointsName_),
- mapMethod_(ptf.mapMethod_),
- mapperPtr_(nullptr),
- sampleTimes_(0),
- startSampleTime_(-1),
- startSampledValues_(0),
- startAverage_(Zero),
- endSampleTime_(-1),
- endSampledValues_(0),
- endAverage_(Zero),
- offset_(ptf.offset_.clone())
+ uniformValue_
+ (
+ new PatchFunction1Types::MappedFile
+ (
+ ptf.uniformValue_,
+ p.patch()
+ )
+ )
{}
@@ -157,20 +110,13 @@ timeVaryingMappedFixedValueFvPatchField
)
:
fixedValueFvPatchField(ptf),
- fieldTableName_(ptf.fieldTableName_),
- setAverage_(ptf.setAverage_),
- perturb_(ptf.perturb_),
- pointsName_(ptf.pointsName_),
- mapMethod_(ptf.mapMethod_),
- mapperPtr_(nullptr),
- sampleTimes_(ptf.sampleTimes_),
- startSampleTime_(ptf.startSampleTime_),
- startSampledValues_(ptf.startSampledValues_),
- startAverage_(ptf.startAverage_),
- endSampleTime_(ptf.endSampleTime_),
- endSampledValues_(ptf.endSampledValues_),
- endAverage_(ptf.endAverage_),
- offset_(ptf.offset_.clone())
+ uniformValue_
+ (
+ new PatchFunction1Types::MappedFile
+ (
+ ptf.uniformValue_
+ )
+ )
{}
@@ -183,20 +129,13 @@ timeVaryingMappedFixedValueFvPatchField
)
:
fixedValueFvPatchField(ptf, iF),
- fieldTableName_(ptf.fieldTableName_),
- setAverage_(ptf.setAverage_),
- perturb_(ptf.perturb_),
- pointsName_(ptf.pointsName_),
- mapMethod_(ptf.mapMethod_),
- mapperPtr_(nullptr),
- sampleTimes_(ptf.sampleTimes_),
- startSampleTime_(ptf.startSampleTime_),
- startSampledValues_(ptf.startSampledValues_),
- startAverage_(ptf.startAverage_),
- endSampleTime_(ptf.endSampleTime_),
- endSampledValues_(ptf.endSampledValues_),
- endAverage_(ptf.endAverage_),
- offset_(ptf.offset_.clone())
+ uniformValue_
+ (
+ new PatchFunction1Types::MappedFile
+ (
+ ptf.uniformValue_
+ )
+ )
{}
@@ -209,15 +148,7 @@ void Foam::timeVaryingMappedFixedValueFvPatchField::autoMap
)
{
fixedValueFvPatchField::autoMap(m);
- if (startSampledValues_.size())
- {
- startSampledValues_.autoMap(m);
- endSampledValues_.autoMap(m);
- }
- // Clear interpolator
- mapperPtr_.clear();
- startSampleTime_ = -1;
- endSampleTime_ = -1;
+ uniformValue_().autoMap(m);
}
@@ -233,227 +164,7 @@ void Foam::timeVaryingMappedFixedValueFvPatchField::rmap
const timeVaryingMappedFixedValueFvPatchField& tiptf =
refCast>(ptf);
- startSampledValues_.rmap(tiptf.startSampledValues_, addr);
- endSampledValues_.rmap(tiptf.endSampledValues_, addr);
-
- // Clear interpolator
- mapperPtr_.clear();
- startSampleTime_ = -1;
- endSampleTime_ = -1;
-}
-
-
-template
-void Foam::timeVaryingMappedFixedValueFvPatchField::checkTable()
-{
- // Initialise
- if (mapperPtr_.empty())
- {
- // Reread values and interpolate
- fileName samplePointsFile
- (
- this->db().time().path()
- /this->db().time().caseConstant()
- /"boundaryData"
- /this->patch().name()
- /pointsName_
- );
-
- pointField samplePoints((IFstream(samplePointsFile)()));
-
- DebugInfo
- << " Read " << samplePoints.size() << " sample points from "
- << samplePointsFile << endl;
-
-
- // tbd: run-time selection
- bool nearestOnly =
- (
- !mapMethod_.empty()
- && mapMethod_ != "planarInterpolation"
- );
-
- // Allocate the interpolator
- mapperPtr_.reset
- (
- new pointToPointPlanarInterpolation
- (
- samplePoints,
- this->patch().patch().faceCentres(),
- perturb_,
- nearestOnly
- )
- );
-
- // Read the times for which data is available
- const fileName samplePointsDir = samplePointsFile.path();
- sampleTimes_ = Time::findTimes(samplePointsDir);
-
- DebugInfo
- << "In directory "
- << samplePointsDir << " found times "
- << pointToPointPlanarInterpolation::timeNames(sampleTimes_)
- << endl;
- }
-
-
- // Find current time in sampleTimes
- label lo = -1;
- label hi = -1;
-
- bool foundTime = mapperPtr_().findTime
- (
- sampleTimes_,
- startSampleTime_,
- this->db().time().value(),
- lo,
- hi
- );
-
- if (!foundTime)
- {
- FatalErrorInFunction
- << "Cannot find starting sampling values for current time "
- << this->db().time().value() << nl
- << "Have sampling values for times "
- << pointToPointPlanarInterpolation::timeNames(sampleTimes_) << nl
- << "In directory "
- << this->db().time().constant()/"boundaryData"/this->patch().name()
- << "\n on patch " << this->patch().name()
- << " of field " << fieldTableName_
- << exit(FatalError);
- }
-
-
- // Update sampled data fields.
-
- if (lo != startSampleTime_)
- {
- startSampleTime_ = lo;
-
- if (startSampleTime_ == endSampleTime_)
- {
- // No need to reread since are end values
- if (debug)
- {
- Pout<< "checkTable : Setting startValues to (already read) "
- << "boundaryData"
- /this->patch().name()
- /sampleTimes_[startSampleTime_].name()
- << endl;
- }
- startSampledValues_ = endSampledValues_;
- startAverage_ = endAverage_;
- }
- else
- {
- if (debug)
- {
- Pout<< "checkTable : Reading startValues from "
- << "boundaryData"
- /this->patch().name()
- /sampleTimes_[lo].name()
- << endl;
- }
-
-
- // Reread values and interpolate
- fileName valsFile
- (
- this->db().time().path()
- /this->db().time().caseConstant()
- /"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 " << valsFile << exit(FatalError);
- }
-
- startSampledValues_ = mapperPtr_().interpolate(vals);
- }
- }
-
- if (hi != endSampleTime_)
- {
- endSampleTime_ = hi;
-
- if (endSampleTime_ == -1)
- {
- // endTime no longer valid. Might as well clear endValues.
- if (debug)
- {
- Pout<< "checkTable : Clearing endValues" << endl;
- }
- endSampledValues_.clear();
- }
- else
- {
- if (debug)
- {
- Pout<< "checkTable : Reading endValues from "
- << "boundaryData"
- /this->patch().name()
- /sampleTimes_[endSampleTime_].name()
- << endl;
- }
-
- // Reread values and interpolate
- fileName valsFile
- (
- this->db().time().path()
- /this->db().time().caseConstant()
- /"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 " << valsFile << exit(FatalError);
- }
-
- endSampledValues_ = mapperPtr_().interpolate(vals);
- }
- }
+ uniformValue_().rmap(tiptf.uniformValue_(), addr);
}
@@ -466,93 +177,8 @@ void Foam::timeVaryingMappedFixedValueFvPatchField::updateCoeffs()
}
- checkTable();
-
- // Interpolate between the sampled data
-
- Type wantedAverage;
-
- if (endSampleTime_ == -1)
- {
- // Only start value
- if (debug)
- {
- Pout<< "updateCoeffs : Sampled, non-interpolated values"
- << " from start time:"
- << sampleTimes_[startSampleTime_].name() << nl;
- }
-
- this->operator==(startSampledValues_);
- wantedAverage = startAverage_;
- }
- else
- {
- scalar start = sampleTimes_[startSampleTime_].value();
- scalar end = sampleTimes_[endSampleTime_].value();
-
- scalar s = (this->db().time().value() - start)/(end - start);
-
- if (debug)
- {
- Pout<< "updateCoeffs : Sampled, interpolated values"
- << " between start time:"
- << sampleTimes_[startSampleTime_].name()
- << " and end time:" << sampleTimes_[endSampleTime_].name()
- << " with weight:" << s << endl;
- }
-
- this->operator==((1 - s)*startSampledValues_ + s*endSampledValues_);
- wantedAverage = (1 - s)*startAverage_ + s*endAverage_;
- }
-
- // Enforce average. Either by scaling (if scaling factor > 0.5) or by
- // offsetting.
- if (setAverage_)
- {
- const Field& fld = *this;
-
- Type averagePsi =
- gSum(this->patch().magSf()*fld)
- /gSum(this->patch().magSf());
-
- if (debug)
- {
- Pout<< "updateCoeffs :"
- << " actual average:" << averagePsi
- << " wanted average:" << wantedAverage
- << endl;
- }
-
- if (mag(averagePsi) < VSMALL)
- {
- // Field too small to scale. Offset instead.
- const Type offset = wantedAverage - averagePsi;
- if (debug)
- {
- Pout<< "updateCoeffs :"
- << " offsetting with:" << offset << endl;
- }
- this->operator==(fld + offset);
- }
- else
- {
- const scalar scale = mag(wantedAverage)/mag(averagePsi);
-
- if (debug)
- {
- Pout<< "updateCoeffs :"
- << " scaling with:" << scale << endl;
- }
- this->operator==(scale*fld);
- }
- }
-
- // Apply offset to mapped values
- if (offset_.valid())
- {
- const scalar t = this->db().time().timeOutputValue();
- this->operator==(*this + offset_->value(t));
- }
+ const scalar t = this->db().time().timeOutputValue();
+ fvPatchField::operator==(uniformValue_->value(t));
if (debug)
{
@@ -572,35 +198,7 @@ void Foam::timeVaryingMappedFixedValueFvPatchField::write
) const
{
fvPatchField::write(os);
-
- os.writeEntryIfDifferent
- (
- "fieldTable",
- this->internalField().name(),
- fieldTableName_
- );
-
- if (setAverage_)
- {
- os.writeEntry("setAverage", setAverage_);
- }
-
- os.writeEntryIfDifferent("perturb", 1e-5, perturb_);
-
- os.writeEntryIfDifferent("points", "points", pointsName_);
-
- os.writeEntryIfDifferent
- (
- "mapMethod",
- "planarInterpolation",
- mapMethod_
- );
-
- if (offset_.valid())
- {
- offset_->writeData(os);
- }
-
+ uniformValue_->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 d832ee1ae8..ae967f0b79 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H
+++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchField.H
@@ -76,10 +76,7 @@ SourceFiles
#define timeVaryingMappedFixedValueFvPatchField_H
#include "fixedValueFvPatchFields.H"
-#include "FixedList.H"
-#include "instantList.H"
-#include "pointToPointPlanarInterpolation.H"
-#include "Function1.H"
+#include "MappedFile.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -97,47 +94,7 @@ class timeVaryingMappedFixedValueFvPatchField
{
// Private data
- //- Name of the field data table, defaults to the name of the field
- word fieldTableName_;
-
- //- If true adjust the mapped field to maintain average value
- Switch setAverage_;
-
- //- Fraction of perturbation (fraction of bounding box) to add
- scalar perturb_;
-
- //- Name of points file; default = "points"
- word pointsName_;
-
- //- Interpolation scheme to use
- word mapMethod_;
-
- //- 2D interpolation (for 'planarInterpolation' mapMethod)
- autoPtr mapperPtr_;
-
- //- List of boundaryData time directories
- instantList sampleTimes_;
-
- //- Current starting index in sampleTimes
- label startSampleTime_;
-
- //- Interpolated values from startSampleTime
- Field startSampledValues_;
-
- //- If setAverage: starting average value
- Type startAverage_;
-
- //- Current end index in sampleTimes
- label endSampleTime_;
-
- //- Interpolated values from endSampleTime
- Field endSampledValues_;
-
- //- If setAverage: end average value
- Type endAverage_;
-
- //- Time varying offset values to interpolated data
- autoPtr> offset_;
+ autoPtr> uniformValue_;
public:
@@ -210,15 +167,6 @@ public:
// Member functions
- // Access
-
- //- Return startSampledValues
- const Field startSampledValues()
- {
- return startSampledValues_;
- }
-
-
// Mapping functions
//- Map (and resize as needed) from self given a mapping object
@@ -235,12 +183,6 @@ public:
);
- // Utility functions
-
- //- Find boundary data inbetween current time and interpolate
- void checkTable();
-
-
// Evaluation functions
//- Update the coefficients associated with the patch field
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.C
index dc4d7c8a93..853502055a 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.C
@@ -61,7 +61,7 @@ Foam::uniformFixedValueFvPatchField::uniformFixedValueFvPatchField
)
:
fixedValueFvPatchField(p, iF, dict, false),
- uniformValue_(Function1::New("uniformValue", dict))
+ uniformValue_(PatchFunction1::New(p.patch(), "uniformValue", dict))
{
this->evaluate();
}
@@ -77,7 +77,7 @@ Foam::uniformFixedValueFvPatchField::uniformFixedValueFvPatchField
)
:
fixedValueFvPatchField(p, iF), // Don't map
- uniformValue_(ptf.uniformValue_.clone())
+ uniformValue_(ptf.uniformValue_.clone(p.patch()))
{
// Evaluate since value not mapped
this->evaluate();
@@ -106,7 +106,7 @@ Foam::uniformFixedValueFvPatchField::uniformFixedValueFvPatchField
uniformValue_(ptf.uniformValue_.clone())
{
// Evaluate the profile if defined
- if (ptf.uniformValue_.valid())
+ if (uniformValue_.valid())
{
this->evaluate();
}
@@ -125,7 +125,6 @@ void Foam::uniformFixedValueFvPatchField::updateCoeffs()
const scalar t = this->db().time().timeOutputValue();
fvPatchField::operator==(uniformValue_->value(t));
-
fixedValueFvPatchField::updateCoeffs();
}
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.H
index 36f3972980..0e725abdc1 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.H
+++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue/uniformFixedValueFvPatchField.H
@@ -63,7 +63,7 @@ SourceFiles
#define uniformFixedValueFvPatchField_H
#include "fixedValueFvPatchFields.H"
-#include "Function1.H"
+#include "PatchFunction1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -81,7 +81,7 @@ class uniformFixedValueFvPatchField
{
// Private data
- autoPtr> uniformValue_;
+ autoPtr> uniformValue_;
public:
diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files
index 1759739ff9..58c3fa156f 100644
--- a/src/meshTools/Make/files
+++ b/src/meshTools/Make/files
@@ -275,6 +275,9 @@ mappedPatches/mappedPolyPatch/mappedVariableThicknessWallPolyPatch.C
mappedPatches/mappedPointPatch/mappedPointPatch.C
mappedPatches/mappedPointPatch/mappedWallPointPatch.C
+PatchFunction1/makePatchFunction1s.C
+PatchFunction1/coordinateLabelScaling.C
+
meshStructure/meshStructure.C
meshStructure/topoDistanceData.C
meshStructure/pointTopoDistanceData.C
diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.C b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C
new file mode 100644
index 0000000000..a6afaa09f4
--- /dev/null
+++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.C
@@ -0,0 +1,118 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\/ 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 .
+
+\*---------------------------------------------------------------------------*/
+
+#include "ConstantField.H"
+
+// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
+
+template
+Foam::PatchFunction1Types::ConstantField::ConstantField
+(
+ const polyPatch& pp,
+ const word& entryName,
+ const Field& value,
+ const dictionary& dict,
+ const bool faceValues
+)
+:
+ PatchFunction1(pp, entryName, dict, faceValues),
+ value_(value)
+{}
+
+
+template
+Foam::PatchFunction1Types::ConstantField::ConstantField
+(
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict,
+ const bool faceValues
+)
+:
+ PatchFunction1(pp, entryName, dict, faceValues),
+ value_(entryName, dict, pp.size())
+{}
+
+
+template
+Foam::PatchFunction1Types::ConstantField::ConstantField
+(
+ const ConstantField& cnst
+)
+:
+ PatchFunction1(cnst),
+ value_(cnst.value_)
+{}
+
+
+template
+Foam::PatchFunction1Types::ConstantField::ConstantField
+(
+ const ConstantField& cnst,
+ const polyPatch& pp
+)
+:
+ PatchFunction1(cnst, pp),
+ value_(cnst.value_)
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+template
+void Foam::PatchFunction1Types::ConstantField::autoMap
+(
+ const FieldMapper& mapper
+)
+{
+ value_.autoMap(mapper);
+}
+
+
+template
+void Foam::PatchFunction1Types::ConstantField::rmap
+(
+ const PatchFunction1& pf1,
+ const labelList& addr
+)
+{
+ const auto& cst = refCast>(pf1);
+ value_.rmap(cst.value_, addr);
+}
+
+
+template
+void Foam::PatchFunction1Types::ConstantField::writeData
+(
+ Ostream& os
+) const
+{
+ PatchFunction1::writeData(os);
+ //os << token::SPACE << value_ << token::END_STATEMENT << nl;
+ value_.writeEntry(this->name_, os);
+}
+
+
+// ************************************************************************* //
diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.H b/src/meshTools/PatchFunction1/ConstantField/ConstantField.H
new file mode 100644
index 0000000000..703cfc49c1
--- /dev/null
+++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.H
@@ -0,0 +1,182 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
+ \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
+-------------------------------------------------------------------------------
+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 .
+
+Class
+ Foam::PatchFunction1Types::ConstantField
+
+Description
+ Templated function that returns a constant value.
+
+ Usage - for entry \ returning the value :
+ \verbatim
+ constant
+ \endverbatim
+
+SourceFiles
+ ConstantField.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef PatchFunction1Types_ConstantField_H
+#define PatchFunction1Types_ConstantField_H
+
+#include "PatchFunction1.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace PatchFunction1Types
+{
+
+/*---------------------------------------------------------------------------*\
+ Class ConstantField Declaration
+\*---------------------------------------------------------------------------*/
+
+template
+class ConstantField
+:
+ public PatchFunction1
+{
+ // Private data
+
+ //- ConstantField value
+ Field value_;
+
+
+ // Private Member Functions
+
+ //- No copy assignment
+ void operator=(const ConstantField&) = delete;
+
+
+public:
+
+ // Runtime type information
+ TypeName("constant");
+
+
+ // Constructors
+
+ //- Construct from components
+ ConstantField
+ (
+ const polyPatch& pp,
+ const word& entryName,
+ const Field& value,
+ const dictionary& dict = dictionary::null,
+ const bool faceValues = true
+ );
+
+ //- Construct from entry name and dictionary
+ ConstantField
+ (
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict,
+ const bool faceValues = true
+ );
+
+ //- Copy constructor
+ explicit ConstantField(const ConstantField& cnst);
+
+ //- Copy constructor setting patch
+ explicit ConstantField
+ (
+ const ConstantField& cnst,
+ const polyPatch& pp
+ );
+
+ //- Construct and return a clone
+ virtual tmp> clone() const
+ {
+ return tmp>(new ConstantField(*this));
+ }
+
+ //- Construct and return a clone setting patch
+ virtual tmp> clone(const polyPatch& pp) const
+ {
+ return tmp>
+ (
+ new ConstantField(*this, pp)
+ );
+ }
+
+
+ //- Destructor
+ virtual ~ConstantField() = default;
+
+
+ // Member Functions
+
+ // Evaluation
+
+ //- Return constant value
+ virtual inline tmp> value(const scalar) const;
+
+ //- Integrate between two values
+ virtual inline tmp> integrate
+ (
+ const scalar x1,
+ const scalar x2
+ ) const;
+
+
+ // Mapping
+
+ //- Map (and resize as needed) from self given a mapping object
+ virtual void autoMap(const FieldMapper& mapper);
+
+ //- Reverse map the given PatchFunction1 onto this PatchFunction1
+ virtual void rmap
+ (
+ const PatchFunction1& pf1,
+ const labelList& addr
+ );
+
+
+ // I-O
+
+ //- Write in dictionary format
+ virtual void writeData(Ostream& os) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace PatchFunction1Types
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#include "ConstantFieldI.H"
+
+#ifdef NoRepository
+ #include "ConstantField.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantFieldI.H b/src/meshTools/PatchFunction1/ConstantField/ConstantFieldI.H
new file mode 100644
index 0000000000..cdb8f903b6
--- /dev/null
+++ b/src/meshTools/PatchFunction1/ConstantField/ConstantFieldI.H
@@ -0,0 +1,67 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2017 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 .
+
+\*---------------------------------------------------------------------------*/
+
+#include "ConstantField.H"
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+template
+inline Foam::tmp>
+Foam::PatchFunction1Types::ConstantField::value
+(
+ const scalar x
+) const
+{
+ if (this->coordSys_.active())
+ {
+ return this->transform(value_);
+ }
+ else
+ {
+ return value_;
+ }
+}
+
+
+template
+inline Foam::tmp>
+Foam::PatchFunction1Types::ConstantField::integrate
+(
+ const scalar x1,
+ const scalar x2
+) const
+{
+ if (this->coordSys_.active())
+ {
+ return (x2 - x1)* this->transform(value_);
+ }
+ else
+ {
+ return (x2 - x1)*value_;
+ }
+}
+
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.C b/src/meshTools/PatchFunction1/MappedFile/AverageField.C
similarity index 100%
rename from src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.C
rename to src/meshTools/PatchFunction1/MappedFile/AverageField.C
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.H b/src/meshTools/PatchFunction1/MappedFile/AverageField.H
similarity index 100%
rename from src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMappedFixedValue/AverageField.H
rename to src/meshTools/PatchFunction1/MappedFile/AverageField.H
diff --git a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C
new file mode 100644
index 0000000000..a13da99ab1
--- /dev/null
+++ b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C
@@ -0,0 +1,638 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\/ 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 .
+
+\*---------------------------------------------------------------------------*/
+
+#include "polyMesh.H"
+#include "IFstream.H"
+#include "AverageField.H"
+
+// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
+
+template
+Foam::PatchFunction1Types::MappedFile::MappedFile
+(
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict,
+ const bool faceValues
+)
+:
+ PatchFunction1(pp, entryName, dict, faceValues),
+ dictConstructed_(true),
+ fieldTableName_(entryName),
+ setAverage_(dict.lookupOrDefault("setAverage", false)),
+ perturb_(dict.lookupOrDefault("perturb", 1e-5)),
+ pointsName_(dict.lookupOrDefault("points", "points")),
+ mapMethod_
+ (
+ dict.lookupOrDefault
+ (
+ "mapMethod",
+ "planarInterpolation"
+ )
+ ),
+ mapperPtr_(nullptr),
+ sampleTimes_(0),
+ startSampleTime_(-1),
+ startSampledValues_(0),
+ startAverage_(Zero),
+ endSampleTime_(-1),
+ endSampledValues_(0),
+ endAverage_(Zero),
+ offset_()
+{
+ if (dict.found("offset"))
+ {
+ offset_ = Function1::New("offset", dict);
+ }
+
+ if
+ (
+ mapMethod_ != "planarInterpolation"
+ && mapMethod_ != "nearest"
+ )
+ {
+ FatalIOErrorInFunction(dict)
+ << "mapMethod should be one of 'planarInterpolation'"
+ << ", 'nearest'" << exit(FatalIOError);
+ }
+
+ dict.readIfPresent("fieldTable", fieldTableName_);
+}
+
+
+template
+Foam::PatchFunction1Types::MappedFile::MappedFile
+(
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict,
+ const word& fieldTableName,
+ const bool faceValues
+)
+:
+ PatchFunction1(pp, entryName, dict, faceValues),
+ dictConstructed_(false),
+ fieldTableName_(fieldTableName),
+ setAverage_(dict.lookupOrDefault("setAverage", false)),
+ perturb_(dict.lookupOrDefault("perturb", 1e-5)),
+ pointsName_(dict.lookupOrDefault("points", "points")),
+ mapMethod_
+ (
+ dict.lookupOrDefault
+ (
+ "mapMethod",
+ "planarInterpolation"
+ )
+ ),
+ mapperPtr_(nullptr),
+ sampleTimes_(0),
+ startSampleTime_(-1),
+ startSampledValues_(0),
+ startAverage_(Zero),
+ endSampleTime_(-1),
+ endSampledValues_(0),
+ endAverage_(Zero),
+ offset_()
+{
+ if (dict.found("offset"))
+ {
+ offset_ = Function1::New("offset", dict);
+ }
+
+ if
+ (
+ mapMethod_ != "planarInterpolation"
+ && mapMethod_ != "nearest"
+ )
+ {
+ FatalIOErrorInFunction(dict)
+ << "mapMethod should be one of 'planarInterpolation'"
+ << ", 'nearest'" << exit(FatalIOError);
+ }
+}
+
+
+template
+Foam::PatchFunction1Types::MappedFile::MappedFile
+(
+ const MappedFile& ut
+)
+:
+ PatchFunction1(ut),
+ dictConstructed_(ut.dictConstructed_),
+ fieldTableName_(ut.fieldTableName_),
+ setAverage_(ut.setAverage_),
+ perturb_(ut.perturb_),
+ pointsName_(ut.pointsName_),
+ mapMethod_(ut.mapMethod_),
+ mapperPtr_(ut.mapperPtr_.clone()),
+ sampleTimes_(ut.sampleTimes_),
+ startSampleTime_(ut.startSampleTime_),
+ startSampledValues_(ut.startSampledValues_),
+ startAverage_(ut.startAverage_),
+ endSampleTime_(ut.endSampleTime_),
+ endSampledValues_(ut.endSampledValues_),
+ endAverage_(ut.endAverage_),
+ offset_(ut.offset_.clone())
+{}
+
+
+template
+Foam::PatchFunction1Types::MappedFile::MappedFile
+(
+ const MappedFile& ut,
+ const polyPatch& pp
+)
+:
+ PatchFunction1(ut, pp),
+ dictConstructed_(ut.dictConstructed_),
+ fieldTableName_(ut.fieldTableName_),
+ setAverage_(ut.setAverage_),
+ perturb_(ut.perturb_),
+ pointsName_(ut.pointsName_),
+ mapMethod_(ut.mapMethod_),
+ mapperPtr_(ut.mapperPtr_.clone()),
+ sampleTimes_(ut.sampleTimes_),
+ startSampleTime_(ut.startSampleTime_),
+ startSampledValues_(ut.startSampledValues_),
+ startAverage_(ut.startAverage_),
+ endSampleTime_(ut.endSampleTime_),
+ endSampledValues_(ut.endSampledValues_),
+ endAverage_(ut.endAverage_),
+ offset_(ut.offset_.clone())
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+template
+void Foam::PatchFunction1Types::MappedFile::autoMap
+(
+ const FieldMapper& mapper
+)
+{
+ PatchFunction1::autoMap(mapper);
+
+ if (startSampledValues_.size())
+ {
+ startSampledValues_.autoMap(mapper);
+ endSampledValues_.autoMap(mapper);
+ }
+ // Clear interpolator
+ mapperPtr_.clear();
+ startSampleTime_ = -1;
+ endSampleTime_ = -1;
+}
+
+
+template
+void Foam::PatchFunction1Types::MappedFile::rmap
+(
+ const PatchFunction1& pf1,
+ const labelList& addr
+)
+{
+ PatchFunction1::rmap(pf1, addr);
+
+ const PatchFunction1Types::MappedFile& tiptf =
+ refCast>(pf1);
+
+ startSampledValues_.rmap(tiptf.startSampledValues_, addr);
+ endSampledValues_.rmap(tiptf.endSampledValues_, addr);
+
+ // Clear interpolator
+ mapperPtr_.clear();
+ startSampleTime_ = -1;
+ endSampleTime_ = -1;
+}
+
+
+template
+void Foam::PatchFunction1Types::MappedFile::checkTable
+(
+ const scalar t
+) const
+{
+ const polyMesh& mesh = this->patch_.boundaryMesh().mesh();
+
+ // Initialise
+ if (mapperPtr_.empty())
+ {
+ // Reread values and interpolate
+ fileName samplePointsFile
+ (
+ mesh.time().path()
+ /mesh.time().caseConstant()
+ /"boundaryData"
+ /this->patch_.name()
+ /pointsName_
+ );
+
+ pointField samplePoints((IFstream(samplePointsFile)()));
+
+ DebugInfo
+ << "Read " << samplePoints.size() << " sample points from "
+ << samplePointsFile << endl;
+
+
+ // tbd: run-time selection
+ bool nearestOnly =
+ (
+ !mapMethod_.empty()
+ && mapMethod_ != "planarInterpolation"
+ );
+
+ // Allocate the interpolator
+ if (this->faceValues_)
+ {
+ mapperPtr_.reset
+ (
+ new pointToPointPlanarInterpolation
+ (
+ samplePoints,
+ this->localPosition(this->patch_.faceCentres()),
+ perturb_,
+ nearestOnly
+ )
+ );
+ }
+ else
+ {
+ mapperPtr_.reset
+ (
+ new pointToPointPlanarInterpolation
+ (
+ samplePoints,
+ this->localPosition(this->patch_.localPoints()),
+ perturb_,
+ nearestOnly
+ )
+ );
+ }
+
+
+
+ // Read the times for which data is available
+ const fileName samplePointsDir = samplePointsFile.path();
+ sampleTimes_ = Time::findTimes(samplePointsDir);
+
+ DebugInfo
+ << "In directory "
+ << samplePointsDir << " found times "
+ << pointToPointPlanarInterpolation::timeNames(sampleTimes_)
+ << endl;
+ }
+
+
+ // Find current time in sampleTimes
+ label lo = -1;
+ label hi = -1;
+
+ bool foundTime = mapperPtr_().findTime
+ (
+ sampleTimes_,
+ startSampleTime_,
+ t, //mesh.time().value(),
+ lo,
+ hi
+ );
+
+ if (!foundTime)
+ {
+ FatalErrorInFunction
+ << "Cannot find starting sampling values for index "
+ << t << nl
+ << "Have sampling values for "
+ << pointToPointPlanarInterpolation::timeNames(sampleTimes_) << nl
+ << "In directory "
+ << mesh.time().constant()/"boundaryData"/this->patch_.name()
+ << "\n on patch " << this->patch_.name()
+ << " of field " << fieldTableName_
+ << exit(FatalError);
+ }
+
+
+ // Update sampled data fields.
+
+ if (lo != startSampleTime_)
+ {
+ startSampleTime_ = lo;
+
+ if (startSampleTime_ == endSampleTime_)
+ {
+ // No need to reread since are end values
+ if (debug)
+ {
+ Pout<< "checkTable : Setting startValues to (already read) "
+ << "boundaryData"
+ /this->patch_.name()
+ /sampleTimes_[startSampleTime_].name()
+ << endl;
+ }
+ startSampledValues_ = endSampledValues_;
+ startAverage_ = endAverage_;
+ }
+ else
+ {
+ if (debug)
+ {
+ Pout<< "checkTable : Reading startValues from "
+ << "boundaryData"
+ /this->patch_.name()
+ /sampleTimes_[lo].name()
+ << endl;
+ }
+
+
+ // Reread values and interpolate
+ fileName valsFile
+ (
+ mesh.time().path()
+ /mesh.time().caseConstant()
+ /"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 " << valsFile << exit(FatalError);
+ }
+
+ startSampledValues_ = mapperPtr_().interpolate(vals);
+ }
+ }
+
+ if (hi != endSampleTime_)
+ {
+ endSampleTime_ = hi;
+
+ if (endSampleTime_ == -1)
+ {
+ // endTime no longer valid. Might as well clear endValues.
+ if (debug)
+ {
+ Pout<< "checkTable : Clearing endValues" << endl;
+ }
+ endSampledValues_.clear();
+ }
+ else
+ {
+ if (debug)
+ {
+ Pout<< "checkTable : Reading endValues from "
+ << "boundaryData"
+ /this->patch_.name()
+ /sampleTimes_[endSampleTime_].name()
+ << endl;
+ }
+
+ // Reread values and interpolate
+ fileName valsFile
+ (
+ mesh.time().path()
+ /mesh.time().caseConstant()
+ /"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 " << valsFile << exit(FatalError);
+ }
+
+ endSampledValues_ = mapperPtr_().interpolate(vals);
+ }
+ }
+}
+
+
+template
+Foam::tmp>
+Foam::PatchFunction1Types::MappedFile::value
+(
+ const scalar x
+) const
+{
+ checkTable(x);
+
+ auto tfld = tmp>::New(startSampledValues_.size());
+ Field& fld = tfld.ref();
+ Type wantedAverage;
+
+ if (endSampleTime_ == -1)
+ {
+ // Only start value
+ if (debug)
+ {
+ Pout<< "MappedFile::value : Sampled, non-interpolated values"
+ << " from start time:"
+ << sampleTimes_[startSampleTime_].name() << nl;
+ }
+
+ fld = startSampledValues_;
+ wantedAverage = startAverage_;
+ }
+ else
+ {
+ scalar start = sampleTimes_[startSampleTime_].value();
+ scalar end = sampleTimes_[endSampleTime_].value();
+
+ scalar s = (x - start)/(end - start);
+
+ if (debug)
+ {
+ Pout<< "MappedFile::value : Sampled, interpolated values"
+ << " between start time:"
+ << sampleTimes_[startSampleTime_].name()
+ << " and end time:" << sampleTimes_[endSampleTime_].name()
+ << " with weight:" << s << endl;
+ }
+
+ fld = ((1 - s)*startSampledValues_ + s*endSampledValues_);
+ wantedAverage = (1 - s)*startAverage_ + s*endAverage_;
+ }
+
+ // Enforce average. Either by scaling (if scaling factor > 0.5) or by
+ // offsetting.
+ if (setAverage_)
+ {
+ Type averagePsi;
+ if (this->faceValues_)
+ {
+ const scalarField magSf(mag(this->patch_.faceAreas()));
+ averagePsi = gSum(magSf*fld)/gSum(magSf);
+ }
+ else
+ {
+ averagePsi = gAverage(fld);
+ }
+
+ if (debug)
+ {
+ Pout<< "MappedFile::value :"
+ << " actual average:" << averagePsi
+ << " wanted average:" << wantedAverage
+ << endl;
+ }
+
+ if (mag(averagePsi) < VSMALL)
+ {
+ // Field too small to scale. Offset instead.
+ const Type offset = wantedAverage - averagePsi;
+ if (debug)
+ {
+ Pout<< "MappedFile::value :"
+ << " offsetting with:" << offset << endl;
+ }
+ fld += offset;
+ }
+ else
+ {
+ const scalar scale = mag(wantedAverage)/mag(averagePsi);
+
+ if (debug)
+ {
+ Pout<< "MappedFile::value :"
+ << " scaling with:" << scale << endl;
+ }
+ fld *= scale;
+ }
+ }
+
+ // Apply offset to mapped values
+ if (offset_.valid())
+ {
+ fld += offset_->value(x);
+ }
+
+ if (debug)
+ {
+ Pout<< "MappedFile::value : set fixedValue to min:" << gMin(fld)
+ << " max:" << gMax(fld)
+ << " avg:" << gAverage(fld) << endl;
+ }
+
+ return this->transform(tfld);
+}
+
+
+template
+Foam::tmp>
+Foam::PatchFunction1Types::MappedFile::integrate
+(
+ const scalar x1,
+ const scalar x2
+) const
+{
+ NotImplemented;
+ return nullptr;
+}
+
+
+template
+void Foam::PatchFunction1Types::MappedFile::writeData
+(
+ Ostream& os
+) const
+{
+ PatchFunction1::writeData(os);
+
+ // Check if field name explicitly provided (e.g. through timeVaryingMapped
+ // bc)
+ if (dictConstructed_)
+ {
+ os.writeKeyword(this->name()) << type();
+ os << token::END_STATEMENT << nl;
+
+ os.writeEntryIfDifferent
+ (
+ "fieldTable",
+ this->name(),
+ fieldTableName_
+ );
+ }
+
+ if (setAverage_)
+ {
+ os.writeEntry("setAverage", setAverage_);
+ }
+
+ os.writeEntryIfDifferent("perturb", 1e-5, perturb_);
+
+ os.writeEntryIfDifferent("points", "points", pointsName_);
+
+ os.writeEntryIfDifferent
+ (
+ "mapMethod",
+ "planarInterpolation",
+ mapMethod_
+ );
+
+ if (offset_.valid())
+ {
+ offset_->writeData(os);
+ }
+}
+
+
+// ************************************************************************* //
diff --git a/src/meshTools/PatchFunction1/MappedFile/MappedFile.H b/src/meshTools/PatchFunction1/MappedFile/MappedFile.H
new file mode 100644
index 0000000000..89840c2a63
--- /dev/null
+++ b/src/meshTools/PatchFunction1/MappedFile/MappedFile.H
@@ -0,0 +1,223 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\/ 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 .
+
+Class
+ Foam::PatchFunction1Types::MappedFile
+
+Description
+
+SourceFiles
+ MappedFile.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef PatchFunction1Types_MappedFile_H
+#define PatchFunction1Types_MappedFile_H
+
+#include "PatchFunction1.H"
+#include "pointToPointPlanarInterpolation.H"
+#include "Function1.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace PatchFunction1Types
+{
+
+/*---------------------------------------------------------------------------*\
+ Class MappedFile Declaration
+\*---------------------------------------------------------------------------*/
+
+template
+class MappedFile
+:
+ public PatchFunction1
+{
+ // Private data
+
+ //- Whether constructed from dictionary
+ const bool dictConstructed_;
+
+ //- Name of the field data table, defaults to the name of the field
+ word fieldTableName_;
+
+ //- If true adjust the mapped field to maintain average value
+ Switch setAverage_;
+
+ //- Fraction of perturbation (fraction of bounding box) to add
+ scalar perturb_;
+
+ //- Name of points file; default = "points"
+ word pointsName_;
+
+ //- Interpolation scheme to use
+ word mapMethod_;
+
+ //- 2D interpolation (for 'planarInterpolation' mapMethod)
+ mutable autoPtr mapperPtr_;
+
+ //- List of boundaryData time directories
+ mutable instantList sampleTimes_;
+
+ //- Current starting index in sampleTimes
+ mutable label startSampleTime_;
+
+ //- Interpolated values from startSampleTime
+ mutable Field startSampledValues_;
+
+ //- If setAverage: starting average value
+ mutable Type startAverage_;
+
+ //- Current end index in sampleTimes
+ mutable label endSampleTime_;
+
+ //- Interpolated values from endSampleTime
+ mutable Field endSampledValues_;
+
+ //- If setAverage: end average value
+ mutable Type endAverage_;
+
+ //- Time varying offset values to interpolated data
+ autoPtr> offset_;
+
+
+ // Private Member Functions
+
+ void checkTable(const scalar t) const;
+
+ //- No copy assignment
+ void operator=(const MappedFile&) = delete;
+
+
+public:
+
+ // Runtime type information
+ TypeName("mappedFile");
+
+
+ // Constructors
+
+ //- Construct from entry name and dictionary
+ MappedFile
+ (
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict,
+ const bool faceValues = true
+ );
+
+ //- Construct from entry name and dictionary
+ MappedFile
+ (
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict,
+ const word& fieldTableName,
+ const bool faceValues
+ );
+
+ //- Copy constructor
+ explicit MappedFile(const MappedFile& ut);
+
+ //- Copy constructor setting patch
+ explicit MappedFile
+ (
+ const MappedFile& ut,
+ const polyPatch& pp
+ );
+
+ //- Construct and return a clone
+ virtual tmp> clone() const
+ {
+ return tmp>
+ (
+ new MappedFile(*this)
+ );
+ }
+
+ //- Construct and return a clone setting patch
+ virtual tmp> clone(const polyPatch& pp) const
+ {
+ return tmp>
+ (
+ new MappedFile(*this, pp)
+ );
+ }
+
+
+ //- Destructor
+ virtual ~MappedFile() = default;
+
+
+ // Member Functions
+
+ // Evaluation
+
+ //- Return MappedFile value
+ virtual tmp> value(const scalar) const;
+
+ //- Integrate between two values
+ virtual tmp> integrate
+ (
+ const scalar x1,
+ const scalar x2
+ ) const;
+
+
+ // Mapping
+
+ //- Map (and resize as needed) from self given a mapping object
+ virtual void autoMap(const FieldMapper& mapper);
+
+ //- Reverse map the given PatchFunction1 onto this PatchFunction1
+ virtual void rmap
+ (
+ const PatchFunction1& pf1,
+ const labelList& addr
+ );
+
+
+ // I-O
+
+ //- Write in dictionary format
+ virtual void writeData(Ostream& os) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace PatchFunction1Types
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#ifdef NoRepository
+ #include "MappedFile.C"
+#endif
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/meshTools/PatchFunction1/PatchFunction1.C b/src/meshTools/PatchFunction1/PatchFunction1.C
new file mode 100644
index 0000000000..2c41e53b90
--- /dev/null
+++ b/src/meshTools/PatchFunction1/PatchFunction1.C
@@ -0,0 +1,232 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\/ 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 .
+
+\*---------------------------------------------------------------------------*/
+
+#include "PatchFunction1.H"
+#include "Time.H"
+#include "polyMesh.H"
+
+// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
+
+template
+Foam::PatchFunction1::PatchFunction1
+(
+ const polyPatch& pp,
+ const word& entryName,
+ const bool faceValues
+)
+:
+ refCount(),
+ name_(entryName),
+ patch_(pp),
+ faceValues_(faceValues),
+ coordSys_()
+{}
+
+
+template
+Foam::PatchFunction1::PatchFunction1
+(
+ const polyPatch& pp,
+ const word& entryName,
+ const dictionary& dict,
+ const bool faceValues
+)
+:
+ refCount(),
+ name_(entryName),
+ patch_(pp),
+ faceValues_(faceValues),
+ coordSys_(pp.boundaryMesh().mesh().thisDb(), dict)
+{}
+
+
+template
+Foam::PatchFunction1::PatchFunction1(const PatchFunction1& pf1)
+:
+ refCount(),
+ name_(pf1.name_),
+ patch_(pf1.patch_),
+ faceValues_(pf1.faceValues_),
+ coordSys_(pf1.coordSys_)
+{}
+
+
+template
+Foam::PatchFunction1::PatchFunction1
+(
+ const PatchFunction1& pf1,
+ const polyPatch& pp
+)
+:
+ refCount(),
+ name_(pf1.name_),
+ patch_(pp),
+ faceValues_(pf1.faceValues_),
+ coordSys_(pf1.coordSys_)
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+template
+const Foam::word& Foam::PatchFunction1::name() const
+{
+ return name_;
+}
+
+
+template
+void Foam::PatchFunction1::convertTimeBase(const Time&)
+{}
+
+
+template
+Foam::tmp> Foam::PatchFunction1::value
+(
+ const scalar x
+) const
+{
+ NotImplemented;
+
+ return Field