From 4fbcbce55140bfc8c940b108373107011f7e8b82 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Wed, 10 Apr 2024 22:15:42 +0200 Subject: [PATCH 01/33] Create a view for std_vector input --- src/Makefile.am | 3 +- src/t8_data/t8_containers.h | 2 + src/t8_data/t8_stdvector_conversion.hxx | 63 +++++++++++++++++++++++++ src/t8_forest/t8_forest_partition.cxx | 3 ++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/t8_data/t8_stdvector_conversion.hxx diff --git a/src/Makefile.am b/src/Makefile.am index 28f686305e..e0143fce2f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -43,7 +43,8 @@ libt8_installed_headers_cmesh = \ src/t8_cmesh/t8_cmesh_helpers.h \ src/t8_cmesh/t8_cmesh_occ.hxx libt8_installed_headers_data = \ - src/t8_data/t8_shmem.h src/t8_data/t8_containers.h + src/t8_data/t8_shmem.h src/t8_data/t8_containers.h \ + src/t8_data/t8_stdvector_conversion.hxx libt8_installed_headers_forest = \ src/t8_forest/t8_forest.h \ src/t8_forest/t8_forest_general.h \ diff --git a/src/t8_data/t8_containers.h b/src/t8_data/t8_containers.h index b7d0836539..f8e7616c8a 100644 --- a/src/t8_data/t8_containers.h +++ b/src/t8_data/t8_containers.h @@ -31,6 +31,8 @@ #include #include + + /** The t8_element_array_t is an array to store t8_element_t * of a given * eclass_scheme implementation. It is a wrapper around \ref sc_array_t. * Each time, a new element is created by the functions for \ref t8_element_array_t, diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx new file mode 100644 index 0000000000..1659612b5e --- /dev/null +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -0,0 +1,63 @@ +/* + 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. +*/ + +/** \file t8_stdvector_conversion.hxx + * Basic conversion routines for std::vector to t8code data types. + */ + + +#ifndef T8_STDVECTOR_CONVERSION_H +#define T8_STDVECTOR_CONVERSION_H + +#include + +/* TODO: write documentation */ +template +sc_array_t* +t8_create_sc_array_view_from_vector (const std::vector &vector) +{ + void *vector_data = (void *) vector.data (); + sc_array_t *new_view = sc_array_new_data (vector_data, sizeof (T), vector.size ()); + return new_view; +} + +template +void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t forest_to, + const std::vector& data_in_vec, std::vector& data_out_vec) +{ + /* Create temporary sc array. */ + sc_array_t *data_in_view, *data_out_view; + + T8_ASSERT (data_in_vec.size () == forest_from->local_num_elements); + T8_ASSERT (data_out_vec.size () == forest_to->local_num_elements); + + data_in_view = t8_create_sc_array_view_from_vector(data_in_vec); + data_out_view = t8_create_sc_array_view_from_vector(data_out_vec); + + t8_forest_partition_data(forest_from, forest_to, data_in_view, data_out_view); + + /* Clean-up memory */ + sc_array_destroy (data_in_view); + sc_array_destroy (data_out_view); +} + +#endif // T8_STDVECTOR_CONVERSION_H \ No newline at end of file diff --git a/src/t8_forest/t8_forest_partition.cxx b/src/t8_forest/t8_forest_partition.cxx index f6259340d3..00c4e6f335 100644 --- a/src/t8_forest/t8_forest_partition.cxx +++ b/src/t8_forest/t8_forest_partition.cxx @@ -26,6 +26,7 @@ #include #include #include +#include /* We want to export the whole implementation to be callable from "C" */ T8_EXTERN_C_BEGIN (); @@ -1249,3 +1250,5 @@ t8_forest_partition_data (t8_forest_t forest_from, t8_forest_t forest_to, const } T8_EXTERN_C_END (); + + From 1d984637caad60771d8a85dd9b99cdfb82bcfa7d Mon Sep 17 00:00:00 2001 From: Prasanna Date: Thu, 11 Apr 2024 15:26:03 +0200 Subject: [PATCH 02/33] create a view of sc_array --- src/t8_data/t8_containers.h | 2 -- src/t8_data/t8_stdvector_conversion.hxx | 37 ++++++++++++++++++++++++- src/t8_forest/t8_forest_partition.cxx | 9 +++--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/t8_data/t8_containers.h b/src/t8_data/t8_containers.h index f8e7616c8a..b7d0836539 100644 --- a/src/t8_data/t8_containers.h +++ b/src/t8_data/t8_containers.h @@ -31,8 +31,6 @@ #include #include - - /** The t8_element_array_t is an array to store t8_element_t * of a given * eclass_scheme implementation. It is a wrapper around \ref sc_array_t. * Each time, a new element is created by the functions for \ref t8_element_array_t, diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index 1659612b5e..de89ec4c10 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -30,7 +30,7 @@ #include -/* TODO: write documentation */ +/* Template to create sc_array view from vector*/ template sc_array_t* t8_create_sc_array_view_from_vector (const std::vector &vector) @@ -59,5 +59,40 @@ void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t fo sc_array_destroy (data_in_view); sc_array_destroy (data_out_view); } +/* Wrapper function gor ghost exchange function */ +template +void t8_forest_ghost_exchange_data_with_vector(t8_forest_t forest, const std::vector& element_vector) { + t8_debugf("Entering ghost_exchange_data_with_vector\n"); + T8_ASSERT(t8_forest_is_committed(forest)); + + if (forest->ghosts == NULL) { + /* This process has no ghosts*/ + return; + } + + /*Create sc_array_t view from the vector*/ + sc_array_t *element_data = t8_create_sc_array_view_from_vector(element_vector); + + /* calling the original function with the sc_array_t view */ + t8_forest_ghost_exchange_data(forest, element_data); + + /*Clean up the sc_array_t view*/ + sc_array_destroy(element_data); +} +/*Wrapper function to handle std::vector directly for t8_forest_search*/ +template +void t8_forest_search_with_vector(t8_forest_t forest, t8_forest_search_query_fn search_fn, + t8_forest_search_query_fn query_fn, const std::vector& query_vector) { + t8_debugf("Entering t8_forest_search_with_vector\n"); + T8_ASSERT(t8_forest_is_committed(forest)); + + /*Create sc_array_t view from the vector*/ + sc_array_t *queries = t8_create_sc_array_view_from_vector(query_vector); + /*calling the original t8_forest_search function with the sc_array_t view */ + t8_forest_search(forest, search_fn, query_fn, queries); + + /* Clean up the sc_array_t view */ + sc_array_destroy(queries); +} #endif // T8_STDVECTOR_CONVERSION_H \ No newline at end of file diff --git a/src/t8_forest/t8_forest_partition.cxx b/src/t8_forest/t8_forest_partition.cxx index 00c4e6f335..4251aa9245 100644 --- a/src/t8_forest/t8_forest_partition.cxx +++ b/src/t8_forest/t8_forest_partition.cxx @@ -26,7 +26,7 @@ #include #include #include -#include + /* We want to export the whole implementation to be callable from "C" */ T8_EXTERN_C_BEGIN (); @@ -1208,8 +1208,9 @@ t8_forest_partition (t8_forest_t forest) t8_global_productionf ("Done forest partition.\n"); } + void -t8_forest_partition_data (t8_forest_t forest_from, t8_forest_t forest_to, const sc_array_t *data_in, +t8_forest_partition_data(t8_forest_t forest_from, t8_forest_t forest_to, const sc_array_t *data_in, sc_array_t *data_out) { t8_forest_t save_set_from; @@ -1249,6 +1250,4 @@ t8_forest_partition_data (t8_forest_t forest_from, t8_forest_t forest_to, const t8_global_productionf ("Done forest partition data.\n"); } -T8_EXTERN_C_END (); - - +T8_EXTERN_C_END (); \ No newline at end of file From c7ee3e8ffc38672b9686ff87bd5a4bde30ba4975 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Thu, 11 Apr 2024 15:29:03 +0200 Subject: [PATCH 03/33] revised version with wrappers for forest search and ghost exchange --- src/t8_data/t8_stdvector_conversion.hxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index de89ec4c10..2250488a19 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -39,7 +39,7 @@ t8_create_sc_array_view_from_vector (const std::vector &vector) sc_array_t *new_view = sc_array_new_data (vector_data, sizeof (T), vector.size ()); return new_view; } - +/* Wrapper function for partition data */ template void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t forest_to, const std::vector& data_in_vec, std::vector& data_out_vec) @@ -52,14 +52,14 @@ void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t fo data_in_view = t8_create_sc_array_view_from_vector(data_in_vec); data_out_view = t8_create_sc_array_view_from_vector(data_out_vec); - + /* calling the original function with the sc_array_t view */ t8_forest_partition_data(forest_from, forest_to, data_in_view, data_out_view); /* Clean-up memory */ sc_array_destroy (data_in_view); sc_array_destroy (data_out_view); } -/* Wrapper function gor ghost exchange function */ +/* Wrapper function for ghost exchange function */ template void t8_forest_ghost_exchange_data_with_vector(t8_forest_t forest, const std::vector& element_vector) { t8_debugf("Entering ghost_exchange_data_with_vector\n"); From c69421aecbde490f0bdd1e9d54990cf7fc65266d Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:52:18 +0200 Subject: [PATCH 04/33] Update t8_forest_partition.cxx --- src/t8_forest/t8_forest_partition.cxx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/t8_forest/t8_forest_partition.cxx b/src/t8_forest/t8_forest_partition.cxx index 4251aa9245..8c4d09c210 100644 --- a/src/t8_forest/t8_forest_partition.cxx +++ b/src/t8_forest/t8_forest_partition.cxx @@ -26,8 +26,6 @@ #include #include #include - - /* We want to export the whole implementation to be callable from "C" */ T8_EXTERN_C_BEGIN (); @@ -1250,4 +1248,4 @@ t8_forest_partition_data(t8_forest_t forest_from, t8_forest_t forest_to, const s t8_global_productionf ("Done forest partition data.\n"); } -T8_EXTERN_C_END (); \ No newline at end of file +T8_EXTERN_C_END (); From f8787081f40c7b3b434d69472f590c010a64a146 Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:53:05 +0200 Subject: [PATCH 05/33] Update t8_forest_partition.cxx --- src/t8_forest/t8_forest_partition.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/t8_forest/t8_forest_partition.cxx b/src/t8_forest/t8_forest_partition.cxx index 8c4d09c210..a3aa3ef937 100644 --- a/src/t8_forest/t8_forest_partition.cxx +++ b/src/t8_forest/t8_forest_partition.cxx @@ -1206,7 +1206,6 @@ t8_forest_partition (t8_forest_t forest) t8_global_productionf ("Done forest partition.\n"); } - void t8_forest_partition_data(t8_forest_t forest_from, t8_forest_t forest_to, const sc_array_t *data_in, sc_array_t *data_out) From bbe995d10ee4be1414b7e6d2e51eee056315257c Mon Sep 17 00:00:00 2001 From: Prasanna Date: Fri, 3 May 2024 00:10:15 +0200 Subject: [PATCH 06/33] Example with vector input --- .vscode/settings.json | 56 +++ src/t8_data/t8_stdvector_conversion.hxx | 10 +- tutorials/Makefile.am | 5 + .../t8_step5_element_data_vector_input.cxx | 320 ++++++++++++++++++ 4 files changed, 384 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 tutorials/general/t8_step5_element_data_vector_input.cxx diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..8e04fb47d7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,56 @@ +{ + "files.associations": { + "array": "cpp", + "bitset": "cpp", + "string_view": "cpp", + "initializer_list": "cpp", + "utility": "cpp", + "vector": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "fstream": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index 2250488a19..ec67a9e3de 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -27,7 +27,8 @@ #ifndef T8_STDVECTOR_CONVERSION_H #define T8_STDVECTOR_CONVERSION_H - +#include +#include #include /* Template to create sc_array view from vector*/ @@ -65,12 +66,7 @@ void t8_forest_ghost_exchange_data_with_vector(t8_forest_t forest, const std::ve t8_debugf("Entering ghost_exchange_data_with_vector\n"); T8_ASSERT(t8_forest_is_committed(forest)); - if (forest->ghosts == NULL) { - /* This process has no ghosts*/ - return; - } - - /*Create sc_array_t view from the vector*/ + /*Create sc_array_t view from the vector*/ sc_array_t *element_data = t8_create_sc_array_view_from_vector(element_vector); /* calling the original function with the sc_array_t view */ diff --git a/tutorials/Makefile.am b/tutorials/Makefile.am index 40b93abcb5..e362862847 100644 --- a/tutorials/Makefile.am +++ b/tutorials/Makefile.am @@ -10,6 +10,7 @@ bin_PROGRAMS += \ tutorials/general/t8_step4_partition_balance_ghost \ tutorials/general/t8_step5_element_data \ tutorials/general/t8_step5_element_data_c_interface \ + tutorials/general/t8_step5_element_data_vector_input \ tutorials/general/t8_step6_stencil \ tutorials/general/t8_step7_interpolation \ tutorials/general/t8_tutorial_build_cmesh \ @@ -37,6 +38,10 @@ tutorials_general_t8_step5_element_data_SOURCES = \ tutorials/general/t8_step3_adapt_forest.cxx \ tutorials/general/t8_step5_element_data.cxx \ tutorials/general/t8_step5_main.cxx +tutorials_general_t8_step5_element_data_vector_input_SOURCES = \ + tutorials/general/t8_step3_adapt_forest.cxx \ + tutorials/general/t8_step5_element_data_vector_input.cxx \ + tutorials/general/t8_step5_main.cxx tutorials_general_t8_step5_element_data_c_interface_SOURCES = \ tutorials/general/t8_step3_adapt_forest.cxx \ tutorials/general/t8_step5_element_data_c_interface.c \ diff --git a/tutorials/general/t8_step5_element_data_vector_input.cxx b/tutorials/general/t8_step5_element_data_vector_input.cxx new file mode 100644 index 0000000000..1e3617a620 --- /dev/null +++ b/tutorials/general/t8_step5_element_data_vector_input.cxx @@ -0,0 +1,320 @@ +/* + 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 types in parallel. + + Copyright (C) 2015 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. +*/ + +/* See also: https://github.com/holke/t8code/wiki/Step-5---Store-element-data + * + * This is step5 of the t8code tutorials. + * In the following we will store data in the individual elements of our forest. + * To do this, we will again create a uniform forest, which will get adapted as in step4, + * with the difference that we partition, balance and create ghost elements all in the same step. + * After adapting the forest we will learn how to build a data array and gather data for + * the local elements. Furthermore, we exchange the data values of the ghost elements and + * output the volume data to vtu. + * + * How you can experiment here: + * - Look at the paraview output files of the adapted forest. + * You can apply a clip filter to look into the cube. Also you can apply (in addition) + * the threshold filter to display only elements with certain properties. + * But at first you may just want to enter the tooltip selection mode 'Hover Cells On' + * to display cell information when hover over them. + * - Change the adaptation criterion as you wish to adapt elements or families as desired. + * - Store even more data per element, for instance the coordinates of its midpoint. + * You can again apply the threshold filter to your new data. Don't forget to write the + * data into the output file. + * */ + +#include /* General t8code header, always include this. */ +#include /* cmesh definition and basic interface. */ +#include /* A collection of exemplary cmeshes */ +#include /* forest definition and basic interface. */ +#include /* save forest */ +#include /* geometrical information */ +#include /* default refinement scheme. */ +#include +#include +#include + + +T8_EXTERN_C_BEGIN (); + +/* The data that we want to store for each element. + * In this example we want to store the element's level and volume. */ +struct t8_step5_data_per_element +{ + int level; + double volume; +}; + +static t8_forest_t +t8_step5_build_forest (sc_MPI_Comm comm, int level) +{ + t8_cmesh_t cmesh = t8_cmesh_new_hypercube_hybrid (comm, 0, 0); + t8_scheme_cxx_t *scheme = t8_scheme_new_default_cxx (); + struct t8_step3_adapt_data adapt_data = { + { 0.5, 0.5, 1 }, /* Midpoints of the sphere. */ + 0.2, /* Refine if inside this radius. */ + 0.4 /* Coarsen if outside this radius. */ + }; + /* Start with a uniform forest. */ + t8_forest_t forest = t8_forest_new_uniform (cmesh, scheme, level, 0, comm); + t8_forest_t forest_apbg; + + /* Adapt, partition, balance and create ghost elements all in the same step. */ + t8_forest_init (&forest_apbg); + t8_forest_set_user_data (forest_apbg, &adapt_data); + t8_forest_set_adapt (forest_apbg, forest, t8_step3_adapt_callback, 0); + t8_forest_set_partition (forest_apbg, NULL, 0); + t8_forest_set_balance (forest_apbg, NULL, 0); + t8_forest_set_ghost (forest_apbg, 1, T8_GHOST_FACES); + t8_forest_commit (forest_apbg); + + return forest_apbg; +} + +std::vector t8_step5_create_element_data (t8_forest_t forest) +{ + t8_locidx_t num_local_elements; + t8_locidx_t num_ghost_elements; + + + /* Check that forest is a committed, that is valid and usable, forest. */ + T8_ASSERT (t8_forest_is_committed (forest)); + + /* Get the number of local elements of forest. */ + num_local_elements = t8_forest_get_local_num_elements (forest); + /* Get the number of ghost elements of forest. */ + num_ghost_elements = t8_forest_get_num_ghosts (forest); +std::vector element_data (num_local_elements+num_ghost_elements); + /* Now we need to build an array of our data that is as long as the number + * of elements plus the number of ghosts. You can use any allocator such as + * new, malloc or the t8code provide allocation macro T8_ALLOC. + * Note that in the latter case you need + * to use T8_FREE in order to free the memory. + */ + /* Note: We will later need to associate this data with an sc_array in order to exchange the values for + * the ghost elements, which we can do with sc_array_new_data (see t8_step5_exchange_ghost_data). + * We could also have directly allocated the data here in an sc_array with + * sc_array_new_count (sizeof (struct data_per_element), num_local_elements + num_ghost_elements); + */ + + /* Let us now fill the data with something. + * For this, we iterate through all trees and for each tree through all its elements, calling + * t8_forest_get_element_in_tree to get a pointer to the current element. + * This is the recommended and most performant way. + * An alternative is to iterate over the number of local elements and use + * t8_forest_get_element. However, this function needs to perform a binary search + * for the element and the tree it is in, while t8_forest_get_element_in_tree has a + * constant look up time. You should only use t8_forest_get_element if you do not know + * in which tree an element is. + */ + { + t8_locidx_t itree, num_local_trees; + t8_locidx_t current_index; + t8_locidx_t ielement, num_elements_in_tree; + t8_eclass_t tree_class; + t8_eclass_scheme_c *eclass_scheme; + const t8_element_t *element; + + /* Get the number of trees that have elements of this process. */ + num_local_trees = t8_forest_get_num_local_trees (forest); + for (itree = 0, current_index = 0; itree < num_local_trees; ++itree) { + /* This loop iterates through all local trees in the forest. */ + /* Each tree may have a different element class (quad/tri/hex/tet etc.) and therefore + * also a different way to interpret its elements. In order to be able to handle elements + * of a tree, we need to get its eclass_scheme, and in order to so we first get its eclass. */ + tree_class = t8_forest_get_tree_class (forest, itree); + eclass_scheme = t8_forest_get_eclass_scheme (forest, tree_class); + /* Get the number of elements of this tree. */ + num_elements_in_tree = t8_forest_get_tree_num_elements (forest, itree); + for (ielement = 0; ielement < num_elements_in_tree; ++ielement, ++current_index) { + /* This loop iterates through all the local elements of the forest in the current tree. */ + + /* We can now write to the position current_index into our array in order to store + * data for this element. */ + /* Since in this example we want to compute the data based on the element in question, + * we need to get a pointer to this element. */ + element = t8_forest_get_element_in_tree (forest, itree, ielement); + /* We want to store the elements level and its volume as data. We compute these + * via the eclass_scheme and the forest_element interface. */ + element_data[current_index].level = eclass_scheme->t8_element_level (element); + element_data[current_index].volume = t8_forest_element_volume (forest, itree, element); + } + } + } + return element_data; +} + +/* Each process has computed the data entries for its local elements. + * In order to get the values for the ghost elements, we use t8_forest_ghost_exchange_data. + * Calling this function will fill all the ghost entries of our element data array with the + * value on the process that owns the corresponding element. */ +static void +t8_step5_exchange_ghost_data (t8_forest_t forest, std::vector& data) +{ + sc_array *sc_array_wrapper; + + /* t8_forest_ghost_exchange_data expects an sc_array (of length num_local_elements + num_ghosts). + * We wrap our data array to an sc_array. */ + sc_array_wrapper = t8_create_sc_array_view_from_vector(data); + + /* Carry out the data exchange. The entries with indices > num_local_elements will get overwritten. + */ + t8_forest_ghost_exchange_data (forest, sc_array_wrapper); + + /* Destroy the wrapper array. This will not free the data memory since we used sc_array_new_data. */ + sc_array_destroy (sc_array_wrapper); +} + +/* Write the forest as vtu and also write the element's volumes in the file. + * + * t8code supports writing element based data to vtu as long as its stored + * as doubles. Each of the data fields to write has to be provided in its own + * array of length num_local_elements. + * We support two types: T8_VTK_SCALAR - One double per element + * and T8_VTK_VECTOR - 3 doubles per element + */ +static void +t8_step5_output_data_to_vtu (t8_forest_t forest, std::vector data, const char *prefix) +{ + t8_locidx_t num_elements = t8_forest_get_local_num_elements (forest); + t8_locidx_t ielem; + /* We need to allocate a new array to store the volumes on their own. + * This array has one entry per local element. */ + double *element_volumes = T8_ALLOC (double, num_elements); + /* The number of user defined data fields to write. */ + int num_data = 1; + /* For each user defined data field we need one t8_vtk_data_field_t variable */ + t8_vtk_data_field_t vtk_data; + /* Set the type of this variable. Since we have one value per element, we pick T8_VTK_SCALAR */ + vtk_data.type = T8_VTK_SCALAR; + /* The name of the field as should be written to the file. */ + strcpy (vtk_data.description, "Element volume"); + vtk_data.data = element_volumes; + /* Copy the element's volumes from our data array to the output array. */ + for (ielem = 0; ielem < num_elements; ++ielem) { + element_volumes[ielem] = data[ielem].volume; + } + { + /* To write user defined data, we need to extended output function t8_forest_vtk_write_file + * from t8_forest_vtk.h. Despite writin user data, it also offers more control over which + * properties of the forest to write. */ + int write_treeid = 1; + int write_mpirank = 1; + int write_level = 1; + int write_element_id = 1; + int write_ghosts = 0; + t8_forest_write_vtk_ext (forest, prefix, write_treeid, write_mpirank, write_level, write_element_id, write_ghosts, + 0, 0, num_data, &vtk_data); + } + T8_FREE (element_volumes); +} + +int +t8_step5_main (int argc, char **argv) +{ + int mpiret; + sc_MPI_Comm comm; + t8_forest_t forest; + /* The prefix for our output files. */ + const char *prefix_forest = "t8_step5_forest"; + const char *prefix_forest_with_data = "t8_step5_forest_with_volume_data"; + /* The uniform refinement level of the forest. */ + const int level = 3; + /* The array that will hold our per element data. */ + + /* Initialize MPI. This has to happen before we initialize sc or t8code. */ + mpiret = sc_MPI_Init (&argc, &argv); + /* Error check the MPI return value. */ + SC_CHECK_MPI (mpiret); + + /* Initialize the sc library, has to happen before we initialize t8code. */ + sc_init (sc_MPI_COMM_WORLD, 1, 1, NULL, SC_LP_ESSENTIAL); + /* Initialize t8code with log level SC_LP_PRODUCTION. See sc.h for more info on the log levels. */ + t8_init (SC_LP_PRODUCTION); + + /* Print a message on the root process. */ + t8_global_productionf (" [step5] \n"); + t8_global_productionf (" [step5] Hello, this is the step5 example of t8code.\n"); + t8_global_productionf ( + " [step5] In this example we will store data on our elements and exchange the data of ghost elements.\n"); + t8_global_productionf (" [step5] \n"); + + /* We will use MPI_COMM_WORLD as a communicator. */ + comm = sc_MPI_COMM_WORLD; + + /* + * Setup. + * Build cmesh and uniform forest. + * Adapt forest similar to step 3 & 4. + */ + + t8_global_productionf (" [step5] \n"); + t8_global_productionf (" [step5] Creating an adapted forest as in step3.\n"); + t8_global_productionf (" [step5] \n"); + + forest = t8_step5_build_forest (comm, level); + t8_forest_write_vtk (forest, prefix_forest); + t8_global_productionf (" [step5] Wrote forest to vtu files: %s*\n", prefix_forest); + + /* + * Build data array and gather data for the local elements. + */ + auto data = t8_step5_create_element_data (forest); + + t8_global_productionf (" [step5] Computed level and volume data for local elements.\n"); + if (t8_forest_get_local_num_elements (forest) > 0) { + /* Output the stored data of the first local element (if it exists). */ + t8_global_productionf (" [step5] Element 0 has level %i and volume %e.\n", data[0].level, data[0].volume); + } + + /* + * Exchange the data values of the ghost elements + */ + t8_step5_exchange_ghost_data (forest, data); + t8_global_productionf (" [step5] Exchanged ghost data.\n"); + + if (t8_forest_get_num_ghosts (forest) > 0) { + /* output the data of the first ghost element (if it exists) */ + t8_locidx_t first_ghost_index = t8_forest_get_local_num_elements (forest); + t8_global_productionf (" [step5] Ghost 0 has level %i and volume %e.\n", data[first_ghost_index].level, + data[first_ghost_index].volume); + } + + /* + * Output the volume data to vtu. + */ + t8_step5_output_data_to_vtu (forest, data, prefix_forest_with_data); + t8_global_productionf (" [step5] Wrote forest and volume data to %s*.\n", prefix_forest_with_data); + + /* Destroy the forest. */ + t8_forest_unref (&forest); + t8_global_productionf (" [step5] Destroyed forest.\n"); + + sc_finalize (); + + mpiret = sc_MPI_Finalize (); + SC_CHECK_MPI (mpiret); + + return 0; +} + +T8_EXTERN_C_END (); From 6d5451669f629eb758393758e44977b22737f634 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Fri, 3 May 2024 17:46:32 +0200 Subject: [PATCH 07/33] test for ghost exchange using std vector as input --- test/Makefile.am | 10 + .../t8_gtest_ghost_exchange_stdvector.cxx | 191 ++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx diff --git a/test/Makefile.am b/test/Makefile.am index d7c1ec92f5..9b287215b2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -42,6 +42,7 @@ t8code_googletest_programs = \ test/t8_forest/t8_gtest_user_data \ test/t8_forest/t8_gtest_transform \ test/t8_forest/t8_gtest_ghost_exchange \ + test/t8_forest/t8_gtest_ghost_exchange_stdvector \ test/t8_forest/t8_gtest_ghost_and_owner \ test/t8_IO/t8_gtest_vtk_reader \ test/t8_forest_incomplete/t8_gtest_permute_hole \ @@ -210,6 +211,10 @@ test_t8_forest_t8_gtest_ghost_exchange_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_exchange.cxx +test_t8_forest_t8_gtest_ghost_exchange_stdvector_SOURCES = \ + test/t8_gtest_main.cxx \ + test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx + test_t8_forest_t8_gtest_ghost_and_owner_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_and_owner.cxx @@ -399,6 +404,10 @@ test_t8_forest_t8_gtest_ghost_exchange_LDADD = $(t8_gtest_target_ld_add) test_t8_forest_t8_gtest_ghost_exchange_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS = $(t8_gtest_target_cpp_flags) +test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDADD = $(t8_gtest_target_ld_add) +test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDFLAGS = $(t8_gtest_target_ld_flags) +test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS = $(t8_gtest_target_cpp_flags) + test_t8_forest_t8_gtest_ghost_and_owner_LDADD = $(t8_gtest_target_ld_add) test_t8_forest_t8_gtest_ghost_and_owner_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS = $(t8_gtest_target_cpp_flags) @@ -469,6 +478,7 @@ test_t8_geometry_t8_gtest_point_inside_CPPFLAGS += $(t8_gtest_target_mpi_cpp_fla test_t8_forest_t8_gtest_user_data_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_transform_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) +test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_IO_t8_gtest_vtk_reader_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_incomplete_t8_gtest_permute_hole_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) diff --git a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx new file mode 100644 index 0000000000..f6a3ee4362 --- /dev/null +++ b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx @@ -0,0 +1,191 @@ +/* + 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) 2015 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "t8_cmesh/t8_cmesh_testcases.h" +#include +/* TODO: when this test works for all cmeshes remove if statement in test_cmesh_ghost_exchange_all () */ + +/* This test program tests the forest ghost exchange routine. + * Given a forest for which the ghost layer was created and an array + * storing data for the local elements and the ghost elements, ghost_exchange + * communicates the data of the local elements to the ghost entries of the + * processes for which these elements are ghost. + * We test the ghost exchange routine for several forests on different + * coarse meshes. + * One test is an integer entry '42' for each element, + * in a second test, we store the element's linear id in the data array. + */ + +class forest_ghost_exchange: public testing::TestWithParam { + protected: + void + SetUp () override + { + cmesh_id = GetParam (); + + scheme = t8_scheme_new_default_cxx (); + /* Construct a cmesh */ + cmesh = t8_test_create_cmesh (cmesh_id); + } + void + TearDown () override + { + t8_cmesh_destroy (&cmesh); + t8_scheme_cxx_unref (&scheme); + } + int cmesh_id; + t8_scheme_cxx_t *scheme; + t8_cmesh_t cmesh; +}; + +static int +t8_test_exchange_adapt (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t which_tree, t8_locidx_t lelement_id, + t8_eclass_scheme_c *ts, const int is_family, const int num_elements, t8_element_t *elements[]) +{ + /* refine every second element up to the maximum level */ + int level = ts->t8_element_level (elements[0]); + t8_linearidx_t eid = ts->t8_element_get_linear_id (elements[0], level); + int maxlevel = *(int *) t8_forest_get_user_data (forest); + + if (eid % 2 && level < maxlevel) { + return 1; + } + return 0; +} + +/* Construct a data array of uin64_t for all elements and all ghosts, + * fill the element's entries with their linear id, perform the ghost exchange and + * check whether the ghost's entries are their linear id. + */ +static void +t8_test_ghost_exchange_data_id (t8_forest_t forest) +{ + t8_eclass_scheme_c *ts; + size_t array_pos = 0; + + t8_locidx_t num_elements = t8_forest_get_local_num_elements (forest); + t8_locidx_t num_ghosts = t8_forest_get_num_ghosts (forest); + /* Initialize a vector of the required size */ + std::vector element_data(num_elements + num_ghosts); + + /* Fill the local element entries with their linear id */ + for (t8_locidx_t itree = 0; itree < t8_forest_get_num_local_trees (forest); itree++) { + /* Get the eclass scheme for this tree */ + ts = t8_forest_get_eclass_scheme (forest, t8_forest_get_tree_class (forest, itree)); + for (t8_locidx_t ielem = 0; ielem < t8_forest_get_tree_num_elements (forest, itree); ielem++) { + /* Get a pointer to this element */ + const t8_element_t *elem = t8_forest_get_element_in_tree (forest, itree, ielem); + /* Compute the linear id of this element */ + t8_linearidx_t elem_id = ts->t8_element_get_linear_id (elem, ts->t8_element_level (elem)); + /* Store this id at the element's index in the array */ + element_data[array_pos] = elem_id; + array_pos++; + } + } + + /* Perform the data exchange */ + t8_forest_ghost_exchange_data_with_vector (forest, element_data); + + /* We now iterate over all ghost elements and check whether the correct + * id was received */ + for (t8_locidx_t itree = 0; itree < t8_forest_get_num_ghost_trees (forest); itree++) { + /* Get the eclass scheme of this ghost tree */ + ts = t8_forest_get_eclass_scheme (forest, t8_forest_ghost_get_tree_class (forest, itree)); + for (t8_locidx_t ielem = 0; ielem < t8_forest_ghost_tree_num_elements (forest, itree); ielem++) { + /* Get a pointer to this ghost */ + const t8_element_t *elem = t8_forest_ghost_get_element (forest, itree, ielem); + /* Compute its ghost_id */ + t8_linearidx_t ghost_id = ts->t8_element_get_linear_id (elem, ts->t8_element_level (elem)); + /* Compare this id with the entry in the element_data array */ + t8_linearidx_t ghost_entry = element_data[array_pos]; + ASSERT_EQ (ghost_id, ghost_entry) << "Error when exchanging ghost data. Received wrong element id.\n"; + /* Since array pos ended with the last element in the loop above, we can + * continue counting for the ghost elements */ + array_pos++; + } + } + +} + +/* Construct a data array of ints for all elements and all ghosts, + * fill the element's entries with '42', perform the ghost exchange and + * check whether the ghost's entries are '42'. + */ +static void +t8_test_ghost_exchange_data_int (t8_forest_t forest) +{ + + t8_locidx_t num_elements = t8_forest_get_local_num_elements (forest); + t8_locidx_t num_ghosts = t8_forest_get_num_ghosts (forest); + std::vector element_data(num_elements+num_ghosts); + /* Fill the local element entries with the integer 42 */ + std::fill(element_data.begin(), element_data.begin() + num_elements, 42); + + /* Perform the ghost data exchange */ + t8_forest_ghost_exchange_data_with_vector (forest, element_data); + + /* Check for the ghosts that we received the correct data */ + for (t8_locidx_t ielem = 0; ielem < num_ghosts; ielem++) { + /* Get the integer for this ghost */ + int ghost_int = element_data[num_elements + ielem]; + ASSERT_EQ (ghost_int, 42) << "Error when exchanging ghost data. Received wrong data.\n"; + } + +} + +TEST_P (forest_ghost_exchange, test_ghost_exchange) +{ + + /* Compute the minimum level, such that the forest is nonempty */ + int min_level = t8_forest_min_nonempty_level (cmesh, scheme); + /* we start with an empty level */ + min_level = SC_MAX (min_level - 1, 0); + t8_debugf ("Testing ghost exchange start level %i. cmesh_id = %i\n", min_level, cmesh_id); + for (int level = min_level; level < min_level + 3; level++) { + /* ref the scheme since we reuse it */ + t8_scheme_cxx_ref (scheme); + /* ref the cmesh since we reuse it */ + t8_cmesh_ref (cmesh); + /* Create a uniformly refined forest */ + t8_forest_t forest = t8_forest_new_uniform (cmesh, scheme, level, 1, sc_MPI_COMM_WORLD); + /* exchange ghost data */ + t8_test_ghost_exchange_data_int (forest); + t8_test_ghost_exchange_data_id (forest); + /* Adapt the forest and exchange data again */ + int maxlevel = level + 2; + t8_forest_t forest_adapt = t8_forest_new_adapt (forest, t8_test_exchange_adapt, 1, 1, &maxlevel); + t8_test_ghost_exchange_data_int (forest_adapt); + t8_test_ghost_exchange_data_id (forest_adapt); + t8_forest_unref (&forest_adapt); + } +} + +INSTANTIATE_TEST_SUITE_P (t8_gtest_ghost_exchange, forest_ghost_exchange, + testing::Range (0, t8_get_number_of_all_testcases ())); From a301b5fafff305d275de6174b2e236713c2fff75 Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Wed, 8 May 2024 15:08:36 +0200 Subject: [PATCH 08/33] Delete .vscode/settings.json --- .vscode/settings.json | 56 ------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 8e04fb47d7..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "files.associations": { - "array": "cpp", - "bitset": "cpp", - "string_view": "cpp", - "initializer_list": "cpp", - "utility": "cpp", - "vector": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "list": "cpp", - "map": "cpp", - "set": "cpp", - "unordered_map": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "string": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "fstream": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file From c167a8b7a0e81e14cc2c50445ddb02b2c36a041f Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Wed, 8 May 2024 15:10:11 +0200 Subject: [PATCH 09/33] Update src/t8_data/t8_stdvector_conversion.hxx Co-authored-by: David Knapp --- src/t8_data/t8_stdvector_conversion.hxx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index ec67a9e3de..2764df3658 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -40,6 +40,7 @@ t8_create_sc_array_view_from_vector (const std::vector &vector) sc_array_t *new_view = sc_array_new_data (vector_data, sizeof (T), vector.size ()); return new_view; } + /* Wrapper function for partition data */ template void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t forest_to, From 0615a3cc4a0a98841107a483f661e6d9b1bae02c Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:20:28 +0200 Subject: [PATCH 10/33] Update src/t8_data/t8_stdvector_conversion.hxx Co-authored-by: David Knapp --- src/t8_data/t8_stdvector_conversion.hxx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index 2764df3658..74abf2afae 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -61,6 +61,7 @@ void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t fo sc_array_destroy (data_in_view); sc_array_destroy (data_out_view); } + /* Wrapper function for ghost exchange function */ template void t8_forest_ghost_exchange_data_with_vector(t8_forest_t forest, const std::vector& element_vector) { From a9559cb6c1af7815a54da7899e6ad63dab99cd08 Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:20:41 +0200 Subject: [PATCH 11/33] Update src/t8_data/t8_stdvector_conversion.hxx Co-authored-by: David Knapp --- src/t8_data/t8_stdvector_conversion.hxx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index 74abf2afae..ebf167f864 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -77,6 +77,7 @@ void t8_forest_ghost_exchange_data_with_vector(t8_forest_t forest, const std::ve /*Clean up the sc_array_t view*/ sc_array_destroy(element_data); } + /*Wrapper function to handle std::vector directly for t8_forest_search*/ template void t8_forest_search_with_vector(t8_forest_t forest, t8_forest_search_query_fn search_fn, From 6fb9f940be81538b70f6b8e3de104ef06dab7fb1 Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:20:57 +0200 Subject: [PATCH 12/33] Update src/t8_forest/t8_forest_partition.cxx Co-authored-by: David Knapp --- src/t8_forest/t8_forest_partition.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t8_forest/t8_forest_partition.cxx b/src/t8_forest/t8_forest_partition.cxx index a3aa3ef937..b2804dbebf 100644 --- a/src/t8_forest/t8_forest_partition.cxx +++ b/src/t8_forest/t8_forest_partition.cxx @@ -1207,7 +1207,7 @@ t8_forest_partition (t8_forest_t forest) } void -t8_forest_partition_data(t8_forest_t forest_from, t8_forest_t forest_to, const sc_array_t *data_in, +t8_forest_partition_data (t8_forest_t forest_from, t8_forest_t forest_to, const sc_array_t *data_in, sc_array_t *data_out) { t8_forest_t save_set_from; From d9d26d6aa9ea126ed4791961cc3ef803c9685122 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Mon, 24 Jun 2024 21:32:59 +0200 Subject: [PATCH 13/33] made a test to compare parameters between std vector and array --- p4est | 2 +- sc | 2 +- test/Makefile.am | 10 ++++++ test/t8_forest/stdvectortest.cxx | 57 ++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 test/t8_forest/stdvectortest.cxx diff --git a/p4est b/p4est index aee0bf1ccc..7896878956 160000 --- a/p4est +++ b/p4est @@ -1 +1 @@ -Subproject commit aee0bf1ccccfbcaeba53beb38688b1d4fc3da8ab +Subproject commit 78968789560133460f0eee74897a44b3444790e5 diff --git a/sc b/sc index edbe89524c..2b209eab18 160000 --- a/sc +++ b/sc @@ -1 +1 @@ -Subproject commit edbe89524c095bc56ec4041e3f6280e0eb3b2028 +Subproject commit 2b209eab184d2feee7bd146ee580ae3c983b85f4 diff --git a/test/Makefile.am b/test/Makefile.am index 9b287215b2..2ce5b3f126 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -43,6 +43,7 @@ t8code_googletest_programs = \ test/t8_forest/t8_gtest_transform \ test/t8_forest/t8_gtest_ghost_exchange \ test/t8_forest/t8_gtest_ghost_exchange_stdvector \ + test/t8_forest/stdvectortest \ test/t8_forest/t8_gtest_ghost_and_owner \ test/t8_IO/t8_gtest_vtk_reader \ test/t8_forest_incomplete/t8_gtest_permute_hole \ @@ -215,6 +216,10 @@ test_t8_forest_t8_gtest_ghost_exchange_stdvector_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx +test_t8_forest_stdvectortest_SOURCES = \ + test/t8_gtest_main.cxx \ + test/t8_forest/stdvectortest.cxx + test_t8_forest_t8_gtest_ghost_and_owner_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_and_owner.cxx @@ -408,6 +413,10 @@ test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDADD = $(t8_gtest_target_ld_ad test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS = $(t8_gtest_target_cpp_flags) +test_t8_forest_stdvectortest_LDADD = $(t8_gtest_target_ld_add) +test_t8_forest_stdvectortest_LDFLAGS = $(t8_gtest_target_ld_flags) +test_t8_forest_stdvectortest_CPPFLAGS = $(t8_gtest_target_cpp_flags) + test_t8_forest_t8_gtest_ghost_and_owner_LDADD = $(t8_gtest_target_ld_add) test_t8_forest_t8_gtest_ghost_and_owner_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS = $(t8_gtest_target_cpp_flags) @@ -479,6 +488,7 @@ test_t8_forest_t8_gtest_user_data_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_transform_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) +test_t8_forest_stdvectortest_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_IO_t8_gtest_vtk_reader_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_incomplete_t8_gtest_permute_hole_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) diff --git a/test/t8_forest/stdvectortest.cxx b/test/t8_forest/stdvectortest.cxx new file mode 100644 index 0000000000..0a44d1f5ab --- /dev/null +++ b/test/t8_forest/stdvectortest.cxx @@ -0,0 +1,57 @@ +#include +#include +#include +#include // header for sc_array conversion +#include "sc_containers.h" // header for sc_array_t and related functions + +// Define sc_array_count function +size_t sc_array_count(const sc_array_t* sc_arr) { + return sc_arr->elem_count; // Access the count member +} + +template +class VectorTest : public ::testing::Test { +protected: + void SetUp() override { + // Initialize the vector with some test values + vec = {T(1), T(2), T(3), T(4), T(5)}; + arr = vec.data(); + // Convert std::vector to sc_array + sc_arr = t8_create_sc_array_view_from_vector(vec); + } + + void TearDown() override { + // Clean up the sc_array to prevent memory leaks + sc_array_destroy(sc_arr); + } + + std::vector vec; // Standard vector + const T* arr; // Raw pointer to the vector data + sc_array_t* sc_arr; // Converted sc_array +}; + +TYPED_TEST_SUITE_P(VectorTest); + +TYPED_TEST_P(VectorTest, LengthTest) { + // Test that the vector length is as expected + ASSERT_EQ(this->vec.size(), 5u) << "Vector length should be 5 for testing purposes"; + // Test that the sc_array length matches the vector length + ASSERT_EQ(sc_array_count(this->sc_arr), this->vec.size()) << "sc_array length should match vector length"; +} + +TYPED_TEST_P(VectorTest, ElementComparisonTest) { + for (size_t i = 0; i < this->vec.size(); ++i) { + // Compare elements in the vector + EXPECT_EQ(this->vec[i], this->arr[i]) << "Element mismatch at index " << i; + // Compare elements between the vector and sc_array + EXPECT_EQ(this->vec[i], *(reinterpret_cast(sc_array_index(this->sc_arr, i)))) + << "Element mismatch between vector and sc_array at index " << i; + } +} + +REGISTER_TYPED_TEST_SUITE_P(VectorTest, LengthTest, ElementComparisonTest); + +typedef ::testing::Types MyTypes; +INSTANTIATE_TYPED_TEST_SUITE_P(MyVectorTests, VectorTest, MyTypes); From 443eca4ef969f97849b3bbc71cdee50b406b4603 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Mon, 24 Jun 2024 21:47:14 +0200 Subject: [PATCH 14/33] Revert "made a test to compare parameters between std vector and array" This reverts commit d9d26d6aa9ea126ed4791961cc3ef803c9685122. --- p4est | 2 +- sc | 2 +- test/Makefile.am | 10 ------ test/t8_forest/stdvectortest.cxx | 57 -------------------------------- 4 files changed, 2 insertions(+), 69 deletions(-) delete mode 100644 test/t8_forest/stdvectortest.cxx diff --git a/p4est b/p4est index 7896878956..aee0bf1ccc 160000 --- a/p4est +++ b/p4est @@ -1 +1 @@ -Subproject commit 78968789560133460f0eee74897a44b3444790e5 +Subproject commit aee0bf1ccccfbcaeba53beb38688b1d4fc3da8ab diff --git a/sc b/sc index 2b209eab18..edbe89524c 160000 --- a/sc +++ b/sc @@ -1 +1 @@ -Subproject commit 2b209eab184d2feee7bd146ee580ae3c983b85f4 +Subproject commit edbe89524c095bc56ec4041e3f6280e0eb3b2028 diff --git a/test/Makefile.am b/test/Makefile.am index 2ce5b3f126..9b287215b2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -43,7 +43,6 @@ t8code_googletest_programs = \ test/t8_forest/t8_gtest_transform \ test/t8_forest/t8_gtest_ghost_exchange \ test/t8_forest/t8_gtest_ghost_exchange_stdvector \ - test/t8_forest/stdvectortest \ test/t8_forest/t8_gtest_ghost_and_owner \ test/t8_IO/t8_gtest_vtk_reader \ test/t8_forest_incomplete/t8_gtest_permute_hole \ @@ -216,10 +215,6 @@ test_t8_forest_t8_gtest_ghost_exchange_stdvector_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx -test_t8_forest_stdvectortest_SOURCES = \ - test/t8_gtest_main.cxx \ - test/t8_forest/stdvectortest.cxx - test_t8_forest_t8_gtest_ghost_and_owner_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_and_owner.cxx @@ -413,10 +408,6 @@ test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDADD = $(t8_gtest_target_ld_ad test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS = $(t8_gtest_target_cpp_flags) -test_t8_forest_stdvectortest_LDADD = $(t8_gtest_target_ld_add) -test_t8_forest_stdvectortest_LDFLAGS = $(t8_gtest_target_ld_flags) -test_t8_forest_stdvectortest_CPPFLAGS = $(t8_gtest_target_cpp_flags) - test_t8_forest_t8_gtest_ghost_and_owner_LDADD = $(t8_gtest_target_ld_add) test_t8_forest_t8_gtest_ghost_and_owner_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS = $(t8_gtest_target_cpp_flags) @@ -488,7 +479,6 @@ test_t8_forest_t8_gtest_user_data_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_transform_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) -test_t8_forest_stdvectortest_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_IO_t8_gtest_vtk_reader_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_incomplete_t8_gtest_permute_hole_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) diff --git a/test/t8_forest/stdvectortest.cxx b/test/t8_forest/stdvectortest.cxx deleted file mode 100644 index 0a44d1f5ab..0000000000 --- a/test/t8_forest/stdvectortest.cxx +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include // header for sc_array conversion -#include "sc_containers.h" // header for sc_array_t and related functions - -// Define sc_array_count function -size_t sc_array_count(const sc_array_t* sc_arr) { - return sc_arr->elem_count; // Access the count member -} - -template -class VectorTest : public ::testing::Test { -protected: - void SetUp() override { - // Initialize the vector with some test values - vec = {T(1), T(2), T(3), T(4), T(5)}; - arr = vec.data(); - // Convert std::vector to sc_array - sc_arr = t8_create_sc_array_view_from_vector(vec); - } - - void TearDown() override { - // Clean up the sc_array to prevent memory leaks - sc_array_destroy(sc_arr); - } - - std::vector vec; // Standard vector - const T* arr; // Raw pointer to the vector data - sc_array_t* sc_arr; // Converted sc_array -}; - -TYPED_TEST_SUITE_P(VectorTest); - -TYPED_TEST_P(VectorTest, LengthTest) { - // Test that the vector length is as expected - ASSERT_EQ(this->vec.size(), 5u) << "Vector length should be 5 for testing purposes"; - // Test that the sc_array length matches the vector length - ASSERT_EQ(sc_array_count(this->sc_arr), this->vec.size()) << "sc_array length should match vector length"; -} - -TYPED_TEST_P(VectorTest, ElementComparisonTest) { - for (size_t i = 0; i < this->vec.size(); ++i) { - // Compare elements in the vector - EXPECT_EQ(this->vec[i], this->arr[i]) << "Element mismatch at index " << i; - // Compare elements between the vector and sc_array - EXPECT_EQ(this->vec[i], *(reinterpret_cast(sc_array_index(this->sc_arr, i)))) - << "Element mismatch between vector and sc_array at index " << i; - } -} - -REGISTER_TYPED_TEST_SUITE_P(VectorTest, LengthTest, ElementComparisonTest); - -typedef ::testing::Types MyTypes; -INSTANTIATE_TYPED_TEST_SUITE_P(MyVectorTests, VectorTest, MyTypes); From 4651ca758b0dfd13c08c9e11497c6d96831003f8 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Mon, 24 Jun 2024 22:11:40 +0200 Subject: [PATCH 15/33] comparing parameters between stdvector and sc_array --- test/Makefile.am | 10 ++++++ test/t8_forest/stdvectortest.cxx | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 test/t8_forest/stdvectortest.cxx diff --git a/test/Makefile.am b/test/Makefile.am index 9b287215b2..2ce5b3f126 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -43,6 +43,7 @@ t8code_googletest_programs = \ test/t8_forest/t8_gtest_transform \ test/t8_forest/t8_gtest_ghost_exchange \ test/t8_forest/t8_gtest_ghost_exchange_stdvector \ + test/t8_forest/stdvectortest \ test/t8_forest/t8_gtest_ghost_and_owner \ test/t8_IO/t8_gtest_vtk_reader \ test/t8_forest_incomplete/t8_gtest_permute_hole \ @@ -215,6 +216,10 @@ test_t8_forest_t8_gtest_ghost_exchange_stdvector_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx +test_t8_forest_stdvectortest_SOURCES = \ + test/t8_gtest_main.cxx \ + test/t8_forest/stdvectortest.cxx + test_t8_forest_t8_gtest_ghost_and_owner_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_and_owner.cxx @@ -408,6 +413,10 @@ test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDADD = $(t8_gtest_target_ld_ad test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS = $(t8_gtest_target_cpp_flags) +test_t8_forest_stdvectortest_LDADD = $(t8_gtest_target_ld_add) +test_t8_forest_stdvectortest_LDFLAGS = $(t8_gtest_target_ld_flags) +test_t8_forest_stdvectortest_CPPFLAGS = $(t8_gtest_target_cpp_flags) + test_t8_forest_t8_gtest_ghost_and_owner_LDADD = $(t8_gtest_target_ld_add) test_t8_forest_t8_gtest_ghost_and_owner_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS = $(t8_gtest_target_cpp_flags) @@ -479,6 +488,7 @@ test_t8_forest_t8_gtest_user_data_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_transform_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) +test_t8_forest_stdvectortest_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_IO_t8_gtest_vtk_reader_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_incomplete_t8_gtest_permute_hole_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) diff --git a/test/t8_forest/stdvectortest.cxx b/test/t8_forest/stdvectortest.cxx new file mode 100644 index 0000000000..0a44d1f5ab --- /dev/null +++ b/test/t8_forest/stdvectortest.cxx @@ -0,0 +1,57 @@ +#include +#include +#include +#include // header for sc_array conversion +#include "sc_containers.h" // header for sc_array_t and related functions + +// Define sc_array_count function +size_t sc_array_count(const sc_array_t* sc_arr) { + return sc_arr->elem_count; // Access the count member +} + +template +class VectorTest : public ::testing::Test { +protected: + void SetUp() override { + // Initialize the vector with some test values + vec = {T(1), T(2), T(3), T(4), T(5)}; + arr = vec.data(); + // Convert std::vector to sc_array + sc_arr = t8_create_sc_array_view_from_vector(vec); + } + + void TearDown() override { + // Clean up the sc_array to prevent memory leaks + sc_array_destroy(sc_arr); + } + + std::vector vec; // Standard vector + const T* arr; // Raw pointer to the vector data + sc_array_t* sc_arr; // Converted sc_array +}; + +TYPED_TEST_SUITE_P(VectorTest); + +TYPED_TEST_P(VectorTest, LengthTest) { + // Test that the vector length is as expected + ASSERT_EQ(this->vec.size(), 5u) << "Vector length should be 5 for testing purposes"; + // Test that the sc_array length matches the vector length + ASSERT_EQ(sc_array_count(this->sc_arr), this->vec.size()) << "sc_array length should match vector length"; +} + +TYPED_TEST_P(VectorTest, ElementComparisonTest) { + for (size_t i = 0; i < this->vec.size(); ++i) { + // Compare elements in the vector + EXPECT_EQ(this->vec[i], this->arr[i]) << "Element mismatch at index " << i; + // Compare elements between the vector and sc_array + EXPECT_EQ(this->vec[i], *(reinterpret_cast(sc_array_index(this->sc_arr, i)))) + << "Element mismatch between vector and sc_array at index " << i; + } +} + +REGISTER_TYPED_TEST_SUITE_P(VectorTest, LengthTest, ElementComparisonTest); + +typedef ::testing::Types MyTypes; +INSTANTIATE_TYPED_TEST_SUITE_P(MyVectorTests, VectorTest, MyTypes); From 12c59d31432e022b119f12eba045457763b53434 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Wed, 10 Jul 2024 14:04:58 +0200 Subject: [PATCH 16/33] indented files --- src/t8_data/t8_stdvector_conversion.hxx | 66 +++++++------- test/t8_forest/stdvectortest.cxx | 90 ++++++++++--------- .../t8_gtest_ghost_exchange_stdvector.cxx | 12 ++- .../t8_step5_element_data_vector_input.cxx | 15 ++-- 4 files changed, 96 insertions(+), 87 deletions(-) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index ebf167f864..b1d2f4a536 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -24,16 +24,15 @@ * Basic conversion routines for std::vector to t8code data types. */ - #ifndef T8_STDVECTOR_CONVERSION_H #define T8_STDVECTOR_CONVERSION_H -#include -#include +#include +#include #include /* Template to create sc_array view from vector*/ template -sc_array_t* +sc_array_t * t8_create_sc_array_view_from_vector (const std::vector &vector) { void *vector_data = (void *) vector.data (); @@ -43,8 +42,9 @@ t8_create_sc_array_view_from_vector (const std::vector &vector) /* Wrapper function for partition data */ template -void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t forest_to, - const std::vector& data_in_vec, std::vector& data_out_vec) +void +t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t forest_to, const std::vector &data_in_vec, + std::vector &data_out_vec) { /* Create temporary sc array. */ sc_array_t *data_in_view, *data_out_view; @@ -52,10 +52,10 @@ void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t fo T8_ASSERT (data_in_vec.size () == forest_from->local_num_elements); T8_ASSERT (data_out_vec.size () == forest_to->local_num_elements); - data_in_view = t8_create_sc_array_view_from_vector(data_in_vec); - data_out_view = t8_create_sc_array_view_from_vector(data_out_vec); - /* calling the original function with the sc_array_t view */ - t8_forest_partition_data(forest_from, forest_to, data_in_view, data_out_view); + data_in_view = t8_create_sc_array_view_from_vector (data_in_vec); + data_out_view = t8_create_sc_array_view_from_vector (data_out_vec); + /* calling the original function with the sc_array_t view */ + t8_forest_partition_data (forest_from, forest_to, data_in_view, data_out_view); /* Clean-up memory */ sc_array_destroy (data_in_view); @@ -64,34 +64,38 @@ void t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t fo /* Wrapper function for ghost exchange function */ template -void t8_forest_ghost_exchange_data_with_vector(t8_forest_t forest, const std::vector& element_vector) { - t8_debugf("Entering ghost_exchange_data_with_vector\n"); - T8_ASSERT(t8_forest_is_committed(forest)); +void +t8_forest_ghost_exchange_data_with_vector (t8_forest_t forest, const std::vector &element_vector) +{ + t8_debugf ("Entering ghost_exchange_data_with_vector\n"); + T8_ASSERT (t8_forest_is_committed (forest)); - /*Create sc_array_t view from the vector*/ - sc_array_t *element_data = t8_create_sc_array_view_from_vector(element_vector); + /*Create sc_array_t view from the vector*/ + sc_array_t *element_data = t8_create_sc_array_view_from_vector (element_vector); - /* calling the original function with the sc_array_t view */ - t8_forest_ghost_exchange_data(forest, element_data); + /* calling the original function with the sc_array_t view */ + t8_forest_ghost_exchange_data (forest, element_data); - /*Clean up the sc_array_t view*/ - sc_array_destroy(element_data); + /*Clean up the sc_array_t view*/ + sc_array_destroy (element_data); } -/*Wrapper function to handle std::vector directly for t8_forest_search*/ +/*Wrapper function to handle std::vector directly for t8_forest_search*/ template -void t8_forest_search_with_vector(t8_forest_t forest, t8_forest_search_query_fn search_fn, - t8_forest_search_query_fn query_fn, const std::vector& query_vector) { - t8_debugf("Entering t8_forest_search_with_vector\n"); - T8_ASSERT(t8_forest_is_committed(forest)); +void +t8_forest_search_with_vector (t8_forest_t forest, t8_forest_search_query_fn search_fn, + t8_forest_search_query_fn query_fn, const std::vector &query_vector) +{ + t8_debugf ("Entering t8_forest_search_with_vector\n"); + T8_ASSERT (t8_forest_is_committed (forest)); - /*Create sc_array_t view from the vector*/ - sc_array_t *queries = t8_create_sc_array_view_from_vector(query_vector); + /*Create sc_array_t view from the vector*/ + sc_array_t *queries = t8_create_sc_array_view_from_vector (query_vector); - /*calling the original t8_forest_search function with the sc_array_t view */ - t8_forest_search(forest, search_fn, query_fn, queries); + /*calling the original t8_forest_search function with the sc_array_t view */ + t8_forest_search (forest, search_fn, query_fn, queries); - /* Clean up the sc_array_t view */ - sc_array_destroy(queries); + /* Clean up the sc_array_t view */ + sc_array_destroy (queries); } -#endif // T8_STDVECTOR_CONVERSION_H \ No newline at end of file +#endif // T8_STDVECTOR_CONVERSION_H \ No newline at end of file diff --git a/test/t8_forest/stdvectortest.cxx b/test/t8_forest/stdvectortest.cxx index 0a44d1f5ab..3ee7063ca7 100644 --- a/test/t8_forest/stdvectortest.cxx +++ b/test/t8_forest/stdvectortest.cxx @@ -1,57 +1,65 @@ #include #include #include -#include // header for sc_array conversion -#include "sc_containers.h" // header for sc_array_t and related functions +#include // header for sc_array conversion +#include "sc_containers.h" // header for sc_array_t and related functions // Define sc_array_count function -size_t sc_array_count(const sc_array_t* sc_arr) { - return sc_arr->elem_count; // Access the count member +size_t +sc_array_count (const sc_array_t* sc_arr) +{ + return sc_arr->elem_count; // Access the count member } template -class VectorTest : public ::testing::Test { -protected: - void SetUp() override { - // Initialize the vector with some test values - vec = {T(1), T(2), T(3), T(4), T(5)}; - arr = vec.data(); - // Convert std::vector to sc_array - sc_arr = t8_create_sc_array_view_from_vector(vec); - } - - void TearDown() override { - // Clean up the sc_array to prevent memory leaks - sc_array_destroy(sc_arr); - } - - std::vector vec; // Standard vector - const T* arr; // Raw pointer to the vector data - sc_array_t* sc_arr; // Converted sc_array +class VectorTest: public ::testing::Test { + protected: + void + SetUp () override + { + // Initialize the vector with some test values + vec = { T (1), T (2), T (3), T (4), T (5) }; + arr = vec.data (); + // Convert std::vector to sc_array + sc_arr = t8_create_sc_array_view_from_vector (vec); + } + + void + TearDown () override + { + // Clean up the sc_array to prevent memory leaks + sc_array_destroy (sc_arr); + } + + std::vector vec; // Standard vector + const T* arr; // Raw pointer to the vector data + sc_array_t* sc_arr; // Converted sc_array }; -TYPED_TEST_SUITE_P(VectorTest); +TYPED_TEST_SUITE_P (VectorTest); -TYPED_TEST_P(VectorTest, LengthTest) { - // Test that the vector length is as expected - ASSERT_EQ(this->vec.size(), 5u) << "Vector length should be 5 for testing purposes"; - // Test that the sc_array length matches the vector length - ASSERT_EQ(sc_array_count(this->sc_arr), this->vec.size()) << "sc_array length should match vector length"; +TYPED_TEST_P (VectorTest, LengthTest) +{ + // Test that the vector length is as expected + ASSERT_EQ (this->vec.size (), 5u) << "Vector length should be 5 for testing purposes"; + // Test that the sc_array length matches the vector length + ASSERT_EQ (sc_array_count (this->sc_arr), this->vec.size ()) << "sc_array length should match vector length"; } -TYPED_TEST_P(VectorTest, ElementComparisonTest) { - for (size_t i = 0; i < this->vec.size(); ++i) { - // Compare elements in the vector - EXPECT_EQ(this->vec[i], this->arr[i]) << "Element mismatch at index " << i; - // Compare elements between the vector and sc_array - EXPECT_EQ(this->vec[i], *(reinterpret_cast(sc_array_index(this->sc_arr, i)))) - << "Element mismatch between vector and sc_array at index " << i; - } +TYPED_TEST_P (VectorTest, ElementComparisonTest) +{ + for (size_t i = 0; i < this->vec.size (); ++i) { + // Compare elements in the vector + EXPECT_EQ (this->vec[i], this->arr[i]) << "Element mismatch at index " << i; + // Compare elements between the vector and sc_array + EXPECT_EQ (this->vec[i], *(reinterpret_cast (sc_array_index (this->sc_arr, i)))) + << "Element mismatch between vector and sc_array at index " << i; + } } -REGISTER_TYPED_TEST_SUITE_P(VectorTest, LengthTest, ElementComparisonTest); +REGISTER_TYPED_TEST_SUITE_P (VectorTest, LengthTest, ElementComparisonTest); -typedef ::testing::Types MyTypes; -INSTANTIATE_TYPED_TEST_SUITE_P(MyVectorTests, VectorTest, MyTypes); +typedef ::testing::Types + MyTypes; +INSTANTIATE_TYPED_TEST_SUITE_P (MyVectorTests, VectorTest, MyTypes); diff --git a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx index f6a3ee4362..2929e07594 100644 --- a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx +++ b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx @@ -93,7 +93,7 @@ t8_test_ghost_exchange_data_id (t8_forest_t forest) t8_locidx_t num_elements = t8_forest_get_local_num_elements (forest); t8_locidx_t num_ghosts = t8_forest_get_num_ghosts (forest); /* Initialize a vector of the required size */ - std::vector element_data(num_elements + num_ghosts); + std::vector element_data (num_elements + num_ghosts); /* Fill the local element entries with their linear id */ for (t8_locidx_t itree = 0; itree < t8_forest_get_num_local_trees (forest); itree++) { @@ -131,7 +131,6 @@ t8_test_ghost_exchange_data_id (t8_forest_t forest) array_pos++; } } - } /* Construct a data array of ints for all elements and all ghosts, @@ -141,13 +140,13 @@ t8_test_ghost_exchange_data_id (t8_forest_t forest) static void t8_test_ghost_exchange_data_int (t8_forest_t forest) { - + t8_locidx_t num_elements = t8_forest_get_local_num_elements (forest); t8_locidx_t num_ghosts = t8_forest_get_num_ghosts (forest); - std::vector element_data(num_elements+num_ghosts); + std::vector element_data (num_elements + num_ghosts); /* Fill the local element entries with the integer 42 */ - std::fill(element_data.begin(), element_data.begin() + num_elements, 42); - + std::fill (element_data.begin (), element_data.begin () + num_elements, 42); + /* Perform the ghost data exchange */ t8_forest_ghost_exchange_data_with_vector (forest, element_data); @@ -157,7 +156,6 @@ t8_test_ghost_exchange_data_int (t8_forest_t forest) int ghost_int = element_data[num_elements + ielem]; ASSERT_EQ (ghost_int, 42) << "Error when exchanging ghost data. Received wrong data.\n"; } - } TEST_P (forest_ghost_exchange, test_ghost_exchange) diff --git a/tutorials/general/t8_step5_element_data_vector_input.cxx b/tutorials/general/t8_step5_element_data_vector_input.cxx index 1e3617a620..fef7744f3a 100644 --- a/tutorials/general/t8_step5_element_data_vector_input.cxx +++ b/tutorials/general/t8_step5_element_data_vector_input.cxx @@ -53,7 +53,6 @@ #include #include - T8_EXTERN_C_BEGIN (); /* The data that we want to store for each element. @@ -90,11 +89,11 @@ t8_step5_build_forest (sc_MPI_Comm comm, int level) return forest_apbg; } -std::vector t8_step5_create_element_data (t8_forest_t forest) +std::vector +t8_step5_create_element_data (t8_forest_t forest) { t8_locidx_t num_local_elements; t8_locidx_t num_ghost_elements; - /* Check that forest is a committed, that is valid and usable, forest. */ T8_ASSERT (t8_forest_is_committed (forest)); @@ -103,14 +102,14 @@ std::vector t8_step5_create_element_data (t8_forest_t num_local_elements = t8_forest_get_local_num_elements (forest); /* Get the number of ghost elements of forest. */ num_ghost_elements = t8_forest_get_num_ghosts (forest); -std::vector element_data (num_local_elements+num_ghost_elements); + std::vector element_data (num_local_elements + num_ghost_elements); /* Now we need to build an array of our data that is as long as the number * of elements plus the number of ghosts. You can use any allocator such as * new, malloc or the t8code provide allocation macro T8_ALLOC. * Note that in the latter case you need * to use T8_FREE in order to free the memory. */ - /* Note: We will later need to associate this data with an sc_array in order to exchange the values for + /* Note: We will later need to associate this data with an sc_array in order to exchange the values for * the ghost elements, which we can do with sc_array_new_data (see t8_step5_exchange_ghost_data). * We could also have directly allocated the data here in an sc_array with * sc_array_new_count (sizeof (struct data_per_element), num_local_elements + num_ghost_elements); @@ -168,13 +167,13 @@ std::vector element_data (num_local_elements+num_ghos * Calling this function will fill all the ghost entries of our element data array with the * value on the process that owns the corresponding element. */ static void -t8_step5_exchange_ghost_data (t8_forest_t forest, std::vector& data) +t8_step5_exchange_ghost_data (t8_forest_t forest, std::vector &data) { sc_array *sc_array_wrapper; - + /* t8_forest_ghost_exchange_data expects an sc_array (of length num_local_elements + num_ghosts). * We wrap our data array to an sc_array. */ - sc_array_wrapper = t8_create_sc_array_view_from_vector(data); + sc_array_wrapper = t8_create_sc_array_view_from_vector (data); /* Carry out the data exchange. The entries with indices > num_local_elements will get overwritten. */ From f39f2a0b827ff44ea5d80a934b39bb406dfcaaef Mon Sep 17 00:00:00 2001 From: Prasanna Date: Wed, 10 Jul 2024 14:39:21 +0200 Subject: [PATCH 17/33] modified makefile --- test/Makefile.am | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/test/Makefile.am b/test/Makefile.am index 9aa919eea6..8fc06190db 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -73,12 +73,6 @@ t8code_googletest_programs = \ test/t8_forest/t8_gtest_user_data \ test/t8_forest/t8_gtest_transform \ test/t8_forest/t8_gtest_ghost_exchange \ -<<<<<<< HEAD - test/t8_forest/t8_gtest_ghost_exchange_stdvector \ - test/t8_forest/stdvectortest \ -======= - test/t8_forest/t8_gtest_ghost_delete \ ->>>>>>> origin/main test/t8_forest/t8_gtest_ghost_and_owner \ test/t8_forest/t8_gtest_forest_commit \ test/t8_forest/t8_gtest_balance \ @@ -283,20 +277,6 @@ test_t8_forest_t8_gtest_ghost_exchange_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_exchange.cxx -<<<<<<< HEAD -test_t8_forest_t8_gtest_ghost_exchange_stdvector_SOURCES = \ - test/t8_gtest_main.cxx \ - test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx - -test_t8_forest_stdvectortest_SOURCES = \ - test/t8_gtest_main.cxx \ - test/t8_forest/stdvectortest.cxx -======= -test_t8_forest_t8_gtest_ghost_delete_SOURCES = \ - test/t8_gtest_main.cxx \ - test/t8_forest/t8_gtest_ghost_delete.cxx ->>>>>>> origin/main - test_t8_forest_t8_gtest_ghost_and_owner_SOURCES = \ test/t8_gtest_main.cxx \ test/t8_forest/t8_gtest_ghost_and_owner.cxx @@ -549,20 +529,6 @@ test_t8_forest_t8_gtest_ghost_exchange_LDADD = $(t8_gtest_target_ld_add) test_t8_forest_t8_gtest_ghost_exchange_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS = $(t8_gtest_target_cpp_flags) -<<<<<<< HEAD -test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDADD = $(t8_gtest_target_ld_add) -test_t8_forest_t8_gtest_ghost_exchange_stdvector_LDFLAGS = $(t8_gtest_target_ld_flags) -test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS = $(t8_gtest_target_cpp_flags) - -test_t8_forest_stdvectortest_LDADD = $(t8_gtest_target_ld_add) -test_t8_forest_stdvectortest_LDFLAGS = $(t8_gtest_target_ld_flags) -test_t8_forest_stdvectortest_CPPFLAGS = $(t8_gtest_target_cpp_flags) -======= -test_t8_forest_t8_gtest_ghost_delete_LDADD = $(t8_gtest_target_ld_add) -test_t8_forest_t8_gtest_ghost_delete_LDFLAGS = $(t8_gtest_target_ld_flags) -test_t8_forest_t8_gtest_ghost_delete_CPPFLAGS = $(t8_gtest_target_cpp_flags) ->>>>>>> origin/main - test_t8_forest_t8_gtest_ghost_and_owner_LDADD = $(t8_gtest_target_ld_add) test_t8_forest_t8_gtest_ghost_and_owner_LDFLAGS = $(t8_gtest_target_ld_flags) test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS = $(t8_gtest_target_cpp_flags) @@ -675,12 +641,6 @@ test_t8_geometry_t8_gtest_point_inside_CPPFLAGS += $(t8_gtest_target_mpi_cpp_fla test_t8_forest_t8_gtest_user_data_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_transform_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_ghost_exchange_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) -<<<<<<< HEAD -test_t8_forest_t8_gtest_ghost_exchange_stdvector_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) -test_t8_forest_stdvectortest_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) -======= -test_t8_forest_t8_gtest_ghost_delete_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) ->>>>>>> origin/main test_t8_forest_t8_gtest_ghost_and_owner_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_forest_commit_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) test_t8_forest_t8_gtest_balance_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags) From 01f7148d8c986780404d04b50d51d071a45c9f0e Mon Sep 17 00:00:00 2001 From: Prasanna Date: Tue, 16 Jul 2024 13:04:13 +0200 Subject: [PATCH 18/33] renamed t8_default header due to Sandro's recent PR --- tutorials/general/t8_step5_element_data_vector_input.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/general/t8_step5_element_data_vector_input.cxx b/tutorials/general/t8_step5_element_data_vector_input.cxx index fef7744f3a..f0d8e3f3f1 100644 --- a/tutorials/general/t8_step5_element_data_vector_input.cxx +++ b/tutorials/general/t8_step5_element_data_vector_input.cxx @@ -48,7 +48,7 @@ #include /* forest definition and basic interface. */ #include /* save forest */ #include /* geometrical information */ -#include /* default refinement scheme. */ +#include /* default refinement scheme. */ #include #include #include From f9fd0a6f3b11014b3139320b22b3e5f4a99e2d9d Mon Sep 17 00:00:00 2001 From: Prasanna Date: Tue, 16 Jul 2024 13:28:33 +0200 Subject: [PATCH 19/33] indented files again --- .../general/t8_step5_element_data_vector_input.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tutorials/general/t8_step5_element_data_vector_input.cxx b/tutorials/general/t8_step5_element_data_vector_input.cxx index f0d8e3f3f1..0c099c8082 100644 --- a/tutorials/general/t8_step5_element_data_vector_input.cxx +++ b/tutorials/general/t8_step5_element_data_vector_input.cxx @@ -42,12 +42,12 @@ * data into the output file. * */ -#include /* General t8code header, always include this. */ -#include /* cmesh definition and basic interface. */ -#include /* A collection of exemplary cmeshes */ -#include /* forest definition and basic interface. */ -#include /* save forest */ -#include /* geometrical information */ +#include /* General t8code header, always include this. */ +#include /* cmesh definition and basic interface. */ +#include /* A collection of exemplary cmeshes */ +#include /* forest definition and basic interface. */ +#include /* save forest */ +#include /* geometrical information */ #include /* default refinement scheme. */ #include #include From 42225d0fdd6618fa7b48e96981b7b0d801c5c3c7 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Tue, 16 Jul 2024 14:31:15 +0200 Subject: [PATCH 20/33] Updated t8_gtest_ghost_exchange_stdvector file --- .../t8_gtest_ghost_exchange_stdvector.cxx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx index 2929e07594..00d8076687 100644 --- a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx +++ b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx @@ -22,13 +22,14 @@ #include #include -#include +#include #include #include #include #include #include -#include "t8_cmesh/t8_cmesh_testcases.h" +#include "test/t8_cmesh_generator/t8_cmesh_example_sets.hxx" +#include #include /* TODO: when this test works for all cmeshes remove if statement in test_cmesh_ghost_exchange_all () */ @@ -43,16 +44,18 @@ * in a second test, we store the element's linear id in the data array. */ -class forest_ghost_exchange: public testing::TestWithParam { +class forest_ghost_exchange: public testing::TestWithParam { protected: void SetUp () override { - cmesh_id = GetParam (); - scheme = t8_scheme_new_default_cxx (); /* Construct a cmesh */ - cmesh = t8_test_create_cmesh (cmesh_id); + cmesh = GetParam ()->cmesh_create (); + if (t8_cmesh_is_empty (cmesh)) { + /* empty cmeshes are currently not supported */ + GTEST_SKIP (); + } } void TearDown () override @@ -60,11 +63,9 @@ class forest_ghost_exchange: public testing::TestWithParam { t8_cmesh_destroy (&cmesh); t8_scheme_cxx_unref (&scheme); } - int cmesh_id; t8_scheme_cxx_t *scheme; t8_cmesh_t cmesh; }; - static int t8_test_exchange_adapt (t8_forest_t forest, t8_forest_t forest_from, t8_locidx_t which_tree, t8_locidx_t lelement_id, t8_eclass_scheme_c *ts, const int is_family, const int num_elements, t8_element_t *elements[]) @@ -165,7 +166,7 @@ TEST_P (forest_ghost_exchange, test_ghost_exchange) int min_level = t8_forest_min_nonempty_level (cmesh, scheme); /* we start with an empty level */ min_level = SC_MAX (min_level - 1, 0); - t8_debugf ("Testing ghost exchange start level %i. cmesh_id = %i\n", min_level, cmesh_id); + for (int level = min_level; level < min_level + 3; level++) { /* ref the scheme since we reuse it */ t8_scheme_cxx_ref (scheme); @@ -185,5 +186,4 @@ TEST_P (forest_ghost_exchange, test_ghost_exchange) } } -INSTANTIATE_TEST_SUITE_P (t8_gtest_ghost_exchange, forest_ghost_exchange, - testing::Range (0, t8_get_number_of_all_testcases ())); +INSTANTIATE_TEST_SUITE_P (t8_gtest_ghost_exchange, forest_ghost_exchange, AllCmeshsParam, pretty_print_base_example); \ No newline at end of file From a5ae2ddb113000151b0651aab7582ca82b915485 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Wed, 17 Jul 2024 11:11:04 +0200 Subject: [PATCH 21/33] fixed errors --- src/t8_data/t8_stdvector_conversion.hxx | 1 + test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index b1d2f4a536..5f60fbaadd 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -28,6 +28,7 @@ #define T8_STDVECTOR_CONVERSION_H #include #include +#include #include /* Template to create sc_array view from vector*/ diff --git a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx index 00d8076687..782498546c 100644 --- a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx +++ b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx @@ -166,7 +166,7 @@ TEST_P (forest_ghost_exchange, test_ghost_exchange) int min_level = t8_forest_min_nonempty_level (cmesh, scheme); /* we start with an empty level */ min_level = SC_MAX (min_level - 1, 0); - + for (int level = min_level; level < min_level + 3; level++) { /* ref the scheme since we reuse it */ t8_scheme_cxx_ref (scheme); From 50a4a364fd2ecc37146198aacb8e4608b32dbafa Mon Sep 17 00:00:00 2001 From: "Dreyer, Lukas" Date: Wed, 17 Jul 2024 15:25:46 +0200 Subject: [PATCH 22/33] Remove warnings --- src/t8_data/t8_stdvector_conversion.hxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index 5f60fbaadd..b1fb247f39 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -50,8 +50,8 @@ t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t forest_ /* Create temporary sc array. */ sc_array_t *data_in_view, *data_out_view; - T8_ASSERT (data_in_vec.size () == forest_from->local_num_elements); - T8_ASSERT (data_out_vec.size () == forest_to->local_num_elements); + T8_ASSERT (data_in_vec.size () == t8_forest_get_local_num_elements (forest_from)); + T8_ASSERT (data_out_vec.size () == t8_forest_get_local_num_elements (forest_to)); data_in_view = t8_create_sc_array_view_from_vector (data_in_vec); data_out_view = t8_create_sc_array_view_from_vector (data_out_vec); From 1a6b92fc3e3dfed53c230d2909f46ae42c159aee Mon Sep 17 00:00:00 2001 From: "Dreyer, Lukas" Date: Wed, 17 Jul 2024 15:49:47 +0200 Subject: [PATCH 23/33] Add empty parameter to variadic macro in order to satisfy ISO C standard --- test/t8_forest/stdvectortest.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/t8_forest/stdvectortest.cxx b/test/t8_forest/stdvectortest.cxx index 3ee7063ca7..244d6aac0b 100644 --- a/test/t8_forest/stdvectortest.cxx +++ b/test/t8_forest/stdvectortest.cxx @@ -59,7 +59,7 @@ TYPED_TEST_P (VectorTest, ElementComparisonTest) REGISTER_TYPED_TEST_SUITE_P (VectorTest, LengthTest, ElementComparisonTest); -typedef ::testing::Types - MyTypes; -INSTANTIATE_TYPED_TEST_SUITE_P (MyVectorTests, VectorTest, MyTypes); +using MyTypes = ::testing::Types; + +INSTANTIATE_TYPED_TEST_SUITE_P (MyVectorTests, VectorTest, MyTypes, ); From 0fcfc7f129eb1db4e4971a504034e683af19ffb2 Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:52:05 +0200 Subject: [PATCH 24/33] Update test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx Co-authored-by: David Knapp --- test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx index 782498546c..c01ba8e4c1 100644 --- a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx +++ b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx @@ -3,7 +3,7 @@ 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) 2015 the developers + 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 From 1bf3f4621491e34eec7c1caf4621b1858341fd6e Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:52:34 +0200 Subject: [PATCH 25/33] Update src/t8_data/t8_stdvector_conversion.hxx Co-authored-by: David Knapp --- src/t8_data/t8_stdvector_conversion.hxx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index b1fb247f39..7ce3d028e7 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -68,7 +68,6 @@ template void t8_forest_ghost_exchange_data_with_vector (t8_forest_t forest, const std::vector &element_vector) { - t8_debugf ("Entering ghost_exchange_data_with_vector\n"); T8_ASSERT (t8_forest_is_committed (forest)); /*Create sc_array_t view from the vector*/ From 13919cd2ac50adc8060702f2d5808c3f05880dcd Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:07:33 +0200 Subject: [PATCH 26/33] license statements for stdvectortest.cxx --- test/t8_forest/stdvectortest.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/t8_forest/stdvectortest.cxx b/test/t8_forest/stdvectortest.cxx index 244d6aac0b..767ba19f62 100644 --- a/test/t8_forest/stdvectortest.cxx +++ b/test/t8_forest/stdvectortest.cxx @@ -1,3 +1,24 @@ +/* + 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. +*/ #include #include #include From ffce2b88c1faaac628a57bb562db7061fa8ec0d5 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Mon, 14 Oct 2024 12:46:22 +0200 Subject: [PATCH 27/33] added in cmake list and indented --- src/CMakeLists.txt | 3 +++ src/t8_data/t8_stdvector_conversion.hxx | 2 +- test/CMakeLists.txt | 3 +++ test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx | 2 +- tutorials/CMakeLists.txt | 3 ++- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6cc4516e49..2a1c6e359c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -191,6 +191,9 @@ install( FILES t8_vec.h t8_version.h t8_vtk.h + src/t8_data/t8_shmem.h + src/t8_data/t8_containers.h + src/t8_data/t8_stdvector_conversion.hxx t8_windows.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include ) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index 7ce3d028e7..d47c0082dd 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -98,4 +98,4 @@ t8_forest_search_with_vector (t8_forest_t forest, t8_forest_search_query_fn sear /* Clean up the sc_array_t view */ sc_array_destroy (queries); } -#endif // T8_STDVECTOR_CONVERSION_H \ No newline at end of file +#endif // T8_STDVECTOR_CONVERSION_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 975a7de94d..4f0a871ee2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,6 +61,9 @@ add_t8_test( NAME t8_gtest_forest_commit SOURCES t8_gtest_main.cxx t add_t8_test( NAME t8_gtest_forest_face_normal SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_forest_face_normal.cxx ) add_t8_test( NAME t8_gtest_element_is_leaf SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_element_is_leaf.cxx ) add_t8_test( NAME t8_gtest_partition_data SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_partition_data.cxx ) +add_t8_test( NAME stdvectortest SOURCES t8_gtest_main.cxx t8_forest/stdvectortest.cxx ) +add_t8_test( NAME t8_gtest_ghost_exchange_stdvector SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_ghost_exchange_stdvector.cxx ) + add_t8_test( NAME t8_gtest_permute_hole SOURCES t8_gtest_main.cxx t8_forest_incomplete/t8_gtest_permute_hole.cxx ) add_t8_test( NAME t8_gtest_recursive SOURCES t8_gtest_main.cxx t8_forest_incomplete/t8_gtest_recursive.cxx ) diff --git a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx index c01ba8e4c1..d98c3e12bd 100644 --- a/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx +++ b/test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx @@ -186,4 +186,4 @@ TEST_P (forest_ghost_exchange, test_ghost_exchange) } } -INSTANTIATE_TEST_SUITE_P (t8_gtest_ghost_exchange, forest_ghost_exchange, AllCmeshsParam, pretty_print_base_example); \ No newline at end of file +INSTANTIATE_TEST_SUITE_P (t8_gtest_ghost_exchange, forest_ghost_exchange, AllCmeshsParam, pretty_print_base_example); diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index ec38320344..fb2ca45050 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -21,4 +21,5 @@ add_t8_tutorial( NAME t8_step6_stencil SOURCES general/t8_step6 add_t8_tutorial( NAME t8_step7_interpolation SOURCES general/t8_step7_main.cxx general/t8_step7_interpolation.cxx ) add_t8_tutorial( NAME t8_tutorial_build_cmesh SOURCES general/t8_tutorial_build_cmesh.cxx general/t8_tutorial_build_cmesh_main.cxx) add_t8_tutorial( NAME t8_tutorial_search SOURCES general/t8_tutorial_search.cxx general/t8_step3_adapt_forest.cxx ) -add_t8_tutorial( NAME t8_features_curved_meshes SOURCES features/t8_features_curved_meshes.cxx) \ No newline at end of file +add_t8_tutorial( NAME t8_features_curved_meshes SOURCES features/t8_features_curved_meshes.cxx) +add_t8_tutorial( NAME t8_step5_element_data_vector_input SOURCES general/t8_step5_element_data_vector_input.cxx) \ No newline at end of file From 68aca00cf2a72491195ec514bdd9408d07037cf1 Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:20:04 +0100 Subject: [PATCH 28/33] Update CMakeLists.txt --- test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 14304771c3..c4c191917d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -141,7 +141,6 @@ add_t8_test( NAME t8_gtest_child_parent_face SOURCES t8_gtest_main.cxx t8_sc add_t8_test( NAME t8_gtest_pack_unpack SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_pack_unpack.cxx ) add_t8_test( NAME t8_gtest_root SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_root.cxx ) add_t8_test( NAME t8_gtest_scheme_consistency SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_scheme_consistency.cxx ) -======= add_t8_test( NAME t8_gtest_cmesh_bcast_parallel SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_bcast.cxx ) add_t8_test( NAME t8_gtest_eclass_serial SOURCES t8_gtest_main.cxx t8_gtest_eclass.cxx ) add_t8_test( NAME t8_gtest_vec_serial SOURCES t8_gtest_main.cxx t8_gtest_vec.cxx ) From 00605c5c29aa0bde85eae86db1351bfa82f7c254 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Thu, 31 Oct 2024 15:38:01 +0100 Subject: [PATCH 29/33] updated t8_forest_search_fn --- src/t8_data/t8_stdvector_conversion.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index d47c0082dd..93809e0f8b 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -83,7 +83,7 @@ t8_forest_ghost_exchange_data_with_vector (t8_forest_t forest, const std::vector /*Wrapper function to handle std::vector directly for t8_forest_search*/ template void -t8_forest_search_with_vector (t8_forest_t forest, t8_forest_search_query_fn search_fn, +t8_forest_search_with_vector (t8_forest_t forest, t8_forest_search_fn search_fn, t8_forest_search_query_fn query_fn, const std::vector &query_vector) { t8_debugf ("Entering t8_forest_search_with_vector\n"); From 239857c5cf111b6769812b6c6ae8d62dc8f1d880 Mon Sep 17 00:00:00 2001 From: Prasanna Ponnusamy <112905663+Prasanna-Ponnusamy@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:57:45 +0100 Subject: [PATCH 30/33] Update Makefile.am --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index cadfe29bef..5f86ae6f84 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,7 +45,7 @@ libt8_installed_headers_cmesh = \ src/t8_cmesh/t8_cmesh_stash.h libt8_installed_headers_data = \ src/t8_data/t8_shmem.h src/t8_data/t8_containers.h \ - src/t8_data/t8_stdvector_conversion.hxx + src/t8_data/t8_stdvector_conversion.hxx \ src/t8_data/t8_element_array_iterator.hxx libt8_installed_headers_forest = \ src/t8_forest/t8_forest.h \ From a9b839530be8e720f62bb3c5126fe6af49e3b5c3 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Thu, 31 Oct 2024 15:58:57 +0100 Subject: [PATCH 31/33] updated query fn --- src/t8_data/t8_stdvector_conversion.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index 93809e0f8b..3d29bb461a 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -84,7 +84,7 @@ t8_forest_ghost_exchange_data_with_vector (t8_forest_t forest, const std::vector template void t8_forest_search_with_vector (t8_forest_t forest, t8_forest_search_fn search_fn, - t8_forest_search_query_fn query_fn, const std::vector &query_vector) + t8_forest_query_fn query_fn, const std::vector &query_vector) { t8_debugf ("Entering t8_forest_search_with_vector\n"); T8_ASSERT (t8_forest_is_committed (forest)); From 40d17ca3e9aabe4504bc0fc8b70d88b514c739d1 Mon Sep 17 00:00:00 2001 From: Prasanna Date: Thu, 31 Oct 2024 16:50:36 +0100 Subject: [PATCH 32/33] corrected cmake and indented --- src/t8_data/t8_stdvector_conversion.hxx | 4 ++-- tutorials/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/t8_data/t8_stdvector_conversion.hxx b/src/t8_data/t8_stdvector_conversion.hxx index 3d29bb461a..d94d97b32f 100644 --- a/src/t8_data/t8_stdvector_conversion.hxx +++ b/src/t8_data/t8_stdvector_conversion.hxx @@ -83,8 +83,8 @@ t8_forest_ghost_exchange_data_with_vector (t8_forest_t forest, const std::vector /*Wrapper function to handle std::vector directly for t8_forest_search*/ template void -t8_forest_search_with_vector (t8_forest_t forest, t8_forest_search_fn search_fn, - t8_forest_query_fn query_fn, const std::vector &query_vector) +t8_forest_search_with_vector (t8_forest_t forest, t8_forest_search_fn search_fn, t8_forest_query_fn query_fn, + const std::vector &query_vector) { t8_debugf ("Entering t8_forest_search_with_vector\n"); T8_ASSERT (t8_forest_is_committed (forest)); diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index cd6d2d0510..ea0ae932c3 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -44,7 +44,7 @@ add_t8_tutorial( NAME t8_step7_interpolation SOURCES general/t8_step7 add_t8_tutorial( NAME t8_tutorial_build_cmesh SOURCES general/t8_tutorial_build_cmesh.cxx general/t8_tutorial_build_cmesh_main.cxx) add_t8_tutorial( NAME t8_tutorial_search SOURCES general/t8_tutorial_search.cxx general/t8_step3_adapt_forest.cxx ) add_t8_tutorial( NAME t8_features_curved_meshes SOURCES features/t8_features_curved_meshes.cxx) -add_t8_tutorial( NAME t8_step5_element_data_vector_input SOURCES general/t8_step5_element_data_vector_input.cxx) +add_t8_tutorial( NAME t8_step5_element_data_vector_input SOURCES general/t8_step5_main.cxx general/t8_step3_adapt_forest.cxx general/t8_step5_element_data_vector_input.cxx) copy_tutorial_file (features/t8_features_curved_meshes_generate_cmesh_hex.geo) copy_tutorial_file (features/t8_features_curved_meshes_generate_cmesh_quad.geo) From 4ebd88278eca64fd5c4187099915145348f74aba Mon Sep 17 00:00:00 2001 From: Prasanna Date: Mon, 4 Nov 2024 10:45:38 +0100 Subject: [PATCH 33/33] updated cmakefile --- src/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ff69fc337d..899c014f74 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -195,9 +195,6 @@ install( FILES t8_vec.h t8_version.h t8_vtk.h - src/t8_data/t8_shmem.h - src/t8_data/t8_containers.h - src/t8_data/t8_stdvector_conversion.hxx t8_windows.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include )