| 1 |
#ifndef STK_SETUP_8QUAD4PROCMESH_H |
| 2 |
#define STK_SETUP_8QUAD4PROCMESH_H |
| 3 |
|
| 4 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 5 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 6 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 7 |
// in this software. |
| 8 |
// |
| 9 |
// Redistribution and use in source and binary forms, with or without |
| 10 |
// modification, are permitted provided that the following conditions are |
| 11 |
// met: |
| 12 |
// |
| 13 |
// * Redistributions of source code must retain the above copyright |
| 14 |
// notice, this list of conditions and the following disclaimer. |
| 15 |
// |
| 16 |
// * Redistributions in binary form must reproduce the above |
| 17 |
// copyright notice, this list of conditions and the following |
| 18 |
// disclaimer in the documentation and/or other materials provided |
| 19 |
// with the distribution. |
| 20 |
// |
| 21 |
// * Neither the name of NTESS nor the names of its contributors |
| 22 |
// may be used to endorse or promote products derived from this |
| 23 |
// software without specific prior written permission. |
| 24 |
// |
| 25 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 26 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 27 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 28 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 29 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 30 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 31 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 32 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 33 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 34 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 35 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 |
// |
| 37 |
|
| 38 |
#include <gtest/gtest.h> |
| 39 |
#include <stddef.h> // for size_t |
| 40 |
#include <stdlib.h> // for exit |
| 41 |
#include <exception> // for exception |
| 42 |
#include <iostream> // for ostringstream, etc |
| 43 |
#include <iterator> // for distance |
| 44 |
#include <map> // for _Rb_tree_const_iterator, etc |
| 45 |
#include <stdexcept> // for logic_error, runtime_error |
| 46 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData, etc |
| 47 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 48 |
#include <stk_util/parallel/Parallel.hpp> // for ParallelMachine, etc |
| 49 |
#include <stk_mesh/base/GetEntities.hpp> |
| 50 |
#include <string> // for string, basic_string, etc |
| 51 |
#include <utility> // for pair |
| 52 |
#include <vector> // for vector, etc |
| 53 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket, has_superset |
| 54 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 55 |
#include "stk_mesh/base/EntityKey.hpp" // for EntityKey |
| 56 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData, entity_rank_names, etc |
| 57 |
#include "stk_mesh/base/Part.hpp" // for Part |
| 58 |
#include "stk_mesh/base/Types.hpp" // for EntityProc, EntityVector, etc |
| 59 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 60 |
|
| 61 |
inline |
| 62 |
void setup8Quad4ProcMesh2D(stk::mesh::BulkData& bulk) |
| 63 |
{ |
| 64 |
STK_ThrowRequire(bulk.parallel_size() == 4); |
| 65 |
// |
| 66 |
// id/proc |
| 67 |
// 11/0--12/0--13/1--14/2--15/3 |
| 68 |
// | | | | | |
| 69 |
// | 5/0 | 6/1 | 7/2 | 8/3 | |
| 70 |
// | | | | | |
| 71 |
// 6/0---7/0---8/1---9/2--10/3 |
| 72 |
// | | | | | |
| 73 |
// | 1/0 | 2/1 | 3/2 | 4/3 | |
| 74 |
// | | | | | |
| 75 |
// 1/0---2/0---3/1---4/2---5/3 |
| 76 |
|
| 77 |
stk::mesh::MetaData& meta = bulk.mesh_meta_data(); |
| 78 |
|
| 79 |
stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", stk::topology::QUAD_4_2D); |
| 80 |
meta.commit(); |
| 81 |
|
| 82 |
bulk.modification_begin(); |
| 83 |
|
| 84 |
//2 elem-ids for each proc |
| 85 |
stk::mesh::EntityId proc_elemIDs[][2] = {{1, 5}, {2, 6}, {3, 7}, {4, 8}}; |
| 86 |
|
| 87 |
//list of node-ids for each element |
| 88 |
stk::mesh::EntityIdVector elem_nodeIDs[] { |
| 89 |
{1, 2, 7, 6}, |
| 90 |
{2, 3, 8, 7}, |
| 91 |
{3, 4, 9, 8}, |
| 92 |
{4, 5, 10, 9}, |
| 93 |
{6, 7, 12, 11}, |
| 94 |
{7, 8, 13, 12}, |
| 95 |
{8, 9, 14, 13}, |
| 96 |
{9, 10, 15, 14} |
| 97 |
}; |
| 98 |
|
| 99 |
//list of triples: (owner-proc, shared-nodeID, sharing-proc) |
| 100 |
int shared_nodeIDs_and_procs[][3] = { |
| 101 |
{0, 2, 1}, {0, 7, 1}, {0, 12, 1}, //proc 0 |
| 102 |
{1, 2, 0}, {1, 7, 0}, {1, 12, 0}, {1, 3, 2}, {1, 8, 2}, {1, 13, 2}, //proc 1 |
| 103 |
{2, 3, 1}, {2, 8, 1}, {2, 13, 1}, {2, 4, 3}, {2, 9, 3}, {2, 14, 3}, //proc 2 |
| 104 |
{3, 4, 2}, {3, 9, 2}, {3, 14, 2} //proc 3 |
| 105 |
}; |
| 106 |
|
| 107 |
stk::mesh::EntityId elemID = proc_elemIDs[bulk.parallel_rank()][0]; |
| 108 |
int elemIdx = elemID - 1; |
| 109 |
stk::mesh::declare_element(bulk, block_1, elemID, elem_nodeIDs[elemIdx]); |
| 110 |
|
| 111 |
elemID = proc_elemIDs[bulk.parallel_rank()][1]; |
| 112 |
elemIdx = elemID - 1; |
| 113 |
stk::mesh::declare_element(bulk, block_1, elemID, elem_nodeIDs[elemIdx]); |
| 114 |
|
| 115 |
int numSharedNodeTriples = 18; |
| 116 |
|
| 117 |
for(int i=0; i<numSharedNodeTriples; ++i) { |
| 118 |
if (bulk.parallel_rank() == shared_nodeIDs_and_procs[i][0]) { |
| 119 |
int nodeID = shared_nodeIDs_and_procs[i][1]; |
| 120 |
int sharingProc = shared_nodeIDs_and_procs[i][2]; |
| 121 |
stk::mesh::Entity node = bulk.get_entity(stk::topology::NODE_RANK, nodeID); |
| 122 |
bulk.add_node_sharing(node, sharingProc); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
bulk.modification_end(); |
| 127 |
|
| 128 |
std::vector<size_t> counts(meta.entity_rank_count()); |
| 129 |
stk::mesh::Selector owned_or_shared = meta.locally_owned_part() | meta.globally_shared_part(); |
| 130 |
stk::mesh::count_entities(owned_or_shared, bulk, counts); |
| 131 |
|
| 132 |
unsigned numNodes = counts[stk::topology::NODE_RANK]; |
| 133 |
unsigned numElems = counts[stk::topology::ELEM_RANK]; |
| 134 |
|
| 135 |
unsigned expectedNumNodes = 6; |
| 136 |
unsigned expectedNumElems = 2; |
| 137 |
EXPECT_EQ(expectedNumNodes, numNodes); |
| 138 |
EXPECT_EQ(expectedNumElems, numElems); |
| 139 |
} |
| 140 |
|
| 141 |
#endif |