Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test with vector as input #1059

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
4fbcbce
Create a view for std_vector input
Prasanna-Ponnusamy Apr 10, 2024
1d98463
create a view of sc_array
Prasanna-Ponnusamy Apr 11, 2024
c7ee3e8
revised version with wrappers for forest search and ghost exchange
Prasanna-Ponnusamy Apr 11, 2024
c69421a
Update t8_forest_partition.cxx
Prasanna-Ponnusamy Apr 11, 2024
f878708
Update t8_forest_partition.cxx
Prasanna-Ponnusamy Apr 11, 2024
bbe995d
Example with vector input
Prasanna-Ponnusamy May 2, 2024
59f89bf
Merge branch 'sc_array-view' of github.com:DLR-AMR/t8code into sc_arr…
Prasanna-Ponnusamy May 2, 2024
6d54516
test for ghost exchange using std vector as input
Prasanna-Ponnusamy May 3, 2024
a301b5f
Delete .vscode/settings.json
Prasanna-Ponnusamy May 8, 2024
c167a8b
Update src/t8_data/t8_stdvector_conversion.hxx
Prasanna-Ponnusamy May 8, 2024
0615a3c
Update src/t8_data/t8_stdvector_conversion.hxx
Prasanna-Ponnusamy Jun 5, 2024
a9559cb
Update src/t8_data/t8_stdvector_conversion.hxx
Prasanna-Ponnusamy Jun 5, 2024
6fb9f94
Update src/t8_forest/t8_forest_partition.cxx
Prasanna-Ponnusamy Jun 5, 2024
d9d26d6
made a test to compare parameters between std vector and array
Prasanna-Ponnusamy Jun 24, 2024
443eca4
Revert "made a test to compare parameters between std vector and array"
Prasanna-Ponnusamy Jun 24, 2024
4651ca7
comparing parameters between stdvector and sc_array
Prasanna-Ponnusamy Jun 24, 2024
90b3527
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jun 25, 2024
e5602b1
Merge remote-tracking branch 'origin/main' into test-with-vector-as-i…
Prasanna-Ponnusamy Jul 10, 2024
12c59d3
indented files
Prasanna-Ponnusamy Jul 10, 2024
f39f2a0
modified makefile
Prasanna-Ponnusamy Jul 10, 2024
fdd9b50
Merge branch 'test-with-vector-as-input' of github.com:DLR-AMR/t8code…
Prasanna-Ponnusamy Jul 10, 2024
aed1e8b
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 12, 2024
01f7148
renamed t8_default header due to Sandro's recent PR
Prasanna-Ponnusamy Jul 16, 2024
cd61488
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 16, 2024
f9fd0a6
indented files again
Prasanna-Ponnusamy Jul 16, 2024
42225d0
Updated t8_gtest_ghost_exchange_stdvector file
Prasanna-Ponnusamy Jul 16, 2024
5c3f71b
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 16, 2024
a5ae2dd
fixed errors
Prasanna-Ponnusamy Jul 17, 2024
1a177eb
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 17, 2024
81fa33a
Merge branch 'test-with-vector-as-input' of github.com:DLR-AMR/t8code…
Prasanna-Ponnusamy Jul 17, 2024
50a4a36
Remove warnings
lukasdreyer Jul 17, 2024
ebfba6c
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Jul 17, 2024
1a6b92f
Add empty parameter to variadic macro in order to satisfy ISO C standard
lukasdreyer Jul 17, 2024
56a5eb4
Merge branch 'test-with-vector-as-input' of github.com:DLR-AMR/t8code…
lukasdreyer Jul 17, 2024
0fcfc7f
Update test/t8_forest/t8_gtest_ghost_exchange_stdvector.cxx
Prasanna-Ponnusamy Aug 14, 2024
1bf3f46
Update src/t8_data/t8_stdvector_conversion.hxx
Prasanna-Ponnusamy Aug 14, 2024
13919cd
license statements for stdvectortest.cxx
Prasanna-Ponnusamy Aug 14, 2024
bf43faa
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Aug 14, 2024
ffce2b8
added in cmake list and indented
Prasanna-Ponnusamy Oct 14, 2024
09ff5a3
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Oct 14, 2024
6248193
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Oct 31, 2024
68aca00
Update CMakeLists.txt
Prasanna-Ponnusamy Oct 31, 2024
00605c5
updated t8_forest_search_fn
Prasanna-Ponnusamy Oct 31, 2024
239857c
Update Makefile.am
Prasanna-Ponnusamy Oct 31, 2024
a9b8395
updated query fn
Prasanna-Ponnusamy Oct 31, 2024
c0fc424
Merge branch 'test-with-vector-as-input' of github.com:DLR-AMR/t8code…
Prasanna-Ponnusamy Oct 31, 2024
40d17ca
corrected cmake and indented
Prasanna-Ponnusamy Oct 31, 2024
4ebd882
updated cmakefile
Prasanna-Ponnusamy Nov 4, 2024
467e5cf
Merge branch 'main' into test-with-vector-as-input
Prasanna-Ponnusamy Nov 4, 2024
3b77547
Merge branch 'main' into test-with-vector-as-input
Davknapp Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +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_element_array_iterator.hxx
libt8_installed_headers_forest = \
src/t8_forest/t8_forest.h \
Expand Down
101 changes: 101 additions & 0 deletions src/t8_data/t8_stdvector_conversion.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
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 <t8_forest/t8_forest_partition.h>
#include <t8_forest/t8_forest_iterate.h>
#include <t8_forest/t8_forest_general.h>
#include <vector>

