From 855ce6159e0370827f60d1c02f14e75c9be3a4c5 Mon Sep 17 00:00:00 2001 From: Benjamin Rodenberg Date: Thu, 28 Nov 2024 07:34:50 +0100 Subject: [PATCH] Simplify code of oscillator and oscillator-overlap (#598) * Remove temporary and unused variables * Fix types * Add mypy.ini in oscillator-overlap --- oscillator-overlap/solver-python/oscillator.py | 16 +++++----------- oscillator/solver-python/oscillator.py | 16 +++++----------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/oscillator-overlap/solver-python/oscillator.py b/oscillator-overlap/solver-python/oscillator.py index 75b4106bc..02b8ddb14 100644 --- a/oscillator-overlap/solver-python/oscillator.py +++ b/oscillator-overlap/solver-python/oscillator.py @@ -59,9 +59,7 @@ class Participant(Enum): mass = this_mass.m stiffness = this_spring.k + connecting_spring.k -u0, v0, f0, d_dt_f0 = this_mass.u0, this_mass.v0, connecting_spring.k * other_mass.u0, connecting_spring.k * other_mass.v0 - -num_vertices = 1 # Number of vertices +u0, v0, f0 = this_mass.u0, this_mass.v0, connecting_spring.k * other_mass.u0 solver_process_index = 0 solver_process_size = 1 @@ -73,13 +71,10 @@ class Participant(Enum): dimensions = participant.get_mesh_dimensions(mesh_name) vertex = np.zeros(dimensions) -read_data = np.zeros(num_vertices) -write_data = u0 * np.ones(num_vertices) - vertex_ids = [participant.set_mesh_vertex(mesh_name, vertex)] if participant.requires_initial_data(): - participant.write_data(mesh_name, write_data_name, vertex_ids, write_data) + participant.write_data(mesh_name, write_data_name, vertex_ids, np.array([u0])) participant.initialize() precice_dt = participant.get_max_time_step_size() @@ -151,13 +146,12 @@ def f(t: float) -> float: return connecting_spring.k * \ # perform n_pseudo pseudosteps dt_pseudo = dt / n_pseudo t_pseudo += dt_pseudo - write_data = np.array([time_stepper.dense_output(t_pseudo)[0]]) - participant.write_data(mesh_name, write_data_name, vertex_ids, write_data) + u_pseudo = time_stepper.dense_output(t_pseudo)[0] + participant.write_data(mesh_name, write_data_name, vertex_ids, np.array([u_pseudo])) participant.advance(dt_pseudo) else: # simple time stepping without dense output; only a single write call per time step - write_data = np.array([u_new]) - participant.write_data(mesh_name, write_data_name, vertex_ids, write_data) + participant.write_data(mesh_name, write_data_name, vertex_ids, np.array([u_new])) participant.advance(dt) if participant.requires_reading_checkpoint(): diff --git a/oscillator/solver-python/oscillator.py b/oscillator/solver-python/oscillator.py index 7550b13c8..9a6c1c304 100644 --- a/oscillator/solver-python/oscillator.py +++ b/oscillator/solver-python/oscillator.py @@ -59,9 +59,7 @@ class Participant(Enum): mass = this_mass.m stiffness = this_spring.k + connecting_spring.k -u0, v0, f0, d_dt_f0 = this_mass.u0, this_mass.v0, connecting_spring.k * other_mass.u0, connecting_spring.k * other_mass.v0 - -num_vertices = 1 # Number of vertices +u0, v0, f0 = this_mass.u0, this_mass.v0, connecting_spring.k * other_mass.u0 solver_process_index = 0 solver_process_size = 1 @@ -73,13 +71,10 @@ class Participant(Enum): dimensions = participant.get_mesh_dimensions(mesh_name) vertex = np.zeros(dimensions) -read_data = np.zeros(num_vertices) -write_data = connecting_spring.k * u0 * np.ones(num_vertices) - vertex_ids = [participant.set_mesh_vertex(mesh_name, vertex)] if participant.requires_initial_data(): - participant.write_data(mesh_name, write_data_name, vertex_ids, write_data) + participant.write_data(mesh_name, write_data_name, vertex_ids, connecting_spring.k * np.array([u0])) participant.initialize() precice_dt = participant.get_max_time_step_size() @@ -150,13 +145,12 @@ def f(t: float) -> float: return participant.read_data(mesh_name, read_data_name # perform n_pseudo pseudosteps dt_pseudo = dt / n_pseudo t_pseudo += dt_pseudo - write_data = np.array([connecting_spring.k * time_stepper.dense_output(t_pseudo)[0]]) - participant.write_data(mesh_name, write_data_name, vertex_ids, write_data) + u_pseudo = time_stepper.dense_output(t_pseudo)[0] + participant.write_data(mesh_name, write_data_name, vertex_ids, connecting_spring.k * np.array([u_pseudo])) participant.advance(dt_pseudo) else: # simple time stepping without dense output; only a single write call per time step - write_data = np.array([connecting_spring.k * u_new]) - participant.write_data(mesh_name, write_data_name, vertex_ids, write_data) + participant.write_data(mesh_name, write_data_name, vertex_ids, connecting_spring.k * np.array([u_new])) participant.advance(dt) if participant.requires_reading_checkpoint():