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

Sc/converters coupling #1558

Merged
merged 146 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
bb07419
Added coupling converters.
SimonCan Jun 26, 2023
95892bf
Added generic converter_function for structured 2d meshes.
SimonCan Jun 29, 2023
4e82276
Added example elixir for coupling converters.
SimonCan Jul 3, 2023
7355ed0
Cleaned up converter coupling elixir.
SimonCan Jul 3, 2023
b8cabf4
Added equations in coupling converters.
SimonCan Jul 3, 2023
6d521a7
Added converter functions.
SimonCan Jul 4, 2023
ab8e750
Added identity converter function.
SimonCan Jul 4, 2023
24773c7
Autoformat for converter coupling implementation.
SimonCan Jul 5, 2023
c7da2cc
Added coupled converter elixir.
SimonCan Jul 5, 2023
98bf2cf
Corrected file name of coupled converters test.
SimonCan Jul 5, 2023
79da4e9
Merge branch 'main' into sc/converters_coupling
sloede Jul 11, 2023
d97302d
Removed redundant doc string.
SimonCan Jul 18, 2023
4a22bfe
Added function signature in doc string.
SimonCan Jul 18, 2023
f1f6ee8
Removed coverage_override in coupled tests.
SimonCan Jul 18, 2023
7a7def0
Removed old commented code.
SimonCan Jul 18, 2023
9045c5d
Update make.jl
SimonCan Jul 19, 2023
31cf07f
Update make.jl
SimonCan Jul 19, 2023
2f19315
Create coupling.md
SimonCan Jul 19, 2023
26d8dd3
Update coupling.md
SimonCan Jul 19, 2023
05579d1
Removed troublesome AnalysisCallbackCoupled from test.
SimonCan Jul 20, 2023
84c872e
Chenged coupling converter function.
SimonCan Jul 20, 2023
78f9948
Changed coupling converter function and updated tests.
SimonCan Jul 20, 2023
2e35046
Sepcialized coupling function call.
SimonCan Jul 24, 2023
6bc7c3b
Removed volume coupling from documentation to avoit confusion.
SimonCan Jul 25, 2023
b4decb7
Update src/coupling_converters/coupling_converters.jl
SimonCan Jul 25, 2023
54d8180
Removed redundant converter function for coupling.
SimonCan Jul 25, 2023
160c7bf
Removed redundant coupling converter file mentioned in some files.
SimonCan Jul 25, 2023
8a2187a
Merge branch 'sc/converters_coupling' of github.com:trixi-framework/T…
SimonCan Jul 25, 2023
cab33c2
Autoreformatted.
SimonCan Jul 25, 2023
024106c
Removed old coupled elixir and replaced it with one using converter f…
SimonCan Jul 25, 2023
5c93324
Merge branch 'main' into sc/converters_coupling
SimonCan Jul 28, 2023
c6d6da6
Updated errors for coupled tests.
SimonCan Aug 1, 2023
62d1408
Corrected test results for coupled equations.
SimonCan Aug 1, 2023
09fd691
Corrected comment.
SimonCan Aug 2, 2023
df67f00
Removed coupled test from special tests.
SimonCan Aug 2, 2023
35980a1
Removed coupled test from specials.
SimonCan Aug 2, 2023
aac8430
Chaned the coupling function to the identity.
SimonCan Aug 2, 2023
eaeec5b
Updated coupling tests.
SimonCan Aug 2, 2023
f161938
Updated errors for coupled test.
SimonCan Aug 3, 2023
fe5312b
Merge branch 'main' into sc/converters_coupling
SimonCan Aug 16, 2023
569da04
Added advice about binary compatability for coupled equations in the …
SimonCan Sep 7, 2023
ab417e7
Merge branch 'main' into sc/converters_coupling
SimonCan Sep 19, 2023
93fc571
Typo.
SimonCan Sep 19, 2023
fac0410
Merge branch 'main' into sc/converters_coupling
SimonCan Sep 28, 2023
00e5150
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 2, 2023
b42d753
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 4, 2023
d3334a8
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 4, 2023
ed1fec9
Added numerical fluxes.
SimonCan Oct 5, 2023
3ea484d
Corrected rs copy routine. Now loop over this semi's components.
SimonCan Oct 6, 2023
e5a5dfb
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 9, 2023
c87095e
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 10, 2023
bfd4ec1
Reformatted equations source file.
SimonCan Oct 11, 2023
5ff438a
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 12, 2023
f3e1ee6
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 13, 2023
c4bc8b3
Removed problemating include of time_integration.jl.
SimonCan Oct 16, 2023
cdd984a
Removed export of deleted methods.
SimonCan Oct 16, 2023
4668b26
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 18, 2023
e572ac0
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 19, 2023
6eb92b6
Reverted to old version of compressible Euler multicomponent with no …
SimonCan Oct 20, 2023
8d26189
Renamed documentation file for multi-physics coupling.
SimonCan Oct 20, 2023
afbcc9d
Renamed doc reference.
SimonCan Oct 20, 2023
e730c9a
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Oct 20, 2023
29f82f9
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 20, 2023
2747e85
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 24, 2023
1cbed94
Update docs/src/multi-physics_coupling.md
SimonCan Oct 24, 2023
fefbe59
Update docs/src/multi-physics_coupling.md
SimonCan Oct 24, 2023
f9ab642
Update docs/src/multi-physics_coupling.md
SimonCan Oct 24, 2023
b1f63dc
Reinstated structured_2d_dgsem coupled in special tests.
SimonCan Oct 24, 2023
4c3254b
Update examples/structured_2d_dgsem/elixir_advection_coupled.jl
SimonCan Oct 24, 2023
64e8dda
Renamed CouplingFunction to CouplingConverter.
SimonCan Oct 24, 2023
bd59f72
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Oct 24, 2023
2331cc1
Cleaned the copy of coupled boundary values.
SimonCan Oct 24, 2023
35bffba
Reduced time span for example coupling elixir.
SimonCan Oct 24, 2023
488cef8
Removed redundant loop.
SimonCan Oct 24, 2023
81a10d0
Applied formatter.
SimonCan Oct 24, 2023
f407e1a
git pushMerge branch 'sc/converters_coupling' of github.com:trixi-fra…
SimonCan Oct 24, 2023
0579dc1
Removed default coupling covnerter function.
SimonCan Oct 24, 2023
baf28fd
Moved coupling converter function into elixir.
SimonCan Oct 24, 2023
7c3d558
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 24, 2023
a4971a5
Apply suggestions from code review
sloede Oct 25, 2023
3491b1a
Update docs/make.jl
sloede Oct 25, 2023
0ff77e2
Removed coupling_converters.jl from the include.
SimonCan Oct 25, 2023
1993560
Corrected introduced issue with coupling boundary copy.
SimonCan Oct 25, 2023
d5129e2
Corrected comment on final simulation time.
SimonCan Oct 25, 2023
21f203f
Updated errors for coupled test to reflect changed final simulation t…
SimonCan Oct 25, 2023
fe4b216
Merge branch 'main' into sc/converters_coupling
SimonCan Oct 25, 2023
4f92bc6
Added miladd.
SimonCan Oct 30, 2023
8789c4b
Corrected coordinate finding in semidiscretization_coupled.
SimonCan Nov 3, 2023
87609bc
Fixed issued related to memory allocation.
SimonCan Nov 3, 2023
2906208
Corrected loop over semidiscretization.
SimonCan Nov 3, 2023
9ee224f
Removed commented out code.
SimonCan Nov 3, 2023
329cbf6
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 6, 2023
dd847e4
Fixed type instability with loops over semidiscretizations using
SimonCan Nov 7, 2023
a54a9e8
Removed obsolete code.
SimonCan Nov 8, 2023
eb14606
Fixed another typa instability in coupled semidiscretization.
SimonCan Nov 8, 2023
20a1676
Cleaning up of the coupled semidiscretization.
SimonCan Nov 8, 2023
58ec8fb
Autoformatted coupled semidiscretization.
SimonCan Nov 8, 2023
52fcb5b
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 8, 2023
ee197c1
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 9, 2023
6886bff
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 13, 2023
49b121e
Fixed last type instability in coupling.
SimonCan Nov 14, 2023
3b5d492
Autoformatter on semidiscretization.
SimonCan Nov 14, 2023
538e401
Fixed bug in boundary values copy that arose when coupling multiple s…
SimonCan Nov 15, 2023
e6b621a
aplpied autoformatter on coupled semidiscretization.
SimonCan Nov 15, 2023
9da5c9f
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 16, 2023
03f7696
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 17, 2023
8b6f7b3
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 20, 2023
cf262a8
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 21, 2023
6737a43
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 23, 2023
2a7fea3
Extended the structured 2d example elixir for the coupled advection
SimonCan Nov 23, 2023
e8c2d52
Updated test results for coupled advection in 2d to reflect
SimonCan Nov 23, 2023
4f76579
Added correct errors for tests for the coupled adveciton equations in…
SimonCan Nov 24, 2023
756eaf1
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 24, 2023
8414741
Merge branch 'main' into sc/converters_coupling
SimonCan Nov 29, 2023
3ea1967
Merge branch 'main' into sc/converters_coupling
SimonCan Dec 4, 2023
824217c
Merge branch 'main' into sc/converters_coupling
SimonCan Dec 8, 2023
418796a
Update examples/structured_2d_dgsem/elixir_advection_coupled.jl
SimonCan Dec 11, 2023
fa4852b
Update examples/structured_2d_dgsem/elixir_advection_coupled.jl
SimonCan Dec 11, 2023
9b55294
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Dec 11, 2023
c830e22
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Dec 11, 2023
e064a56
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Dec 11, 2023
9d8f4e5
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Dec 11, 2023
6c60c3e
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Dec 11, 2023
388a309
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Dec 11, 2023
0e7fd19
Update src/semidiscretization/semidiscretization_coupled.jl
SimonCan Dec 11, 2023
b4493a2
Corrected foreach_enumerate implementation.
SimonCan Dec 11, 2023
98f7eed
Merge branch 'sc/converters_coupling' of github.com:trixi-framework/T…
SimonCan Dec 11, 2023
bbca47e
Merge branch 'main' into sc/converters_coupling
sloede Dec 14, 2023
4753bf5
Merge branch 'main' into sc/converters_coupling
SimonCan Dec 17, 2023
012e01e
Merge branch 'main' into sc/converters_coupling
sloede Dec 19, 2023
34e6fcd
Fix closing parens
sloede Dec 19, 2023
4c2b90b
Remove unused recursive rhs!
sloede Dec 19, 2023
f0911c0
Pass equations to converter function
sloede Dec 19, 2023
dbf2aea
Apply formatting
sloede Dec 19, 2023
307f68a
Merge branch 'main' into sc/converters_coupling
SimonCan Jan 4, 2024
401e835
Reverted copy_to_coupled_boundary to previou version
SimonCan Jan 9, 2024
6472d36
Corrected computation of coupled semidiscretizations and fixed memory…
SimonCan Jan 11, 2024
52f7645
Removed redundant nelements function, as it is no longer used.
SimonCan Jan 15, 2024
dc9dda2
Merge branch 'main' into sc/converters_coupling
SimonCan Jan 15, 2024
9bfc7cc
Applied autoformatter.
SimonCan Jan 15, 2024
26e4c94
Merge branch 'main' into sc/converters_coupling
SimonCan Jan 22, 2024
d313172
Merge branch 'main' into sc/converters_coupling
sloede Jan 29, 2024
2d2194f
Improvements in style and added info about passing equations
SimonCan Jan 30, 2024
05ba222
Merge branch 'main' into sc/converters_coupling
SimonCan Jan 30, 2024
c3e6037
Merge branch 'main' into sc/converters_coupling
sloede Jan 31, 2024
b490cbf
Restored timings in semidiscretization coupled.
SimonCan Jan 31, 2024
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
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ makedocs(
],
"Time integration" => "time_integration.md",
"Callbacks" => "callbacks.md",
"Coupling" => "coupling.md"
sloede marked this conversation as resolved.
Show resolved Hide resolved
],
"Advanced topics & developers" => [
"Conventions" =>"conventions.md",
Expand Down
37 changes: 37 additions & 0 deletions docs/src/multi-physics_coupling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# [Multi-physics coupling](@id multi-physics-coupling)
A complex simulation can consist of different spatial domains in which
different equations are being solved, different numerical methods being used
or the grid structure is different.
One example would be a fluid in a tank and an extended hot plate attached to it.
We would then like to solve the Navier-Stokes equations in the fluid domain
and the heat conduction equations in the plate.
The coupling would happen at the interface through the exchange of thermal energy.


## Converter Coupling
We can have the case where the two systems do not share any variables, but
share some of the physics.
Here, the same physics is just represented in a different form and with
different variables.
This is the case for a fluid system on one side and a Vlasov system on the other.
To translate the fields from one description to the other one needs to use
converter functions.

In the general case, we have a system A with $m$ variables $u_{A,i}$ and another
sloede marked this conversation as resolved.
Show resolved Hide resolved
system B with $n$ variables $u_{B,j}$.
sloede marked this conversation as resolved.
Show resolved Hide resolved
We then define two coupling functions, one that transforms $u_A$ into $u_B$
sloede marked this conversation as resolved.
Show resolved Hide resolved
and one that goes the other way.

In their minimal form they take the position vector $x$ and state vector $u$
sloede marked this conversation as resolved.
Show resolved Hide resolved
and return the transformed variables.
Examples can be seen in `examples/structured_2d_dgsem/elixir_advection_coupled.jl`.


## Warning about binary compatibility
Currently the coordinate values on the nodes can differ by machine precision when
simulating the mesh and when splitting the mesh in multiple domains.
This is an issue coming from the coordinate interpolation on the nodes.
As a result, running a simulation in a single system and in two coupled domains
may result in a difference of the order of the machine precision.
While this is not an issue for most practical problems, it is best to keep this in mind when comparing test runs.

83 changes: 50 additions & 33 deletions examples/structured_2d_dgsem/elixir_advection_coupled.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using OrdinaryDiffEq
using Trixi


###############################################################################
# Coupled semidiscretization of two linear advection systems, which are connected periodically
# Coupled semidiscretization of two linear advection systems using converter functions such that
# the upper half of the domain is coupled periodically, while the lower half is not coupled
# and any incoming wave is completely absorbed.
#
# In this elixir, we have a square domain that is divided into a left half and a right half. On each
# half of the domain, a completely independent SemidiscretizationHyperbolic is created for the
Expand Down Expand Up @@ -35,11 +36,11 @@ advection_velocity = (0.2, -0.7)
equations = LinearScalarAdvectionEquation2D(advection_velocity)

# Create DG solver with polynomial degree = 3 and (local) Lax-Friedrichs/Rusanov flux as surface flux
solver = DGSEM(polydeg=3, surface_flux=flux_lax_friedrichs)
solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs)

