function to list available setup files can be useful

This commit is contained in:
Daniel Otto de Mentock 2022-11-09 12:48:37 +01:00
parent ce7d2af6e3
commit 1cdb7ef09f
2 changed files with 15 additions and 0 deletions

View File

@ -1996,3 +1996,14 @@ class Result:
output=output,
cfg_dir=cfg_dir,
overwrite=overwrite))
def list_simulation_setup_files(self):
"""List available simulation setup files used to generate the Result object."""
simulation_datasets = []
def retrieve_dataset(name, node):
simulation_datasets.append(name)
with h5py.File(self.fname,'r') as f_in:
f_in['setup'].visititems(retrieve_dataset)
return simulation_datasets

View File

@ -564,6 +564,10 @@ class TestResult:
r.export_simulation_setup_files('material.yaml',target_dir=t)
assert 'material.yaml' in os.listdir(absdir); (absdir/'material.yaml').unlink()
def test_list_simulation_setup_files(self,ref_path):
r = Result(ref_path/'4grains2x4x3_compressionY.hdf5')
assert r.list_simulation_setup_files()==['4grains2x4x3.vti', 'compressionY.yaml', 'material.yaml']
@pytest.mark.parametrize('fname',['4grains2x4x3_compressionY.hdf5',
'6grains6x7x8_single_phase_tensionY.hdf5'])
def test_export_DADF5(self,ref_path,tmp_path,fname):