TUT: example of user access for Function1

This commit is contained in:
Mark Olesen
2020-12-11 16:08:07 +01:00
parent b59ae32d68
commit c2692e7c99
3 changed files with 201 additions and 9 deletions

View File

@ -1,14 +1,14 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / O peration | Version: v2106 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format binary;
format ascii;
class volVectorField;
object U;
}
@ -25,13 +25,82 @@ boundaryField
type uniformFixedValue;
value $internalField;
uniformValue table
(
(0 (0 0 0.1))
(1 (0 0 0.1))
(4 (0 0 0.3))
(14 (0 0 0.5))
);
uniformValue
{
type coded;
name examplePatchFunction1;
// Example code to combine/adapt Function1 to PatchFunction1
// User inputs
/// verbose true;
timeFunction
{
type table;
values
(
(0 0.1)
(1 0.1)
(4 0.3)
(14 0.5)
);
}
// ... or a function of time
directionFunction (0 0 1);
// Code implementation.
code
#{
// Persistent (Member) Data
static autoPtr<Function1<scalar>> baseVel;
static autoPtr<Function1<vector>> baseDir;
// Base settings
const dictionary& dict = this->dictionaryContent::dict();
const polyPatch& pp = this->patch();
vector velDir(0, 0, 1);
if (!baseVel)
{
baseVel = Function1<scalar>::New("timeFunction", dict);
}
const bool verbose = dict.getOrDefault<bool>("verbose", false);
if (!baseDir && dict.found("directionFunction"))
{
// ie, NewIfPresent
baseDir = Function1<vector>::New("directionFunction", dict);
InfoErr
<< "Function1 for direction" << nl;
}
if (baseDir)
{
velDir = normalised(baseDir->value(x));
}
if (verbose)
{
InfoErr
<< "vel: " << baseVel->value(x)
<< " dir:" << velDir << nl;
}
return tmp<vectorField>::New
(
pp.size(),
baseVel->value(x) * velDir
);
#};
}
}
outlet