Skip to content
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

Fix subcycling #443

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 2 additions & 3 deletions channel-transport/fluid-nutils/fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ def main():
data_name = "Velocity"

participant.initialize()
precice_dt = participant.get_max_time_step_size()

timestep = 0
dt = 0.005
solver_dt = 0.005

state = solver.solve_linear(("u", "p"), (ures, pres), constrain=cons) # initial condition

Expand All @@ -87,7 +86,7 @@ def main():
precice_dt = participant.get_max_time_step_size()

# potentially adjust non-matching timestep sizes
dt = min(dt, precice_dt)
dt = min(solver_dt, precice_dt)

# solve Nutils timestep
state["u0"] = state["u"]
Expand Down
5 changes: 2 additions & 3 deletions channel-transport/transport-nutils/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ def main():
data_name = "Velocity"

participant.initialize()
precice_dt = participant.get_max_time_step_size()

timestep = 0
dt = 0.005
solver_dt = 0.005

# set blob as initial condition
sqr = domain.integral("(u - uinit)^2" @ ns, degree=2)
Expand All @@ -85,7 +84,7 @@ def main():
precice_dt = participant.get_max_time_step_size()

# potentially adjust non-matching timestep sizes
dt = min(dt, precice_dt)
dt = min(solver_dt, precice_dt)

# read velocity values from participant
velocity_values = participant.read_data(mesh_name, data_name, vertex_ids, dt)
Expand Down
22 changes: 10 additions & 12 deletions flow-over-heated-plate/solid-nutils/solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)
cons0 = cons # to not lose the Dirichlet BC at the bottom
lhs0 = np.zeros(res.shape) # solution from previous timestep
timestep = 0
dt = 0.01
solver_dt = 0.01

participant.initialize()
precice_dt = participant.get_max_time_step_size()
dt = min(dt, precice_dt)

# set u = uwall as initial condition and visualize
sqr = domain.integral('(u - uwall)^2' @ ns, degree=2)
Expand All @@ -68,20 +66,21 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)

while participant.is_coupling_ongoing():

# read temperature from participant
temperature_values = participant.read_data(mesh_name, "Temperature", vertex_ids, dt)
temperature_function = coupling_sample.asfunction(temperature_values)

sqr = coupling_sample.integral((ns.u - temperature_function)**2)
cons = solver.optimize('lhs', sqr, droptol=1e-15, constrain=cons0)

# save checkpoint
if participant.requires_writing_checkpoint():
lhs_checkpoint = lhs0
timestep_checkpoint = timestep

# potentially adjust non-matching timestep sizes
dt = min(dt, precice_dt)
precice_dt = participant.get_max_time_step_size()
dt = min(solver_dt, precice_dt)

# read temperature from participant
temperature_values = participant.read_data(mesh_name, "Temperature", vertex_ids, dt)
temperature_function = coupling_sample.asfunction(temperature_values)

sqr = coupling_sample.integral((ns.u - temperature_function)**2)
cons = solver.optimize('lhs', sqr, droptol=1e-15, constrain=cons0)

# solve nutils timestep
lhs = solver.solve_linear('lhs', res, constrain=cons, arguments=dict(lhs0=lhs0, dt=dt))
Expand All @@ -93,7 +92,6 @@ def fluxdofs(v): return projection_matrix.solve(v, constrain=projection_cons)

# do the coupling
participant.advance(dt)
precice_dt = participant.get_max_time_step_size()

# advance variables
timestep += 1
Expand Down
13 changes: 5 additions & 8 deletions partitioned-heat-conduction-direct/nutils/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.2):
participant.set_mesh_access_region(mesh_name_write, [.9, 1.1, -.1, 1.1])

participant.initialize()
precice_dt = participant.get_max_time_step_size()
dt = min(timestep, precice_dt)

vertex_ids_write, coords = participant.get_mesh_vertex_ids_and_coordinates(mesh_name_write)
write_sample = domain.locate(ns.x, coords, eps=1e-10, tol=1e-10)
Expand Down Expand Up @@ -106,15 +104,16 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.2):
if participant.requires_writing_checkpoint():
checkpoint = lhs, t, istep

# read data from participant
read_data = precice_read(dt)

# prepare next timestep
precice_dt = participant.get_max_time_step_size()
dt = min(timestep, precice_dt)
lhs0 = lhs
istep += 1
dt = min(timestep, precice_dt)
t += dt

