Path: blob/main/src/t8_cmesh/t8_cmesh_internal/t8_cmesh_copy.c
915 views
/*1This file is part of t8code.2t8code is a C library to manage a collection (a forest) of multiple3connected adaptive space-trees of general element classes in parallel.45Copyright (C) 2015 the developers67t8code is free software; you can redistribute it and/or modify8it under the terms of the GNU General Public License as published by9the Free Software Foundation; either version 2 of the License, or10(at your option) any later version.1112t8code is distributed in the hope that it will be useful,13but WITHOUT ANY WARRANTY; without even the implied warranty of14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15GNU General Public License for more details.1617You should have received a copy of the GNU General Public License18along with t8code; if not, write to the Free Software Foundation, Inc.,1951 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.20*/2122/** \file t8_cmesh_copy.c23* Functionality to copy a cmesh.24*/2526#include <t8_data/t8_shmem.h>27#include <t8_cmesh/t8_cmesh.h>28#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_types.h>29#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_partition.h>30#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_trees.h>31#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_copy.h>32#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity.h>3334void35t8_cmesh_copy (t8_cmesh_t cmesh, const t8_cmesh_t cmesh_from, sc_MPI_Comm comm)36{37size_t num_parts;38t8_locidx_t first_tree, num_trees, first_ghost, num_ghosts;3940T8_ASSERT (t8_cmesh_is_initialized (cmesh));41T8_ASSERT (!cmesh->committed);42T8_ASSERT (t8_cmesh_is_committed (cmesh_from));4344if (t8_cmesh_uses_vertex_connectivity (cmesh_from)) {45SC_ABORT ("Error in t8_cmesh_copy: The given cmesh cannot be copied because it uses vertex connectivity, "46"see https://github.com/DLR-AMR/t8code/issues/1799.\n");47}4849/* Copy all variables */50cmesh->dimension = cmesh_from->dimension;51cmesh->face_knowledge = cmesh_from->face_knowledge;52cmesh->first_tree = cmesh_from->first_tree;53cmesh->first_tree_shared = cmesh_from->first_tree_shared;54cmesh->mpirank = cmesh_from->mpirank;55cmesh->mpisize = cmesh_from->mpisize;56cmesh->num_ghosts = cmesh_from->num_ghosts;57cmesh->num_local_trees = cmesh_from->num_local_trees;58cmesh->num_trees = cmesh_from->num_trees;59cmesh->set_partition = cmesh_from->set_partition;60cmesh->set_partition_level = cmesh_from->set_partition_level;61#if T8_ENABLE_DEBUG62cmesh->negative_volume_check = cmesh_from->negative_volume_check;63#endif /* T8_ENABLE_DEBUG */64T8_ASSERT (t8_cmesh_comm_is_valid (cmesh, comm));6566/* Copy the tree_offsets */67if (cmesh_from->tree_offsets != NULL) {68T8_ASSERT (cmesh->tree_offsets == NULL);69cmesh->tree_offsets = t8_cmesh_alloc_offsets (cmesh->mpisize, comm);70t8_shmem_array_copy (cmesh->tree_offsets, cmesh_from->tree_offsets);71}72/* Copy the numbers of trees */73memcpy (cmesh->num_trees_per_eclass, cmesh_from->num_trees_per_eclass, T8_ECLASS_COUNT * sizeof (t8_gloidx_t));74/* Copy the numbers of local trees */75memcpy (cmesh->num_local_trees_per_eclass, cmesh_from->num_local_trees_per_eclass,76T8_ECLASS_COUNT * sizeof (t8_locidx_t));7778/* Copy the tree info */79cmesh->trees = NULL;80if (cmesh_from->trees) {81num_parts = t8_cmesh_trees_get_numproc (cmesh_from->trees);82t8_cmesh_trees_init (&cmesh->trees, num_parts, cmesh_from->num_local_trees, cmesh_from->num_ghosts);83t8_cmesh_trees_copy_toproc (cmesh->trees, cmesh_from->trees, cmesh_from->num_local_trees, cmesh_from->num_ghosts);84for (size_t ipart = 0; ipart < num_parts; ipart++) {85t8_cmesh_trees_get_part_data (cmesh_from->trees, ipart, &first_tree, &num_trees, &first_ghost, &num_ghosts);86t8_cmesh_trees_start_part (cmesh->trees, ipart, first_tree, num_trees, first_ghost, num_ghosts, 0);87t8_cmesh_trees_copy_part (cmesh->trees, ipart, cmesh_from->trees, ipart);88}89}90}919293