Skip to content

Commit

Permalink
Pull element centroid into common utils class
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed Jun 7, 2024
1 parent b1a380f commit 0cb2faf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 88 deletions.
42 changes: 2 additions & 40 deletions packages/seacas/applications/slice/SL_Decompose.C
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <Ioss_CodeTypes.h>
#include <Ioss_DatabaseIO.h>
#include <Ioss_DecompositionUtils.h>
#include <Ioss_ElementBlock.h>
#include <Ioss_NodeBlock.h>
#include <Ioss_ParallelUtils.h>
Expand Down Expand Up @@ -127,45 +128,6 @@ namespace {
}

#if USE_ZOLTAN
template <typename INT>
std::tuple<std::vector<double>, std::vector<double>, std::vector<double>>
get_element_centroid(const Ioss::Region &region, IOSS_MAYBE_UNUSED INT dummy)
{
size_t element_count = region.get_property("element_count").get_int();

// The zoltan methods supported in slice are all geometry based
// and use the element centroid.
std::vector<double> x(element_count);
std::vector<double> y(element_count);
std::vector<double> z(element_count);

const auto *nb = region.get_node_blocks()[0];
std::vector<double> coor;
nb->get_field_data("mesh_model_coordinates", coor);

const auto &blocks = region.get_element_blocks();
size_t el = 0;
for (auto &eb : blocks) {
std::vector<INT> connectivity;
eb->get_field_data("connectivity_raw", connectivity);
size_t blk_element_count = eb->entity_count();
size_t blk_element_nodes = eb->topology()->number_nodes();

for (size_t j = 0; j < blk_element_count; j++) {
for (size_t k = 0; k < blk_element_nodes; k++) {
auto node = connectivity[j * blk_element_nodes + k] - 1;
x[el] += coor[node * 3 + 0];
y[el] += coor[node * 3 + 1];
z[el] += coor[node * 3 + 2];
}
x[el] /= blk_element_nodes;
y[el] /= blk_element_nodes;
z[el] /= blk_element_nodes;
el++;
}
}
return {x, y, z};
}
/*****************************************************************************/
/***** Global data structure used by Zoltan callbacks. *****/
/***** Could implement Zoltan callbacks without global data structure, *****/
Expand Down Expand Up @@ -262,7 +224,7 @@ namespace {
exit(EXIT_FAILURE);
}

auto [x, y, z] = get_element_centroid(region, dummy);
auto [x, y, z] = Ioss::DecompUtils::get_element_centroid(region, dummy);

