Commit Graph

7581 Commits

Author SHA1 Message Date
476bb42b04 unitConversion: Unit conversions on all input parameters
The majority of input parameters now support automatic unit conversion.
Units are specified within square brackets, either before or after the
value. Primitive parameters (e.g., scalars, vectors, tensors, ...),
dimensioned types, fields, Function1-s and Function2-s all support unit
conversion in this way.

Unit conversion occurs on input only. OpenFOAM writes out all fields and
parameters in standard units. It is recommended to use '.orig' files in
the 0 directory to preserve user-readable input if those files are being
modified by pre-processing applications (e.g., setFields).

For example, to specify a volumetric flow rate inlet boundary in litres
per second [l/s], rather than metres-cubed per second [m^3/s], in 0/U:

    boundaryField
    {
        inlet
        {
            type            flowRateInletVelocity;
            volumetricFlowRate 0.1 [l/s];
            value           $internalField;
        }

        ...
    }

Or, to specify the pressure field in bar, in 0/p:

    internalField   uniform 1 [bar];

Or, to convert the parameters of an Arrhenius reaction rate from a
cm-mol-kcal unit system, in constant/chemistryProperties:

    reactions
    {
        methaneReaction
        {
            type    irreversibleArrhenius;
            reaction "CH4^0.2 + 2O2^1.3 = CO2 + 2H2O";
            A       6.7e12 [(mol/cm^3)^-0.5/s];
            beta    0;
            Ea      48.4 [kcal/mol];
        }
    }

Or, to define a time-varying outlet pressure using a CSV file in which
the pressure column is in mega-pascals [MPa], in 0/p:

    boundaryField
    {
        outlet
        {
            type            uniformFixedValue;
            value
            {
                type            table;
                format          csv;
                nHeaderLine     1;
                units           ([s] [MPa]); // <-- new units entry
                columns         (0 1);
                mergeSeparators no;
                file            "data/pressure.csv";
                outOfBounds     clamp;
                interpolationScheme linear;
            }
        }

        ...
    }

(Note also that a new 'columns' entry replaces the old 'refColumn' and
'componentColumns'. This is is considered to be more intuitive, and has
a consistent syntax with the new 'units' entry. 'columns' and
'componentColumns' have been retained for backwards compatibility and
will continue to work for the time being.)

Unit definitions can be added in the global or case controlDict files.
See UnitConversions in $WM_PROJECT_DIR/etc/controlDict for examples.
Currently available units include:

    Standard: kg m s K kmol A Cd

     Derived: Hz N Pa J W g um mm cm km l ml us ms min hr mol
              rpm bar atm kPa MPa cal kcal cSt cP % rad rot deg

A user-time unit is also provided if user-time is in operation. This
allows it to be specified locally whether a parameter relates to
real-time or to user-time. For example, to define a mass source that
ramps up from a given engine-time (in crank-angle-degrees [CAD]) over a
duration in real-time, in constant/fvModels:

    massSource1
    {
        type        massSource;
        points      ((1 2 3));
        massFlowRate
        {
            type        scale;
            scale       linearRamp;
            start       20 [CAD];
            duration    50 [ms];
            value       0.1 [g/s];
        }
    }

Specified units will be checked against the parameter's dimensions where
possible, and an error generated if they are not consistent. For the
dimensions to be available for this check, the code requires
modification, and work propagating this change across OpenFOAM is
ongoing. Unit conversions are still possible without these changes, but
the validity of such conversions will not be checked.

Units are no longer permitted in 'dimensions' entries in field files.
These 'dimensions' entries can now, instead, take the names of
dimensions. The names of the available dimensions are:

    Standard: mass length time temperature
              moles current luminousIntensity

     Derived: area volume rate velocity momentum acceleration density
              force energy power pressure kinematicPressure
              compressibility gasConstant specificHeatCapacity
              kinematicViscosity dynamicViscosity thermalConductivity
              volumetricFlux massFlux

So, for example, a 0/epsilon file might specify the dimensions as
follows:

    dimensions      [energy/mass/time];

And a 0/alphat file might have:

    dimensions      [thermalConductivity/specificHeatCapacity];

*** Development Notes ***

A unit conversion can construct trivially from a dimension set,
resulting in a "standard" unit with a conversion factor of one. This
means the functions which perform unit conversion on read can be
provided dimension sets or unit conversion objects interchangeably.

A basic `dict.lookup<vector>("Umean")` call will do unit conversion, but
it does not know the parameter's dimensions, so it cannot check the
validity of the supplied units. A corresponding lookup function has been
added in which the dimensions or units can be provided; in this case the
corresponding call would be `dict.lookup<vector>("Umean", dimVelocity)`.
This function enables additional checking and should be used wherever
possible.