# read data from participant
read_data = precice_read(dt)

# update (time-dependent) boundary condition
cons = solver.optimize('lhs', sqr, droptol=1e-15, arguments=dict(t=t, readdata=read_data))

Expand All @@ -133,8 +132,6 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.2):

# do the coupling
participant.advance(dt)
precice_dt = participant.get_max_time_step_size()
dt = min(timestep, precice_dt)

# read checkpoint if required
if participant.requires_reading_checkpoint():
Expand Down
12 changes: 4 additions & 8 deletions partitioned-heat-conduction/nutils/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.2):
precice_write(coupling_sample.eval(0.))

participant.initialize()
precice_dt = participant.get_max_time_step_size()
dt = min(timestep, precice_dt)

t = 0.
istep = 0
Expand All @@ -128,17 +126,17 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.2):
if not participant.is_coupling_ongoing():
break

# read data from participant
readdata = precice_read(dt)

# save checkpoint
if participant.requires_writing_checkpoint():
checkpoint = lhs, t, istep

# prepare next timestep
precice_dt = participant.get_max_time_step_size()
dt = min(timestep, precice_dt)
lhs0 = lhs
istep += 1
dt = min(timestep, precice_dt)
# read data from participant
readdata = precice_read(dt)
t += dt

# update (time-dependent) boundary condition
Expand Down Expand Up @@ -168,8 +166,6 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.2):

# do the coupling
participant.advance(dt)
precice_dt = participant.get_max_time_step_size()
dt = min(timestep, precice_dt)

# read checkpoint if required
if participant.requires_reading_checkpoint():
Expand Down
7 changes: 3 additions & 4 deletions perpendicular-flap/fluid-nutils/fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ def main(inflow: 'inflow velocity' = 10,

# initialize preCICE
participant.initialize()
precice_dt = participant.get_max_time_step_size()
dt = min(precice_dt, timestepsize)

# boundary conditions for fluid equations
sqr = domain.boundary['wall,flap'].integral('urel_k urel_k d:x0' @ ns, degree=4)
Expand Down Expand Up @@ -162,6 +160,9 @@ def main(inflow: 'inflow velocity' = 10,

while participant.is_coupling_ongoing():

precice_dt = participant.get_max_time_step_size()
dt = min(precice_dt, timestepsize)

# read displacements from participant
readdata = participant.read_data(meshName, readDataName, dataIndices, dt)
coupledata = couplingsample.asfunction(readdata)
Expand Down Expand Up @@ -197,8 +198,6 @@ def main(inflow: 'inflow velocity' = 10,

# do the coupling
participant.advance(dt)
precice_dt = participant.get_max_time_step_size()
dt = min(precice_dt, timestepsize)

# advance variables
timestep += 1
Expand Down
7 changes: 4 additions & 3 deletions two-scale-heat-conduction/macro-nutils/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main():
participant.write_data(mesh_name, "concentration", vertex_ids, concentrations)

participant.initialize()
dt = participant.get_max_time_step_size()
dt = solver_dt = participant.get_max_time_step_size()
else:
dt = 1.0E-2

Expand Down Expand Up @@ -105,6 +105,9 @@ def main():
t_checkpoint = t
n_checkpoint = n

precice_dt = participant.get_max_time_step_size()
dt = min(precice_dt, solver_dt)

# Read porosity and apply it to the existing solution
poro_data = participant.read_data(mesh_name, "porosity", vertex_ids, dt)
poro_coupledata = couplingsample.asfunction(poro_data)
Expand All @@ -130,8 +133,6 @@ def main():
participant.write_data(mesh_name, "concentration", vertex_ids, concentration)

participant.advance(dt)
precice_dt = participant.get_max_time_step_size()
dt = min(precice_dt, dt)

n += 1
t += dt
Expand Down
5 changes: 2 additions & 3 deletions volume-coupled-flow/source-nutils/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ def main():
data_name = "Velocity"

participant.initialize()
precice_dt = participant.get_max_time_step_size()

timestep = 0
dt = 0.005
solver_dt = 0.005

while participant.is_coupling_ongoing():

precice_dt = participant.get_max_time_step_size()

# potentially adjust non-matching timestep sizes
dt = min(dt, precice_dt)
dt = min(solver_dt, precice_dt)

participant.write_data(mesh_name, data_name, vertex_ids, source_values)
# do the coupling
Expand Down
Loading