| 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_util/stk_config.h> |
| 36 |
#if defined ( STK_HAS_MPI ) |
| 37 |
#include "mpi.h" // for MPI_COMM_WORLD, etc |
| 38 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 39 |
#include "stk_mesh/base/CreateEdges.hpp" // for create_edges |
| 40 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 41 |
#include "stk_mesh/base/Field.hpp" // for Field |
| 42 |
#include "stk_mesh/base/FieldBase.hpp" // for field_data, etc |
| 43 |
#include "stk_mesh/base/Selector.hpp" // for Selector |
| 44 |
#include "stk_mesh/base/Types.hpp" // for BucketVector, EntityId, 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_util/util/ReportHandler.hpp" // for ThrowRequire |
| 48 |
#include "gtest/gtest.h" // for EXPECT_EQ |
| 49 |
#include <algorithm> // for max, min |
| 50 |
#include <gtest/gtest.h> |
| 51 |
#include <iostream> // for basic_ostream::operator<< |
| 52 |
#include <stddef.h> // for size_t |
| 53 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 54 |
#include <stk_mesh/base/FieldParallel.hpp> // for parallel_max, etc |
| 55 |
#include <stk_mesh/base/GetEntities.hpp> // for count_entities |
| 56 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData, put_field |
| 57 |
#include <stk_util/parallel/Parallel.hpp> // for parallel_machine_rank, etc |
| 58 |
#include <vector> // for vector |
| 59 |
namespace stk { namespace mesh { class Part; } } |
| 60 |
|
| 61 |
namespace stk { namespace mesh { class FieldBase; } } |
| 62 |
|
| 63 |
namespace { |
| 64 |
|
| 65 |
using namespace stk::mesh; |
| 66 |
using stk::mesh::fixtures::HexFixture; |
| 67 |
|
| 68 |
template <typename T> |
| 69 |
T do_operation(Operation Op, T lhs, T rhs) |
| 70 |
{ |
| 71 |
switch(Op) { |
| 72 |
case Operation::SUM: |
| 73 |
return lhs + rhs; |
| 74 |
case Operation::MIN: |
| 75 |
return std::min(lhs, rhs); |
| 76 |
case Operation::MAX: |
| 77 |
return std::max(lhs, rhs); |
| 78 |
default: |
| 79 |
STK_ThrowRequire(false); |
| 80 |
return 0; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
template <typename FieldVector> |
| 87 |
void do_assemble(Operation Op, BulkData & bulk, FieldVector const& field_vector) |
| 88 |
{ |
| 89 |
switch(Op) { |
| 90 |
case Operation::SUM: |
| 91 |
parallel_sum(bulk, field_vector); |
| 92 |
break; |
| 93 |
case Operation::MIN: |
| 94 |
parallel_min(bulk, field_vector); |
| 95 |
break; |
| 96 |
case Operation::MAX: |
| 97 |
parallel_max(bulk, field_vector); |
| 98 |
break; |
| 99 |
default: |
| 100 |
STK_ThrowRequire(false); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
typedef Field<double> ScalarField; |
| 105 |
typedef Field<double> CartesianField; |
| 106 |
typedef Field<long double> LongDoubleField; |
| 107 |
typedef Field<int> IntField; |
| 108 |
typedef Field<unsigned long> IdField; |
| 109 |
|
| 110 |
template <Operation Op> |
| 111 |
void do_parallel_assemble() |
| 112 |
{ |
| 113 |
stk::ParallelMachine pm = MPI_COMM_WORLD; |
| 114 |
|
| 115 |
int p_rank = stk::parallel_machine_rank(pm); |
| 116 |
int p_size = stk::parallel_machine_size(pm); |
| 117 |
|
| 118 |
if (p_size == 1) { |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
const unsigned NX = 3; |
| 123 |
const unsigned NY = 3; |
| 124 |
const unsigned NZ = p_size; |
| 125 |
|
| 126 |
HexFixture fixture(pm, NX, NY, NZ); |
| 127 |
|
| 128 |
MetaData& meta = fixture.m_meta; |
| 129 |
BulkData& bulk = fixture.m_bulk_data; |
| 130 |
|
| 131 |
ScalarField& universal_scalar_node_field = meta.declare_field<double>( stk::topology::NODE_RANK, "universal_scalar_node_field" ); |
| 132 |
ScalarField& non_universal_scalar_node_field = meta.declare_field<double>( stk::topology::NODE_RANK, "non_universal_scalar_node_field" ); |
| 133 |
CartesianField& universal_cartesian_node_field = meta.declare_field<double>( stk::topology::NODE_RANK, "universal_cartesian_node_field" ); |
| 134 |
IntField& universal_scalar_int_node_field = meta.declare_field<int>( stk::topology::NODE_RANK, "universal_scalar_int_node_field" ); |
| 135 |
ScalarField& universal_scalar_edge_field = meta.declare_field<double>( stk::topology::EDGE_RANK, "universal_scalar_edge_field" ); |
| 136 |
LongDoubleField& universal_scalar_long_double_node_field = meta.declare_field<long double>( stk::topology::NODE_RANK, "universal_scalar_long_double_node_field" ); |
| 137 |
IdField& universal_scalar_id_node_field = meta.declare_field<unsigned long>( stk::topology::NODE_RANK, "universal_scalar_id_node_field" ); |
| 138 |
|
| 139 |
Part& center_part = meta.declare_part("center_part", stk::topology::NODE_RANK); |
| 140 |
|
| 141 |
put_field_on_mesh(universal_scalar_node_field, meta.universal_part(), nullptr); |
| 142 |
put_field_on_mesh(universal_cartesian_node_field, meta.universal_part(), 3, nullptr); |
| 143 |
put_field_on_mesh(universal_scalar_int_node_field, meta.universal_part(), nullptr); |
| 144 |
put_field_on_mesh(universal_scalar_edge_field, meta.universal_part(), nullptr); |
| 145 |
put_field_on_mesh(non_universal_scalar_node_field, center_part, nullptr); |
| 146 |
put_field_on_mesh(universal_scalar_long_double_node_field, meta.universal_part(), nullptr); |
| 147 |
put_field_on_mesh(universal_scalar_id_node_field, meta.universal_part(), nullptr); |
| 148 |
|
| 149 |
// TODO - Need a field that gets shared between more than 2 procs. |
| 150 |
|
| 151 |
meta.commit(); |
| 152 |
|
| 153 |
fixture.generate_mesh(); |
| 154 |
|
| 155 |
// Generate edges |
| 156 |
|
| 157 |
create_edges(bulk); |
| 158 |
|
| 159 |
Selector shared_sel = meta.globally_shared_part(); |
| 160 |
|
| 161 |
std::vector<size_t> counts; |
| 162 |
count_entities( shared_sel, bulk, counts ); |
| 163 |
|
| 164 |
int multiplier = (p_rank == 0 || p_rank == p_size - 1) ? 1 : 2; |
| 165 |
EXPECT_EQ( multiplier * (NX + 1) * (NY + 1), counts[0]); // nodes |
| 166 |
EXPECT_EQ( multiplier * 2 * NX * (NY + 1), counts[1]); // edges |
| 167 |
|
| 168 |
// Move center nodes into center part |
| 169 |
Entity center_element = fixture.elem(NX / 2, NY / 2, p_rank); |
| 170 |
|
| 171 |
bulk.modification_begin(); |
| 172 |
|
| 173 |
Entity const* nodes = bulk.begin_nodes(center_element); |
| 174 |
EXPECT_EQ(bulk.num_nodes(center_element), 8u); |
| 175 |
PartVector add_center_part(1, ¢er_part); |
| 176 |
for (int i = 0; i < 8; ++i) { |
| 177 |
if (bulk.parallel_owner_rank(nodes[i]) == p_rank) { |
| 178 |
bulk.change_entity_parts(nodes[i], add_center_part); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
bulk.modification_end(); |
| 183 |
|
| 184 |
// Fill field data |
| 185 |
|
| 186 |
BucketVector const& all_node_buckets = bulk.get_buckets(stk::topology::NODE_RANK, shared_sel); |
| 187 |
for (size_t b = 0, be = all_node_buckets.size(); b < be; ++b) { |
| 188 |
Bucket& bucket = *all_node_buckets[b]; |
| 189 |
for (size_t n = 0, ne = bucket.size(); n < ne; ++n) { |
| 190 |
Entity node = bucket[n]; |
| 191 |
EntityId node_id = bulk.identifier(node); |
| 192 |
|
| 193 |
int field_id = universal_scalar_node_field.mesh_meta_data_ordinal(); |
| 194 |
*field_data(universal_scalar_node_field, node) = p_rank + field_id + node_id; |
| 195 |
|
| 196 |
field_id = universal_cartesian_node_field.mesh_meta_data_ordinal(); |
| 197 |
double* data = stk::mesh::field_data(universal_cartesian_node_field, node); |
| 198 |
for (int d = 0; d < 3; ++d) { |
| 199 |
data[d] = p_rank + (field_id*d) + node_id; |
| 200 |
} |
| 201 |
|
| 202 |
field_id = universal_scalar_int_node_field.mesh_meta_data_ordinal(); |
| 203 |
*field_data(universal_scalar_int_node_field, node) = p_rank + field_id + node_id; |
| 204 |
|
| 205 |
|
| 206 |
field_id = non_universal_scalar_node_field.mesh_meta_data_ordinal(); |
| 207 |
if (bucket.member(center_part)) { |
| 208 |
*field_data(non_universal_scalar_node_field, node) = p_rank + field_id + node_id; |
| 209 |
} |
| 210 |
|
| 211 |
field_id = universal_scalar_long_double_node_field.mesh_meta_data_ordinal(); |
| 212 |
*field_data(universal_scalar_long_double_node_field, node) = p_rank + field_id + node_id; |
| 213 |
|
| 214 |
field_id = universal_scalar_id_node_field.mesh_meta_data_ordinal(); |
| 215 |
*field_data(universal_scalar_id_node_field, node) = p_rank + field_id + node_id; |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
BucketVector const& all_edge_buckets = bulk.get_buckets(stk::topology::EDGE_RANK, shared_sel); |
| 220 |
for (size_t b = 0, be = all_edge_buckets.size(); b < be; ++b) { |
| 221 |
Bucket& bucket = *all_edge_buckets[b]; |
| 222 |
for (size_t e = 0, ee = bucket.size(); e < ee; ++e) { |
| 223 |
Entity edge = bucket[e]; |
| 224 |
EntityId edge_id = bulk.identifier(edge); |
| 225 |
|
| 226 |
int field_id = universal_scalar_edge_field.mesh_meta_data_ordinal(); |
| 227 |
*field_data(universal_scalar_edge_field, edge) = p_rank + field_id + edge_id; |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
std::vector<const FieldBase*> double_field_vector; |
| 232 |
double_field_vector.push_back(&universal_scalar_node_field); |
| 233 |
double_field_vector.push_back(&non_universal_scalar_node_field); |
| 234 |
double_field_vector.push_back(&universal_cartesian_node_field); |
| 235 |
double_field_vector.push_back(&universal_scalar_edge_field); |
| 236 |
|
| 237 |
do_assemble(Op, bulk, double_field_vector); |
| 238 |
|
| 239 |
std::vector<const FieldBase*> int_field_vector(1, &universal_scalar_int_node_field); |
| 240 |
|
| 241 |
do_assemble(Op, bulk, int_field_vector); |
| 242 |
|
| 243 |
std::vector<const FieldBase*> long_double_field_vector(1, &universal_scalar_long_double_node_field); |
| 244 |
|
| 245 |
do_assemble(Op, bulk, long_double_field_vector); |
| 246 |
|
| 247 |
std::vector<const FieldBase*> id_field_vector(1, &universal_scalar_id_node_field); |
| 248 |
|
| 249 |
do_assemble(Op, bulk, id_field_vector); |
| 250 |
|
| 251 |
// Check field values |
| 252 |
|
| 253 |
for (size_t b = 0, be = all_node_buckets.size(); b < be; ++b) { |
| 254 |
Bucket& bucket = *all_node_buckets[b]; |
| 255 |
for (size_t n = 0, ne = bucket.size(); n < ne; ++n) { |
| 256 |
Entity node = bucket[n]; |
| 257 |
EntityId node_id = bulk.identifier(node); |
| 258 |
|
| 259 |
bool is_left_node = bulk.in_shared(bulk.entity_key(node), p_rank - 1); |
| 260 |
|
| 261 |
int sharing_rank = is_left_node ? p_rank - 1 : p_rank + 1; |
| 262 |
int field_id = universal_scalar_node_field.mesh_meta_data_ordinal(); |
| 263 |
EXPECT_EQ( *field_data(universal_scalar_node_field, node), |
| 264 |
(do_operation<double>(Op, p_rank + field_id + node_id, sharing_rank + field_id + node_id)) ); |
| 265 |
|
| 266 |
field_id = universal_cartesian_node_field.mesh_meta_data_ordinal(); |
| 267 |
double* data = stk::mesh::field_data(universal_cartesian_node_field, node); |
| 268 |
for (int d = 0; d < 3; ++d) { |
| 269 |
EXPECT_EQ( data[d], (do_operation<double>(Op, p_rank + field_id*d + node_id, sharing_rank + field_id*d + node_id)) ); |
| 270 |
} |
| 271 |
|
| 272 |
field_id = universal_scalar_int_node_field.mesh_meta_data_ordinal(); |
| 273 |
EXPECT_EQ( *field_data(universal_scalar_int_node_field, node), |
| 274 |
(do_operation<int>(Op, p_rank + field_id + node_id, sharing_rank + field_id + node_id)) ); |
| 275 |
|
| 276 |
field_id = non_universal_scalar_node_field.mesh_meta_data_ordinal(); |
| 277 |
if (bucket.member(center_part)) { |
| 278 |
EXPECT_EQ( *field_data(non_universal_scalar_node_field, node), |
| 279 |
(do_operation<double>(Op, p_rank + field_id + node_id, sharing_rank + field_id + node_id)) ); |
| 280 |
} |
| 281 |
|
| 282 |
field_id = universal_scalar_long_double_node_field.mesh_meta_data_ordinal(); |
| 283 |
EXPECT_EQ( *field_data(universal_scalar_long_double_node_field, node), |
| 284 |
(do_operation<long double>(Op, p_rank + field_id + node_id, sharing_rank + field_id + node_id)) ); |
| 285 |
|
| 286 |
field_id = universal_scalar_id_node_field.mesh_meta_data_ordinal(); |
| 287 |
EXPECT_EQ( *field_data(universal_scalar_id_node_field, node), |
| 288 |
(do_operation<unsigned long>(Op, p_rank + field_id + node_id, sharing_rank + field_id + node_id)) ); |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
for (size_t b = 0, be = all_edge_buckets.size(); b < be; ++b) { |
| 293 |
Bucket& bucket = *all_edge_buckets[b]; |
| 294 |
for (size_t e = 0, ee = bucket.size(); e < ee; ++e) { |
| 295 |
Entity edge = bucket[e]; |
| 296 |
EntityId edge_id = bulk.identifier(edge); |
| 297 |
|
| 298 |
bool is_left_edge = bulk.in_shared(bulk.entity_key(edge), p_rank - 1); |
| 299 |
|
| 300 |
int sharing_rank = is_left_edge ? p_rank - 1 : p_rank + 1; |
| 301 |
|
| 302 |
int field_id = universal_scalar_edge_field.mesh_meta_data_ordinal(); |
| 303 |
EXPECT_EQ( *field_data(universal_scalar_edge_field, edge), |
| 304 |
(do_operation<double>(Op, p_rank + field_id + edge_id, sharing_rank + field_id + edge_id)) ); |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
TEST(FieldParallel, parallel_sum) |
| 310 |
{ |
| 311 |
do_parallel_assemble<Operation::SUM>(); |
| 312 |
} |
| 313 |
|
| 314 |
TEST(FieldParallel, parallel_min) |
| 315 |
{ |
| 316 |
do_parallel_assemble<Operation::MIN>(); |
| 317 |
} |
| 318 |
|
| 319 |
TEST(FieldParallel, parallel_max) |
| 320 |
{ |
| 321 |
do_parallel_assemble<Operation::MAX>(); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
template <typename FieldVector> |
| 326 |
void do_assemble_including_ghosts(Operation Op, BulkData & bulk, FieldVector const& field_vector) |
| 327 |
{ |
| 328 |
switch(Op) { |
| 329 |
case Operation::SUM: |
| 330 |
parallel_sum_including_ghosts(bulk, field_vector); |
| 331 |
break; |
| 332 |
case Operation::MIN: |
| 333 |
parallel_min_including_ghosts(bulk, field_vector); |
| 334 |
break; |
| 335 |
case Operation::MAX: |
| 336 |
parallel_max_including_ghosts(bulk, field_vector); |
| 337 |
break; |
| 338 |
default: |
| 339 |
STK_ThrowRequire(false); |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
template <Operation Op> |
| 344 |
void do_parallel_assemble_including_ghosts() |
| 345 |
{ |
| 346 |
stk::ParallelMachine pm = MPI_COMM_WORLD; |
| 347 |
|
| 348 |
int p_rank = stk::parallel_machine_rank(pm); |
| 349 |
int p_size = stk::parallel_machine_size(pm); |
| 350 |
|
| 351 |
if (p_size == 1) { |
| 352 |
return; |
| 353 |
} |
| 354 |
|
| 355 |
const unsigned NX = 3; |
| 356 |
const unsigned NY = 3; |
| 357 |
const unsigned NZ = p_size; |
| 358 |
|
| 359 |
const bool autoAuraOn = false; |
| 360 |
HexFixture fixture(pm, NX, NY, NZ, autoAuraOn); |
| 361 |
|
| 362 |
MetaData& meta = fixture.m_meta; |
| 363 |
BulkData& bulk = fixture.m_bulk_data; |
| 364 |
|
| 365 |
ScalarField& universal_scalar_node_field = meta.declare_field<double>( stk::topology::NODE_RANK, "universal_scalar_node_field" ); |
| 366 |
ScalarField& non_universal_scalar_node_field = meta.declare_field<double>( stk::topology::NODE_RANK, "non_universal_scalar_node_field" ); |
| 367 |
CartesianField& universal_cartesian_node_field = meta.declare_field<double>( stk::topology::NODE_RANK, "universal_cartesian_node_field" ); |
| 368 |
IntField& universal_scalar_int_node_field = meta.declare_field<int>( stk::topology::NODE_RANK, "universal_scalar_int_node_field" ); |
| 369 |
IdField& universal_scalar_id_node_field = meta.declare_field<unsigned long>( stk::topology::NODE_RANK, "universal_scalar_id_node_field" ); |
| 370 |
|
| 371 |
Part& center_part = meta.declare_part("center_part", stk::topology::NODE_RANK); |
| 372 |
|
| 373 |
put_field_on_mesh(universal_scalar_node_field, meta.universal_part(), nullptr); |
| 374 |
put_field_on_mesh(universal_cartesian_node_field, meta.universal_part(), 3, nullptr); |
| 375 |
put_field_on_mesh(universal_scalar_int_node_field, meta.universal_part(), nullptr); |
| 376 |
put_field_on_mesh(non_universal_scalar_node_field, center_part, nullptr); |
| 377 |
put_field_on_mesh(universal_scalar_id_node_field, meta.universal_part(), nullptr); |
| 378 |
|
| 379 |
meta.commit(); |
| 380 |
|
| 381 |
fixture.generate_mesh(); |
| 382 |
|
| 383 |
// Ghost non-shared nodes from the "ends" of the mesh to the opposite side |
| 384 |
std::vector<EntityProc> add_send1; |
| 385 |
std::vector<EntityProc> add_send2; |
| 386 |
Selector non_shared_sel = !meta.globally_shared_part(); |
| 387 |
if (p_rank == 0 || p_rank == p_size - 1) { |
| 388 |
const int target_proc = (p_rank == 0) ? (p_size - 1) : 0; // Opposite ends |
| 389 |
BucketVector const& non_shared_node_buckets = bulk.get_buckets(stk::topology::NODE_RANK, non_shared_sel); |
| 390 |
for (size_t b = 0, be = non_shared_node_buckets.size(); b < be; ++b) { |
| 391 |
Bucket& bucket = *non_shared_node_buckets[b]; |
| 392 |
for (size_t n = 0, ne = bucket.size(); n < ne; ++n) { |
| 393 |
Entity node = bucket[n]; |
| 394 |
add_send1.push_back(std::make_pair(node, target_proc)); |
| 395 |
add_send2.push_back(std::make_pair(node, target_proc)); |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
bulk.modification_begin(); |
| 400 |
stk::mesh::Ghosting & ghosting1 = bulk.create_ghosting("test ghosting 1"); |
| 401 |
stk::mesh::Ghosting & ghosting2 = bulk.create_ghosting("test ghosting 2"); |
| 402 |
bulk.change_ghosting(ghosting1, add_send1); |
| 403 |
bulk.change_ghosting(ghosting2, add_send2); |
| 404 |
bulk.modification_end(); |
| 405 |
|
| 406 |
|
| 407 |
Selector shared_sel = meta.globally_shared_part(); |
| 408 |
|
| 409 |
std::vector<size_t> counts; |
| 410 |
count_entities( shared_sel, bulk, counts ); |
| 411 |
|
| 412 |
int multiplier = (p_rank == 0 || p_rank == p_size - 1) ? 1 : 2; |
| 413 |
EXPECT_EQ( multiplier * (NX + 1) * (NY + 1), counts[0]); // nodes |
| 414 |
|
| 415 |
// Move center nodes into center part |
| 416 |
Entity center_element = fixture.elem(NX / 2, NY / 2, p_rank); |
| 417 |
|
| 418 |
bulk.modification_begin(); |
| 419 |
|
| 420 |
Entity const* nodes = bulk.begin_nodes(center_element); |
| 421 |
EXPECT_EQ(bulk.num_nodes(center_element), 8u); |
| 422 |
PartVector add_center_part(1, ¢er_part); |
| 423 |
for (int i = 0; i < 8; ++i) { |
| 424 |
if (bulk.parallel_owner_rank(nodes[i]) == p_rank) { |
| 425 |
bulk.change_entity_parts(nodes[i], add_center_part); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
bulk.modification_end(); |
| 430 |
|
| 431 |
// Fill field data |
| 432 |
|
| 433 |
BucketVector const& all_node_buckets = bulk.get_buckets(stk::topology::NODE_RANK, meta.universal_part()); |
| 434 |
for (size_t b = 0, be = all_node_buckets.size(); b < be; ++b) { |
| 435 |
Bucket& bucket = *all_node_buckets[b]; |
| 436 |
for (size_t n = 0, ne = bucket.size(); n < ne; ++n) { |
| 437 |
Entity node = bucket[n]; |
| 438 |
EntityId node_id = bulk.identifier(node); |
| 439 |
|
| 440 |
int field_id = universal_scalar_node_field.mesh_meta_data_ordinal(); |
| 441 |
*field_data(universal_scalar_node_field, node) = p_rank + field_id + node_id; |
| 442 |
|
| 443 |
field_id = universal_cartesian_node_field.mesh_meta_data_ordinal(); |
| 444 |
double* data = stk::mesh::field_data(universal_cartesian_node_field, node); |
| 445 |
for (int d = 0; d < 3; ++d) { |
| 446 |
data[d] = p_rank + (field_id*d) + node_id; |
| 447 |
} |
| 448 |
|
| 449 |
field_id = universal_scalar_int_node_field.mesh_meta_data_ordinal(); |
| 450 |
*field_data(universal_scalar_int_node_field, node) = p_rank + field_id + node_id; |
| 451 |
|
| 452 |
|
| 453 |
field_id = non_universal_scalar_node_field.mesh_meta_data_ordinal(); |
| 454 |
if (bucket.member(center_part)) { |
| 455 |
*field_data(non_universal_scalar_node_field, node) = p_rank + field_id + node_id; |
| 456 |
} |
| 457 |
|
| 458 |
field_id = universal_scalar_id_node_field.mesh_meta_data_ordinal(); |
| 459 |
*field_data(universal_scalar_id_node_field, node) = p_rank + field_id + node_id; |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
std::vector<const FieldBase*> double_field_vector; |
| 464 |
double_field_vector.push_back(&universal_scalar_node_field); |
| 465 |
double_field_vector.push_back(&non_universal_scalar_node_field); |
| 466 |
double_field_vector.push_back(&universal_cartesian_node_field); |
| 467 |
|
| 468 |
do_assemble_including_ghosts(Op, bulk, double_field_vector); |
| 469 |
|
| 470 |
std::vector<const FieldBase*> int_field_vector(1, &universal_scalar_int_node_field); |
| 471 |
|
| 472 |
do_assemble_including_ghosts(Op, bulk, int_field_vector); |
| 473 |
|
| 474 |
std::vector<const FieldBase*> id_field_vector(1, &universal_scalar_id_node_field); |
| 475 |
|
| 476 |
do_assemble_including_ghosts(Op, bulk, id_field_vector); |
| 477 |
|
| 478 |
// Check field values |
| 479 |
|
| 480 |
for (size_t b = 0, be = all_node_buckets.size(); b < be; ++b) { |
| 481 |
Bucket& bucket = *all_node_buckets[b]; |
| 482 |
for (size_t n = 0, ne = bucket.size(); n < ne; ++n) { |
| 483 |
Entity node = bucket[n]; |
| 484 |
EntityId node_id = bulk.identifier(node); |
| 485 |
|
| 486 |
int other_rank = 0; |
| 487 |
if (bulk.in_shared(bulk.entity_key(node))) { |
| 488 |
bool is_left_node = bulk.in_shared(bulk.entity_key(node), p_rank - 1); |
| 489 |
other_rank = is_left_node ? p_rank - 1 : p_rank + 1; |
| 490 |
} |
| 491 |
else { |
| 492 |
other_rank = (p_rank == 0) ? (p_size - 1) : 0; // Opposite ends |
| 493 |
} |
| 494 |
|
| 495 |
int field_id = universal_scalar_node_field.mesh_meta_data_ordinal(); |
| 496 |
EXPECT_EQ( do_operation<double>(Op, p_rank + field_id + node_id, other_rank + field_id + node_id), |
| 497 |
*field_data(universal_scalar_node_field, node) ); |
| 498 |
|
| 499 |
field_id = universal_cartesian_node_field.mesh_meta_data_ordinal(); |
| 500 |
double* data = stk::mesh::field_data(universal_cartesian_node_field, node); |
| 501 |
for (int d = 0; d < 3; ++d) { |
| 502 |
EXPECT_EQ( do_operation<double>(Op, p_rank + field_id*d + node_id, other_rank + field_id*d + node_id), data[d] ); |
| 503 |
} |
| 504 |
|
| 505 |
field_id = universal_scalar_int_node_field.mesh_meta_data_ordinal(); |
| 506 |
EXPECT_EQ( do_operation<int>(Op, p_rank + field_id + node_id, other_rank + field_id + node_id), |
| 507 |
*field_data(universal_scalar_int_node_field, node) ); |
| 508 |
|
| 509 |
field_id = non_universal_scalar_node_field.mesh_meta_data_ordinal(); |
| 510 |
if (bucket.member(center_part)) { |
| 511 |
EXPECT_EQ( do_operation<double>(Op, p_rank + field_id + node_id, other_rank + field_id + node_id), |
| 512 |
*field_data(non_universal_scalar_node_field, node) ); |
| 513 |
} |
| 514 |
|
| 515 |
field_id = universal_scalar_id_node_field.mesh_meta_data_ordinal(); |
| 516 |
EXPECT_EQ( do_operation<unsigned long>(Op, p_rank + field_id + node_id, other_rank + field_id + node_id), |
| 517 |
*field_data(universal_scalar_id_node_field, node) ); |
| 518 |
} |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
TEST(FieldParallel, parallel_sum_including_ghosts) |
| 523 |
{ |
| 524 |
do_parallel_assemble_including_ghosts<Operation::SUM>(); |
| 525 |
} |
| 526 |
|
| 527 |
TEST(FieldParallel, parallel_min_including_ghosts) |
| 528 |
{ |
| 529 |
do_parallel_assemble_including_ghosts<Operation::MIN>(); |
| 530 |
} |
| 531 |
|
| 532 |
TEST(FieldParallel, parallel_max_including_ghosts) |
| 533 |
{ |
| 534 |
do_parallel_assemble_including_ghosts<Operation::MAX>(); |
| 535 |
} |
| 536 |
|
| 537 |
} //namespace <anonymous> |
| 538 |
#endif |