Skip to content

Commit edacd51

Browse files
authored
Merge pull request #776 from tjotaha/generated_mesh_blocks_touching_sideset_fix
Generated mesh blocks touching sideset fix
2 parents ee99fe9 + 9690885 commit edacd51

File tree

5 files changed

+141
-15
lines changed

5 files changed

+141
-15
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
2-
LIB_OPTIONAL_TPLS GTest
2+
LIB_OPTIONAL_TPLS ${SEACAS_GTest_TPL_name}
33
)

packages/seacas/libraries/ioss/src/generated/Iogn_GeneratedMesh.C

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Ioss_TriShell3.h"
1212
#include "Ioss_Utils.h"
1313
#include "generated/Iogn_GeneratedMesh.h"
14+
#include <algorithm>
1415
#include <cassert> // for assert
1516
#include <cmath> // for atan2, cos, sin
1617
#include <fmt/format.h>
@@ -1623,19 +1624,11 @@ namespace Iogn {
16231624
// If there is a shell block on this face, then the sideset is
16241625
// applied to the shell block; if not, it is applied to the
16251626
// underlying hex elements.
1626-
bool underlying_shell = false;
1627-
int64_t shell_block = 0;
1628-
for (size_t i = 0; i < shellBlocks.size(); i++) {
1629-
if (shellBlocks[i] == loc) {
1630-
underlying_shell = true;
1631-
shell_block = i + 2;
1632-
break;
1633-
}
1634-
}
1627+
auto shell_ids = shell_ids_at_location(loc);
16351628

1636-
if (underlying_shell) {
1629+
if (!shell_ids.empty()) {
16371630
// Get ids of shell elements at this location...
1638-
element_map(shell_block, elem_sides);
1631+
element_map(shell_ids.back(), elem_sides);
16391632

16401633
// Insert face_ordinal in between each entry in elem_sides...
16411634
// Face will be 0 for all shells...
@@ -1653,9 +1646,36 @@ namespace Iogn {
16531646
}
16541647
}
16551648

1656-
Ioss::NameList GeneratedMesh::sideset_touching_blocks(int64_t /*set_id*/) const
1649+
Ioss::NameList GeneratedMesh::sideset_touching_blocks(int64_t set_id) const
1650+
{
1651+
if (set_id <= 0 || (size_t)set_id > sidesets.size()) {
1652+
IOSS_ERROR(fmt::format("set_id out of range in sideset_touching_blocks: ", set_id));
1653+
}
1654+
1655+
Ioss::NameList result;
1656+
ShellLocation loc = sidesets[set_id - 1];
1657+
auto shell_ids = shell_ids_at_location(loc);
1658+
if (!shell_ids.empty()) {
1659+
result.push_back("block_" + std::to_string(shell_ids.back()));
1660+
}
1661+
else {
1662+
result.push_back("block_1");
1663+
}
1664+
return result;
1665+
}
1666+
1667+
std::vector<size_t> GeneratedMesh::shell_ids_at_location(ShellLocation loc) const
16571668
{
1658-
Ioss::NameList result(1, "block_1");
1669+
std::vector<size_t> result;
1670+
1671+
for (size_t i = 0; i < shellBlocks.size(); i++) {
1672+
if (shellBlocks[i] == loc) {
1673+
result.push_back(i + 2);
1674+
}
1675+
}
1676+
if (loc == MX || loc == MY || loc == MZ) {
1677+
std::reverse(result.begin(), result.end());
1678+
}
16591679
return result;
16601680
}
16611681

packages/seacas/libraries/ioss/src/generated/Iogn_GeneratedMesh.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ namespace Iogn {
8282
multicharacter string. You can add multiple shell blocks to a face,
8383
for example, shell:xxx would add three layered shell blocks on the
8484
minimum x face. An error is output if a non xXyYzZ character is
85-
found, but execution continues.
85+
found, but execution continues. The shell block ids start from 2 and
86+
increase from left to right through the shell creations argument string.
87+
Block id 1 is reserved for the cube block.
8688
8789
- `nodeset` -- argument = xXyYzZ which specifies whether there is
8890
a nodeset at that location. `x` is minimum x face, `X` is
@@ -454,8 +456,20 @@ namespace Iogn {
454456
*/
455457
virtual void sideset_elem_sides(int64_t id, Ioss::Int64Vector &elem_sides) const;
456458

459+
/**
460+
* Returns names of element blocks and shell blocks touched by sideset given by set_id.
461+
* If the sideset is on a shell block with multiple stacked shells, then return the
462+
* outermost shell block name.
463+
*/
457464
IOSS_NODISCARD virtual Ioss::NameList sideset_touching_blocks(int64_t set_id) const;
458465

466+
/**
467+
* For mesh face given by loc, returns the shell block ids of the shells on the face
468+
* in innermost to outermost order. Returns an empty vector if no shells are defined
469+
* on the face.
470+
*/
471+
IOSS_NODISCARD virtual std::vector<size_t> shell_ids_at_location(ShellLocation loc) const;
472+
459473
IOSS_NODISCARD int64_t get_num_x() const { return numX; }
460474
IOSS_NODISCARD int64_t get_num_y() const { return numY; }
461475
IOSS_NODISCARD int64_t get_num_z() const { return numZ; }

packages/seacas/libraries/ioss/src/unit_tests/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ TRIBITS_ADD_EXECUTABLE(
1919
SOURCES unitMain.C UnitTestDynamicTopology.C
2020
)
2121

22+
TRIBITS_ADD_EXECUTABLE(
23+
Utst_generatedmesh
24+
SOURCES unitMain.C UnitTestGeneratedMesh.C
25+
)
26+
27+
TRIBITS_ADD_TEST(
28+
Utst_generatedmesh
29+
NAME Utst_generatedmesh
30+
NUM_MPI_PROCS 1
31+
)
32+
2233
TRIBITS_ADD_TEST(
2334
Utst_dynamictopology
2435
NAME Utst_dynamictopology
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright(C) 2024, 2025 National Technology & Engineering Solutions
2+
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3+
// NTESS, the U.S. Government retains certain rights in this software.
4+
//
5+
// See packages/seacas/LICENSE for details
6+
7+
#include "generated/Iogn_GeneratedMesh.h"
8+
#include "gtest/gtest.h"
9+
#include <stdexcept>
10+
11+
TEST(GeneratedMesh, NoSideSets)
12+
{
13+
Iogn::GeneratedMesh gm("10x12x14");
14+
EXPECT_THROW(gm.sideset_touching_blocks(0), std::runtime_error);
15+
}
16+
17+
TEST(GeneratedMesh, TwoSideSets)
18+
{
19+
Iogn::GeneratedMesh gm("10x12x14|sideset:XY");
20+
EXPECT_EQ(gm.sideset_count(), 2);
21+
EXPECT_EQ(gm.sideset_touching_blocks(1)[0], "block_1");
22+
EXPECT_EQ(gm.sideset_touching_blocks(2)[0], "block_1");
23+
}
24+
25+
TEST(GeneratedMesh, OneShellOneSideSetDifferentSides)
26+
{
27+
Iogn::GeneratedMesh gm("10x12x14|shell:z|sideset:Z");
28+
EXPECT_EQ(gm.sideset_count(), 1);
29+
EXPECT_EQ(gm.block_count(), 2);
30+
EXPECT_EQ(gm.sideset_touching_blocks(1)[0], "block_1");
31+
}
32+
33+
TEST(GeneratedMesh, OneShellOneSideSetSameSide)
34+
{
35+
Iogn::GeneratedMesh gm("10x12x14|shell:z|sideset:z");
36+
EXPECT_EQ(gm.sideset_count(), 1);
37+
EXPECT_EQ(gm.block_count(), 2);
38+
EXPECT_EQ(gm.sideset_touching_blocks(1)[0], "block_2");
39+
}
40+
41+
TEST(GeneratedMesh, FourShellsOppositeSides)
42+
{
43+
Iogn::GeneratedMesh gm("10x12x14|shell:yyYY|sideset:Y");
44+
EXPECT_EQ(gm.sideset_count(), 1);
45+
EXPECT_EQ(gm.block_count(), 5);
46+
EXPECT_EQ(gm.sideset_touching_blocks(1)[0], "block_5");
47+
}
48+
49+
TEST(GeneratedMesh, ShellIdsatLocationPXEmpty)
50+
{
51+
Iogn::GeneratedMesh gm("10x12x14");
52+
auto shell_ids = gm.shell_ids_at_location(Iogn::GeneratedMesh::ShellLocation::PX);
53+
EXPECT_TRUE(shell_ids.empty());
54+
}
55+
56+
TEST(GeneratedMesh, ShellIdsatLocationMX)
57+
{
58+
Iogn::GeneratedMesh gm("10x12x14|shell:xxx");
59+
auto shell_ids = gm.shell_ids_at_location(Iogn::GeneratedMesh::ShellLocation::MX);
60+
EXPECT_EQ(shell_ids.size(), 3);
61+
EXPECT_EQ(shell_ids.back(), 2);
62+
EXPECT_EQ(shell_ids.front(), 4);
63+
EXPECT_EQ(shell_ids[1], 3);
64+
}
65+
66+
TEST(GeneratedMesh, ShellIdsatLocationPX)
67+
{
68+
Iogn::GeneratedMesh gm("10x12x14|shell:xxxXX");
69+
auto shell_ids = gm.shell_ids_at_location(Iogn::GeneratedMesh::ShellLocation::PX);
70+
EXPECT_EQ(shell_ids.size(), 2);
71+
EXPECT_EQ(shell_ids.back(), 6);
72+
EXPECT_EQ(shell_ids.front(), 5);
73+
}
74+
75+
TEST(GeneratedMesh, ShellIdsatLocationMZ)
76+
{
77+
Iogn::GeneratedMesh gm("10x12x14|shell:xxxXXyyyYYzZZ");
78+
auto shell_ids = gm.shell_ids_at_location(Iogn::GeneratedMesh::ShellLocation::MZ);
79+
EXPECT_EQ(shell_ids.size(), 1);
80+
EXPECT_EQ(shell_ids.front(), 12);
81+
}

0 commit comments

Comments
 (0)