Commit Graph

1324 Commits

Author SHA1 Message Date
bf044f5c47 DimensionedFunction1: Function1 with dimensions
This can be used identically to a standard Function1. In addition, it
also permits specification of the dimensions. This allows the dimensions
to be checked. It also permits unit conversions. For example:

    <name>
    {
        type        table;

        // Dimensions
        xDimensions [CAD];  // Optional. Argument dimensions/units.
                            // Here, this specifies coordinates are in
                            // crank angle degrees (available if using
                            // engine time).
        dimensions  [mm];   // Optional. Value dimensions/units.
                            // Here, values are in mm.

        // Tablulated data
        values
        (
            (0 0)
            (60 12)         // <-- i.e., 12 mm at 60 degrees
            (180 20)
            (240 8)
            (360 0)
        );
        outOfBounds repeat;
    }

This replaces TimeFunction1, as it allows per-function control over
whether the function is considered to be one of real-time or user-time.
2023-08-08 13:11:59 +01:00
3a52ee2ac5 src/OpenFOAM/Make/files: added stepInterpolationWeights.C 2023-08-07 14:28:44 +01:00
50c0530276 stepInterpolationWeights: New interpolation weight for Function1s::Table
Description
    Generates the weight for step-wise interpolation and integration

    The step transitions are at the end of each interval.

The value returned by the Table::value function returns the value set for the
start of each interval within that interval and transitions abruptly to the next
interval value at the start of the next interval.
2023-08-07 12:08:05 +01:00
32a877d236 polyMesh: Prevent "no points/cells" warnings on processor cases 2023-07-28 14:52:04 +01:00
65f3050b35 thermophysicalModels: Renamed he*Thermo classes
The he*Thermo classes have been renamed to match their corresponding
basic thermo classes. E.g., rhoThermo now corresponds to RhoThermo,
rather than heRhoThermo.
2023-07-27 08:39:58 +01:00
966457788c IOerror: Split location into separate class
This simplifies the IOerror constructors and allows for the location to
be conveniently cached for errors that can't be triggered until after
the IO operation.
2023-07-27 08:39:58 +01:00
66188fac7a XiFluid, PDRFoam: Updated so that coefficients can be specified without dimensions
All associated combustion tutorials have been simplified using this functionality.
2023-07-26 14:44:10 +01:00
d194e63820 controlDict::maxDeltaT: Changed to user-time for consistency with other time controls 2023-07-20 17:24:00 +01:00
2779442d2a functionObjects::fluidMaxDeltaT: New functionObject to set the maximum Courant number and time-step
at Function1s of time.

Underlying this new functionObject is a generalisation of the handling of the
maximum time-step in the modular solvers to allow complex user-specification of
the maximum time-step used in a simulation, not just the time-dependency
provided by fluidMaxDeltaT but functions of anything in the simulation by
creating a specialised functionObject in which the maxDeltaT function is
defined.

The chemical and combustion time-scale functionObjects adjustTimeStepToChemistry
and adjustTimeStepToCombustion have been updated and simplified using the above
mechanism.
2023-07-20 14:37:18 +01:00
821be4d281 fvModels: Added virtual writeObject function
which calls the fvModel::write function which defaults to doing nothing but can
be overridden in derived fvModels to write useful state information at the end
of the write-times.
2023-07-17 15:13:34 +01:00
75f0a86384 createMeshNoClear.H: Removed unnecessary header 2023-07-12 16:33:15 +01:00
044bfdb34e functionEntries::calcEntry, codeStream: Added documentation for typed variable lookup 2023-07-11 21:31:18 +01:00
805a7de6d9 dictionary: Removed support for the deprecated "dot" syntax
to simplify maintenance and extension of the current "slash" syntax.
2023-07-11 15:22:44 +01:00
2b3b820c90 Corrected duplicate word and it's typos 2023-07-11 11:02:47 +01:00
441b60c70d functionEntries::calcEntry: Extended the functionality of multi-statement/multi-line #calc
If the code string is delimited by '#{...#}' multiple lines and multiple code
statements can be used to generate the entry using 'os << ...;'.  This is
equivalent to #codeStream but with a more compact syntax, e.g.

