GridFormat

GridFormat: header-only C++-library for grid file I/O - Published in JOSS (2023)

https://github.com/dglaeser/gridformat

Science Score: 100.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 7 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
    1 of 2 committers (50.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

computational-grid input-output numerical-modeling simulation
Last synced: 4 months ago · JSON representation ·

Repository

Header-only C++-Library for grid file I/O

Basic Info
Statistics
  • Stars: 20
  • Watchers: 2
  • Forks: 2
  • Open Issues: 28
  • Releases: 6
Topics
computational-grid input-output numerical-modeling simulation
Created about 3 years ago · Last pushed 9 months ago
Metadata Files
Readme Changelog License Citation

README.md

C++ Standard Pages Test suite Coverage Report API Documentation REUSE status JOSS DOI

GridFormat is a header-only C++ library for reading/writing data from/to standardized grid file formats that are supported by visualization tools such as e.g. ParaView. Thus, applications that operate on grid-like data structures such as numerical simulations, GIS or computational geometry applications, can leverage GridFormat to import/export their data from/into interoperable file formats. The typical use case for GridFormat is within codes for numerical simulations, for visualization of results or for importing them for further processing. A variety of simulation frameworks exist, such as Dune, DuMuX, Deal.II, Fenics or MFEM, which usually provide mechanisms to export/import data produced with the framework into some file formats. However, there are situations in which one wants to use a format that the framework does not support, or, use some features of the format specification that are not implemented in the framework. GridFormat aims to provide access to a variety of file formats through a unified interface and without the need to convert any data or to use a specific data structure to represent computational grids. Using generic programming and traits classes, GridFormat fully operates on the user-given data structures, thereby minimizing the runtime overhead. GridFormat also supports writing files from parallel computations that use MPI. Ideally, simulation frameworks use GridFormat under-the-hood to avoid duplicate implementation efforts, and implement support for new formats into GridFormat such that they are directly available to all other frameworks that utilize it.

Currently, GridFormat is focused on VTK file formats. However, the API is suitable for any grid format describing one of the supported grid concepts. Contributions are welcomed, see below for information on how to contribute.

Quick Start

Prerequisites:

  • C++-compiler with C++-20-support (tests run with gcc-12/13, clang++-16)
  • cmake (tests run with cmake-3.26)

It is easiest to integrate GridFormat either as a git submodule or via the FetchContent module of cmake. A minimal example (using FetchContent) of a project using GridFormat to write a VTU file and read it back in may look like this:

```cmake cmakeminimumrequired(VERSION 3.22) project(someappusing_gridformat)

include(FetchContent) FetchContentDeclare( gridformat GITREPOSITORY https://github.com/dglaeser/gridformat GITTAG main GITPROGRESS true GITSHALLOW true GITSUBMODULESRECURSE OFF ) FetchContentMakeAvailable(gridformat)

addexecutable(myapp myapp.cpp) targetlinklibraries(myapp PRIVATE gridformat::gridformat) ```

```cpp

include

include

include

double f(const std::array& x) { return x[0]*x[1]; }

int main () { // For this example we have no user-defined grid type. Let's just use a predefined one... GridFormat::ImageGrid<2, double> grid{ {1.0, 1.0}, // domain size {10, 12} // number of cells (pixels) in each direction };

// This shows the `GridFormat` API: Construct a writer for the desired format, and add
// point/cell fields as lambdas. Metadata can be added directly and can be ranges or scalars.
// If the lambdas are not suitable or inefficient for your data structures, you can also pass
// a (custom) implementation of `GridFormat::Field` (see documentation)
GridFormat::Writer writer{GridFormat::vtu, grid};
writer.set_meta_data("some_metadata", "i am metadata");
writer.set_point_field("point_field", [&] (const auto& point) { return f(grid.position(point)); });
writer.set_cell_field("cell_field", [&] (const auto& cell) { return f(grid.center(cell)); });
const auto written_file = writer.write("my_test_file"); // extension is added by the writer

// read the data back in (here we create a generic reader, but you can also select specific ones)
auto reader = GridFormat::Reader::from(written_file);
std::vector<double> cell_field_values(reader.number_of_cells());
std::vector<double> point_field_values(reader.number_of_points());
reader.cell_field("cell_field")->export_to(cell_field_values);
reader.point_field("point_field")->export_to(point_field_values);

return 0;

} `` Many more formats, options and functions are available, see the [API documentation](https://dglaeser.github.io/gridformat/) or have a look at the <!-- DOXYGEN_MAKE_ABSOLUTE -->[examples](examples). Moreover, if your data is cumbersome to access via lambdas (as done in the example above), you may also provide a custom implementation of the <!-- DOXYGEN_MAKE_ABSOLUTE -->[Field`interface](gridformat/common/field.hpp).