/* Template to create sc_array view from vector*/
template <typename T>
sc_array_t *
t8_create_sc_array_view_from_vector (const std::vector<T> &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;
}
Prasanna-Ponnusamy marked this conversation as resolved.
Show resolved Hide resolved

/* Wrapper function for partition data */
template <typename T>
void
t8_forest_partition_data_stdvector (t8_forest_t forest_from, t8_forest_t forest_to, const std::vector<T> &data_in_vec,
std::vector<T> &data_out_vec)
{
/* Create temporary sc array. */
sc_array_t *data_in_view, *data_out_view;

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);
/* 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);
}
Prasanna-Ponnusamy marked this conversation as resolved.
Show resolved Hide resolved

/* Wrapper function for ghost exchange function */
template <typename T>
void
t8_forest_ghost_exchange_data_with_vector (t8_forest_t forest, const std::vector<T> &element_vector)
{
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);

/* 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);
}
Prasanna-Ponnusamy marked this conversation as resolved.
Show resolved Hide resolved

/*Wrapper function to handle std::vector directly for t8_forest_search*/
template <typename T>
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<T> &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
78 changes: 78 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,84 @@ function( copy_test_file TEST_FILE_NAME )
configure_file(${CMAKE_CURRENT_LIST_DIR}/testfiles/${TEST_FILE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/test/testfiles/${TEST_FILE_NAME} COPYONLY)
endfunction()


add_t8_test( NAME t8_gtest_cmesh_bcast SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_bcast.cxx )
add_t8_test( NAME t8_gtest_eclass SOURCES t8_gtest_main.cxx t8_gtest_eclass.cxx )
add_t8_test( NAME t8_gtest_vec SOURCES t8_gtest_main.cxx t8_gtest_vec.cxx )
add_t8_test( NAME t8_gtest_mat SOURCES t8_gtest_main.cxx t8_gtest_mat.cxx )
add_t8_test( NAME t8_gtest_refcount SOURCES t8_gtest_main.cxx t8_gtest_refcount.cxx )
add_t8_test( NAME t8_gtest_occ_linkage SOURCES t8_gtest_main.cxx t8_gtest_occ_linkage.cxx )
add_t8_test( NAME t8_gtest_version SOURCES t8_gtest_main.cxx t8_gtest_version.cxx )
add_t8_test( NAME t8_gtest_basics SOURCES t8_gtest_main.cxx t8_gtest_basics.cxx )
add_t8_test( NAME t8_gtest_netcdf_linkage SOURCES t8_gtest_main.cxx t8_gtest_netcdf_linkage.cxx )
add_t8_test( NAME t8_gtest_vtk_linkage SOURCES t8_gtest_main.cxx t8_gtest_vtk_linkage.cxx )

add_t8_test( NAME t8_gtest_hypercube SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_hypercube.cxx )
add_t8_test( NAME t8_gtest_cmesh_readmshfile SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_cmesh_readmshfile.cxx )
add_t8_test( NAME t8_gtest_cmesh_copy SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_cmesh_copy.cxx )
add_t8_test( NAME t8_gtest_cmesh_face_is_boundary SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_cmesh_face_is_boundary.cxx )
add_t8_test( NAME t8_gtest_cmesh_partition SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_cmesh_partition.cxx )
add_t8_test( NAME t8_gtest_cmesh_set_partition_offsets SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_cmesh_set_partition_offsets.cxx )
add_t8_test( NAME t8_gtest_cmesh_set_join_by_vertices SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_cmesh_set_join_by_vertices.cxx )
add_t8_test( NAME t8_gtest_cmesh_add_attributes_when_derive SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_cmesh_add_attributes_when_derive.cxx )
add_t8_test( NAME t8_gtest_cmesh_tree_vertices_negative_volume SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_cmesh_tree_vertices_negative_volume.cxx )

add_t8_test( NAME t8_gtest_multiple_attributes SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_multiple_attributes.cxx )
add_t8_test( NAME t8_gtest_attribute_gloidx_array SOURCES t8_gtest_main.cxx t8_cmesh/t8_gtest_attribute_gloidx_array.cxx )

add_t8_test( NAME t8_gtest_shmem SOURCES t8_gtest_main.cxx t8_data/t8_gtest_shmem.cxx )

add_t8_test( NAME t8_gtest_element_volume SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_element_volume.cxx )
add_t8_test( NAME t8_gtest_search SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_search.cxx )
add_t8_test( NAME t8_gtest_half_neighbors SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_half_neighbors.cxx )
add_t8_test( NAME t8_gtest_find_owner SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_find_owner.cxx )
add_t8_test( NAME t8_gtest_user_data SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_user_data.cxx )
add_t8_test( NAME t8_gtest_transform SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_transform.cxx )
add_t8_test( NAME t8_gtest_ghost_exchange SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_ghost_exchange.cxx )
add_t8_test( NAME t8_gtest_ghost_delete SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_ghost_delete.cxx )
add_t8_test( NAME t8_gtest_ghost_and_owner SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_ghost_and_owner.cxx )
add_t8_test( NAME t8_gtest_balance SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_balance.cxx )
add_t8_test( NAME t8_gtest_forest_commit SOURCES t8_gtest_main.cxx t8_forest/t8_gtest_forest_commit.cxx )
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 )
add_t8_test( NAME t8_gtest_iterate_replace SOURCES t8_gtest_main.cxx t8_forest_incomplete/t8_gtest_iterate_replace.cxx )
add_t8_test( NAME t8_gtest_empty_local_tree SOURCES t8_gtest_main.cxx t8_forest_incomplete/t8_gtest_empty_local_tree.cxx )
add_t8_test( NAME t8_gtest_empty_global_tree SOURCES t8_gtest_main.cxx t8_forest_incomplete/t8_gtest_empty_global_tree.cxx )

