Skip to content

Commit b467051

Browse files
committed
Introduce update_scan_paths
1 parent 0025d0f commit b467051

File tree

8 files changed

+121
-81
lines changed

8 files changed

+121
-81
lines changed

application/adamantine.hh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,10 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
775775
heat_sources = thermal_physics->get_heat_sources();
776776
// Store the current end time of each heat source and set a flag that the
777777
// scan path has changed
778-
for (auto const &source : heat_sources)
778+
auto const& scan_paths = heat_sources.get_scan_paths();
779+
for (auto const &scan_path : scan_paths)
779780
{
780-
scan_path_end.emplace_back(
781-
source->get_scan_path().get_segment_list().back().end_time, true);
781+
scan_path_end.emplace_back(scan_path.get_segment_list().back().end_time, true);
782782
}
783783
post_processor_database.put("thermal_output", true);
784784
}
@@ -1026,14 +1026,15 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
10261026
}
10271027
if (scan_path_updated)
10281028
{
1029+
adamantine::HeatSources<dim, dealii::MemorySpace::Host> host_heat_sources = heat_sources.copy_to(dealii::MemorySpace::Host{});
1030+
host_heat_sources.update_scan_paths();
1031+
heat_sources = host_heat_sources.copy_to(MemorySpaceType{});
1032+
1033+
auto const& scan_paths = heat_sources.get_scan_paths();
10291034
for (unsigned int s = 0; s < scan_path_end.size(); ++s)
10301035
{
1031-
// Read the scan path file
1032-
heat_sources[s]->get_scan_path().read_file();
1033-
10341036
// Update scan_path_end
1035-
double new_end_time = heat_sources[s]
1036-
->get_scan_path()
1037+
double new_end_time = scan_paths[s]
10371038
.get_segment_list()
10381039
.back()
10391040
.end_time;
@@ -1044,7 +1045,7 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
10441045
std::tie(material_deposition_boxes, deposition_times, deposition_cos,
10451046
deposition_sin) =
10461047
adamantine::create_material_deposition_boxes<dim>(geometry_database,
1047-
heat_sources);
1048+
host_heat_sources);
10481049
}
10491050

10501051
auto activation_start =

source/DataAssimilator.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <deal.II/fe/mapping_q1_eulerian.h>
1515
#include <deal.II/lac/full_matrix.h>
1616
#include <deal.II/lac/la_parallel_block_vector.h>
17-
#include <deal.II/lac/la_vector.h>
1817
#include <deal.II/lac/solver_gmres.h>
1918
#include <deal.II/lac/sparse_matrix.h>
2019
#include <deal.II/lac/trilinos_sparse_matrix.h>

source/ElectronBeamHeatSource.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public:
5353
*/
5454
ScanPath<MemorySpaceType> const &get_scan_path() const;
5555

56+
void set_scan_path(ScanPath<MemorySpaceType> const scan_path)
57+
{
58+
_scan_path = scan_path;
59+
}
60+
5661
/**
5762
* Compute the current height of the where the heat source meets the material
5863
* (i.e. the current scan path height).

source/GoldakHeatSource.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public:
5353
*/
5454
ScanPath<MemorySpaceType> const &get_scan_path() const;
5555

56+
void set_scan_path(ScanPath<MemorySpaceType> const scan_path)
57+
{
58+
_scan_path = scan_path;
59+
}
60+
5661
/**
5762
* Compute the current height of the where the heat source meets the material
5863
* (i.e. the current scan path height).

source/HeatSources.hh

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public:
4343
*/
4444
void update_time(double time);
4545

46+
/**
47+
* Update the scan paths for all heat sources reading again from the
48+
* respective files.
49+
*/
50+
template <typename Dummy = MemorySpaceType>
51+
std::enable_if_t<std::is_same_v<Dummy, dealii::MemorySpace::Host>>
52+
update_scan_paths();
53+
4654
/**
4755
* Compute the cumulative heat source at a given point at a given time given
4856
* the current height of the object being manufactured.
@@ -77,6 +85,11 @@ private:
7785
friend class HeatSources<dim, dealii::MemorySpace::Default>;
7886
friend class HeatSources<dim, dealii::MemorySpace::Host>;
7987

88+
/**
89+
* Private helper for update_scan_paths
90+
*/
91+
void internal_update_scan_paths();
92+
8093
/**
8194
* Private constructor used by copy_to_host.
8295
*/
@@ -117,17 +130,70 @@ private:
117130
std::vector<int> _electron_beam_indices;
118131
std::vector<int> _cube_indices;
119132
std::vector<int> _goldak_indices;
133+
134+
std::vector<std::string> _goldak_scan_files;
135+
std::vector<std::string> _electron_beam_scan_files;
136+
std::vector<std::string> _goldak_scan_formats;
137+
std::vector<std::string> _electron_beam_scan_formats;
120138
};
121139