Installation

The recommended way of using GridFormat is to include it via cmake's FetchContent module (see quickstart). However, if you want to install GridFormat locally into a custom location, clone the repository, enter the folder and type

bash cmake -DCMAKE_INSTALL_PREFIX=$(pwd)/install \ -DCMAKE_C_COMPILER=/usr/bin/gcc-12 \ -DCMAKE_CXX_COMPILER=/usr/bin/g++-12 \ -B build cmake --install build

Note that you can omit the explicit definition of C_COMPILER and CXX_COMPILER in case your default compiler is compatible. Moreover, for a system-wide installation you may omit the definition of CMAKE_INSTALL_PREFIX. After installation, you can use cmake to link against GridFormat in your own project:

cmake find_package(gridformat) target_link_libraries(... gridformat::gridformat)

Dependencies

GridFormat has no required dependencies, however, some features are only available if certain dependencies are present. For instance, the VTK-HDF file formats are only available if HighFive is found, which itself requires libhdf5-dev. If the latter is found on your system, including GridFormat via cmake's FetchContent (see quickstart) automatically brings in HighFive, as it is included in GridFormat as a git submodule. However, when installing GridFormat from the cloned sources (as described above), make sure to use git clone --recursive in case you want to use the HDF file formats.

The availability of some specific features of a file format may also depend on the availability of certain dependencies. For instance, compression of data (e.g. for the VTK-XML file formats) can only be used if the respective compression libraries are found on the system. Dependencies of those features are stated in the API documentation.

Command-line interface

GridFormat comes with a few command-line apps that you can build and install alongside the library. To include them in the build, pass the option -DGRIDFORMAT_BUILD_BINARIES=ON to cmake when configuring (see above). For performance reasons, you should set -DCMAKE_BUILD_TYPE=Release when configuring. If successfully built, you can then use the command-line apps to print information on a grid file to the terminal, or convert between different file formats. For instance:

cpp gridformat-info my_vti_file.vti # prints info on the contents of the vti file gridformat-convert my_vti_file.vti vtu # converts an image grid format (.vti) to vtu format gridformat-convert my_vti_file.vti vtu encoder=ascii # format options can be set as key-value pairs gridformat-convert my_vti_file.vti vtu -o some_file # choose an output filename

Compatibility with user-defined grids

GridFormat does not operate on a specific grid data structure, but instead, it can be made compatible with any user-defined grid types by implementing specializations for a few traits classes. For information on how to do this, please have a look at the traits classes overview, the <!-- DOXYGENMAKEABSOLUTE -->examples, the predefined <!-- DOXYGENMAKEABSOLUTE -->image grid implementation or the predefined <!-- DOXYGENMAKEABSOLUTE -->traits for several frameworks.

Predefined traits

GridFormat comes with predefined traits for dune grid views (tested dune version: 2.9), deal.ii triangulations (tested deal.ii version: 9.6.0), cgal triangulations in 2d and 3d (tested cgal version: 5.5.2), dolfinx meshes and function spaces (tested dolfinx version: 0.6.0) and mfem meshes (tested mfem version: 4.5.2). Users of these frameworks can include these predefined traits and use GridFormat directly (see the <!-- DOXYGENMAKEABSOLUTE -->examples).

Caveats