add_t8_test( NAME t8_gtest_geometry_cad SOURCES t8_gtest_main.cxx t8_geometry/t8_geometry_implementations/t8_gtest_geometry_cad.cxx )
add_t8_test( NAME t8_gtest_geometry_linear SOURCES t8_gtest_main.cxx t8_geometry/t8_geometry_implementations/t8_gtest_geometry_linear.cxx )
add_t8_test( NAME t8_gtest_geometry_lagrange SOURCES t8_gtest_main.cxx t8_geometry/t8_geometry_implementations/t8_gtest_geometry_lagrange.cxx )
add_t8_test( NAME t8_gtest_geometry_handling SOURCES t8_gtest_main.cxx t8_geometry/t8_gtest_geometry_handling.cxx )
add_t8_test( NAME t8_gtest_point_inside SOURCES t8_gtest_main.cxx t8_geometry/t8_gtest_point_inside.cxx )

add_t8_test( NAME t8_gtest_vtk_reader SOURCES t8_gtest_main.cxx t8_IO/t8_gtest_vtk_reader.cxx )
add_t8_test( NAME t8_gtest_vtk_writer SOURCES t8_gtest_main.cxx t8_IO/t8_gtest_vtk_writer.cxx )

add_t8_test( NAME t8_gtest_nca SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_nca.cxx )
add_t8_test( NAME t8_gtest_pyra_connectivity SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_pyra_connectivity.cxx )
add_t8_test( NAME t8_gtest_face_neigh SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_face_neigh.cxx )
add_t8_test( NAME t8_gtest_init_linear_id SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_init_linear_id.cxx )
add_t8_test( NAME t8_gtest_ancestor SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_ancestor.cxx )
add_t8_test( NAME t8_gtest_element_count_leaves SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_element_count_leaves.cxx )
add_t8_test( NAME t8_gtest_element_ref_coords SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_element_ref_coords.cxx )
add_t8_test( NAME t8_gtest_descendant SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_descendant.cxx )
add_t8_test( NAME t8_gtest_find_parent SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_find_parent.cxx )
add_t8_test( NAME t8_gtest_equal SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_equal.cxx )
add_t8_test( NAME t8_gtest_successor SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_successor.cxx )
add_t8_test( NAME t8_gtest_boundary_extrude SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_boundary_extrude.cxx )
add_t8_test( NAME t8_gtest_face_descendant SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_face_descendant.cxx )
add_t8_test( NAME t8_gtest_default SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_default.cxx )
add_t8_test( NAME t8_gtest_child_parent_face SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_child_parent_face.cxx )
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 )
Expand Down
24 changes: 24 additions & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ 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/stdvectortest \
test/t8_forest/t8_gtest_ghost_delete \
test/t8_forest/t8_gtest_ghost_and_owner \
test/t8_forest/t8_gtest_forest_commit \
Expand Down Expand Up @@ -286,10 +288,20 @@ 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_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


test_t8_forest_t8_gtest_ghost_and_owner_SOURCES = \
test/t8_gtest_main.cxx \
test/t8_forest/t8_gtest_ghost_and_owner.cxx
Expand Down Expand Up @@ -554,6 +566,14 @@ 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_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)
Expand Down Expand Up @@ -678,7 +698,11 @@ 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_stdvectortest_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)
test_t8_forest_t8_gtest_ghost_delete_CPPFLAGS += $(t8_gtest_target_mpi_cpp_flags)

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)
Expand Down
86 changes: 86 additions & 0 deletions test/t8_forest/stdvectortest.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
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 <gtest/gtest.h>
Prasanna-Ponnusamy marked this conversation as resolved.
Show resolved Hide resolved
#include <vector>
#include <typeinfo>
#include <t8_data/t8_stdvector_conversion.hxx> // 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 <typename T>
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<T> 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<const TypeParam*> (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);

using MyTypes = ::testing::Types<int, double, float, char, short, long, long long, unsigned int, unsigned char,
unsigned short, unsigned long, unsigned long long>;

INSTANTIATE_TYPED_TEST_SUITE_P (MyVectorTests, VectorTest, MyTypes, );
Loading