-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Generate adios4dolfinx legacy data | ||
|
||
on: | ||
workflow_call: | ||
|
||
env: | ||
data_dir: "legacy_checkpoint" | ||
|
||
|
||
jobs: | ||
create-data: | ||
runs-on: "ubuntu-22.04" | ||
container: ghcr.io/fenics/dolfinx/dolfinx:v0.7.3 | ||
env: | ||
adios4dolfinx_version: "0.7.1" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install legacy version of adios4dolfinx | ||
- run: python3 -m pip install adios4dolfinx==${adios4dolfinx_version} | ||
- name: Create datasets | ||
run: python3 ./tests/create_legacy_checkpoint.py --output-dir=$data_dir | ||
|
||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ env.data_dir }} | ||
path: ./${{ env.data_dir }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright (C) 2024 Jørgen Schartum Dokken | ||
# | ||
# This file is part of adios4dolfinx | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
|
||
""" | ||
Functions to create checkpoints with adios4dolfinx v0.7.x | ||
""" | ||
|
||
import argparse | ||
import pathlib | ||
|
||
import numpy as np | ||
from mpi4py import MPI | ||
import adios4dolfinx | ||
import dolfinx | ||
from importlib.metadata import version | ||
|
||
a4d_version = version("adios4dolfinx") | ||
assert a4d_version < "0.8.0", f"Creating a legacy checkpoint requires adios4dolfinx < 0.8.0, you have {a4d_version}." | ||
|
||
|
||
def f(x): | ||
values = np.zeros((2, x.shape[1]), dtype=np.float64) | ||
values[0] = x[0] | ||
values[1] = -x[1] | ||
return values | ||
|
||
|
||
def write_checkpoint(filename, mesh, el, f): | ||
V = dolfinx.fem.FunctionSpace(mesh, el) | ||
uh = dolfinx.fem.Function(V, dtype=np.float64) | ||
uh.interpolate(f) | ||
|
||
adios4dolfinx.write_mesh(V.mesh, filename) | ||
adios4dolfinx.write_function(uh, filename) | ||
|
||
|
||
def verify_checkpoint(filename, el, f): | ||
mesh = adios4dolfinx.read_mesh(MPI.COMM_WORLD, filename, "BP4", dolfinx.mesh.GhostMode.shared_facet) | ||
V = dolfinx.fem.FunctionSpace(mesh, el) | ||
uh = dolfinx.fem.Function(V, dtype=np.float64) | ||
adios4dolfinx.read_function(uh, filename) | ||
|
||
u_ex = dolfinx.fem.Function(V, dtype=np.float64) | ||
u_ex.interpolate(f) | ||
|
||
np.testing.assert_allclose(u_ex.x.array, uh.x.array, atol=1e-15) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
) | ||
parser.add_argument("--output-dir", type=str, default="legacy_checkpoint", dest="dir") | ||
|
||
inputs = parser.parse_args() | ||
path = pathlib.Path(inputs.dir) | ||
path.mkdir(exist_ok=True, parents=True) | ||
filename = path / "adios4dolfinx_checkpoint.bp" | ||
|
||
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10) | ||
el = ("N1curl", 3) | ||
write_checkpoint(filename, mesh, el, f) | ||
MPI.COMM_WORLD.Barrier() | ||
verify_checkpoint(filename, el, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters