| 1 |
#include <gtest/gtest.h> |
| 2 |
#include <stk_util/parallel/Parallel.hpp> |
| 3 |
#include <stk_mesh/base/BulkData.hpp> |
| 4 |
#include <stk_mesh/base/GetEntities.hpp> |
| 5 |
#include <stk_middle_mesh_util/create_stk_mesh.hpp> |
| 6 |
#include <stk_middle_mesh/incremental_mesh_boundary_snapper.hpp> |
| 7 |
#include <stk_middle_mesh/nonconformal4.hpp> |
| 8 |
#include <stk_middle_mesh/application_interface.hpp> |
| 9 |
#include <stk_middle_mesh/create_mesh.hpp> |
| 10 |
#include <stk_middle_mesh/utils.hpp> |
| 11 |
#include <stk_coupling/SplitComms.hpp> |
| 12 |
#include <stk_io/FillMesh.hpp> |
| 13 |
#include <stk_unit_test_utils/getOption.h> |
| 14 |
#include <stk_unit_test_utils/timer.hpp> |
| 15 |
#include <memory> |
| 16 |
#include <iostream> |
| 17 |
|
| 18 |
namespace |
| 19 |
{ |
| 20 |
|
| 21 |
stk::middle_mesh::stk_interface::MeshPart |
| 22 |
create_surface_mesh(stk::ParallelMachine comm, |
| 23 |
const std::string& fileName, |
| 24 |
const std::string& surfacePartName) |
| 25 |
{ |
| 26 |
stk::middle_mesh::stk_interface::StkMeshCreator stkMeshCreator(fileName, "NONE", comm); |
| 27 |
stk::mesh::Part* surfacePart = stkMeshCreator.get_meta_data().get_part(surfacePartName); |
| 28 |
EXPECT_TRUE((surfacePart != nullptr)); |
| 29 |
stk::mesh::Selector ownedSurface = stkMeshCreator.get_meta_data().locally_owned_part() & *surfacePart; |
| 30 |
const unsigned stkNumFaces = stk::mesh::count_entities(stkMeshCreator.get_bulk_data(), stk::topology::FACE_RANK, ownedSurface); |
| 31 |
stk::middle_mesh::stk_interface::MeshPart meshAndField = stkMeshCreator.create_mesh_from_part(surfacePartName); |
| 32 |
const int myRank = stk::parallel_machine_rank(comm); |
| 33 |
|
| 34 |
std::cout<<"localRank="<<myRank<<", mesh="<<fileName |
| 35 |
<<", stk surface numFaces: " << stkNumFaces |
| 36 |
<<", surface-mesh size: "<< meshAndField.mesh->get_elements().size() |
| 37 |
<<std::endl; |
| 38 |
return meshAndField; |
| 39 |
} |
| 40 |
|
| 41 |
TEST(MiddleMesh, StkMeshCreator) |
| 42 |
{ |
| 43 |
stk::ParallelMachine commWorld = MPI_COMM_WORLD; |
| 44 |
|
| 45 |
std::string meshFileName = stk::unit_test_util::get_command_line_option<std::string>("--mesh", "generated:2x1000x1000|sideset:x"); |
| 46 |
std::string surfacePartName = stk::unit_test_util::get_command_line_option<std::string>("--surface", "surface_1"); |
| 47 |
|
| 48 |
const unsigned NUM_RUNS = 5; |
| 49 |
const int NUM_ITERS = 1; |
| 50 |
stk::unit_test_util::BatchTimer batchTimer(commWorld); |
| 51 |
|
| 52 |
batchTimer.initialize_batch_timer(); |
| 53 |
for(unsigned run=0; run<NUM_RUNS; ++run) { |
| 54 |
batchTimer.start_batch_timer(); |
| 55 |
|
| 56 |
create_surface_mesh(commWorld, meshFileName, surfacePartName); |
| 57 |
|
| 58 |
batchTimer.stop_batch_timer(); |
| 59 |
} |
| 60 |
|
| 61 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 62 |
} |
| 63 |
|
| 64 |
TEST(MiddleMesh, CreateMeshUsingMeshGenerator) |
| 65 |
{ |
| 66 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 67 |
|
| 68 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 69 |
const int NUM_RUNS = 5; |
| 70 |
const int NUM_ITERS = 1; |
| 71 |
stk::middle_mesh::mesh::impl::MeshSpec spec{2000, 2000, 0, 1, 0, 1}; |
| 72 |
|
| 73 |
batchTimer.initialize_batch_timer(); |
| 74 |
for (int i = 0; i < NUM_RUNS; ++i) { |
| 75 |
batchTimer.start_batch_timer(); |
| 76 |
stk::middle_mesh::mesh::impl::create_mesh(spec, [&](stk::middle_mesh::utils::Point const& pt) { return pt; } ); |
| 77 |
batchTimer.stop_batch_timer(); |
| 78 |
} |
| 79 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
TEST(MiddleMesh, CreateMiddleMeshFromIdenticalMeshes) |
| 84 |
{ |
| 85 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 86 |
|
| 87 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 88 |
const int NUM_RUNS = 5; |
| 89 |
const int NUM_ITERS = 1; |
| 90 |
|
| 91 |
stk::middle_mesh::mesh::impl::MeshSpec spec{600, 600, 0, 1, 0, 1}; |
| 92 |
auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; }; |
| 93 |
|
| 94 |
batchTimer.initialize_batch_timer(); |
| 95 |
for (int i = 0; i < NUM_RUNS; ++i) { |
| 96 |
batchTimer.start_batch_timer(); |
| 97 |
|
| 98 |
auto mesh1 = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 99 |
auto mesh2 = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 100 |
|
| 101 |
double eps = 1e-12; |
| 102 |
stk::middle_mesh::BoundarySnapAndQualityImprovementOpts snapOpts; |
| 103 |
snapOpts.type = stk::middle_mesh::BoundarySnapAndQualityImprovementType::None; |
| 104 |
|
| 105 |
stk::middle_mesh::MiddleGridOpts middleMeshOpts; |
| 106 |
middleMeshOpts.normalProjectionOpts.classifierTolerances = stk::middle_mesh::impl::PointClassifierNormalWrapperTolerances(eps); |
| 107 |
middleMeshOpts.normalProjectionOpts.edgeTracerTolerances = stk::middle_mesh::impl::EdgeTracerTolerances(eps); |
| 108 |
auto interface = stk::middle_mesh::application_interface_factory(stk::middle_mesh::ApplicationInterfaceType::Parallel, |
| 109 |
mesh1, mesh2, comm, nullptr, |
| 110 |
stk::middle_mesh::ParallelSearchOpts(), |
| 111 |
stk::middle_mesh::VolumeSnapOpts(), |
| 112 |
snapOpts, middleMeshOpts); |
| 113 |
interface->create_middle_grid(); |
| 114 |
|
| 115 |
batchTimer.stop_batch_timer(); |
| 116 |
} |
| 117 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 118 |
} |
| 119 |
|
| 120 |
TEST(MiddleMesh, CreateMiddleMeshFromOffByOneMeshes) |
| 121 |
{ |
| 122 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 123 |
|
| 124 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 125 |
const int NUM_RUNS = 5; |
| 126 |
const int NUM_ITERS = 1; |
| 127 |
|
| 128 |
stk::middle_mesh::mesh::impl::MeshSpec spec{500, 500, 0, 1, 0, 1}; |
| 129 |
stk::middle_mesh::mesh::impl::MeshSpec spec2{501, 501, 0, 1, 0, 1}; |
| 130 |
|
| 131 |
auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; }; |
| 132 |
|
| 133 |
batchTimer.initialize_batch_timer(); |
| 134 |
for (int i = 0; i < NUM_RUNS; ++i) { |
| 135 |
batchTimer.start_batch_timer(); |
| 136 |
auto mesh1 = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 137 |
auto mesh2 = stk::middle_mesh::mesh::impl::create_mesh(spec2, func); |
| 138 |
|
| 139 |
|
| 140 |
double eps = 1e-12; |
| 141 |
stk::middle_mesh::BoundarySnapAndQualityImprovementOpts snapOpts; |
| 142 |
snapOpts.type = stk::middle_mesh::BoundarySnapAndQualityImprovementType::None; |
| 143 |
|
| 144 |
stk::middle_mesh::MiddleGridOpts middleMeshOpts; |
| 145 |
middleMeshOpts.normalProjectionOpts.classifierTolerances = stk::middle_mesh::impl::PointClassifierNormalWrapperTolerances(eps); |
| 146 |
middleMeshOpts.normalProjectionOpts.edgeTracerTolerances = stk::middle_mesh::impl::EdgeTracerTolerances(eps); |
| 147 |
auto interface = stk::middle_mesh::application_interface_factory(stk::middle_mesh::ApplicationInterfaceType::Parallel, |
| 148 |
mesh1, mesh2, comm, nullptr, |
| 149 |
stk::middle_mesh::ParallelSearchOpts(), |
| 150 |
stk::middle_mesh::VolumeSnapOpts(), |
| 151 |
snapOpts, middleMeshOpts); |
| 152 |
interface->create_middle_grid(); |
| 153 |
|
| 154 |
batchTimer.stop_batch_timer(); |
| 155 |
} |
| 156 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 157 |
} |
| 158 |
|
| 159 |
TEST(MiddleMesh, CreateMiddleMeshFromMeshesWithLargeRefinementRatio) |
| 160 |
{ |
| 161 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 162 |
|
| 163 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 164 |
const int NUM_RUNS = 5; |
| 165 |
const int NUM_ITERS = 1; |
| 166 |
|
| 167 |
stk::middle_mesh::mesh::impl::MeshSpec spec{40, 40, 0, 1, 0, 1}; |
| 168 |
stk::middle_mesh::mesh::impl::MeshSpec spec2{800, 800, 0, 1, 0, 1}; |
| 169 |
auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; }; |
| 170 |
|
| 171 |
batchTimer.initialize_batch_timer(); |
| 172 |
for (int i = 0; i < NUM_RUNS; ++i) { |
| 173 |
batchTimer.start_batch_timer(); |
| 174 |
|
| 175 |
auto mesh1 = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 176 |
auto mesh2 = stk::middle_mesh::mesh::impl::create_mesh(spec2, func); |
| 177 |
|
| 178 |
double eps = 1e-12; |
| 179 |
stk::middle_mesh::BoundarySnapAndQualityImprovementOpts snapOpts; |
| 180 |
snapOpts.type = stk::middle_mesh::BoundarySnapAndQualityImprovementType::None; |
| 181 |
|
| 182 |
stk::middle_mesh::MiddleGridOpts middleMeshOpts; |
| 183 |
middleMeshOpts.normalProjectionOpts.classifierTolerances = stk::middle_mesh::impl::PointClassifierNormalWrapperTolerances(eps); |
| 184 |
middleMeshOpts.normalProjectionOpts.edgeTracerTolerances = stk::middle_mesh::impl::EdgeTracerTolerances(eps); |
| 185 |
auto interface = stk::middle_mesh::application_interface_factory(stk::middle_mesh::ApplicationInterfaceType::Parallel, |
| 186 |
mesh1, mesh2, comm, nullptr, |
| 187 |
stk::middle_mesh::ParallelSearchOpts(), |
| 188 |
stk::middle_mesh::VolumeSnapOpts(), |
| 189 |
snapOpts, middleMeshOpts); |
| 190 |
interface->create_middle_grid(); |
| 191 |
|
| 192 |
batchTimer.stop_batch_timer(); |
| 193 |
} |
| 194 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 195 |
} |
| 196 |
|
| 197 |
TEST(MiddleMesh, CreateMiddleMeshFromMeshesWithLargeRefinementRatio2) |
| 198 |
{ |
| 199 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 200 |
|
| 201 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 202 |
const int NUM_RUNS = 5; |
| 203 |
const int NUM_ITERS = 1; |
| 204 |
|
| 205 |
stk::middle_mesh::mesh::impl::MeshSpec spec{800, 800, 0, 1, 0, 1}; |
| 206 |
stk::middle_mesh::mesh::impl::MeshSpec spec2{40, 40, 0, 1, 0, 1}; |
| 207 |
auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; }; |
| 208 |
|
| 209 |
batchTimer.initialize_batch_timer(); |
| 210 |
for (int i = 0; i < NUM_RUNS; ++i) { |
| 211 |
batchTimer.start_batch_timer(); |
| 212 |
|
| 213 |
auto mesh1 = stk::middle_mesh::mesh::impl::create_mesh(spec, func); |
| 214 |
auto mesh2 = stk::middle_mesh::mesh::impl::create_mesh(spec2, func); |
| 215 |
|
| 216 |
double eps = 1e-12; |
| 217 |
stk::middle_mesh::BoundarySnapAndQualityImprovementOpts snapOpts; |
| 218 |
snapOpts.type = stk::middle_mesh::BoundarySnapAndQualityImprovementType::None; |
| 219 |
|
| 220 |
stk::middle_mesh::MiddleGridOpts middleMeshOpts; |
| 221 |
middleMeshOpts.normalProjectionOpts.classifierTolerances = stk::middle_mesh::impl::PointClassifierNormalWrapperTolerances(eps); |
| 222 |
middleMeshOpts.normalProjectionOpts.edgeTracerTolerances = stk::middle_mesh::impl::EdgeTracerTolerances(eps); |
| 223 |
auto interface = stk::middle_mesh::application_interface_factory(stk::middle_mesh::ApplicationInterfaceType::Parallel, |
| 224 |
mesh1, mesh2, comm, nullptr, |
| 225 |
stk::middle_mesh::ParallelSearchOpts(), |
| 226 |
stk::middle_mesh::VolumeSnapOpts(), |
| 227 |
snapOpts, middleMeshOpts); |
| 228 |
interface->create_middle_grid(); |
| 229 |
|
| 230 |
batchTimer.stop_batch_timer(); |
| 231 |
} |
| 232 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
namespace { |
| 237 |
class CommSplitter |
| 238 |
{ |
| 239 |
public: |
| 240 |
CommSplitter(MPI_Comm comm) : |
| 241 |
m_inputComm(comm) |
| 242 |
{ |
| 243 |
split_comm(); |
| 244 |
} |
| 245 |
|
| 246 |
~CommSplitter() { MPI_Comm_free(&m_splitComm); } |
| 247 |
|
| 248 |
int get_color() const { return m_color; } |
| 249 |
|
| 250 |
MPI_Comm get_comm() const { return m_splitComm; } |
| 251 |
|
| 252 |
private: |
| 253 |
|
| 254 |
void split_comm() |
| 255 |
{ |
| 256 |
int inputCommSize = stk::middle_mesh::utils::impl::comm_size(m_inputComm); |
| 257 |
MPI_Comm newComm; |
| 258 |
int color = 0; |
| 259 |
if (inputCommSize == 1) |
| 260 |
{ |
| 261 |
MPI_Comm_dup(m_inputComm, &newComm); |
| 262 |
} else |
| 263 |
{ |
| 264 |
int nprocs1 = inputCommSize / 2 + (inputCommSize % 2); |
| 265 |
//int nprocs2 = inputCommSize / 2; |
| 266 |
|
| 267 |
color = stk::middle_mesh::utils::impl::comm_rank(m_inputComm) < nprocs1 ? 0 : 1; |
| 268 |
|
| 269 |
MPI_Comm_split(m_inputComm, color, 0, &newComm); |
| 270 |
} |
| 271 |
|
| 272 |
m_color = color; |
| 273 |
m_splitComm = newComm; |
| 274 |
} |
| 275 |
|
| 276 |
MPI_Comm m_inputComm; |
| 277 |
int m_color; |
| 278 |
MPI_Comm m_splitComm; |
| 279 |
|
| 280 |
}; |
| 281 |
} |
| 282 |
|
| 283 |
TEST(MiddleMesh, CreateMiddleMeshMPMD) |
| 284 |
{ |
| 285 |
using namespace stk::middle_mesh; |
| 286 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 287 |
|
| 288 |
int commSize = utils::impl::comm_size(comm); |
| 289 |
|
| 290 |
CommSplitter commSplitter(comm); |
| 291 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 292 |
const int NUM_RUNS = 5; |
| 293 |
const int NUM_ITERS = 1; |
| 294 |
|
| 295 |
stk::middle_mesh::mesh::impl::MeshSpec spec{400, 400, 0, 1, 0, 1}; |
| 296 |
stk::middle_mesh::mesh::impl::MeshSpec spec2{401, 401, 0, 1, 0, 1}; |
| 297 |
auto func = [&](const utils::Point& pt) { return utils::Point(pt.x, 0, pt.y); }; |
| 298 |
|
| 299 |
batchTimer.initialize_batch_timer(); |
| 300 |
for (int i = 0; i < NUM_RUNS; ++i) { |
| 301 |
batchTimer.start_batch_timer(); |
| 302 |
|
| 303 |
std::shared_ptr<mesh::Mesh> mesh1, mesh2; |
| 304 |
|
| 305 |
if (commSize == 1 || commSplitter.get_color() == 0) |
| 306 |
mesh1 = create_mesh(spec, func, commSplitter.get_comm()); |
| 307 |
|
| 308 |
if (commSize == 1 || commSplitter.get_color() == 1) |
| 309 |
mesh2 = create_mesh(spec2, func, commSplitter.get_comm()); |
| 310 |
|
| 311 |
double eps = 1e-12; |
| 312 |
BoundarySnapAndQualityImprovementOpts snapOpts; |
| 313 |
snapOpts.incrementalMeshBoundarySnapOpts.qualityImproverOpts.nlayers=5; |
| 314 |
|
| 315 |
MiddleGridOpts middleMeshOpts; |
| 316 |
middleMeshOpts.normalProjectionOpts.classifierTolerances = impl::PointClassifierNormalWrapperTolerances(eps); |
| 317 |
middleMeshOpts.normalProjectionOpts.edgeTracerTolerances = impl::EdgeTracerTolerances(eps); |
| 318 |
auto interface = application_interface_factory(ApplicationInterfaceType::Parallel, mesh1, mesh2, |
| 319 |
MPI_COMM_WORLD, nullptr, ParallelSearchOpts(), |
| 320 |
VolumeSnapOpts(), |
| 321 |
snapOpts, |
| 322 |
middleMeshOpts); |
| 323 |
|
| 324 |
interface->create_middle_grid(); |
| 325 |
|
| 326 |
batchTimer.stop_batch_timer(); |
| 327 |
} |
| 328 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
} |
| 334 |
|