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

Add particle class creation functions #124

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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"];
streeve marked this conversation as resolved.
Show resolved Hide resolved
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<
streeve marked this conversation as resolved.
Show resolved Hide resolved
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
Loading