Skip to content

Commit 6023dbd

Browse files
Use pathlib and absolute paths to allow execution from root folder of tutorial.
1 parent 5d22b76 commit 6023dbd

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

channel-transport-reaction/chemical-fenics/chemical-reaction-advection-diffusion.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import numpy as np
55
import csv
66
from mpi4py import MPI
7+
from pathlib import Path
78

8-
outfolder = 'output'
9+
outfolder = Path(__file__).parent / 'output'
910

1011
default_dt = 1.0 # time step size
1112

@@ -26,7 +27,7 @@ def inside(self, x, on_boundary):
2627

2728
# Initialize preCICE
2829
precice = fenicsprecice.Adapter(
29-
adapter_config_filename="chemical-reaction-advection-diffusion.json")
30+
adapter_config_filename=Path(__file__).parent / "chemical-reaction-advection-diffusion.json")
3031
precice.initialize(coupling_subdomain=CouplingDomain(), read_function_space=W)
3132
precice_dt = precice.get_max_time_step_size()
3233

@@ -78,16 +79,16 @@ def inside(self, x, on_boundary):
7879

7980

8081
t = 0
81-
vtkfileA = File(outfolder + '/chemical_A.pvd')
82-
vtkfileB = File(outfolder + '/chemical_B.pvd')
83-
vtkfileC = File(outfolder + '/chemical_C.pvd')
84-
vtkfileFlow = File(outfolder + '/chemical_fluid_read.pvd')
82+
vtkfileA = File(str(outfolder / 'chemical_A.pvd'))
83+
vtkfileB = File(str(outfolder / 'chemical_B.pvd'))
84+
vtkfileC = File(str(outfolder / 'chemical_C.pvd'))
85+
vtkfileFlow = File(str(outfolder / 'chemical_fluid_read.pvd'))
8586

8687
# CSV file to keep track of integrals (i.e. total amount of A, B, C)
87-
# with open(outfolder + '/chemical_out.csv', 'w', newline='') as csvfile:
88+
# with open(outfolder / 'chemical_out.csv', 'w', newline='') as csvfile:
8889

8990
if MPI.COMM_WORLD.rank == 0:
90-
csvfile = open(outfolder + '/chemical_out.csv', 'w', newline='')
91+
csvfile = open(outfolder / 'chemical_out.csv', 'w', newline='')
9192
writer = csv.writer(csvfile, delimiter=' ', quotechar='|',
9293
quoting=csv.QUOTE_MINIMAL)
9394

channel-transport-reaction/fluid-fenics/fluid.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
from mshr import *
1212
import fenicsprecice
1313
import numpy as np
14+
from pathlib import Path
1415

15-
outfolder = 'output'
16+
outfolder = Path(__file__).parent / 'output'
1617

1718
# time step size (preCICE handles the main loop; if this is smaller than
1819
# preCICE dt, we subcycle)
@@ -117,7 +118,7 @@ def inside(self, x, on_boundary):
117118
return True
118119

119120

120-
precice = fenicsprecice.Adapter(adapter_config_filename="fluid-config.json")
121+
precice = fenicsprecice.Adapter(adapter_config_filename=Path(__file__).parent / "fluid-config.json")
121122
precice.initialize(coupling_subdomain=CouplingDomain(), write_object=u_)
122123
precice_dt = precice.get_max_time_step_size()
123124

@@ -127,7 +128,7 @@ def inside(self, x, on_boundary):
127128
# No implicit coupling supported, as this is uni-directional coupling
128129
# If needed, implement checkpointing
129130
t = 0
130-
vtkfile = File(outfolder + '/chemical_fluid_write.pvd')
131+
vtkfile = File(str(outfolder / 'chemical_fluid_write.pvd'))
131132

132133
while precice.is_coupling_ongoing():
133134

0 commit comments

Comments
 (0)