Debian Codegraph @

packages/stk/stk_unit_tests/stk_io/UnitTestUtils.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 "stk_io/StkIoUtils.hpp" // for DatabasePurpose::READ_MESH, etc
36 #include "stk_io/FillMesh.hpp"
37 #include "stk_io/IossBridge.hpp"
38 #include <stk_util/parallel/Parallel.hpp>
39 #include <gtest/gtest.h>
40 #include <stk_unit_test_utils/BuildMesh.hpp>
41
42 namespace {
43
44 using stk::unit_test_util::build_mesh;
45 using stk::unit_test_util::build_mesh_no_simple_fields;
46
47 TEST(ParallelFileName, serialNameShouldBeUnchanged)
48 {
49 std::string fileName = "filename.exo";
50 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 1, 0), "filename.exo");
51 }
52
53 TEST(ParallelFileName, singleDigitNames)
54 {
55 std::string fileName = "filename.exo";
56 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 5, 0), "filename.exo.5.0");
57 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 9, 0), "filename.exo.9.0");
58 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 9, 8), "filename.exo.9.8");
59 }
60
61 TEST(ParallelFileName, multiDigitNames)
62 {
63 std::string fileName = "filename.exo";
64 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 10, 0), "filename.exo.10.00");
65 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 10, 9), "filename.exo.10.09");
66 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 99, 0), "filename.exo.99.00");
67 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 99, 9), "filename.exo.99.09");
68 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 99, 10), "filename.exo.99.10");
69 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 99, 98), "filename.exo.99.98");
70 EXPECT_EQ(stk::io::construct_filename_for_serial_or_parallel(fileName, 100, 98), "filename.exo.100.098");
71 }
72
73 TEST(ParallelFileName, InvalidInputs) {
74 std::string fileName = "filename.exo";
75 EXPECT_THROW(stk::io::construct_filename_for_serial_or_parallel(fileName, -1, 0), std::exception);
76 EXPECT_THROW(stk::io::construct_filename_for_serial_or_parallel(fileName, 100, -5), std::exception);
77 EXPECT_THROW(stk::io::construct_filename_for_serial_or_parallel(fileName, 107, 107), std::exception);
78 EXPECT_THROW(stk::io::construct_filename_for_serial_or_parallel(fileName, 107, 130), std::exception);
79
80 }
81
82 TEST(CheckElemBlockTopology, validTopology)
83 {
84 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) return;
85
86 const unsigned spatialDim = 3;
87 std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(spatialDim, MPI_COMM_WORLD);
88 stk::io::fill_mesh("generated:2x2x2", *bulk);
89 EXPECT_NO_THROW(stk::io::throw_if_any_elem_block_has_invalid_topology(bulk->mesh_meta_data(), "test"));
90 }
91
92 TEST(CheckElemBlockTopology, invalidTopology)
93 {
94 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) return;
95
96 stk::mesh::MetaData meta(3);
97 stk::mesh::Part& block2 = meta.declare_part("block_2", stk::topology::ELEM_RANK);
98 stk::io::put_io_part_attribute(block2);
99 EXPECT_THROW(stk::io::throw_if_any_elem_block_has_invalid_topology(meta, "test"), std::runtime_error);
100 }
101
102 }