diff --git a/src/CabanaPD_Comm.hpp b/src/CabanaPD_Comm.hpp index 6ab1508c..3b73cd34 100644 --- a/src/CabanaPD_Comm.hpp +++ b/src/CabanaPD_Comm.hpp @@ -230,12 +230,13 @@ struct HaloIds } }; -template +template class Comm; // FIXME: extract model from ParticleType instead. template -class Comm +class Comm { public: int mpi_size = -1; @@ -320,11 +321,12 @@ class Comm }; template -class Comm - : public Comm +class Comm + : public Comm { public: - using base_type = Comm; + using base_type = + Comm; using memory_space = typename base_type::memory_space; using halo_type = typename base_type::halo_type; using base_type::gather_u; @@ -368,12 +370,52 @@ class Comm } }; +template +class Comm + : public Comm +{ + public: + using base_type = + Comm; + using memory_space = typename base_type::memory_space; + using halo_type = typename base_type::halo_type; + using base_type::halo; + + using base_type::_init_timer; + using base_type::_timer; + + using gather_species_type = + Cabana::Gather; + std::shared_ptr gather_species; + + Comm( ParticleType& particles, int max_export_guess = 100 ) + : base_type( particles, max_export_guess ) + { + _init_timer.start(); + + gather_species = std::make_shared( + *halo, particles._aosoa_species ); + + particles.resize( halo->numLocal(), halo->numGhost() ); + _init_timer.stop(); + } + + void gatherSpecies() + { + _timer.start(); + gather_species->apply(); + _timer.stop(); + } +}; + template -class Comm - : public Comm +class Comm + : public Comm { public: - using base_type = Comm; + using base_type = + Comm; using memory_space = typename base_type::memory_space; using halo_type = typename base_type::halo_type; using base_type::halo; diff --git a/src/CabanaPD_ForceModels.hpp b/src/CabanaPD_ForceModels.hpp index 83ed009c..42d456e6 100644 --- a/src/CabanaPD_ForceModels.hpp +++ b/src/CabanaPD_ForceModels.hpp @@ -23,6 +23,7 @@ struct BaseForceModel; template <> struct BaseForceModel<> { + using species_type = SingleSpecies; double delta; BaseForceModel(){}; @@ -40,6 +41,8 @@ struct BaseForceModel<> template struct BaseForceModel { + using species_type = MultiSpecies; + // Only allow one memory space. using memory_space = typename std::tuple_element<0, std::tuple>::type; @@ -86,6 +89,7 @@ struct BaseForceModel template struct BaseTemperatureModel { + using species_type = SingleSpecies; using memory_space = typename TemperatureType::memory_space; double alpha; double temp0; diff --git a/src/CabanaPD_Particles.hpp b/src/CabanaPD_Particles.hpp index c1151770..ec4f2cf7 100644 --- a/src/CabanaPD_Particles.hpp +++ b/src/CabanaPD_Particles.hpp @@ -101,12 +101,11 @@ class Particles using vector_type = Cabana::MemberTypes; // volume, dilatation, weighted_volume. using scalar_type = Cabana::MemberTypes; - // no-fail. + // no-fail, type. using int_type = Cabana::MemberTypes; - // v, W, rho, damage, type. + // v, W, rho, damage. using other_types = - Cabana::MemberTypes; - // Potentially needed later: body force (b), ID. + Cabana::MemberTypes; // FIXME: add vector length. // FIXME: enable variable aosoa. @@ -114,6 +113,7 @@ class Particles using aosoa_y_type = Cabana::AoSoA; using aosoa_vol_type = Cabana::AoSoA; using aosoa_nofail_type = Cabana::AoSoA; + using aosoa_species_type = Cabana::AoSoA; using aosoa_other_type = Cabana::AoSoA; // Using grid here for the particle init. using plist_x_type = @@ -356,8 +356,11 @@ class Particles { return Cabana::slice<0>( _aosoa_vol, "volume" ); } - auto sliceType() { return Cabana::slice<4>( _aosoa_other, "type" ); } - auto sliceType() const { return Cabana::slice<4>( _aosoa_other, "type" ); } + auto sliceType() { return Cabana::slice<0>( _aosoa_species, "type" ); } + auto sliceType() const + { + return Cabana::slice<0>( _aosoa_species, "type" ); + } auto sliceStrainEnergy() { return Cabana::slice<1>( _aosoa_other, "strain_energy" ); @@ -427,6 +430,7 @@ class Particles _plist_f.aosoa().resize( new_local ); _aosoa_other.resize( new_local ); _aosoa_nofail.resize( new_local + new_ghost ); + _aosoa_species.resize( new_local + new_ghost ); size = _plist_x.size(); _timer.stop(); }; @@ -457,7 +461,7 @@ class Particles "particles", local_grid->globalGrid(), output_step, output_time, 0, n_local, getPosition( use_reference ), sliceStrainEnergy(), sliceForce(), sliceDisplacement(), sliceVelocity(), - sliceDamage() ); + sliceDamage(), sliceType() ); #else log( std::cout, "No particle output enabled." ); #endif @@ -470,14 +474,17 @@ class Particles auto timeOutput() { return _output_timer.time(); }; auto time() { return _timer.time(); }; - friend class Comm; - friend class Comm; + friend class Comm; + friend class Comm; + friend class Comm; + friend class Comm; protected: aosoa_u_type _aosoa_u; aosoa_y_type _aosoa_y; aosoa_vol_type _aosoa_vol; aosoa_nofail_type _aosoa_nofail; + aosoa_species_type _aosoa_species; aosoa_other_type _aosoa_other; plist_x_type _plist_x; @@ -619,7 +626,7 @@ class Particles base_type::sliceStrainEnergy(), base_type::sliceForce(), base_type::sliceDisplacement(), base_type::sliceVelocity(), base_type::sliceDamage(), sliceWeightedVolume(), - sliceDilatation() ); + sliceDilatation(), base_type::sliceType() ); #else log( std::cout, "No particle output enabled." ); #endif @@ -628,8 +635,10 @@ class Particles _output_timer.stop(); } - friend class Comm; - friend class Comm; + friend class Comm; + friend class Comm; + friend class Comm; + friend class Comm; protected: void init_lps() @@ -761,10 +770,10 @@ class Particles #endif } - friend class Comm; - friend class Comm; - friend class Comm; - friend class Comm; + friend class Comm; + friend class Comm; + friend class Comm; + friend class Comm; protected: void init_temp() diff --git a/src/CabanaPD_Solver.hpp b/src/CabanaPD_Solver.hpp index d01b00e0..acfa379e 100644 --- a/src/CabanaPD_Solver.hpp +++ b/src/CabanaPD_Solver.hpp @@ -103,6 +103,7 @@ class SolverElastic using force_model_type = ForceModel; using force_type = Force; using comm_type = Comm; using neighbor_type = Cabana::VerletList( *particles ); - // Update temperature ghost size if needed. + // Update optional property ghost sizes if needed. + if constexpr ( std::is_same::value ) + force_model.update( particles->sliceType() ); if constexpr ( std::is_same::value ) force_model.update( particles->sliceTemperature() ); @@ -213,7 +217,10 @@ class SolverElastic if ( !boundary_condition.forceUpdate() ) boundary_condition.apply( exec_space(), *particles, 0.0 ); - // Communicate temperature. + // Communicate optional properties. + if constexpr ( std::is_same::value ) + comm->gatherSpecies(); if constexpr ( std::is_same::value ) comm->gatherTemperature(); @@ -253,6 +260,11 @@ class SolverElastic // Update ghost particles. comm->gatherDisplacement(); + // Communicate optional type. + if constexpr ( std::is_same::value ) + comm->gatherSpecies(); + // Compute internal forces. updateForce(); @@ -285,6 +297,11 @@ class SolverElastic // Update ghost particles. comm->gatherDisplacement(); + // Communicate optional properties. + if constexpr ( std::is_same::value ) + comm->gatherSpecies(); + // Compute internal forces. updateForce(); @@ -506,7 +523,10 @@ class SolverFracture if ( !boundary_condition.forceUpdate() ) boundary_condition.apply( exec_space(), *particles, 0.0 ); - // Communicate temperature. + // Communicate optional properties. + if constexpr ( std::is_same::value ) + comm->gatherSpecies(); if constexpr ( std::is_same::value ) comm->gatherTemperature(); @@ -546,6 +566,11 @@ class SolverFracture // Update ghost particles. comm->gatherDisplacement(); + // Communicate optional type. + if constexpr ( std::is_same::value ) + comm->gatherSpecies(); + // Compute internal forces. updateForce(); @@ -581,6 +606,10 @@ class SolverFracture // Update ghost particles. comm->gatherDisplacement(); + // Communicate optional properties. + if constexpr ( std::is_same::value ) + comm->gatherSpecies(); // Compute internal forces. updateForce(); diff --git a/src/CabanaPD_Types.hpp b/src/CabanaPD_Types.hpp index 62076735..ac5d097a 100644 --- a/src/CabanaPD_Types.hpp +++ b/src/CabanaPD_Types.hpp @@ -20,6 +20,14 @@ struct Elastic struct Fracture { }; + +struct SingleSpecies +{ +}; +struct MultiSpecies +{ +}; + struct TemperatureDependent { }; diff --git a/src/force/CabanaPD_ForceModels_LPS.hpp b/src/force/CabanaPD_ForceModels_LPS.hpp index 2a4eeeb9..b3231c40 100644 --- a/src/force/CabanaPD_ForceModels_LPS.hpp +++ b/src/force/CabanaPD_ForceModels_LPS.hpp @@ -23,6 +23,7 @@ template <> struct ForceModel : public BaseForceModel { using base_type = BaseForceModel; + using species_type = SingleSpecies; using base_model = LPS; using fracture_type = Elastic; using thermal_type = TemperatureIndependent; @@ -60,6 +61,7 @@ template <> struct ForceModel : public ForceModel { using base_type = ForceModel; + using species_type = SingleSpecies; using base_model = typename base_type::base_model; using fracture_type = Fracture; using thermal_type = base_type::thermal_type; @@ -81,11 +83,11 @@ struct ForceModel : public ForceModel { if ( influence_type == 1 ) { - s0 = sqrt( 5.0 * G0 / 9.0 / K / delta(0) ); // 1/xi + s0 = sqrt( 5.0 * G0 / 9.0 / K / delta( 0 ) ); // 1/xi } else { - s0 = sqrt( 8.0 * G0 / 15.0 / K / delta(0) ); // 1 + s0 = sqrt( 8.0 * G0 / 15.0 / K / delta( 0 ) ); // 1 } bond_break_coeff = ( 1.0 + s0 ) * ( 1.0 + s0 ); } @@ -95,6 +97,7 @@ template <> struct ForceModel : public ForceModel { using base_type = ForceModel; + using species_type = SingleSpecies; using base_model = typename base_type::base_model; using fracture_type = typename base_type::fracture_type; using thermal_type = base_type::thermal_type; @@ -113,6 +116,7 @@ template <> struct ForceModel : public ForceModel { using base_type = ForceModel; + using species_type = SingleSpecies; using base_model = typename base_type::base_model; using fracture_type = typename base_type::fracture_type; using thermal_type = base_type::thermal_type; diff --git a/src/force/CabanaPD_ForceModels_PMB.hpp b/src/force/CabanaPD_ForceModels_PMB.hpp index b2d0709a..57c04d6f 100644 --- a/src/force/CabanaPD_ForceModels_PMB.hpp +++ b/src/force/CabanaPD_ForceModels_PMB.hpp @@ -23,6 +23,7 @@ struct ForceModel : public BaseForceModel<> { using base_type = BaseForceModel<>; + using species_type = typename base_type::species_type; using base_model = PMB; using fracture_type = Elastic; using thermal_type = TemperatureIndependent; @@ -62,6 +63,7 @@ struct ForceModel { using memory_space = typename ParticleType::memory_space; using base_type = BaseForceModel; + using species_type = typename base_type::species_type; using base_model = PMB; using fracture_type = Elastic; using thermal_type = TemperatureIndependent; @@ -121,6 +123,8 @@ struct ForceModel { return c( type( i ), type( j ) ); } + + void update( const ParticleType _type ) { type = _type; } }; template @@ -181,6 +185,7 @@ struct ForceModel ForceModel; using memory_space = typename base_type::memory_space; using base_model = typename base_type::base_model; + using species_type = typename base_type::species_type; using fracture_type = Fracture; using thermal_type = typename base_type::thermal_type; @@ -239,18 +244,18 @@ struct ForceModel } KOKKOS_INLINE_FUNCTION - auto criticalStretch( const int i ) + auto criticalStretch( const int type_i ) { - return sqrt( 5.0 * G0( i ) / 9.0 / K( i ) / delta( i ) ); + return sqrt( 5.0 * G0( type_i ) / 9.0 / K( type_i ) / delta( type_i ) ); } KOKKOS_INLINE_FUNCTION - auto criticalStretch( const int i, const int j ) const + auto criticalStretch( const int type_i, const int type_j ) const { - auto s0_i = s0( type( i ), type( i ) ); - auto s0_j = s0( type( j ), type( j ) ); - auto c_i = c( type( i ), type( i ) ); - auto c_j = c( type( j ), type( j ) ); + auto s0_i = s0( type_i, type_i ); + auto s0_j = s0( type_j, type_j ); + auto c_i = c( type_i, type_i ); + auto c_j = c( type_j, type_j ); return Kokkos::sqrt( ( s0_i * s0_i * c_i + s0_j * s0_j * c_j ) / ( c_i + c_j ) ); } @@ -259,6 +264,10 @@ struct ForceModel bool criticalStretch( const int i, const int j, const double r, const double xi ) const { + // if ( type( j ) != 0 ) + // std::cout << bond_break_coeff.size() << " " << type( i ) << " " + // << type( j ) << "\n"; + //<< type.size() << " " << i << " " << j << "\n"; return r * r >= bond_break_coeff( type( i ), type( j ) ) * xi * xi; } }; @@ -281,6 +290,7 @@ struct ForceModel using base_type = ForceModel; using base_model = typename base_type::base_model; + using species_type = typename base_type::species_type; using fracture_type = typename base_type::fracture_type; using thermal_type = typename base_type::thermal_type; @@ -298,6 +308,7 @@ struct ForceModel using base_type = ForceModel; using base_model = typename base_type::base_model; + using species_type = typename base_type::species_type; using fracture_type = typename base_type::fracture_type; using thermal_type = typename base_type::thermal_type; @@ -319,6 +330,7 @@ struct ForceModel { using memory_space = typename TemperatureType::memory_space; using base_type = ForceModel; + using species_type = typename base_type::species_type; using base_temperature_type = BaseTemperatureModel; using base_model = PMB; using fracture_type = Elastic; @@ -363,6 +375,7 @@ struct ForceModel { using memory_space = typename TemperatureType::memory_space; using base_type = ForceModel; + using species_type = typename base_type::species_type; using base_temperature_type = BaseTemperatureModel; using base_model = typename base_type::base_model; using fracture_type = typename base_type::fracture_type;