| 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 "stk_unit_test_utils/stk_mesh_fixtures/HexFixture.hpp" |
| 36 |
#include <cmath> |
| 37 |
#include <gtest/gtest.h> |
| 38 |
#include <iomanip> |
| 39 |
#include <iostream> |
| 40 |
#include <sstream> |
| 41 |
#include <stk_mesh/base/Field.hpp> |
| 42 |
#include <stk_search_util/PeriodicBoundarySearch.hpp> |
| 43 |
|
| 44 |
typedef stk::mesh::fixtures::HexFixture::CoordFieldType CoordFieldType; |
| 45 |
typedef stk::mesh::GetCoordinates<CoordFieldType> CoordinateFunctor; |
| 46 |
typedef stk::mesh::PeriodicBoundarySearch<CoordinateFunctor> PeriodicSearch; |
| 47 |
|
| 48 |
namespace { |
| 49 |
const double PI = M_PI; |
| 50 |
const double TWO_PI = 2 * PI; |
| 51 |
|
| 52 |
void expect_eq_for_shared_or_owned_node(const stk::mesh::BulkData & bulk_data, stk::mesh::Entity node, |
| 53 |
const stk::mesh::Field<double> & theField, double expected_value) |
| 54 |
{ |
| 55 |
if (bulk_data.is_valid(node) && (bulk_data.bucket(node).owned() || bulk_data.bucket(node).shared() ) ) |
| 56 |
{ |
| 57 |
const double * const vol = stk::mesh::field_data(theField, node); |
| 58 |
EXPECT_EQ(*vol, expected_value); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
void do_periodic_assembly(stk::mesh::BulkData & bulk_data, PeriodicSearch & pbc_search, |
| 63 |
stk::mesh::Field<double> & volField) |
| 64 |
{ |
| 65 |
//gather to domain node from possibly multiple ranges |
| 66 |
for (size_t i = 0; i < pbc_search.size(); ++i) |
| 67 |
{ |
| 68 |
std::pair<stk::mesh::Entity, stk::mesh::Entity> entityPair = pbc_search.get_node_pair(i); |
| 69 |
STK_ThrowRequire(bulk_data.is_valid(entityPair.first)); |
| 70 |
STK_ThrowRequire(bulk_data.is_valid(entityPair.second)); |
| 71 |
double * domainField = stk::mesh::field_data(volField, entityPair.first); |
| 72 |
double * rangeField = stk::mesh::field_data(volField, entityPair.second); |
| 73 |
*domainField += *rangeField; |
| 74 |
} |
| 75 |
|
| 76 |
std::vector< stk::mesh::FieldBase const * > ghosted_fields; |
| 77 |
ghosted_fields.push_back(&volField); |
| 78 |
stk::mesh::communicate_field_data( pbc_search.get_ghosting(), ghosted_fields); |
| 79 |
|
| 80 |
//set ranges equal to domain value |
| 81 |
for (size_t i = 0; i < pbc_search.size(); ++i) |
| 82 |
{ |
| 83 |
std::pair<stk::mesh::Entity, stk::mesh::Entity> entityPair = pbc_search.get_node_pair(i); |
| 84 |
STK_ThrowRequire(bulk_data.is_valid(entityPair.first)); |
| 85 |
STK_ThrowRequire(bulk_data.is_valid(entityPair.second)); |
| 86 |
double * domainField = stk::mesh::field_data(volField, entityPair.first); |
| 87 |
double * rangeField = stk::mesh::field_data(volField, entityPair.second); |
| 88 |
*rangeField = *domainField; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
void do_volume_assembly(stk::mesh::BulkData & bulk_data, stk::mesh::Field<double> & volField) |
| 93 |
{ |
| 94 |
const stk::mesh::BucketVector & elemBuckets = bulk_data.buckets(stk::topology::ELEMENT_RANK); |
| 95 |
for (size_t elemBucket = 0; elemBucket < elemBuckets.size(); ++elemBucket) |
| 96 |
{ |
| 97 |
const stk::mesh::Bucket & bucket = *elemBuckets[elemBucket]; |
| 98 |
for (size_t i = 0; i < bucket.size(); ++i) |
| 99 |
{ |
| 100 |
stk::mesh::Entity elem = bucket[i]; |
| 101 |
|
| 102 |
const stk::mesh::Entity * aNode = bulk_data.begin_nodes(elem); |
| 103 |
const size_t numNodes = bulk_data.num_nodes(elem); |
| 104 |
for (size_t in = 0; in < numNodes; ++in) |
| 105 |
{ |
| 106 |
double * vol = stk::mesh::field_data(volField, aNode[in]); |
| 107 |
*vol += 0.125; |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
template<typename SearchPairVector> |
| 115 |
void check_gold( const SearchPairVector & search_results ) |
| 116 |
// check search result |
| 117 |
{ |
| 118 |
typedef std::vector<std::pair<stk::mesh::EntityId,stk::mesh::EntityId> > GoldVector; |
| 119 |
GoldVector gold; |
| 120 |
gold.push_back(std::make_pair(1,4)); |
| 121 |
gold.push_back(std::make_pair(5,8)); |
| 122 |
gold.push_back(std::make_pair(9,12)); |
| 123 |
gold.push_back(std::make_pair(13,16)); |
| 124 |
|
| 125 |
gold.push_back(std::make_pair(17,20)); |
| 126 |
gold.push_back(std::make_pair(21,24)); |
| 127 |
gold.push_back(std::make_pair(25,28)); |
| 128 |
gold.push_back(std::make_pair(29,32)); |
| 129 |
|
| 130 |
gold.push_back(std::make_pair(33,36)); |
| 131 |
gold.push_back(std::make_pair(37,40)); |
| 132 |
gold.push_back(std::make_pair(41,44)); |
| 133 |
gold.push_back(std::make_pair(45,48)); |
| 134 |
|
| 135 |
gold.push_back(std::make_pair(49,52)); |
| 136 |
gold.push_back(std::make_pair(53,56)); |
| 137 |
gold.push_back(std::make_pair(57,60)); |
| 138 |
gold.push_back(std::make_pair(61,64)); |
| 139 |
|
| 140 |
//make sure search result shows up in gold |
| 141 |
for (size_t i=0, size=search_results.size(); i<size; ++i) { |
| 142 |
stk::mesh::EntityId domain_node = search_results[i].first.id().id(); |
| 143 |
stk::mesh::EntityId range_node = search_results[i].second.id().id(); |
| 144 |
|
| 145 |
//entry in search is found in gold |
| 146 |
|
| 147 |
bool found = std::find(gold.begin(),gold.end(),std::make_pair(domain_node,range_node)) != gold.end(); |
| 148 |
EXPECT_TRUE(found) << "We can't find domain/range: " << search_results[i].first << "/" << search_results[i].second << std::endl; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
template<typename SearchPairVector> |
| 153 |
void check_gold_two_way_multiperiodic( const SearchPairVector & search_results ) |
| 154 |
// check search result |
| 155 |
{ |
| 156 |
typedef std::vector<std::pair<stk::mesh::EntityId,stk::mesh::EntityId> > GoldVector; |
| 157 |
GoldVector gold; |
| 158 |
gold.push_back(std::make_pair(1,4)); |
| 159 |
gold.push_back(std::make_pair(5,8)); |
| 160 |
gold.push_back(std::make_pair(9,12)); |
| 161 |
|
| 162 |
gold.push_back(std::make_pair(17,20)); |
| 163 |
gold.push_back(std::make_pair(21,24)); |
| 164 |
gold.push_back(std::make_pair(25,28)); |
| 165 |
|
| 166 |
gold.push_back(std::make_pair(33,36)); |
| 167 |
gold.push_back(std::make_pair(37,40)); |
| 168 |
gold.push_back(std::make_pair(41,44)); |
| 169 |
|
| 170 |
gold.push_back(std::make_pair(49,52)); |
| 171 |
gold.push_back(std::make_pair(53,56)); |
| 172 |
gold.push_back(std::make_pair(57,60)); |
| 173 |
|
| 174 |
//top and bottom |
| 175 |
gold.push_back(std::make_pair(1,13)); |
| 176 |
gold.push_back(std::make_pair(2,14)); |
| 177 |
gold.push_back(std::make_pair(3,15)); |
| 178 |
|
| 179 |
gold.push_back(std::make_pair(17,29)); |
| 180 |
gold.push_back(std::make_pair(18,30)); |
| 181 |
gold.push_back(std::make_pair(19,31)); |
| 182 |
|
| 183 |
gold.push_back(std::make_pair(33,45)); |
| 184 |
gold.push_back(std::make_pair(34,46)); |
| 185 |
gold.push_back(std::make_pair(35,47)); |
| 186 |
|
| 187 |
gold.push_back(std::make_pair(49,61)); |
| 188 |
gold.push_back(std::make_pair(50,62)); |
| 189 |
gold.push_back(std::make_pair(51,63)); |
| 190 |
|
| 191 |
//edge cases |
| 192 |
gold.push_back(std::make_pair(1,16)); |
| 193 |
gold.push_back(std::make_pair(17,32)); |
| 194 |
gold.push_back(std::make_pair(33,48)); |
| 195 |
gold.push_back(std::make_pair(49,64)); |
| 196 |
|
| 197 |
for (size_t i=0, size=search_results.size(); i<size; ++i) { |
| 198 |
stk::mesh::EntityId domain_node = search_results[i].first.id().id(); |
| 199 |
stk::mesh::EntityId range_node = search_results[i].second.id().id(); |
| 200 |
|
| 201 |
EXPECT_TRUE((std::find(gold.begin(), gold.end(), std::make_pair(domain_node,range_node) ) ) != gold.end()); |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
template<typename SearchPairVector> |
| 206 |
void check_gold_three_way_multiperiodic( const SearchPairVector & search_results ) |
| 207 |
// check search result |
| 208 |
{ |
| 209 |
typedef std::vector<std::pair<stk::mesh::EntityId,stk::mesh::EntityId> > GoldVector; |
| 210 |
GoldVector gold; |
| 211 |
gold.push_back(std::make_pair(1, 4)); |
| 212 |
gold.push_back(std::make_pair(5, 8)); |
| 213 |
gold.push_back(std::make_pair(9, 12)); |
| 214 |
gold.push_back(std::make_pair(17, 20)); |
| 215 |
gold.push_back(std::make_pair(21, 24)); |
| 216 |
gold.push_back(std::make_pair(25, 28)); |
| 217 |
gold.push_back(std::make_pair(33, 36)); |
| 218 |
gold.push_back(std::make_pair(37, 40)); |
| 219 |
gold.push_back(std::make_pair(41, 44)); |
| 220 |
gold.push_back(std::make_pair(1, 13)); |
| 221 |
gold.push_back(std::make_pair(2, 14)); |
| 222 |
gold.push_back(std::make_pair(3, 15)); |
| 223 |
gold.push_back(std::make_pair(17, 29)); |
| 224 |
gold.push_back(std::make_pair(18, 30)); |
| 225 |
gold.push_back(std::make_pair(19, 31)); |
| 226 |
gold.push_back(std::make_pair(33, 45)); |
| 227 |
gold.push_back(std::make_pair(34, 46)); |
| 228 |
gold.push_back(std::make_pair(35, 47)); |
| 229 |
gold.push_back(std::make_pair(1, 49)); |
| 230 |
gold.push_back(std::make_pair(2, 50)); |
| 231 |
gold.push_back(std::make_pair(3, 51)); |
| 232 |
gold.push_back(std::make_pair(5, 53)); |
| 233 |
gold.push_back(std::make_pair(6, 54)); |
| 234 |
gold.push_back(std::make_pair(7, 55)); |
| 235 |
gold.push_back(std::make_pair(9, 57)); |
| 236 |
gold.push_back(std::make_pair(10, 58)); |
| 237 |
gold.push_back(std::make_pair(11, 59)); |
| 238 |
gold.push_back(std::make_pair(1, 16)); |
| 239 |
gold.push_back(std::make_pair(17, 32)); |
| 240 |
gold.push_back(std::make_pair(33, 48)); |
| 241 |
gold.push_back(std::make_pair(1, 61)); |
| 242 |
gold.push_back(std::make_pair(2, 62)); |
| 243 |
gold.push_back(std::make_pair(3, 63)); |
| 244 |
gold.push_back(std::make_pair(1, 52)); |
| 245 |
gold.push_back(std::make_pair(5, 56)); |
| 246 |
gold.push_back(std::make_pair(9, 60)); |
| 247 |
gold.push_back(std::make_pair(1, 64)); |
| 248 |
|
| 249 |
for (size_t i=0, size=search_results.size(); i<size; ++i) { |
| 250 |
stk::mesh::EntityId domain_node = search_results[i].first.id().id(); |
| 251 |
stk::mesh::EntityId range_node = search_results[i].second.id().id(); |
| 252 |
|
| 253 |
EXPECT_TRUE((std::find(gold.begin(), gold.end(), std::make_pair(domain_node,range_node) ) ) != gold.end()); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
void check_single_periodic_assembly(const stk::mesh::BulkData & bulk_data, |
| 258 |
const stk::mesh::fixtures::HexFixture & fixture, |
| 259 |
const stk::mesh::Field<double> & volField, |
| 260 |
unsigned x, |
| 261 |
unsigned y, |
| 262 |
unsigned z) |
| 263 |
{ |
| 264 |
//interior of domain should be 1.0 |
| 265 |
for (unsigned i=0; i<x+1u; ++i) { |
| 266 |
for (unsigned j=1; j<y; ++j) { |
| 267 |
for (unsigned k=1; k<z; ++k) { |
| 268 |
stk::mesh::Entity node = fixture.node(i,j,k); |
| 269 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 1.0); |
| 270 |
} |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
//faces (not edges) should be 0.5 |
| 275 |
//edges should be 0.25 |
| 276 |
//there are no "corners" since it is periodic in the x direction |
| 277 |
for (unsigned i=0; i<x+1u; ++i) { |
| 278 |
//top and bottom |
| 279 |
for (unsigned k=1; k<z; ++k) { |
| 280 |
const unsigned jTop = 3; |
| 281 |
const unsigned jBot = 0; |
| 282 |
stk::mesh::Entity node = fixture.node(i,jTop,k); |
| 283 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.5); |
| 284 |
node = fixture.node(i,jBot,k); |
| 285 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.5); |
| 286 |
} |
| 287 |
//front and back |
| 288 |
for (unsigned j=1; j<y; ++j) { |
| 289 |
const unsigned kFront = 0; |
| 290 |
const unsigned kBack = 3; |
| 291 |
stk::mesh::Entity node = fixture.node(i,j,kFront); |
| 292 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.5); |
| 293 |
node = fixture.node(i,j,kBack); |
| 294 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.5); |
| 295 |
} |
| 296 |
//edges |
| 297 |
stk::mesh::Entity node = fixture.node(i, 0, 0); |
| 298 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.25); |
| 299 |
node = fixture.node(i, 0, 3); |
| 300 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.25); |
| 301 |
node = fixture.node(i, 3, 0); |
| 302 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.25); |
| 303 |
node = fixture.node(i, 3, 3); |
| 304 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.25); |
| 305 |
} |
| 306 |
|
| 307 |
} |
| 308 |
|
| 309 |
void check_rotation_matrix(const PeriodicSearch & pbc_search, double rotationAngle) |
| 310 |
{ |
| 311 |
//stored column major |
| 312 |
std::vector<double> matrix(9); |
| 313 |
pbc_search.get_search_row_major_rotation(matrix); |
| 314 |
const double tol = 1.0e-12; |
| 315 |
EXPECT_NEAR(matrix[0], std::cos(rotationAngle), tol); |
| 316 |
EXPECT_NEAR(matrix[1], -std::sin(rotationAngle), tol); |
| 317 |
EXPECT_NEAR(matrix[2], 0.0, tol); |
| 318 |
|
| 319 |
EXPECT_NEAR(matrix[3], std::sin(rotationAngle), tol); |
| 320 |
EXPECT_NEAR(matrix[4], std::cos(rotationAngle), tol); |
| 321 |
EXPECT_NEAR(matrix[5], 0.0, tol); |
| 322 |
|
| 323 |
EXPECT_NEAR(matrix[6], 0.0, tol); |
| 324 |
EXPECT_NEAR(matrix[7], 0.0, tol); |
| 325 |
EXPECT_NEAR(matrix[8], 1.0, tol); |
| 326 |
} |
| 327 |
|
| 328 |
class CylindricalCoordinateMappingWithOffset : public stk::mesh::fixtures::CoordinateMapping |
| 329 |
{ |
| 330 |
public: |
| 331 |
typedef double Scalar; |
| 332 |
CylindricalCoordinateMappingWithOffset(Scalar radius, Scalar theta, |
| 333 |
unsigned numTheta, Scalar offsetX, Scalar offsetY, Scalar offsetZ) |
| 334 |
: CoordinateMapping(), |
| 335 |
m_radius(radius), |
| 336 |
m_theta(theta), |
| 337 |
m_numTheta(numTheta), |
| 338 |
m_offsetX(offsetX), |
| 339 |
m_offsetY(offsetY), |
| 340 |
m_offsetZ(offsetZ) |
| 341 |
{ } |
| 342 |
virtual void getNodeCoordinates(Scalar * field, const size_t nx, const size_t ny, const size_t nz) const |
| 343 |
{ |
| 344 |
Scalar fracTheta = nx/(m_numTheta - 1); |
| 345 |
|
| 346 |
//we want the angle to go from pi/2 to pi/2 - theta so we do not |
| 347 |
//invert any elements |
| 348 |
Scalar angle = PI/2.0 + m_theta*fracTheta; |
| 349 |
field[0] = (m_radius + ny)*std::cos(angle) + m_offsetX; |
| 350 |
field[1] = (m_radius + ny)*std::sin(angle) + m_offsetY; |
| 351 |
field[2] = nz + m_offsetZ; |
| 352 |
} |
| 353 |
private: |
| 354 |
Scalar m_radius; |
| 355 |
Scalar m_theta; |
| 356 |
unsigned m_numTheta; |
| 357 |
Scalar m_offsetX; |
| 358 |
Scalar m_offsetY; |
| 359 |
Scalar m_offsetZ; |
| 360 |
|
| 361 |
|
| 362 |
}; |
| 363 |
|
| 364 |
}// namespace |
| 365 |
|
| 366 |
TEST(CoarseSearch, PeriodicBC) |
| 367 |
{ |
| 368 |
const unsigned x = 3, y = 3, z = 3; |
| 369 |
|
| 370 |
stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, x, y, z); |
| 371 |
|
| 372 |
stk::mesh::BulkData & bulk_data = fixture.m_bulk_data; |
| 373 |
stk::mesh::MetaData & meta_data = fixture.m_meta; |
| 374 |
CoordFieldType & coords_field = *fixture.m_coord_field; |
| 375 |
|
| 376 |
stk::mesh::Part & side_0 = meta_data.declare_part("side_0", stk::topology::NODE_RANK); |
| 377 |
stk::mesh::Part & side_3 = meta_data.declare_part("side_3", stk::topology::NODE_RANK); |
| 378 |
|
| 379 |
stk::mesh::Field<double> & volField = meta_data.declare_field<double>(stk::topology::NODE_RANK, "volume"); |
| 380 |
stk::mesh::put_field_on_mesh(volField, meta_data.universal_part(), nullptr); |
| 381 |
|
| 382 |
meta_data.commit(); |
| 383 |
|
| 384 |
fixture.generate_mesh(); |
| 385 |
|
| 386 |
stk::mesh::PartVector independent_parts(1,&side_0); |
| 387 |
stk::mesh::PartVector dependent_parts(1,&side_3); |
| 388 |
|
| 389 |
bulk_data.modification_begin(); |
| 390 |
for (unsigned i=0; i<y+1u; ++i) { |
| 391 |
for (unsigned j=0; j<z+1u; ++j) { |
| 392 |
stk::mesh::Entity node_0 = fixture.node(0,i,j); |
| 393 |
if (bulk_data.is_valid(node_0) && bulk_data.bucket(node_0).owned()) { |
| 394 |
bulk_data.change_entity_parts( fixture.node(0,i,j), independent_parts); |
| 395 |
} |
| 396 |
stk::mesh::Entity node_3 = fixture.node(3,i,j); |
| 397 |
if (bulk_data.is_valid(node_3) && bulk_data.bucket(node_3).owned()) { |
| 398 |
bulk_data.change_entity_parts( fixture.node(3,i,j), dependent_parts); |
| 399 |
} |
| 400 |
}} |
| 401 |
bulk_data.modification_end(); |
| 402 |
|
| 403 |
//do periodic search |
| 404 |
PeriodicSearch pbc_search(bulk_data, CoordinateFunctor(bulk_data, coords_field)); |
| 405 |
|
| 406 |
const stk::mesh::Selector side_0_selector = side_0 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 407 |
const stk::mesh::Selector side_3_selector = side_3 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 408 |
|
| 409 |
pbc_search.add_linear_periodic_pair(side_0_selector, side_3_selector); |
| 410 |
pbc_search.find_periodic_nodes(bulk_data.parallel()); |
| 411 |
|
| 412 |
|
| 413 |
check_gold(pbc_search.get_pairs() ); |
| 414 |
|
| 415 |
bulk_data.modification_begin(); |
| 416 |
pbc_search.create_ghosting("periodic_ghosts"); |
| 417 |
bulk_data.modification_end(); |
| 418 |
|
| 419 |
do_volume_assembly(bulk_data, volField); |
| 420 |
|
| 421 |
std::vector< stk::mesh::FieldBase const * > ghosted_fields; |
| 422 |
ghosted_fields.push_back(&volField); |
| 423 |
stk::mesh::communicate_field_data( pbc_search.get_ghosting(), ghosted_fields); |
| 424 |
|
| 425 |
do_periodic_assembly(bulk_data, pbc_search, volField); |
| 426 |
|
| 427 |
check_single_periodic_assembly(bulk_data, fixture, volField, x, y, z); |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
void assign_to_parts_for_two_way(const unsigned /*x*/, const unsigned y, const unsigned z, |
| 432 |
stk::mesh::fixtures::HexFixture &fixture, |
| 433 |
stk::mesh::BulkData &bulk_data, |
| 434 |
stk::mesh::PartVector &side_0_parts, |
| 435 |
stk::mesh::PartVector &side_1_parts, |
| 436 |
stk::mesh::PartVector &side_2_parts, |
| 437 |
stk::mesh::PartVector &side_3_parts) |
| 438 |
{ |
| 439 |
|
| 440 |
//add periodic pair for side 0 and side 2 |
| 441 |
bulk_data.modification_begin(); |
| 442 |
for (unsigned i=0; i<y+1u; ++i) { |
| 443 |
for (unsigned j=0; j<z+1u; ++j) { |
| 444 |
stk::mesh::Entity node_0 = fixture.node(0,i,j); |
| 445 |
if (bulk_data.is_valid(node_0) && bulk_data.bucket(node_0).owned()) { |
| 446 |
bulk_data.change_entity_parts( fixture.node(0,i,j), side_0_parts); |
| 447 |
} |
| 448 |
stk::mesh::Entity node_2 = fixture.node(3,i,j); |
| 449 |
if (bulk_data.is_valid(node_2) && bulk_data.bucket(node_2).owned()) { |
| 450 |
bulk_data.change_entity_parts( fixture.node(3,i,j), side_2_parts); |
| 451 |
} |
| 452 |
}} |
| 453 |
bulk_data.modification_end(); |
| 454 |
|
| 455 |
//add periodic pair for side 1 and side 3 |
| 456 |
bulk_data.modification_begin(); |
| 457 |
for (unsigned i=0; i<y+1u; ++i) { |
| 458 |
for (unsigned j=0; j<z+1u; ++j) { |
| 459 |
stk::mesh::Entity node_1 = fixture.node(i,0,j); |
| 460 |
if (bulk_data.is_valid(node_1) && bulk_data.bucket(node_1).owned()) { |
| 461 |
bulk_data.change_entity_parts( fixture.node(i,0,j), side_1_parts); |
| 462 |
} |
| 463 |
stk::mesh::Entity node_3 = fixture.node(i,3,j); |
| 464 |
if (bulk_data.is_valid(node_3) && bulk_data.bucket(node_3).owned()) { |
| 465 |
bulk_data.change_entity_parts( fixture.node(i,3,j), side_3_parts); |
| 466 |
} |
| 467 |
}} |
| 468 |
bulk_data.modification_end(); |
| 469 |
} |
| 470 |
|
| 471 |
TEST(CoarseSearch, TwoWayMultiPeriodicBC) |
| 472 |
{ |
| 473 |
const unsigned x = 3, y = 3, z = 3; |
| 474 |
|
| 475 |
|
| 476 |
stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, x, y, z); |
| 477 |
|
| 478 |
stk::mesh::BulkData & bulk_data = fixture.m_bulk_data; |
| 479 |
stk::mesh::MetaData & meta_data = fixture.m_meta; |
| 480 |
CoordFieldType & coords_field = *fixture.m_coord_field; |
| 481 |
|
| 482 |
stk::mesh::Part & side_0 = meta_data.declare_part("side_0", stk::topology::NODE_RANK); |
| 483 |
stk::mesh::Part & side_2 = meta_data.declare_part("side_2", stk::topology::NODE_RANK); |
| 484 |
|
| 485 |
stk::mesh::Part & side_1 = meta_data.declare_part("side_1", stk::topology::NODE_RANK); |
| 486 |
stk::mesh::Part & side_3 = meta_data.declare_part("side_3", stk::topology::NODE_RANK); |
| 487 |
|
| 488 |
stk::mesh::Field<double> & volField = meta_data.declare_field<double>(stk::topology::NODE_RANK, "volume"); |
| 489 |
stk::mesh::put_field_on_mesh(volField, meta_data.universal_part(), nullptr); |
| 490 |
|
| 491 |
meta_data.commit(); |
| 492 |
|
| 493 |
fixture.generate_mesh(); |
| 494 |
|
| 495 |
stk::mesh::PartVector side_0_parts(1,&side_0); |
| 496 |
stk::mesh::PartVector side_2_parts(1,&side_2); |
| 497 |
|
| 498 |
stk::mesh::PartVector side_1_parts(1,&side_1); |
| 499 |
stk::mesh::PartVector side_3_parts(1,&side_3); |
| 500 |
|
| 501 |
assign_to_parts_for_two_way(x, y, z, fixture, bulk_data, |
| 502 |
side_0_parts, side_1_parts, side_2_parts, side_3_parts); |
| 503 |
|
| 504 |
//do periodic search |
| 505 |
PeriodicSearch pbc_search(bulk_data, CoordinateFunctor(bulk_data, coords_field)); |
| 506 |
|
| 507 |
const stk::mesh::Selector side_0_selector = side_0 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 508 |
const stk::mesh::Selector side_1_selector = side_1 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 509 |
const stk::mesh::Selector side_2_selector = side_2 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 510 |
const stk::mesh::Selector side_3_selector = side_3 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 511 |
|
| 512 |
pbc_search.add_linear_periodic_pair(side_0_selector, side_2_selector ); |
| 513 |
pbc_search.add_linear_periodic_pair(side_1_selector, side_3_selector ); |
| 514 |
pbc_search.find_periodic_nodes(bulk_data.parallel()); |
| 515 |
|
| 516 |
//check to see if re-entrant |
| 517 |
pbc_search.find_periodic_nodes(bulk_data.parallel()); |
| 518 |
|
| 519 |
check_gold_two_way_multiperiodic(pbc_search.get_pairs()); |
| 520 |
|
| 521 |
//now we ghost everything to do a local search |
| 522 |
bulk_data.modification_begin(); |
| 523 |
pbc_search.create_ghosting("periodic_ghosts"); |
| 524 |
bulk_data.modification_end(); |
| 525 |
|
| 526 |
do_volume_assembly(bulk_data, volField); |
| 527 |
|
| 528 |
std::vector< stk::mesh::FieldBase const * > ghosted_fields; |
| 529 |
ghosted_fields.push_back(&volField); |
| 530 |
stk::mesh::communicate_field_data( pbc_search.get_ghosting(), ghosted_fields); |
| 531 |
|
| 532 |
do_periodic_assembly(bulk_data, pbc_search, volField); |
| 533 |
|
| 534 |
//interior of domain should be 1.0 |
| 535 |
for (unsigned i=0; i<x+1u; ++i) { |
| 536 |
for (unsigned j=0; j<y+1u; ++j) { |
| 537 |
for (unsigned k=1; k<z; ++k) { |
| 538 |
stk::mesh::Entity node = fixture.node(i,j,k); |
| 539 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 1.0); |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
//faces (not edges) should be 0.5 |
| 544 |
//there are no corners or edges since this is two way periodic |
| 545 |
for (unsigned i=0; i<x+1u; ++i) { |
| 546 |
//front and back |
| 547 |
for (unsigned j=0; j<y+1u; ++j) { |
| 548 |
const unsigned kFront = 0; |
| 549 |
const unsigned kBack = 3; |
| 550 |
stk::mesh::Entity node = fixture.node(i,j,kFront); |
| 551 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.5); |
| 552 |
node = fixture.node(i,j,kBack); |
| 553 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 0.5); |
| 554 |
} |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
void assign_to_parts_for_three_way(const unsigned x, const unsigned y, const unsigned z, |
| 559 |
stk::mesh::fixtures::HexFixture &fixture, |
| 560 |
stk::mesh::BulkData &bulk_data, |
| 561 |
stk::mesh::PartVector &side_0_parts, |
| 562 |
stk::mesh::PartVector &side_1_parts, |
| 563 |
stk::mesh::PartVector &side_2_parts, |
| 564 |
stk::mesh::PartVector &side_3_parts, |
| 565 |
stk::mesh::PartVector &side_4_parts, |
| 566 |
stk::mesh::PartVector &side_5_parts) |
| 567 |
{ |
| 568 |
assign_to_parts_for_two_way(x, y, z, fixture, bulk_data, |
| 569 |
side_0_parts, side_1_parts, side_2_parts, side_3_parts); |
| 570 |
|
| 571 |
//add periodic pair for side 4 and side 5 |
| 572 |
bulk_data.modification_begin(); |
| 573 |
for (unsigned i=0; i<y+1u; ++i) { |
| 574 |
for (unsigned j=0; j<z+1u; ++j) { |
| 575 |
stk::mesh::Entity node_4 = fixture.node(i,j,0); |
| 576 |
if (bulk_data.is_valid(node_4) && bulk_data.bucket(node_4).owned()) { |
| 577 |
bulk_data.change_entity_parts( fixture.node(i,j,0), side_4_parts); |
| 578 |
} |
| 579 |
stk::mesh::Entity node_5 = fixture.node(i,j,3); |
| 580 |
if (bulk_data.is_valid(node_5) && bulk_data.bucket(node_5).owned()) { |
| 581 |
bulk_data.change_entity_parts( fixture.node(i,j,3), side_5_parts); |
| 582 |
} |
| 583 |
}} |
| 584 |
bulk_data.modification_end(); |
| 585 |
} |
| 586 |
|
| 587 |
TEST(CoarseSearch, ThreeWayMultiPeriodicBC) |
| 588 |
{ |
| 589 |
const unsigned x = 3, y = 3, z = 3; |
| 590 |
|
| 591 |
stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, x, y, z); |
| 592 |
|
| 593 |
stk::mesh::BulkData & bulk_data = fixture.m_bulk_data; |
| 594 |
stk::mesh::MetaData & meta_data = fixture.m_meta; |
| 595 |
CoordFieldType & coords_field = *fixture.m_coord_field; |
| 596 |
|
| 597 |
stk::mesh::Part & side_0 = meta_data.declare_part("side_0", stk::topology::NODE_RANK); |
| 598 |
stk::mesh::Part & side_2 = meta_data.declare_part("side_2", stk::topology::NODE_RANK); |
| 599 |
|
| 600 |
stk::mesh::Part & side_1 = meta_data.declare_part("side_1", stk::topology::NODE_RANK); |
| 601 |
stk::mesh::Part & side_3 = meta_data.declare_part("side_3", stk::topology::NODE_RANK); |
| 602 |
|
| 603 |
stk::mesh::Part & side_4 = meta_data.declare_part("side_4", stk::topology::NODE_RANK); |
| 604 |
stk::mesh::Part & side_5 = meta_data.declare_part("side_5", stk::topology::NODE_RANK); |
| 605 |
|
| 606 |
stk::mesh::Field<double> & volField = meta_data.declare_field<double>(stk::topology::NODE_RANK, "volume"); |
| 607 |
stk::mesh::put_field_on_mesh(volField, meta_data.universal_part(), nullptr); |
| 608 |
|
| 609 |
meta_data.commit(); |
| 610 |
|
| 611 |
fixture.generate_mesh(); |
| 612 |
|
| 613 |
stk::mesh::PartVector side_0_parts(1, &side_0); |
| 614 |
stk::mesh::PartVector side_2_parts(1, &side_2); |
| 615 |
|
| 616 |
stk::mesh::PartVector side_1_parts(1, &side_1); |
| 617 |
stk::mesh::PartVector side_3_parts(1, &side_3); |
| 618 |
|
| 619 |
stk::mesh::PartVector side_4_parts(1, &side_4); |
| 620 |
stk::mesh::PartVector side_5_parts(1, &side_5); |
| 621 |
|
| 622 |
assign_to_parts_for_three_way(x, y, z, fixture, bulk_data, |
| 623 |
side_0_parts, side_1_parts, |
| 624 |
side_2_parts, side_3_parts, |
| 625 |
side_4_parts, side_5_parts); |
| 626 |
|
| 627 |
//do periodic search |
| 628 |
PeriodicSearch pbc_search(bulk_data, CoordinateFunctor(bulk_data, coords_field)); |
| 629 |
|
| 630 |
const stk::mesh::Selector side_0_selector = side_0 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 631 |
const stk::mesh::Selector side_1_selector = side_1 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 632 |
const stk::mesh::Selector side_2_selector = side_2 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 633 |
const stk::mesh::Selector side_3_selector = side_3 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 634 |
const stk::mesh::Selector side_4_selector = side_4 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 635 |
const stk::mesh::Selector side_5_selector = side_5 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 636 |
|
| 637 |
pbc_search.add_linear_periodic_pair(side_0_selector, side_2_selector); |
| 638 |
pbc_search.add_linear_periodic_pair(side_1_selector, side_3_selector); |
| 639 |
pbc_search.add_linear_periodic_pair(side_4_selector, side_5_selector); |
| 640 |
pbc_search.find_periodic_nodes(bulk_data.parallel()); |
| 641 |
|
| 642 |
check_gold_three_way_multiperiodic(pbc_search.get_pairs()); |
| 643 |
|
| 644 |
//now we ghost everything to do a local search |
| 645 |
bulk_data.modification_begin(); |
| 646 |
pbc_search.create_ghosting("periodic_ghosts"); |
| 647 |
bulk_data.modification_end(); |
| 648 |
|
| 649 |
do_volume_assembly(bulk_data, volField); |
| 650 |
|
| 651 |
std::vector< stk::mesh::FieldBase const * > ghosted_fields; |
| 652 |
ghosted_fields.push_back(&volField); |
| 653 |
stk::mesh::communicate_field_data( pbc_search.get_ghosting(), ghosted_fields); |
| 654 |
|
| 655 |
do_periodic_assembly(bulk_data, pbc_search, volField); |
| 656 |
|
| 657 |
//interior of domain should be 1.0 |
| 658 |
for (unsigned i=0; i<x+1u; ++i) { |
| 659 |
for (unsigned j=0; j<y+1u; ++j) { |
| 660 |
for (unsigned k=0; k<z+1u; ++k) { |
| 661 |
stk::mesh::Entity node = fixture.node(i,j,k); |
| 662 |
expect_eq_for_shared_or_owned_node(bulk_data, node, volField, 1.0); |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
TEST(CoarseSearch, MultiPeriodicBCDisallowRotational) |
| 671 |
{ |
| 672 |
const unsigned x = 3, y = 3, z = 3; |
| 673 |
|
| 674 |
stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, x, y, z); |
| 675 |
|
| 676 |
stk::mesh::BulkData & bulk_data = fixture.m_bulk_data; |
| 677 |
stk::mesh::MetaData & meta_data = fixture.m_meta; |
| 678 |
CoordFieldType & coords_field = *fixture.m_coord_field; |
| 679 |
|
| 680 |
stk::mesh::Part & side_0 = meta_data.declare_part("side_0", stk::topology::NODE_RANK); |
| 681 |
stk::mesh::Part & side_2 = meta_data.declare_part("side_2", stk::topology::NODE_RANK); |
| 682 |
|
| 683 |
stk::mesh::Part & side_1 = meta_data.declare_part("side_1", stk::topology::NODE_RANK); |
| 684 |
stk::mesh::Part & side_3 = meta_data.declare_part("side_3", stk::topology::NODE_RANK); |
| 685 |
|
| 686 |
stk::mesh::Part & side_4 = meta_data.declare_part("side_4", stk::topology::NODE_RANK); |
| 687 |
stk::mesh::Part & side_5 = meta_data.declare_part("side_5", stk::topology::NODE_RANK); |
| 688 |
|
| 689 |
meta_data.commit(); |
| 690 |
|
| 691 |
fixture.generate_mesh(); |
| 692 |
|
| 693 |
stk::mesh::PartVector side_0_parts(1, &side_0); |
| 694 |
stk::mesh::PartVector side_2_parts(1, &side_2); |
| 695 |
|
| 696 |
stk::mesh::PartVector side_1_parts(1, &side_1); |
| 697 |
stk::mesh::PartVector side_3_parts(1, &side_3); |
| 698 |
|
| 699 |
stk::mesh::PartVector side_4_parts(1, &side_4); |
| 700 |
stk::mesh::PartVector side_5_parts(1, &side_5); |
| 701 |
|
| 702 |
// Any assignment is okay, since we don't care about the search results. |
| 703 |
assign_to_parts_for_three_way(x, y, z, fixture, bulk_data, |
| 704 |
side_0_parts, side_1_parts, |
| 705 |
side_2_parts, side_3_parts, |
| 706 |
side_4_parts, side_5_parts); |
| 707 |
|
| 708 |
const double rotationAngle = TWO_PI/4.0; |
| 709 |
const double rotationAxis[3] = {0.0, 0.0, 1.0}; |
| 710 |
const double axisLocation[3] = {0.0, 0.0, 0.0}; |
| 711 |
|
| 712 |
PeriodicSearch pbc_search_caseA(bulk_data, CoordinateFunctor(bulk_data, coords_field)); |
| 713 |
pbc_search_caseA.add_rotational_periodic_pair(side_0 & meta_data.locally_owned_part(), |
| 714 |
side_2 & meta_data.locally_owned_part(), |
| 715 |
rotationAngle, rotationAxis, axisLocation); |
| 716 |
|
| 717 |
EXPECT_THROW( pbc_search_caseA.add_rotational_periodic_pair(side_1 & meta_data.locally_owned_part(), |
| 718 |
side_3 & meta_data.locally_owned_part(), |
| 719 |
rotationAngle, rotationAxis, axisLocation), |
| 720 |
std::exception); |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
TEST(CoarseSearch, RotationalPeriodicBC) |
| 725 |
{ |
| 726 |
const unsigned x = 3, y = 3, z = 3; |
| 727 |
|
| 728 |
stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, x, y, z); |
| 729 |
|
| 730 |
stk::mesh::BulkData & bulk_data = fixture.m_bulk_data; |
| 731 |
stk::mesh::MetaData & meta_data = fixture.m_meta; |
| 732 |
CoordFieldType & coords_field = *fixture.m_coord_field; |
| 733 |
|
| 734 |
stk::mesh::Part & side_0 = meta_data.declare_part("side_0", stk::topology::NODE_RANK); |
| 735 |
stk::mesh::Part & side_3 = meta_data.declare_part("side_3", stk::topology::NODE_RANK); |
| 736 |
|
| 737 |
stk::mesh::Field<double> & volField = meta_data.declare_field<double>(stk::topology::NODE_RANK, "volume"); |
| 738 |
stk::mesh::put_field_on_mesh(volField, meta_data.universal_part(), nullptr); |
| 739 |
|
| 740 |
meta_data.commit(); |
| 741 |
|
| 742 |
const double rotationAngle = -TWO_PI/4.0; |
| 743 |
const double rotationAxis[3] = {0.0, 0.0, 1.0}; |
| 744 |
const double axisLocation[3] = {0.0, 0.0, 0.0}; |
| 745 |
stk::mesh::fixtures::CylindricalCoordinateMapping coordMap(1.0, rotationAngle, 4); |
| 746 |
fixture.generate_mesh(coordMap); |
| 747 |
|
| 748 |
stk::mesh::PartVector independent_parts(1,&side_0); |
| 749 |
stk::mesh::PartVector dependent_parts(1,&side_3); |
| 750 |
|
| 751 |
bulk_data.modification_begin(); |
| 752 |
for (unsigned i=0; i<y+1u; ++i) { |
| 753 |
for (unsigned j=0; j<z+1u; ++j) { |
| 754 |
stk::mesh::Entity node_0 = fixture.node(0,i,j); |
| 755 |
if (bulk_data.is_valid(node_0) && bulk_data.bucket(node_0).owned()) { |
| 756 |
bulk_data.change_entity_parts( fixture.node(0,i,j), independent_parts); |
| 757 |
} |
| 758 |
stk::mesh::Entity node_3 = fixture.node(3,i,j); |
| 759 |
if (bulk_data.is_valid(node_3) && bulk_data.bucket(node_3).owned()) { |
| 760 |
bulk_data.change_entity_parts( fixture.node(3,i,j), dependent_parts); |
| 761 |
} |
| 762 |
}} |
| 763 |
bulk_data.modification_end(); |
| 764 |
|
| 765 |
//do periodic search |
| 766 |
PeriodicSearch pbc_search(bulk_data, CoordinateFunctor(bulk_data, coords_field)); |
| 767 |
|
| 768 |
const stk::mesh::Selector side_0_selector = side_0 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 769 |
const stk::mesh::Selector side_3_selector = side_3 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 770 |
|
| 771 |
|
| 772 |
pbc_search.add_rotational_periodic_pair(side_0_selector, |
| 773 |
side_3_selector, |
| 774 |
rotationAngle, |
| 775 |
rotationAxis, |
| 776 |
axisLocation); |
| 777 |
|
| 778 |
pbc_search.find_periodic_nodes(bulk_data.parallel()); |
| 779 |
|
| 780 |
|
| 781 |
check_gold(pbc_search.get_pairs() ); |
| 782 |
|
| 783 |
bulk_data.modification_begin(); |
| 784 |
pbc_search.create_ghosting("periodic_ghosts"); |
| 785 |
bulk_data.modification_end(); |
| 786 |
|
| 787 |
do_volume_assembly(bulk_data, volField); |
| 788 |
|
| 789 |
std::vector< stk::mesh::FieldBase const * > ghosted_fields; |
| 790 |
ghosted_fields.push_back(&volField); |
| 791 |
stk::mesh::communicate_field_data( pbc_search.get_ghosting(), ghosted_fields); |
| 792 |
|
| 793 |
do_periodic_assembly(bulk_data, pbc_search, volField); |
| 794 |
|
| 795 |
check_single_periodic_assembly(bulk_data, fixture, volField, x, y, z); |
| 796 |
|
| 797 |
check_rotation_matrix(pbc_search, rotationAngle); |
| 798 |
} |
| 799 |
|
| 800 |
TEST(CoarseSearch, OffsetRotationalPeriodicBC) |
| 801 |
{ |
| 802 |
const unsigned x = 3, y = 3, z = 3; |
| 803 |
|
| 804 |
stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, x, y, z); |
| 805 |
|
| 806 |
stk::mesh::BulkData & bulk_data = fixture.m_bulk_data; |
| 807 |
stk::mesh::MetaData & meta_data = fixture.m_meta; |
| 808 |
CoordFieldType & coords_field = *fixture.m_coord_field; |
| 809 |
|
| 810 |
stk::mesh::Part & side_0 = meta_data.declare_part("side_0", stk::topology::NODE_RANK); |
| 811 |
stk::mesh::Part & side_3 = meta_data.declare_part("side_3", stk::topology::NODE_RANK); |
| 812 |
|
| 813 |
stk::mesh::Field<double> & volField = meta_data.declare_field<double>(stk::topology::NODE_RANK, "volume"); |
| 814 |
stk::mesh::put_field_on_mesh(volField, meta_data.universal_part(), nullptr); |
| 815 |
|
| 816 |
meta_data.commit(); |
| 817 |
|
| 818 |
const double rotationAngle = -TWO_PI/4.0; |
| 819 |
const double rotationAxis[3] = {0.0, 0.0, 1.0}; |
| 820 |
const double axisLocation[3] = {1.0, 0.0, 0.0}; |
| 821 |
CylindricalCoordinateMappingWithOffset coordMap(1.0, rotationAngle, 4, 1.0, 0.0, 0.0); |
| 822 |
fixture.generate_mesh(coordMap); |
| 823 |
|
| 824 |
stk::mesh::PartVector independent_parts(1,&side_0); |
| 825 |
stk::mesh::PartVector dependent_parts(1,&side_3); |
| 826 |
|
| 827 |
bulk_data.modification_begin(); |
| 828 |
for (unsigned i=0; i<y+1u; ++i) { |
| 829 |
for (unsigned j=0; j<z+1u; ++j) { |
| 830 |
stk::mesh::Entity node_0 = fixture.node(0,i,j); |
| 831 |
if (bulk_data.is_valid(node_0) && bulk_data.bucket(node_0).owned()) { |
| 832 |
bulk_data.change_entity_parts( fixture.node(0,i,j), independent_parts); |
| 833 |
} |
| 834 |
stk::mesh::Entity node_3 = fixture.node(3,i,j); |
| 835 |
if (bulk_data.is_valid(node_3) && bulk_data.bucket(node_3).owned()) { |
| 836 |
bulk_data.change_entity_parts( fixture.node(3,i,j), dependent_parts); |
| 837 |
} |
| 838 |
}} |
| 839 |
bulk_data.modification_end(); |
| 840 |
|
| 841 |
//do periodic search |
| 842 |
PeriodicSearch pbc_search(bulk_data, CoordinateFunctor(bulk_data, coords_field)); |
| 843 |
|
| 844 |
const stk::mesh::Selector side_0_selector = side_0 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 845 |
const stk::mesh::Selector side_3_selector = side_3 & (meta_data.locally_owned_part() | meta_data.globally_shared_part()); |
| 846 |
|
| 847 |
|
| 848 |
pbc_search.add_rotational_periodic_pair(side_0_selector, |
| 849 |
side_3_selector, |
| 850 |
rotationAngle, |
| 851 |
|
| 852 |
|
| 853 |
rotationAxis, |
| 854 |
axisLocation); |
| 855 |
|
| 856 |
pbc_search.find_periodic_nodes(bulk_data.parallel()); |
| 857 |
|
| 858 |
|
| 859 |
check_gold(pbc_search.get_pairs() ); |
| 860 |
|
| 861 |
bulk_data.modification_begin(); |
| 862 |
pbc_search.create_ghosting("periodic_ghosts"); |
| 863 |
bulk_data.modification_end(); |
| 864 |
|
| 865 |
do_volume_assembly(bulk_data, volField); |
| 866 |
|
| 867 |
std::vector< stk::mesh::FieldBase const * > ghosted_fields; |
| 868 |
ghosted_fields.push_back(&volField); |
| 869 |
stk::mesh::communicate_field_data( pbc_search.get_ghosting(), ghosted_fields); |
| 870 |
|
| 871 |
do_periodic_assembly(bulk_data, pbc_search, volField); |
| 872 |
|
| 873 |
check_single_periodic_assembly(bulk_data, fixture, volField, x, y, z); |
| 874 |
|
| 875 |
check_rotation_matrix(pbc_search, rotationAngle); |
| 876 |
} |
| 877 |
|
| 878 |
TEST(PeriodicBoundarySearch, testRotationMatrixForRotationAboutZ) |
| 879 |
{ |
| 880 |
double angleInRadians = PI/2; |
| 881 |
double axis[3] = { 0, 0, 1 }; |
| 882 |
|
| 883 |
stk::mesh::matrix3x3 matrix1; |
| 884 |
stk::mesh::fillRotationMatrix(angleInRadians, axis[0], axis[1], axis[2], matrix1); |
| 885 |
|
| 886 |
stk::mesh::matrix3x3 goldMatrix; |
| 887 |
|
| 888 |
goldMatrix.setData(0, 0); |
| 889 |
goldMatrix.setData(1, -1); |
| 890 |
goldMatrix.setData(2, 0); |
| 891 |
|
| 892 |
goldMatrix.setData(3, 1); |
| 893 |
goldMatrix.setData(4, 0); |
| 894 |
goldMatrix.setData(5, 0); |
| 895 |
|
| 896 |
goldMatrix.setData(6, 0); |
| 897 |
goldMatrix.setData(7, 0); |
| 898 |
goldMatrix.setData(8, 1); |
| 899 |
|
| 900 |
EXPECT_EQ(goldMatrix.getData(0), 0); |
| 901 |
EXPECT_EQ(goldMatrix.getData(1), -1); |
| 902 |
EXPECT_EQ(goldMatrix.getData(2), 0); |
| 903 |
EXPECT_EQ(goldMatrix.getData(3), 1); |
| 904 |
EXPECT_EQ(goldMatrix.getData(4), 0); |
| 905 |
EXPECT_EQ(goldMatrix.getData(5), 0); |
| 906 |
EXPECT_EQ(goldMatrix.getData(6), 0); |
| 907 |
EXPECT_EQ(goldMatrix.getData(7), 0); |
| 908 |
EXPECT_EQ(goldMatrix.getData(8), 1); |
| 909 |
|
| 910 |
EXPECT_EQ(goldMatrix.getData(0,0), 0); |
| 911 |
EXPECT_EQ(goldMatrix.getData(0,1), -1); |
| 912 |
EXPECT_EQ(goldMatrix.getData(0,2), 0); |
| 913 |
EXPECT_EQ(goldMatrix.getData(1,0), 1); |
| 914 |
EXPECT_EQ(goldMatrix.getData(1,1), 0); |
| 915 |
EXPECT_EQ(goldMatrix.getData(1,2), 0); |
| 916 |
EXPECT_EQ(goldMatrix.getData(2,0), 0); |
| 917 |
EXPECT_EQ(goldMatrix.getData(2,1), 0); |
| 918 |
EXPECT_EQ(goldMatrix.getData(2,2), 1); |
| 919 |
|
| 920 |
double tol = 1e-6; |
| 921 |
|
| 922 |
EXPECT_EQ(9, goldMatrix.numEntries()); |
| 923 |
|
| 924 |
for (int i=0;i<goldMatrix.numEntries();i++) |
| 925 |
{ |
| 926 |
EXPECT_NEAR(goldMatrix.getData(i), matrix1.getData(i), tol) << " for index = " << i; |
| 927 |
} |
| 928 |
|
| 929 |
for (int row=0;row<3;row++) |
| 930 |
{ |
| 931 |
for (int col=0;col<3;col++) |
| 932 |
{ |
| 933 |
EXPECT_NEAR(goldMatrix.getData(row,col), matrix1.getData(row,col), tol) << " for (row,col) = (" << row << "," << col << ")"; |
| 934 |
} |
| 935 |
} |
| 936 |
|
| 937 |
double coordinate[3] = { 1, 0, 0 }; |
| 938 |
double result[3] = { 0, 0, 0 }; |
| 939 |
double goldResult[3] = { 0, 1, 0 }; |
| 940 |
|
| 941 |
matrix1.transformVec(coordinate, result); |
| 942 |
|
| 943 |
for (int i=0;i<3;i++) |
| 944 |
{ |
| 945 |
EXPECT_NEAR(goldResult[i], result[i], tol) << " for index = " << i; |
| 946 |
} |
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
TEST(PeriodicBoundarySearch, testRotationMatrixForRotationAboutY) |
| 951 |
{ |
| 952 |
double angleInRadians = PI/6; |
| 953 |
double axis[3] = { 0, 1, 0 }; |
| 954 |
|
| 955 |
stk::mesh::matrix3x3 matrix1; |
| 956 |
stk::mesh::fillRotationMatrix(angleInRadians, axis[0], axis[1], axis[2], matrix1); |
| 957 |
|
| 958 |
stk::mesh::matrix3x3 goldMatrix; |
| 959 |
|
| 960 |
|
| 961 |
goldMatrix.setData(0, cos(angleInRadians)); |
| 962 |
goldMatrix.setData(1, 0); |
| 963 |
goldMatrix.setData(2, sin(angleInRadians)); |
| 964 |
|
| 965 |
goldMatrix.setData(3, 0); |
| 966 |
goldMatrix.setData(4, 1); |
| 967 |
goldMatrix.setData(5, 0); |
| 968 |
|
| 969 |
goldMatrix.setData(6, -sin(angleInRadians)); |
| 970 |
goldMatrix.setData(7, 0); |
| 971 |
goldMatrix.setData(8, cos(angleInRadians)); |
| 972 |
|
| 973 |
double tol = 1e-6; |
| 974 |
|
| 975 |
EXPECT_EQ(9, goldMatrix.numEntries()); |
| 976 |
|
| 977 |
for (int i=0;i<goldMatrix.numEntries();i++) |
| 978 |
{ |
| 979 |
EXPECT_NEAR(goldMatrix.getData(i), matrix1.getData(i), tol) << " for index = " << i; |
| 980 |
} |
| 981 |
} |
| 982 |
|
| 983 |
TEST(PeriodicBoundarySearch, testRotationMatrixForRotationAboutX) |
| 984 |
{ |
| 985 |
double angleInRadians = PI/3; |
| 986 |
|
| 987 |
double axis[3] = { 2, 0, 0 }; |
| 988 |
|
| 989 |
stk::mesh::matrix3x3 matrix1; |
| 990 |
stk::mesh::fillRotationMatrix(angleInRadians, axis[0], axis[1], axis[2], matrix1); |
| 991 |
|
| 992 |
stk::mesh::matrix3x3 goldMatrix; |
| 993 |
|
| 994 |
|
| 995 |
goldMatrix.setData(0, 1); |
| 996 |
goldMatrix.setData(1, 0); |
| 997 |
goldMatrix.setData(2, 0); |
| 998 |
|
| 999 |
goldMatrix.setData(3, 0); |
| 1000 |
goldMatrix.setData(4, cos(angleInRadians)); |
| 1001 |
goldMatrix.setData(5, -sin(angleInRadians)); |
| 1002 |
|
| 1003 |
goldMatrix.setData(6, 0); |
| 1004 |
goldMatrix.setData(7, sin(angleInRadians)); |
| 1005 |
goldMatrix.setData(8, cos(angleInRadians)); |
| 1006 |
|
| 1007 |
double tol = 1e-6; |
| 1008 |
|
| 1009 |
EXPECT_EQ(9, goldMatrix.numEntries()); |
| 1010 |
|
| 1011 |
for (int i=0;i<goldMatrix.numEntries();i++) |
| 1012 |
{ |
| 1013 |
EXPECT_NEAR(goldMatrix.getData(i), matrix1.getData(i), tol) << " for index = " << i; |
| 1014 |
} |
| 1015 |
} |
| 1016 |
|
| 1017 |
|