Skip to content
Merged
Show file tree
Hide file tree
Changes from 138 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
d3e1e1b
Add header file and define cmesh vertex interface
holke Dec 8, 2023
4481299
Add header
chiaraMaHe Dec 8, 2023
3a5200e
New header vertex_to_tree
chiaraMaHe Dec 8, 2023
23918cd
add new header to makefile
holke Dec 19, 2023
40532f8
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Jan 11, 2024
94a55bb
started tree to vertex files
holke Jan 11, 2024
6f5b233
indentation
holke Jan 11, 2024
bdc0899
add a comment
holke Jan 11, 2024
e9b7479
indent
holke Jan 11, 2024
fd0c479
Start with implementation of global id setting for tree vertices
holke Jan 11, 2024
c18acf8
Merge branch 'feature-set_attribute_gloidx_array' into feature-cmesh_…
holke Jan 12, 2024
44bd495
Merge branch 'feature-set_attribute_gloidx_array' into feature-cmesh_…
holke Jan 12, 2024
0244a5b
Implement set and get global tree vertices
holke Jan 12, 2024
047ff64
Implement get_global_vertex
holke Jan 18, 2024
3231cf5
minor improvements
holke Feb 2, 2024
787e9a3
add test for tree to vertex - currently not working
holke Feb 2, 2024
030fef2
add testcase include and change include order in gtest_macros
holke Feb 2, 2024
8ae5f35
define data structures for tree to vertex
holke Feb 22, 2024
6bba129
add vtt to makefile
holke Feb 22, 2024
5b2ca50
rename file
holke Feb 22, 2024
f89ca03
add empty c file
holke Feb 22, 2024
f9cde0f
first implementations of vertex to tree set and get
holke Feb 22, 2024
022a5a4
move parameter declarations out of class
holke Feb 22, 2024
82544b1
typo
holke Feb 22, 2024
2bb6e19
start vertex to tree test
holke Feb 24, 2024
05cc31d
vtt setter public and cmesh must be committed
holke Feb 24, 2024
8608b0c
remove comments from test
holke Feb 24, 2024
b0c2c31
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Feb 24, 2024
ccfa081
fix merge
holke Feb 24, 2024
3d464e8
Sort vertex to tree
holke Feb 24, 2024
0f27f11
Add state committed/non-committed
holke Feb 24, 2024
129b7c5
also fill ghost tree in test
holke Feb 24, 2024
c130c4c
Implement test in single global id case
holke Feb 24, 2024
457ae38
indent
holke Feb 24, 2024
191fc97
Finalize test case with single global id
holke Feb 24, 2024
60adba6
make datypes class internal
holke Feb 24, 2024
1f6cc11
Add iterator over internal storage
holke Feb 24, 2024
5921d0a
Implement test for multiple global ids - wip
holke Feb 24, 2024
2d3d629
finalize test
holke Feb 24, 2024
faaf0db
Add vtt constructor from ttv
holke Feb 24, 2024
fbd8d49
const all the functions
holke Feb 24, 2024
cf40a8a
improve doc
holke Feb 24, 2024
d286aa6
Implement check that vtt contains all cmesh trees and vertices
holke Feb 24, 2024
0564d14
constructor for ttv from vtt
holke Feb 25, 2024
ded3641
Equality function and operator for vtt
holke Feb 27, 2024
0ab403c
indent
holke Feb 27, 2024
feca72c
New test for ttv: convert to vtt and back to ttv
holke Feb 27, 2024
f4a79c9
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Feb 27, 2024
4eae29e
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Mar 27, 2024
c10d4ae
change Makefiles to cmesh_commit.cxx
holke Mar 27, 2024
31358c8
Change test to new cmesh generator
holke Mar 27, 2024
b2d2109
Change second test to new cmesh generator
holke Mar 27, 2024
20f4531
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Mar 27, 2024
72a2da4
remove set state function, add struct keyword
holke Mar 27, 2024
a93082a
Only test vertices if there are vertices
holke Mar 27, 2024
e4a1ac2
indent
holke Mar 27, 2024
d0b0892
Merge branch 'feature-923_cmesh_add_attr_error' into feature-cmesh_ve…
holke Mar 27, 2024
c20c2f9
Use set_attribute in set_tree_vertices
holke Apr 2, 2024
4dcac79
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Apr 3, 2024
65bc316
Temporarily replace test with manual cmesh construction
holke Apr 4, 2024
2e64214
Disable ttv conversion test until 923 is resolved
holke Apr 4, 2024
2839296
Add comment that constructor does not work until issue 923 is resolved
holke Apr 4, 2024
89ed3b5
Add file and line to error
holke Apr 4, 2024
8d0bf17
Add a ttv test that checks conversion to vtt
holke Apr 4, 2024
9071560
add call of standard constructor to vtt constructor
holke Apr 4, 2024
38d4596
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Apr 24, 2024
a0b3707
Add a (non-compiling) test case for cmesh vertex connectivity
holke Apr 24, 2024
dedce21
update test - start adding functionality for general cmesh vertex access
holke Apr 24, 2024
9e0f03b
Add vertex_connectivity source and c header
holke Apr 24, 2024
2e4e6a8
converted to C compatible functions in tree_to_vertex test
jfussbro May 7, 2024
52d25bd
adapted cmesh_vertex_connectivity to be handled by cmesh
jfussbro May 7, 2024
52e7964
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
jfussbro May 7, 2024
68cb7c3
indent
jfussbro May 7, 2024
2bbe470
we now test the core classes and the cmesh functions for tree to vert…
jfussbro May 7, 2024
341f052
enabled vertex connectivity functionality (internal C++/external C)
jfussbro May 17, 2024
53ad20e
adapted vertex connectivity tests
jfussbro May 17, 2024
d44924b
minor changes
jfussbro May 17, 2024
76544d4
fix bug with uninitialized ttv
jfussbro May 17, 2024
5ef8163
Merge branch 'feature-cmesh_vertex_connectivity' of https://github.co…
dutkalex Oct 11, 2024
a0235ac
Merge pull request #1267 from dutkalex/main
holke Oct 14, 2024
40246ad
Merge remote-tracking branch 'origin/feature-cmesh_vertex_connectivit…
holke Oct 14, 2024
ef622db
indent and typo
holke Oct 14, 2024
4353f17
Merge remote-tracking branch 'origin/feature-cmesh_vertex_connectivit…
holke Oct 14, 2024
928eaf8
Merge branch 'main' into feature-cmesh_vertex_connectivity
sandro-elsweijer Jan 23, 2025
172ffd6
update copyright years
sandro-elsweijer Jan 27, 2025
f8f48da
remove pragma onces
sandro-elsweijer Jan 27, 2025
b954b20
update file descriptions
sandro-elsweijer Jan 27, 2025
5b3d05b
update docstrings
sandro-elsweijer Jan 27, 2025
d5316a9
format comments
sandro-elsweijer Jan 27, 2025
2b64381
update copyright years
sandro-elsweijer Jan 27, 2025
f0b6b82
Merge branch 'main' into feature-cmesh_vertex_connectivity
tunxu Feb 25, 2025
5e22227
Improve docstring
holke Mar 8, 2025
46fb5ac
Document unimplemented function
holke Mar 8, 2025
8d686f7
Merge remote-tracking branch 'origin/feature-cmesh_vertex_connectivit…
holke Mar 8, 2025
dc4120e
add missing const param
holke Mar 8, 2025
8356316
improve docstring of ttv constructor
holke Mar 8, 2025
8173b23
Inline functions in cmesh vertex conn
holke Mar 8, 2025
06ddacd
inlining requires us to move implementation into the header
holke Mar 8, 2025
40916af
More Const vars
holke Mar 8, 2025
562e560
Add cmesh committed check to some vtt functions
holke Mar 8, 2025
f5e9594
Add more docstrings
holke Mar 8, 2025
6f2e55d
Merge remote-tracking branch 'origin/feature-cmesh_vertex_connectivit…
holke Mar 8, 2025
25e3b1c
remove outdated comment
holke Mar 8, 2025
d105b16
Add EXTERN_C Begin and end
holke Mar 8, 2025
e9540dd
Document vertex connectivity and clean up interface from unnecessary …
holke Mar 8, 2025
907190b
Merge remote-tracking branch 'origin/feature-cmesh_vertex_connectivit…
holke Mar 8, 2025
6e78345
move extern c macros to header
holke Mar 8, 2025
a62b511
Fix bug in getting tree class for local tree or ghost
holke Mar 8, 2025
ea0db11
Add assertion for using replicated cmesh only - but only in c interfa…
holke Mar 8, 2025
309db66
typo
holke Mar 8, 2025
cc6d247
Merge branch 'main' into feature-cmesh_vertex_connectivity
sandro-elsweijer Mar 9, 2025
870ca30
Move vertex conn files into a subfolder
holke Mar 14, 2025
b5870bb
Proper docstring for vertex pair comparison
holke Mar 14, 2025
a3cbfc9
improve class documentation
holke Mar 14, 2025
6b58012
Use global id not local
holke Mar 14, 2025
a3e6c21
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Mar 14, 2025
62c3c75
update documentation
holke Mar 14, 2025
66c3879
make function inline
holke Mar 14, 2025
cbe8134
clean up inlining
holke Mar 14, 2025
f10c40f
more docstrings
holke Mar 14, 2025
c103cfe
remove empty line at EOF
holke Mar 14, 2025
48bff2b
move state getter to internal functions
holke Mar 14, 2025
6d0da99
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Apr 15, 2025
69ddf0f
Add a long comment in the test about the disabled tests
holke Apr 15, 2025
01f9be6
remove the DISABLED keyword. Tests are disabled via preprocessor
holke Apr 15, 2025
8e39cbe
remove const from return type since it is ignored and triggers a warning
holke Apr 15, 2025
e61f13e
unused qualifier for parameter of unimplemented function
holke Apr 15, 2025
b8d52d6
typo in qualifier
holke Apr 15, 2025
2b01c45
remove more const qualifiers in return value
holke Apr 15, 2025
a405ace
add unused directive to cmesh parameter used only in debugging mode
holke Apr 15, 2025
e5c758a
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke Apr 23, 2025
e4c5d6f
Add comment of test and reorder tests
holke Apr 23, 2025
3ac855c
Add (currently not supported) test for partitioned cmesh
holke Apr 25, 2025
1204bd1
Merge branch 'main' into feature-cmesh_vertex_connectivity
holke Apr 29, 2025
e5c9828
add comment about partitioned test and disable it
holke Apr 30, 2025
8d36153
fix wrong documentation
holke Apr 30, 2025
a534f27
Merge remote-tracking branch 'origin/feature-cmesh_vertex_connectivit…
holke Apr 30, 2025
edc319a
Merge remote-tracking branch 'origin/main' into feature-cmesh_vertex_…
holke May 5, 2025
c23baa6
Add docstring to two test cases
holke May 5, 2025
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
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ target_sources( T8 PRIVATE
t8_cmesh/t8_cmesh_examples.cxx
t8_cmesh/t8_cmesh_helpers.cxx
t8_cmesh/t8_cmesh_offset.c
t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_tree_to_vertex.cxx
t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_vertex_to_tree.cxx
t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.cxx
t8_cmesh/t8_cmesh_readmshfile.cxx
t8_data/t8_shmem.c
t8_data/t8_containers.cxx
Expand Down
8 changes: 7 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ libt8_internal_headers = \
src/t8_cmesh/t8_cmesh_trees.h src/t8_cmesh/t8_cmesh_partition.h \
src/t8_cmesh/t8_cmesh_copy.h \
src/t8_cmesh/t8_cmesh_offset.h \
src/t8_cmesh/t8_cmesh_vertex_connectivity.hxx \
src/t8_cmesh/t8_cmesh_vertex_conn_tree_to_vertex.hxx \
src/t8_cmesh/t8_cmesh_vertex_conn_vertex_to_tree.hxx \
src/t8_vtk/t8_vtk_polydata.hxx \
src/t8_vtk/t8_vtk_unstructured.hxx \
src/t8_vtk/t8_vtk_parallel.hxx \
Expand All @@ -119,7 +122,10 @@ libt8_compiled_sources = \
src/t8_cmesh/t8_cmesh_save.cxx \
src/t8_cmesh/t8_cmesh_netcdf.c \
src/t8_cmesh/t8_cmesh_trees.cxx src/t8_cmesh/t8_cmesh_commit.cxx \
src/t8_cmesh/t8_cmesh_partition.cxx\
src/t8_cmesh/t8_cmesh_vertex_conn_tree_to_vertex.cxx \
src/t8_cmesh/t8_cmesh_vertex_conn_vertex_to_tree.cxx \
src/t8_cmesh/t8_cmesh_vertex_connectivity.cxx \
src/t8_cmesh/t8_cmesh_partition.cxx \
src/t8_cmesh/t8_cmesh_copy.c src/t8_data/t8_shmem.c \
src/t8_cmesh/t8_cmesh_geometry.cxx \
src/t8_cmesh/t8_cmesh_examples.cxx \
Expand Down
2 changes: 2 additions & 0 deletions src/t8_cmesh/t8_cmesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <t8_cmesh.h>
#include <t8_cmesh/t8_cmesh_geometry.h>
#include <t8_geometry/t8_geometry_handler.hxx>
#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.hxx>
#include <t8_geometry/t8_geometry_implementations/t8_geometry_linear.h>
#include <t8_geometry/t8_geometry_implementations/t8_geometry_linear_axis_aligned.h>
#include <t8_schemes/t8_scheme.hxx>
Expand Down Expand Up @@ -204,6 +205,7 @@ t8_cmesh_init (t8_cmesh_t *pcmesh)
* It will get initialized either when a geometry is registered
* or when the cmesh gets committed. */
cmesh->geometry_handler = NULL;
cmesh->vertex_connectivity = new t8_cmesh_vertex_connectivity ();

T8_ASSERT (t8_cmesh_is_initialized (cmesh));
}
Expand Down
10 changes: 10 additions & 0 deletions src/t8_cmesh/t8_cmesh_commit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <t8_cmesh/t8_cmesh_copy.h>
#include <t8_cmesh/t8_cmesh_geometry.h>
#include <t8_geometry/t8_geometry_handler.hxx>
#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.hxx>