maxAngle        30;
nAngles         7;
Us              #calc
    const vector U($<vector>testCalc2!U);
    const int nAngles = $nAngles;
    const scalar angleStep = ($<scalar>maxAngle)/(nAngles - 1);
    List<vector> Us(nAngles);
    for(int i=0; i<nAngles; i++)
    {
        const scalar angle = degToRad(i*angleStep);
        Us[i] = transform(Ry(angle), U);
    }
    os << Us;

Note the 'os << Us;' statement which writes the data to the dictionary entry in
the same manner as #codeStream, this provides flexibility on how the data is
created and written.
2023-07-06 23:11:36 +01:00
36f5a4daa4 stringOps::inplaceExpandCodeString: Now generates a detailed error message
if the variable type is not specified and cannot be deduced from the value.
2023-07-06 16:07:16 +01:00
8d1f918c31 stringOps::inplaceExpandCodeString: Added environment variable path expansion to #calc
This allows #FOAM_CASE for example to be used in #calc variable lookup, e.g. in
test/dictionary/testCalc:

// assuming the testCalc2 file is local
magU            #calc "mag($<vector>testCalc2!U)";

// finding the testCalc2 file using $FOAM_CASE
k               #calc "1.5*magSqr(0.05*$<vector>{${FOAM_CASE}/testCalc2!U})";
2023-07-04 21:51:22 +01:00
9fbb298204 test/dictionary: Added more dictionary tests and examples
All dictionaries are expanded using foamDictionary -expand
2023-07-04 13:44:37 +01:00
d5f038493a Make disallowed constructors and assignment operators public 2023-06-30 22:16:37 +01:00
faf0dd2e35 Ensure delete modifier is applied to disallowed constructors and assignment operators 2023-06-30 17:25:07 +01:00
bcc5169ddc fvMesh: Added meshPhi to the geometricFields set
Also provide fields and curFields functions which return the list of registered
fields not including the geometryFields and current registered fields not
including the geometryFields or old-time fields to simplify mapping code for
NCC, mesh-to-mesh mapping and load-balancing.
2023-06-28 11:53:14 +01:00
8611db460a functionEntries::calcEntry: Added support for #{...#} delimited verbatim string
Class
    Foam::functionEntries::calcEntry

Description
    Compiles and executes code string expressions,
    returning the result to the dictionary

Usage
    \verbatim
    a 1.1;
    b 3.2;
    c #calc "$a*$b";
    \endverbatim

    Special care is required for calc entries that include a division since
    "/" is also used as the scoping operator to identify keywords in
    sub-dictionaries. For example, "$a/b" expects a keyword "b" within a
    sub-dictionary named "a". A division can be correctly executed by using a
    space between a variables and "/", e.g.

    \verbatim
    c #calc "$a / $b";
    \endverbatim

    or bracketing the variable, e.g.

    \verbatim
    c #calc "($a)/$b";
    \endverbatim

    The code string can be delimited either by '"..."' in which newlines must be
    escaped or '#{...#}' which directly supports multi-line strings and is more
    convenient when evaluating string expressions by avoiding the need to
    escape the quotes, e.g.

    \verbatim
    c #calc #{ $a*sqrt($b) #};
    \endverbatim

    \verbatim
    s "field";
    fieldName #calc #{ $<string>s + "Name" #};
    \endverbatim

    Additional include files for the #calc code compilation can be specified
    using the #calcInclude entry, e.g. if functions from transform.H are used
    \verbatim
    angleOfAttack   5; // degs

    angle           #calc "-degToRad($angleOfAttack)";

    #calcInclude    "transform.H"
    liftDir         #calc "transform(Ry($angle), vector(0, 0, 1))";
    dragDir         #calc "transform(Ry($angle), vector(1, 0, 0))";
    \endverbatim

    Note:
        Internally this is just a wrapper around codeStream functionality - the
        #calc string is used to construct a dictionary for codeStream.

See also
    Foam::functionEntries::calcIncludeEntry
2023-06-28 10:58:57 +01:00
0de23df8bb functionEntries::calcIncludeEntry: New dictionary function entry to provide additional include files for #calc
Description
    Specify an include file for #calc, expects a single string to follow.

    For example if functions from transform.H are used in the #calc expression
    \verbatim
    angleOfAttack   5; // degs

    angle           #calc "-degToRad($angleOfAttack)";

    #calcInclude    "transform.H"
    liftDir         #calc "transform(Ry($angle), vector(0, 0, 1))";
    dragDir         #calc "transform(Ry($angle), vector(1, 0, 0))";
    \endverbatim

    The usual expansion of environment variables and other constructs
    (eg, the \c ~OpenFOAM/ expansion) is retained.

