Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
NFDI: provide source path as external variable
  • Loading branch information
jan-janssen committed May 14, 2025
commit 21542587cd955643476f16e58a430feefd261197
10 changes: 8 additions & 2 deletions example_workflows/nfdi/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
{"id": 4, "type": "function", "value": "workflow.substitute_macros"},
{"id": 5, "type": "function", "value": "workflow.compile_paper"},
{"id": 6, "type": "input", "value": 2.0, "name": "domain_size"},
{"id": 7, "type": "output", "name": "result"}
{"id": 7, "type": "input", "value": "source", "name": "source_directory"},
{"id": 8, "type": "output", "name": "result"}
],
"edges": [
{"target": 0, "targetPort": "domain_size", "source": 6, "sourcePort": null},
{"target": 0, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 1, "targetPort": "gmsh_output_file", "source": 0, "sourcePort": null},
{"target": 2, "targetPort": "meshio_output_xdmf", "source": 1, "sourcePort": "xdmf_file"},
{"target": 2, "targetPort": "meshio_output_h5", "source": 1, "sourcePort": "h5_file"},
{"target": 2, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 3, "targetPort": "poisson_output_pvd_file", "source": 2, "sourcePort": "pvd_file"},
{"target": 3, "targetPort": "poisson_output_vtu_file", "source": 2, "sourcePort": "vtu_file"},
{"target": 3, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 4, "targetPort": "pvbatch_output_file", "source": 3, "sourcePort": null},
{"target": 4, "targetPort": "ndofs", "source": 2, "sourcePort": "numdofs"},
{"target": 4, "targetPort": "domain_size", "source": 6, "sourcePort": null},
{"target": 4, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 5, "targetPort": "macros_tex", "source": 4, "sourcePort": null},
{"target": 5, "targetPort": "plot_file", "source": 3, "sourcePort": null},
{"target": 7, "targetPort": null, "source": 5, "sourcePort": null}
{"target": 5, "targetPort": "source_directory", "source": 7, "sourcePort": null},
{"target": 8, "targetPort": null, "source": 5, "sourcePort": null}
]
}
26 changes: 13 additions & 13 deletions example_workflows/nfdi/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from conda_subprocess import check_output
import shutil

source_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "source")
source_directory_global = os.path.join(os.path.dirname(os.path.abspath(__file__)), "source")


def generate_mesh(domain_size: float = 2.0) -> str:
def generate_mesh(domain_size: float = 2.0, source_directory: str = source_directory_global) -> str:
stage_name = "preprocessing"
gmsh_output_file_name = "square.msh"
source_file_name ="unit_square.geo"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_ = check_output(
[
"gmsh", "-2", "-setnumber", "domain_size", str(domain_size),
Expand Down Expand Up @@ -40,13 +40,13 @@ def convert_to_xdmf(gmsh_output_file : str) -> dict:
}


def poisson(meshio_output_xdmf: str, meshio_output_h5: str) -> dict:
def poisson(meshio_output_xdmf: str, meshio_output_h5: str, source_directory: str = source_directory_global) -> dict:
stage_name = "processing"
poisson_output_pvd_file_name = "poisson.pvd"
poisson_output_numdofs_file_name = "numdofs.txt"
source_file_name = "poisson.py"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_copy_file(stage_name=stage_name, source_file=meshio_output_xdmf)
_copy_file(stage_name=stage_name, source_file=meshio_output_h5)
_ = check_output(
Expand All @@ -65,12 +65,12 @@ def poisson(meshio_output_xdmf: str, meshio_output_h5: str) -> dict:
}


def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str) -> str:
def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str, source_directory: str = source_directory_global) -> str:
stage_name = "postprocessing"
pvbatch_output_file_name = "plotoverline.csv"
source_file_name = "postprocessing.py"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_copy_file(stage_name=stage_name, source_file=poisson_output_pvd_file)
_copy_file(stage_name=stage_name, source_file=poisson_output_vtu_file)
_ = check_output(
Expand All @@ -82,14 +82,14 @@ def plot_over_line(poisson_output_pvd_file: str, poisson_output_vtu_file: str) -
return os.path.abspath(os.path.join("postprocessing", pvbatch_output_file_name))


def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float = 2.0) -> str:
def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float = 2.0, source_directory: str = source_directory_global) -> str:
stage_name = "postprocessing"
source_file_name = "prepare_paper_macros.py"
template_file_name = "macros.tex.template"
macros_output_file_name = "macros.tex"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=template_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_copy_file_from_source(stage_name=stage_name, source_file_name=template_file_name, source_directory=source_directory)
_copy_file(stage_name=stage_name, source_file=pvbatch_output_file)
_ = check_output(
[
Expand All @@ -104,12 +104,12 @@ def substitute_macros(pvbatch_output_file: str, ndofs: int, domain_size: float =
return os.path.abspath(os.path.join(stage_name, macros_output_file_name))


def compile_paper(macros_tex: str, plot_file: str) -> str:
def compile_paper(macros_tex: str, plot_file: str, source_directory: str = source_directory_global) -> str:
stage_name = "postprocessing"
paper_output = "paper.pdf"
source_file_name = "paper.tex"
os.makedirs(stage_name, exist_ok=True)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name)
_copy_file_from_source(stage_name=stage_name, source_file_name=source_file_name, source_directory=source_directory)
_copy_file(stage_name=stage_name, source_file=macros_tex)
_copy_file(stage_name=stage_name, source_file=plot_file)
_ = check_output(
Expand All @@ -132,6 +132,6 @@ def _copy_file(stage_name, source_file):
shutil.copyfile(source_file, input_file)


def _copy_file_from_source(stage_name, source_file_name):
def _copy_file_from_source(stage_name, source_file_name, source_directory: str = source_directory_global):
source_file = os.path.join(source_directory, source_file_name)
shutil.copyfile(source_file, os.path.join(stage_name, source_file_name))