File: CustomGhostEntities.cpp

package info (click to toggle)
trilinos 13.2.0-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 837,964 kB
  • sloc: cpp: 3,466,826; ansic: 433,701; fortran: 168,838; python: 102,712; xml: 66,353; sh: 38,380; makefile: 25,246; perl: 7,516; f90: 6,358; csh: 4,161; objc: 2,620; lex: 1,484; lisp: 810; javascript: 552; yacc: 515; awk: 364; ml: 281; php: 145
file content (120 lines) | stat: -rw-r--r-- 3,673 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "gtest/gtest.h"
#include "mpi.h"
#include <stk_mesh/base/Part.hpp>
#include <stk_mesh/base/MetaData.hpp>
#include <stk_mesh/base/BulkData.hpp>
#include <stk_mesh/base/GetEntities.hpp>
#include <stk_unit_test_utils/MeshFixture.hpp>
#include <stk_unit_test_utils/getOption.h>
#include <stk_util/parallel/CommSparse.hpp>
#include <stk_util/parallel/Parallel.hpp>

namespace
{

class CustomGhostEntities: public stk::unit_test_util::MeshFixture
{
protected:
    CustomGhostEntities()
    : stk::unit_test_util::MeshFixture(),
      myPart(get_meta().declare_part("myPart",stk::topology::FACE_RANK))
    {
        if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) {
            setup_mesh("generated:2x1x2|sideset:z", stk::mesh::BulkData::NO_AUTO_AURA);
            get_face_entities();
            add_myPart_to_both_faces();
        }
    }

    void get_face_entities()
    {
        face15 = get_bulk().get_entity(stk::topology::FACE_RANK, 15);
        face25 = get_bulk().get_entity(stk::topology::FACE_RANK, 25);
    }

    void add_myPart_to_face15_and_face25()
    {
        if (get_bulk().is_valid(face15)) {
            get_bulk().change_entity_parts(face15, stk::mesh::ConstPartVector{&myPart});
        }
        if (get_bulk().is_valid(face25)) {
            get_bulk().change_entity_parts(face25, stk::mesh::ConstPartVector{&myPart});
        }
    }

    void add_myPart_to_both_faces()
    {
        get_bulk().modification_begin();
        add_myPart_to_face15_and_face25();
        get_bulk().modification_end();
    }

    void send_face_15_from_proc_0_to_proc_1(stk::mesh::Ghosting& ghosting)
    {
        stk::mesh::EntityProcVec entitiesToGhost;
        if (get_bulk().parallel_rank() == 0) {
            entitiesToGhost.push_back(stk::mesh::EntityProc(face15, proc1));
        }
        get_bulk().change_ghosting(ghosting, entitiesToGhost);
    }

    void custom_ghost_face_15_from_proc_0_to_proc_1()
    {
        get_bulk().modification_begin();
        stk::mesh::Ghosting& ghosting = get_bulk().create_ghosting("myCustomGhosting");
        send_face_15_from_proc_0_to_proc_1(ghosting);
        get_bulk().modification_end();
    }

    void remove_face_15_from_myPart_on_proc_0()
    {
        get_bulk().modification_begin();
        if (get_bulk().parallel_rank() == 0) {
            get_bulk().change_entity_parts(face15, stk::mesh::ConstPartVector{}, stk::mesh::ConstPartVector{&myPart});
        }
        get_bulk().modification_end();
    }

    void expect_face15_not_in_myPart_on_any_proc()
    {
        face15 = get_bulk().get_entity(stk::topology::FACE_RANK, 15);
        EXPECT_FALSE(get_bulk().bucket(face15).member(myPart));
    }

    void expect_proc_0_has_4_nodes_in_myPart()
    {
        if (get_bulk().parallel_rank() == 0) {
            EXPECT_EQ(4u, stk::mesh::count_selected_entities(myPart, get_bulk().buckets(stk::topology::NODE_RANK)));
        }
    }

    void expect_proc_1_has_2_nodes_in_myPart()
    {
        if (get_bulk().parallel_rank() == 1) {
            EXPECT_EQ(2u, stk::mesh::count_selected_entities(myPart, get_bulk().buckets(stk::topology::NODE_RANK)));
        }
    }

    void check_results()
    {
        expect_face15_not_in_myPart_on_any_proc();
        expect_proc_0_has_4_nodes_in_myPart();
        expect_proc_1_has_2_nodes_in_myPart();
    }

private:
    stk::mesh::Part& myPart;
    stk::mesh::Entity face15, face25;
    int proc1 = 1;
};

TEST_F(CustomGhostEntities, removePart)
{
    if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) {
        custom_ghost_face_15_from_proc_0_to_proc_1();
        remove_face_15_from_myPart_on_proc_0();
        check_results();
    }
}

}