Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_field_shared_reduction.cpp

raw
1 #include "gtest/gtest.h"
2 #include "stk_middle_mesh/field_shared_reduction.hpp"
3 #include "stk_middle_mesh/create_mesh.hpp"
4
5 using namespace stk::middle_mesh;
6
7 TEST(FieldSharedReduction, Sum)
8 {
9 mesh::impl::MeshSpec spec;
10 spec.numelX = 4;
11 spec.numelY = 5;
12 spec.xmin = 0;
13 spec.xmax = 1;
14 spec.ymin = 0;
15 spec.ymax = 1;
16
17 auto func = [&](const utils::Point& pt) { return pt; };
18 std::shared_ptr<mesh::Mesh> mesh = create_mesh(spec, func);
19
20 auto fieldPtr = mesh::create_field<int>(mesh, mesh::FieldShape(2, 2, 0), 3);
21 auto& field = *fieldPtr;
22
23 for (int dim=0; dim < 2; ++dim)
24 for (auto entity : mesh->get_mesh_entities(dim))
25 {
26 int idx = 0;
27 for (int i=0; i < 2; ++i)
28 for (int j=0; j < 3; ++j)
29 field(entity, i, j) = entity->get_id() + idx++;
30 }
31
32 mesh::ReductionOpSum<int> op;
33 mesh::FieldSharedReduction<int> reducer(fieldPtr, op);
34 reducer.reduce();
35
36 for (int dim=0; dim < 2; ++dim)
37 {
38 for (auto entity : mesh->get_mesh_entities(dim))
39 {
40 int baseVal = entity->get_id();
41 for (int i=0; i < entity->count_remote_shared_entities(); ++i)
42 {
43 baseVal += entity->get_remote_shared_entity(i).remoteId;
44 }
45
46 int idx = 0;
47 for (int i=0; i < 2; ++i)
48 for (int j=0; j < 3; ++j)
49 {
50 EXPECT_EQ(field(entity, i, j), baseVal + (entity->count_remote_shared_entities() + 1)*idx);
51 ++idx;
52 }
53 }
54 }
55
56
57 }