Skip to content

Commit

Permalink
Merge pull request #124 from streeve/particle_creation
Browse files Browse the repository at this point in the history
Add particle class creation functions
  • Loading branch information
streeve authored Aug 22, 2024
2 parents d6aa4e7 + d28e51c commit 9b2fef3
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 32 deletions.
12 changes: 3 additions & 9 deletions examples/mechanics/crack_branching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ void crackBranchingExample( const std::string filename )
// FIXME: set halo width based on delta
std::array<double, 3> low_corner = inputs["low_corner"];
std::array<double, 3> high_corner = inputs["high_corner"];
std::array<int, 3> num_cells = inputs["num_cells"];
int m = std::floor( delta /
( ( high_corner[0] - low_corner[0] ) / num_cells[0] ) );
int halo_width = m + 1; // Just to be safe.

// ====================================================
// Pre-notch
Expand All @@ -77,11 +73,9 @@ void crackBranchingExample( const std::string filename )
// ====================================================
// Particle generation
// ====================================================
// Does not set displacements, velocities, etc.
auto particles = std::make_shared<
CabanaPD::Particles<memory_space, typename model_type::base_model,
typename model_type::thermal_type>>(
exec_space(), low_corner, high_corner, num_cells, halo_width );
// Note that individual inputs can be passed instead (see other examples).
auto particles = CabanaPD::createParticles<memory_space, model_type>(
exec_space{}, inputs );

// ====================================================
// Boundary conditions
Expand Down
6 changes: 1 addition & 5 deletions examples/mechanics/elastic_wave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ void elasticWaveExample( const std::string filename )
// ====================================================
// Discretization
// ====================================================
// FIXME: set halo width based on delta
std::array<double, 3> low_corner = inputs["low_corner"];
std::array<double, 3> high_corner = inputs["high_corner"];
std::array<int, 3> num_cells = inputs["num_cells"];
Expand All @@ -62,10 +61,7 @@ void elasticWaveExample( const std::string filename )
// ====================================================
// Particle generation
// ====================================================
// Does not set displacements, velocities, etc.
auto particles = std::make_shared<
CabanaPD::Particles<memory_space, typename model_type::base_model,
typename model_type::thermal_type>>(
auto particles = CabanaPD::createParticles<memory_space, model_type>(
exec_space(), low_corner, high_corner, num_cells, halo_width );

// ====================================================
Expand Down
11 changes: 2 additions & 9 deletions examples/mechanics/fragmenting_cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ void fragmentingCylinderExample( const std::string filename )
// ====================================================
// Particle generation
// ====================================================
// Does not set displacements, velocities, etc.
auto particles = std::make_shared<
CabanaPD::Particles<memory_space, typename model_type::base_model,
typename model_type::thermal_type>>(
auto particles = CabanaPD::createParticles<memory_space, model_type>(
exec_space(), low_corner, high_corner, num_cells, halo_width );

// ====================================================
Expand Down Expand Up @@ -142,12 +139,8 @@ void fragmentingCylinderExample( const std::string filename )
// ====================================================
// Simulation run
// ====================================================

// Define empty pre-notch
CabanaPD::Prenotch<0> prenotch;

auto cabana_pd = CabanaPD::createSolverFracture<memory_space>(
inputs, particles, force_model, prenotch );
inputs, particles, force_model );
cabana_pd->init();
cabana_pd->run();
}
Expand Down
4 changes: 1 addition & 3 deletions examples/mechanics/kalthoff_winkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ void kalthoffWinklerExample( const std::string filename )
// Particle generation
// ====================================================
// Does not set displacements, velocities, etc.
auto particles = std::make_shared<
CabanaPD::Particles<memory_space, typename model_type::base_model,
typename model_type::thermal_type>>(
auto particles = CabanaPD::createParticles<memory_space, model_type>(
exec_space(), low_corner, high_corner, num_cells, halo_width );

// ====================================================
Expand Down
6 changes: 3 additions & 3 deletions examples/thermomechanics/thermal_crack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ void thermalCrackExample( const std::string filename )
// Particle generation
// ====================================================
// Does not set displacements, velocities, etc.
auto particles = std::make_shared<
CabanaPD::Particles<memory_space, model_type, thermal_type>>(
exec_space(), low_corner, high_corner, num_cells, halo_width );
auto particles =
CabanaPD::createParticles<memory_space, model_type, thermal_type>(
exec_space(), low_corner, high_corner, num_cells, halo_width );

// ====================================================
// Custom particle initialization
Expand Down
6 changes: 3 additions & 3 deletions examples/thermomechanics/thermal_deformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ void thermalDeformationExample( const std::string filename )
// Particle generation
// ====================================================
// Does not set displacements, velocities, etc.
auto particles = std::make_shared<
CabanaPD::Particles<memory_space, model_type, thermal_type>>(
exec_space(), low_corner, high_corner, num_cells, halo_width );
auto particles =
CabanaPD::createParticles<memory_space, model_type, thermal_type>(
exec_space(), low_corner, high_corner, num_cells, halo_width );

// ====================================================
// Custom particle initialization
Expand Down
49 changes: 49 additions & 0 deletions src/CabanaPD_Particles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

#include <CabanaPD_Comm.hpp>
#include <CabanaPD_Fields.hpp>
#include <CabanaPD_Input.hpp>
#include <CabanaPD_Output.hpp>
#include <CabanaPD_Timer.hpp>
#include <CabanaPD_Types.hpp>
Expand Down Expand Up @@ -780,6 +781,54 @@ class Particles<MemorySpace, PMB, TemperatureDependent, Dimension>
#endif
};

template <typename MemorySpace, typename ModelType, typename ExecSpace>
auto createParticles( ExecSpace exec_space, CabanaPD::Inputs inputs )
{
std::array<double, 3> low_corner = inputs["low_corner"];
std::array<double, 3> high_corner = inputs["high_corner"];
std::array<int, 3> num_cells = inputs["num_cells"];
double delta = inputs["horizon"];
int m = std::floor( delta /
( ( high_corner[0] - low_corner[0] ) / num_cells[0] ) );
int halo_width = m + 1; // Just to be safe.

return std::make_shared<
CabanaPD::Particles<MemorySpace, typename ModelType::base_model,
typename ModelType::thermal_type>>(
exec_space, low_corner, high_corner, num_cells, halo_width );
}

template <typename MemorySpace, typename ModelType, typename ExecSpace,
std::size_t Dim>
auto createParticles( const ExecSpace& exec_space,
std::array<double, Dim> low_corner,
std::array<double, Dim> high_corner,
const std::array<int, Dim> num_cells,
const int max_halo_width )
{
return std::make_shared<
CabanaPD::Particles<MemorySpace, typename ModelType::base_model,
typename ModelType::thermal_type>>(
exec_space, low_corner, high_corner, num_cells, max_halo_width );
}

template <typename MemorySpace, typename ModelType, typename ThermalType,
typename ExecSpace, std::size_t Dim>
auto createParticles( const ExecSpace& exec_space,
std::array<double, Dim> low_corner,
std::array<double, Dim> high_corner,
const std::array<int, Dim> num_cells,
const int max_halo_width,
typename std::enable_if<
(std::is_same_v<ThermalType, TemperatureDependent> ||
std::is_same_v<ThermalType, TemperatureIndependent>),
int>::type* = 0 )
{
return std::make_shared<
CabanaPD::Particles<MemorySpace, ModelType, ThermalType>>(
exec_space, low_corner, high_corner, num_cells, max_halo_width );
}

} // namespace CabanaPD

#endif

0 comments on commit 9b2fef3

Please sign in to comment.