diff --git a/examples/mechanics/crack_branching.cpp b/examples/mechanics/crack_branching.cpp index b9dc1b7d..49e798d5 100644 --- a/examples/mechanics/crack_branching.cpp +++ b/examples/mechanics/crack_branching.cpp @@ -49,10 +49,6 @@ void crackBranchingExample( const std::string filename ) // FIXME: set halo width based on delta std::array low_corner = inputs["low_corner"]; std::array high_corner = inputs["high_corner"]; - std::array 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 @@ -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>( - 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( + exec_space{}, inputs ); // ==================================================== // Boundary conditions diff --git a/examples/mechanics/elastic_wave.cpp b/examples/mechanics/elastic_wave.cpp index d08c250d..5c780c3f 100644 --- a/examples/mechanics/elastic_wave.cpp +++ b/examples/mechanics/elastic_wave.cpp @@ -44,7 +44,6 @@ void elasticWaveExample( const std::string filename ) // ==================================================== // Discretization // ==================================================== - // FIXME: set halo width based on delta std::array low_corner = inputs["low_corner"]; std::array high_corner = inputs["high_corner"]; std::array num_cells = inputs["num_cells"]; @@ -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>( + auto particles = CabanaPD::createParticles( exec_space(), low_corner, high_corner, num_cells, halo_width ); // ==================================================== diff --git a/examples/mechanics/fragmenting_cylinder.cpp b/examples/mechanics/fragmenting_cylinder.cpp index 8c245cc4..0c84a553 100644 --- a/examples/mechanics/fragmenting_cylinder.cpp +++ b/examples/mechanics/fragmenting_cylinder.cpp @@ -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>( + auto particles = CabanaPD::createParticles( exec_space(), low_corner, high_corner, num_cells, halo_width ); // ==================================================== @@ -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( - inputs, particles, force_model, prenotch ); + inputs, particles, force_model ); cabana_pd->init(); cabana_pd->run(); } diff --git a/examples/mechanics/kalthoff_winkler.cpp b/examples/mechanics/kalthoff_winkler.cpp index 9da84ce1..d27c506f 100644 --- a/examples/mechanics/kalthoff_winkler.cpp +++ b/examples/mechanics/kalthoff_winkler.cpp @@ -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>( + auto particles = CabanaPD::createParticles( exec_space(), low_corner, high_corner, num_cells, halo_width ); // ==================================================== diff --git a/examples/thermomechanics/thermal_crack.cpp b/examples/thermomechanics/thermal_crack.cpp index 3b08c966..171eafb7 100644 --- a/examples/thermomechanics/thermal_crack.cpp +++ b/examples/thermomechanics/thermal_crack.cpp @@ -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>( - exec_space(), low_corner, high_corner, num_cells, halo_width ); + auto particles = + CabanaPD::createParticles( + exec_space(), low_corner, high_corner, num_cells, halo_width ); // ==================================================== // Custom particle initialization diff --git a/examples/thermomechanics/thermal_deformation.cpp b/examples/thermomechanics/thermal_deformation.cpp index ec4c346c..0df6e766 100644 --- a/examples/thermomechanics/thermal_deformation.cpp +++ b/examples/thermomechanics/thermal_deformation.cpp @@ -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>( - exec_space(), low_corner, high_corner, num_cells, halo_width ); + auto particles = + CabanaPD::createParticles( + exec_space(), low_corner, high_corner, num_cells, halo_width ); // ==================================================== // Custom particle initialization diff --git a/src/CabanaPD_Particles.hpp b/src/CabanaPD_Particles.hpp index c9e9816d..c1bdb472 100644 --- a/src/CabanaPD_Particles.hpp +++ b/src/CabanaPD_Particles.hpp @@ -71,6 +71,7 @@ #include #include +#include #include #include #include @@ -780,6 +781,54 @@ class Particles #endif }; +template +auto createParticles( ExecSpace exec_space, CabanaPD::Inputs inputs ) +{ + std::array low_corner = inputs["low_corner"]; + std::array high_corner = inputs["high_corner"]; + std::array 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>( + exec_space, low_corner, high_corner, num_cells, halo_width ); +} + +template +auto createParticles( const ExecSpace& exec_space, + std::array low_corner, + std::array high_corner, + const std::array num_cells, + const int max_halo_width ) +{ + return std::make_shared< + CabanaPD::Particles>( + exec_space, low_corner, high_corner, num_cells, max_halo_width ); +} + +template +auto createParticles( const ExecSpace& exec_space, + std::array low_corner, + std::array high_corner, + const std::array num_cells, + const int max_halo_width, + typename std::enable_if< + (std::is_same_v || + std::is_same_v), + int>::type* = 0 ) +{ + return std::make_shared< + CabanaPD::Particles>( + exec_space, low_corner, high_corner, num_cells, max_halo_width ); +} + } // namespace CabanaPD #endif