Commit 0885f054 authored by Mattijs Janssens's avatar Mattijs Janssens

Feature patch function1

parent 9d60118b
Test-PatchFunction1.C
EXE = $(FOAM_USER_APPBIN)/Test-PatchFunction1
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
This diff is collapsed.
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
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 Type>
class MappedField
:
public PatchFunction1<Type>
{
// 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<pointToPointPlanarInterpolation> mapperPtr_;
//- List of boundaryData time directories
mutable instantList sampleTimes_;
//- Current starting index in sampleTimes
mutable label startSampleTime_;
//- Interpolated values from startSampleTime
mutable Field<Type> startSampledValues_;
//- If setAverage: starting average value
mutable Type startAverage_;
//- Current end index in sampleTimes
mutable label endSampleTime_;
//- Interpolated values from endSampleTime
mutable Field<Type> endSampledValues_;
//- If setAverage: end average value
mutable Type endAverage_;
//- Time varying offset values to interpolated data
autoPtr<Function1<Type>> offset_;
// Private Member Functions
void checkTable() const;
//- No copy assignment
void operator=(const MappedField<Type>&) = delete;
public:
// Runtime type information
TypeName("mapped");
// Constructors
//- Construct from components
MappedField
(
const polyPatch& pp,
const word& entryName,
const Field<Type>& value
);
//- Construct from entry name and dictionary
MappedField
(
const polyPatch& pp,
const word& entryName,
const dictionary& dict
);
//- Copy constructor
explicit MappedField(const MappedField<Type>& ut);
//- Copy constructor setting patch
explicit MappedField
(
const MappedField<Type>& ut,
const polyPatch& pp
);
//- Construct and return a clone
virtual tmp<PatchFunction1<Type>> clone() const
{
return tmp<PatchFunction1<Type>>
(
new MappedField<Type>(*this)
);
}
//- Construct and return a clone setting patch
virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
{
return tmp<PatchFunction1<Type>>
(
new MappedField<Type>(*this, pp)
);
}
//- Destructor
virtual ~MappedField() = default;
// Member Functions
// Evaluation
//- Return MappedField value
virtual inline tmp<Field<Type>> value(const scalar) const;
//- Integrate between two values
virtual inline tmp<Field<Type>> 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<Type>& 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
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "MappedField.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline Foam::tmp<Foam::Field<Type>>
Foam::PatchFunction1Types::MappedField<Type>::value
(
const scalar x
) const
{
const polyMesh& mesh = this->patch_.boundaryMesh().mesh();
checkTable();
tmp<Field<Type>> tfld(new Field<Type>(this->patch_.size()));
Field<Type>& 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<class Type>
inline Foam::tmp<Foam::Field<Type>>
Foam::PatchFunction1Types::MappedField<Type>::integrate
(
const scalar x1,
const scalar x2
) const
{
NotImplemented;
return tmp<Field<Type>>(nullptr);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
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<PatchFunction1<vector>> function1
(
PatchFunction1<vector>::New
(
mesh.boundaryMesh()[0],
"function1",
function1Properties
)
);
scalar x0 = function1Properties.get<scalar>("x0");
scalar x1 = function1Properties.get<scalar>("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;
}
// ************************************************************************* //
/*--------------------------------*- 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)));
}
// ************************************************************************* //
...@@ -47,8 +47,7 @@ SourceFiles ...@@ -47,8 +47,7 @@ SourceFiles
#ifndef Table_H #ifndef Table_H
#define Table_H #define Table_H
#include "Function1.H" #include "TableBase.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
...@@ -76,10 +76,7 @@ SourceFiles ...@@ -76,10 +76,7 @@ SourceFiles
#define timeVaryingMappedFixedValueFvPatchField_H #define timeVaryingMappedFixedValueFvPatchField_H
#include "fixedValueFvPatchFields.H" #include "fixedValueFvPatchFields.H"
#include "FixedList.H" #include "MappedFile.H"
#include "instantList.H"
#include "pointToPointPlanarInterpolation.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -97,47 +94,7 @@ class timeVaryingMappedFixedValueFvPatchField ...@@ -97,47 +94,7 @@ class timeVaryingMappedFixedValueFvPatchField
{ {
// Private data // Private data
//- Name of the field data table, defaults to the name of the field autoPtr<PatchFunction1Types::MappedFile<Type>> uniformValue_;
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<pointToPointPlanarInterpolation> mapperPtr_;
//- List of boundaryData time directories
instantList sampleTimes_;
//- Current starting index in sampleTimes
label startSampleTime_;
//- Interpolated values from startSampleTime
Field<Type> startSampledValues_;
//- If setAverage: starting average value
Type startAverage_;
//- Current end index in sampleTimes
label endSampleTime_;
//- Interpolated values from endSampleTime
Field<Type> endSampledValues_;
//- If setAverage: end average value
Type endAverage_;
//- Time varying offset values to interpolated data
autoPtr<Function1<Type>> offset_;
public: public:
...@@ -210,15 +167,6 @@ public: ...@@ -210,15 +167,6 @@ public:
// Member functions // Member functions
// Access
//- Return startSampledValues
const Field<Type> startSampledValues()
{
return startSampledValues_;