OpenFOAM® v1812: Core developments

OpenFOAM® v1812: Core developments

20/12/2018

New and improved low-level containers

OpenFOAM-v1812 introduces a number of moderate changes in the core containers. Many of these changes are only of interest to developers, but even the casual programmer may find the adjustments for hashing of lists useful.

Hashing of lists

A Hash<> function has been added to List and FixedList. This means that it is now possible to use lists of elements as a hash key in a HashTable or a HashSet. A practical example of where this might be useful is when a HashSet of faces is required. This is now directly possible:

HashSet<face> facesUsed;
facesUsed.insert(someFace);
...

For other types of ”hashing”, it is now also possible to use a FixedList of labels, e.g. a triFace to set or unset values of a bitSet.

Normalisation

When dealing with vector, such as face normals, the treatment of zero-length vectors becomes a concern when coding. This is now addressed by the normalise() method for all vector-space types, and by a equivalent global normalised() function. These provide a consistent treatment for avoiding divide-by-zero. The method call modifies the item inplace, whereas the global function returns a copy.

In previous code, this type construct was often seen:

vector vec1(...);
vec1 /= mag(vec1) + VSMALL;

The more modern approach would use the normalise() method instead:

vector vec1(...);
vec1.normalise();

This change makes it easier to use consistently, and can be used to create constant variables. For example,

const vector vec2a( vector(...).normalise() );
const vector vec2b(  normalised(vector(...)) );

In a related topic, faces now use either a unitNormal() or an areaNormal() method depending on whether the face normal is required to be normalised or if its area magnitude should be included.

In previous versions, the method name normal() was used, from which it was not immediately clear if this meant the area normal or the unit normal (it was the areaNormal) by simply reading the code.

PtrList

When accessing entries in a PtrList, the get() method can be used to return the pointer address instead of the reference.

PackedList and bitSet

When transferring packed content between processors, it is now possible to specify a smaller data size to be used for the communicated data instead of the default unsigned int. This functionality is provided by the unpack() method. For example,

processorPolyPatch pp = ...;
UOPstream toNbr(pp.neighbProcNo(), pBufs);
toNbr << faceValues.unpack<uint8_t>(pp.range());
This saves some bandwidth and does not need the same data alignment.

globalIndex

The globalIndex index is used when coordinating sizing for parallel simulations. It now has additional methods, e.g., empty, reset, localSize that improve its flexibility.

Mesh-related addressing and querying

The whichPatch() method now uses a binary search for faster lookups.

Finding matching names or indices is now easier with a wordRes matcher for coordinateSystems, polyBoundaryMesh, faBoundaryMesh, fvBoundaryMesh, and ZoneMesh.

Improved efficiency in handling of patch group matching.

fvMeshSubset and fvMeshSubsetProxy

The fvMeshSubset class and fvMeshSubsetProxy classes were adjusted to reduce their memory overhead and improve their performance.

The fvMeshSubset now uses a bitSet for a memory-efficient interface and for internal accounting. A subset can now be created immediately on construction, which simplifies coding. For example,

return autoPtr<fvMeshSubset>::New(mesh, selectedCells);

Anyone who is currently using an fvMeshSubset in their code is encouraged to read the class documentation to find an improved interface that best suits their purposes.

New PatchFunction1 class

The new PatchFunction1 is an extension of the Function1 class, and provides a straightforward mechanism to assign time and spatially varying field values. It is this class which gives the uniformFixedValue boundary condition its new functionality. The current types comprise all of the Function1 types:

  • constant
  • csvFile
  • one
  • polynomial
  • scale
  • sine
  • square
  • table
  • tableFile
  • uniformValue
  • zero

and two new types:

  • mappedFile
  • item sampled

The mappedFile type implements all of the functionality of the timeVaryingMappedFixedValue boundary condition so allows interpolation of files read from the constant/boundaryData directory. The sampled type implements the functionality from the mapped boundary condition so re-cycles values from the simulation itself.

Anywhere where currently a Function1 would be applicable and there is access to a polyPatch one could use a PatchFunction1 instead and get all the new types and the local coordinate system functionality. The only additional change (compared to Function1) generally required is to feed through the autoMap, rmap calls. See e.g. the uniformFixedValue boundary condition.

Source code
$FOAM_SRC/meshTools/PatchFunction1
$FOAM_SRC/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue