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 11 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
15 changes: 10 additions & 5 deletions examples/structured_2d_dgsem/elixir_advection_coupled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ 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
boundary_conditions_x_neg1 = BoundaryConditionCoupled(2, (:end, :i_forward), Float64, coupling_converter_identity(equations))
boundary_conditions_x_pos1 = BoundaryConditionCoupled(2, (:begin, :i_forward), Float64, coupling_converter_identity(equations))

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),
x_neg=boundary_conditions_x_neg1,
# Connect right boundary with left boundary of right mesh
x_pos=BoundaryConditionCoupled(2, (:begin, :i_forward), Float64),
x_pos=boundary_conditions_x_pos1,
y_neg=boundary_condition_periodic,
y_pos=boundary_condition_periodic))

Expand All @@ -67,12 +69,15 @@ cells_per_dimension2 = cells_per_dimension

mesh2 = StructuredMesh(cells_per_dimension2, coordinates_min2, coordinates_max2)

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

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),
x_neg=boundary_conditions_x_neg2,
# Connect right boundary with left boundary of left mesh
x_pos=BoundaryConditionCoupled(1, (:begin, :i_forward), Float64),
x_pos=boundary_conditions_x_pos2,
y_neg=boundary_condition_periodic,
y_pos=boundary_condition_periodic))

Expand Down
136 changes: 136 additions & 0 deletions examples/structured_2d_dgsem/elixir_advection_coupled_converter.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using OrdinaryDiffEq
using Trixi

###############################################################################
# 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
# linear advection equations. The two systems are coupled in the x-direction and have periodic
# boundaries in the y-direction. For a high-level overview, see also the figure below:
#
# (-1, 1) ( 1, 1)
# ┌────────────────────┬────────────────────┐
# │ ↑ periodic ↑ │ ↑ periodic ↑ │
# │ │ │
# │ │ │
# │ ========= │ ========= │
# │ system #1 │ system #2 │
# │ ========= │ ========= │
# │ │ │
# │ │ │
# │ │ │
# │ │ │
# │ coupled -->│<-- coupled │
# │ │ │
# │<-- coupled │ coupled -->│
# │ │ │
# │ │ │
# │ ↓ periodic ↓ │ ↓ periodic ↓ │
# └────────────────────┴────────────────────┘
# (-1, -1) ( 1, -1)

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)

# 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))

# Define identical resolution as a variable such that it is easier to change from `trixi_include`
cells_per_dimension = (8, 16)

cells_per_dimension1 = cells_per_dimension

mesh1 = StructuredMesh(cells_per_dimension1, coordinates_min1, coordinates_max1)

coupling_function1 = coupling_converter_heaviside_2d(-0.5, 1.0, 1.0, equations)
# The user can define their own coupling functions.
# coupling_function1 = (x, u) -> (sign(x[2] - 0.0)*0.1 + 1.0)/1.1 * 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))

cells_per_dimension2 = cells_per_dimension

mesh2 = StructuredMesh(cells_per_dimension2, coordinates_min2, coordinates_max2)

