| 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, TEST, etc |
| 36 |
#include <stddef.h> // for size_t |
| 37 |
#include <ostream> // for basic_ostream::operator<< |
| 38 |
#include "mpi.h" // for MPI_COMM_WORLD, etc |
| 39 |
|
| 40 |
#include "stk_mesh/base/BulkData.hpp" // for BulkData |
| 41 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 42 |
#include "stk_mesh/base/EntityKey.hpp" // for EntityKey |
| 43 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData |
| 44 |
#include "stk_mesh/base/Types.hpp" // for ConnectivityOrdinal, etc |
| 45 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 46 |
#include "stk_unit_test_utils/stk_mesh_fixtures/HexFixture.hpp" // for HexFixture |
| 47 |
#include "stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp" // for QuadFixture |
| 48 |
#include "stk_util/parallel/Parallel.hpp" // for parallel_machine_rank, etc |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
//---------------------------------------------------------------------------- |
| 53 |
|
| 54 |
TEST ( UnitTestCrackMesh , VerifyDestroy2D ) |
| 55 |
{ |
| 56 |
// In 2D, build a fresh 3x3 mesh each loop iteration, destroying a different |
| 57 |
// single element each time. |
| 58 |
|
| 59 |
stk::ParallelMachine pm = MPI_COMM_WORLD ; |
| 60 |
const int p_rank = stk::parallel_machine_rank( pm ); |
| 61 |
|
| 62 |
const unsigned nx = 3 , ny = 3 ; |
| 63 |
|
| 64 |
for ( unsigned iy = 0 ; iy < ny ; ++iy ) { |
| 65 |
for ( unsigned ix = 0 ; ix < nx ; ++ix ) { |
| 66 |
stk::mesh::fixtures::QuadFixture fixture( pm , nx , ny ); |
| 67 |
fixture.m_meta.commit(); |
| 68 |
fixture.generate_mesh(); |
| 69 |
|
| 70 |
fixture.m_bulk_data.modification_begin(); |
| 71 |
|
| 72 |
stk::mesh::Entity elem = fixture.elem( ix , iy ); |
| 73 |
|
| 74 |
if ( fixture.m_bulk_data.is_valid(elem) && p_rank == fixture.m_bulk_data.parallel_owner_rank(elem) ) { |
| 75 |
stk::mesh::Entity tmp = elem ; |
| 76 |
fixture.m_bulk_data.destroy_entity( tmp ); |
| 77 |
} |
| 78 |
|
| 79 |
fixture.m_bulk_data.modification_end(); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
TEST ( UnitTestCrackMesh , VerifyDestroy3D ) |
| 85 |
{ |
| 86 |
// In 3D, build a 3x3x3 mesh each loop iteration, destroying a different |
| 87 |
// single element each time. |
| 88 |
|
| 89 |
stk::ParallelMachine pm = MPI_COMM_WORLD ; |
| 90 |
const int p_rank = stk::parallel_machine_rank( pm ); |
| 91 |
|
| 92 |
const unsigned nx = 3 , ny = 3 , nz = 3 ; |
| 93 |
|
| 94 |
for ( unsigned iz = 0 ; iz < nz ; ++iz ) { |
| 95 |
for ( unsigned iy = 0 ; iy < ny ; ++iy ) { |
| 96 |
for ( unsigned ix = 0 ; ix < nx ; ++ix ) { |
| 97 |
stk::mesh::fixtures::HexFixture fixture( pm , nx , ny , nz ); |
| 98 |
fixture.m_meta.commit(); |
| 99 |
fixture.generate_mesh(); |
| 100 |
|
| 101 |
fixture.m_bulk_data.modification_begin(); |
| 102 |
|
| 103 |
stk::mesh::Entity elem = fixture.elem( ix , iy , iz ); |
| 104 |
|
| 105 |
if ( fixture.m_bulk_data.is_valid(elem) && p_rank == fixture.m_bulk_data.parallel_owner_rank(elem) ) { |
| 106 |
stk::mesh::Entity tmp = elem ; |
| 107 |
fixture.m_bulk_data.destroy_entity( tmp ); |
| 108 |
} |
| 109 |
|
| 110 |
fixture.m_bulk_data.modification_end(); |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
//---------------------------------------------------------------------------- |
| 117 |
|
| 118 |
TEST ( UnitTestCrackMesh , verifyBoxGhosting ) |
| 119 |
{ |
| 120 |
// Start with a normal hex fixture, then crack it, and check to see |
| 121 |
// if all (incl ghosted) copies get updated. |
| 122 |
|
| 123 |
// Make the hex fixture |
| 124 |
stk::mesh::fixtures::HexFixture fixture( MPI_COMM_WORLD, 2,2,2 ); |
| 125 |
fixture.m_meta.commit(); |
| 126 |
fixture.generate_mesh(); |
| 127 |
|
| 128 |
stk::mesh::BulkData & mesh = fixture.m_bulk_data; |
| 129 |
|
| 130 |
// Hardwire which entities are being modified. Note that not every |
| 131 |
// process will know about these entities |
| 132 |
|
| 133 |
stk::mesh::Entity old_node = fixture.node(0,1,1); |
| 134 |
|
| 135 |
stk::mesh::Entity right_element = fixture.elem(0,0,1); |
| 136 |
const stk::mesh::EntityKey right_element_key = mesh.entity_key(right_element); |
| 137 |
|
| 138 |
unsigned right_ordinal = 0; |
| 139 |
const unsigned new_node_id = 28; |
| 140 |
|
| 141 |
// If this process knows about both entities, compute the ordinal |
| 142 |
// of the relation from right_element to old_node |
| 143 |
if ( mesh.is_valid(old_node) && mesh.is_valid(right_element) ) |
| 144 |
{ |
| 145 |
size_t num_rels = mesh.num_elements(old_node); |
| 146 |
stk::mesh::Entity const *rel_elems = mesh.begin_elements(old_node); |
| 147 |
stk::mesh::ConnectivityOrdinal const *rel_ords = mesh.begin_element_ordinals(old_node); |
| 148 |
for (size_t i = 0; i < num_rels; ++i) |
| 149 |
{ |
| 150 |
if (right_element == rel_elems[i]) |
| 151 |
{ |
| 152 |
right_ordinal = rel_ords[i]; |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
// Crack the mesh |
| 158 |
|
| 159 |
mesh.modification_begin(); |
| 160 |
|
| 161 |
//only crack the mesh if I own the element |
| 162 |
if ( mesh.is_valid(right_element) && |
| 163 |
mesh.parallel_owner_rank(right_element) == mesh.parallel_rank() ) { |
| 164 |
|
| 165 |
const stk::mesh::PartVector no_parts; |
| 166 |
|
| 167 |
// create a new node |
| 168 |
stk::mesh::Entity new_node = mesh.declare_node(new_node_id, no_parts); |
| 169 |
|
| 170 |
// destroy right_element's relation to old_node, replace with a |
| 171 |
// relation to new node |
| 172 |
mesh.destroy_relation(right_element, old_node, right_ordinal); |
| 173 |
mesh.declare_relation(right_element, new_node, right_ordinal); |
| 174 |
} |
| 175 |
|
| 176 |
mesh.modification_end(); |
| 177 |
|
| 178 |
// Refesh handle. If ghosting, it would have been deleted and recreated, so the unlying |
| 179 |
// pointer may have changed. |
| 180 |
right_element = mesh.get_entity(right_element_key); |
| 181 |
|
| 182 |
// Now that modification_end has been called, all processes that know |
| 183 |
// about right_element should know about the crack. |
| 184 |
|
| 185 |
if ( mesh.is_valid(right_element) ) { |
| 186 |
int num_node_rels = mesh.num_nodes(right_element); |
| 187 |
ASSERT_EQ(num_node_rels, 8); |
| 188 |
stk::mesh::Entity new_node = mesh.begin_nodes(right_element)[right_ordinal]; |
| 189 |
ASSERT_TRUE(mesh.is_valid(new_node)); |
| 190 |
|
| 191 |
EXPECT_EQ ( mesh.identifier(new_node), new_node_id ); |
| 192 |
} |
| 193 |
} |