-
Notifications
You must be signed in to change notification settings - Fork 2
First steps towards accessing Trixi data #45
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
70b19bd
first steps towards accessing Trixi data
benegee 8affd33
the real changes
benegee 6a7b7c0
Merge branch 'main' into bg/get_cell_averages
benegee b6f1858
adapt to current main
benegee 7a39eea
add queries and data access to fortran interface
benegee 9ad0958
start with Fortran example for data handling
benegee 155e895
set refinement level to 2 for testing
benegee b5ddfcb
enumerate is not necessary here
benegee 5f99e56
get Fortran example working
benegee 5db2864
use load instead of get
benegee 874f710
Update LibTrixi.jl/src/api_c.jl
benegee 9725e2a
Update LibTrixi.jl/src/api_c.jl
benegee cddfd8b
Update examples/trixi_controller_data.c
benegee ab7bd6e
Update LibTrixi.jl/src/api_jl.jl
benegee d027822
small fixes
benegee 4dc4cb5
add all required Trixi symbols to using statement
benegee 24f9176
Merge branch 'main' into bg/get_cell_averages
benegee 41c3bc4
changed data interface to real(c_double)
benegee 5d550b4
Merge branch 'main' into bg/get_cell_averages
benegee a39b3c9
make computation of averages dimension agnostic
benegee 0f853f6
Update LibTrixi.jl/src/api_c.jl
benegee 6315297
Update LibTrixi.jl/src/api_c.jl
benegee 48aae60
Update LibTrixi.jl/src/api_c.jl
benegee ad0d308
doc consistent to suggestion
benegee 5d63a53
move conversion of C to julia array from api_jl to api_c
benegee 8a3b793
switch to 1-based Fortran array
benegee d71c53c
removed example, libelixir_p4est2d_dgsem_euler_sedov.jl can be used
benegee 1af0098
add new examples to CI testing
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
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
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
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
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,64 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #include <trixi.h> | ||
|
|
||
| int main ( int argc, char *argv[] ) { | ||
|
|
||
| if ( argc < 2 ) { | ||
| fprintf(stderr, "ERROR: missing arguments: PROJECT_DIR LIBELIXIR_PATH\n\n"); | ||
| fprintf(stderr, "usage: %s PROJECT_DIR LIBELIXIR_PATH\n", argv[0]); | ||
| return 2; | ||
| } else if ( argc < 3 ) { | ||
| fprintf(stderr, "ERROR: missing argument: LIBELIXIR_PATH\n\n"); | ||
| fprintf(stderr, "usage: %s PROJECT_DIR LIBELIXIR_PATH\n", argv[0]); | ||
| return 2; | ||
| } | ||
|
|
||
| // Initialize Trixi | ||
| printf("\n*** Trixi controller *** Initialize Trixi\n"); | ||
| trixi_initialize( argv[1], NULL ); | ||
|
|
||
| // Set up the Trixi simulation | ||
| // We get a handle to use subsequently | ||
| printf("\n*** Trixi controller *** Set up Trixi simulation\n"); | ||
| int handle = trixi_initialize_simulation( argv[2] ); | ||
|
|
||
| // Main loop | ||
| printf("\n*** Trixi controller *** Entering main loop\n"); | ||
| while ( !trixi_is_finished( handle ) ) { | ||
|
|
||
| trixi_step( handle ); | ||
| } | ||
|
|
||
| // get number of elements | ||
| int nelements = trixi_nelements( handle ); | ||
| printf("\n*** Trixi controller *** nelements %d\n", nelements); | ||
|
|
||
| // get number of variables | ||
| int nvariables = trixi_nvariables( handle ); | ||
| printf("\n*** Trixi controller *** nvariables %d\n", nvariables); | ||
|
|
||
| // allocate memory | ||
| double* data = malloc( sizeof(double) * nelements * nvariables ); | ||
|
|
||
| // get averaged cell values for each variable | ||
| trixi_load_cell_averages(data, handle); | ||
|
|
||
| // compute temperature | ||
| const double gas_constant = 0.287; | ||
|
|
||
| for (int i = 0; i < nelements; ++i) { | ||
| printf("T[cell %3d] = %f\n", i, data[i+3*nelements] / (gas_constant * data[i]) ); | ||
| } | ||
|
|
||
| // Finalize Trixi simulation | ||
| printf("\n*** Trixi controller *** Finalize Trixi simulation\n"); | ||
| trixi_finalize_simulation( handle ); | ||
|
|
||
| // Finalize Trixi | ||
| printf("\n*** Trixi controller *** Finalize Trixi\n"); | ||
| trixi_finalize(); | ||
|
|
||
| return 0; | ||
| } |
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,78 @@ | ||
| program simple_trixi_controller_f | ||
| use LibTrixi | ||
| use, intrinsic :: iso_fortran_env, only: error_unit | ||
| use, intrinsic :: iso_c_binding, only: c_int, c_double | ||
|
|
||
| implicit none | ||
|
|
||
| integer(c_int) :: handle, nelements, nvariables, i | ||
| character(len=256) :: argument | ||
| integer, parameter :: dp = selected_real_kind(12) | ||
| real(dp), dimension(:), pointer :: data | ||
| real(c_double) :: gas_constant | ||
|
|
||
|
|
||
| if (command_argument_count() < 1) then | ||
| call get_command_argument(0, argument) | ||
| write(error_unit, '(a)') "ERROR: missing arguments: PROJECT_DIR LIBELIXIR_PATH" | ||
| write(error_unit, '(a)') "" | ||
| write(error_unit, '(3a)') "usage: ", trim(argument), " PROJECT_DIR LIBELIXIR_PATH" | ||
| stop 1 | ||
| else if (command_argument_count() < 2) then | ||
| call get_command_argument(0, argument) | ||
| write(error_unit, '(a)') "ERROR: missing argument: LIBELIXIR_PATH" | ||
| write(error_unit, '(a)') "" | ||
| write(error_unit, '(3a)') "usage: ", trim(argument), " PROJECT_DIR LIBELIXIR_PATH" | ||
| stop 1 | ||
| end if | ||
|
|
||
|
|
||
| ! Initialize Trixi | ||
| call get_command_argument(1, argument) | ||
| call trixi_initialize(argument) | ||
|
|
||
| ! Set up the Trixi simulation | ||
| ! We get a handle to use subsequently | ||
| call get_command_argument(2, argument) | ||
| handle = trixi_initialize_simulation(argument) | ||
|
|
||
| ! Main loop | ||
| do | ||
| ! Exit loop once simulation is completed | ||
| if ( trixi_is_finished(handle) ) exit | ||
|
|
||
| call trixi_step(handle) | ||
| end do | ||
|
|
||
| ! get number of elements | ||
| nelements = trixi_nelements(handle); | ||
| write(*, '(a,i6)') "*** Trixi controller *** nelements ", nelements | ||
| write(*, '(a)') "" | ||
|
|
||
| ! get number of variables | ||
| nvariables = trixi_nvariables( handle ); | ||
| write(*, '(a,i6)') "*** Trixi controller *** nvariables ", nvariables | ||
| write(*, '(a)') "" | ||
|
|
||
| ! allocate memory | ||
| allocate ( data(nelements*nvariables) ) | ||
sloede marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ! get averaged cell values for each variable | ||
| call trixi_load_cell_averages(data, handle); | ||
|
|
||
| ! compute temperature | ||
| gas_constant = 0.287; | ||
|
|
||
| do i = 1,nelements | ||
| print "('T[cell ', i4, '] = ', e14.8)", i, data(i+3*nelements)/(gas_constant*data(i)) | ||
| end do | ||
|
|
||
| write(*, '(a,i6)') "*** Trixi controller *** Finalize Trixi simulation " | ||
| write(*, '(a)') "" | ||
|
|
||
| ! Finalize Trixi simulation | ||
| call trixi_finalize_simulation(handle) | ||
|
|
||
| ! Finalize Trixi | ||
| call trixi_finalize() | ||
| end program | ||
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.