Skip to content

Commit 28103d7

Browse files
committed
EAMxx: split grid tests into multiple unit tests
1 parent e1ffa2a commit 28103d7

File tree

4 files changed

+141
-106
lines changed

4 files changed

+141
-106
lines changed

components/eamxx/src/share/grid/tests/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
if (NOT SCREAM_ONLY_GENERATE_BASELINES)
33
include(ScreamUtils)
44

5-
# Test grids
5+
# Test point grid
6+
CreateUnitTest(point_grid "point_grid_tests.cpp"
7+
LIBS eamxx_grid
8+
MPI_RANKS 1 ${SCREAM_TEST_MAX_RANKS})
9+
10+
# Test se grid
11+
CreateUnitTest(se_grid "se_grid_tests.cpp"
12+
LIBS eamxx_grid
13+
MPI_RANKS 1 ${SCREAM_TEST_MAX_RANKS})
14+
15+
# Test grid gid-related methods
616
CreateUnitTest(grid "grid_tests.cpp"
717
LIBS eamxx_grid
818
MPI_RANKS 1 ${SCREAM_TEST_MAX_RANKS})
Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,12 @@
11
#include <catch2/catch.hpp>
22

3-
#include "share/manager/mesh_free_grids_manager.hpp"
43
#include "share/grid/point_grid.hpp"
5-
#include "share/grid/se_grid.hpp"
6-
#include "share/grid/grid_utils.hpp"
74
#include "share/core/eamxx_setup_random_test.hpp"
85
#include "share/core/eamxx_types.hpp"
96

10-
#include <ekat_pack.hpp>
11-
127
#include <algorithm>
138

