Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/src/t8_cmesh/t8_cmesh_internal/t8_cmesh_copy.c
915 views
1
/*
2
This file is part of t8code.
3
t8code is a C library to manage a collection (a forest) of multiple
4
connected adaptive space-trees of general element classes in parallel.
5
6
Copyright (C) 2015 the developers
7
8
t8code is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
13
t8code is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with t8code; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
*/
22
23
/** \file t8_cmesh_copy.c
24
* Functionality to copy a cmesh.
25
*/
26
27
#include <t8_data/t8_shmem.h>
28
#include <t8_cmesh/t8_cmesh.h>
29
#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_types.h>
30
#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_partition.h>
31
#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_trees.h>
32
#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_copy.h>
33
#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.h>
34
35
void
36
t8_cmesh_copy (t8_cmesh_t cmesh, const t8_cmesh_t cmesh_from, sc_MPI_Comm comm)
37
{
38
size_t num_parts;
39
t8_locidx_t first_tree, num_trees, first_ghost, num_ghosts;
40
41
T8_ASSERT (t8_cmesh_is_initialized (cmesh));
42
T8_ASSERT (!cmesh->committed);
43
T8_ASSERT (t8_cmesh_is_committed (cmesh_from));
44
45
if (t8_cmesh_uses_vertex_connectivity (cmesh_from)) {
46
SC_ABORT ("Error in t8_cmesh_copy: The given cmesh cannot be copied because it uses vertex connectivity, "
47
"see https://github.com/DLR-AMR/t8code/issues/1799.\n");
48
}
49
50
/* Copy all variables */
51
cmesh->dimension = cmesh_from->dimension;
52
cmesh->face_knowledge = cmesh_from->face_knowledge;
53
cmesh->first_tree = cmesh_from->first_tree;
54
cmesh->first_tree_shared = cmesh_from->first_tree_shared;
55
cmesh->mpirank = cmesh_from->mpirank;
56
cmesh->mpisize = cmesh_from->mpisize;
57
cmesh->num_ghosts = cmesh_from->num_ghosts;
58
cmesh->num_local_trees = cmesh_from->num_local_trees;
59
cmesh->num_trees = cmesh_from->num_trees;
60
cmesh->set_partition = cmesh_from->set_partition;
61
cmesh->set_partition_level = cmesh_from->set_partition_level;
62
#if T8_ENABLE_DEBUG
63
cmesh->negative_volume_check = cmesh_from->negative_volume_check;
64
#endif /* T8_ENABLE_DEBUG */
65
T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm));
66
67
/* Copy the tree_offsets */
68
if (cmesh_from->tree_offsets != NULL) {
69
T8_ASSERT (cmesh->tree_offsets == NULL);
70
cmesh->tree_offsets = t8_cmesh_alloc_offsets (cmesh->mpisize, comm);
71
t8_shmem_array_copy (cmesh->tree_offsets, cmesh_from->tree_offsets);
72
}
73
/* Copy the numbers of trees */
74
memcpy (cmesh->num_trees_per_eclass, cmesh_from->num_trees_per_eclass, T8_ECLASS_COUNT * sizeof (t8_gloidx_t));
75
/* Copy the numbers of local trees */
76
memcpy (cmesh->num_local_trees_per_eclass, cmesh_from->num_local_trees_per_eclass,
77
T8_ECLASS_COUNT * sizeof (t8_locidx_t));
78
79
/* Copy the tree info */
80
cmesh->trees = NULL;
81
if (cmesh_from->trees) {
82
num_parts = t8_cmesh_trees_get_numproc (cmesh_from->trees);
83
t8_cmesh_trees_init (&cmesh->trees, num_parts, cmesh_from->num_local_trees, cmesh_from->num_ghosts);
84
t8_cmesh_trees_copy_toproc (cmesh->trees, cmesh_from->trees, cmesh_from->num_local_trees, cmesh_from->num_ghosts);
85
for (size_t ipart = 0; ipart < num_parts; ipart++) {
86
t8_cmesh_trees_get_part_data (cmesh_from->trees, ipart, &first_tree, &num_trees, &first_ghost, &num_ghosts);
87
t8_cmesh_trees_start_part (cmesh->trees, ipart, first_tree, num_trees, first_ghost, num_ghosts, 0);
88
t8_cmesh_trees_copy_part (cmesh->trees, ipart, cmesh_from->trees, ipart);
89
}
90
}
91
}
92
93