Debian Codegraph @

packages/stk/stk_unit_tests/stk_io/UnitTestAccessCommSet.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 <stddef.h> // for size_t
36 #include <stdlib.h> // for exit
37 #include <exception> // for exception
38 #include <iostream> // for ostringstream, etc
39 #include <gtest/gtest.h>
40 #include <string> // for string, basic_string, etc
41 #include <utility> // for pair
42 #include <vector> // for vector, etc
43 #include "stk_mesh/base/MetaData.hpp"
44 #include "stk_mesh/base/BulkData.hpp"
45 #include "stk_mesh/base/GetEntities.hpp"
46 #include <stk_util/parallel/Parallel.hpp> // for ParallelMachine, etc
47 #include "stk_io/StkMeshIoBroker.hpp"
48 #include "Ioss_Region.h"
49 #include "Ioss_CommSet.h"
50
51 TEST(UnitTestAccessCommSet, basicNodeComm)
52 {
53 stk::ParallelMachine communicator = MPI_COMM_WORLD;
54
55 stk::io::StkMeshIoBroker stkMeshIoBroker(communicator);
56 stkMeshIoBroker.add_mesh_database("generated:1x1x4", stk::io::READ_MESH);
57 stkMeshIoBroker.create_input_mesh();
58 stkMeshIoBroker.populate_bulk_data();
59
60 const stk::mesh::MetaData& stkmeta = stkMeshIoBroker.meta_data();
61 const stk::mesh::BulkData& stkmesh = stkMeshIoBroker.bulk_data();
62 int myProc = stkmesh.parallel_rank();
63 int numProcs = stkmesh.parallel_size();
64
65 if (numProcs != 2) {
66 std::cout<<"UnitTestAccessCommSet.basicNodeComm only runs on 2 procs"<<std::endl;
67 return;
68 }
69
70 const unsigned expected_num_nodes = 16;
71 unsigned num_nodes = stk::mesh::count_selected_entities(stkmeta.universal_part(), stkmesh.buckets(stk::topology::NODE_RANK));
72 EXPECT_EQ(expected_num_nodes, num_nodes);
73
74 std::cout<<"proc "<<myProc<<", num nodes: "<<num_nodes<<std::endl;
75
76 Ioss::Region& ioss_region = *stkMeshIoBroker.get_input_ioss_region();
77 Ioss::CommSet* io_cs = ioss_region.get_commset("commset_node");
78 EXPECT_FALSE(NULL == io_cs);
79
80 const int expected_num_shared_nodes = 4;
81 int num_shared_nodes = io_cs->get_field("entity_processor").raw_count();
82 EXPECT_EQ(expected_num_shared_nodes, num_shared_nodes);
83
84 std::cout<<"proc "<<myProc<<", num shared nodes: "<<num_shared_nodes<<std::endl;
85
86 std::vector<int> entity_proc;
87 io_cs->get_field_data("entity_processor", entity_proc);
88
89 // std::cout<<"proc "<<myProc<<", entity_processor field data size: "<<entity_proc.size()<<std::endl;
90 // for(int i=0; i<num_shared_nodes; ++i) {
91 // std::cout<<"on proc "<<myProc<<", node "<<entity_proc[i*2]<<" is shared with proc "<<entity_proc[i*2+1]<<std::endl;
92 // }
93 }