Program Listing for File t8_cmesh.hxx

Return to documentation for file (src/t8_cmesh/t8_cmesh.hxx)

/*
  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.
*/

#ifndef T8_CMESH_HXX
#define T8_CMESH_HXX

#include <vector>
#include <unordered_map>
#include <t8_cmesh/t8_cmesh.h>
#include <t8_cmesh/t8_cmesh_internal/t8_cmesh_types.h>
#include <t8_cmesh/t8_cmesh_vertex_connectivity/t8_cmesh_vertex_connectivity_types.hxx>
#include <t8_geometry/t8_geometry_handler.hxx>

constexpr uint64_t
t8_cmesh_get_first_element_of_process (const uint32_t process, const uint32_t mpisize,
                                       const uint64_t global_num_elements)
{
  T8_ASSERT (mpisize > 0);
  T8_ASSERT (process <= mpisize);

  /* Cast everything into uint64_t */
  const uint64_t process_64 = static_cast<uint64_t> (process);
  const uint64_t mpisize_64 = static_cast<uint64_t> (mpisize);

  /* Split the uint64_t */
  const uint64_t elem_over_size = global_num_elements / mpisize_64;
  const uint64_t remainder_0 = global_num_elements % mpisize_64;

  const uint64_t proc_over_size = process_64 / mpisize_64;
  const uint64_t remainder_1 = process_64 % mpisize_64;

  const uint64_t sum_0 = (elem_over_size * proc_over_size) * mpisize_64;
  const uint64_t sum_1 = elem_over_size * (process_64 % mpisize_64);
  const uint64_t sum_2 = proc_over_size * (global_num_elements % mpisize_64);
  const uint64_t sum_3 = (remainder_0 * remainder_1) / mpisize_64;

  return (sum_0 + sum_1 + sum_2 + sum_3);
}

template <typename geometry_type, typename... _args>
inline geometry_type *
t8_cmesh_register_geometry (t8_cmesh_t cmesh, _args &&...args)
{
  if (cmesh->geometry_handler == NULL) {
    /* The handler was not constructed, do it now. */
    cmesh->geometry_handler = new t8_geometry_handler ();
  }
  return cmesh->geometry_handler->register_geometry<geometry_type> (std::forward<_args> (args)...);
}

const tree_vertex_list &
t8_cmesh_get_vertex_to_tree_list (const t8_cmesh_t cmesh, const t8_gloidx_t global_vertex);

#endif /* T8_CMESH_HXX */