140+
template <int dim, typename MemorySpaceType>
141+
void HeatSources<dim, MemorySpaceType>::internal_update_scan_paths()
142+
{
143+
std::vector<ScanPathSegment> scan_path_segments;
144+
_goldak_scan_path_segments.clear();
145+
for (unsigned int i = 0; i < _goldak_indices.size(); ++i)
146+
{
147+
scan_path_segments = ScanPath<MemorySpaceType>::extract_scan_paths(
148+
_goldak_scan_files[i], _goldak_scan_formats[i]);
149+
_goldak_scan_path_segments.emplace_back(
150+
Kokkos::view_alloc(Kokkos::WithoutInitializing,
151+
"goldak_scan_path_segments_" + std::to_string(i)),
152+
scan_path_segments.size());
153+
Kokkos::deep_copy(
154+
_goldak_scan_path_segments.back(),
155+
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace>(
156+
scan_path_segments.data(), scan_path_segments.size()));
157+
}
158+
_electron_beam_scan_path_segments.clear();
159+
for (unsigned int i = 0; i < _electron_beam_indices.size(); ++i)
160+
{
161+
scan_path_segments = ScanPath<MemorySpaceType>::extract_scan_paths(
162+
_electron_beam_scan_files[i], _electron_beam_scan_formats[i]);
163+
_electron_beam_scan_path_segments.emplace_back(
164+
Kokkos::view_alloc(Kokkos::WithoutInitializing,
165+
"electron_beam_scan_path_segments_" +
166+
std::to_string(i)),
167+
scan_path_segments.size());
168+
Kokkos::deep_copy(
169+
_electron_beam_scan_path_segments.back(),
170+
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace>(
171+
scan_path_segments.data(), scan_path_segments.size()));
172+
}
173+
}
174+
175+
template <int dim, typename MemorySpaceType>
176+
template <typename Dummy>
177+
std::enable_if_t<std::is_same_v<Dummy, dealii::MemorySpace::Host>>
178+
HeatSources<dim, MemorySpaceType>::update_scan_paths()
179+
{
180+
internal_update_scan_paths();
181+
182+
for (unsigned int i = 0; i < _goldak_heat_sources.size(); ++i)
183+
_goldak_heat_sources(i).set_scan_path(
184+
ScanPath<MemorySpaceType>{_goldak_scan_path_segments[i]});
185+
for (unsigned int i = 0; i < _electron_beam_heat_sources.size(); ++i)
186+
_electron_beam_heat_sources(i).set_scan_path(
187+
ScanPath<MemorySpaceType>{_electron_beam_scan_path_segments[i]});
188+
}
189+
122190
template <int dim, typename MemorySpaceType>
123191
HeatSources<dim, MemorySpaceType>::HeatSources(
124192
boost::property_tree::ptree const &source_database)
125193
{
126194
unsigned int const n_beams = source_database.get<unsigned int>("n_beams");
127195
std::vector<BeamHeatSourceProperties> goldak_beams;
128196
std::vector<BeamHeatSourceProperties> electron_beam_beams;
129-
std::vector<std::vector<ScanPathSegment>> goldak_scan_path_segments;
130-
std::vector<std::vector<ScanPathSegment>> electron_beam_scan_path_segments;
131197
std::vector<CubeHeatSource<dim>> cube_heat_sources;
132198

133199
for (unsigned int i = 0; i < n_beams; ++i)
@@ -138,20 +204,20 @@ HeatSources<dim, MemorySpaceType>::HeatSources(
138204
if (type == "goldak")
139205
{
140206
goldak_beams.emplace_back(beam_database);
141-
goldak_scan_path_segments.push_back(
142-
ScanPath<MemorySpaceType>::extract_scan_paths(
143-
beam_database.get<std::string>("scan_path_file"),
144-
beam_database.get<std::string>("scan_path_file_format")));
145207
_goldak_indices.push_back(i);
208+
_goldak_scan_files.push_back(
209+
beam_database.get<std::string>("scan_path_file"));
210+
_goldak_scan_formats.push_back(
211+
beam_database.get<std::string>("scan_path_file_format"));
146212
}
147213
else if (type == "electron_beam")
148214
{
149215
electron_beam_beams.emplace_back(beam_database);
150-
electron_beam_scan_path_segments.push_back(
151-
ScanPath<MemorySpaceType>::extract_scan_paths(
152-
beam_database.get<std::string>("scan_path_file"),
153-
beam_database.get<std::string>("scan_path_file_format")));
154216
_electron_beam_indices.push_back(i);
217+
_electron_beam_scan_files.push_back(
218+
beam_database.get<std::string>("scan_path_file"));
219+
_electron_beam_scan_formats.push_back(
220+
beam_database.get<std::string>("scan_path_file_format"));
155221
}
156222
else if (type == "cube")
157223
{
@@ -166,35 +232,20 @@ HeatSources<dim, MemorySpaceType>::HeatSources(
166232
}
167233
}
168234

235+
internal_update_scan_paths();
236+
169237
std::vector<GoldakHeatSource<dim, MemorySpaceType>> goldak_heat_sources;
170-
for (unsigned int i = 0; i < goldak_scan_path_segments.size(); ++i)
238+
for (unsigned int i = 0; i < goldak_beams.size(); ++i)
171239
{
172-
_goldak_scan_path_segments.emplace_back(
173-
Kokkos::view_alloc(Kokkos::WithoutInitializing,
174-
"goldak_scan_path_segments_" + std::to_string(i)),
175-
goldak_scan_path_segments[i].size());
176-
Kokkos::deep_copy(_goldak_scan_path_segments.back(),
177-
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace>(
178-
goldak_scan_path_segments[i].data(),
179-
goldak_scan_path_segments[i].size()));
180240
goldak_heat_sources.emplace_back(
181241
goldak_beams[i],
182242
ScanPath<MemorySpaceType>(_goldak_scan_path_segments.back()));
183243
}
184244

185245
std::vector<ElectronBeamHeatSource<dim, MemorySpaceType>>
186246
electron_beam_heat_sources;
187-
for (unsigned int i = 0; i < electron_beam_scan_path_segments.size(); ++i)
247+
for (unsigned int i = 0; i < electron_beam_beams.size(); ++i)
188248
{
189-
_electron_beam_scan_path_segments.emplace_back(
190-
Kokkos::view_alloc(Kokkos::WithoutInitializing,
191-
"electron_beam_scan_path_segments_" +
192-
std::to_string(i)),
193-
electron_beam_scan_path_segments[i].size());
194-
Kokkos::deep_copy(_electron_beam_scan_path_segments.back(),
195-
Kokkos::View<ScanPathSegment *, Kokkos::HostSpace>(
196-
electron_beam_scan_path_segments[i].data(),
197-
electron_beam_scan_path_segments[i].size()));
198249
electron_beam_heat_sources.emplace_back(
199250
electron_beam_beams[i],
200251
ScanPath<MemorySpaceType>(_electron_beam_scan_path_segments.back()));

source/MaterialProperty.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <deal.II/fe/fe_dgq.h>
2323
#include <deal.II/grid/filtered_iterator.h>
2424
#include <deal.II/lac/la_parallel_vector.h>
25-
#include <deal.II/lac/la_vector.h>
2625

2726
#include <boost/property_tree/ptree.hpp>
2827

source/ScanPath.cc

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <utils.hh>
1010

1111
#include <deal.II/base/memory_space.h>
12+
1213
#include <boost/algorithm/string.hpp>
1314

1415
#include <fstream>
@@ -21,36 +22,31 @@ std::vector<ScanPathSegment>
2122
ScanPath<MemorySpaceType>::extract_scan_paths(std::string scan_path_file,
2223
std::string file_format)
2324
{
24-
ASSERT_THROW((_file_format == "segment") || (_file_format == "event_series"),
25+
ASSERT_THROW((file_format == "segment") || (file_format == "event_series"),
2526
"Error: Format of scan path file not recognized.");
2627

27-
wait_for_file(_scan_path_file,
28-
"Waiting for scan path file: " + _scan_path_file);
29-
30-
read_file();
31-
}
28+
wait_for_file(scan_path_file,
29+
"Waiting for scan path file: " + scan_path_file);
3230

33-
void ScanPath::read_file()
34-
{
35-
if (_file_format == "segment")
31+
if (file_format == "segment")
3632
{
37-
load_segment_scan_path(scan_path_file);
33+
return load_segment_scan_path(scan_path_file);
3834
}
3935
else
4036
{
41-
load_event_series_scan_path();
37+
return load_event_series_scan_path(scan_path_file);
4238
}
4339

4440
return {};
4541
}
4642

4743
template <typename MemorySpaceType>
4844
std::vector<ScanPathSegment>
49-
ScanPath<MemorySpaceType>::load_segment_scan_path()
45+
ScanPath<MemorySpaceType>::load_segment_scan_path(std::string scan_path_file)
5046
{
51-
_segment_list.clear();
47+
std::vector<ScanPathSegment> segment_list;
5248
std::ifstream file;
53-
file.open(_scan_path_file);
49+
file.open(scan_path_file);
5450
std::string line;
5551
unsigned int data_index = 0;
5652
// Skip first line
@@ -127,11 +123,12 @@ ScanPath<MemorySpaceType>::load_segment_scan_path()
127123

128124
template <typename MemorySpaceType>
129125
std::vector<ScanPathSegment>
130-
ScanPath<MemorySpaceType>::load_event_series_scan_path()
126+
ScanPath<MemorySpaceType>::load_event_series_scan_path(
127+
std::string scan_path_file)
131128
{
132-
_segment_list.clear();
129+
std::vector<ScanPathSegment> segment_list;
133130
std::ifstream file;
134-
file.open(_scan_path_file);
131+
file.open(scan_path_file);
135132
std::string line;
136133

137134
double last_power = 0.0;

source/ScanPath.hh

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2016 - 2024, the adamantine authors.
2-
*
2+
*
33
* This file is subject to the Modified BSD License and may not be distributed
44
* without copyright and license information. Please refer to the file LICENSE
55
* for the text and further information on this license.
@@ -65,11 +65,11 @@ public:
6565
*/
6666
ScanPath() = default;
6767

68-
ScanPath(
68+
KOKKOS_FUNCTION ScanPath(
6969
Kokkos::View<ScanPathSegment *, typename MemorySpaceType::kokkos_space,
7070
Kokkos::MemoryTraits<Kokkos::Unmanaged>>
7171
scan_path_segments)
72-
: _segment_list(scan_path_segments)
72+
: _segment_list(scan_path_segments.data(), scan_path_segments.size())
7373
{
7474
}
7575

@@ -98,18 +98,6 @@ public:
9898
void read_file();
9999

100100
private:
101-
/**
102-
* The list of information about each segment in the scan path.
103-
*/
104-
Kokkos::View<ScanPathSegment *, typename MemorySpaceType::kokkos_space,
105-
Kokkos::MemoryTraits<Kokkos::Unmanaged>>
106-
_segment_list;
107-
108-
/**
109-
* The index of the current segment in the scan path.
110-
*/
111-
mutable unsigned int _current_segment = 0;
112-
113101
/**
114102
* Method to load a "segment" scan path file
115103
*/
@@ -129,18 +117,13 @@ private:
129117
dealii::Point<3> &segment_start_point,
130118
double &segment_start_time) const;
131119

132-
/**
133-
* File name of the scan path
134-
*/
135-
std::string _scan_path_file;
136-
/**
137-
* Format of the scan path file, either segment of event_series.
138-
*/
139-
std::string _file_format;
140120
/**
141121
* The list of information about each segment in the scan path.
142122
*/
143-
std::vector<ScanPathSegment> _segment_list;
123+
Kokkos::View<ScanPathSegment *, typename MemorySpaceType::kokkos_space,
124+
Kokkos::MemoryTraits<Kokkos::Unmanaged>>
125+
_segment_list;
126+
144127
/**
145128
* The index of the current segment in the scan path.
146129
*/

0 commit comments

Comments
 (0)