# First mesh is the left half of a [-1,1]^2 square
coordinates_min1 = (-1.0, -1.0) # minimum coordinates (min(x), min(y))
coordinates_max1 = ( 0.0, 1.0) # maximum coordinates (max(x), max(y))
coordinates_max1 = (0.0, 1.0) # maximum coordinates (max(x), max(y))

# Define identical resolution as a variable such that it is easier to change from `trixi_include`
cells_per_dimension = (8, 16)
Expand All @@ -48,70 +49,86 @@ cells_per_dimension1 = cells_per_dimension

mesh1 = StructuredMesh(cells_per_dimension1, coordinates_min1, coordinates_max1)

# A semidiscretization collects data structures and functions for the spatial discretization
semi1 = SemidiscretizationHyperbolic(mesh1, equations, initial_condition_convergence_test, solver,
boundary_conditions=(
# Connect left boundary with right boundary of right mesh
x_neg=BoundaryConditionCoupled(2, (:end, :i_forward), Float64),
# Connect right boundary with left boundary of right mesh
x_pos=BoundaryConditionCoupled(2, (:begin, :i_forward), Float64),
y_neg=boundary_condition_periodic,
y_pos=boundary_condition_periodic))
# The user can define their own coupling functions.
coupling_function1 = (x, u) -> u

