From cb7954e3c1adfa0f8dc7e578d82a70001b80bc8e Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 14:46:26 +0200 Subject: [PATCH 01/20] rename all examples to trixi_controller_*.(c|f90) --- .github/workflows/ci.yml | 24 +++++----- README.md | 18 +++---- docs/src/index.md | 18 +++---- examples/.gitignore | 4 +- examples/CMakeLists.txt | 12 +++-- examples/MakefileCompiled | 2 +- examples/MakefileExternal | 2 +- examples/trixi_controller_data.f90 | 2 +- ...xi_controller.c => trixi_controller_mpi.c} | 0 ...ontroller.f90 => trixi_controller_mpi.f90} | 2 +- examples/trixi_controller_simple.c | 43 +++++++++++++++++ examples/trixi_controller_simple.f90 | 47 +++++++++++++++++++ ...ntroller.jl => trixi_controller_simple.jl} | 0 ...ple_t8code.c => trixi_controller_t8code.c} | 0 14 files changed, 133 insertions(+), 41 deletions(-) rename examples/{simple_trixi_controller.c => trixi_controller_mpi.c} (100%) rename examples/{simple_trixi_controller.f90 => trixi_controller_mpi.f90} (98%) create mode 100644 examples/trixi_controller_simple.c create mode 100644 examples/trixi_controller_simple.f90 rename examples/{simple_trixi_controller.jl => trixi_controller_simple.jl} (100%) rename examples/{simple_t8code.c => trixi_controller_t8code.c} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c662b44c..cf90fa71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -203,13 +203,13 @@ jobs: if: ${{ matrix.test_type == 'regular' || matrix.test_type == 'coverage' }} run: | cd libtrixi-julia - ../build/examples/simple_trixi_controller_c . libelixir_tree1d_dgsem_advection_basic.jl - ../build/examples/simple_trixi_controller_f . libelixir_tree1d_dgsem_advection_basic.jl - ../build/examples/simple_trixi_controller_c . libelixir_p4est2d_dgsem_euler_sedov.jl - ../build/examples/simple_trixi_controller_f . libelixir_p4est2d_dgsem_euler_sedov.jl + ../build/examples/trixi_controller_simple_c . libelixir_tree1d_dgsem_advection_basic.jl + ../build/examples/trixi_controller_simple_f . libelixir_tree1d_dgsem_advection_basic.jl + ../build/examples/trixi_controller_simple_c . libelixir_p4est2d_dgsem_euler_sedov.jl + ../build/examples/trixi_controller_simple_f . libelixir_p4est2d_dgsem_euler_sedov.jl ../build/examples/trixi_controller_data_c . libelixir_p4est2d_dgsem_euler_sedov.jl ../build/examples/trixi_controller_data_f . libelixir_p4est2d_dgsem_euler_sedov.jl - ../build/examples/simple_t8code_c . libelixir_t8code_2d_dgsem_advection_basic.jl + ../build/examples/trixi_controller_t8code_c . libelixir_t8code_2d_dgsem_advection_basic.jl env: LIBTRIXI_DEBUG: all @@ -217,7 +217,7 @@ jobs: if: ${{ matrix.test_type == 'package-compiler' }} run: | cd examples - mpirun -n 2 simple_trixi_controller_c \ + mpirun -n 2 trixi_controller_simple_c \ ../libtrixi-julia \ ../LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl env: @@ -228,16 +228,16 @@ jobs: run: | cd libtrixi-julia set +e # disable early exit on non-zero exit code - for command in "../build/examples/simple_trixi_controller_c" \ - "../build/examples/simple_trixi_controller_c ." \ - "../build/examples/simple_trixi_controller_f" \ - "../build/examples/simple_trixi_controller_f ." \ + for command in "../build/examples/trixi_controller_simple_c" \ + "../build/examples/trixi_controller_simple_c ." \ + "../build/examples/trixi_controller_simple_f" \ + "../build/examples/trixi_controller_simple_f ." \ "../build/examples/trixi_controller_data_c" \ "../build/examples/trixi_controller_data_c ." \ "../build/examples/trixi_controller_data_f" \ "../build/examples/trixi_controller_data_f ." \ - "../build/examples/simple_t8code_c" \ - "../build/examples/simple_t8code_c ." + "../build/examples/trixi_controller_t8code_c" \ + "../build/examples/trixi_controller_t8code_c ." do $command if [ $? -ne 2 ]; then diff --git a/README.md b/README.md index 03b51ff4..f7e70fd4 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Go to some directory from where you want to run a Trixi simulation. ```shell LIBTRIXI_DEBUG=all \ - /bin/simple_trixi_controller_c \ + /bin/trixi_controller_simple_c \ \ /share/libtrixi/LibTrixi.jl/examples/libelixir_tree1d_dgsem_advection_basic.jl ``` @@ -207,9 +207,9 @@ Current time step length: 0.050000 ──────────────────────────────────────────────────────────────────────────────────── ``` -If you change the executable name from `simple_trixi_controller_c` to -`simple_trixi_controller_f`, you will get a near identical output. The corresponding source -files `simple_trixi_controller.c` and `simple_trixi_controller.f90` give you an idea on how +If you change the executable name from `trixi_controller_simple_c` to +`trixi_controller_simple_f`, you will get a near identical output. The corresponding source +files `trixi_controller_simple.c` and `trixi_controller_simple.f90` give you an idea on how to use the C and Fortran APIs of libtrixi, and can be found in the [`examples/`](examples/) folder. @@ -220,7 +220,7 @@ everything from Julia. JULIA_DEPOT_PATH= \ LIBTRIXI_DEBUG=all \ julia --project= - /share/libtrixi/examples/simple_trixi_controller.jl + /share/libtrixi/examples/trixi_controller_simple.jl /share/libtrixi/LibTrixi.jl/examples/libelixir_tree1d_dgsem_advection_basic.jl ``` @@ -244,7 +244,7 @@ the `examples/` directory as ```shell make -f MakefileExternal LIBTRIXI_PREFIX=path/to/libtrixi/prefix ``` -to build `simple_trixi_controller_f`. +to build `trixi_controller_simple_f`. Note: On Linux and FreeBSD systems (i.e., *not* on macOS or Windows), Julia may internally use a faster implementation for thread-local storage (TLS), which is used whenever Julia @@ -271,16 +271,16 @@ To try this out, perform the following steps: make ``` 3. Go to the `examples` folder in the repository root and compile - `simple_trixi_controller_c`: + `trixi_controller_simple_c`: ```shell cd examples make -f MakefileCompiled LIBTRIXI_PREFIX=$PWD/../LibTrixi.jl/lib/build ``` - This will create a `simple_trixi_controller_c` file. + This will create a `trixi_controller_simple_c` file. 4. From inside the `examples` folder you should be able to run the example (in parallel) with the following command: ```shell - mpirun -n 2 simple_trixi_controller_c \ + mpirun -n 2 trixi_controller_simple_c \ ../libtrixi-julia \ ../LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl ``` diff --git a/docs/src/index.md b/docs/src/index.md index b03fb759..5882c87b 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -113,7 +113,7 @@ Go to some directory from where you want to run a Trixi simulation. ```shell LIBTRIXI_DEBUG=all \ - /bin/simple_trixi_controller_c \ + /bin/trixi_controller_simple_c \ \ /share/libtrixi/LibTrixi.jl/examples/libelixir_tree1d_dgsem_advection_basic.jl ``` @@ -209,9 +209,9 @@ Current time step length: 0.050000 ──────────────────────────────────────────────────────────────────────────────────── ``` -If you change the executable name from `simple_trixi_controller_c` to -`simple_trixi_controller_f`, you will get a near identical output. The corresponding source -files `simple_trixi_controller.c` and `simple_trixi_controller.f90` give you an idea on how +If you change the executable name from `trixi_controller_simple_c` to +`trixi_controller_simple_f`, you will get a near identical output. The corresponding source +files `trixi_controller_simple.c` and `trixi_controller_simple.f90` give you an idea on how to use the C and Fortran APIs of libtrixi, and can be found in the [`examples/`](https://github.com/trixi-framework/libtrixi/tree/main/examples/) folder. @@ -220,7 +220,7 @@ everything from Julia. From the repository root, execute ```shell JULIA_DEPOT_PATH=$PWD/libtrixi-julia/julia-depot \ julia --project= - /share/libtrixi/LibTrixi.jl/examples/simple_trixi_controller.jl + /share/libtrixi/LibTrixi.jl/examples/trixi_controller_simple.jl ``` Note: Most auxiliary output is hidden unless the environment variable `LIBTRIXI_DEBUG` is @@ -244,7 +244,7 @@ which can be invoked from inside the `examples/` directory as ```shell make -f MakefileExternal LIBTRIXI_PREFIX=path/to/libtrixi/prefix ``` -to build `simple_trixi_controller_f`. +to build `trixi_controller_simple_f`. Note: On Linux and FreeBSD systems (i.e., *not* on macOS or Windows), Julia may internally use a faster implementation for thread-local storage (TLS), which is used whenever Julia @@ -271,16 +271,16 @@ To try this out, perform the following steps: make ``` 3. Go to the `examples` folder in the repository root and compile - `simple_trixi_controller_c`: + `trixi_controller_simple_c`: ```shell cd examples make -f MakefileCompiled LIBTRIXI_PREFIX=$PWD/../LibTrixi.jl/lib/build ``` - This will create a `simple_trixi_controller_c` file. + This will create a `trixi_controller_simple_c` file. 4. From inside the `examples` folder you should be able to run the example (in parallel) with the following command: ```shell - mpirun -n 2 simple_trixi_controller_c \ + mpirun -n 2 trixi_controller_simple_c \ ../libtrixi-julia \ ../LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl ``` diff --git a/examples/.gitignore b/examples/.gitignore index 770e6753..5eff49d8 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,2 +1,2 @@ -simple_trixi_controller_c -simple_trixi_controller_f +trixi_controller_simple_c +trixi_controller_simple_f diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b1c8ff39..66eb986a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,9 +1,11 @@ set ( EXAMPLES - simple_trixi_controller.c - simple_trixi_controller.f90 - simple_t8code.c + trixi_controller_simple.c + trixi_controller_simple.f90 + trixi_controller_mpi.c + trixi_controller_mpi.f90 trixi_controller_data.c - trixi_controller_data.f90 ) + trixi_controller_data.f90 + trixi_controller_t8code.c ) if ( NOT T8CODE_FOUND ) list( FILTER EXAMPLES EXCLUDE REGEX ".*(t|T)8(c|C)(o|O)(d|D)(e|E).*" ) @@ -61,4 +63,4 @@ foreach ( EXAMPLE ${EXAMPLES} ) endforeach() # install the julia controller example as well -install( FILES simple_trixi_controller.jl DESTINATION share/libtrixi/examples/ ) +install( FILES trixi_controller_simple.jl DESTINATION share/libtrixi/examples/ ) diff --git a/examples/MakefileCompiled b/examples/MakefileCompiled index 151521a9..5c3bc01a 100644 --- a/examples/MakefileCompiled +++ b/examples/MakefileCompiled @@ -14,5 +14,5 @@ CFLAGS ?= -fPIC LDFLAGS ?= -L$(libdir) -Wl,-rpath,$(libdir) -L$(MPI_PREFIX)/lib -Wl,-rpath,$(MPI_PREFIX)/lib LIBS ?= -ltrixi -lmpi -simple_trixi_controller_c: simple_trixi_controller.c +trixi_controller_simple_c: trixi_controller_simple.c $(CC) $< -o $@ $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBS) diff --git a/examples/MakefileExternal b/examples/MakefileExternal index 0c2a6eff..0c91ec9f 100644 --- a/examples/MakefileExternal +++ b/examples/MakefileExternal @@ -6,5 +6,5 @@ FC ?= f95 libdir := $(LIBTRIXI_PREFIX)/lib incdir := $(LIBTRIXI_PREFIX)/include -simple_trixi_controller_f: simple_trixi_controller.f90 +trixi_controller_simple_f: trixi_controller_simple.f90 $(FC) $< -o $@ -fPIC -I$(incdir) -L$(libdir) -Wl,-rpath,$(libdir) -ltrixi $(libdir)/libtrixi_tls.o diff --git a/examples/trixi_controller_data.f90 b/examples/trixi_controller_data.f90 index 3d12a508..d9fc4e7a 100644 --- a/examples/trixi_controller_data.f90 +++ b/examples/trixi_controller_data.f90 @@ -1,4 +1,4 @@ -program simple_trixi_controller_f +program trixi_controller_data_f use LibTrixi use, intrinsic :: iso_fortran_env, only: error_unit use, intrinsic :: iso_c_binding, only: c_int, c_double diff --git a/examples/simple_trixi_controller.c b/examples/trixi_controller_mpi.c similarity index 100% rename from examples/simple_trixi_controller.c rename to examples/trixi_controller_mpi.c diff --git a/examples/simple_trixi_controller.f90 b/examples/trixi_controller_mpi.f90 similarity index 98% rename from examples/simple_trixi_controller.f90 rename to examples/trixi_controller_mpi.f90 index 39fbfc6c..838d99c6 100644 --- a/examples/simple_trixi_controller.f90 +++ b/examples/trixi_controller_mpi.f90 @@ -1,4 +1,4 @@ -program simple_trixi_controller_f +program trixi_controller_mpi_f use LibTrixi use, intrinsic :: iso_fortran_env, only: error_unit use, intrinsic :: iso_c_binding, only: c_int, c_null_char diff --git a/examples/trixi_controller_simple.c b/examples/trixi_controller_simple.c new file mode 100644 index 00000000..c862c959 --- /dev/null +++ b/examples/trixi_controller_simple.c @@ -0,0 +1,43 @@ +#include +//#include + +#include + +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 ); + } + + // 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; +} diff --git a/examples/trixi_controller_simple.f90 b/examples/trixi_controller_simple.f90 new file mode 100644 index 00000000..593b246d --- /dev/null +++ b/examples/trixi_controller_simple.f90 @@ -0,0 +1,47 @@ +program trixi_controller_simple_f + use LibTrixi + use, intrinsic :: iso_fortran_env, only: error_unit + use, intrinsic :: iso_c_binding, only: c_int + + implicit none + + integer(c_int) :: handle + character(len=256) :: argument + + 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" + call exit(2) + 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" + call exit(2) + 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 + + ! Finalize Trixi simulation + call trixi_finalize_simulation(handle) + + ! Finalize Trixi + call trixi_finalize() +end program diff --git a/examples/simple_trixi_controller.jl b/examples/trixi_controller_simple.jl similarity index 100% rename from examples/simple_trixi_controller.jl rename to examples/trixi_controller_simple.jl diff --git a/examples/simple_t8code.c b/examples/trixi_controller_t8code.c similarity index 100% rename from examples/simple_t8code.c rename to examples/trixi_controller_t8code.c From 00a80e9585940a0803a8c957fb3bc4d983ba24f9 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 18:17:31 +0200 Subject: [PATCH 02/20] increase buffer size (was not enough for all julia packages) --- src/api.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api.f90 b/src/api.f90 index 6c91a7dd..c75771aa 100644 --- a/src/api.f90 +++ b/src/api.f90 @@ -417,7 +417,7 @@ function trixi_version_julia() function trixi_version_julia_extended() use, intrinsic :: iso_c_binding, only: c_char, c_null_char, c_f_pointer character(len=:), allocatable :: trixi_version_julia_extended - character(len=4096, kind=c_char), pointer :: buffer + character(len=8192, kind=c_char), pointer :: buffer integer :: length, i ! Associate buffer with C pointer @@ -425,7 +425,7 @@ function trixi_version_julia_extended() ! Determine the actual length of the version string length = 0 - do i = 1,4096 + do i = 1,8192 if ( buffer(i:i) == c_null_char ) exit length = length + 1 end do From b68fbec78f1cce089b88eea131136454aaf1e003 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 18:18:00 +0200 Subject: [PATCH 03/20] add MPI to Fotran example trixi_controller_mpi.(c|f90) should not be comparable --- examples/trixi_controller_mpi.c | 6 +-- examples/trixi_controller_mpi.f90 | 62 ++++++++++++++++++++++++++++-- examples/trixi_controller_simple.c | 1 - 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/examples/trixi_controller_mpi.c b/examples/trixi_controller_mpi.c index 2fc2718f..c778a048 100644 --- a/examples/trixi_controller_mpi.c +++ b/examples/trixi_controller_mpi.c @@ -84,15 +84,15 @@ int main ( int argc, char *argv[] ) { } // Finalize Trixi simulation - printf("\n*** Trixi controller *** Finalize Trixi simulation\n"); + printf("*** Trixi controller *** Finalize Trixi simulation\n\n"); trixi_finalize_simulation( handle ); // Finalize Trixi - printf("\n*** Trixi controller *** Finalize Trixi\n"); + printf("*** Trixi controller *** Finalize Trixi\n\n"); trixi_finalize(); // Finalize MPI - printf("\n*** Trixi controller *** Finalize MPI\n"); + printf("*** Trixi controller *** Finalize MPI\n"); MPI_Finalize(); return 0; diff --git a/examples/trixi_controller_mpi.f90 b/examples/trixi_controller_mpi.f90 index 838d99c6..4c90f881 100644 --- a/examples/trixi_controller_mpi.f90 +++ b/examples/trixi_controller_mpi.f90 @@ -1,3 +1,37 @@ +subroutine init_mpi_external + use mpi + + implicit none + + logical :: flag_init + integer :: ierror, provided_threadlevel, requested_threadlevel, comm, rank, nranks + + comm = MPI_COMM_WORLD + + call MPI_Initialized(flag_init, ierror) + write(*, '(a,i1,a,l,a,i0)') "[EXT] MPI Initialized: return ", ierror, & + ", initialized ", flag_init, & + ", MPI_COMM_WORLD ", comm + + if (.not.(flag_init)) then + requested_threadlevel = MPI_THREAD_SERIALIZED + call MPI_Init_thread(requested_threadlevel, provided_threadlevel, ierror) + write(*, '(a,i1,a,i1,a,i1)') "[EXT] MPI_Init: return ", ierror, & + ", threadlevel requested ", requested_threadlevel, & + ", provided ", provided_threadlevel + end if + + call MPI_Comm_rank(comm, rank, ierror) + write(*, '(a,i1,a,i1)') "[EXT] MPI rank: return ", ierror, ", rank ", rank + + call MPI_Comm_size(comm, nranks, ierror) + write(*, '(a,i1,a,i1)') "[EXT] MPI size: return ", ierror, ", size ", nranks + + call MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN, ierror) + write(*, '(a,i1,a,i1)') "[EXT] MPI errhandler: return ", ierror +end subroutine + + program trixi_controller_mpi_f use LibTrixi use, intrinsic :: iso_fortran_env, only: error_unit @@ -5,6 +39,7 @@ program trixi_controller_mpi_f implicit none + integer :: ierror integer(c_int) :: handle character(len=256) :: argument @@ -22,7 +57,14 @@ program trixi_controller_mpi_f call exit(2) end if + ! Initialize MPI + write(*, '(a)') "" + write(*, '(a)') "*** Trixi controller *** Initialize MPI" + call init_mpi_external() + ! Initialize Trixi + write(*, '(a)') "" + write(*, '(a)') "*** Trixi controller *** Initialize Trixi" call get_command_argument(1, argument) call trixi_initialize(argument) @@ -31,23 +73,28 @@ program trixi_controller_mpi_f trixi_version_library_major(), ".", trixi_version_library_minor(), ".", & trixi_version_library_patch(), " ", trixi_version_library() write(*, '(a)') "" - write(*, '(a)') "All loaded Julia packages" + write(*, '(a)') "All loaded Julia packages:" write(*, '(a)') trixi_version_julia_extended() write(*, '(a)') "" ! Execute Julia code write(*, '(a)') "Execute Julia code" - call trixi_eval_julia('println("3! = ", factorial(3))'); + call trixi_eval_julia('println("3! = ", factorial(3))') + write(*, '(a)') "" ! Set up the Trixi simulation ! We get a handle to use subsequently + write(*, '(a)') "*** Trixi controller *** Set up Trixi simulation" call get_command_argument(2, argument) handle = trixi_initialize_simulation(argument) ! Get time step length - write(*, '(a, e14.8)') "Current time step length: ", trixi_calculate_dt(handle) + write(*, '(a, e14.8)') "*** Trixi controller *** Current time step length: ", & + trixi_calculate_dt(handle) ! Main loop + write(*, '(a)') "" + write(*, '(a)') "*** Trixi controller *** Entering main loop" do ! Exit loop once simulation is completed if ( trixi_is_finished(handle) ) exit @@ -56,8 +103,17 @@ program trixi_controller_mpi_f end do ! Finalize Trixi simulation + write(*, '(a)') "*** Trixi controller *** Finalize Trixi simulation" + write(*, '(a)') "" call trixi_finalize_simulation(handle) ! Finalize Trixi + write(*, '(a)') "*** Trixi controller *** Finalize Trixi" + write(*, '(a)') "" call trixi_finalize() + + ! Finalize MPI + write(*, '(a)') "*** Trixi controller *** Finalize MPI" + call MPI_Finalize(ierror) + end program diff --git a/examples/trixi_controller_simple.c b/examples/trixi_controller_simple.c index c862c959..f9f27822 100644 --- a/examples/trixi_controller_simple.c +++ b/examples/trixi_controller_simple.c @@ -1,5 +1,4 @@ #include -//#include #include From c74dfb6a57ece1d5614e7b9ef1f5a23e9204e1d1 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 18:18:43 +0200 Subject: [PATCH 04/20] explain contents of examples --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f7e70fd4..b40b4de3 100644 --- a/README.md +++ b/README.md @@ -209,12 +209,16 @@ Current time step length: 0.050000 If you change the executable name from `trixi_controller_simple_c` to `trixi_controller_simple_f`, you will get a near identical output. The corresponding source -files `trixi_controller_simple.c` and `trixi_controller_simple.f90` give you an idea on how -to use the C and Fortran APIs of libtrixi, and can be found in the -[`examples/`](examples/) folder. +files can be found in the [`examples/`](examples/) folder. The examples demonstrate different +aspects on how to use the C and Fortran APIs of libtrixi: + +- `trixi_controller_simple.(c|f90)`: basic usage +- `trixi_controller_mpi.(c|f90)`: usage in the presence of MPI +- `trixi_controller_data.(c|f90)`: simulation data access +- `trixi_controller_t8code.c`: interacting with t8code If you just want to test the Julia part of libtrixi, i.e., LibTrixi.jl, you can also run -everything from Julia. +`trixi_controller_simple.jl` from Julia. ```shell JULIA_DEPOT_PATH= \ From 02006b361ae451854c44ba6290533f3c44213e99 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 18:35:30 +0200 Subject: [PATCH 05/20] update docs corresponding to README.md --- docs/src/index.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 5882c87b..123dbe7f 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -211,16 +211,24 @@ Current time step length: 0.050000 If you change the executable name from `trixi_controller_simple_c` to `trixi_controller_simple_f`, you will get a near identical output. The corresponding source -files `trixi_controller_simple.c` and `trixi_controller_simple.f90` give you an idea on how -to use the C and Fortran APIs of libtrixi, and can be found in the -[`examples/`](https://github.com/trixi-framework/libtrixi/tree/main/examples/) folder. +files can be found in the +[`examples/`](https://github.com/trixi-framework/libtrixi/tree/main/examples/) folder. The +examples demonstrate different aspects on how to use the C and Fortran APIs of libtrixi: + +- `trixi_controller_simple.(c|f90)`: basic usage +- `trixi_controller_mpi.(c|f90)`: usage in the presence of MPI +- `trixi_controller_data.(c|f90)`: simulation data access +- `trixi_controller_t8code.c`: interacting with t8code If you just want to test the Julia part of libtrixi, i.e., LibTrixi.jl, you can also run -everything from Julia. From the repository root, execute +`trixi_controller_simple.jl` from Julia. + ```shell -JULIA_DEPOT_PATH=$PWD/libtrixi-julia/julia-depot \ +JULIA_DEPOT_PATH= \ +LIBTRIXI_DEBUG=all \ julia --project= - /share/libtrixi/LibTrixi.jl/examples/trixi_controller_simple.jl + /share/libtrixi/examples/trixi_controller_simple.jl + /share/libtrixi/LibTrixi.jl/examples/libelixir_tree1d_dgsem_advection_basic.jl ``` Note: Most auxiliary output is hidden unless the environment variable `LIBTRIXI_DEBUG` is From d6c8d21478a09b02cdaba770b283878686c66588 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Fri, 6 Oct 2023 15:25:15 +0200 Subject: [PATCH 06/20] get data several times in trixi_controller_data (relevant for AMR) --- ...ibelixir_t8code_2d_dgsem_advection_amr.jl} | 11 +++++++ examples/trixi_controller_data.c | 33 +++++++++++-------- 2 files changed, 30 insertions(+), 14 deletions(-) rename LibTrixi.jl/examples/{libelixir_t8code_2d_dgsem_advection_basic.jl => libelixir_t8code_2d_dgsem_advection_amr.jl} (82%) diff --git a/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_basic.jl b/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl similarity index 82% rename from LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_basic.jl rename to LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl index 96cfe9c8..86314323 100644 --- a/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_basic.jl +++ b/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl @@ -48,10 +48,21 @@ function init_simstate() # The StepsizeCallback handles the re-calculation of the maximum Δt after each time step stepsize_callback = StepsizeCallback(cfl=0.5) + # The AMRCallback triggers adaptive mesh refinement + amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable=first), + base_level=4, + med_level=5, med_threshold=0.1, + max_level=6, max_threshold=0.6) + amr_callback = AMRCallback(semi, amr_controller, + interval=5, + adapt_initial_condition=true, + adapt_initial_condition_only_refine=true) + # Create a CallbackSet to collect all callbacks such that they can be passed to the ODE solver callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, + amr_callback, stepsize_callback) diff --git a/examples/trixi_controller_data.c b/examples/trixi_controller_data.c index 87f705f6..2ec1c1bf 100644 --- a/examples/trixi_controller_data.c +++ b/examples/trixi_controller_data.c @@ -24,29 +24,34 @@ int main ( int argc, char *argv[] ) { printf("\n*** Trixi controller *** Set up Trixi simulation\n"); int handle = trixi_initialize_simulation( argv[2] ); + // Get number of variables + int nvariables = trixi_nvariables( handle ); + printf("\n*** Trixi controller *** nvariables %d\n", nvariables); + // Main loop + int steps = 0; + int nelements = 0; + double* data = NULL; + printf("\n*** Trixi controller *** Entering main loop\n"); while ( !trixi_is_finished( handle ) ) { trixi_step( handle ); - } + steps++; - // get number of elements - int nelements = trixi_nelements( handle ); - printf("\n*** Trixi controller *** nelements %d\n", nelements); + if (steps % 10 == 0) { - // get number of variables - int nvariables = trixi_nvariables( handle ); - printf("\n*** Trixi controller *** nvariables %d\n", nvariables); + // Get number of elements + nelements = trixi_nelements( handle ); + printf("\n*** Trixi controller *** nelements %d\n", nelements); - // allocate memory - double* data = malloc( sizeof(double) * nelements * nvariables ); + // Allocate memory + data = realloc( data, 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; + // Get averaged cell values for each variable + trixi_load_cell_averages(data, handle); + } + } for (int i = 0; i < nelements; ++i) { printf("T[cell %3d] = %f\n", i, data[i+3*nelements] / (gas_constant * data[i]) ); From be8b4bc9a02bf5a0514cee4b64d0c47c161c5a19 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Fri, 6 Oct 2023 15:26:23 +0200 Subject: [PATCH 07/20] make trixi_controller_data also work for just one variable --- examples/trixi_controller_data.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/trixi_controller_data.c b/examples/trixi_controller_data.c index 2ec1c1bf..2accac5d 100644 --- a/examples/trixi_controller_data.c +++ b/examples/trixi_controller_data.c @@ -53,8 +53,9 @@ int main ( int argc, char *argv[] ) { } } + // Print first variable for (int i = 0; i < nelements; ++i) { - printf("T[cell %3d] = %f\n", i, data[i+3*nelements] / (gas_constant * data[i]) ); + printf("u[cell %3d] = %f\n", i, data[i]); } // Finalize Trixi simulation From 4bb5363b65ad3b565675b8e5807af7767a3cfa1f Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Fri, 6 Oct 2023 15:27:16 +0200 Subject: [PATCH 08/20] test t8code elixir --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf90fa71..a3fc4da0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,7 +207,7 @@ jobs: ../build/examples/trixi_controller_simple_f . libelixir_tree1d_dgsem_advection_basic.jl ../build/examples/trixi_controller_simple_c . libelixir_p4est2d_dgsem_euler_sedov.jl ../build/examples/trixi_controller_simple_f . libelixir_p4est2d_dgsem_euler_sedov.jl - ../build/examples/trixi_controller_data_c . libelixir_p4est2d_dgsem_euler_sedov.jl + ../build/examples/trixi_controller_data_c . libelixir_t8code_2d_dgsem_advection_amr.jl ../build/examples/trixi_controller_data_f . libelixir_p4est2d_dgsem_euler_sedov.jl ../build/examples/trixi_controller_t8code_c . libelixir_t8code_2d_dgsem_advection_basic.jl env: From 1c056b766c700d1815990cf02f6a894442dec5f1 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Fri, 6 Oct 2023 15:45:57 +0200 Subject: [PATCH 09/20] rename elixir in CI --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3fc4da0..28504575 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -151,7 +151,7 @@ jobs: --force cp ../install/share/libtrixi/LibTrixi.jl/examples/libelixir_tree1d_dgsem_advection_basic.jl . cp ../install/share/libtrixi/LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl . - cp ../install/share/libtrixi/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_basic.jl . + cp ../install/share/libtrixi/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl . - name: Initialize project directory if: ${{ matrix.test_type == 'package-compiler' }} @@ -209,7 +209,7 @@ jobs: ../build/examples/trixi_controller_simple_f . libelixir_p4est2d_dgsem_euler_sedov.jl ../build/examples/trixi_controller_data_c . libelixir_t8code_2d_dgsem_advection_amr.jl ../build/examples/trixi_controller_data_f . libelixir_p4est2d_dgsem_euler_sedov.jl - ../build/examples/trixi_controller_t8code_c . libelixir_t8code_2d_dgsem_advection_basic.jl + ../build/examples/trixi_controller_t8code_c . libelixir_t8code_2d_dgsem_advection_amr.jl env: LIBTRIXI_DEBUG: all From 731c0dea8fba865fa9939ba31da4600ea34c202e Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 9 Oct 2023 17:16:16 +0200 Subject: [PATCH 10/20] adapt to C version --- examples/trixi_controller_data.f90 | 46 +++++++++++++++++------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/examples/trixi_controller_data.f90 b/examples/trixi_controller_data.f90 index d9fc4e7a..03c2cbbc 100644 --- a/examples/trixi_controller_data.f90 +++ b/examples/trixi_controller_data.f90 @@ -5,11 +5,10 @@ program trixi_controller_data_f implicit none - integer(c_int) :: handle, nelements, nvariables, i + integer(c_int) :: handle, nelements, nvariables, steps, 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 @@ -28,51 +27,58 @@ program trixi_controller_data_f ! Initialize Trixi + write(*, '(a)') "*** Trixi controller *** Initialize Trixi" call get_command_argument(1, argument) call trixi_initialize(argument) ! Set up the Trixi simulation ! We get a handle to use subsequently + write(*, '(a)') "*** Trixi controller *** Set up Trixi simulation" call get_command_argument(2, argument) handle = trixi_initialize_simulation(argument) + ! get number of variables + nvariables = trixi_nvariables( handle ); + write(*, '(a,i6)') "*** Trixi controller *** nvariables ", nvariables + write(*, '(a)') "" + ! Main loop + steps = 0 + do ! Exit loop once simulation is completed if ( trixi_is_finished(handle) ) exit call trixi_step(handle) - end do + steps = steps + 1 - ! get number of elements - nelements = trixi_nelements(handle); - write(*, '(a,i6)') "*** Trixi controller *** nelements ", nelements - write(*, '(a)') "" + if (modulo(steps, 10) == 0) then + ! 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) ) - ! allocate memory - allocate ( data(nelements*nvariables) ) - - ! get averaged cell values for each variable - call trixi_load_cell_averages(data, handle); - - ! compute temperature - gas_constant = 0.287; + ! get averaged cell values for each variable + call trixi_load_cell_averages(data, handle) + end if + end do + ! print first variable do i = 1,nelements - print "('T[cell ', i4, '] = ', e14.8)", i, data(i+3*nelements)/(gas_constant*data(i)) + print "('u[cell ', i4, '] = ', e14.8)", i, data(i) end do write(*, '(a,i6)') "*** Trixi controller *** Finalize Trixi simulation " write(*, '(a)') "" ! Finalize Trixi simulation + write(*, '(a)') "*** Trixi controller *** Finalize Trixi simulation" call trixi_finalize_simulation(handle) ! Finalize Trixi + write(*, '(a)') "*** Trixi controller *** Finalize Trixi" call trixi_finalize() end program From c4a437115cce9c4a9038d21225c12152933209b0 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 9 Oct 2023 17:46:32 +0200 Subject: [PATCH 11/20] touch-up --- examples/trixi_controller_data.f90 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/trixi_controller_data.f90 b/examples/trixi_controller_data.f90 index 03c2cbbc..fcdcf139 100644 --- a/examples/trixi_controller_data.f90 +++ b/examples/trixi_controller_data.f90 @@ -27,6 +27,7 @@ program trixi_controller_data_f ! Initialize Trixi + write(*, '(a)') "" write(*, '(a)') "*** Trixi controller *** Initialize Trixi" call get_command_argument(1, argument) call trixi_initialize(argument) @@ -39,11 +40,13 @@ program trixi_controller_data_f ! get number of variables nvariables = trixi_nvariables( handle ); + write(*, '(a)') "" write(*, '(a,i6)') "*** Trixi controller *** nvariables ", nvariables write(*, '(a)') "" ! Main loop steps = 0 + write(*, '(a)') "*** Trixi controller *** Entering main loop" do ! Exit loop once simulation is completed @@ -55,8 +58,8 @@ program trixi_controller_data_f if (modulo(steps, 10) == 0) then ! get number of elements nelements = trixi_nelements(handle); - write(*, '(a,i6)') "*** Trixi controller *** nelements ", nelements write(*, '(a)') "" + write(*, '(a,i6)') "*** Trixi controller *** nelements ", nelements ! allocate memory allocate( data(nelements*nvariables) ) @@ -71,14 +74,13 @@ program trixi_controller_data_f print "('u[cell ', i4, '] = ', e14.8)", i, data(i) end do - write(*, '(a,i6)') "*** Trixi controller *** Finalize Trixi simulation " - write(*, '(a)') "" - ! Finalize Trixi simulation + write(*, '(a)') "" write(*, '(a)') "*** Trixi controller *** Finalize Trixi simulation" call trixi_finalize_simulation(handle) ! Finalize Trixi + write(*, '(a)') "" write(*, '(a)') "*** Trixi controller *** Finalize Trixi" call trixi_finalize() end program From f8f835b7bd098e0f2e36ab779fa3940fe327aab4 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 9 Oct 2023 17:48:42 +0200 Subject: [PATCH 12/20] same libelexir for C and Fortran --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0424d6d6..0b44d909 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -219,7 +219,7 @@ jobs: ../build/examples/trixi_controller_simple_c . libelixir_p4est2d_dgsem_euler_sedov.jl ../build/examples/trixi_controller_simple_f . libelixir_p4est2d_dgsem_euler_sedov.jl ../build/examples/trixi_controller_data_c . libelixir_t8code_2d_dgsem_advection_amr.jl - ../build/examples/trixi_controller_data_f . libelixir_p4est2d_dgsem_euler_sedov.jl + ../build/examples/trixi_controller_data_f . libelixir_t8code_2d_dgsem_advection_amr.jl ../build/examples/trixi_controller_t8code_c . libelixir_t8code_2d_dgsem_advection_amr.jl env: LIBTRIXI_DEBUG: all From c2dcbdd66ee64dfc17d59201ff4319e8faf9653f Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 9 Oct 2023 18:10:01 +0200 Subject: [PATCH 13/20] missed renaming --- .github/workflows/ci.yml | 2 +- examples/external/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b44d909..2cb6e06a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -187,7 +187,7 @@ jobs: run: | cd examples/external ./build.sh - mpirun -n 2 ./build/simple_trixi_controller_c \ + mpirun -n 2 ./build/trixi_controller_simple_c \ ../../libtrixi-julia \ ../../LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl env: diff --git a/examples/external/CMakeLists.txt b/examples/external/CMakeLists.txt index cf7217f0..874c8511 100644 --- a/examples/external/CMakeLists.txt +++ b/examples/external/CMakeLists.txt @@ -14,8 +14,8 @@ find_package( MPI REQUIRED ) find_package( LibTrixi REQUIRED ) # Set sources -set ( TARGET_NAME simple_trixi_controller_c ) -add_executable ( ${TARGET_NAME} ${CMAKE_SOURCE_DIR}/../simple_trixi_controller.c ) +set ( TARGET_NAME trixi_controller_simple_c ) +add_executable ( ${TARGET_NAME} ${CMAKE_SOURCE_DIR}/../trixi_controller_simple.c ) # Set libraries to link target_link_libraries( From e1e8542d23d66229c7b4c2cb1b7c0f3e34816769 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Tue, 10 Oct 2023 08:44:34 +0200 Subject: [PATCH 14/20] more missing --- LibTrixi.jl/test/test_t8code.jl | 2 +- test/c/t8code.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LibTrixi.jl/test/test_t8code.jl b/LibTrixi.jl/test/test_t8code.jl index a2ddb6b8..6d6a3200 100644 --- a/LibTrixi.jl/test/test_t8code.jl +++ b/LibTrixi.jl/test/test_t8code.jl @@ -6,7 +6,7 @@ using Trixi libelixir = joinpath(dirname(pathof(LibTrixi)), - "../examples/libelixir_t8code_2d_dgsem_advection_basic.jl") + "../examples/libelixir_t8code_2d_dgsem_advection_amr.jl") # initialize a simulation via API, receive a handle handle = trixi_initialize_simulation(libelixir) diff --git a/test/c/t8code.cpp b/test/c/t8code.cpp index b6bc8afe..dd99a555 100644 --- a/test/c/t8code.cpp +++ b/test/c/t8code.cpp @@ -9,7 +9,7 @@ const char * julia_project_path = JULIA_PROJECT_PATH; // Example libexlixir const char * libelixir_path = - "../../../LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_basic.jl"; + "../../../LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl"; TEST(CInterfaceTest, T8code) { From 0c9cde376612e26bc2e0ddb971fd7a40bd18a2fc Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Tue, 10 Oct 2023 11:33:06 +0200 Subject: [PATCH 15/20] make t8code amr example more lightweight --- .../libelixir_t8code_2d_dgsem_advection_amr.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl b/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl index 86314323..5fa31db1 100644 --- a/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl +++ b/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl @@ -19,7 +19,7 @@ function init_simstate() mapping = Trixi.coordinates2mapping(coordinates_min, coordinates_max) - trees_per_dimension = (4, 4) + trees_per_dimension = (2, 2) mesh = T8codeMesh(trees_per_dimension, polydeg=3, mapping=mapping, @@ -33,7 +33,7 @@ function init_simstate() # ODE solvers, callbacks etc. # Create ODE problem with time span from 0.0 to 1.0 - ode = semidiscretize(semi, (0.0, 1.0)); + ode = semidiscretize(semi, (0.0, 0.1)); # At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup # and resets the timers @@ -50,9 +50,9 @@ function init_simstate() # The AMRCallback triggers adaptive mesh refinement amr_controller = ControllerThreeLevel(semi, IndicatorMax(semi, variable=first), - base_level=4, - med_level=5, med_threshold=0.1, - max_level=6, max_threshold=0.6) + base_level=2, + med_level=3, med_threshold=0.1, + max_level=4, max_threshold=0.6) amr_callback = AMRCallback(semi, amr_controller, interval=5, adapt_initial_condition=true, From d5d381c1834553f5b40d15e8906f806cff3c5574 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Tue, 10 Oct 2023 12:07:23 +0200 Subject: [PATCH 16/20] not too lightweight --- .../examples/libelixir_t8code_2d_dgsem_advection_amr.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl b/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl index 5fa31db1..e6256107 100644 --- a/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl +++ b/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl @@ -33,7 +33,7 @@ function init_simstate() # ODE solvers, callbacks etc. # Create ODE problem with time span from 0.0 to 1.0 - ode = semidiscretize(semi, (0.0, 0.1)); + ode = semidiscretize(semi, (0.0, 0.2)); # At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup # and resets the timers @@ -54,7 +54,7 @@ function init_simstate() med_level=3, med_threshold=0.1, max_level=4, max_threshold=0.6) amr_callback = AMRCallback(semi, amr_controller, - interval=5, + interval=10, adapt_initial_condition=true, adapt_initial_condition_only_refine=true) From cd005e93134d056b311341b25d9f8e32d4716b2b Mon Sep 17 00:00:00 2001 From: Benedict <135045760+bgeihe@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:39:24 +0200 Subject: [PATCH 17/20] Update LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl Co-authored-by: Michael Schlottke-Lakemper --- LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl b/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl index e6256107..a30080b7 100644 --- a/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl +++ b/LibTrixi.jl/examples/libelixir_t8code_2d_dgsem_advection_amr.jl @@ -32,7 +32,7 @@ function init_simstate() ############################################################################### # ODE solvers, callbacks etc. - # Create ODE problem with time span from 0.0 to 1.0 + # Create ODE problem with time span from 0.0 to 0.2 ode = semidiscretize(semi, (0.0, 0.2)); # At the beginning of the main loop, the SummaryCallback prints a summary of the simulation setup From 30761efd80c1ab644293f6f60773099b4363d468 Mon Sep 17 00:00:00 2001 From: Benedict <135045760+bgeihe@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:41:30 +0200 Subject: [PATCH 18/20] Update examples/.gitignore Co-authored-by: Michael Schlottke-Lakemper --- examples/.gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/.gitignore b/examples/.gitignore index 5eff49d8..70e92df7 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,2 +1,8 @@ trixi_controller_simple_c trixi_controller_simple_f +trixi_controller_mpi_c +trixi_controller_mpi_f +trixi_controller_data_c +trixi_controller_data_f +trixi_controller_t8code_c +trixi_controller_t8code_f From b6a79be0a1928b3aabd83ffc782c39a7543e8d76 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 19 Oct 2023 11:32:53 +0200 Subject: [PATCH 19/20] Fortran awareness --- README.md | 1 + docs/src/index.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 79f20039..3945be21 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,7 @@ aspects on how to use the C and Fortran APIs of libtrixi: - `trixi_controller_mpi.(c|f90)`: usage in the presence of MPI - `trixi_controller_data.(c|f90)`: simulation data access - `trixi_controller_t8code.c`: interacting with t8code + (there is no Fortran example yet as the Fortran interface of t8code is still under development) If you just want to test the Julia part of libtrixi, i.e., LibTrixi.jl, you can also run `trixi_controller_simple.jl` from Julia. diff --git a/docs/src/index.md b/docs/src/index.md index 0b774db8..b3c009fd 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -219,6 +219,7 @@ examples demonstrate different aspects on how to use the C and Fortran APIs of l - `trixi_controller_mpi.(c|f90)`: usage in the presence of MPI - `trixi_controller_data.(c|f90)`: simulation data access - `trixi_controller_t8code.c`: interacting with t8code + (there is no Fortran example yet as the Fortran interface of t8code is still under development) If you just want to test the Julia part of libtrixi, i.e., LibTrixi.jl, you can also run `trixi_controller_simple.jl` from Julia. From f6798b5695ff8ac02e58da550d1449095c97716d Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 19 Oct 2023 12:34:00 +0200 Subject: [PATCH 20/20] free data --- examples/trixi_controller_data.c | 2 ++ examples/trixi_controller_data.f90 | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/trixi_controller_data.c b/examples/trixi_controller_data.c index 2accac5d..5e6d0f1f 100644 --- a/examples/trixi_controller_data.c +++ b/examples/trixi_controller_data.c @@ -66,5 +66,7 @@ int main ( int argc, char *argv[] ) { printf("\n*** Trixi controller *** Finalize Trixi\n"); trixi_finalize(); + free(data); + return 0; } diff --git a/examples/trixi_controller_data.f90 b/examples/trixi_controller_data.f90 index fcdcf139..ae038efe 100644 --- a/examples/trixi_controller_data.f90 +++ b/examples/trixi_controller_data.f90 @@ -8,7 +8,7 @@ program trixi_controller_data_f integer(c_int) :: handle, nelements, nvariables, steps, i character(len=256) :: argument integer, parameter :: dp = selected_real_kind(12) - real(dp), dimension(:), pointer :: data + real(dp), dimension(:), pointer :: data => null() if (command_argument_count() < 1) then @@ -62,6 +62,7 @@ program trixi_controller_data_f write(*, '(a,i6)') "*** Trixi controller *** nelements ", nelements ! allocate memory + if ( associated(data) ) deallocate(data) allocate( data(nelements*nvariables) ) ! get averaged cell values for each variable @@ -83,4 +84,6 @@ program trixi_controller_data_f write(*, '(a)') "" write(*, '(a)') "*** Trixi controller *** Finalize Trixi" call trixi_finalize() + + deallocate(data) end program