Function1-s and Function2-s have had their constructors and selectors
changed so that dimensions/units must be specified by calling code. In
the case of Function1, two unit arguments must be given; one for the
x-axis and one for the value-axis. For Function2-s, three must be
provided.

In some cases, it is desirable (or at least established practice), that
a given non-standard unit be used in the absence of specific
user-defined units. Commonly this includes reading angles in degrees
(rather than radians) and reading times in user-time (rather than
real-time). The primitive lookup functions and Function1 and Function2
selectors both support specifying a non-standard default unit. For
example, `theta_ = dict.lookup<scalar>("theta", unitDegrees)` will read
an angle in degrees by default. If this is done within a model which
also supports writing then the write call must be modified accordingly
so that the data is also written out in degrees. Overloads of writeEntry
have been created for this purpose. In this case, the angle theta should
be written out with `writeEntry(os, "theta", unitDegrees, theta_)`.
Function1-s and Function2-s behave similarly, but with greater numbers
of dimensions/units arguments as before.

The non-standard user-time unit can be accessed by a `userUnits()`
method that has been added to Time. Use of this user-time unit in the
construction of Function1-s should prevent the need for explicit
user-time conversion in boundary conditions and sub-models and similar.

Some models might contain non-typed stream-based lookups of the form
`dict.lookup("p0") >> p0_` (e.g., in a re-read method), or
`Umean_(dict.lookup("Umean"))` (e.g., in an initialiser list). These
calls cannot facilitate unit conversion and are therefore discouraged.
They should be replaced with
`p0_ = dict.lookup<scalar>("p0", dimPressure)` and
`Umean_(dict.lookup<vector>("Umean", dimVelocity))` and similar whenever
they are found.
2024-05-16 09:01:46 +01:00
d21e75ac74 fvMesh::distributing: New member function to check if the mesh will redistribute 2024-05-13 12:02:36 +01:00
408e332ac8 ParticleForceList: Added missing initialisation calls in copy constructor 2024-05-13 12:01:39 +01:00
23946e8347 incompressibleDenseParticleFluid: call storeGlobalPositions for redistribution 2024-05-13 12:00:53 +01:00
17b667c3f3 MPPIC: PackingModels::Implicit: Improved time handling
The alpha equation in this model has been changed to a d2dt2 scheme,
rather than a hard-coded correction on a ddt scheme that relies on the
old-time value remaining unchanged from the previous timestep. This
modification makes the model compatible with some forms of mesh change.
2024-05-10 14:04:03 +01:00
2c2e6aafec edgeMeshFormats, surfaceFormats: Removed unused code 2024-05-10 08:42:49 +01:00
47fa9bc620 snappyHexMesh: Corrected use of layer featureAngle
The 'featureAngle' control defines the included angle between faces
above which layer extrusion is prevented. Its use within snappyHexMesh
was incorrect in that the cosine was not being taken before being
compared to dot products of face normals. This has now been corrected.

Existing 'featureAngle' settings may need changing to recover equivalent
behaviour. Any angle previously set to 58 degrees or above previously
resulted in no reduction of layer coverage. A large angle between 90 and
180 degrees is likely to be an appropriate replacement for cases such as
this. Angles previously set to 57 degrees and below can be equivalently
replaced by a value of (180/pi)*arccos(<angle>*(pi/180)).

Note that changing the feature angle also affects the slip feature
angle. The slip feature angle is taken to be half the feature angle if a
'slipFeatureAngle' is not specified.
2024-05-09 14:15:38 +01:00
cdef200385 MRF: Make flux relative following correctPhi
This fixes an incompatibility between MRF and adaptive mesh refinement
2024-05-07 14:45:21 +01:00
fb4d7abf42 dictionary::lookupCompoundScoped: New member function to return a reference to a compound token type
lookupCompoundScoped is used by dictionary via stringOps to provide fast access
to compound tokens without the need to construct the container for every access,
e.g.

listU           List<vector> ((1.1 2.1 1.1) (2.1 3.2 4.1) (4.3 5.3 0));
magU1           #calc "mag($listU[1])";
magU2           #calc "mag($listU[2])";

where the listU is declared as a List<vector> compound token which is then
accessed directly by $listU without the need to specify the type and the data is
accessed directly by reference which is more efficient, particularly if the list
is large.
20240506
2024-05-05 17:42:20 +01:00
ff7fce900c token: Generalised the handling of the type name of the primitive token types
The new token::typeName() function is used in stringOps to provide dictionary
with better support for automatic type inference for variables in #calc
expressions.
2024-05-04 14:11:01 +01:00
97b4a26a4c triIntersect: Fixes to rejection of invalid intersection topologies
This change corrects some of the logic governing whether a geometry is
determined to result in a valid intersection or not. It has fixed some
issues with regards to intersections being erroneously duplicated or
omitted and has thereby increased the proportion of intersections that
result in unity or near-unity coverage.
2024-05-03 08:51:57 +01:00
bf5a843c82 CloudFunctionObject: Prevent overwrite of existing results on foamPostProcess
Cloud functions are now not created at all during foamPostProcess. These
functions mostly usually compute state during tracking, so they cannot
produce anything useful when run as a post-process. In addition, in a
few cases, their initialisation can overwrites valid post-processing
files created at run-time.

