Debian Codegraph @

packages/stk/stk_performance_tests/stk_mesh/MeshOperations.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
37 #include <stk_io/StkMeshIoBroker.hpp>
38 #include <stk_mesh/base/BulkData.hpp>
39 #include <stk_mesh/base/Comm.hpp>
40 #include <stk_mesh/base/FEMHelpers.hpp>
41 #include <stk_mesh/base/SkinMesh.hpp>
42 #include <stk_unit_test_utils/CommandLineArgs.hpp>
43 #include <stk_unit_test_utils/MeshFixture.hpp>
44 #include <stk_unit_test_utils/timer.hpp>
45 #include <stk_util/environment/perf_util.hpp>
46 #include <stk_util/parallel/ParallelReduce.hpp>
47 #include <string>
48
49 class MeshOperations : public stk::unit_test_util::MeshFixture {
50 public:
51 MeshOperations()
52 : p_rank(get_parallel_rank()),
53 PHASE_NAMES(NUM_PHASES+1),
54 input_base_filename("mesh_operations.g"),
55 output_base_filename("mesh_operations.e")
56 {
57 PHASE_NAMES[INIT_META_DATA_PHASE_ID] = "Init meta data";
58 PHASE_NAMES[INIT_BULK_DATA_PHASE_ID] = "Init bulk data";
59 PHASE_NAMES[SKIN_MESH_PHASE_ID] = "Skin mesh";
60 PHASE_NAMES[EXODUS_CREATE_PHASE_ID] = "Exodus file creation";
61 PHASE_NAMES[PROCESS_OUTPUT_PHASE_ID] = "Process output";
62 PHASE_NAMES[NUM_PHASES] = "Total time";
63 }
64
65 protected:
66 void parse_filename_args() {
67 const std::string input_flag = "--heavy-test:input-file=";
68 const std::string output_flag = "--heavy-test:output-file=";
69
70 stk::unit_test_util::GlobalCommandLineArguments& args = stk::unit_test_util::GlobalCommandLineArguments::self();
71
72 for (int argitr = 1; argitr < args.get_argc(); ++argitr) {
73 std::string argv(args.get_argv()[argitr]);
74 if (argv.find(input_flag) == 0) {
75 input_base_filename = argv.replace(0, input_flag.size(), "");
76 }
77 else if (argv.find(output_flag) == 0) {
78 output_base_filename = argv.replace(0, output_flag.size(), "");
79 }
80 }
81 }
82
83 void initialize_meta(stk::io::StkMeshIoBroker& broker) {
84 broker.add_mesh_database(input_base_filename, stk::io::READ_MESH);
85 broker.create_input_mesh();
86 }
87
88 void initialize_bulk(stk::io::StkMeshIoBroker& broker) {
89 broker.populate_bulk_data();
90 }
91
92 void skin_bulk(stk::io::StkMeshIoBroker& broker) {
93 stk::mesh::skin_mesh(broker.bulk_data());
94 }
95
96 size_t create_exodus_file(stk::io::StkMeshIoBroker& broker) {
97 size_t index = broker.create_output_mesh( output_base_filename, stk::io::WRITE_RESULTS);
98 return index;
99 }
100
101 void process_output(stk::io::StkMeshIoBroker& broker, size_t index) {
102 double time_step = 0;
103 broker.process_output_request(index, time_step);
104 }
105
106 void print_mesh_stats(stk::mesh::BulkData& bulk) {
107 std::vector<size_t> counts ;
108 stk::mesh::comm_mesh_counts(bulk, counts);
109
110 if (p_rank == 0) {
111 std::cout << " mesh_stats\n";
112 for (unsigned i = 0; i < counts.size(); ++i) {
113 std::cout << " entity rank=" << i << " count=" << counts[i] << "\n";
114 }
115 std::cout << std::endl;
116 }
117 }
118
119 private:
120 const size_t p_rank;
121
122 static constexpr unsigned NUM_PHASES = 5;
123
124 const unsigned INIT_META_DATA_PHASE_ID = 0;
125 const unsigned INIT_BULK_DATA_PHASE_ID = 1;
126 const unsigned SKIN_MESH_PHASE_ID = 2;
127 const unsigned EXODUS_CREATE_PHASE_ID = 3;
128 const unsigned PROCESS_OUTPUT_PHASE_ID = 4;
129
130 std::vector<std::string> PHASE_NAMES;
131
132 std::string input_base_filename;
133 std::string output_base_filename;
134 };
135
136 TEST_F( MeshOperations, PerformanceTimings )
137 {
138 const unsigned NUM_RUNS = 5;
139
140 stk::parallel_machine_barrier(get_comm());
141 stk::unit_test_util::BatchTimer batchTimer(get_comm());
142
143 parse_filename_args();
144
145 batchTimer.initialize_batch_timer();
146 for (unsigned run=0; run<NUM_RUNS; run++) {
147 stk::parallel_machine_barrier(get_comm());
148 batchTimer.start_batch_timer();
149
150 stk::io::StkMeshIoBroker broker(get_comm());
151
152 initialize_meta(broker);
153 initialize_bulk(broker);
154 skin_bulk(broker);
155 size_t index = create_exodus_file(broker);
156 process_output(broker, index);
157
158 if (run == NUM_RUNS-1) {
159 print_mesh_stats(broker.bulk_data());
160 }
161
162 batchTimer.stop_batch_timer();
163 }
164
165 batchTimer.print_batch_timing(NUM_RUNS);
166 }
167