Debian Codegraph @

packages/stk/stk_doc_tests/stk_io/readMeshDelayFieldAllocation.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> // for AssertHelper, EXPECT_NE, etc
36 #include <stddef.h> // for size_t, NULL
37 #include <unistd.h> // for unlink
38 #include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
39 #include <stk_mesh/base/MetaData.hpp> // for MetaData
40 #include <string> // for string
41 #include "stk_io/DatabasePurpose.hpp" // for DatabasePurpose::READ_MESH, etc
42 namespace stk { namespace mesh { class Part; } }
43 namespace {
44
45 TEST(StkMeshIoBrokerHowTo, readMeshDelayFieldAllocation)
46 {
47 std::string mesh_name = "input_mesh_example.e";
48 MPI_Comm communicator = MPI_COMM_WORLD;
49
50 {
51 // ============================================================
52 //+ INITIALIZATION:
53 //+ Create a basic mesh with a hex block, 3 shell blocks, 3 nodesets, and 3 sidesets.
54 stk::io::StkMeshIoBroker stkIo(communicator);
55
56 const std::string generatedFileName = "generated:8x8x8|shell:xyz|nodeset:xyz|sideset:XYZ";
57 size_t index = stkIo.add_mesh_database(generatedFileName, stk::io::READ_MESH);
58 stkIo.set_active_mesh(index);
59
60 stkIo.create_input_mesh();
61 stkIo.populate_bulk_data();
62
63 size_t fh = stkIo.create_output_mesh(mesh_name, stk::io::WRITE_RESULTS);
64 stkIo.write_output_mesh(fh);
65 }
66
67 {
68 //-BEGIN
69 // ============================================================
70 //+ EXAMPLE:
71 //+ Read mesh data from the specified file.
72 stk::io::StkMeshIoBroker stkIo(communicator);
73 stkIo.add_mesh_database(mesh_name, stk::io::READ_MESH);
74
75 //+ Creates meta data; creates parts
76 stkIo.create_input_mesh();
77
78 //+ Any modifications to the meta data must be done here.
79 //+ This includes declaring fields.
80
81 //+ Commit the meta data and create the bulk data.
82 //+ populate the bulk data with data from the mesh file.
83 stkIo.populate_mesh();
84
85 //+ Application would call mesh modification here.
86 //+ for example, create_edges().
87
88 //+ Mesh modifications complete, allocate field data.
89 stkIo.populate_field_data();
90
91 //-END
92 // ============================================================
93 //+ VERIFICATION
94 //+ There should be:
95 //+ 4 parts corresponding to the 1 hex block and 3 shell blocks
96 stk::mesh::MetaData &meta = stkIo.meta_data();
97 stk::mesh::Part *invalid = NULL;
98 EXPECT_NE(invalid, meta.get_part("block_1"));
99 EXPECT_NE(invalid, meta.get_part("block_2"));
100 EXPECT_NE(invalid, meta.get_part("block_3"));
101 EXPECT_NE(invalid, meta.get_part("block_4"));
102
103 //+ 3 parts corresponding to the 3 nodesets.
104 EXPECT_NE(invalid, meta.get_part("nodelist_1"));
105 EXPECT_NE(invalid, meta.get_part("nodelist_2"));
106 EXPECT_NE(invalid, meta.get_part("nodelist_3"));
107
108 //+ 3 parts corresponding to the 3 sidesets.
109 EXPECT_NE(invalid, meta.get_part("surface_1"));
110 EXPECT_NE(invalid, meta.get_part("surface_2"));
111 EXPECT_NE(invalid, meta.get_part("surface_3"));
112
113 }
114 // ============================================================
115 // Cleanup
116 unlink(mesh_name.c_str());
117 }
118 }