A more "complete" system might distinguish between the few cloud
functions that can be evaluated instantaneously (e.g., sizeDistribution,
relativeVelocity, ...) and those those that cannot (e.g., fluxes,
patchCollisionDensity, ...) and only construct and execute the former
within foamPostProcess. This could be achieved with appropriate
support/funding.

In addition, volFieldValue and surfaceFieldValue have been modified so
that they do not write anything if no fields are available. This also
prevents the overwriting of valid run-time results in some cases.
2024-05-01 11:28:50 +01:00
0b130b5620 engineTime, rotorDisk: Optional angular velocity specification
Angular velocity can be specified either as 'rpm' or 'omega',
consistently with other parts of OpenFOAM.
2024-04-29 22:02:23 +01:00
c3f131e816 Function1s::Polynomial: Simplification
The coefficients in the polynomial are now specified in order of
increasing exponent, starting from the constant coefficient (i.e., zero
exponent). Exponents are no longer specified. This better fits the
definition of a polynomial, and it prevents the strange scenario when if
exponents are given as a vector or tensor or similar then the units of
the coefficients are not the same across the different components.

For example, polynomial y = -1 + x^2 + 2x^3 can be specified as:

    <name>  polynomial (-1 0 1 2);

Or, alternatively:

    <name>
    {
        type    polynomial;
        coeffs  (-1 0 1 2);
    }
2024-04-29 22:02:22 +01:00
f28110ae94 UniformDimensionedField: Added support for oldTime 2024-04-29 21:17:59 +01:00
3aba7ea46f dimensionSets: Added dimRate = dimless/dimTime 2024-04-29 21:17:34 +01:00
0081c6a3e2 swirlInletVelocity, swirlFlowRateInletVelocity: Consistent specification
Both these boundary conditions now support specification of the radial
and tangential components as a function of time and radius, or
alternatively the tangential component as a time-varying rotational
speed.

The cylindricalInletVelocity condition has been superseeded by
swirlInletVelocity and has therefore been removed.
2024-04-26 15:15:34 +01:00
187b795713 Function2s: Added 'function1', 'product' and 'radial'
The 'function1' function returns the result of a Function1 using just
one of the arguments given to the function2. The function1 is specified
as value1 or value2, depending on which argument it is to be evaluated
with. E.g.:

    <name>
    {
        type            function1;
        value2          table
        (
            (0.00 (0 0 0))
            (0.35 (0 0 1))
            (0.71 (0 0 0))
        );
    }

The 'product' function returns the product of two independent
Function1-s of the two input arguments, again specified as value1 and
value2. For example, to scale a table of vectors in the first argument
with a ramp in the second argument:

    <name>
    {
        type            product;
        value1<vector>  table
        (
            (0.00 (0 0 0))
            (0.25 (1 0 0))
            (0.50 (0 0 0))
        );
        value2<scalar>
        {
            type        linearRamp;
            start       1;
            duration    4;
        }
    }

Note that only one type specification (the <vector>/<scalar>/... part)
is needed in general for the value entries, and no type specifications
are needed if the function is scalar.

The 'radial' function returns a Function1 of the magnitude of the
two-dimensional vector with components equal to the input arguments.
E.g.:

    <name>
    {
        type            radial;
        value           table
        (
            (0.00 (0 0 0))
            (0.35 (0 0 1))
            (0.71 (0 0 0))
        );
    }
2024-04-26 15:15:34 +01:00
42456c3ce9 timeVaryingMappedFvPatchField: Standardise constructors 2024-04-26 11:29:13 +01:00
73feebd5f4 logFile: New prototype log file class for functionObjects etc.
to write integral data into a table in the postProcessing directory.
2024-04-25 15:32:21 +01:00
d5285f23e5 snappyHexMesh: Rationalised #includes 2024-04-24 15:28:07 +01:00
2f4081dc15 timeControlFunctionObject: Removed unused optional control 2024-04-24 15:27:29 +01:00
7fbd730f2a PatchInjection: Fixed number of injected parcels for small timesteps
Resolves bug report https://bugs.openfoam.org/view.php?id=4071
2024-04-23 08:40:41 +01:00
5b389288e7 dimensionedType: Removed unused read method 2024-04-23 08:40:38 +01:00
f789a4f530 shapeToCell: Changed keyword type -> shape
to avoid clash with the set type, e.g. in topoSetDict

