diff --git a/partitioned-heat-conduction/doConvergenceStudy.py b/partitioned-heat-conduction/doConvergenceStudy.py index 6c9668fff..1930a55bd 100644 --- a/partitioned-heat-conduction/doConvergenceStudy.py +++ b/partitioned-heat-conduction/doConvergenceStudy.py @@ -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 @@ -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: @@ -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}") @@ -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, @@ -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) \ No newline at end of file + print('-' * term_size.columns) diff --git a/partitioned-heat-conduction/fenics/heat.py b/partitioned-heat-conduction/fenics/heat.py index 2a21e78d3..2d2128487 100644 --- a/partitioned-heat-conduction/fenics/heat.py +++ b/partitioned-heat-conduction/fenics/heat.py @@ -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,) @@ -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 @@ -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) \ No newline at end of file + df.to_csv(f) diff --git a/partitioned-heat-conduction/fenics/problem_setup.py b/partitioned-heat-conduction/fenics/problem_setup.py index f9274a87a..b96443254 100644 --- a/partitioned-heat-conduction/fenics/problem_setup.py +++ b/partitioned-heat-conduction/fenics/problem_setup.py @@ -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) @@ -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}