| 1 |
#include <gtest/gtest.h> |
| 2 |
|
| 3 |
#include "UnitTestSkinMeshUseCaseUtils.hpp" |
| 4 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 5 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 6 |
|
| 7 |
namespace { |
| 8 |
|
| 9 |
using namespace stk::mesh::impl; |
| 10 |
using namespace stk::mesh; |
| 11 |
using stk::unit_test_util::build_mesh; |
| 12 |
|
| 13 |
TEST(ElementGraph, RefinedQuad) |
| 14 |
{ |
| 15 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 16 |
if (stk::parallel_machine_size(comm) <= 2) |
| 17 |
{ |
| 18 |
const int spatialDim = 2; |
| 19 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, comm, stk::mesh::BulkData::NO_AUTO_AURA); |
| 20 |
stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data(); |
| 21 |
|
| 22 |
stk::mesh::Part &quad_part = meta.declare_part_with_topology("Quads", stk::topology::QUADRILATERAL_4_2D); |
| 23 |
stk::mesh::Part &skin = meta.declare_part_with_topology("Edges", stk::topology::LINE_2); |
| 24 |
stk::io::put_io_part_attribute(skin); |
| 25 |
stk::mesh::Part &active = meta.declare_part("active"); |
| 26 |
|
| 27 |
stk::mesh::Field<double> & node_coord = meta.declare_field<double>(stk::topology::NODE_RANK, "coordinates"); |
| 28 |
stk::mesh::put_field_on_mesh(node_coord, meta.universal_part(), 3, nullptr); |
| 29 |
stk::io::put_io_part_attribute(quad_part); |
| 30 |
meta.commit(); |
| 31 |
|
| 32 |
stk::mesh::BulkData& mesh = *bulkPtr; |
| 33 |
|
| 34 |
mesh.modification_begin(); |
| 35 |
|
| 36 |
std::vector<std::vector<stk::mesh::EntityId>> elem_this_proc = { |
| 37 |
{1, 2, 3, 4, 5, 6}, |
| 38 |
{7} |
| 39 |
}; |
| 40 |
|
| 41 |
std::vector<stk::mesh::EntityId> ids = {1, 2, 3, 4, 5, 6, 7}; |
| 42 |
std::vector<std::vector<stk::mesh::EntityId> > connectivity = { |
| 43 |
{1, 2, 3, 4}, |
| 44 |
{1, 2, 6, 5}, |
| 45 |
{2, 3, 7, 6}, |
| 46 |
{8, 7, 3, 4}, |
| 47 |
{1, 5, 8, 4}, |
| 48 |
{5, 6, 7, 8}, |
| 49 |
{10, 1, 4, 9} |
| 50 |
}; |
| 51 |
|
| 52 |
bool running_2_procs = mesh.parallel_size() > 1; |
| 53 |
|
| 54 |
int my_proc_id = mesh.parallel_rank(); |
| 55 |
std::vector<stk::mesh::EntityId> elems_this_proc; |
| 56 |
if(running_2_procs) |
| 57 |
{ |
| 58 |
elems_this_proc = elem_this_proc[my_proc_id]; |
| 59 |
} |
| 60 |
else |
| 61 |
{ |
| 62 |
elems_this_proc = ids; |
| 63 |
} |
| 64 |
|
| 65 |
for(size_t i = 0; i < elems_this_proc.size(); ++i) |
| 66 |
{ |
| 67 |
int index = static_cast<int>(elems_this_proc[i])-1; |
| 68 |
stk::mesh::Entity element = stk::mesh::declare_element(mesh, quad_part, elems_this_proc[i], connectivity[index]); |
| 69 |
if(ids[index]!=1) |
| 70 |
{ |
| 71 |
mesh.change_entity_parts(element, stk::mesh::ConstPartVector{&active}, stk::mesh::ConstPartVector{}); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
std::vector<stk::mesh::EntityId> nodes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; |
| 76 |
|
| 77 |
std::vector<std::vector<stk::mesh::EntityId>> nodes_this_proc = { |
| 78 |
{1, 2, 3, 4, 5, 6, 7, 8}, |
| 79 |
{1, 4, 9, 10} |
| 80 |
}; |
| 81 |
|
| 82 |
std::vector<std::vector<double> > node_coords = { |
| 83 |
{0, 0}, {3, 0}, {3, 3}, {0, 3}, {1, 1}, {2, 1}, {2, 2}, {1, 2}, {-3, 3}, {-3, 0} |
| 84 |
}; |
| 85 |
|
| 86 |
std::vector<stk::mesh::EntityId> nodes_to_create; |
| 87 |
if(running_2_procs) |
| 88 |
{ |
| 89 |
nodes_to_create = nodes_this_proc[my_proc_id]; |
| 90 |
} |
| 91 |
else |
| 92 |
{ |
| 93 |
nodes_to_create = nodes; |
| 94 |
} |
| 95 |
|
| 96 |
for(unsigned i = 0; i < nodes_to_create.size(); ++i) |
| 97 |
{ |
| 98 |
stk::mesh::Entity const node = mesh.get_entity(stk::topology::NODE_RANK, nodes_to_create[i]); |
| 99 |
if(running_2_procs && (nodes_to_create[i]==1 || nodes_to_create[i]==4)) |
| 100 |
{ |
| 101 |
mesh.add_node_sharing(node,1-my_proc_id); |
| 102 |
} |
| 103 |
|
| 104 |
double * const coord = stk::mesh::field_data(node_coord, node); |
| 105 |
int index = static_cast<int>(nodes_to_create[i])-1; |
| 106 |
|
| 107 |
coord[0] = node_coords[index][0]; |
| 108 |
coord[1] = node_coords[index][1]; |
| 109 |
} |
| 110 |
|
| 111 |
mesh.modification_end(); |
| 112 |
|
| 113 |
stk::mesh::Selector active_sel = active; |
| 114 |
stk::mesh::Selector air = !active; |
| 115 |
|
| 116 |
stk::mesh::create_exposed_block_boundary_sides(mesh, active_sel, {}, air); |
| 117 |
|
| 118 |
std::vector<size_t> mesh_counts; |
| 119 |
stk::mesh::comm_mesh_counts(mesh, mesh_counts); |
| 120 |
EXPECT_EQ(10u, mesh_counts[stk::topology::NODE_RANK]); |
| 121 |
EXPECT_EQ(7u, mesh_counts[stk::topology::ELEM_RANK]); |
| 122 |
EXPECT_EQ(6u, mesh_counts[meta.side_rank()]); |
| 123 |
|
| 124 |
std::vector<std::pair<stk::mesh::EntityId, int>> id_and_num_faces = { |
| 125 |
{1, 3}, |
| 126 |
{2, 1}, |
| 127 |
{3, 1}, |
| 128 |
{4, 1}, |
| 129 |
{5, 0}, |
| 130 |
{6, 0}, |
| 131 |
{7, 3} |
| 132 |
}; |
| 133 |
|
| 134 |
for(size_t i = 0; i < id_and_num_faces.size(); ++i) |
| 135 |
{ |
| 136 |
stk::mesh::EntityId id = id_and_num_faces[i].first; |
| 137 |
int gold_num_faces = id_and_num_faces[i].second; |
| 138 |
stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEM_RANK, id); |
| 139 |
if(mesh.is_valid(elem)) |
| 140 |
{ |
| 141 |
int num_faces = mesh.num_sides(elem); |
| 142 |
EXPECT_EQ(gold_num_faces, num_faces)<< "element " << id << " has topology " << mesh.bucket(elem).topology() << " with num faces " << num_faces << " not same as gold value " << gold_num_faces << std::endl; |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
} // namespace |