Skip to content

Commit d1ce403

Browse files
committed
Hoist ScanPath out of HeatSource
1 parent 63407f7 commit d1ce403

13 files changed

+168
-84
lines changed

source/CubeHeatSource.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ CubeHeatSource<dim>::CubeHeatSource(boost::property_tree::ptree const &database)
3030
}
3131

3232
template <int dim>
33-
void CubeHeatSource<dim>::update_time(double time)
33+
void CubeHeatSource<dim>::update_time(double time,
34+
const ScanPath & /*scan_path*/)
3435
{
3536
_source_on = ((time > _start_time) && (time < _end_time));
3637
}
@@ -59,7 +60,9 @@ double CubeHeatSource<dim>::value(dealii::Point<dim> const &point,
5960
}
6061

6162
template <int dim>
62-
double CubeHeatSource<dim>::get_current_height(double const /*time*/) const
63+
double
64+
CubeHeatSource<dim>::get_current_height(double const /*time*/,
65+
const ScanPath & /*scan_path*/) const
6366
{
6467
return _max_point[axis<dim>::z];
6568
}

source/CubeHeatSource.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public:
3838
/**
3939
* Set the time variable.
4040
*/
41-
void update_time(double time) final;
41+
void update_time(double time, const ScanPath &scan_path) final;
4242

4343
/**
4444
* Return the value of the source for a given point and time.
@@ -49,7 +49,8 @@ public:
4949
* Compute the current height of the where the heat source meets the material
5050
* (i.e. the current scan path height).
5151
*/
52-
double get_current_height(double const time) const final;
52+
double get_current_height(double const time,
53+
const ScanPath &scan_path) const final;
5354

5455
private:
5556
bool _source_on = false;

source/ElectronBeamHeatSource.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ ElectronBeamHeatSource<dim>::ElectronBeamHeatSource(
2020
}
2121

2222
template <int dim>
23-
void ElectronBeamHeatSource<dim>::update_time(double time)
23+
void ElectronBeamHeatSource<dim>::update_time(double time,
24+
const ScanPath &scan_path)
2425
{
2526
static const double log_01 = std::log(0.1);
26-
_beam_center = this->_scan_path.value(time);
27-
double segment_power_modifier = this->_scan_path.get_power_modifier(time);
27+
_beam_center = scan_path.value(time);
28+
double segment_power_modifier = scan_path.get_power_modifier(time);
2829
_alpha =
2930
-this->_beam.absorption_efficiency * this->_beam.max_power *
3031
segment_power_modifier * log_01 /

source/ElectronBeamHeatSource.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public:
3636
/**
3737
* Set the time variable.
3838
*/
39-
void update_time(double time) final;
39+
void update_time(double time, const ScanPath &scan_path) final;
4040

4141
/**
4242
* Returns the value of an electron beam heat source at a specified point and

source/GoldakHeatSource.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ GoldakHeatSource<dim>::GoldakHeatSource(
2020
}
2121

2222
template <int dim>
23-
void GoldakHeatSource<dim>::update_time(double time)
23+
void GoldakHeatSource<dim>::update_time(double time, const ScanPath &scan_path)
2424
{
2525
static const double _pi_over_3_to_1p5 =
2626
std::pow(dealii::numbers::PI / 3.0, 1.5);
2727

28-
_beam_center = this->_scan_path.value(time);
29-
double segment_power_modifier = this->_scan_path.get_power_modifier(time);
28+
_beam_center = scan_path.value(time);
29+
double segment_power_modifier = scan_path.get_power_modifier(time);
3030
_alpha = 2.0 * this->_beam.absorption_efficiency * this->_beam.max_power *
3131
segment_power_modifier /
3232
(this->_beam.radius_squared * this->_beam.depth * _pi_over_3_to_1p5);

source/GoldakHeatSource.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public:
3636
/**
3737
* Set the time variable.
3838
*/
39-
void update_time(double time) final;
39+
void update_time(double time, const ScanPath &scan_path) final;
4040

4141
/**
4242
* Returns the value of a Goldak heat source at a specified point and

source/HeatSource.hh

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,7 @@ public:
4949
* - <B>input_file</B>: name of the file that contains the scan path
5050
* segments
5151
*/
52-
HeatSource(boost::property_tree::ptree const &database)
53-
: _beam(database),
54-
// PropertyTreeInput sources.beam_X.scan_path_file
55-
// PropertyTreeInput sources.beam_X.scan_path_format
56-
_scan_path(database.get<std::string>("scan_path_file"),
57-
database.get<std::string>("scan_path_file_format"))
58-
{
59-
}
52+
HeatSource(boost::property_tree::ptree const &database) : _beam(database) {}
6053

6154
/**
6255
* Destructor.
@@ -66,24 +59,21 @@ public:
6659
/**
6760
* Set the time variable.
6861
*/
69-
virtual void update_time(double time) = 0;
62+
virtual void update_time(double time, const ScanPath &scan_path) = 0;
7063

7164
/**
7265
* Compute the heat source at a given point at a given time given the current
7366
* height of the object being manufactured.
7467
*/
7568
virtual double value(dealii::Point<dim> const &point,
7669
double const height) const = 0;
77-
/**
78-
* Return the scan path for the heat source.
79-
*/
80-
virtual ScanPath const &get_scan_path() const;
8170

8271
/**
8372
* Compute the current height of the where the heat source meets the material
8473
* (i.e. the current scan path height).
8574
*/
86-
virtual double get_current_height(double const time) const;
75+
virtual double get_current_height(double const time,
76+
const ScanPath &scan_path) const;
8777

8878
/**
8979
* (Re)sets the BeamHeatSourceProperties member variable, necessary if the
@@ -96,23 +86,14 @@ protected:
9686
* Structure of the physical properties of the beam heat source.
9787
*/
9888
BeamHeatSourceProperties _beam;
99-
100-
/**
101-
* The scan path for the heat source.
102-
*/
103-
ScanPath _scan_path;
10489
};
10590

