How to open a file for writing, dump data into it, and close it.
You can also use the STL::fstream class. This makes it easy to manipulate output using ios:app
for appending and setw
and setfill
for padding the output with other characters (often zeros).
OpenFOAM file output
// Open the error file for measurement output..
OFstream errorFile(dataFileName);
// Nt : number of cells in the tool mesh
// Nb : number of cells in the tool mesh
// Ev : volume conservation error:
// |tool mesh volume from volume fraction - tool mesh volume | / tool mesh volume.
// Ti : initialization time, loading the mesh and fields,
// Te : execution time of the CCI mesh intersection operation.
// Nx : total number of cells that are intersected: larger than the
// number of interface cells, as bulk cells are intersected as well.
// Ni : number of interface cells,
// Nk : number of bulk cells.
errorFile << "Nt,Nb,Ev,Ti,Te,Nx,Ni,Nk\n";
...
errorFile << toolMesh.nCells() << ","
<< baseMesh.nCells() << ","
<< Ev << ","
<< Ti << ","
<< Te << ","
<< meshIntersection.Nx() << ","
<< Ni << "," << Nb << nl;
OpenFOAM uses a global object for the newline character: ’nl’, it’s easier to write and corresponds to the OF formatting syntax.