typedef struct ghost_facejoins_struct
{
Expand Down Expand Up @@ -582,6 +583,15 @@ t8_cmesh_commit (t8_cmesh_t cmesh, sc_MPI_Comm comm)
}
T8_ASSERT (cmesh->set_partition || cmesh->tree_offsets == NULL);

/* Build vertex_to_tree instance from the cmesh and a tree_to_vertex instance,
* but only if the vertex_to_tree instance is not yet committed
* and if the tree_to_vertex instance is not empty.
*/
if (cmesh->vertex_connectivity->get_vertex_to_tree_state () == 0
&& cmesh->vertex_connectivity->get_tree_to_vertex_state () == 1) {
cmesh->vertex_connectivity->build_vertex_to_tree (cmesh);
}

#if T8_ENABLE_DEBUG
t8_debugf ("Cmesh is %spartitioned.\n", cmesh->set_partition ? "" : "not ");
if (cmesh->set_partition) {
Expand Down
11 changes: 8 additions & 3 deletions src/t8_cmesh/t8_cmesh_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <t8_refcount.h>
#include <t8_data/t8_shmem.h>
#include <t8_geometry/t8_geometry.h>
#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.h>
#include "t8_cmesh_stash.h"
#include "t8_element.h"

Expand All @@ -51,9 +52,10 @@ typedef struct t8_cprofile t8_cprofile_t; /* Defined below */
/* Definitions for attribute identifiers that are reserved for a special purpose.
* T8_CMESH_NEXT_POSSIBLE_KEY is the first unused key, hence it can be repurposed for different attributes.*/
#define T8_CMESH_VERTICES_ATTRIBUTE_KEY 0 /* Used to store vertex coordinates. */
#define T8_CMESH_GEOMETRY_ATTRIBUTE_KEY 1 /* Used to store the name of a tree's geometry. */
#define T8_CMESH_CAD_EDGE_ATTRIBUTE_KEY 2 /* Used to store which edge is linked to which geometry */
#define T8_CMESH_CAD_EDGE_PARAMETERS_ATTRIBUTE_KEY 3 /* Used to store edge parameters */
#define T8_CMESH_GLOBAL_VERTICES_ATTRIBUTE_KEY 1 /* Used to store global vertex ids. */
#define T8_CMESH_GEOMETRY_ATTRIBUTE_KEY 2 /* Used to store the name of a tree's geometry. */
#define T8_CMESH_CAD_EDGE_ATTRIBUTE_KEY 3 /* Used to store which edge is linked to which geometry */
#define T8_CMESH_CAD_EDGE_PARAMETERS_ATTRIBUTE_KEY 4 /* Used to store edge parameters */
#define T8_CMESH_CAD_FACE_ATTRIBUTE_KEY \
T8_CMESH_CAD_EDGE_PARAMETERS_ATTRIBUTE_KEY \
+T8_ECLASS_MAX_EDGES /* Used to store which face is linked to which surface */
Expand Down Expand Up @@ -137,6 +139,9 @@ typedef struct t8_cmesh

t8_geometry_handler_c *geometry_handler; /**< Handles all geometries that are used by trees in this cmesh. */

struct t8_cmesh_vertex_connectivity
*vertex_connectivity; /**< Structure that manages tree_to_vertex and vertex_to_tree connectivity. */

#if T8_ENABLE_DEBUG
t8_locidx_t inserted_trees; /**< Count the number of inserted trees to
check at commit if it equals the total number. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
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) 2025 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_cmesh_conn_tree_to_vertex.cxx
* This file implements the routines for the t8_cmesh_conn_tree_to_vertex struct.
*/

#include <t8_cmesh.h>
#include <t8_cmesh/t8_cmesh_types.h>
#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_tree_to_vertex.hxx>

/* constructor from a given vertex to tree list. */
t8_cmesh_vertex_conn_tree_to_vertex::t8_cmesh_vertex_conn_tree_to_vertex (
const t8_cmesh_t cmesh_from, const t8_cmesh_t cmesh, const t8_cmesh_vertex_conn_vertex_to_tree &vtt)
: t8_cmesh_vertex_conn_tree_to_vertex ()
{
T8_ASSERT (t8_cmesh_is_committed (cmesh_from));
T8_ASSERT (t8_cmesh_is_initialized (cmesh));
T8_ASSERT (vtt.is_committed ());

/* Since we need to collect all global ids of a tree before we can add the tree,
* we need a temporary buffer structure.
* Note that this is very memory intensive, doubling the required memory. */

const t8_locidx_t num_local_trees = t8_cmesh_get_num_local_trees (cmesh_from);
const t8_locidx_t num_ghosts = t8_cmesh_get_num_ghosts (cmesh_from);
const t8_locidx_t num_local_trees_and_ghosts = num_local_trees + num_ghosts;

/* Stores an array of local indices and mapped global vertices for each tree.
* We need to store the local indices as well, since they will not be
* sorted. Hence we need to sort later. */
using global_local_index_pair = std::pair<t8_gloidx_t, t8_locidx_t>;
std::vector<std::vector<global_local_index_pair>> global_ids_per_tree (num_local_trees_and_ghosts);

/* Iterate over all entries of the vertex to tree list. */
for (auto &[global_vertex, vertex_list] : vtt) {
/* Iterate over all entries of the vertex list,
* thus, each entry is a local tree id and vertex index. */
for (auto &[tree_index, vertex_index] : vertex_list) {
global_local_index_pair new_pair (global_vertex, vertex_index);
global_ids_per_tree[tree_index].push_back (new_pair);
}
}
/* Now sort the list and add the global indices of each tree. */
for (t8_locidx_t itree = 0; itree < num_local_trees_and_ghosts; ++itree) {
auto &tree_indices = global_ids_per_tree[itree];
/* Sort according to local index. */
std::sort (tree_indices.begin (), tree_indices.end (),
[] (global_local_index_pair &a, global_local_index_pair &b) { return a.second < b.second; });

/* Compute number of vertices of this tree. */
/* Get the trees class depending on whether it is a local tree or ghost. */
const t8_eclass_t tree_class = itree < num_local_trees
? t8_cmesh_get_tree_class (cmesh_from, itree)
: t8_cmesh_get_ghost_class (cmesh_from, itree - num_local_trees);

const int num_tree_vertices = t8_eclass_num_vertices[tree_class];

/* Size of list must match number of tree vertices. */
SC_CHECK_ABORTF (
tree_indices.size () == (size_t) num_tree_vertices,
"ERROR. Number of mapped local tree vertices for tree %i does not equal number of tree vertices. %zu != %i\n",
itree, tree_indices.size (), num_tree_vertices);
/* We now build the array of global indices of this tree, sorted
* by the trees local indices. */
t8_gloidx_t *global_tree_indices = T8_ALLOC (t8_gloidx_t, num_tree_vertices);
for (int ivertex = 0; ivertex < num_tree_vertices; ++ivertex) {
global_tree_indices[ivertex] = tree_indices[ivertex].first;
}
const t8_gloidx_t global_tree_id = t8_cmesh_get_global_id (cmesh_from, itree);
set_global_vertex_ids_of_tree_vertices (cmesh, global_tree_id, global_tree_indices, num_tree_vertices);
T8_FREE (global_tree_indices);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
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) 2025 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_cmesh_vertex_conn_tree_to_vertex.hxx
* Class to save data structure for tree_to_vertex_lists of the cmesh.
* When the cmesh stores global vertex numbers, we require a lookup that
* matches a tree and its local vertex to a global vertex id.
* This lookup is encoded in the t8_cmesh_vertex_conn_tree_to_vertex struct.
*/

/* TODO:
* It is probably best to set all global ids of a single tree as one attribute.
* That way we can store it as a single arrays of id's.
* We will probably most often want to access all ids of one tree, so a function returning an array of ids
* is a good idea anyway and if we already store them as such then we do not need to do any data movement
* when accessing.
*
* On the downside we will only have a "set all ids of a tree" function and no "set this single id for this tree and this vertex" function.
*/

#ifndef T8_CMESH_VERTEX_CONN_TREE_TO_VERTEX_HXX
#define T8_CMESH_VERTEX_CONN_TREE_TO_VERTEX_HXX

#include <algorithm>
#include <t8_cmesh.h>
#include <t8_cmesh/t8_cmesh_types.h>
#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_conn_vertex_to_tree.hxx>

/* forward declaration of ttv class needed since the two class headers include each other. */
class t8_cmesh_vertex_conn_vertex_to_tree;

class t8_cmesh_vertex_conn_tree_to_vertex {
public:
/** Standard constructor. Does nothing. */
t8_cmesh_vertex_conn_tree_to_vertex (): state (EMPTY)
{
}

/** Constructor from a cmesh where all the attributes are set.
* Currently unclear if we implement this eventually.
* If we do so: Should the cmesh be already committed, or in pre-commit state but attributes set?
*
* \note This function is not implemented yet.
*/
t8_cmesh_vertex_conn_tree_to_vertex ([[maybe_unused]] const t8_cmesh_t cmesh)
{
// TODO: Remove the [[maybe unused]] qualifier when implemented
SC_ABORT ("not implemented.");
}

/** Constructor from a cmesh and a given vertex to tree connectivity.
*
* \param [in] cmesh_from A committed cmesh.
* \param [in] cmesh An initialized but not committed cmesh that is to be derived from \a cmesh_from.
* \param [in] vtt A committed vertex to tree connectivity for \a cmesh_from.
*
* As a result a tree to vertec connectivity for \a cmesh will be constructed.
* \note \a cmesh_from must be committed.
* \note \a cmesh must not be committed.
* \note \a vtt must be committed.
* \note This does not work until issue #923 https://github.com/DLR-AMR/t8code/issues/923 is resolved.
*/
t8_cmesh_vertex_conn_tree_to_vertex (const t8_cmesh_t cmesh_from, const t8_cmesh_t cmesh,
const struct t8_cmesh_vertex_conn_vertex_to_tree &vtt);

/* Setter functions */
/** Set all global vertex ids of a local tree.
* \param [in] cmesh The considered cmesh
* \param [in] local_tree A local tree id of \a cmesh
* \param [in] global_vertex_id The ids of the global vertices in order of \a local_tree's vertices.
* \param [in] num_vertices Must match the number of vertices of \a local_tree
*
* \note \a cmesh must not be committed.
*/
inline void
set_global_vertex_ids_of_tree_vertices (const t8_cmesh_t cmesh, const t8_gloidx_t global_tree,
const t8_gloidx_t *global_tree_vertices, const int num_vertices)
{
T8_ASSERT (t8_cmesh_is_initialized (cmesh));
T8_ASSERT (num_vertices >= 0);
T8_ASSERT (global_tree_vertices != NULL);

/* TODO: we currently do not check whether the num_vertices argument
* matches the number of vertices of the tree.
* We cannot do it here, since this function call happens before commit,
* thus we might not even know the eclass of the tree.
* Maybe it is possible to check this during t8_cmesh_add_attributes?
*/

/* We copy the data directly, hence set data_persiss to 0 */
const int data_persists = 0;
t8_debugf ("Setting %i global vertices for global tree %li.\n", num_vertices, global_tree);
t8_cmesh_set_attribute_gloidx_array (cmesh, global_tree, t8_get_package_id (),
T8_CMESH_GLOBAL_VERTICES_ATTRIBUTE_KEY, global_tree_vertices, num_vertices,
data_persists);
state = FILLED;
}

/* TODO: What if the attribute is not set? error handling */
/** Return the global vertex indices of a local tree.
* \param [in] cmesh A committed cmesh.
* \param [in] local_tree A local tree in \a cmesh.
* \param [in] num_vertices The count of local vertices of \a local_tree
* \return An array of length \a num_vertices containing the global vertex ids of \a local_tree's vertices.
*/
inline const t8_gloidx_t *
get_global_vertices (const t8_cmesh_t cmesh, const t8_locidx_t local_tree, const int num_vertices) const
{
T8_ASSERT (t8_cmesh_is_committed (cmesh));

#if T8_ENABLE_DEBUG
/* Verify that num_vertices matches the number of tree vertices */
const t8_eclass_t tree_class = t8_cmesh_get_tree_class (cmesh, local_tree);
const int num_tree_vertices = t8_eclass_num_vertices[tree_class];

T8_ASSERT (num_vertices == num_tree_vertices);
#endif

t8_debugf ("Getting %i global vertices for local tree %i.\n", num_vertices, local_tree);
const t8_gloidx_t *global_vertices = t8_cmesh_get_attribute_gloidx_array (
cmesh, t8_get_package_id (), T8_CMESH_GLOBAL_VERTICES_ATTRIBUTE_KEY, local_tree, num_vertices);
T8_ASSERT (global_vertices != NULL);
return global_vertices;
}

/* TODO: What if the attribute is not set? error handling */
/** Return a single global vertex id of a single local vertex.
*
*
* \param [in] cmesh A committed cmesh.
* \param [in] local_tree A local tree of \a cmesh.
* \param [in] local_tree_vertex A local vertex of \a local_tree
* \param [in] num_tree_vertices The count of vertices of \a local_tree
* \return The global id of the local vertex \a local_tree_vertex of \a local_tree.
*/
t8_gloidx_t
get_global_vertex (const t8_cmesh_t cmesh, const t8_locidx_t local_tree, const int local_tree_vertex,
const int num_tree_vertices) const
{
T8_ASSERT (t8_cmesh_is_committed (cmesh));

/* Verify that local_tree_vertex is in fact a local vertex of the tree */
/* Note: We only perform this check in debugging mode.
* In non-debugging mode, using a vertex index beyond the trees index allows
* for a potential attacker to gain access to memory possibly not owned by the caller.
* We do not check in non-debugging mode for (obvious) performance reasons. */
T8_ASSERT (0 <= local_tree_vertex);
T8_ASSERT (local_tree_vertex < num_tree_vertices);

return get_global_vertices (cmesh, local_tree, num_tree_vertices)[local_tree_vertex];
}

friend struct t8_cmesh_vertex_connectivity;

private:
enum state {
EMPTY, /*< Is initialized but empty. */
FILLED /*< Is filled with at least one entry. */
} state;

/** Return the state of this object. */
inline enum state
get_state ()
{
return state;
}
};

#endif /* !T8_CMESH_VERTEX_CONN_TREE_TO_VERTEX_HXX */
Loading