10691
template <int dim>
107-
inline ScanPath const &HeatSource<dim>::get_scan_path() const
108-
{
109-
return _scan_path;
110-
}
111-
112-
template <int dim>
113-
inline double HeatSource<dim>::get_current_height(double const time) const
92+
inline double
93+
HeatSource<dim>::get_current_height(double const time,
94+
const ScanPath &scan_path) const
11495
{
115-
return _scan_path.value(time)[2];
96+
return scan_path.value(time)[2];
11697
}
11798

11899
template <int dim>

source/HeatSources.hh

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ public:
3838
Kokkos::View<CubeHeatSource<dim> *, typename MemorySpace::kokkos_space>
3939
cube_heat_sources,
4040
Kokkos::View<GoldakHeatSource<dim> *, typename MemorySpace::kokkos_space>
41-
goldak_heat_sources)
41+
goldak_heat_sources,
42+
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
43+
electron_beam_scan_paths,
44+
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
45+
cube_scan_paths,
46+
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
47+
goldak_scan_paths)
4248
: _electron_beam_heat_sources(electron_beam_heat_sources),
4349
_cube_heat_sources(cube_heat_sources),
44-
_goldak_heat_sources(goldak_heat_sources)
50+
_goldak_heat_sources(goldak_heat_sources),
51+
_electron_beam_scan_paths(electron_beam_scan_paths),
52+
_cube_scan_paths(cube_scan_paths), _goldak_scan_paths(goldak_scan_paths)
4553
{
4654
}
4755

@@ -52,7 +60,13 @@ public:
5260
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
5361
_cube_heat_sources),
5462
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
55-
_goldak_heat_sources)};
63+
_goldak_heat_sources),
64+
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
65+
_electron_beam_scan_paths),
66+
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
67+
_cube_scan_paths),
68+
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
69+
_goldak_scan_paths)};
5670
}
5771

