Skip to content

Simplify code of oscillator #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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