Skip to content

Commit

Permalink
Hoist ScanPath out of HeatSource
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed May 7, 2024
1 parent 63407f7 commit d1ce403
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 84 deletions.
7 changes: 5 additions & 2 deletions source/CubeHeatSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ CubeHeatSource<dim>::CubeHeatSource(boost::property_tree::ptree const &database)
}

template <int dim>
void CubeHeatSource<dim>::update_time(double time)
void CubeHeatSource<dim>::update_time(double time,
const ScanPath & /*scan_path*/)
{
_source_on = ((time > _start_time) && (time < _end_time));
}
Expand Down Expand Up @@ -59,7 +60,9 @@ double CubeHeatSource<dim>::value(dealii::Point<dim> const &point,
}

template <int dim>
double CubeHeatSource<dim>::get_current_height(double const /*time*/) const
double
CubeHeatSource<dim>::get_current_height(double const /*time*/,
const ScanPath & /*scan_path*/) const
{
return _max_point[axis<dim>::z];
}
Expand Down
5 changes: 3 additions & 2 deletions source/CubeHeatSource.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public:
/**
* Set the time variable.
*/
void update_time(double time) final;
void update_time(double time, const ScanPath &scan_path) final;

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

private:
bool _source_on = false;
Expand Down
7 changes: 4 additions & 3 deletions source/ElectronBeamHeatSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ ElectronBeamHeatSource<dim>::ElectronBeamHeatSource(
}

template <int dim>
void ElectronBeamHeatSource<dim>::update_time(double time)
void ElectronBeamHeatSource<dim>::update_time(double time,
const ScanPath &scan_path)
{
static const double log_01 = std::log(0.1);
_beam_center = this->_scan_path.value(time);
double segment_power_modifier = this->_scan_path.get_power_modifier(time);
_beam_center = scan_path.value(time);
double segment_power_modifier = scan_path.get_power_modifier(time);
_alpha =
-this->_beam.absorption_efficiency * this->_beam.max_power *
segment_power_modifier * log_01 /
Expand Down
2 changes: 1 addition & 1 deletion source/ElectronBeamHeatSource.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public:
/**
* Set the time variable.
*/
void update_time(double time) final;
void update_time(double time, const ScanPath &scan_path) final;

/**
* Returns the value of an electron beam heat source at a specified point and
Expand Down
6 changes: 3 additions & 3 deletions source/GoldakHeatSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ GoldakHeatSource<dim>::GoldakHeatSource(
}

template <int dim>
void GoldakHeatSource<dim>::update_time(double time)
void GoldakHeatSource<dim>::update_time(double time, const ScanPath &scan_path)
{
static const double _pi_over_3_to_1p5 =
std::pow(dealii::numbers::PI / 3.0, 1.5);

_beam_center = this->_scan_path.value(time);
double segment_power_modifier = this->_scan_path.get_power_modifier(time);
_beam_center = scan_path.value(time);
double segment_power_modifier = scan_path.get_power_modifier(time);
_alpha = 2.0 * this->_beam.absorption_efficiency * this->_beam.max_power *
segment_power_modifier /
(this->_beam.radius_squared * this->_beam.depth * _pi_over_3_to_1p5);
Expand Down
2 changes: 1 addition & 1 deletion source/GoldakHeatSource.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public:
/**
* Set the time variable.
*/
void update_time(double time) final;
void update_time(double time, const ScanPath &scan_path) final;

/**
* Returns the value of a Goldak heat source at a specified point and
Expand Down
35 changes: 8 additions & 27 deletions source/HeatSource.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ public:
* - <B>input_file</B>: name of the file that contains the scan path
* segments
*/
HeatSource(boost::property_tree::ptree const &database)
: _beam(database),
// PropertyTreeInput sources.beam_X.scan_path_file
// PropertyTreeInput sources.beam_X.scan_path_format
_scan_path(database.get<std::string>("scan_path_file"),
database.get<std::string>("scan_path_file_format"))
{
}
HeatSource(boost::property_tree::ptree const &database) : _beam(database) {}

/**
* Destructor.
Expand All @@ -66,24 +59,21 @@ public:
/**
* Set the time variable.
*/
virtual void update_time(double time) = 0;
virtual void update_time(double time, const ScanPath &scan_path) = 0;

/**
* Compute the heat source at a given point at a given time given the current
* height of the object being manufactured.
*/
virtual double value(dealii::Point<dim> const &point,
double const height) const = 0;
/**
* Return the scan path for the heat source.
*/
virtual ScanPath const &get_scan_path() const;

/**
* Compute the current height of the where the heat source meets the material
* (i.e. the current scan path height).
*/
virtual double get_current_height(double const time) const;
virtual double get_current_height(double const time,
const ScanPath &scan_path) const;

/**
* (Re)sets the BeamHeatSourceProperties member variable, necessary if the
Expand All @@ -96,23 +86,14 @@ protected:
* Structure of the physical properties of the beam heat source.
*/
BeamHeatSourceProperties _beam;

/**
* The scan path for the heat source.
*/
ScanPath _scan_path;
};