When reading from grid files, GridFormat provides access to the data as specified by the file format. These specifications may not be sufficient in all applications. For instance, to fully instantiate a simulator for parallel computations, information on the grid entities shared by different processes is usually required. Since these requirements are simulator-specific, any further processing has to be done manually by the user and for their data structures. The recommended way to deal with this issue is to add any information required for reinstantiation as data fields to the output. This way, it is readily available when reading the file.

Getting help

Find answered questions, ask questions or start discussions through GitHub Discussions.

Contribution Guidelines

Contributions are highly welcome! For bug reports, please file an issue. If you want to contribute with features, improvements or bug fixes please fork this project and open a merge request into the main branch of this repository.

Development and test suite

In order to configure your local copy for testing, tell cmake to include the test suite:

```bash

Note: you may have to set a compiler explicitly (see installation section)

cmake -DGRIDFORMATBUILDTESTS=ON -B build ```

Afterwards, you can build and run all tests with ctest:

```bash

Note: use, e.g., ctest -j4 if you want to use 4 processors

cd build make build_tests ctest ```

Note that an internet connection is required for the call to cmake as it pulls in ut on-the-fly. Moreover, in the configure step a Python script is invoked that produces some test data using VTK. If your Python environment does not have VTK, this step is skipped. Note that some tests in the test suite will be skipped in this case.

Creating a release

To create a release, you may use the utility script util/update_versions.py, which creates a git tag and adjusts the versions and release dates specified in the cmake setup and the CITATION.cff file. We maintain a branch for each minor release to incorporate bug fixes and patch releases. As an example, to create a new minor release version 1.2, you may type type the following into the console:

```bash git switch main # a new minor release should always be started from main git pull --rebase origin main # make sure the local state matches the remote state git switch --create releases/1.2 # this branch will be kept for incorporation of bug fixes and patch release tags 1.2.X

... from now on, only changes that are important for v1.2 but should NOT go into main should be committed on this branch

python3 util/update_versions.py -v 1.2.0 # modifies versions&dates and creates a commit + tag git push origin releases/1.2 git push origin v1.2.0 ```

Afterwards, a release workflow will be triggered. If this runs through successfully, a release has been created. If not, the new tag has to be deleted and the procedure has to be repeated after fixing the errors. After a successful release, the version on main should be increased (without triggering an actual release). Following the above example, you may run the following commands:

```bash git switch main git switch --create feature/bump-version

.. add a new section for release 1.3 in the CHANGELOG and commit it

python3 util/update_versions.py -v 1.3.0 --skip-tag # only modifies versions, no commit or tag git commit -m "bump version to v1.3.0" . git push origin feature/bump-version ```

and pose a pull request for the changes to be incorporated in main.

License

GridFormat is licensed under the terms and conditions of the MIT License. It can be read online or in the <!-- DOXYGENMAKEABSOLUTE -->LICENSES/MIT.txt file. See <!-- DOXYGENMAKEABSOLUTE -->LICENSES/MIT.txt for full copying permissions.

Owner

  • Name: Dennis Gläser
  • Login: dglaeser
  • Kind: user

JOSS Publication

GridFormat: header-only C++-library for grid file I/O
Published
October 16, 2023
Volume 8, Issue 90, Page 5778
Authors
Dennis Gläser ORCID
University of Stuttgart, Germany
Timo Koch ORCID
University of Oslo, Norway
Bernd Flemisch ORCID
University of Stuttgart, Germany
Editor
Daniel S. Katz ORCID
Tags
simulation

Citation (CITATION.cff)

# SPDX-FileCopyrightText: 2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
# SPDX-License-Identifier: MIT

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: "GridFormat - header-only C++-library for grid file I/O"
type: software
authors:
  - given-names: Dennis
    family-names: Gläser
    email: dennis.glaeser@iws.uni-stuttgart.de
    affiliation: University of Stuttgart
    orcid: 'https://orcid.org/0000-0001-9646-881X'
  - given-names: Timo
    family-names: Koch
    orcid: 'https://orcid.org/0000-0003-4776-5222'
    affiliation: University of Oslo
    email: timokoch@math.uio.no
