| 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 |
#ifndef FACECREATORFIXTURE_HPP_ |
| 35 |
#define FACECREATORFIXTURE_HPP_ |
| 36 |
|
| 37 |
#include "stk_mesh/base/Comm.hpp" |
| 38 |
#include "stk_mesh/base/GetEntities.hpp" |
| 39 |
#include <gtest/gtest.h> |
| 40 |
#include <stk_unit_test_utils/FaceTestingUtils.hpp> |
| 41 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 42 |
|
| 43 |
class FaceCreatorFixture : public stk::unit_test_util::MeshFixture |
| 44 |
{ |
| 45 |
protected: |
| 46 |
|
| 47 |
FaceCreatorFixture(unsigned spatial_dim = 3) : MeshFixture(spatial_dim) {} |
| 48 |
|
| 49 |
virtual ~FaceCreatorFixture() { } |
| 50 |
|
| 51 |
void test_that_one_face_exists_after_both_procs_create_face_on_proc_boundary() |
| 52 |
{ |
| 53 |
each_proc_make_face_on_proc_boundary(); |
| 54 |
test_that_num_sides_is_expected_value(1); |
| 55 |
} |
| 56 |
|
| 57 |
void each_proc_make_face_on_proc_boundary() |
| 58 |
{ |
| 59 |
unsigned id = get_bulk().parallel_rank()+1; |
| 60 |
stk::mesh::Entity elem = get_bulk().get_entity(stk::topology::ELEM_RANK, id); |
| 61 |
stk::mesh::EntityVector nodes_of_face = get_nodes_of_face_for_this_proc(); |
| 62 |
create_faces(elem, nodes_of_face); |
| 63 |
} |
| 64 |
|
| 65 |
virtual stk::mesh::EntityVector get_nodes_of_face_for_this_proc() |
| 66 |
{ |
| 67 |
std::vector<unsigned> face_node_ids = { 8, 7, 5, 6 }; |
| 68 |
return get_nodes_for_proc(face_node_ids); |
| 69 |
} |
| 70 |
|
| 71 |
void create_faces(stk::mesh::Entity element, stk::mesh::EntityVector& nodes_of_face) |
| 72 |
{ |
| 73 |
get_bulk().modification_begin(); |
| 74 |
create_face_per_proc(element, nodes_of_face); |
| 75 |
test_that_num_sides_is_expected_value(2); |
| 76 |
get_bulk().modification_end(); |
| 77 |
} |
| 78 |
|
| 79 |
virtual void test_that_one_face_exists_on_both_procs_after_only_one_proc_makes_face() |
| 80 |
{ |
| 81 |
only_proc_0_makes_a_face(); |
| 82 |
test_that_num_sides_is_expected_value(1); |
| 83 |
test_that_each_proc_has_num_sides_with_expected_value(1); |
| 84 |
} |
| 85 |
|
| 86 |
void only_proc_0_makes_a_face() |
| 87 |
{ |
| 88 |
unsigned id = get_bulk().parallel_rank()+1; |
| 89 |
stk::mesh::Entity elem = get_bulk().get_entity(stk::topology::ELEM_RANK, id); |
| 90 |
stk::mesh::EntityVector nodes_of_face = get_nodes_of_face_for_this_proc(); |
| 91 |
create_faces_only_one_proc(elem, nodes_of_face); |
| 92 |
} |
| 93 |
|
| 94 |
virtual void create_faces_only_one_proc(stk::mesh::Entity element, stk::mesh::EntityVector& nodes_of_face) |
| 95 |
{ |
| 96 |
get_bulk().modification_begin(); |
| 97 |
if(get_bulk().parallel_rank()==0) |
| 98 |
{ |
| 99 |
create_face_per_proc(element, nodes_of_face); |
| 100 |
} |
| 101 |
test_that_num_sides_is_expected_value(1); |
| 102 |
get_bulk().modification_end(); |
| 103 |
} |
| 104 |
|
| 105 |
void create_face_per_proc(stk::mesh::Entity element, stk::mesh::EntityVector& nodes_of_face) |
| 106 |
{ |
| 107 |
unsigned id = get_bulk().parallel_rank()+1; |
| 108 |
stk::topology side_topology = get_bulk().bucket(element).topology().side_topology(); |
| 109 |
stk::mesh::Entity side = stk::unit_test_util::declare_element_side_with_nodes(get_bulk(), element, nodes_of_face, id, get_meta().get_topology_root_part(side_topology)); |
| 110 |
EXPECT_TRUE(get_bulk().is_valid(side)); |
| 111 |
} |
| 112 |
|
| 113 |
virtual unsigned get_permuted_index(unsigned i) |
| 114 |
{ |
| 115 |
std::vector<std::vector<unsigned> > index_for_proc = { |
| 116 |
{0, 1, 2, 3}, |
| 117 |
{3, 2, 1, 0} |
| 118 |
}; |
| 119 |
return index_for_proc[get_bulk().parallel_rank()][i]; |
| 120 |
} |
| 121 |
|
| 122 |
stk::mesh::EntityVector get_nodes_for_proc(const std::vector<unsigned>& face_node_ids) |
| 123 |
{ |
| 124 |
stk::mesh::EntityVector nodes(face_node_ids.size()); |
| 125 |
for(size_t n = 0; n < nodes.size(); ++n) |
| 126 |
nodes[n] = get_bulk().get_entity(stk::topology::NODE_RANK, face_node_ids[get_permuted_index(n)]); |
| 127 |
return nodes; |
| 128 |
} |
| 129 |
|
| 130 |
void test_that_num_sides_is_expected_value(size_t num_sides_gold) |
| 131 |
{ |
| 132 |
std::vector<size_t> counts; |
| 133 |
stk::mesh::comm_mesh_counts(get_bulk(), counts); |
| 134 |
EXPECT_EQ(num_sides_gold, counts[get_meta().side_rank()]); |
| 135 |
} |
| 136 |
|
| 137 |
void test_that_each_proc_has_num_sides_with_expected_value(unsigned expected_num_sides) |
| 138 |
{ |
| 139 |
unsigned num_local_sides = stk::mesh::count_selected_entities(get_bulk().mesh_meta_data().globally_shared_part(), get_bulk().buckets(get_bulk().mesh_meta_data().side_rank())); |
| 140 |
EXPECT_EQ(expected_num_sides, num_local_sides); |
| 141 |
} |
| 142 |
}; |
| 143 |
|
| 144 |
#endif /* FACECREATORFIXTURE_HPP_ */ |