template <int dim>
inline ScanPath const &HeatSource<dim>::get_scan_path() const
{
return _scan_path;
}

template <int dim>
inline double HeatSource<dim>::get_current_height(double const time) const
inline double
HeatSource<dim>::get_current_height(double const time,
const ScanPath &scan_path) const
{
return _scan_path.value(time)[2];
return scan_path.value(time)[2];
}

template <int dim>
Expand Down
86 changes: 69 additions & 17 deletions source/HeatSources.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ public:
Kokkos::View<CubeHeatSource<dim> *, typename MemorySpace::kokkos_space>
cube_heat_sources,
Kokkos::View<GoldakHeatSource<dim> *, typename MemorySpace::kokkos_space>
goldak_heat_sources)
goldak_heat_sources,
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
electron_beam_scan_paths,
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
cube_scan_paths,
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
goldak_scan_paths)
: _electron_beam_heat_sources(electron_beam_heat_sources),
_cube_heat_sources(cube_heat_sources),
_goldak_heat_sources(goldak_heat_sources)
_goldak_heat_sources(goldak_heat_sources),
_electron_beam_scan_paths(electron_beam_scan_paths),
_cube_scan_paths(cube_scan_paths), _goldak_scan_paths(goldak_scan_paths)
{
}

Expand All @@ -52,7 +60,13 @@ public:
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
_cube_heat_sources),
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
_goldak_heat_sources)};
_goldak_heat_sources),
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
_electron_beam_scan_paths),
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
_cube_scan_paths),
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{},
_goldak_scan_paths)};
}