boundary_conditions_x_neg1 = BoundaryConditionCoupled(2, (:end, :i_forward), Float64,
coupling_function1)
boundary_conditions_x_pos1 = BoundaryConditionCoupled(2, (:begin, :i_forward), Float64,
coupling_function1)

# A semidiscretization collects data structures and functions for the spatial discretization
semi1 = SemidiscretizationHyperbolic(mesh1, equations, initial_condition_convergence_test,
solver,
boundary_conditions = (
# Connect left boundary with right boundary of right mesh
x_neg = boundary_conditions_x_neg1,
# Connect right boundary with left boundary of right mesh
x_pos = boundary_conditions_x_pos1,
y_neg = boundary_condition_periodic,
y_pos = boundary_condition_periodic))

# Second mesh is the right half of a [-1,1]^2 square
coordinates_min2 = (0.0, -1.0) # minimum coordinates (min(x), min(y))
coordinates_max2 = (1.0, 1.0) # maximum coordinates (max(x), max(y))
coordinates_max2 = (1.0, 1.0) # maximum coordinates (max(x), max(y))

cells_per_dimension2 = cells_per_dimension

mesh2 = StructuredMesh(cells_per_dimension2, coordinates_min2, coordinates_max2)

semi2 = SemidiscretizationHyperbolic(mesh2, equations, initial_condition_convergence_test, solver,
boundary_conditions=(
# Connect left boundary with right boundary of left mesh
x_neg=BoundaryConditionCoupled(1, (:end, :i_forward), Float64),
# Connect right boundary with left boundary of left mesh
x_pos=BoundaryConditionCoupled(1, (:begin, :i_forward), Float64),
y_neg=boundary_condition_periodic,
y_pos=boundary_condition_periodic))
coupling_function2 = (x, u) -> u