See also:

Class
    Foam::functionEntries::calcEntry

Description
    Uses dynamic compilation to provide calculating functionality
    for entering dictionary entries.

    E.g.

    \verbatim
    a 1.0;
    b 3;
    c #calc "$a*$b";
    \endverbatim

    Note the explicit trailing 0 ('1.0') to force a to be read (and written)
    as a floating point number.

    Special care is required for calc entries that include a division since
    "/" is also used as the scoping operator to identify keywords in
    sub-dictionaries. For example, "$a/b" expects a keyword "b" within a
    sub-dictionary named "a". A division can be correctly executed by using a
    space between a variables and "/", e.g.

    \verbatim
    c #calc "$a / $b";
    \endverbatim

    or "()" scoping around the variable, e.g.

    \verbatim
    c #calc "($a)/$b";
    \endverbatim

    Additional include files for the #calc code compilation can be specified
    using the #calcInclude entry, e.g. if functions from transform.H are used
    \verbatim
    angleOfAttack   5; // degs

    angle           #calc "-degToRad($angleOfAttack)";

    #calcInclude    "transform.H"
    liftDir         #calc "transform(Ry($angle), vector(0, 0, 1))";
    dragDir         #calc "transform(Ry($angle), vector(1, 0, 0))";
    \endverbatim

    Note:
        Internally this is just a wrapper around codeStream functionality - the
        #calc string is used to construct a dictionary for codeStream.
2023-06-24 16:56:59 +01:00
0657826ab9 Replaced all remaining addTimeOptions.H includes with the more flexible timeSelector 2023-06-23 15:24:06 +01:00
e019049bef primitiveMesh,polyMesh: Further refactoring of mesh checking 2023-06-23 13:44:35 +01:00
6f38550879 Function1s::Table: slight improvement to integration with outOfBounds repeat 2023-06-22 15:28:27 +01:00
3d95d179ea Function1s::Table: Corrected integration with outOfBounds repeat
Resolves bug-report https://bugs.openfoam.org/view.php?id=3990
2023-06-22 15:05:20 +01:00
aad7408f5f distributions::unintegrable: Formatting 2023-06-22 14:55:27 +01:00
b2d4f25fff codeStream: Typed substitutions
Dictionary entries constructed with #calc and #codeStream can now
conveniently access and use typed variables. This means calculations
involving vectors and tensors and list and field types are now possible.

To access a variable and construct it as a given type within a #calc
or #codeStream entry, put the type immediately after the $ symbol inside
angled brackets <>. So, $<vector>var or $<vector>{var} substitutes a
variable named var as a vector.

Examples:

- Reflect a point in a plane defined by a normal

    p       (1 2 3);
    n       (1 1 0);
    pStar   #calc "$<vector>p - (2*sqr($<vector>n)/magSqr($<vector>n)&$<vector>p)";

- Rotate a list of points around an axis by a given angle

    points  ((3 0 0) (2 1 1) (1 2 2) (0 3 3));
    rotation
    {
        axis    (0 1 1);
        angle   45;
    }

    #codeStream
    {
        codeInclude
        #{
            #include "pointField.H"
            #include "transform.H"
        #};

        code
        #{
            const pointField points($<List<point>>points);
            const vector axis = $<vector>!rotation/axis;
            const scalar angle = degToRad($!rotation/angle);
            os << "pointsRotated" << nl << (Ra(axis, angle) & points)() << ";";
        #};
    };

- Compute the centre and trianglation of a polygon

   polygon  ((0 0 0) (1 0 0) (2 1 0) (0 2 0) (-1 1 0));

   #codeStream
   {
       codeInclude
       #{
           #include "polygonTriangulate.H"
       #};

       code
       #{
           const List<point> polygon($<List<point>>polygon);
           writeEntry(os, "polygonCentre", face::centre(polygon));

           polygonTriangulate triEngine;
           triEngine.triangulate(polygon);
           os << "polygonTris" << ' ' << triEngine.triPoints() << ";";
       #};
    };