/**
Expand Down Expand Up @@ -100,6 +114,11 @@ private:
_cube_heat_sources;
Kokkos::View<GoldakHeatSource<dim> *, typename MemorySpace::kokkos_space>
_goldak_heat_sources;
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
_electron_beam_scan_paths;
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space> _cube_scan_paths;
Kokkos::View<ScanPath *, typename MemorySpace::kokkos_space>
_goldak_scan_paths;
};

template <typename MemorySpace, int dim>
Expand All @@ -108,23 +127,31 @@ HeatSources<MemorySpace, dim>::HeatSources(
{
unsigned int const n_beams = source_database.get<unsigned int>("n_beams");
std::vector<ElectronBeamHeatSource<dim>> electron_beam_heat_sources;
std::vector<ScanPath> electron_beam_scan_paths;
std::vector<CubeHeatSource<dim>> cube_heat_sources;
std::vector<ScanPath> cube_scan_paths;
std::vector<GoldakHeatSource<dim>> goldak_heat_sources;
std::vector<ScanPath> goldak_scan_paths;
for (unsigned int i = 0; i < n_beams; ++i)
{
boost::property_tree::ptree const &beam_database =
source_database.get_child("beam_" + std::to_string(i));
std::string type = beam_database.get<std::string>("type");
ScanPath scan_path(beam_database.get<std::string>("scan_path_file"),
beam_database.get<std::string>("scan_path_file_format"));
if (type == "goldak")
{
goldak_scan_paths.push_back(std::move(scan_path));
goldak_heat_sources.emplace_back(beam_database);
}
else if (type == "electron_beam")
{
electron_beam_scan_paths.push_back(std::move(scan_path));
electron_beam_heat_sources.emplace_back(beam_database);
}
else if (type == "cube")
{
cube_scan_paths.push_back(std::move(scan_path));
cube_heat_sources.emplace_back(beam_database);
}
else
Expand Down Expand Up @@ -156,17 +183,39 @@ HeatSources<MemorySpace, dim>::HeatSources(
Kokkos::deep_copy(_cube_heat_sources,
Kokkos::View<CubeHeatSource<dim> *, Kokkos::HostSpace>(
cube_heat_sources.data(), cube_heat_sources.size()));

_goldak_scan_paths = decltype(_goldak_scan_paths)(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "goldak_scan_paths"),
goldak_scan_paths.size());
_electron_beam_scan_paths = decltype(_electron_beam_scan_paths)(
Kokkos::view_alloc(Kokkos::WithoutInitializing,
"electron_beam_scan_paths"),
electron_beam_scan_paths.size());
_cube_scan_paths = decltype(_cube_scan_paths)(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "cube_scan_paths"),
cube_scan_paths.size());
Kokkos::deep_copy(_goldak_scan_paths,
Kokkos::View<ScanPath *, Kokkos::HostSpace>(
goldak_scan_paths.data(), goldak_scan_paths.size()));
Kokkos::deep_copy(
_electron_beam_scan_paths,
Kokkos::View<ScanPath *, Kokkos::HostSpace>(
electron_beam_scan_paths.data(), electron_beam_scan_paths.size()));
Kokkos::deep_copy(_cube_scan_paths,
Kokkos::View<ScanPath *, Kokkos::HostSpace>(
cube_scan_paths.data(), cube_scan_paths.size()));
}

template <typename MemorySpace, int dim>
KOKKOS_FUNCTION void HeatSources<MemorySpace, dim>::update_time(double time)
{
for (unsigned int i = 0; i < _electron_beam_heat_sources.size(); ++i)
_electron_beam_heat_sources(i).update_time(time);
_electron_beam_heat_sources(i).update_time(time,
_electron_beam_scan_paths(i));
for (unsigned int i = 0; i < _cube_heat_sources.size(); ++i)
_cube_heat_sources(i).update_time(time);
_cube_heat_sources(i).update_time(time, _cube_scan_paths(i));
for (unsigned int i = 0; i < _goldak_heat_sources.size(); ++i)
_goldak_heat_sources(i).update_time(time);
_goldak_heat_sources(i).update_time(time, _goldak_scan_paths(i));
}

template <typename MemorySpace, int dim>
Expand Down Expand Up @@ -204,12 +253,12 @@ template <typename MemorySpace, int dim>
std::vector<ScanPath> HeatSources<MemorySpace, dim>::get_scan_paths() const
{
std::vector<ScanPath> scan_paths;
for (unsigned int i = 0; i < _electron_beam_heat_sources.size(); ++i)
scan_paths.push_back(_electron_beam_heat_sources(i).get_scan_path());
for (unsigned int i = 0; i < _cube_heat_sources.size(); ++i)
scan_paths.push_back(_cube_heat_sources(i).get_scan_path());
for (unsigned int i = 0; i < _goldak_heat_sources.size(); ++i)
scan_paths.push_back(_goldak_heat_sources(i).get_scan_path());
for (unsigned int i = 0; i < _electron_beam_scan_paths.size(); ++i)
scan_paths.push_back(_electron_beam_scan_paths(i));
for (unsigned int i = 0; i < _cube_scan_paths.size(); ++i)
scan_paths.push_back(_cube_scan_paths(i));
for (unsigned int i = 0; i < _goldak_scan_paths.size(); ++i)
scan_paths.push_back(_goldak_scan_paths(i));
return scan_paths;
}

Expand All @@ -220,14 +269,17 @@ double HeatSources<MemorySpace, dim>::get_current_height(double time) const
// unexpected behavior for different sources with different heights.
double temp_height = std::numeric_limits<double>::lowest();
for (unsigned int i = 0; i < _electron_beam_heat_sources.size(); ++i)
temp_height = std::max(
temp_height, _electron_beam_heat_sources(i).get_current_height(time));
for (unsigned int i = 0; i < _cube_heat_sources.size(); ++i)
temp_height =
std::max(temp_height, _cube_heat_sources(i).get_current_height(time));
std::max(temp_height, _electron_beam_heat_sources(i).get_current_height(
time, _electron_beam_scan_paths(i)));
for (unsigned int i = 0; i < _cube_heat_sources.size(); ++i)
temp_height = std::max(
temp_height,
_cube_heat_sources(i).get_current_height(time, _cube_scan_paths(i)));
for (unsigned int i = 0; i < _goldak_heat_sources.size(); ++i)
temp_height =
std::max(temp_height, _goldak_heat_sources(i).get_current_height(time));
std::max(temp_height, _goldak_heat_sources(i).get_current_height(
time, _goldak_scan_paths(i)));
return temp_height;
}

Expand Down

0 comments on commit d1ce403

Please sign in to comment.