Skip to content

Commit

Permalink
all open statements and file paths use os.path.join
Browse files Browse the repository at this point in the history
updated post
  • Loading branch information
muddi900 committed Jan 4, 2023
1 parent 8816a9b commit 2fe178a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions pyelmer/elmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def write_boundary_ids(self, simulation_dir):
simulation_dir (str): Path of simulation directory
"""
data = {boundary.id: name for name, boundary in self.boundaries.items()}
with open(simulation_dir + "/boundaries.yml", "w") as f:
with open(os.path.join(simulation_dir + "/boundaries.yml"), "w") as f:
yaml.dump(data, f, sort_keys=False)

def _dict_to_str(self, dictionary, *, key_value_separator=" = "):
Expand Down Expand Up @@ -425,7 +425,7 @@ def load_simulation(name, setup_file=""):
Simulation object.
"""
if setup_file == "":
setup_file = f"{data_dir}/simulations.yml"
setup_file = os.path.join(data_dir, "simulations.yml")
with open(setup_file) as f:
settings = yaml.safe_load(f)[name]
sim = Simulation()
Expand All @@ -445,7 +445,7 @@ def load_material(name, simulation, setup_file=""):
Material object.
"""
if setup_file == "":
setup_file = f"{data_dir}/materials.yml"
setup_file = os.path.join(data_dir, "materials.yml")
with open(setup_file) as f:
data = yaml.safe_load(f)[name]
return Material(simulation, name, data)
Expand All @@ -463,7 +463,7 @@ def load_solver(name, simulation, setup_file=""):
Solver object.
"""
if setup_file == "":
setup_file = f"{data_dir}/solvers.yml"
setup_file = os.path.join(data_dir, "solvers.yml")
with open(setup_file) as f:
data = yaml.safe_load(f)[name]
return Solver(simulation, name, data)
Expand All @@ -481,7 +481,7 @@ def load_boundary(name, simulation, setup_file=""):
Boundary object.
"""
if setup_file == "":
setup_file = f"{data_dir}/boundaries.yml"
setup_file = os.path.join(data_dir, "boundaries.yml")
with open(setup_file) as f:
data = yaml.safe_load(f)[name]
return Boundary(simulation, name, data=data)
Expand All @@ -499,7 +499,7 @@ def load_initial_condition(name, simulation, setup_file=""):
InitialCondition object.
"""
if setup_file == "":
setup_file = f"{data_dir}/initial_conditions.yml"
setup_file = os.path.join(data_dir, "initial_conditions.yml")
with open(setup_file) as f:
data = yaml.safe_load(f)[name]
return InitialCondition(simulation, name, data)
Expand Down
4 changes: 2 additions & 2 deletions pyelmer/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def run_elmer_grid(sim_dir, meshfile, elmergrid=None):
elmergrid = "ElmerGrid"

args = [elmergrid, "14", "2", meshfile]
with open(sim_dir + "/elmergrid.log", "w") as f:
with open(os.path.join(sim_dir, "elmergrid.log"), "w") as f:
subprocess.run(args, cwd=sim_dir, stdout=f, stderr=f)

mesh_dir = sim_dir + "/" + ".".join(meshfile.split(".")[:-1])
Expand Down Expand Up @@ -72,7 +72,7 @@ def run_elmer_solver(sim_dir, elmersolver=None):
elmersolver = "ElmerSolver"

args = [elmersolver, "case.sif"]
with open(sim_dir + "/elmersolver.log", "w") as f:
with open(os.path.join(sim_dir, "elmersolver.log"), "w") as f:
subprocess.run(args, cwd=sim_dir, stdout=f, stderr=f)


Expand Down
4 changes: 2 additions & 2 deletions pyelmer/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def scan_logfile(sim_dir):
Returns:
list[str], list[str], dict: error messages, warnings, statistics
"""
with open(sim_dir + "/elmersolver.log", "r") as f:
with open(os.path.join(sim_dir, "elmersolver.log"), "r") as f:
log = f.readlines()
for i in range(len(log)):
log[i] = log[i][:-1]
Expand Down Expand Up @@ -92,7 +92,7 @@ def plot_residuals(sim_dir, solvers, save=False):
solvers (list): solvers to analyze - currently works only for
'heat equation' and 'statmagsolver'
"""
with open(sim_dir + "/elmersolver.log", "r") as f:
with open(os.path.join(sim_dir, "elmersolver.log"), "r") as f:
log = f.readlines()
for i in range(len(log)):
log[i] = log[i][:-1]
Expand Down
12 changes: 6 additions & 6 deletions pyelmer/test/test_elmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_equation():


def test_load_simulation():
with open(file_dir + "/test_data/simulations.yml") as f:
with open(os.path.join(file_dir, "test_data", "simulations.yml") as f:
settings = yaml.safe_load(f)["test_simulation"]
assert (
elmer.load_simulation(
Expand All @@ -170,7 +170,7 @@ def test_load_simulation():


def test_load_material():
with open(file_dir + "/test_data/materials.yml") as f:
with open(os.path.join(file_dir, "test_data", "materials.yml") as f:
data = yaml.safe_load(f)["test_material"]
sim = elmer.Simulation()
assert (
Expand All @@ -182,7 +182,7 @@ def test_load_material():


def test_load_solver():
with open(file_dir + "/test_data/solvers.yml") as f:
with open(os.path.join(file_dir, "test_data", "solvers.yml") as f:
data = yaml.safe_load(f)["test_solver"]
sim = elmer.Simulation()
assert (
Expand All @@ -194,7 +194,7 @@ def test_load_solver():


def test_load_body_force():
with open(file_dir + "/test_data/body_forces.yml") as f:
with open(os.path.join(file_dir, "test_data", "body_forces.yml") as f:
data = yaml.safe_load(f)["test_body_force"]
sim = elmer.Simulation()
assert (
Expand All @@ -206,7 +206,7 @@ def test_load_body_force():


def test_load_boundary():
with open(file_dir + "/test_data/boundaries.yml") as f:
with open(os.path.join(file_dir, "test_data", "boundaries.yml") as f:
data = yaml.safe_load(f)["test_boundary"]
sim = elmer.Simulation()
assert elmer.load_boundary(
Expand All @@ -218,7 +218,7 @@ def test_load_boundary():


def test_load_initial_condition():
with open(file_dir + "/test_data/initial_conditions.yml") as f:
with open(os.path.join(file_dir, "test_data", "initial_conditions.yml") as f:
data = yaml.safe_load(f)["test_initial_condition"]
sim = elmer.Simulation()
assert (
Expand Down

0 comments on commit 2fe178a

Please sign in to comment.