- Generate a single block blockMeshDict for use with snappyHexMesh with no redundant information

    min         (-2.5 -1.2 -3.0);   // Minimum coordinates of the block
    max         (2.5 1.2 3.0);      // Maximum coordinates of the block
    nCellsByL   33.3333;            // Number of cells per unit length

    // Calculate the number of cells in each block direction
    nCells      #calc "Vector<label>($nCellsByL*($<vector>max - $<vector>min) + vector::one/2)";

    // Generate the vertices using a boundBox
    vertices    #codeStream
    {
        codeInclude
        #{
            #include "boundBox.H"
        #};

        code
        #{
            os << boundBox($<vector>min, $<vector>max).points();
        #};
    };

    blocks
    (
        hex (0 1 2 3 4 5 6 7) $nCells simpleGrading (1 1 1)
    );

    defaultPatch
    {
        type patch;
    }

    boundary
    ();
2023-06-22 12:53:21 +01:00
0927fd47fa stringOps: Rationalisation of expansions
Specific names have been given for expand functions. Unused functions
have been removed, and functions only used locally have been removed
from the namespace. Documentation has been corrected. Default and
alternative value handling has been removed from code template
expansion.
2023-06-22 11:46:23 +01:00
d028a9a4d3 bool: Add name function and read and write as "true" and "false" 2023-06-22 11:46:14 +01:00
c40f918c0d primitiveMesh,polyMesh: Initial refactoring of mesh checking 2023-06-21 19:10:39 +01:00
9de6683244 pTraits::read: Moved the read<Type>(Istream&) from read.H to pTraits.H
so that primitives can be read from Istream without the need to include
IStringStream.H
2023-06-21 12:44:55 +01:00
3ef7a23b32 pTraits::read: Added global templated read functions for pTraits
This allows primitive and other types either directly or indirectly
constructable from Istream to be constructed from a string using pTraits and
IStringStream, e.g.

    const vector v(read<vector>("(1 2 3)"));
2023-06-21 12:22:43 +01:00
0ba5ebb0cd UIndirectList: Use UList<label> rather than the labelUList typedef
to avoid dependency on another file.
2023-06-21 12:21:16 +01:00
c9bb53e109 ISstream: Corrected parsing of variables 2023-06-20 19:14:47 +01:00
de2b4457d6 distribtion: Prevent hidden overload warning with Clang 2023-06-20 09:28:31 +01:00
d1cb137266 dictionary: Convenient programmatic construction
Variadic constructors have been added to dictionary to facilitate
convenient construction in code, including within a #codeStream entry.
The constructors take an even number of arguments, alternating between
the key and the corresponding value. The values may, themselves, be
dictionaries constructed in the same way. This means that the code
directly maps to the resulting nested dictionary structure.

For example, the following code stream entry:

    #codeStream
    {
        code
        #{
            writeEntry
            (
                os,
                "dict",
                dictionary
                (
                    "s", 1,
                    "wl", wordList({"apples", "oranges"}),
                    "subDict", dictionary
                    (
                        "v", vector(2, 3, 4),
                        "t", tensor(5, 6, 7, 8, 9, 10, 11, 12, 13),
                        "ll", labelList(10, -1)
                    )
                )
            );
        #};
    }

Expands to the following:

    dict
    {
        s               1;
        wl              2 ( apples oranges );
        subDict
        {
            v               ( 2 3 4 );
            t               ( 5 6 7 8 9 10 11 12 13 );
            ll              10 { -1 };
        }
    }
2023-06-20 09:28:26 +01:00
04dd989911 Time: Removed graphFormat
setFormat no longer defaults to the value of graphFormat optionally set in
controlDict and must be set in the functionObject dictionary.

boundaryFoam, financialFoam and pdfPlot still require a graphFormat entry in
controlDict but this is now read directly rather than by Time.
2023-06-16 14:51:30 +01:00
29fb55b24b fvMesh: Stabilise magSf with rootVSmall rather than vSmall
for running cases NCC in extended precision
2023-06-16 13:22:25 +01:00
f8074234c0 Updates for extended precision operation 2023-06-16 10:01:52 +01:00
cafe173bf7 Function1,Function2: Updated run-time selection table construction to add to foamToC
With this change foamToC now includes Function1 and Function2 entries, thus

    foamToC -table Function1