5872
/**
@@ -100,6 +114,11 @@ private:
100114
_cube_heat_sources;
101115
Kokkos::View<GoldakHeatSource<dim> *, typename MemorySpace::kokkos_space>
102116
_goldak_heat_sources;
117+
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
118+
_electron_beam_scan_paths;
119+
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space> _cube_scan_paths;
120+
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
121+
_goldak_scan_paths;
103122
};
104123

105124
template <typename MemorySpace, int dim>
@@ -108,23 +127,31 @@ HeatSources<MemorySpace, dim>::HeatSources(
108127
{
109128
unsigned int const n_beams = source_database.get<unsigned int>("n_beams");
110129
std::vector<ElectronBeamHeatSource<dim>> electron_beam_heat_sources;
130+
std::vector<ScanPath> electron_beam_scan_paths;
111131
std::vector<CubeHeatSource<dim>> cube_heat_sources;
132+
std::vector<ScanPath> cube_scan_paths;
112133
std::vector<GoldakHeatSource<dim>> goldak_heat_sources;
134+
std::vector<ScanPath> goldak_scan_paths;
113135
for (unsigned int i = 0; i < n_beams; ++i)
114136
{
115137
boost::property_tree::ptree const &beam_database =
116138
source_database.get_child("beam_" + std::to_string(i));
117139
std::string type = beam_database.get<std::string>("type");
140+
ScanPath scan_path(beam_database.get<std::string>("scan_path_file"),
141+
beam_database.get<std::string>("scan_path_file_format"));
118142
if (type == "goldak")
119143
{
144+
goldak_scan_paths.push_back(std::move(scan_path));
120145
goldak_heat_sources.emplace_back(beam_database);
121146
}
122147
else if (type == "electron_beam")
123148
{
149+
electron_beam_scan_paths.push_back(std::move(scan_path));
124150
electron_beam_heat_sources.emplace_back(beam_database);
125151
}
126152
else if (type == "cube")
127153
{
154+
cube_scan_paths.push_back(std::move(scan_path));
128155
cube_heat_sources.emplace_back(beam_database);
129156
}
130157
else
@@ -156,17 +183,39 @@ HeatSources<MemorySpace, dim>::HeatSources(
156183
Kokkos::deep_copy(_cube_heat_sources,
157184
Kokkos::View<CubeHeatSource<dim> *, Kokkos::HostSpace>(
158185
cube_heat_sources.data(), cube_heat_sources.size()));
186+
187+
_goldak_scan_paths = decltype(_goldak_scan_paths)(
188+
Kokkos::view_alloc(Kokkos::WithoutInitializing, "goldak_scan_paths"),
189+
goldak_scan_paths.size());
190+
_electron_beam_scan_paths = decltype(_electron_beam_scan_paths)(
191+
Kokkos::view_alloc(Kokkos::WithoutInitializing,
192+
"electron_beam_scan_paths"),
193+
electron_beam_scan_paths.size());
194+
_cube_scan_paths = decltype(_cube_scan_paths)(
195+
Kokkos::view_alloc(Kokkos::WithoutInitializing, "cube_scan_paths"),
196+
cube_scan_paths.size());
197+
Kokkos::deep_copy(_goldak_scan_paths,
198+
Kokkos::View<ScanPath *, Kokkos::HostSpace>(
199+
goldak_scan_paths.data(), goldak_scan_paths.size()));
200+
Kokkos::deep_copy(
201+
_electron_beam_scan_paths,
202+
Kokkos::View<ScanPath *, Kokkos::HostSpace>(
203+
electron_beam_scan_paths.data(), electron_beam_scan_paths.size()));
204+
Kokkos::deep_copy(_cube_scan_paths,
205+
Kokkos::View<ScanPath *, Kokkos::HostSpace>(
206+
cube_scan_paths.data(), cube_scan_paths.size()));
159207
}
160208

161209
template <typename MemorySpace, int dim>
162210
KOKKOS_FUNCTION void HeatSources<MemorySpace, dim>::update_time(double time)
163211
{
164212
for (unsigned int i = 0; i < _electron_beam_heat_sources.size(); ++i)
165-
_electron_beam_heat_sources(i).update_time(time);
213+
_electron_beam_heat_sources(i).update_time(time,
214+
_electron_beam_scan_paths(i));
166215
for (unsigned int i = 0; i < _cube_heat_sources.size(); ++i)
167-
_cube_heat_sources(i).update_time(time);
216+
_cube_heat_sources(i).update_time(time, _cube_scan_paths(i));
168217
for (unsigned int i = 0; i < _goldak_heat_sources.size(); ++i)
169-
_goldak_heat_sources(i).update_time(time);
218+
_goldak_heat_sources(i).update_time(time, _goldak_scan_paths(i));
170219
}
171220

172221
template <typename MemorySpace, int dim>
@@ -204,12 +253,12 @@ template <typename MemorySpace, int dim>
204253
std::vector<ScanPath> HeatSources<MemorySpace, dim>::get_scan_paths() const
205254
{
206255
std::vector<ScanPath> scan_paths;
207-
for (unsigned int i = 0; i < _electron_beam_heat_sources.size(); ++i)
208-
scan_paths.push_back(_electron_beam_heat_sources(i).get_scan_path());
209-
for (unsigned int i = 0; i < _cube_heat_sources.size(); ++i)
210-
scan_paths.push_back(_cube_heat_sources(i).get_scan_path());
211-
for (unsigned int i = 0; i < _goldak_heat_sources.size(); ++i)
212-
scan_paths.push_back(_goldak_heat_sources(i).get_scan_path());
256+
for (unsigned int i = 0; i < _electron_beam_scan_paths.size(); ++i)
257+
scan_paths.push_back(_electron_beam_scan_paths(i));
258+
for (unsigned int i = 0; i < _cube_scan_paths.size(); ++i)
259+
scan_paths.push_back(_cube_scan_paths(i));
260+
for (unsigned int i = 0; i < _goldak_scan_paths.size(); ++i)
261+
scan_paths.push_back(_goldak_scan_paths(i));
213262
return scan_paths;
214263
}
215264

@@ -220,14 +269,17 @@ double HeatSources<MemorySpace, dim>::get_current_height(double time) const
220269
// unexpected behavior for different sources with different heights.
221270
double temp_height = std::numeric_limits<double>::lowest();
222271
for (unsigned int i = 0; i < _electron_beam_heat_sources.size(); ++i)
223-
temp_height = std::max(
224-
temp_height, _electron_beam_heat_sources(i).get_current_height(time));
225-
for (unsigned int i = 0; i < _cube_heat_sources.size(); ++i)
226272
temp_height =
227-
std::max(temp_height, _cube_heat_sources(i).get_current_height(time));
273+
std::max(temp_height, _electron_beam_heat_sources(i).get_current_height(
274+
time, _electron_beam_scan_paths(i)));
275+
for (unsigned int i = 0; i < _cube_heat_sources.size(); ++i)
276+
temp_height = std::max(
277+
temp_height,
278+
_cube_heat_sources(i).get_current_height(time, _cube_scan_paths(i)));
228279
for (unsigned int i = 0; i < _goldak_heat_sources.size(); ++i)
229280
temp_height =
230-
std::max(temp_height, _goldak_heat_sources(i).get_current_height(time));
281+
std::max(temp_height, _goldak_heat_sources(i).get_current_height(
282+
time, _goldak_scan_paths(i)));
231283
return temp_height;
232284
}
233285

0 commit comments

Comments
 (0)