Skip to content

Commit

Permalink
Fix format.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminRodenberg committed Oct 25, 2023
1 parent 2f5f35e commit 91ff400
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
25 changes: 17 additions & 8 deletions partitioned-heat-conduction/doConvergenceStudy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def render(precice_config_params):
file.write(precice_config_template.render(precice_config_params))


def do_run(dt, n_substeps = 1, polynomial_degree = 1, error_tol=10e-3, precice_config_params=default_precice_config_params):
def do_run(dt, n_substeps=1, polynomial_degree=1, error_tol=10e-3, precice_config_params=default_precice_config_params):
time_window_size = dt
time_step_size = time_window_size / n_substeps

Expand All @@ -42,19 +42,27 @@ def do_run(dt, n_substeps = 1, polynomial_degree = 1, error_tol=10e-3, precice_c
participants = [
{
"name": "Dirichlet",
"cmd":"-d",
"cmd": "-d",
},
{
"name": "Neumann",
"cmd":"-n",
"cmd": "-n",
},
]

for participant in participants: participant['logfile'] = f"stdout-{participant['name']}.log"
for participant in participants:
participant['logfile'] = f"stdout-{participant['name']}.log"

for participant in participants:
with open(fenics / participant['logfile'], "w") as outfile:
p = subprocess.Popen(["python3", fenics / "heat.py", participant["cmd"], f"-e {error_tol}", f"-s {n_substeps}", f"-p {polynomial_degree}"], cwd=fenics, stdout=outfile)
p = subprocess.Popen(["python3",
fenics / "heat.py",
participant["cmd"],
f"-e {error_tol}",
f"-s {n_substeps}",
f"-p {polynomial_degree}"],
cwd=fenics,
stdout=outfile)
participant["proc"] = p

for participant in participants:
Expand Down Expand Up @@ -97,7 +105,8 @@ def do_run(dt, n_substeps = 1, polynomial_degree = 1, error_tol=10e-3, precice_c

for dt in dts:
for n in substeps:
summary = do_run(dt, n_substeps=n, polynomial_degree=polynomial_degree, error_tol=10e10, precice_config_params=precice_config_params)
summary = do_run(dt, n_substeps=n, polynomial_degree=polynomial_degree,
error_tol=10e10, precice_config_params=precice_config_params)
df = pd.concat([df, pd.DataFrame(summary, index=[0])], ignore_index=True)

print(f"Write preliminary output to {summary_file}")
Expand All @@ -119,7 +128,7 @@ def do_run(dt, n_substeps = 1, polynomial_degree = 1, error_tol=10e-3, precice_c
if repo.is_dirty():
chash += "-dirty"

metadata={
metadata = {
"git repository": repo.remotes.origin.url,
"git commit": chash,
"precice_config_params": precice_config_params,
Expand All @@ -134,4 +143,4 @@ def do_run(dt, n_substeps = 1, polynomial_degree = 1, error_tol=10e-3, precice_c

print('-' * term_size.columns)
print(df)
print('-' * term_size.columns)
print('-' * term_size.columns)
16 changes: 13 additions & 3 deletions partitioned-heat-conduction/fenics/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def determine_gradient(V_g, u, flux):
command_group.add_argument("-d", "--dirichlet", help="create a dirichlet problem", dest="dirichlet",
action="store_true")
command_group.add_argument("-n", "--neumann", help="create a neumann problem", dest="neumann", action="store_true")
parser.add_argument("-s", "--n-substeps", help="Number of substeps in one window for this participant", type=int, default=1)
parser.add_argument(
"-s",
"--n-substeps",
help="Number of substeps in one window for this participant",
type=int,
default=1)
parser.add_argument("-p", "--polynomial-order", help="Polynomial order of manufactured solution", type=int, default=1)
parser.add_argument("-e", "--error-tol", help="set error tolerance", type=float, default=10**-6,)

Expand Down Expand Up @@ -120,7 +125,12 @@ def determine_gradient(V_g, u, flux):
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f_manufactured = - sp.diff(sp.diff(u_manufactured, symbols['x']), symbols['x']) - sp.diff(sp.diff(u_manufactured, symbols['y']), symbols['y']) + sp.diff(u_manufactured, symbols['t'])
f_manufactured = - sp.diff(sp.diff(u_manufactured,
symbols['x']),
symbols['x']) - sp.diff(sp.diff(u_manufactured,
symbols['y']),
symbols['y']) + sp.diff(u_manufactured,
symbols['t'])
f = Expression(sp.printing.ccode(f_manufactured), degree=2, t=0)
F = u * v / dt * dx + dot(grad(u), grad(v)) * dx - (u_n / dt + f) * v * dx

Expand Down Expand Up @@ -256,4 +266,4 @@ def determine_gradient(V_g, u, flux):

with open(errors_csv, 'a') as f:
f.write(f"{metadata}")
df.to_csv(f)
df.to_csv(f)
4 changes: 2 additions & 2 deletions partitioned-heat-conduction/fenics/problem_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_manufactured_solution(time_dependence, alpha, beta, p=-1):
x, y, t = sp.symbols('x[0], x[1], t')
# Define analytical solution
if time_dependence == TimeDependence.POLYNOMIAL:
assert(p > -1)
assert (p > -1)
g = (t + 1)**p
elif time_dependence == TimeDependence.TRIGONOMETRIC:
g = 1 + sp.sin(t)
Expand All @@ -65,4 +65,4 @@ def get_manufactured_solution(time_dependence, alpha, beta, p=-1):

manufactured_solution = 1 + g * x**2 + alpha * y**2 + beta * t
print("manufactured solution = {}".format(manufactured_solution))
return manufactured_solution, {'x':x, 'y':y, 't':t}
return manufactured_solution, {'x': x, 'y': y, 't': t}

0 comments on commit 91ff400

Please sign in to comment.