For writing unit and/or integration tests in OpenFOAM it is useful to avoid
IO calls as much as possible to be independent of the state of the case files.
Creating a mesh and object registry without IO is however not possible by
default in OpenFOAM. This repository provides a library with which a
cubed, structured mesh with
Source your OpenFOAM environment and execute wmake
in the src
folder
#include "unitMesh.H"
int main()
{
// start of your case
...
// create the object uMesh with 10^3 cells
// Optional: provide a path to where objects are written if write()
// is called. (Defaults to: rootPath='./')
fileName rootPath = "PATH_TO_MY_TESTS";
// Optional case name. By default empty
word caseName;
unitMesh uMesh(10,rootPath,caseName);
// Get the mesh
const fvMesh& mesh = uMesh.mesh();
// Create a volScalarField on that mesh
volScalarField testField
(
IOobject
(
"test",
uMesh.runTime().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("test",dimless,1E+5)
);
}