actions
(
    {
        action  new;
        type    cellZoneSet;
        name    c0;
        source  shapeToCell;
        shape   hex;
    }
);

the entry "shape hex" selects the hex cell shape.
2024-04-22 13:52:52 +01:00
6a3c7ab502 dimensionedType: Reinstated backwards-compatibility reading the name of named dimensionedTypes 2024-04-22 13:38:53 +01:00
28e5556864 refinementRegions: Updated triSurfacePointScalarField constructor call 2024-04-22 11:53:28 +01:00
59f30e8de1 Merge branch 'master' of github.com:OpenFOAM/OpenFOAM-dev 2024-04-19 20:54:32 +01:00
f9ac53aab4 bin/foamFind: added '-edit' option to open file in a text editor
The editor must be specified by configuring the EDITOR environment
variable. For example to use the 'gedit' editor, the following entry
could be added to the user's .bashrc file:

export EDITOR=gedit
2024-04-19 20:53:00 +01:00
dce39ffbd2 Merge branch 'master' of github.com-OpenFOAM:OpenFOAM/OpenFOAM-dev 2024-04-19 18:22:12 +01:00
3dc7e13b27 polyBoundaryMesh: Removed unnecessary patch face ordering check 2024-04-19 18:21:37 +01:00
29360be8cd Function1s, Function2s: Remove unnecessary read methods and improve const-ness 2024-04-19 14:22:57 +01:00
2e9e37d67c bin/foamFind: fixed typo in header 2024-04-19 09:17:06 +01:00
92c83f5c1c test/dictionary/testCalc: Added a file name construction example 2024-04-18 18:05:49 +01:00
57cb8b2c59 foamSearch: Updated call to foamDictionary for absolute paths 2024-04-18 15:24:24 +01:00
3ce8a35029 tutorials: Use seven element dimension sets as standard 2024-04-18 13:48:59 +01:00
26f9c794b4 dimensionedType: Permit reading dimensions after the value in all contexts 2024-04-18 13:37:10 +01:00
c2ec1037d9 createEngineZones: Disabled parallel operation which requires further development 2024-04-18 09:07:45 +01:00
8bd14164ad utilities removeFaces and createEngineZones: Replaced Pout with Info 2024-04-18 08:27:49 +01:00
3bd79f0447 bash_completion: Added reorderPatches 2024-04-17 17:38:33 +01:00
161710acd1 Merge branch 'master' of github.com-OpenFOAM:OpenFOAM/OpenFOAM-dev 2024-04-17 17:38:26 +01:00
6e754fd650 extrudeToRegionMesh: moved setting the mesh instance to after the deletion of empty patches 2024-04-17 17:37:42 +01:00
b85aebb250 dimensionSet: Remove #include dependence on Field 2024-04-17 16:22:38 +01:00
347cf0e9e2 GeometricVectorField: Added normalised and perpendicular unary functions 2024-04-17 16:22:38 +01:00
4707bc917e reorderPatches: New utility to reorder patches
corresponding to a give order, another case or another region.

Description
    Utility to reorder the patches of a case

    The new patch order may be specified directly as a list of patch names
    following the -patchOrder option or from the boundary file of a reference
    case specified using the -referenceCase option with or without the
    -referenceRegion option.

    This utility run either serial or parallel but either way the reference
    case boundary file is read from the constant directory.

Usage
    \b reorderPatches

    Options:
      - \par -patchOrder \<patch names\>
        Specify the list of patch names in the new order.

      - \par -referenceCase \<case path\>
        Specify the reference case path

      - \par -referenceRegion \<name\>
        Specify an alternative mesh region for the reference case.
        If -referenceCase is not specified the current case is used.

      - \par -overwrite \n
        Replace the old mesh with the new one, rather than writing the new one
        into a separate time directory

      - \par -region \<name\>
        Specify an alternative mesh region.
2024-04-17 16:15:10 +01:00
441d7f1243 snappyHexMesh::meshRefinement: Correct mesh instance for overwrite
Must be done just before write to correct the instance in case it has changed
due to call to reorderPatches to remove zero-sized patches.
2024-04-17 15:16:12 +01:00
86a9c41c21 tutorials: Removed redundant fluxRequired entries 2024-04-17 15:15:38 +01:00
261d2aac60 randomGenerator: Added functions to return fields of samples 2024-04-17 09:39:40 +01:00
f582eff8a7 patchIntersection, nonConformalMappedPolyFacesFvsPatchLabelField: Fixes for 64-bit labels 2024-04-16 16:14:56 +01:00
08870e4560 PhysicalPropertiesThermo, mirrorMesh, renumberMesh: Clang compilation fixes 2024-04-16 16:14:56 +01:00