-
Notifications
You must be signed in to change notification settings - Fork 1
RFC: Source terms via callback #172
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
Open
benegee
wants to merge
123
commits into
main
Choose a base branch
from
bg/source-terms-callback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 121 commits
Commits
Show all changes
123 commits
Select commit
Hold shift + click to select a range
d5ecc49
add getter for number of dofs
benegee 72709e5
change trixi_load_cell_average
benegee 71ba4bf
fix: ensure Int32
benegee 9c83b05
adapt reference value
benegee 5b3960b
add getter for all dofs values
benegee 3e31f4a
adapt next value
benegee 2d45c62
add trixi_store_in_database
benegee 92d817a
add trixi_ndofs_element
benegee 530f5cc
add tests
benegee c7d38d4
add missing parts in tests
benegee ba00c6f
fix tests
benegee cdf6e5e
deallocate first
benegee aa6d8c7
add trixi_load_prim to Fortran API
benegee cf43795
reference value
benegee dda491a
get doxygen right
benegee 35513ac
Merge branch 'main' into more-data-access
sloede 895282a
add example source_term library
benegee eb95ae0
new libelixir demonstrating callback
benegee 2cf9bb4
Merge branch 'main' into bg/source-terms-callback
benegee e15a9bb
use path relative to install directory
benegee bf0b732
Merge branch 'main' into bg/store-in-database
benegee b864850
add trixi_get_time, trixi_load_node_coordinates
benegee 9430f2d
implement source terms controller
benegee 5956a78
libelixir with source terms via database
benegee ccd23fc
change Array to Vector
benegee 1be73d9
spelling
benegee 584a674
libelixir for baroclinic instability
benegee 7c82c90
remove method only required by steady state correction
benegee d1850a7
Update LibTrixi.jl/examples/libelixir_p4est3d_euler_baroclinic_instab…
benegee fd103d9
Merge branch 'main' into bg/baroclinic-instability
benegee 6170610
Merge branch 'more-data-access' into bg/store-in-database
benegee 94cc1c7
Merge branch 'more-data-access' of github.com:trixi-framework/libtrix…
benegee 7dbb2c6
make everything more consistent!
benegee 7906080
use const double *
benegee ff6ac54
Merge branch 'main' into more-data-access
benegee dfea9e4
Merge branch 'main' into more-data-access
sloede 017e166
Merge branch 'bg/store-in-database' of github.com:trixi-framework/lib…
benegee f534175
Merge branch 'main' into more-data-access
benegee 8b6a81f
Merge branch 'more-data-access' into bg/store-in-database
benegee f96436b
missed merge conflict
benegee b76ca70
transpose calloc args
benegee 37b88a1
Merge branch 'main' into more-data-access
benegee 95ba0cc
Merge branch 'more-data-access' into bg/store-in-database
benegee 44ffad8
Merge branch 'bg/store-in-database' into bg/baroclinic-instability
benegee b40a2a1
add functions to get quadrature information
benegee e4d6901
update CI badge URL
benegee 66ee664
Merge branch 'main' into more-data-access
benegee 3f665f0
Merge branch 'more-data-access' into bg/store-in-database
benegee 3a0387b
remove load_node_coordinates
benegee 49394c7
Merge branch 'bg/store-in-database' into bg/baroclinic-instability
benegee 9bc76b4
add baroclinic instability elixir and controller
benegee 110219d
fix
benegee ade7e73
clean up
benegee 6627b97
add get_t8code_forest to Fortran interface
benegee 2550872
format
benegee 211de01
Merge branch 'more-data-access' into bg/store-in-database
benegee 08daf22
add trixi_store_in_database to Fortran interface
benegee e7ab9eb
Merge branch 'bg/store-in-database' into bg/baroclinic-instability
benegee 6672d9c
add fortran controller for baroclinic test case
benegee e48dcb2
remove parameter t
00e4914
spelling
benegee 312e979
Merge branch 'main' into bg/store-in-database
benegee a175a04
adapt min version according to main CMakeLists.txt
benegee d5fd61f
missed while merging
benegee 4449a82
Merge branch 'main' into bg/store-in-database
benegee 0a359b1
change default argument for DataBase parameter
benegee b150614
Merge branch 'main' into bg/source-terms-callback
benegee a8d2058
fix merge fails
benegee 0351ea9
Merge branch 'bg/store-in-database' into bg/baroclinic-instability
benegee 7b654a4
remove deprecated export
benegee 41ab02a
test for get_time
benegee 6bda669
add tests for trixi_store_in_database
benegee a8c573e
need Int32
benegee 5a33b95
cannot compare Refs
benegee 378dc90
check based on address
benegee 8c36455
relax error tolerance
benegee f28d802
remove deprecated example
benegee d95de39
Merge branch 'bg/store-in-database' into bg/baroclinic-instability
benegee 492d1c4
new cubed sphere examples
benegee 272a0a2
remove deprecated libelixir
benegee 9e36f4e
unify naming of libelixirs
benegee c6ec30a
fixes
benegee b866b8b
adapt index.md to README.md
benegee ac1b653
change to non-adaptive time integrator
benegee 58444f3
missing controlers in ci checks
benegee 5f02f44
Merge branch 'main' into bg/baroclinic-instability
benegee 218cd91
use zeros in initial data
benegee 47a2e4c
missing renamings
benegee 8bd1b23
time not needed anymore
benegee 85f882c
tuned simulation parameters
benegee 49fa815
itree and ielement need to be 0-based
benegee 5cf1aec
one more to free
benegee 8ccad7b
ouch...
benegee 5599568
less output
benegee 86d28ba
Merge branch 'bg/baroclinic-instability' into bg/source-terms-callback
benegee a90d983
add trixi_get_data_pointer
benegee 449149f
add examples working with data pointer
benegee 427b253
Merge branch 'main' into bg/raw-data-access
benegee 9dec2df
changed file name
benegee 4274883
Merge branch 'main' into bg/source-terms-callback
benegee c8cae4c
improve example using new passive tracer equations
benegee 4c06845
Merge branch 'main' into bg/raw-data-access
benegee e5b53a7
new Trixi compat
benegee 7c5f20b
adjust time steps
benegee a15a65e
fix access pattern
benegee f3927d5
add trixi_(load|store)_conservative_vars
benegee bd0670e
tests
benegee aa098d9
!fixup
benegee b29b880
!fixup
benegee 4ee71ba
fortran test
benegee bbf2a60
reference
benegee 5b2d2cc
mention new examples
benegee bbc37f1
Merge branch 'main' into bg/raw-data-access
benegee 4372c57
rename (load|store)*vars to var
benegee 2aa9710
Merge branch 'bg/raw-data-access' into bg/source-terms-callback
benegee d97e743
Merge branch 'main' into bg/raw-data-access
benegee 2d1bb72
niceify
benegee 1a8f059
Merge branch 'bg/raw-data-access' into bg/source-terms-callback
benegee 482ee63
typo
benegee 33b4903
move so next to libelixir
benegee 548850d
Merge branch 'main' into bg/source-terms-callback
benegee d4db650
use Base.RefValue{NTuple}
benegee 1ad3ff6
easier to write
benegee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
LibTrixi.jl/examples/libelixir_structured2d_source_terms_callback.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| using LibTrixi | ||
| using Trixi | ||
| using OrdinaryDiffEq | ||
| using Libdl | ||
|
|
||
| struct SourceTermsCallback | ||
| source_term_fptr::Ptr{Nothing} | ||
| buffer::Vector{Cdouble} | ||
|
|
||
| function SourceTermsCallback(; n_vars, so_path) | ||
| so_handle = dlopen(so_path) | ||
| @info "Opened library ", dlpath(so_handle) | ||
| source_term_fptr = dlsym(so_handle, "source_term_wave") | ||
| @info "Obtained function pointer ", source_term_fptr | ||
|
|
||
| new(source_term_fptr, Vector{Cdouble}(undef, n_vars)) | ||
| end | ||
| end | ||
|
|
||
| function (callback::SourceTermsCallback)(u, x, t, equations::CompressibleEulerEquations2D) | ||
| @unpack source_term_fptr, buffer = callback | ||
| @ccall $source_term_fptr(u::Ptr{Cdouble}, x::Ptr{Cdouble}, t::Cdouble, | ||
| equations.gamma::Cdouble, buffer::Ptr{Cdouble})::Cvoid | ||
| return SVector(buffer[1], buffer[2], buffer[3], buffer[4]) | ||
benegee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| # The function to create the simulation state needs to be named `init_simstate` | ||
| function init_simstate() | ||
|
|
||
| ############################################################################### | ||
| # semidiscretization of the compressible Euler equations | ||
|
|
||
| # use external function in locally compiled shared object | ||
| source_terms_callback = SourceTermsCallback(n_vars = 4, | ||
| so_path = joinpath(@__DIR__, | ||
| "libsource_terms.so")) | ||
|
|
||
| equations = CompressibleEulerEquations2D(1.4) | ||
|
|
||
| initial_condition = initial_condition_convergence_test | ||
|
|
||
| solver = DGSEM(polydeg = 3, surface_flux = flux_lax_friedrichs) | ||
|
|
||
| coordinates_min = (0.0, 0.0) | ||
| coordinates_max = (2.0, 2.0) | ||
|
|
||
| cells_per_dimension = (16, 16) | ||
|
|
||
| mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max) | ||
|
|
||
| semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver, | ||
| source_terms = source_terms_callback) | ||
|
|
||
| ############################################################################### | ||
| # ODE solvers, callbacks etc. | ||
|
|
||
| tspan = (0.0, 2.0) | ||
| ode = semidiscretize(semi, tspan) | ||
|
|
||
| summary_callback = SummaryCallback() | ||
|
|
||
| analysis_interval = 100 | ||
| analysis_callback = AnalysisCallback(semi, interval = analysis_interval) | ||
|
|
||
| alive_callback = AliveCallback(analysis_interval = analysis_interval) | ||
|
|
||
| save_solution = SaveSolutionCallback(interval = 100, | ||
| save_initial_solution = true, | ||
| save_final_solution = true, | ||
| solution_variables = cons2prim) | ||
|
|
||
| stepsize_callback = StepsizeCallback(cfl = 1.0) | ||
|
|
||
| callbacks = CallbackSet(summary_callback, | ||
| analysis_callback, alive_callback, | ||
| save_solution, | ||
| stepsize_callback) | ||
|
|
||
| ############################################################################### | ||
| # create OrdinaryDiffEq's `integrator` | ||
|
|
||
| integrator = init(ode, | ||
| CarpenterKennedy2N54(williamson_condition=false), | ||
| dt=1.0, # will be overwritten by the stepsize_callback | ||
| save_everystep=false, | ||
| callback=callbacks); | ||
|
|
||
| ############################################################################### | ||
| # Create simulation state | ||
|
|
||
| simstate = SimulationState(semi, integrator) | ||
|
|
||
| return simstate | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include <stdio.h> | ||
| #include <math.h> | ||
|
|
||
| /* | ||
| * Example for an external source term evaluation | ||
| * Diagonally running wave, taken from Trixi.jl's source_terms_convergence_test | ||
| */ | ||
| void source_term_wave(const double * u, const double * x, const double t, | ||
| const double gamma, double * sourceterm) { | ||
|
Comment on lines
+8
to
+9
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we pass in the length of
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then check on C side before accessing the fields? |
||
|
|
||
| const double c = 2.0; | ||
| const double A = 0.1; | ||
| const double L = 2.0; | ||
| const double f = 1.0 / L; | ||
| const double omega = 2 * M_PI * f; | ||
|
|
||
| const double si = sin(omega * (x[0] + x[1] - t)); | ||
| const double co = cos(omega * (x[0] + x[1] - t)); | ||
| const double rho = c + A * si; | ||
| const double rho_x = omega * A * co; | ||
| const double tmp = (2 * rho - 1) * (gamma - 1); | ||
|
|
||
| sourceterm[0] = rho_x; | ||
| sourceterm[1] = rho_x * (1 + tmp); | ||
| sourceterm[2] = sourceterm[1]; | ||
| sourceterm[3] = 2 * rho_x * (rho + tmp); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| void source_term_wave(const double * u, const double * x, const double t, | ||
| const double gamma, double * sourceterm); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.