-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add flexibility to nonconservative BCs #2200
base: main
Are you sure you want to change the base?
Conversation
Review checklistThis checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging. Purpose and scope
Code quality
Documentation
Testing
Performance
Verification
Created with ❤️ by the Trixi.jl community. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2200 +/- ##
==========================================
- Coverage 96.42% 96.41% -0.00%
==========================================
Files 486 489 +3
Lines 39164 39398 +234
==========================================
+ Hits 37761 37985 +224
- Misses 1403 1413 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
According to the way this feature has been implemented, the functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this @MarcoArtiano! The functionality works as discussed where it is on the user to put in the boundary conditions for the conservative and nonconservative terms and then combine them appropriately, i.e., scaling noncons
with 0.5f0
. This is the only aspect I am not a huge fan of, as it is related to how the nonconservative terms are implemented at interfaces and has nothing to do with boundary conditions.
Because of this, we should maybe document where this factor of 0.5f0
magically comes from in the new boundary condition routines (as it was documented beofre inside the compute boundary flux call).
What do you think @patrickersing ?
# Note the factor 0.5 necessary for the nonconservative fluxes based on | ||
# the interpretation of global SBP operators coupled discontinuously via | ||
# central fluxes/SATs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment would possibly need added to where the factor of 0.5 scaling occurs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also not very content that we have to expose this to the user in order to specify the boundary condition, but I don't see a better way to accomplish this. I definitely think that we should comment this to give some explanation where the factor 0.5
comes from and that it is not specific to any boundary condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with all of you. I'm also not a huge fan of the factor 0.5
. We may alternatively return a tuple from the boundary conditions for non-conservative systems and multiply by 0.5 inside the solver. As an example:
flux_, noncons_ = boundary_condition(u_inner, normal_direction, x, t, surface_integral.surface_flux, equations)
# Copy flux to element storage in the correct orientation
for v in eachvariable(equations)
# Note the factor 0.5 necessary for the nonconservative fluxes based on
# the interpretation of global SBP operators coupled discontinuously via
# central fluxes/SATs
surface_flux_values[v, node_index, direction_index, element_index] = flux_[v] + 0.5f0 * noncons_[v]
end
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea, since it doesn't require knowledge about the implementation aspect of adding the 0.5
to create the boundary condition. It should work well for the BCs that are currently implemented, but I am not sure what this would look like for the new type of boundary condition that you plan to add. Would you then only set the flux_
part and set the noncons_
part to zero?
I think it would be helpful to include a specific example with such a new BC in the PR to better understand and evaluate what the implementation should look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like this idea with the documentation of how it would work in practice from Patrick's comment above. That is, for something like the standard shallow water equations the jump in the bottom topography is zero at the physical boundary (typically) so one's new boundary condition could compute the conservative flux pieces and then have
return flux_, SVector(0,0,0,0) # flux, noncons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! The only thing that I suggest is using the little more verbose noncons_flux
instead of noncons
.
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Co-authored-by: Daniel Doehring <[email protected]>
Thanks! You are definitely right! I committed all your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MarcoArtiano ! I like this structure and it is quite clean to have the boundary_condition
return both fluxes a la
flux, noncons_flux = boundary_condition(u_inner, outward_direction, x, t,
surface_integral.surface_flux, equations)
I just left a few minor suggestions.
Co-authored-by: Andrew Winters <[email protected]>
Co-authored-by: Andrew Winters <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MarcoArtiano! I think the PR is looking good. I just have some smaller suggestions.
@@ -74,13 +74,37 @@ struct BoundaryConditionDoNothing end | |||
return surface_flux(u_inner, u_inner, orientation_or_normal_direction, equations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return surface_flux(u_inner, u_inner, orientation_or_normal_direction, equations) | |
return flux(u_inner, orientation_or_normal_direction, equations) |
In a previous PR (https://github.com/trixi-framework/Trixi.jl/pull/2062/files#r1768020588) I changed this from flux
to surface_flux
. such that the BC works for both conservative and nonconservative systems. Now that we treat them separately, we should be able to only use the flux
-function in the conservative case.
nonconservative_flux_function(u_inner, u_inner, | ||
orientation_or_normal_direction, equations) | ||
end | ||
|
||
# This version can be called by hyperbolic solvers on unstructured, curved meshes | ||
@inline function (::BoundaryConditionDoNothing)(u_inner, | ||
outward_direction::AbstractVector, | ||
x, t, surface_flux, equations) | ||
return surface_flux(u_inner, u_inner, outward_direction, equations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return surface_flux(u_inner, u_inner, outward_direction, equations) | |
return flux(u_inner, outward_direction, equations) |
see comment above
@@ -2258,7 +2258,7 @@ isdir(outdir) && rm(outdir, recursive = true) | |||
directions = [1, 2] | |||
normal_direction = SVector(one(RealT)) | |||
|
|||
surface_flux_function = flux_lax_friedrichs | |||
surface_flux_function = (flux_lax_friedrichs, flux_lax_friedrichs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we set a true nonconservative flux here instead of flux_lax_friedrichs
?
@@ -2347,7 +2348,7 @@ isdir(outdir) && rm(outdir, recursive = true) | |||
directions = [1, 2, 3, 4] | |||
normal_direction = SVector(one(RealT), zero(RealT)) | |||
|
|||
surface_flux_function = flux_lax_friedrichs | |||
surface_flux_function = (flux_lax_friedrichs, flux_lax_friedrichs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above
# Call pointwise numerical flux function for the conservative part | ||
# in the normal direction on the boundary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Call pointwise numerical flux function for the conservative part | |
# in the normal direction on the boundary | |
# Call pointwise numerical flux functions for the conservative and nonconservative part | |
# in the normal direction on the boundary |
# Call pointwise numerical flux function for the conservative part | ||
# in the normal direction on the boundary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Call pointwise numerical flux function for the conservative part | |
# in the normal direction on the boundary | |
# Call pointwise numerical flux functions for the conservative and nonconservative part | |
# in the normal direction on the boundary |
|
||
# Compute pointwise nonconservative numerical flux at the boundary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Compute pointwise nonconservative numerical flux at the boundary. |
This comment can be removed.
This PR allows to have more flexibility when defining the boundary conditions for a set of equations with nonconservative terms. This issues has been discussed in #2175. Now the user can define his own boundary condition, considering that the function accepts both surface flux and the nonconservative flux. An example can be found in elixir_mhd_reflective_wall