boundary_conditions_x_neg2 = BoundaryConditionCoupled(1, (:end, :i_forward), Float64,
coupling_function2)
boundary_conditions_x_pos2 = BoundaryConditionCoupled(1, (:begin, :i_forward), Float64,
coupling_function2)

semi2 = SemidiscretizationHyperbolic(mesh2, equations, initial_condition_convergence_test,
solver,
boundary_conditions = (
# Connect left boundary with right boundary of left mesh
x_neg = boundary_conditions_x_neg2,
# Connect right boundary with left boundary of left mesh
x_pos = boundary_conditions_x_pos2,
y_neg = boundary_condition_periodic,
y_pos = boundary_condition_periodic))

# Create a semidiscretization that bundles semi1 and semi2
semi = SemidiscretizationCoupled(semi1, semi2)

###############################################################################
# ODE solvers, callbacks etc.

# Create ODE problem with time span from 0.0 to 2.0
# Create ODE problem with time span from 0.0 to 20.0
ode = semidiscretize(semi, (0.0, 2.0));

# At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup
# and resets the timers
summary_callback = SummaryCallback()

# The AnalysisCallback allows to analyse the solution in regular intervals and prints the results
analysis_callback1 = AnalysisCallback(semi1, interval=100)
analysis_callback2 = AnalysisCallback(semi2, interval=100)
analysis_callback1 = AnalysisCallback(semi1, interval = 100)
analysis_callback2 = AnalysisCallback(semi2, interval = 100)
analysis_callback = AnalysisCallbackCoupled(semi, analysis_callback1, analysis_callback2)

