-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-options-adios: writes correctly settings.bp and test-out.bp
- Loading branch information
Showing
10 changed files
with
208 additions
and
32 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
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
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,6 @@ | ||
bout_add_integrated_test(test-options-adios | ||
SOURCES test-options-adios.cxx | ||
USE_RUNTEST | ||
USE_DATA_BOUT_INP | ||
REQUIRES BOUT_HAS_ADIOS | ||
) |
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,6 @@ | ||
|
||
|
||
[mesh] | ||
nx = 5 | ||
ny = 2 | ||
nz = 2 |
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,6 @@ | ||
|
||
BOUT_TOP = ../../.. | ||
|
||
SOURCEC = test-options-adios.cxx | ||
|
||
include $(BOUT_TOP)/make.config |
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,73 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Note: This test requires NCDF4, whereas on Travis NCDF is used | ||
# requires: netcdf | ||
# requires: not legacy_netcdf | ||
|
||
from boututils.datafile import DataFile | ||
from boututils.run_wrapper import build_and_log, shell, launch | ||
from boutdata.data import BoutOptionsFile | ||
|
||
import math | ||
import numpy as np | ||
|
||
build_and_log("options-netcdf test") | ||
shell("rm -f test-out.ini") | ||
shell("rm -f test-out.nc") | ||
|
||
# Create a NetCDF input file | ||
with DataFile("test.nc", create=True, format="NETCDF4") as f: | ||
f.write("int", 42) | ||
f.write("real", 3.1415) | ||
f.write("string", "hello") | ||
|
||
# run BOUT++ | ||
launch("./test-options-adios", nproc=1, mthread=1) | ||
|
||
# Check the output INI file | ||
result = BoutOptionsFile("test-out.ini") | ||
|
||
print(result) | ||
|
||
assert result["int"] == 42 | ||
assert math.isclose(result["real"], 3.1415) | ||
assert result["string"] == "hello" | ||
|
||
print("Checking saved ADIOS test-out file -- Not implemented") | ||
|
||
# Check the output NetCDF file | ||
# with DataFile("test-out.nc") as f: | ||
# assert f["int"] == 42 | ||
# assert math.isclose(f["real"], 3.1415) | ||
# assert result["string"] == "hello" | ||
|
||
print("Checking saved settings.ini") | ||
|
||
# Check the settings.ini file, coming from BOUT.inp | ||
# which is converted to NetCDF, read in, then written again | ||
settings = BoutOptionsFile("settings.ini") | ||
|
||
assert settings["mesh"]["nx"] == 5 | ||
assert settings["mesh"]["ny"] == 2 | ||
|
||
print("Checking saved fields.bp -- Not implemented") | ||
|
||
# with DataFile("fields.nc") as f: | ||
# assert f["f2d"].shape == (5, 6) # Field2D | ||
# assert f["f3d"].shape == (5, 6, 2) # Field3D | ||
# assert f["fperp"].shape == (5, 2) # FieldPerp | ||
# assert np.allclose(f["f2d"], 1.0) | ||
# assert np.allclose(f["f3d"], 2.0) | ||
# assert np.allclose(f["fperp"], 3.0) | ||
|
||
print("Checking saved fields2.bp -- Not implemented") | ||
|
||
# with DataFile("fields2.nc") as f: | ||
# assert f["f2d"].shape == (5, 6) # Field2D | ||
# assert f["f3d"].shape == (5, 6, 2) # Field3D | ||
# assert f["fperp"].shape == (5, 2) # FieldPerp | ||
# assert np.allclose(f["f2d"], 1.0) | ||
# assert np.allclose(f["f3d"], 2.0) | ||
# assert np.allclose(f["fperp"], 3.0) | ||
|
||
print(" => Passed") |
85 changes: 85 additions & 0 deletions
85
tests/integrated/test-options-adios/test-options-adios.cxx
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,85 @@ | ||
|
||
#include "bout/bout.hxx" | ||
|
||
#include "bout/options_io.hxx" | ||
#include "bout/options_netcdf.hxx" | ||
#include "bout/options_adios.hxx" | ||
#include "bout/optionsreader.hxx" | ||
|
||
using bout::OptionsADIOS; | ||
|
||
int main(int argc, char** argv) { | ||
BoutInitialise(argc, argv); | ||
|
||
// Read values from a NetCDF file | ||
bout::OptionsNetCDF file("test.nc"); | ||
|
||
auto values = file.read(); | ||
|
||
values.printUnused(); | ||
|
||
// Write to an INI text file | ||
OptionsReader* reader = OptionsReader::getInstance(); | ||
reader->write(&values, "test-out.ini"); | ||
|
||
// Write to a NetCDF file | ||
OptionsADIOS("test-out.bp").write(values); | ||
|
||
/////////////////////////// | ||
|
||
// Write the BOUT.inp settings to NetCDF file | ||
OptionsADIOS("settings.bp").write(Options::root()); | ||
|
||
// Read back in | ||
auto settings = OptionsADIOS("settings.bp").read(); | ||
|
||
// Write to INI file | ||
reader->write(&settings, "settings.ini"); | ||
|
||
/////////////////////////// | ||
// Write fields | ||
|
||
Options fields; | ||
fields["f2d"] = Field2D(1.0); | ||
fields["f3d"] = Field3D(2.0); | ||
fields["fperp"] = FieldPerp(3.0); | ||
OptionsADIOS("fields.bp").write(fields); | ||
|
||
/////////////////////////// | ||
// Read fields | ||
|
||
Options fields_in = OptionsADIOS("fields.bp").read(); | ||
|
||
auto f2d = fields_in["f2d"].as<Field2D>(bout::globals::mesh); | ||
auto f3d = fields_in["f3d"].as<Field3D>(bout::globals::mesh); | ||
auto fperp = fields_in["fperp"].as<FieldPerp>(bout::globals::mesh); | ||
|
||
Options fields2; | ||
fields2["f2d"] = f2d; | ||
fields2["f3d"] = f3d; | ||
fields2["fperp"] = fperp; | ||
|
||
// Write out again | ||
OptionsADIOS("fields2.bp").write(fields2); | ||
|
||
/////////////////////////// | ||
// Time dependent values | ||
|
||
Options data; | ||
data["scalar"] = 1.0; | ||
data["scalar"].attributes["time_dimension"] = "t"; | ||
|
||
data["field"] = Field3D(2.0); | ||
data["field"].attributes["time_dimension"] = "t"; | ||
|
||
OptionsADIOS("time.bp").write(data); | ||
|
||
// Update time-dependent values | ||
data["scalar"] = 2.0; | ||
data["field"] = Field3D(3.0); | ||
|
||
// Append data to file | ||
OptionsADIOS("time.nc", bout::OptionsIO::FileMode::append).write(data); | ||
|
||
BoutFinalise(); | ||
}; |
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