Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce HeatSources #282

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8728e74
Introduce HeatSources
masterleinad May 3, 2024
7db8d9a
Update ScanPath implementation
masterleinad May 6, 2024
9e31ea3
Store ScanPathSegments outside of ScanPath
masterleinad May 7, 2024
5fdff90
Refactor HeatSources to store std::vectors of ScanPathSegments
masterleinad May 8, 2024
cf6263f
Remove HeatSource.hh
masterleinad May 10, 2024
4ec8fd0
Copy to host where necessary and fix copy_to_host
masterleinad May 10, 2024
432c229
Restructure HeatSources
masterleinad May 13, 2024
9e520b7
Add copy_to_device
masterleinad May 13, 2024
fce7f5c
Use correct heat source order in set_beam_properties
masterleinad May 14, 2024
9193862
Fix order of template parameters
masterleinad May 14, 2024
7b88824
Fix copy_to when targeting GPUs
masterleinad May 17, 2024
ac35083
Remove KOKKOS_FUNCTION from HeatSources.hh
masterleinad May 20, 2024
69394d1
Restore lac/la_vector.h
masterleinad May 20, 2024
0025d0f
Merge remote-tracking branch 'upstream/master' into introduce_heat_so…
masterleinad Jun 4, 2024
b467051
Introduce update_scan_paths
masterleinad Jun 6, 2024
583ab35
Remove max_value
masterleinad Jun 10, 2024
aef6051
host_heat_sources -> heat_sources_host
masterleinad Jun 10, 2024
3358d7f
Indent more filles
masterleinad Jun 10, 2024
647ee6f
Remove redundant include
masterleinad Jun 10, 2024
76ff0bf
Remove beam from cube heat source
masterleinad Jun 10, 2024
a788186
Remove redundant final
masterleinad Jun 10, 2024
87efdf7
Resets -> Reset
masterleinad Jun 10, 2024
dea04e4
Return BeamHeatSourceProperties by const&
masterleinad Jun 10, 2024
af4f181
Fix formatting
masterleinad Jun 10, 2024
a95bcb3
_pi_over_3_to_1p5 -> pi_over_3_to_1p5
masterleinad Jun 10, 2024
02a7600
Formatting
masterleinad Jun 10, 2024
ab3a2d5
Avoid duplications in tests
masterleinad Jun 11, 2024
24601c6
Fix running on GPUs
masterleinad Jun 11, 2024
044ad9f
extract_scan_paths->read_file
masterleinad Jun 25, 2024
a01cbc5
Store ScanPath on host
masterleinad Jul 11, 2024
6f13c95
Minimize changes
masterleinad Jul 16, 2024
1f5f784
Merge remote-tracking branch 'upstream/master' into introduce_heat_so…
masterleinad Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 26 additions & 47 deletions application/adamantine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ compute_cells_to_refine(
dealii::parallel::distributed::Triangulation<dim> &triangulation,
double const time, double const next_refinement_time,
unsigned int const n_time_steps,
std::vector<std::shared_ptr<adamantine::HeatSource<dim>>> &heat_sources,
adamantine::HeatSources<dim, dealii::MemorySpace::Host> &heat_sources,
double const current_source_height, double const refinement_beam_cutoff)
{

Expand All @@ -538,25 +538,22 @@ compute_cells_to_refine(
double const current_time = time + static_cast<double>(i) /
static_cast<double>(n_time_steps) *
(next_refinement_time - time);
for (auto &beam : heat_sources)
heat_sources.update_time(current_time);
for (auto cell :
dealii::filter_iterators(triangulation.active_cell_iterators(),
dealii::IteratorFilters::LocallyOwnedCell()))
{
beam->update_time(current_time);
for (auto cell : dealii::filter_iterators(
triangulation.active_cell_iterators(),
dealii::IteratorFilters::LocallyOwnedCell()))
// Check the value at the center of the cell faces. For most cases this
// should be sufficient, but if the beam is small compared to the
// coarsest mesh we may need to add other points to check (e.g.
// quadrature points, vertices).
for (unsigned int f = 0; f < cell->reference_cell().n_faces(); ++f)
{
// Check the value at the center of the cell faces. For most cases this
// should be sufficient, but if the beam is small compared to the
// coarsest mesh we may need to add other points to check (e.g.
// quadrature points, vertices).
for (unsigned int f = 0; f < cell->reference_cell().n_faces(); ++f)
if (heat_sources.value(cell->face(f)->center(), current_source_height) >
refinement_beam_cutoff)
{
if (beam->value(cell->face(f)->center(), current_source_height) >
refinement_beam_cutoff)
{
cells_to_refine.push_back(cell);
break;
}
cells_to_refine.push_back(cell);
break;
}
}
}
Expand All @@ -573,7 +570,7 @@ void refine_mesh(
adamantine::MaterialProperty<dim, p_order, MaterialStates, MemorySpaceType>
&material_properties,
dealii::LA::distributed::Vector<double, MemorySpaceType> &solution,
std::vector<std::shared_ptr<adamantine::HeatSource<dim>>> &heat_sources,
adamantine::HeatSources<dim, dealii::MemorySpace::Host> &heat_sources,
double const time, double const next_refinement_time,
unsigned int const time_steps_refinement,
boost::property_tree::ptree const &refinement_database)
Expand Down Expand Up @@ -662,7 +659,7 @@ void refine_mesh(
adamantine::MaterialProperty<dim, p_order, MaterialStates, MemorySpaceType>
&material_properties,
dealii::LA::distributed::Vector<double, MemorySpaceType> &solution,
std::vector<std::shared_ptr<adamantine::HeatSource<dim>>> &heat_sources,
adamantine::HeatSources<dim, dealii::MemorySpace::Host> &heat_sources,
double const time, double const next_refinement_time,
unsigned int const time_steps_refinement,
boost::property_tree::ptree const &refinement_database)
Expand Down Expand Up @@ -760,7 +757,7 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
// Create ThermalPhysics if necessary
std::unique_ptr<adamantine::ThermalPhysicsInterface<dim, MemorySpaceType>>
thermal_physics;
std::vector<std::shared_ptr<adamantine::HeatSource<dim>>> heat_sources;
adamantine::HeatSources<dim, dealii::MemorySpace::Host> heat_sources;
if (use_thermal_physics)
{
// PropertyTreeInput discretization.thermal.fe_degree
Expand Down Expand Up @@ -1011,9 +1008,10 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
{
// Check if we have reached the end of current scan path.
bool need_updated_scan_path = false;
for (auto &source : heat_sources)
auto const &scan_paths = heat_sources.get_scan_paths();
for (auto &scan_path : scan_paths)
{
if (time > source->get_scan_path().get_segment_list().back().end_time)
if (time > scan_path.get_segment_list().back().end_time)
{
need_updated_scan_path = true;
break;
Expand All @@ -1024,17 +1022,7 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
{
// Check if we have reached the end of the file. If not, read the
// updated scan path file
bool scan_path_end = true;
for (auto &source : heat_sources)
{
if (!source->get_scan_path().is_finished())
{
scan_path_end = false;
// This functions waits for the scan path file to be updated
// before reading the file.
source->get_scan_path().read_file();
}
}
bool scan_path_end = heat_sources.update_scan_paths();

// If we have reached the end of scan path file for all the heat
// sources, we just exit.
Expand Down Expand Up @@ -1416,7 +1404,7 @@ run_ensemble(MPI_Comm const &global_communicator,
adamantine::ThermalPhysicsInterface<dim, MemorySpaceType>>>
thermal_physics_ensemble(local_ensemble_size);

std::vector<std::vector<std::shared_ptr<adamantine::HeatSource<dim>>>>
std::vector<adamantine::HeatSources<dim, MemorySpaceType>>
heat_sources_ensemble(local_ensemble_size);

std::vector<std::unique_ptr<adamantine::Geometry<dim>>> geometry_ensemble;
Expand Down Expand Up @@ -1819,10 +1807,10 @@ run_ensemble(MPI_Comm const &global_communicator,
// Check if we have reached the end of current scan path.
bool need_updated_scan_path = false;
{
for (auto &source : heat_sources_ensemble[0])
auto const &scan_paths = heat_sources_ensemble[0].get_scan_paths();
for (auto &scan_path : scan_paths)
{
if (time >
source->get_scan_path().get_segment_list().back().end_time)
if (time > scan_path.get_segment_list().back().end_time)
{
need_updated_scan_path = true;
break;
Expand All @@ -1841,16 +1829,7 @@ run_ensemble(MPI_Comm const &global_communicator,
bool scan_path_end = true;
for (unsigned int member = 0; member < local_ensemble_size; ++member)
{
for (auto &source : heat_sources_ensemble[member])
{
if (!source->get_scan_path().is_finished())
{
scan_path_end = false;
// This functions waits for the scan path file to be updated
// before reading the file.
source->get_scan_path().read_file();
}
}
scan_path_end &= heat_sources_ensemble[member].update_scan_paths();
}

// If we have reached the end of scan path file for all the heat
Expand Down
1 change: 1 addition & 0 deletions indent
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ clang-format -style=file -i source/*.cc
clang-format -style=file -i source/*.hh
clang-format -style=file -i tests/*.cc
clang-format -style=file -i application/*.cc
clang-format -style=file -i application/*.hh
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(Adamantine_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/ExperimentalData.hh
${CMAKE_CURRENT_SOURCE_DIR}/Geometry.hh
${CMAKE_CURRENT_SOURCE_DIR}/GoldakHeatSource.hh
${CMAKE_CURRENT_SOURCE_DIR}/HeatSource.hh
${CMAKE_CURRENT_SOURCE_DIR}/HeatSources.hh
${CMAKE_CURRENT_SOURCE_DIR}/ImplicitOperator.hh
${CMAKE_CURRENT_SOURCE_DIR}/MaterialProperty.hh
${CMAKE_CURRENT_SOURCE_DIR}/MaterialProperty.templates.hh
Expand Down
1 change: 0 additions & 1 deletion source/CubeHeatSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace adamantine
{
template <int dim>
CubeHeatSource<dim>::CubeHeatSource(boost::property_tree::ptree const &database)
: HeatSource<dim>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the copyright date to 2024

{
_start_time = database.get<double>("start_time");
_end_time = database.get<double>("end_time");
Expand Down
15 changes: 9 additions & 6 deletions source/CubeHeatSource.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#ifndef CUBE_HEAT_SOURCE_HH
#define CUBE_HEAT_SOURCE_HH

#include <HeatSource.hh>
#include <BeamHeatSourceProperties.hh>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no beam here. It's just a static heat source.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be removed and the copyright date updated.


#include <deal.II/base/point.h>

namespace adamantine
{
Expand All @@ -17,7 +19,7 @@ namespace adamantine
* used for verification purpose.
*/
template <int dim>
class CubeHeatSource final : public HeatSource<dim>
class CubeHeatSource
{
public:
/**
Expand All @@ -38,18 +40,17 @@ public:
/**
* Set the time variable.
*/
void update_time(double time) final;
void update_time(double time);

/**
* Return the value of the source for a given point and time.
*/
double value(dealii::Point<dim> const &point,
double const /*height*/) const final;
double value(dealii::Point<dim> const &point, double const /*height*/) const;
/**
* 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;

private:
bool _source_on = false;
Expand All @@ -58,7 +59,9 @@ private:
double _value;
dealii::Point<dim> _min_point;
dealii::Point<dim> _max_point;
double _alpha;
};

} // namespace adamantine

#endif
1 change: 0 additions & 1 deletion source/DataAssimilator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <deal.II/fe/mapping_q1_eulerian.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/la_parallel_block_vector.h>
#include <deal.II/lac/la_vector.h>
#include <deal.II/lac/solver_gmres.h>
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/lac/trilinos_sparse_matrix.h>
Expand Down
13 changes: 10 additions & 3 deletions source/ElectronBeamHeatSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@
#include <instantiation.hh>
#include <types.hh>

#include <deal.II/base/memory_space.h>

namespace adamantine
{

template <int dim>
ElectronBeamHeatSource<dim>::ElectronBeamHeatSource(
boost::property_tree::ptree const &database)
: HeatSource<dim>(database)
: _beam(database),
_scan_path(database.get<std::string>("scan_path_file"),
database.get<std::string>("scan_path_file_format"))
{
}

template <int dim>
void ElectronBeamHeatSource<dim>::update_time(double time)
{
static const double log_01 = std::log(0.1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

_beam_center = this->_scan_path.value(time);
double segment_power_modifier = this->_scan_path.get_power_modifier(time);
_alpha =
-this->_beam.absorption_efficiency * this->_beam.max_power *
segment_power_modifier * _log_01 /
segment_power_modifier * log_01 /
(dealii::numbers::PI * this->_beam.radius_squared * this->_beam.depth);
}

Expand All @@ -52,9 +57,11 @@ double ElectronBeamHeatSource<dim>::value(dealii::Point<dim> const &point,
std::pow(point[axis<dim>::y] - _beam_center[axis<dim>::y], 2);
}

static const double log_01 = std::log(0.1);

// Electron beam heat source equation
double heat_source =
_alpha * std::exp(_log_01 * xpy_squared / this->_beam.radius_squared) *
_alpha * std::exp(log_01 * xpy_squared / this->_beam.radius_squared) *
distribution_z;

return heat_source;
Expand Down
66 changes: 59 additions & 7 deletions source/ElectronBeamHeatSource.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
#ifndef ELECTRON_BEAM_HEAT_SOURCE_HH
#define ELECTRON_BEAM_HEAT_SOURCE_HH

#include <HeatSource.hh>
#include <BeamHeatSourceProperties.hh>
#include <ScanPath.hh>

#include <limits>

namespace adamantine
{
/**
* A derived class from HeatSource for a model of an electron beam heat source.
* A model of an electron beam heat source.
* The form of the heat source model is taken from the following reference:
* Raghavan et al, Acta Materilia, 112, 2016, pp 303-314.
*/
template <int dim>
class ElectronBeamHeatSource final : public HeatSource<dim>
class ElectronBeamHeatSource
{
public:
/**
Expand All @@ -38,20 +39,71 @@ public:
/**
* Set the time variable.
*/
void update_time(double time) final;
void update_time(double time);

/**
* Returns the value of an electron beam heat source at a specified point and
* time.
*/
double value(dealii::Point<dim> const &point,
double const height) const final;
double value(dealii::Point<dim> const &point, double const height) const;

/**
* Return the scan path.
*/
ScanPath &get_scan_path();

void set_scan_path(ScanPath const scan_path) { _scan_path = scan_path; }

/**
* Compute the current height of the where the heat source meets the material
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Compute the current height of the where the heat source meets the material
* Compute the current height where the heat source meets the material

* (i.e. the current scan path height).
*/
double get_current_height(double const time) const;

/**
* (Re)set the BeamHeatSourceProperties member variable, necessary if the
* beam parameters vary in time (e.g. due to data assimilation).
*/
void set_beam_properties(boost::property_tree::ptree const &database);

/**
* Return the beam properties.
*/
BeamHeatSourceProperties const &get_beam_properties() const;

private:
dealii::Point<3> _beam_center;
double _alpha = std::numeric_limits<double>::signaling_NaN();
double const _log_01 = std::log(0.1);
BeamHeatSourceProperties _beam;
ScanPath _scan_path;
};

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

template <int dim>
double ElectronBeamHeatSource<dim>::get_current_height(double const time) const
{
return _scan_path.value(time)[2];
}

template <int dim>
void ElectronBeamHeatSource<dim>::set_beam_properties(
boost::property_tree::ptree const &database)
{
_beam.set_from_database(database);
}
Rombur marked this conversation as resolved.
Show resolved Hide resolved

template <int dim>
BeamHeatSourceProperties const &
ElectronBeamHeatSource<dim>::get_beam_properties() const
{
return _beam;
}

} // namespace adamantine

#endif
Loading