Debian Codegraph @

packages/stk/stk_doc_tests/stk_io/howToWriteMesh.cpp

raw
1 #include <gtest/gtest.h>
2 #include <stk_unit_test_utils/getOption.h>
3 #include <unistd.h>
4
5 #include <stk_io/StkMeshIoBroker.hpp>
6 #include <stk_io/WriteMesh.hpp>
7 #include <stk_mesh/base/BulkData.hpp>
8 #include <stk_mesh/base/MeshBuilder.hpp>
9 #include <stk_mesh/base/Comm.hpp>
10 #include <stk_mesh/base/MetaData.hpp>
11 #include <stk_unit_test_utils/CommandLineArgs.hpp>
12 #include <stk_unit_test_utils/ioUtils.hpp>
13
14 namespace
15 {
16
17 TEST(StkIoHowTo, WriteMesh)
18 {
19 std::string filename = "output.exo";
20 {
21 std::shared_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(MPI_COMM_WORLD).create();
22 stk::io::fill_mesh("generated:1x1x4", *bulk);
23
24 stk::io::StkMeshIoBroker stkIo;
25 stkIo.set_bulk_data(bulk);
26 size_t outputFileIndex = stkIo.create_output_mesh(filename, stk::io::WRITE_RESULTS);
27 stkIo.write_output_mesh(outputFileIndex);
28 stkIo.write_defined_output_fields(outputFileIndex);
29 }
30
31 {
32 std::shared_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(MPI_COMM_WORLD).create();
33 stk::io::fill_mesh(filename, *bulk);
34
35 std::vector<size_t> entityCounts;
36 stk::mesh::comm_mesh_counts(*bulk, entityCounts);
37 EXPECT_EQ(4u, entityCounts[stk::topology::ELEM_RANK]);
38 }
39
40 unlink(filename.c_str());
41 }
42
43 TEST(StkIoHowTo, generateMeshWith64BitIds)
44 {
45 std::string meshSpec = stk::unit_test_util::get_option("-i", "1x1x4");
46 std::string fullMeshSpec = "generated:"+meshSpec;
47
48 std::string filename = "output.exo";
49 stk::io::StkMeshIoBroker inputBroker;
50
51 //+ Set properties to ensure that 64-bit integers will be used
52 inputBroker.property_add(Ioss::Property("INTEGER_SIZE_API" , 8));
53 inputBroker.property_add(Ioss::Property("INTEGER_SIZE_DB" , 8));
54 std::shared_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(MPI_COMM_WORLD).create();
55 stk::io::fill_mesh_preexisting(inputBroker, fullMeshSpec, *bulk);
56
57 stk::io::write_mesh_with_large_ids_and_fields(filename, *bulk);
58
59 if (stk::unit_test_util::GlobalCommandLineArguments::self().get_argc() == 0) {
60 unlink(filename.c_str());
61 }
62 }
63
64 }