Skip to content

Commit ab3a2d5

Browse files
committed
Avoid duplications in tests
1 parent 02a7600 commit ab3a2d5

File tree

2 files changed

+47
-78
lines changed

2 files changed

+47
-78
lines changed

tests/test_heat_source.cc

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,43 @@ namespace utf = boost::unit_test;
1919
namespace adamantine
2020
{
2121

22-
BOOST_AUTO_TEST_CASE(heat_source_value_2d, *utf::tolerance(1e-12))
22+
template <int dim>
23+
std::tuple<Kokkos::View<ScanPathSegment *, Kokkos::HostSpace>,
24+
ElectronBeamHeatSource<dim, dealii::MemorySpace::Host>,
25+
GoldakHeatSource<dim, dealii::MemorySpace::Host>>
26+
create_heat_sources(std::string scan_path_file)
2327
{
2428
boost::property_tree::ptree database;
2529

2630
database.put("depth", 0.1);
2731
database.put("absorption_efficiency", 0.1);
2832
database.put("diameter", 1.0);
2933
database.put("max_power", 10.);
30-
database.put("scan_path_file", "scan_path.txt");
34+
database.put("scan_path_file", scan_path_file);
3135
database.put("scan_path_file_format", "segment");
3236
std::vector<ScanPathSegment> scan_path_segments =
3337
ScanPath<dealii::MemorySpace::Host>::extract_scan_paths(
3438
database.get<std::string>("scan_path_file"),
3539
database.get<std::string>("scan_path_file_format"));
36-
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace> scan_paths_segments_view(
37-
scan_path_segments.data(), scan_path_segments.size());
40+
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace> scan_path_segments_view(
41+
"scan_path_segments", scan_path_segments.size());
42+
Kokkos::deep_copy(scan_path_segments_view,
43+
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace>{
44+
scan_path_segments.data(), scan_path_segments.size()});
3845
BeamHeatSourceProperties beam(database);
39-
GoldakHeatSource<2, dealii::MemorySpace::Host> goldak_heat_source(
40-
beam, ScanPath<dealii::MemorySpace::Host>(scan_paths_segments_view));
41-
ElectronBeamHeatSource<2, dealii::MemorySpace::Host> eb_heat_source(
42-
database, ScanPath<dealii::MemorySpace::Host>(scan_paths_segments_view));
46+
return std::tuple(
47+
scan_path_segments_view,
48+
ElectronBeamHeatSource<dim, dealii::MemorySpace::Host>{
49+
database,
50+
ScanPath<dealii::MemorySpace::Host>(scan_path_segments_view)},
51+
GoldakHeatSource<dim, dealii::MemorySpace::Host>{
52+
beam, ScanPath<dealii::MemorySpace::Host>(scan_path_segments_view)});
53+
}
54+
55+
BOOST_AUTO_TEST_CASE(heat_source_value_2d, *utf::tolerance(1e-12))
56+
{
57+
auto [scan_paths_segments, eb_heat_source, goldak_heat_source] =
58+
create_heat_sources<2>("scan_path.txt");
4359

4460
double g_value = 0.0;
4561
double eb_value = 0.0;
@@ -110,26 +126,8 @@ BOOST_AUTO_TEST_CASE(heat_source_value_2d, *utf::tolerance(1e-12))
110126

111127
BOOST_AUTO_TEST_CASE(heat_source_value_3d, *utf::tolerance(1e-12))
112128
{
113-
boost::property_tree::ptree database;
114-
115-
database.put("depth", 0.1);
116-
database.put("absorption_efficiency", 0.1);
117-
database.put("diameter", 1.0);
118-
database.put("max_power", 10.);
119-
database.put("scan_path_file", "scan_path.txt");
120-
database.put("scan_path_file_format", "segment");
121-
std::vector<ScanPathSegment> scan_path_segments =
122-
ScanPath<dealii::MemorySpace::Host>::extract_scan_paths(
123-
database.get<std::string>("scan_path_file"),
124-
database.get<std::string>("scan_path_file_format"));
125-
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace> scan_paths_segments_view(
126-
scan_path_segments.data(), scan_path_segments.size());
127-
BeamHeatSourceProperties beam(database);
128-
129-
GoldakHeatSource<3, dealii::MemorySpace::Host> goldak_heat_source(
130-
beam, ScanPath<dealii::MemorySpace::Host>(scan_paths_segments_view));
131-
ElectronBeamHeatSource<3, dealii::MemorySpace::Host> eb_heat_source(
132-
beam, ScanPath<dealii::MemorySpace::Host>(scan_paths_segments_view));
129+
auto [scan_paths_segments, eb_heat_source, goldak_heat_source] =
130+
create_heat_sources<3>("scan_path.txt");
133131

134132
double g_value = 0.0;
135133
double eb_value = 0.0;
@@ -188,26 +186,8 @@ BOOST_AUTO_TEST_CASE(heat_source_value_3d, *utf::tolerance(1e-12))
188186

189187
BOOST_AUTO_TEST_CASE(heat_source_height, *utf::tolerance(1e-12))
190188
{
191-
boost::property_tree::ptree database;
192-
193-
database.put("depth", 0.1);
194-
database.put("absorption_efficiency", 0.1);
195-
database.put("diameter", 1.0);
196-
database.put("max_power", 10.);
197-
database.put("scan_path_file", "scan_path_layers.txt");
198-
database.put("scan_path_file_format", "segment");
199-
std::vector<ScanPathSegment> scan_path_segments =
200-
ScanPath<dealii::MemorySpace::Host>::extract_scan_paths(
201-
database.get<std::string>("scan_path_file"),
202-
database.get<std::string>("scan_path_file_format"));
203-
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace> scan_paths_segments_view(
204-
scan_path_segments.data(), scan_path_segments.size());
205-
BeamHeatSourceProperties beam(database);
206-
207-
GoldakHeatSource<2, dealii::MemorySpace::Host> goldak_heat_source(
208-
beam, ScanPath<dealii::MemorySpace::Host>(scan_paths_segments_view));
209-
ElectronBeamHeatSource<2, dealii::MemorySpace::Host> eb_heat_source(
210-
beam, ScanPath<dealii::MemorySpace::Host>(scan_paths_segments_view));
189+
auto [scan_paths_segments, eb_heat_source, goldak_heat_source] =
190+
create_heat_sources<2>("scan_path_layers.txt");
211191

212192
double g_height = 0.0;
213193
double eb_height = 0.0;

tests/test_material_deposition.cc

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,25 @@ BOOST_AUTO_TEST_CASE(material_deposition)
351351
}
352352
}
353353

354-
BOOST_AUTO_TEST_CASE(deposition_from_scan_path_2d, *utf::tolerance(1e-13))
354+
std::pair<Kokkos::View<adamantine::ScanPathSegment *, Kokkos::HostSpace>,
355+
adamantine::ScanPath<dealii::MemorySpace::Host>>
356+
create_scan_path(std::string file_name)
355357
{
356358
std::vector<adamantine::ScanPathSegment> scan_path_segments =
357359
adamantine::ScanPath<dealii::MemorySpace::Host>::extract_scan_paths(
358-
"scan_path.txt", "segment");
360+
file_name, "segment");
359361
Kokkos::View<adamantine::ScanPathSegment *, Kokkos::HostSpace>
360-
scan_paths_segments_view(scan_path_segments.data(),
361-
scan_path_segments.size());
362-
adamantine::ScanPath<dealii::MemorySpace::Host> scan_path(
363-
scan_paths_segments_view);
362+
scan_path_segments_view("scan_path_segments", scan_path_segments.size());
363+
Kokkos::deep_copy(
364+
scan_path_segments_view,
365+
Kokkos::View<adamantine::ScanPathSegment *, Kokkos::HostSpace>{
366+
scan_path_segments.data(), scan_path_segments.size()});
367+
return {scan_path_segments_view, {scan_path_segments_view}};
368+
}
369+
370+
BOOST_AUTO_TEST_CASE(deposition_from_scan_path_2d, *utf::tolerance(1e-13))
371+
{
372+
auto [scan_path_segments, scan_path] = create_scan_path("scan_path.txt");
364373

365374
boost::property_tree::ptree database;
366375
database.put("deposition_length", 0.0005);
@@ -408,14 +417,7 @@ BOOST_AUTO_TEST_CASE(deposition_from_scan_path_2d, *utf::tolerance(1e-13))
408417

409418
BOOST_AUTO_TEST_CASE(deposition_from_scan_path_3d, *utf::tolerance(1e-13))
410419
{
411-
std::vector<adamantine::ScanPathSegment> scan_path_segments =
412-
adamantine::ScanPath<dealii::MemorySpace::Host>::extract_scan_paths(
413-
"scan_path.txt", "segment");
414-
Kokkos::View<adamantine::ScanPathSegment *, Kokkos::HostSpace>
415-
scan_paths_segments_view(scan_path_segments.data(),
416-
scan_path_segments.size());
417-
adamantine::ScanPath<dealii::MemorySpace::Host> scan_path(
418-
scan_paths_segments_view);
420+
auto [scan_path_segments, scan_path] = create_scan_path("scan_path.txt");
419421

420422
boost::property_tree::ptree database;
421423
database.put("deposition_length", 0.0005);
@@ -467,14 +469,7 @@ BOOST_AUTO_TEST_CASE(deposition_from_scan_path_3d, *utf::tolerance(1e-13))
467469

468470
BOOST_AUTO_TEST_CASE(deposition_from_L_scan_path_3d, *utf::tolerance(1e-13))
469471
{
470-
std::vector<adamantine::ScanPathSegment> scan_path_segments =
471-
adamantine::ScanPath<dealii::MemorySpace::Host>::extract_scan_paths(
472-
"scan_path_L.txt", "segment");
473-
Kokkos::View<adamantine::ScanPathSegment *, Kokkos::HostSpace>
474-
scan_paths_segments_view(scan_path_segments.data(),
475-
scan_path_segments.size());
476-
adamantine::ScanPath<dealii::MemorySpace::Host> scan_path(
477-
scan_paths_segments_view);
472+
auto [scan_path_segments, scan_path] = create_scan_path("scan_path_L.txt");
478473

479474
boost::property_tree::ptree database;
480475
database.put("deposition_length", 0.0005);
@@ -560,14 +555,8 @@ BOOST_AUTO_TEST_CASE(deposition_from_L_scan_path_3d, *utf::tolerance(1e-13))
560555
BOOST_AUTO_TEST_CASE(deposition_from_diagonal_scan_path_3d,
561556
*utf::tolerance(1e-10))
562557
{
563-
std::vector<adamantine::ScanPathSegment> scan_path_segments =
564-
adamantine::ScanPath<dealii::MemorySpace::Host>::extract_scan_paths(
565-
"scan_path_diagonal.txt", "segment");
566-
Kokkos::View<adamantine::ScanPathSegment *, Kokkos::HostSpace>
567-
scan_paths_segments_view(scan_path_segments.data(),
568-
scan_path_segments.size());
569-
adamantine::ScanPath<dealii::MemorySpace::Host> scan_path(
570-
scan_paths_segments_view);
558+
auto [scan_path_segments, scan_path] =
559+
create_scan_path("scan_path_diagonal.txt");
571560

572561
boost::property_tree::ptree database;
573562
database.put("deposition_length", 0.0005);

0 commit comments

Comments
 (0)