|
1 | 1 | import os |
| 2 | +import shutil |
2 | 3 | from pyiron_base import Project |
3 | 4 |
|
4 | 5 | # input parameter |
|
13 | 14 | "processing": "../source/envs/processing.yaml", |
14 | 15 | "postprocessing": "../source/envs/postprocessing.yaml" |
15 | 16 | }.items(): |
16 | | - pr.conda_environment.create(env_name=k, env_file=v) |
| 17 | + pr.conda_environment.create(env_name=k, env_file=v, global_installation=False) |
17 | 18 |
|
18 | 19 |
|
19 | 20 | # Preprocessing |
20 | 21 | ## generate mesh |
21 | 22 | gmsh = pr.wrap_executable( |
22 | | - job_name="gmsh", |
23 | 23 | executable_str=f"gmsh -2 -setnumber domain_size {domain_size} unit_square.geo -o square.msh", |
24 | 24 | conda_environment_path=pr.conda_environment.preprocessing, |
25 | 25 | input_file_lst=["../source/unit_square.geo"], |
26 | | - execute_job=True, |
| 26 | + delayed=True, |
| 27 | + output_file_lst=["square.msh"], |
27 | 28 | ) |
28 | 29 |
|
29 | 30 | ## convert mesh to xdmf |
30 | 31 | meshio = pr.wrap_executable( |
31 | | - job_name="meshio", |
32 | 32 | executable_str="meshio convert square.msh square.xdmf", |
33 | 33 | conda_environment_path=pr.conda_environment.preprocessing, |
34 | 34 | input_file_lst=[gmsh.files.square_msh], |
35 | | - execute_job=True, |
| 35 | + delayed=True, |
| 36 | + output_file_lst=["square.xdmf", "square.h5"], |
36 | 37 | ) |
37 | 38 |
|
38 | 39 |
|
39 | 40 | # Processing |
40 | 41 | ## poisson |
| 42 | +def collect_output(working_directory): |
| 43 | + with open(os.path.join(working_directory, "numdofs.txt"), "r") as f: |
| 44 | + return {"numdofs": int(f.read())} |
| 45 | + |
41 | 46 | poisson = pr.wrap_executable( |
42 | | - job_name="poisson", |
43 | 47 | executable_str="python poisson.py --mesh square.xdmf --degree 2 --outputfile poisson.pvd --num-dofs numdofs.txt", |
44 | 48 | conda_environment_path=pr.conda_environment.processing, |
45 | 49 | input_file_lst=["../source/poisson.py", meshio.files.square_xdmf, meshio.files.square_h5], |
46 | | - execute_job=True, |
| 50 | + delayed=True, |
| 51 | + collect_output_funct=collect_output, |
| 52 | + output_key_lst=["numdofs"], |
| 53 | + output_file_lst=["poisson.pvd", "poisson000000.vtu"], |
47 | 54 | ) |
48 | 55 |
|
49 | 56 |
|
50 | 57 | # Postprocessing |
51 | 58 | ## plot over line |
52 | 59 | pvbatch = pr.wrap_executable( |
53 | | - job_name="pvbatch", |
54 | 60 | executable_str="pvbatch postprocessing.py poisson.pvd plotoverline.csv", |
55 | 61 | conda_environment_path=pr.conda_environment.postprocessing, |
56 | 62 | input_file_lst=["../source/postprocessing.py", poisson.files.poisson_pvd, poisson.files.poisson000000_vtu], |
57 | | - execute_job=True, |
| 63 | + delayed=True, |
| 64 | + output_file_lst=["plotoverline.csv"], |
58 | 65 | ) |
59 | 66 |
|
60 | 67 | ## substitute macros |
| 68 | +def write_input(input_dict, working_directory): |
| 69 | + script_name = os.path.join(working_directory, "macros.sh") |
| 70 | + with open(script_name, "w") as f: |
| 71 | + f.writelines(f"python prepare_paper_macros.py --macro-template-file macros.tex.template --plot-data-path plotoverline.csv --domain-size {domain_size} --num-dofs {input_dict["numdofs"]} --output-macro-file macros.tex") |
| 72 | + os.chmod(script_name, 0o744) |
| 73 | + |
61 | 74 | macros = pr.wrap_executable( |
62 | | - job_name="macros", |
63 | | - executable_str=f"python prepare_paper_macros.py --macro-template-file macros.tex.template --plot-data-path plotoverline.csv --domain-size {domain_size} --num-dofs {int(poisson.output['stdout'].split()[-1])} --output-macro-file macros.tex", |
| 75 | + input_dict={"numdofs": poisson.output.numdofs}, |
| 76 | + write_input_funct=write_input, |
| 77 | + executable_str="./macros.sh", |
64 | 78 | conda_environment_path=pr.conda_environment.postprocessing, |
65 | 79 | input_file_lst=["../source/macros.tex.template", "../source/prepare_paper_macros.py", pvbatch.files.plotoverline_csv], |
66 | | - execute_job=True, |
| 80 | + delayed=True, |
| 81 | + output_file_lst=["macros.tex"], |
67 | 82 | ) |
68 | 83 |
|
69 | 84 | ## compile paper |
70 | 85 | tectonic = pr.wrap_executable( |
71 | | - job_name="tectonic", |
72 | 86 | executable_str="tectonic paper.tex", |
73 | 87 | conda_environment_path=pr.conda_environment.postprocessing, |
74 | 88 | input_file_lst=["../source/paper.tex", macros.files.macros_tex, pvbatch.files.plotoverline_csv], |
75 | | - execute_job=True, |
| 89 | + delayed=True, |
| 90 | + output_file_lst=["paper.pdf"], |
76 | 91 | ) |
| 92 | + |
| 93 | +# Execute Workflow Graph and copy output |
| 94 | +result = tectonic.pull() |
| 95 | +shutil.copyfile(str(result.files.paper_pdf), "paper.pdf") |
0 commit comments