14-
namespace {
15-
16-
using namespace scream;
17-
using namespace scream::ShortFieldTagsNames;
18-
19-
TEST_CASE("point_grid", "") {
20-
21-
ekat::Comm comm(MPI_COMM_WORLD);
22-
23-
const int num_procs = comm.size();
24-
const int num_local_cols = 128;
25-
const int num_global_cols = num_local_cols*num_procs;
26-
const int num_levels = 72;
27-
28-
auto grid = create_point_grid("my_grid", num_global_cols, num_levels, comm);
29-
REQUIRE(grid->type() == GridType::Point);
30-
REQUIRE(grid->name() == "my_grid");
31-
REQUIRE(grid->get_num_vertical_levels() == num_levels);
32-
REQUIRE(grid->get_num_local_dofs() == num_local_cols);
33-
REQUIRE(grid->get_num_global_dofs() == num_global_cols);
34-
REQUIRE(grid->is_unique());
35-
36-
// Point grids should have (global) gids spanning the interval [min_gid, min_gid+num_global_dofs)
37-
const auto max_gid = grid->get_global_max_dof_gid();
38-
const auto min_gid = grid->get_global_min_dof_gid();
39-
REQUIRE( (max_gid-min_gid+1)==grid->get_num_global_dofs() );
40-
41-
auto lid_to_idx = grid->get_lid_to_idx_map().get_view<int**,Host>();
42-
for (int i = 0; i < grid->get_num_local_dofs(); ++i) {
43-
REQUIRE(lid_to_idx.extent_int(1) == 1);
44-
REQUIRE(i == lid_to_idx(i, 0));
45-
}
46-
47-
auto layout = grid->get_2d_scalar_layout();
48-
REQUIRE(layout.tags().size() == 1);
49-
REQUIRE(layout.tag(0) == COL);
50-
51-
auto shallow_copy = grid->clone("shallow",true);
52-
auto deep_copy = grid->clone("deep",false);
53-
54-
using gid_type = AbstractGrid::gid_type;
55-
56-
auto grid_gids = grid->get_dofs_gids().get_view<const gid_type*,Host>();
57-
auto scopy_gids = shallow_copy->get_dofs_gids().get_view<const gid_type*,Host>();
58-
auto dcopy_gids = deep_copy->get_dofs_gids().get_view<const gid_type*,Host>();
59-
REQUIRE (scopy_gids.data()==grid_gids.data());
60-
REQUIRE (dcopy_gids.data()!=grid_gids.data());
61-
for (int i=0; i<grid->get_num_local_dofs(); ++i) {
62-
REQUIRE (dcopy_gids[i]==grid_gids[i]);
63-
}
64-
65-
shallow_copy->reset_num_vertical_lev(4);
66-
REQUIRE (shallow_copy->get_num_vertical_levels()==4);
67-
}
68-
69-
TEST_CASE("se_grid", "") {
70-
ekat::Comm comm(MPI_COMM_WORLD);
71-
72-
const int num_local_elems = 10;
73-
const int num_gp = 4;
74-
const int num_levels = 72;
75-
76-
auto gm = create_mesh_free_grids_manager(comm,num_local_elems,num_gp,num_levels,0);
77-
gm->build_grids();
78-
79-
// SE grid
80-
auto se_grid = gm->get_grid("SE Grid");
81-
82-
REQUIRE(se_grid->type() == GridType::SE);
83-
REQUIRE(se_grid->name() == "SE Grid");
84-
REQUIRE(se_grid->get_num_vertical_levels() == num_levels);
85-
REQUIRE(se_grid->get_num_local_dofs() == num_local_elems*num_gp*num_gp);
86-
87-
auto layout = se_grid->get_2d_scalar_layout();
88-
REQUIRE(layout.tags().size() == 3);
89-
REQUIRE(layout.tag(0) == EL);
90-
REQUIRE(layout.tag(1) == GP);
91-
REQUIRE(layout.tag(2) == GP);
92-
93-
REQUIRE (se_grid->is_unique());
94-
95-
const auto max_gid = se_grid->get_global_max_dof_gid();
96-
const auto min_gid = se_grid->get_global_min_dof_gid();
97-
REQUIRE( (max_gid-min_gid+1)==se_grid->get_num_global_dofs() );
98-
99-
auto shallow_copy = se_grid->clone("shallow",true);
100-
auto deep_copy = se_grid->clone("deep",false);
101-
102-
using gid_type = AbstractGrid::gid_type;
103-
104-
auto grid_gids = se_grid->get_dofs_gids().get_view<const gid_type*,Host>();
105-
auto scopy_gids = shallow_copy->get_dofs_gids().get_view<const gid_type*,Host>();
106-
auto dcopy_gids = deep_copy->get_dofs_gids().get_view<const gid_type*,Host>();
107-
REQUIRE (scopy_gids.data()==grid_gids.data());
108-
REQUIRE (dcopy_gids.data()!=grid_gids.data());
109-
for (int i=0; i<se_grid->get_num_local_dofs(); ++i) {
110-
REQUIRE (dcopy_gids[i]==grid_gids[i]);
111-
}
112-
}
9+
namespace scream {
11310

11411
TEST_CASE ("get_owners") {
11512
ekat::Comm comm(MPI_COMM_WORLD);
@@ -218,4 +115,4 @@ TEST_CASE ("get_remote_pids_and_lids") {
218115
}
219116
}
220117

221-
} // anonymous namespace
118+
} // namespace scream
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <catch2/catch.hpp>
2+
3+
#include "share/grid/point_grid.hpp"
4+
#include "share/grid/grid_utils.hpp"
5+
#include "share/core/eamxx_types.hpp"
6+
7+
#include <algorithm>
8+
9+
namespace scream {
10+
11+
TEST_CASE("point_grid", "") {
12+
using namespace scream::ShortFieldTagsNames;
13+
14+
ekat::Comm comm(MPI_COMM_WORLD);
15+
16+
const int num_procs = comm.size();
17+
const int num_local_cols = 128;
18+
const int num_global_cols = num_local_cols*num_procs;
19+
const int num_levels = 72;
20+
21+
auto grid = create_point_grid("my_grid", num_global_cols, num_levels, comm);
22+
23+
REQUIRE(grid->type() == GridType::Point);
24+
REQUIRE(grid->name() == "my_grid");
25+
REQUIRE(grid->get_num_vertical_levels() == num_levels);
26+
REQUIRE(grid->get_num_local_dofs() == num_local_cols);
27+
REQUIRE(grid->get_num_global_dofs() == num_global_cols);
28+
REQUIRE(grid->is_unique());
29+
30+
// Point grids should have (global) gids spanning the interval [min_gid, min_gid+num_global_dofs)
31+
const auto max_gid = grid->get_global_max_dof_gid();
32+
const auto min_gid = grid->get_global_min_dof_gid();
33+
REQUIRE( (max_gid-min_gid+1)==grid->get_num_global_dofs() );
34+
35+
auto lid_to_idx = grid->get_lid_to_idx_map().get_view<int**,Host>();
36+
for (int i = 0; i < grid->get_num_local_dofs(); ++i) {
37+
REQUIRE(lid_to_idx.extent_int(1) == 1);
38+
REQUIRE(i == lid_to_idx(i, 0));
39+
}
40+
41+
auto layout = grid->get_2d_scalar_layout();
42+
REQUIRE(layout.tags().size() == 1);
43+
REQUIRE(layout.tag(0) == COL);
44+
45+
auto shallow_copy = grid->clone("shallow",true);
46+
auto deep_copy = grid->clone("deep",false);
47+
48+
using gid_type = AbstractGrid::gid_type;
49+
50+
auto grid_gids = grid->get_dofs_gids().get_view<const gid_type*,Host>();
51+
auto scopy_gids = shallow_copy->get_dofs_gids().get_view<const gid_type*,Host>();
52+
auto dcopy_gids = deep_copy->get_dofs_gids().get_view<const gid_type*,Host>();
53+
REQUIRE (scopy_gids.data()==grid_gids.data());
54+
REQUIRE (dcopy_gids.data()!=grid_gids.data());
55+
for (int i=0; i<grid->get_num_local_dofs(); ++i) {
56+
REQUIRE (dcopy_gids[i]==grid_gids[i]);
57+
}
58+
59+
shallow_copy->reset_num_vertical_lev(4);
60+
REQUIRE (shallow_copy->get_num_vertical_levels()==4);
61+
}
62+
63+
} // namespace scream
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <catch2/catch.hpp>
2+
3+
#include "share/grid/se_grid.hpp"
4+
#include "share/grid/grid_utils.hpp"
5+
#include "share/core/eamxx_types.hpp"
6+
7+
#include <algorithm>
8+
9+
namespace scream {
10+
11+
12+
TEST_CASE("se_grid", "") {
13+
using namespace scream::ShortFieldTagsNames;
14+
ekat::Comm comm(MPI_COMM_WORLD);
15+
16+
const int num_local_elems = 10;
17+
const int num_gp = 4;
18+
const int num_levels = 72;
19+
20+
// SE grid
21+
auto se_grid = std::make_shared<SEGrid>("se_grid",num_local_elems,num_gp,num_levels,comm);
22+
{
23+
auto nldofs = se_grid->get_num_local_dofs();
24+
auto dof_offset = nldofs;
25+
comm.scan(&dof_offset,1,MPI_SUM);
26+
dof_offset -= nldofs; // comm.scan(..) is an INCLUSIVE prefix op
27+
auto dofs_gids = se_grid->get_dofs_gids();
28+
auto h_dofs_gids = dofs_gids.get_view<AbstractGrid::gid_type*,Host>();
29+
std::iota(h_dofs_gids.data(),h_dofs_gids.data()+nldofs,dof_offset);
30+
dofs_gids.sync_to_dev();
31+
}
32+
33+
REQUIRE(se_grid->type() == GridType::SE);
34+
REQUIRE(se_grid->name() == "se_grid");
35+
REQUIRE(se_grid->get_num_vertical_levels() == num_levels);
36+
REQUIRE(se_grid->get_num_local_dofs() == num_local_elems*num_gp*num_gp);
37+
38+
auto layout = se_grid->get_2d_scalar_layout();
39+
REQUIRE(layout.tags().size() == 3);
40+
REQUIRE(layout.tag(0) == EL);
41+
REQUIRE(layout.tag(1) == GP);
42+
REQUIRE(layout.tag(2) == GP);
43+
44+
REQUIRE (se_grid->is_unique());
45+
46+
const auto max_gid = se_grid->get_global_max_dof_gid();
47+
const auto min_gid = se_grid->get_global_min_dof_gid();
48+
REQUIRE( (max_gid-min_gid+1)==se_grid->get_num_global_dofs() );
49+
50+
auto shallow_copy = se_grid->clone("shallow",true);
51+
auto deep_copy = se_grid->clone("deep",false);
52+
53+
using gid_type = AbstractGrid::gid_type;
54+
55+
auto grid_gids = se_grid->get_dofs_gids().get_view<const gid_type*,Host>();
56+
auto scopy_gids = shallow_copy->get_dofs_gids().get_view<const gid_type*,Host>();
57+
auto dcopy_gids = deep_copy->get_dofs_gids().get_view<const gid_type*,Host>();
58+
REQUIRE (scopy_gids.data()==grid_gids.data());
59+
REQUIRE (dcopy_gids.data()!=grid_gids.data());
60+
for (int i=0; i<se_grid->get_num_local_dofs(); ++i) {
61+
REQUIRE (dcopy_gids[i]==grid_gids[i]);
62+
}
63+
}
64+
65+
} // anonymous namespace

0 commit comments

Comments
 (0)