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

Create a view for std_vector input #1022

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 56 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
94 changes: 94 additions & 0 deletions src/t8_data/t8_stdvector_conversion.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
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 <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;
}
/* Wrapper function for partition data */
template <typename T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hope it is clear now. If not please let me know.

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 () == 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);

/* Clean-up memory */
sc_array_destroy (data_in_view);
sc_array_destroy (data_out_view);
}
/* 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_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);

/* 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 <typename T>
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<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
3 changes: 1 addition & 2 deletions src/t8_forest/t8_forest_partition.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <t8_forest/t8_forest_general.h>
#include <t8_cmesh/t8_cmesh_offset.h>
#include <t8_element_cxx.hxx>

/* We want to export the whole implementation to be callable from "C" */
T8_EXTERN_C_BEGIN ();

Expand Down Expand Up @@ -1208,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;
Expand Down
5 changes: 5 additions & 0 deletions tutorials/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
Loading
Loading