Skip to content

Common interface for grid-readers

When comparing the various file-readers for different grids, e.g. albertareader, gmshreader, starcdreader, amirameshreader, ..., I've noticed that every reader has a different api, different methods to call, with different signatures. Sometimes this makes sense (e.g. if a reader provides additional data to be extracted from the grid), sometimes it is just irritating and not necessary, e.g.

void AlbertaReader::readGrid(const std::string& fileName, Dune::GridFactory<Grid>& factory);

static Grid* StartCDReader::read(const std::string& fileName, bool=true);

static Grid* GmshReader::read(const std::string& fileName, bool=true, bool=true);
static void GmshReader::read(Dune::GridFactory<Grid>& factory, const std::string& fileName, bool=true, bool=true);

static Grid* AmiraMeshReader::read(const std::string& filename);
static void AmiraMeshReader::read(Grid& grid, const std::string& filename);

AlbertaReader has a non-static method and expects a filename and a factory, whereas all other mentioned readers provide static methods and work with a filename alone (creating a factory internally). GmshReader provides a read method, that takes a factory, but compared to AlbertaReader the arguments are exchanged. In AmiraMeshReader instead of a factory, the grid itself must be passed to the method. And finally in AlbertaReader the method has a different name than all the other readers.

I propose to define a common interface that all readers should implement, but is allowed to be extended:

static Grid* Reader::read(const std::string& fileName, bool verbose = true);
static void Reader::read(Dune::GridFactory<Grid>& factory, const std::string& fileName, bool verbose = true);

Maybe the verbose parameter can be removed in the common interface.

All the readers above can easily be modified to conform with this common interface.