contact:
  - family-names: Gläser
    given-names: Dennis
    orcid: "https://orcid.org/0000-0001-9646-881X"
repository-code: 'https://github.com/dglaeser/gridformat'
url: 'https://dglaeser.github.io/gridformat/'
abstract: Header-only C++-Library for grid file I/O
keywords:
  - numerical simulation
  - grid file I/O
  - mesh file I/O
license: MIT
version: 0.5.0
date-released: '2025-04-08'
identifiers:
  - description: Collection of archived snapshots of all versions
    type: doi
    value: "10.5281/zenodo.10008061"
message: If you use this software, please cite our article in the
  Journal of Open Source Software.
preferred-citation:
  authors:
  - family-names: Gläser
    given-names: Dennis
    orcid: "https://orcid.org/0000-0001-9646-881X"
  - family-names: Koch
    given-names: Timo
    orcid: "https://orcid.org/0000-0003-4776-5222"
  - family-names: Flemisch
    given-names: Bernd
    orcid: "https://orcid.org/0000-0001-8188-620X"
  date-published: 2023-10-16
  doi: 10.21105/joss.05778
  issn: 2475-9066
  issue: 90
  journal: Journal of Open Source Software
  publisher:
    name: Open Journals
  start: 5778
  title: "GridFormat: header-only C++-library for grid file I/O"
  type: article
  url: "https://joss.theoj.org/papers/10.21105/joss.05778"
  volume: 8

GitHub Events

Total
  • Create event: 47
  • Release event: 1
  • Issues event: 30
  • Watch event: 4
  • Delete event: 45
  • Issue comment event: 163
  • Push event: 232
  • Pull request review event: 52
  • Pull request review comment event: 41
  • Pull request event: 93
Last Year
  • Create event: 47
  • Release event: 1
  • Issues event: 30
  • Watch event: 4
  • Delete event: 45
  • Issue comment event: 163
  • Push event: 232
  • Pull request review event: 52
  • Pull request review comment event: 41
  • Pull request event: 93

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 1,157
  • Total Committers: 2
  • Avg Commits per committer: 578.5
  • Development Distribution Score (DDS): 0.033
Past Year
  • Commits: 135
  • Committers: 2
  • Avg Commits per committer: 67.5
  • Development Distribution Score (DDS): 0.126
Top Committers
Name Email Commits
Dennis Gläser d****r@g****m 1,119
Timo Koch t****h@u****o 38
Committer Domains (Top 20 + Academic)
uio.no: 1

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 26
  • Total pull requests: 108
  • Average time to close issues: 2 months
  • Average time to close pull requests: 2 days
  • Total issue authors: 3
  • Total pull request authors: 3
  • Average comments per issue: 1.38
  • Average comments per pull request: 2.44
  • Merged pull requests: 85
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 15
  • Pull requests: 79
  • Average time to close issues: 5 days
  • Average time to close pull requests: 1 day
  • Issue authors: 3
  • Pull request authors: 2
  • Average comments per issue: 2.0
  • Average comments per pull request: 2.95
  • Merged pull requests: 61
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • dglaeser (20)
  • timokoch (6)
  • HuntFeng (2)
Pull Request Authors
  • dglaeser (121)
  • timokoch (26)
  • danielskatz (1)
Top Labels
Issue Labels
enhancement (1)
Pull Request Labels
enhancement (15) documentation (10) bug (6)

Dependencies

.github/workflows/release.yml actions
  • actions/checkout v3 composite
  • ncipollo/release-action v1 composite
.github/workflows/main.yml actions
  • actions/checkout v2 composite
.github/actions/test-installed-pkg/action.yml actions
.github/workflows/images.yml actions
  • actions/checkout v2 composite
  • docker/build-push-action v4.1.1 composite
  • docker/login-action v2.2.0 composite
.github/workflows/pages.yml actions
  • JamesIves/github-pages-deploy-action v4 composite
  • actions/checkout v2 composite
docker/Dockerfile docker
  • base latest build
  • minimal latest build
  • ubuntu 22.04 build