Debian Codegraph @

packages/stk/stk_performance_tests/stk_middle_mesh/perfMiddleMeshQualityImprover.cpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include <gtest/gtest.h>
36 #include <stk_util/parallel/Parallel.hpp>
37 #include <stk_mesh/base/BulkData.hpp>
38 #include <stk_mesh/base/GetEntities.hpp>
39 #include <stk_middle_mesh/create_mesh.hpp>
40 #include <stk_middle_mesh/mesh_boundary_snapper.hpp>
41 #include <stk_middle_mesh/incremental_mesh_boundary_snapper.hpp>
42 #include <stk_middle_mesh_util/create_stk_mesh.hpp>
43 #include <stk_unit_tests/stk_middle_mesh/util/meshes.hpp>
44 #include <stk_unit_test_utils/getOption.h>
45 #include <stk_unit_test_utils/timer.hpp>
46
47 namespace {
48
49 auto pi = std::atan(1) * 4;
50
51 template <typename T>
52 std::shared_ptr<stk::middle_mesh::mesh::Mesh> make_annulus_mesh(const int nelemR, const int nelemTheta, const double rIn,
53 const double rOut, double dtheta, MPI_Comm comm, T func2)
54 {
55 assert(rIn > 0);
56 assert(rOut > rIn);
57
58 stk::middle_mesh::mesh::impl::MeshSpec spec;
59 spec.numelX = nelemR;
60 spec.numelY = nelemTheta;
61 spec.xmin = rIn;
62 spec.xmax = rOut;
63 spec.ymin = 0;
64 spec.ymax = 2 * pi;
65 spec.yPeriodic = true;
66
67 auto func = [&](const stk::middle_mesh::utils::Point& pt) {
68 double r = pt.x;
69 double theta = pt.y;
70 if (std::fmod(theta, 2 * pi) > 1e-12)
71 theta += dtheta;
72
73 double x = r * std::cos(theta);
74 double y = r * std::sin(theta);
75 double z = func2(x, y);
76 stk::middle_mesh::utils::Point pt2(x, y, z);
77 return pt2;
78 };
79
80 return stk::middle_mesh::mesh::impl::create_mesh(spec, func, comm);
81 }
82
83 std::shared_ptr<stk::middle_mesh::mesh::Mesh> make_annulus_mesh(const int nelemR, const int nelemTheta, const double rIn,
84 const double rOut, double dtheta, MPI_Comm comm = MPI_COMM_WORLD)
85 {
86 auto f2 = [](const double /*x*/, const double /*y*/) { return 0.0; };
87 return make_annulus_mesh(nelemR, nelemTheta, rIn, rOut, dtheta, comm, f2);
88 }
89
90
91 TEST(MiddleMeshQualityImprover, IncrementalBoundarySnapperAnnulusRotation)
92 {
93 stk::ParallelMachine comm = MPI_COMM_WORLD;
94
95 const int NUM_RUNS = 3;
96 const int NUM_ITERS = 1;
97
98 stk::unit_test_util::BatchTimer batchTimer(comm);
99 batchTimer.initialize_batch_timer();
100 for (unsigned run = 0; run < NUM_RUNS; ++run) {
101 std::cout << "run = " << run << std::endl;
102 auto mesh1 = make_annulus_mesh(35, 35, 0.5, 1.5, 0);
103 auto mesh2 = make_annulus_mesh(71, 71, 0.5, 1.5, pi/32);
104
105 batchTimer.start_batch_timer();
106 auto bsnapper = stk::middle_mesh::mesh::impl::make_incremental_boundary_snapper(mesh1, mesh2, comm);
107 bsnapper->snap();
108 batchTimer.stop_batch_timer();
109 }
110 batchTimer.print_batch_timing(NUM_ITERS);
111 }
112
113 TEST(MiddleMeshQualityImprover, IncrementalBoundarySnapperLargeElemCount)
114 {
115 stk::ParallelMachine comm = MPI_COMM_WORLD;
116
117 const int NUM_RUNS = 3;
118 const int NUM_ITERS = 1;
119
120 stk::unit_test_util::BatchTimer batchTimer(comm);
121 batchTimer.initialize_batch_timer();
122 for (unsigned run = 0; run < NUM_RUNS; ++run) {
123
124 stk::middle_mesh::mesh::impl::MeshSpec spec{300, 300, 0, 1, 0, 1};
125 stk::middle_mesh::mesh::impl::MeshSpec spec2{30, 30, 0, 1, 0, 1};
126 auto func = [&](stk::middle_mesh::utils::Point const& pt) { return pt; };
127
128 auto mesh1 = create_mesh(spec, func);
129 auto mesh2 = create_mesh(spec2, func);
130
131 batchTimer.start_batch_timer();
132 auto bsnapper = stk::middle_mesh::mesh::impl::make_incremental_boundary_snapper(mesh1, mesh2, comm);
133 bsnapper->snap();
134 batchTimer.stop_batch_timer();
135 }
136 batchTimer.print_batch_timing(NUM_ITERS);
137 }
138
139 }