Skip to content

Commit

Permalink
NEM_SLICE: modernize syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed Aug 26, 2024
1 parent 094d030 commit 1f8d0c8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 67 deletions.
47 changes: 20 additions & 27 deletions packages/seacas/applications/nem_slice/elb_elem.C
Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,31 @@ E_Type get_elem_type(const char *elem_name, const int num_nodes, const int num_d
/*****************************************************************************/
/* Convenience functions for code readability
*****************************************************************************/
int is_hex(E_Type etype)
bool is_hex(E_Type etype)
{
return static_cast<int>(etype == HEX8 || etype == HEX27 || etype == HEX20 || etype == HEXSHELL);
return etype == HEX8 || etype == HEX27 || etype == HEX20 || etype == HEXSHELL;
}

int is_tet(E_Type etype)
bool is_tet(E_Type etype)
{
return static_cast<int>(etype == TET4 || etype == TET10 || etype == TET8 || etype == TET14 ||
etype == TET15);
return etype == TET4 || etype == TET10 || etype == TET8 || etype == TET14 || etype == TET15;
}

int is_wedge(E_Type etype)
bool is_wedge(E_Type etype)
{
return static_cast<int>(etype == WEDGE6 || etype == WEDGE15 || etype == WEDGE16 ||
etype == WEDGE20 || etype == WEDGE21);
return etype == WEDGE6 || etype == WEDGE15 || etype == WEDGE16 || etype == WEDGE20 ||
etype == WEDGE21;
}

int is_pyramid(E_Type etype)
bool is_pyramid(E_Type etype)
{
return static_cast<int>(etype == PYRAMID5 || etype == PYRAMID13 || etype == PYRAMID14 ||
etype == PYRAMID18 || etype == PYRAMID19);
return etype == PYRAMID5 || etype == PYRAMID13 || etype == PYRAMID14 || etype == PYRAMID18 ||
etype == PYRAMID19;
}

int is_3d_element(E_Type etype)
bool is_3d_element(E_Type etype)
{
return static_cast<int>((is_hex(etype) != 0) || (is_tet(etype) != 0) || (is_wedge(etype) != 0) ||
(is_pyramid(etype) != 0));
return is_hex(etype) || is_tet(etype) || is_wedge(etype) || is_pyramid(etype);
}

/*****************************************************************************/
Expand Down Expand Up @@ -901,9 +899,7 @@ template <typename INT>
int get_side_id(const E_Type etype, const INT *connect, const int nsnodes, INT side_nodes[],
const int skip_check, const int partial_adj)
{
int dup;
int location[9];
int count;
int count = 0;
/* min_match for hex elements means that min_match+1 nodes
on a face of a hex must match to return the side of the
hex on which the nodes exist, i.e., if 3/4 nodes of a hex
Expand All @@ -917,7 +913,8 @@ int get_side_id(const E_Type etype, const INT *connect, const int nsnodes, INT s
/* const int min_match = 2; */

/* check if this is a degenerate face */
dup = 0;
int dup = 0;
std::array<int, 9> location{};
for (int i = 0; i < (nsnodes - 1); i++) {
for (int j = (i + 1); j < nsnodes; j++) {
if (side_nodes[i] == side_nodes[j]) {
Expand Down Expand Up @@ -1449,18 +1446,14 @@ int get_side_id_hex_tet(const E_Type etype, /* The element type */
int nsnodes, /* The number of side nodes */
const INT side_nodes[]) /* The list of side node IDs */
{
int nnodes;
int lcnt;
int i1;
int i2;
std::vector<int> loc_node_ids(MAX_SIDE_NODES);
std::array<int, MAX_SIDE_NODES> loc_node_ids{};

nnodes = get_elem_info(NNODES, etype);
int nnodes = get_elem_info(NNODES, etype);

/* Find the local node numbers for nodes forming the side */
lcnt = 0;
for (i1 = 0; i1 < nnodes; i1++) {
for (i2 = 0; i2 < nsnodes; i2++) {
int lcnt = 0;
for (int i1 = 0; i1 < nnodes; i1++) {
for (int i2 = 0; i2 < nsnodes; i2++) {
if (connect[i1] == side_nodes[i2]) {
loc_node_ids[lcnt++] = i1 + 1;
break;
Expand Down
10 changes: 5 additions & 5 deletions packages/seacas/applications/nem_slice/elb_elem.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ int get_ss_mirror(E_Type etype, /* The element type */
*/
#define MAX_ELEM_SIDES 6

int is_hex(E_Type etype);
int is_tet(E_Type etype);
int is_wedge(E_Type etype);
int is_pyramid(E_Type etype);
int is_3d_element(E_Type etype);
bool is_hex(E_Type etype);
bool is_tet(E_Type etype);
bool is_wedge(E_Type etype);
bool is_pyramid(E_Type etype);
bool is_3d_element(E_Type etype);
59 changes: 24 additions & 35 deletions packages/seacas/applications/nem_slice/elb_loadbal.C
Original file line number Diff line number Diff line change
Expand Up @@ -1493,25 +1493,6 @@ namespace {
Mesh_Description<INT> *mesh, Graph_Description<INT> *graph,
Problem_Description *problem)
{
int sid;
int hflag1;
int hflag2;
int tflag1;
int tflag2;
int dflag;

INT nelem;
INT side_nodes[MAX_SIDE_NODES];
INT mirror_nodes[MAX_SIDE_NODES];
int side_cnt;

double time2;

std::string cmesg;
std::string tmpstr;

/*-----------------------------Execution Begins------------------------------*/

/* Allocate memory */
lb->int_nodes.resize(machine->num_procs);
lb->bor_nodes.resize(machine->num_procs);
Expand Down Expand Up @@ -1548,7 +1529,9 @@ namespace {
for (int nscnt = 0; nscnt < nsides; nscnt++) {

/* get the node on this element side (should only be one)*/
side_cnt = ss_to_node_list(etype, mesh->connect[ecnt], (nscnt + 1), side_nodes);
std::array<INT, MAX_SIDE_NODES> side_nodes;
int side_cnt =
ss_to_node_list(etype, mesh->connect[ecnt], (nscnt + 1), side_nodes.data());
assert(side_cnt == 1);

size_t nhold = graph->sur_elem[side_nodes[0]].size();
Expand Down Expand Up @@ -1586,6 +1569,7 @@ namespace {
}
}
else {
std::array<INT, MAX_SIDE_NODES> side_nodes;
for (size_t ecnt = 0; ecnt < mesh->num_elems; ecnt++) {
int proc = lb->vertex2proc[ecnt];
assert(proc < machine->num_procs);
Expand All @@ -1595,18 +1579,19 @@ namespace {
int dim1 = get_elem_info(NDIM, etype);

/* need to check for hex's or tet's */
hflag1 = is_hex(etype);
bool hflag1 = is_hex(etype);

/* a TET10 cannot connect to a HEX */
tflag1 = is_tet(etype);
bool tflag1 = is_tet(etype);

int nsides = get_elem_info(NSIDES, etype);

/* check each side of this element */
for (int nscnt = 0; nscnt < nsides; nscnt++) {

/* get the list of nodes on this element side */
side_cnt = ss_to_node_list(etype, mesh->connect[ecnt], (nscnt + 1), side_nodes);
int side_cnt =
ss_to_node_list(etype, mesh->connect[ecnt], (nscnt + 1), side_nodes.data());

/*
* now determine how many side set nodes are needed to
Expand All @@ -1624,7 +1609,7 @@ namespace {
}
nnodes--; /* decrement to find the number of intersections needed */

nelem = 0; /* reset this in case no intersections are needed */
INT nelem = 0; /* reset this in case no intersections are needed */

/*
* need to handle hex's differently because of
Expand Down Expand Up @@ -1674,7 +1659,7 @@ namespace {
*/

/* first need to check for a degenerate element */
dflag = 0;
int dflag = 0;
if (side_nodes[0] == side_nodes[1] || side_nodes[0] == side_nodes[3]) {
dflag++;
}
Expand Down Expand Up @@ -1835,10 +1820,11 @@ namespace {
if (diff < 2) {

/* need to check for hex's */
hflag2 = is_hex(etype2);
tflag2 = is_tet(etype2);
bool hflag2 = is_hex(etype2);
bool tflag2 = is_tet(etype2);

/* check here for tet/hex combinations */
int sid = 0;
if ((tflag1 && hflag2) || (hflag1 && tflag2)) {
/*
* have to call a special function to get the side id
Expand All @@ -1853,14 +1839,16 @@ namespace {
* with the hex.
*/
sid = get_side_id_hex_tet(mesh->elem_type[elem], mesh->connect[elem], side_cnt,
side_nodes);
side_nodes.data());
}
else {
/*
* get the side id of elem. Make sure that ecnt is
* trying to communicate to a valid side of elem
*/
side_cnt = get_ss_mirror(etype, side_nodes, (nscnt + 1), mirror_nodes);
std::array<INT, MAX_SIDE_NODES> mirror_nodes;
side_cnt =
get_ss_mirror(etype, side_nodes.data(), (nscnt + 1), mirror_nodes.data());

/*
* small kludge to handle 6 node faces butted up against
Expand All @@ -1875,7 +1863,8 @@ namespace {
* get the mirror of the side of ecnt
*/
sid = get_side_id(mesh->elem_type[elem], mesh->connect[elem], side_cnt,
mirror_nodes, problem->skip_checks, problem->partial_adj);
mirror_nodes.data(), problem->skip_checks,
problem->partial_adj);
}

if (sid > 0) {
Expand All @@ -1897,23 +1886,23 @@ namespace {
* too many errors with bad meshes, print out
* more information here for diagnostics
*/
cmesg =
std::string cmesg =
fmt::format("Error returned while getting side id for communication map.");
Gen_Error(0, cmesg);
cmesg = fmt::format("Element 1: {}", (ecnt + 1));
Gen_Error(0, cmesg);
nnodes = get_elem_info(NNODES, etype);
cmesg = "connect table:";
for (int i = 0; i < nnodes; i++) {
tmpstr = fmt::format(" {}", (size_t)(mesh->connect[ecnt][i] + 1));
std::string tmpstr = fmt::format(" {}", (size_t)(mesh->connect[ecnt][i] + 1));
cmesg += tmpstr;
}
Gen_Error(0, cmesg);
cmesg = fmt::format("side id: {}", static_cast<size_t>(nscnt + 1));
Gen_Error(0, cmesg);
cmesg = "side nodes:";
for (int i = 0; i < side_cnt; i++) {
tmpstr = fmt::format(" {}", (size_t)(side_nodes[i] + 1));
std::string tmpstr = fmt::format(" {}", (size_t)(side_nodes[i] + 1));
cmesg += tmpstr;
}
Gen_Error(0, cmesg);
Expand All @@ -1922,7 +1911,7 @@ namespace {
nnodes = get_elem_info(NNODES, etype2);
cmesg = "connect table:";
for (int i = 0; i < nnodes; i++) {
tmpstr = fmt::format(" {}", (size_t)(mesh->connect[elem][i] + 1));
std::string tmpstr = fmt::format(" {}", (size_t)(mesh->connect[elem][i] + 1));
cmesg += tmpstr;
}
Gen_Error(0, cmesg);
Expand All @@ -1940,7 +1929,7 @@ namespace {
}
} /* End "for(ecnt=0; ecnt < mesh->num_elems; ecnt++)" */
}
time2 = get_time();
double time2 = get_time();
fmt::print("Time for elemental categorization: {}s\n", time2 - time1);

/* Find the internal and border nodes */
Expand Down

0 comments on commit 1f8d0c8

Please sign in to comment.