# The SaveSolutionCallback allows to save the solution to a file in regular intervals
save_solution = SaveSolutionCallback(interval=100,
solution_variables=cons2prim)
save_solution = SaveSolutionCallback(interval = 100,
solution_variables = cons2prim)

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
stepsize_callback = StepsizeCallback(cfl=1.6)
stepsize_callback = StepsizeCallback(cfl = 1.6)

# Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver
callbacks = CallbackSet(summary_callback, analysis_callback, save_solution, stepsize_callback)

callbacks = CallbackSet(summary_callback, analysis_callback, save_solution,
stepsize_callback)

###############################################################################
# run the simulation

# OrdinaryDiffEq's `solve` method evolves the solution in time and executes the passed callbacks
sol = solve(ode, CarpenterKennedy2N54(williamson_condition=false),
dt=1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep=false, callback=callbacks);
sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);

# Print the timer summary
summary_callback()
1 change: 1 addition & 0 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ include("time_integration/time_integration.jl")
include("callbacks_step/callbacks_step.jl")
include("callbacks_stage/callbacks_stage.jl")
include("semidiscretization/semidiscretization_euler_gravity.jl")
include("coupling_converters/coupling_converters.jl")

# `trixi_include` and special elixirs such as `convergence_test`
include("auxiliary/special_elixirs.jl")
Expand Down
41 changes: 25 additions & 16 deletions src/semidiscretization/semidiscretization_coupled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,18 @@ BoundaryConditionCoupled(2, (:j, :i_backwards, :end), Float64)
!!! warning "Experimental code"
This is an experimental feature and can change any time.
"""
mutable struct BoundaryConditionCoupled{NDIMS, NDIMST2M1, uEltype <: Real, Indices}
mutable struct BoundaryConditionCoupled{NDIMS, NDIMST2M1, uEltype <: Real, Indices,
CouplingConverter}
# NDIMST2M1 == NDIMS * 2 - 1
# Buffer for boundary values: [variable, nodes_i, nodes_j, cell_i, cell_j]
u_boundary :: Array{uEltype, NDIMST2M1} # NDIMS * 2 - 1
other_semi_index :: Int
other_orientation :: Int
indices :: Indices

function BoundaryConditionCoupled(other_semi_index, indices, uEltype)
u_boundary::Array{uEltype, NDIMST2M1} # NDIMS * 2 - 1
other_semi_index::Int
other_orientation::Int
indices::Indices
coupling_converter::CouplingConverter
SimonCan marked this conversation as resolved.
Show resolved Hide resolved

function BoundaryConditionCoupled(other_semi_index, indices, uEltype,
coupling_converter)
NDIMS = length(indices)
u_boundary = Array{uEltype, NDIMS * 2 - 1}(undef, ntuple(_ -> 0, NDIMS * 2 - 1))

Expand All @@ -384,8 +387,11 @@ mutable struct BoundaryConditionCoupled{NDIMS, NDIMST2M1, uEltype <: Real, Indic
other_orientation = 3
end

new{NDIMS, NDIMS * 2 - 1, uEltype, typeof(indices)}(u_boundary, other_semi_index,
other_orientation, indices)
new{NDIMS, NDIMS * 2 - 1, uEltype, typeof(indices), typeof(coupling_converter)}(u_boundary,
other_semi_index,
other_orientation,
indices,
coupling_converter)
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down Expand Up @@ -464,8 +470,10 @@ function copy_to_coupled_boundary!(boundary_condition::BoundaryConditionCoupled{
semi)
@unpack u_indices = semi
@unpack other_semi_index, other_orientation, indices = boundary_condition
@unpack coupling_converter, u_boundary = boundary_condition

mesh, equations, solver, cache = mesh_equations_solver_cache(semi.semis[other_semi_index])
@unpack node_coordinates = cache.elements
u = wrap_array(get_system_u_ode(u_ode, other_semi_index, semi), mesh, equations, solver,
cache)

Expand All @@ -492,13 +500,14 @@ function copy_to_coupled_boundary!(boundary_condition::BoundaryConditionCoupled{
for cell in cells
i_node = i_node_start
j_node = j_node_start
SimonCan marked this conversation as resolved.
Show resolved Hide resolved

for i in eachnode(solver)
for v in 1:size(u, 1)
boundary_condition.u_boundary[v, i, cell] = u[v, i_node, j_node,
linear_indices[i_cell,
j_cell]]
end
element_id = linear_indices[i_cell, j_cell]

for element_id in eachnode(solver)
x = get_node_vars(node_coordinates, equations, solver, i_node, j_node,
element_id)
u_node = get_node_vars(u, equations, solver, i_node, j_node, element_id)
converted_u = coupling_converter(x, u_node)
boundary_condition.u_boundary[:, element_id, cell] = converted_u
i_node += i_node_step
j_node += j_node_step
end
Expand Down
8 changes: 4 additions & 4 deletions test/test_structured_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ isdir(outdir) && rm(outdir, recursive=true)

@trixi_testset "elixir_advection_coupled.jl" begin
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_coupled.jl"),
l2 = [7.816742843181738e-6, 7.816742843196112e-6],
linf = [6.314906965543265e-5, 6.314906965410039e-5],
l2 = [8.336466488044185e-6, 8.336466488028504e-6],
linf = [6.406463687191888e-5, 6.406463686947639e-5],
coverage_override = (maxiters=10^5,))

@testset "analysis_callback(sol) for AnalysisCallbackCoupled" begin
errors = analysis_callback(sol)
@test errors.l2 ≈ [7.816742843181738e-6, 7.816742843196112e-6] rtol=1.0e-4
@test errors.linf ≈ [6.314906965543265e-5, 6.314906965410039e-5] rtol=1.0e-4
@test errors.l2 ≈ [8.336466488044185e-6, 8.336466488028504e-6] rtol=1.0e-4
@test errors.linf ≈ [6.406463687191888e-5, 6.406463686947639e-5] rtol=1.0e-4
# Ensure that we do not have excessive memory allocations
# (e.g., from type instabilities)
let
Expand Down
Loading