Skip to content

Commit 2154258

Browse files
committed
NFDI: provide source path as external variable
1 parent e9aba8a commit 2154258

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

example_workflows/nfdi/workflow.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@
77
{"id": 4, "type": "function", "value": "workflow.substitute_macros"},
88
{"id": 5, "type": "function", "value": "workflow.compile_paper"},
99
{"id": 6, "type": "input", "value": 2.0, "name": "domain_size"},
10-
{"id": 7, "type": "output", "name": "result"}
10+
{"id": 7, "type": "input", "value": "source", "name": "source_directory"},
11+
{"id": 8, "type": "output", "name": "result"}
1112
],
1213
"edges": [
1314
{"target": 0, "targetPort": "domain_size", "source": 6, "sourcePort": null},
15+
{"target": 0, "targetPort": "source_directory", "source": 7, "sourcePort": null},
1416
{"target": 1, "targetPort": "gmsh_output_file", "source": 0, "sourcePort": null},
1517
{"target": 2, "targetPort": "meshio_output_xdmf", "source": 1, "sourcePort": "xdmf_file"},
1618
{"target": 2, "targetPort": "meshio_output_h5", "source": 1, "sourcePort": "h5_file"},
19+
{"target": 2, "targetPort": "source_directory", "source": 7, "sourcePort": null},
1720
{"target": 3, "targetPort": "poisson_output_pvd_file", "source": 2, "sourcePort": "pvd_file"},
1821
{"target": 3, "targetPort": "poisson_output_vtu_file", "source": 2, "sourcePort": "vtu_file"},
22+
{"target": 3, "targetPort": "source_directory", "source": 7, "sourcePort": null},
1923
{"target": 4, "targetPort": "pvbatch_output_file", "source": 3, "sourcePort": null},
2024
{"target": 4, "targetPort": "ndofs", "source": 2, "sourcePort": "numdofs"},
2125
{"target": 4, "targetPort": "domain_size", "source": 6, "sourcePort": null},
26+
{"target": 4, "targetPort": "source_directory", "source": 7, "sourcePort": null},
2227
{"target": 5, "targetPort": "macros_tex", "source": 4, "sourcePort": null},
2328
{"target": 5, "targetPort": "plot_file", "source": 3, "sourcePort": null},
24-
{"target": 7, "targetPort": null, "source": 5, "sourcePort": null}
29+
{"target": 5, "targetPort": "source_directory", "source": 7, "sourcePort": null},
30+
{"target": 8, "targetPort": null, "source": 5, "sourcePort": null}
2531
]
2632
}

example_workflows/nfdi/workflow.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
from conda_subprocess import check_output
33
import shutil
44

5-
source_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "source")
5+
source_directory_global = os.path.join(os.path.dirname(os.path.abspath(__file__)), "source")
66

77

8-
def generate_mesh(domain_size: float = 2.0) -> str:
8+
def generate_mesh(domain_size: float = 2.0, source_directory: str = source_directory_global) -> str:
99
stage_name = "preprocessing"
1010
gmsh_output_file_name = "square.msh"
1111
source_file_name ="unit_square.geo"
1212
os.makedirs(stage_name, exist_ok=True)
13-
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
13+
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
1414
_ = check_output(
1515
[
1616
"gmsh", "-2", "-setnumber", "domain_size", str(domain_size),
@@ -40,13 +40,13 @@ def convert_to_xdmf(gmsh_output_file : str) -> dict:
4040
}
4141

4242

43-
def poisson(meshio_output_xdmf: str, meshio_output_h5: str) -> dict:
43+
def poisson(meshio_output_xdmf: str, meshio_output_h5: str, source_directory: str = source_directory_global) -> dict:
4444
stage_name = "processing"
4545
poisson_output_pvd_file_name = "poisson.pvd"
4646
poisson_output_numdofs_file_name = "numdofs.txt"
4747
source_file_name = "poisson.py"
4848
os.makedirs(stage_name, exist_ok=True)
49-
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
49+
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
5050
_copy_file(stage_name=stage_name, source_file=meshio_output_xdmf)
5151
_copy_file(stage_name=stage_name, source_file=meshio_output_h5)
5252
_ = check_output(
@@ -65,12 +65,12 @@ def poisson(meshio_output_xdmf: str, meshio_output_h5: str) -> dict:
6565
}
6666

6767

68-
def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str) -> str:
68+
def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str, source_directory: str = source_directory_global) -> str:
6969
stage_name = "postprocessing"
7070
pvbatch_output_file_name = "plotoverline.csv"
7171
source_file_name = "postprocessing.py"
7272
os.makedirs(stage_name, exist_ok=True)
73-
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
73+
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
7474
_copy_file(stage_name=stage_name, source_file=poisson_output_pvd_file)
7575
_copy_file(stage_name=stage_name, source_file=poisson_output_vtu_file)
7676
_ = check_output(
@@ -82,14 +82,14 @@ def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str) -
8282
return os.path.abspath(os.path.join("postprocessing", pvbatch_output_file_name))
8383

8484

85-
def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float = 2.0) -> str:
85+
def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float = 2.0, source_directory: str = source_directory_global) -> str:
8686
stage_name = "postprocessing"
8787
source_file_name = "prepare_paper_macros.py"
8888
template_file_name = "macros.tex.template"
8989
macros_output_file_name = "macros.tex"
9090
os.makedirs(stage_name, exist_ok=True)
91-
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
92-
_copy_file_from_source(stage_name=stage_name, source_file_name=template_file_name)
91+
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
92+
_copy_file_from_source(stage_name=stage_name, source_file_name=template_file_name, source_directory=source_directory)
9393
_copy_file(stage_name=stage_name, source_file=pvbatch_output_file)
9494
_ = check_output(
9595
[
@@ -104,12 +104,12 @@ def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float =
104104
return os.path.abspath(os.path.join(stage_name, macros_output_file_name))
105105

106106

107-
def compile_paper(macros_tex: str, plot_file: str) -> str:
107+
def compile_paper(macros_tex: str, plot_file: str, source_directory: str = source_directory_global) -> str:
108108
stage_name = "postprocessing"
109109
paper_output = "paper.pdf"
110110
source_file_name = "paper.tex"
111111
os.makedirs(stage_name, exist_ok=True)
112-
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
112+
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
113113
_copy_file(stage_name=stage_name, source_file=macros_tex)
114114
_copy_file(stage_name=stage_name, source_file=plot_file)
115115
_ = check_output(
@@ -132,6 +132,6 @@ def _copy_file(stage_name, source_file):
132132
shutil.copyfile(source_file, input_file)
133133

134134

135-
def _copy_file_from_source(stage_name, source_file_name):
135+
def _copy_file_from_source(stage_name, source_file_name, source_directory: str = source_directory_global):
136136
source_file = os.path.join(source_directory, source_file_name)
137137
shutil.copyfile(source_file, os.path.join(stage_name, source_file_name))

0 commit comments

Comments
 (0)