diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index ec18302494..6d8fe6b172 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -91,7 +91,7 @@ jobs: run: export TEST_LEVEL_FLAG="-DT8CODE_TEST_LEVEL=${{ inputs.TEST_LEVEL }}" && echo TEST_LEVEL_FLAG="$TEST_LEVEL_FLAG" >> $GITHUB_ENV - name: build config variables - run: export CONFIG_OPTIONS="${TEST_LEVEL_FLAG} -DT8CODE_CODE_COVERAGE=ON -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_WALL=ON -DT8CODE_BUILD_WERROR=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake" + run: export CONFIG_OPTIONS="${TEST_LEVEL_FLAG} -DT8CODE_CODE_COVERAGE=ON -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_WALL=ON -DT8CODE_BUILD_WERROR=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DT8CODE_BUILD_FORTRAN_INTERFACE=ON -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake -DT8CODE_BUILD_BENCHMARKS=OFF -DT8CODE_BUILD_DOCUMENTATION=OFF -DT8CODE_BUILD_EXAMPLES=ON -DT8CODE_BUILD_TUTORIALS=OFF" && echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV # cmake - name: echo cmake line diff --git a/api/t8_fortran_interface/t8_fortran_interface_mod.f90 b/api/t8_fortran_interface/t8_fortran_interface_mod.f90 index 3facffbb9a..78179b3593 100644 --- a/api/t8_fortran_interface/t8_fortran_interface_mod.f90 +++ b/api/t8_fortran_interface/t8_fortran_interface_mod.f90 @@ -162,14 +162,15 @@ end subroutine t8_fortran_cmesh_set_join_f end Interface Interface - subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f (cmesh, ntrees, eclasses, vertices, do_both_directions) & - bind (c, name = 't8_fortran_cmesh_set_join_by_vertices_noConn') + subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f (cmesh, ntrees, eclasses, vertices, & + connectivity, do_both_directions) bind (c, name = 't8_cmesh_set_join_by_vertices') use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int IMPLICIT NONE type (c_ptr), value :: cmesh integer (c_int), value :: ntrees type (c_ptr), value :: eclasses type (c_ptr), value :: vertices + type (c_ptr), value :: connectivity integer (c_int), value :: do_both_directions end subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f end Interface @@ -239,7 +240,7 @@ end function t8_forest_get_local_num_leaf_elements Interface integer (c_int) function t8_forest_get_global_num_elements (forest) & - bind (c, name = 't8_forest_get_global_num_elements') + bind (c, name = 't8_forest_get_global_num_leaf_elements') use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int IMPLICIT NONE type (c_ptr), value :: forest @@ -257,7 +258,7 @@ end function t8_forest_get_num_local_trees Interface integer (c_int) function t8_forest_get_tree_num_elements (forest, ltreeid) & - bind (c, name = 't8_forest_get_tree_num_elements') + bind (c, name = 't8_forest_get_tree_num_leaf_elements') use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int IMPLICIT NONE type (c_ptr), value :: forest @@ -267,7 +268,7 @@ end function t8_forest_get_tree_num_elements Interface type (c_ptr) function t8_forest_get_element_in_tree (forest, ltreeid, leid_in_tree) & - bind (c, name = 't8_forest_get_element_in_tree') + bind (c, name = 't8_forest_get_leaf_element_in_tree') use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int IMPLICIT NONE type (c_ptr), value :: forest diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 21b812aaab..d26804f659 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -194,6 +194,8 @@ add_t8_cpp_test( NAME t8_gtest_set_linear_id_serial SOURCES t8_schemes/t add_t8_cpp_test( NAME t8_gtest_elements_are_family_serial SOURCES t8_schemes/t8_gtest_elements_are_family.cxx ) if( T8CODE_BUILD_FORTRAN_INTERFACE AND T8CODE_ENABLE_MPI ) add_t8_test( NAME t8_test_fortran_mpi_interface_init_parallel SOURCES api/t8_fortran_interface/t8_test_mpi_init.f90 ) + add_t8_test( NAME t8_test_fortran_mpi_interface_cmesh_parallel SOURCES api/t8_fortran_interface/t8_test_cmesh.f90 ) + add_t8_test( NAME t8_test_fortran_mpi_interface_forest_parallel SOURCES api/t8_fortran_interface/t8_test_forest.f90 ) endif() add_t8_cpp_test( NAME t8_gtest_vector_split_serial SOURCES t8_vector_helper/t8_gtest_vector_split.cxx ) diff --git a/test/api/t8_fortran_interface/t8_test_cmesh.f90 b/test/api/t8_fortran_interface/t8_test_cmesh.f90 new file mode 100644 index 0000000000..6890abe017 --- /dev/null +++ b/test/api/t8_fortran_interface/t8_test_cmesh.f90 @@ -0,0 +1,103 @@ +!! This file is part of t8code. +!! t8code is a C library to manage a collection (a forest) of multiple +!! connected adaptive space-trees of general element classes in parallel. +!! +!! Copyright (C) 2024 the developers +!! +!! t8code is free software; you can redistribute it and/or modify +!! it under the terms of the GNU General Public License as published by +!! the Free Software Foundation; either version 2 of the License, or +!! (at your option) any later version. +!! +!! t8code is distributed in the hope that it will be useful, +!! but WITHOUT ANY WARRANTY; without even the implied warranty of +!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +!! GNU General Public License for more details. +!! +!! You should have received a copy of the GNU General Public License +!! along with t8code; if not, write to the Free Software Foundation, Inc., +!! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +!! Description: +!! +!! This program tests if the cmesh part of the Fortran +!! interface can be called. +!! Works only when MPI is enabled. + +program t8_test_cmesh + use mpi + use iso_c_binding, only: c_ptr, c_int + use t8_fortran_interface_mod + + implicit none + + integer :: ierror, fcomm + type(c_ptr) :: ccomm, cmesh, geometry + real(c_double), target :: vertices_tri_0(9), vertices_tri_1(9), vertices_total(18) + integer(c_int), target :: eclasses(2) + + call MPI_Init (ierror) + + if (ierror /= 0) then + print *, 'MPI initialization failed.' + stop 1 + endif + + fcomm = MPI_COMM_WORLD + ccomm = t8_fortran_mpi_comm_new_f (fcomm) + call t8_fortran_init_all_f (ccomm) + + cmesh = t8_cmesh_new_periodic_tri_f (ccomm) +!! call t8_cmesh_vtk_write_file_f(cmesh, 'test_mpi_init', 0) + call t8_cmesh_destroy_f(cmesh) + + vertices_tri_0 = [0.0_c_double, 0.0_c_double, 0.0_c_double, & + 1.0_c_double, 0.0_c_double, 0.0_c_double, & + 1.0_c_double, 1.0_c_double, 0.0_c_double] + + vertices_tri_1 = [0.0_c_double, 0.0_c_double, 0.0_c_double, & + 1.0_c_double, 1.0_c_double, 0.0_c_double, & + 0.0_c_double, 1.0_c_double, 0.0_c_double] + vertices_total = [vertices_tri_0, vertices_tri_1] + + !! Create a test quad mesh with 2 triangles in a square + call t8_fortran_cmesh_init_f(cmesh) + !! Create and register a geometry for linear triangles + geometry = t8_fortran_geometry_linear_new_f (2) + call t8_fortran_cmesh_register_geometry_f(cmesh, geometry) + !! Set tree class + call t8_fortran_cmesh_set_tree_class_f(cmesh, int(0, kind=8), 3) + call t8_fortran_cmesh_set_tree_class_f(cmesh, int(1, kind=8), 3) + !! Set tree vertices for the two triangles + call t8_fortran_cmesh_set_tree_vertices_f(cmesh, int(0, kind=8), c_loc(vertices_tri_0), 3) + call t8_fortran_cmesh_set_tree_vertices_f(cmesh, int(1, kind=8), c_loc(vertices_tri_1), 3) + !! Set connections between the two triangles + call t8_fortran_cmesh_set_join_f(cmesh, int(0, kind=8), int(1, kind=8), 1, 2, 0) + call t8_fortran_cmesh_commit_f(cmesh, ccomm) + call t8_cmesh_destroy_f(cmesh) + + !! Create the same mesh again, but let t8code find the connectivity + eclasses = [3, 3] + call t8_fortran_cmesh_init_f(cmesh) + geometry = t8_fortran_geometry_linear_new_f (2) + call t8_fortran_cmesh_register_geometry_f(cmesh, geometry) + call t8_fortran_cmesh_set_tree_class_f(cmesh, int(0, kind=8), 3) + call t8_fortran_cmesh_set_tree_class_f(cmesh, int(1, kind=8), 3) + call t8_fortran_cmesh_set_tree_vertices_f(cmesh, int(0, kind=8), c_loc(vertices_tri_0), 3) + call t8_fortran_cmesh_set_tree_vertices_f(cmesh, int(1, kind=8), c_loc(vertices_tri_1), 3) + call t8_fortran_cmesh_set_join_by_vertices_noConn_f(cmesh, 2, c_loc(eclasses), c_loc(vertices_total), C_NULL_PTR, 0) + call t8_fortran_cmesh_commit_f(cmesh, ccomm) + call t8_cmesh_destroy_f(cmesh) + + call t8_fortran_finalize_f () + call t8_fortran_mpi_comm_delete_f(ccomm) + call MPI_Finalize(ierror) + + if (ierror /= 0) then + print *, 'MPI Finalize failed.' + stop 1 + endif + print *, 'All good!' + stop 0 + +end program diff --git a/test/api/t8_fortran_interface/t8_test_forest.f90 b/test/api/t8_fortran_interface/t8_test_forest.f90 new file mode 100644 index 0000000000..7dececc712 --- /dev/null +++ b/test/api/t8_fortran_interface/t8_test_forest.f90 @@ -0,0 +1,73 @@ +!! This file is part of t8code. +!! t8code is a C library to manage a collection (a forest) of multiple +!! connected adaptive space-trees of general element classes in parallel. +!! +!! Copyright (C) 2024 the developers +!! +!! t8code is free software; you can redistribute it and/or modify +!! it under the terms of the GNU General Public License as published by +!! the Free Software Foundation; either version 2 of the License, or +!! (at your option) any later version. +!! +!! t8code is distributed in the hope that it will be useful, +!! but WITHOUT ANY WARRANTY; without even the implied warranty of +!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +!! GNU General Public License for more details. +!! +!! You should have received a copy of the GNU General Public License +!! along with t8code; if not, write to the Free Software Foundation, Inc., +!! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +!! Description: +!! +!! This program tests if the forest part of the Fortran +!! interface can be called. +!! Works only when MPI is enabled. + +program t8_test_forest + use mpi + use iso_c_binding, only: c_ptr, c_int + use t8_fortran_interface_mod + + implicit none + + integer :: ierror, fcomm + integer :: num_local_elements, num_global_elements, num_local_trees + type(c_ptr) :: ccomm, cmesh, forest, element + integer :: num_elems_in_tree + real(c_double) :: ref_coords(3), out_coords(3) + + call MPI_Init (ierror) + + if (ierror /= 0) then + print *, 'MPI initialization failed.' + stop 1 + endif + + fcomm = MPI_COMM_WORLD + ccomm = t8_fortran_mpi_comm_new_f (fcomm) + call t8_fortran_init_all_f (ccomm) + + cmesh = t8_cmesh_new_periodic_tri_f (ccomm) + forest = t8_forest_new_uniform_default_f (cmesh, 2, 0, ccomm) + !! ierror = t8_forest_write_vtk_f (forest, 'test_forest') + num_local_elements = t8_forest_get_local_num_leaf_elements (forest) + num_global_elements = t8_forest_get_global_num_elements (forest) + num_local_trees = t8_forest_get_num_local_trees (forest) + num_elems_in_tree = t8_forest_get_tree_num_elements (forest, 0) + element = t8_forest_get_element_in_tree (forest, 0, 0) + ref_coords = [0.5_c_double, 0.5_c_double, 0.0_c_double] + call t8_forest_element_from_ref_coords (forest, 0, element, ref_coords, 1, out_coords) + call t8_forest_unref_f (forest) + call t8_fortran_finalize_f () + call t8_fortran_mpi_comm_delete_f(ccomm) + !! call t8_global_productionf_noargs_f ('Finalize forest tests') + call MPI_Finalize(ierror) + if (ierror /= 0) then + print *, 'MPI Finalize failed.' + stop 1 + endif + + print *, 'All good!' + stop 0 +end program diff --git a/test/api/t8_fortran_interface/t8_test_mpi_init.f90 b/test/api/t8_fortran_interface/t8_test_mpi_init.f90 index 665a6d0ec7..8283b62a1f 100644 --- a/test/api/t8_fortran_interface/t8_test_mpi_init.f90 +++ b/test/api/t8_fortran_interface/t8_test_mpi_init.f90 @@ -45,6 +45,12 @@ program t8_test_mpi_init call t8_fortran_init_all_f (ccomm) call t8_fortran_finalize_f () + call t8_fortran_mpi_comm_delete_f(ccomm) + call MPI_Finalize(ierror) + if (ierror /= 0) then + print *, 'MPI Finalize failed.' + stop 1 + endif print *, 'All good!' stop 0