Skip to content

Commit

Permalink
890 require hydrolib core 080 to extend mdu keyword support (#891)
Browse files Browse the repository at this point in the history
* updated minimal version for hydrolib-core

* removed workaround for number of processes in dimr_config.xml
  • Loading branch information
veenstrajelmer authored Jul 9, 2024
1 parent 76f8dd9 commit 8448556
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
13 changes: 0 additions & 13 deletions dfm_tools/modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,6 @@ def create_model_exec_files(file_mdu, nproc=1, dimrset_folder=None, path_style=N
print(f"writing {dimr_name}")
dimr_model.save(file_dimr)

# TODO: hydrolib-core does not support multiple cores properly: https://github.com/Deltares/dfm_tools/issues/214
# therefore we manually replace it in the file
print(f"re-writing {dimr_name}")
with open(file_dimr,'r') as f:
lines = f.readlines()
str_from = f"<process>{nproc}</process>"
nproc_range_str = " ".join([str(x) for x in range(nproc)])
str_to = f"<process>{nproc_range_str}</process>"
lines_new = [line.replace(str_from,str_to) for line in lines]
with open(file_dimr,'w') as f:
for line in lines_new:
f.write(line)

if dimrset_folder is None:
print("no dimrset_folder provided, cannot write bat/sh file")
return
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ dependencies = [
"rws-ddlpy>=0.4.0",
#pooch<1.1.0 do not have attribute retrieve
"pooch>=1.1.0",
#hydrolib-core 0.7.0 supports meshkernel>=4.1.0
"hydrolib-core>=0.7.0",
#hydrolib-core 0.8.0 support for many more mdu keywords and correct dimr_config.xml for parallel runs
"hydrolib-core>=0.8.0",
#meshkernel<4.2.0 support for more gridded_samples dtypes and workarounds for non-orthogonal grids
"meshkernel>=4.2.0",
]
Expand Down
10 changes: 8 additions & 2 deletions tests/test_modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ def test_create_model_exec_files_none(tmp_path):
mdu_file = tmp_path / "temp_test.mdu"
file_dimr = tmp_path / "dimr_config.xml"

nproc = 1 # number of processes
nproc = 4 # number of processes
dimrset_folder = None
mdu = hcdfm.FMModel()
mdu.save(mdu_file)
dfmt.create_model_exec_files(file_mdu=mdu_file, nproc=nproc, dimrset_folder=dimrset_folder)

assert os.path.isfile(file_dimr)

# check if the dimr_config.xml file had the correct amount of processes
# this failed before fixing https://github.com/Deltares/HYDROLIB-core/issues/562
with open(file_dimr, 'r') as f:
data = f.readlines()
assert ' <process>0 1 2 3</process>\n' in data


@pytest.mark.unittest
Expand Down Expand Up @@ -116,7 +122,7 @@ def test_make_paths_relative(tmp_path):
forcingfile=ForcingModel_object)
ext_new.boundary.append(boundary_object)
ext_new.save(filepath=ext_file_new)

# old ext
ext_file_old = os.path.join(tmp_path, 'test_old.ext')
ext_old = hcdfm.ExtOldModel()
Expand Down

0 comments on commit 8448556

Please sign in to comment.