// Copy mesh data and pointers into structure accessible from callback fns.
Zoltan_Data.ndot = element_count;
Expand Down
2 changes: 0 additions & 2 deletions packages/seacas/libraries/ioss/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ APPEND_GLOB(SOURCES ${DIR}/elements/*.C)
IF (NOT TPL_ENABLE_MPI)
LIST(REMOVE_ITEM SOURCES ${DIR}/Ioss_Decomposition.C)
LIST(REMOVE_ITEM HEADERS ${DIR}/Ioss_Decomposition.h)
LIST(REMOVE_ITEM SOURCES ${DIR}/Ioss_DecompositionUtils.C)
LIST(REMOVE_ITEM HEADERS ${DIR}/Ioss_DecompositionUtils.h)
ENDIF()

TRIBITS_INCLUDE_DIRECTORIES(
Expand Down
97 changes: 51 additions & 46 deletions packages/seacas/libraries/ioss/src/Ioss_DecompositionUtils.C
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@
#include <vector>
#include <string>

#include "Ioss_DecompositionUtils.h"
#include "Ioss_CodeTypes.h"
#include "Ioss_ChainGenerator.h"
#include "Ioss_Decomposition.h"
#include "Ioss_DecompositionUtils.h"
#include "Ioss_NodeBlock.h"
#include "Ioss_ElementBlock.h"
#include "Ioss_ParallelUtils.h"
#include "Ioss_Region.h"
#include "Ioss_SmartAssert.h"

#include <cassert>
#include <fstream>

#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
Expand Down Expand Up @@ -133,46 +129,6 @@ std::map<INT, std::vector<INT>> string_chains(const Ioss::chain_t<INT> &element_
return chains;
}

template <typename INT>
std::tuple<std::vector<double>, std::vector<double>, std::vector<double>>
get_element_centroid(const Ioss::Region &region, IOSS_MAYBE_UNUSED INT dummy)
{
size_t element_count = region.get_property("element_count").get_int();

// The zoltan methods supported in slice are all geometry based
// and use the element centroid.
std::vector<double> x(element_count);
std::vector<double> y(element_count);
std::vector<double> z(element_count);

const auto *nb = region.get_node_blocks()[0];
std::vector<double> coor;
nb->get_field_data("mesh_model_coordinates", coor);

const auto &blocks = region.get_element_blocks();
size_t el = 0;
for (auto &eb : blocks) {
std::vector<INT> connectivity;
eb->get_field_data("connectivity_raw", connectivity);
size_t blk_element_count = eb->entity_count();
size_t blk_element_nodes = eb->topology()->number_nodes();

for (size_t j = 0; j < blk_element_count; j++) {
for (size_t k = 0; k < blk_element_nodes; k++) {
auto node = connectivity[j * blk_element_nodes + k] - 1;
x[el] += coor[node * 3 + 0];
y[el] += coor[node * 3 + 1];
z[el] += coor[node * 3 + 2];
}
x[el] /= blk_element_nodes;
y[el] /= blk_element_nodes;
z[el] /= blk_element_nodes;
el++;
}
}
return {x, y, z};
}

void output_histogram(const std::vector<size_t> &proc_work, size_t avg_work, size_t median)
{
fmt::print("Work-per-processor Histogram\n");
Expand Down Expand Up @@ -247,7 +203,7 @@ std::map<INT, std::vector<INT>> string_chains(const Ioss::chain_t<INT> &element_
exit(EXIT_FAILURE);
}

auto [x, y, z] = get_element_centroid(region, dummy);
auto [x, y, z] = Ioss::DecompUtils::get_element_centroid(region, dummy);

// Copy mesh data and pointers into structure accessible from callback fns.
Zoltan_Data.ndot = element_count;
Expand Down Expand Up @@ -514,4 +470,53 @@ template void DecompUtils::output_decomposition_statistics(const std::vector<int
size_t number_elements);
template void DecompUtils::output_decomposition_statistics(const std::vector<int64_t> &elem_to_proc,
int proc_count, size_t number_elements);

template <typename INT>
std::tuple<std::vector<double>, std::vector<double>, std::vector<double>>
DecompUtils::get_element_centroid(const Ioss::Region &region, IOSS_MAYBE_UNUSED INT dummy)
{
size_t element_count = region.get_property("element_count").get_int();

// The zoltan methods supported in slice are all geometry based
// and use the element centroid.
std::vector<double> x(element_count);
std::vector<double> y(element_count);
std::vector<double> z(element_count);

const auto *nb = region.get_node_blocks()[0];
std::vector<double> coor;
nb->get_field_data("mesh_model_coordinates", coor);

const auto &blocks = region.get_element_blocks();
size_t el = 0;
for (auto &eb : blocks) {
std::vector<INT> connectivity;
eb->get_field_data("connectivity_raw", connectivity);
size_t blk_element_count = eb->entity_count();
size_t blk_element_nodes = eb->topology()->number_nodes();

for (size_t j = 0; j < blk_element_count; j++) {
for (size_t k = 0; k < blk_element_nodes; k++) {
auto node = connectivity[j * blk_element_nodes + k] - 1;
x[el] += coor[node * 3 + 0];
y[el] += coor[node * 3 + 1];
z[el] += coor[node * 3 + 2];
}
x[el] /= blk_element_nodes;
y[el] /= blk_element_nodes;
z[el] /= blk_element_nodes;
el++;
}
}
return {x, y, z};
}

template
std::tuple<std::vector<double>, std::vector<double>, std::vector<double>>
DecompUtils::get_element_centroid(const Ioss::Region &region, IOSS_MAYBE_UNUSED int dummy);

template
std::tuple<std::vector<double>, std::vector<double>, std::vector<double>>
DecompUtils::get_element_centroid(const Ioss::Region &region, IOSS_MAYBE_UNUSED int64_t dummy);

}
4 changes: 4 additions & 0 deletions packages/seacas/libraries/ioss/src/Ioss_DecompositionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@ namespace Ioss {

static int line_decompose(Region &region, size_t num_ranks, const std::string &method,
const std::string &surface_list, std::vector<int> &element_to_proc);

template <typename INT>
static std::tuple<std::vector<double>, std::vector<double>, std::vector<double>>
get_element_centroid(const Ioss::Region &region, IOSS_MAYBE_UNUSED INT dummy);
};
} // namespace Ioss

0 comments on commit 0cb2faf

Please sign in to comment.