prints

    Tables of type Function1
        avTypeFunction1
        labelFunction1
        scalarFunction1
        sphericalTensorFunction1
        symmTensorFunction1
        tensorFunction1
        trvTypeFunction1
        vectorFunction1

and

    foamToC -table scalarFunction1

prints

    Contents of table scalarFunction1, base type Function1:
        NSRDS0                                  libspecie.so
        NSRDS1                                  libspecie.so
        NSRDS14                                 libspecie.so
        NSRDS2                                  libspecie.so
        NSRDS3                                  libspecie.so
        NSRDS4                                  libspecie.so
        NSRDS5                                  libspecie.so
        NSRDS6                                  libspecie.so
        NSRDS7                                  libspecie.so
        coded                                   libOpenFOAM.so
        constant                                libOpenFOAM.so
        exponentialSqrRamp                      libOpenFOAM.so
        halfCosineRamp                          libOpenFOAM.so
        integratedNonUniformTable               libspecie.so
        laminarBL                               libfiniteVolume.so
        linearRamp                              libOpenFOAM.so
        nonUniformTable                         libOpenFOAM.so
        none                                    libOpenFOAM.so
        one                                     libOpenFOAM.so
        polynomial                              libOpenFOAM.so
        quadraticRamp                           libOpenFOAM.so
        quarterCosineRamp                       libOpenFOAM.so
        quarterSineRamp                         libOpenFOAM.so
        reverseRamp                             libOpenFOAM.so
        scale                                   libOpenFOAM.so
        sine                                    libOpenFOAM.so
        square                                  libOpenFOAM.so
        squarePulse                             libOpenFOAM.so
        table                                   libOpenFOAM.so
        tableFile                               libOpenFOAM.so
        turbulentBL                             libfiniteVolume.so
        uniform                                 libOpenFOAM.so
        uniformTable                            libOpenFOAM.so
        zero                                    libOpenFOAM.so
2023-06-15 20:59:10 +01:00
09a2da22b2 functionObject::timeControl: Added runTimes option to execute/write at specified list of run times
With
    executeControl  runTimes;
    executeTimes    (0.1 0.2 0.3);

the functionObject will be executed at 0.1s, 0.2s and 0.3s only.

With
    writeControl    runTimes;
    writeTimes      (0.1 0.2 0.3);

the functionObject will write at 0.1s, 0.2s and 0.3s only.
2023-06-14 17:31:52 +01:00
0fa46ef28a controlDict: Added optional 'beginTime' entry
for cases started or restarted from some arbitrary time without a corresponding
<time>/uniform/time dictionary to set the beginTime to the logical start of the
simulation.  Setting beginTime to 0 for example ensures that write times,
functionObject evaluations and writes etc. occur at intervals starting from 0
rather than the arbitrary startTime.
2023-06-13 15:54:57 +01:00
aa89c7806e timeControl: Moved timeToNextWrite functionality from timeControlFunctionObject
to simplify the interface and make it more extensible
2023-06-13 15:54:09 +01:00
618d9d33b2 controlDict: the optional graphFormat entry is now used as the default for all setFormat entries
Foam::graph superseded by the more general Foam::setWriter reducing code
maintenance overhead, simplifying usage and further development.
2023-06-12 17:14:37 +01:00
08544446e8 Time, functionObjectList: Refactored to simplify construction and switching-off functionObjects 2023-06-06 08:17:52 +01:00
0b8c17d8c1 functionObject,fvModel,fvConstraint: Added automatic library loading
If the libs entry is not provided and the name of the library containing the
functionObject, fvModel or fvConstraint corresponds to the type specified the
corresponding library is automatically loaded, e.g. to apply the
VoFTurbulenceDamping fvModel to an incompressibleVoF simulation the following
will load the libVoFTurbulenceDamping.so library automatically and instantiate
the fvModel:

turbulenceDamping
{
    type            VoFTurbulenceDamping;

    delta           1e-4;
}
2023-06-01 20:31:16 +01:00
2561212f56 string: Added remove(const char) member functions
which remove all occurrences of the specified character
2023-06-01 11:50:58 +01:00
32e26b819b fvsPatchField::New: Improved the error messages to match the updated fvPatchField::New 2023-05-29 11:31:05 +01:00