Skip to content

Commit

Permalink
Simplify code of oscillator and oscillator-overlap (#598)
Browse files Browse the repository at this point in the history
* Remove temporary and unused variables
* Fix types
* Add mypy.ini in oscillator-overlap
  • Loading branch information
BenjaminRodenberg authored Nov 28, 2024
1 parent 4ded055 commit 855ce61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
16 changes: 5 additions & 11 deletions oscillator-overlap/solver-python/oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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():
Expand Down
16 changes: 5 additions & 11 deletions oscillator/solver-python/oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 855ce61

Please sign in to comment.