coupling_function2 = coupling_converter_heaviside_2d(-0.5, 1.0, 1.0, equations)
# coupling_function2 = (x, u) -> (sign(x[2] - 0.0)*0.1 + 1.0)/1.1 * 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
ode = semidiscretize(semi, (0.0, 20.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_callback = AnalysisCallbackCoupled(semi, analysis_callback1, analysis_callback2)

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

# The StepsizeCallback handles the re-calculation of the maximum Δt after each time step
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)

###############################################################################
# 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);

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

# `trixi_include` and special elixirs such as `convergence_test`
include("auxiliary/special_elixirs.jl")
Expand Down Expand Up @@ -189,6 +190,9 @@ export boundary_condition_do_nothing,
BoundaryConditionNavierStokesWall, NoSlip, Adiabatic, Isothermal,
BoundaryConditionCoupled

export coupling_converter_identity,
coupling_converter_heaviside_2d, coupling_converter_linear_2d

export initial_condition_convergence_test, source_terms_convergence_test
export source_terms_harmonic
export initial_condition_poisson_nonperiodic, source_terms_poisson_nonperiodic,
Expand Down
36 changes: 36 additions & 0 deletions src/coupling_converters/coupling_converters.jl
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
# Since these FMAs can increase the performance of many numerical algorithms,
# we need to opt-in explicitly.
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
@muladd begin
#! format: noindent

@doc raw"""
coupling_converters

Define converter functions for two coupled systems.
These should be used together with SemidiscretizationCoupled.
Using converter functions we can couple two systems that do not
share any variables.
This is done by taking the last inner point of system i, apply
a converter function on the state vector u_i and obtain a state
vector u_j for the boundary of system j.
"""
SimonCan marked this conversation as resolved.
Show resolved Hide resolved

@doc raw"""
Identity coupling converter function.

The coupling is given as a linear function.
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
```math
c(x) = u(x)
```
"""
function coupling_converter_identity(equations::AbstractEquations)
return (x, u) -> u
end

####################################################################################################
# Include files with actual implementations for different systems of equations.

include("coupling_converters_2d.jl")
end # @muladd
35 changes: 35 additions & 0 deletions src/coupling_converters/coupling_converters_2d.jl
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
# Since these FMAs can increase the performance of many numerical algorithms,
# we need to opt-in explicitly.
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
@muladd begin
#! format: noindent

@doc raw"""
Coupling converter function for a system of two LinearScalarAdvectionEquation2D.

SimonCan marked this conversation as resolved.
Show resolved Hide resolved
The coupling is given as a Heaviside step.
```math
c(x) = {c_0, for x \ge x_0 \times s
0, for x < x_0 \times s}
```
Here, `s` is the sign of the step function, x_0 the save_position
of the step and c_0 the amplitude.
"""
function coupling_converter_heaviside_2d(x_0, c_0, s,
equations::LinearScalarAdvectionEquation2D)
return (x, u) -> c_0 * (s * sign(x[2] - x_0) + 1.0) / 2.0 * u
end

@doc raw"""
Coupling converter function for a system of two LinearScalarAdvectionEquation2D.

The coupling is given as a linear function.
```math
c(x) = x * u(x)
```
"""
function coupling_converter_linear_2d(equations::LinearScalarAdvectionEquation2D)
return (x, u) -> x[2] * u
end
end # @muladd
30 changes: 20 additions & 10 deletions src/semidiscretization/semidiscretization_coupled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,14 @@ BoundaryConditionCoupled(2, (:j, :i_backwards, :end), Float64)
mutable struct BoundaryConditionCoupled{NDIMS, NDIMST2M1, uEltype <: Real, Indices}
# 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::Function
ranocha 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 @@ -385,7 +387,8 @@ mutable struct BoundaryConditionCoupled{NDIMS, NDIMST2M1, uEltype <: Real, Indic
end

new{NDIMS, NDIMS * 2 - 1, uEltype, typeof(indices)}(u_boundary, other_semi_index,
other_orientation, indices)
other_orientation, indices,
coupling_converter)
end
end

Expand Down Expand Up @@ -495,9 +498,16 @@ function copy_to_coupled_boundary!(boundary_condition::BoundaryConditionCoupled{

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]]
x = cache.elements.node_coordinates[:, i_node, j_node,
linear_indices[i_cell, j_cell]]
converted_u = boundary_condition.coupling_converter(x,
u[:, i_node, j_node,
linear_indices[i_cell,
j_cell]])
boundary_condition.u_boundary[v, i, cell] = converted_u[v]
# boundary_condition.u_boundary[v, i, cell] = u[v, i_node, j_node,
# linear_indices[i_cell,
# j_cell]]
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
end
i_node += i_node_step
j_node += j_node_step
Expand Down
7 changes: 7 additions & 0 deletions test/test_structured_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ isdir(outdir) && rm(outdir, recursive=true)
end
end

@trixi_testset "elixir_advection_coupled_converter.jl" begin
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_coupled_converter.jl"),
l2 = [0.97560175611287, 0.9707973849860191],
linf = [1.5703274355039958, 1.6235401582169442],
coverage_override = (maxiters=10^5,))
SimonCan marked this conversation as resolved.
Show resolved Hide resolved
end

@trixi_testset "elixir_advection_extended.jl" begin
@test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_extended.jl"),
l2 = [4.220397559713772e-6],
Expand Down