Skip to content

Commit

Permalink
Finish multi-species
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Jul 22, 2024
1 parent 2a202c2 commit 57d4112
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 36 deletions.
58 changes: 50 additions & 8 deletions src/CabanaPD_Comm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,13 @@ struct HaloIds
}
};

template <class ParticleType, class ModelType, class ThermalType>
template <class ParticleType, class ModelType, class SpeciesType,
class ThermalType>
class Comm;

// FIXME: extract model from ParticleType instead.
template <class ParticleType>
class Comm<ParticleType, PMB, TemperatureIndependent>
class Comm<ParticleType, PMB, SingleSpecies, TemperatureIndependent>
{
public:
int mpi_size = -1;
Expand Down Expand Up @@ -320,11 +321,12 @@ class Comm<ParticleType, PMB, TemperatureIndependent>
};

template <class ParticleType>
class Comm<ParticleType, LPS, TemperatureIndependent>
: public Comm<ParticleType, PMB, TemperatureIndependent>
class Comm<ParticleType, LPS, SingleSpecies, TemperatureIndependent>
: public Comm<ParticleType, PMB, SingleSpecies, TemperatureIndependent>
{
public:
using base_type = Comm<ParticleType, PMB, TemperatureIndependent>;
using base_type =
Comm<ParticleType, PMB, SingleSpecies, TemperatureIndependent>;
using memory_space = typename base_type::memory_space;
using halo_type = typename base_type::halo_type;
using base_type::gather_u;
Expand Down Expand Up @@ -368,12 +370,52 @@ class Comm<ParticleType, LPS, TemperatureIndependent>
}
};

template <class ParticleType, class ModelType>
class Comm<ParticleType, ModelType, MultiSpecies, TemperatureIndependent>
: public Comm<ParticleType, ModelType, SingleSpecies,
TemperatureIndependent>
{
public:
using base_type =
Comm<ParticleType, ModelType, SingleSpecies, TemperatureIndependent>;
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<halo_type, typename ParticleType::aosoa_species_type>;
std::shared_ptr<gather_species_type> gather_species;

Comm( ParticleType& particles, int max_export_guess = 100 )
: base_type( particles, max_export_guess )
{
_init_timer.start();

gather_species = std::make_shared<gather_species_type>(
*halo, particles._aosoa_species );

particles.resize( halo->numLocal(), halo->numGhost() );
_init_timer.stop();
}

void gatherSpecies()
{
_timer.start();
gather_species->apply();
_timer.stop();
}
};

template <class ParticleType>
class Comm<ParticleType, PMB, TemperatureDependent>
: public Comm<ParticleType, PMB, TemperatureIndependent>
class Comm<ParticleType, PMB, SingleSpecies, TemperatureDependent>
: public Comm<ParticleType, PMB, SingleSpecies, TemperatureIndependent>
{
public:
using base_type = Comm<ParticleType, PMB, TemperatureIndependent>;
using base_type =
Comm<ParticleType, PMB, SingleSpecies, TemperatureIndependent>;
using memory_space = typename base_type::memory_space;
using halo_type = typename base_type::halo_type;
using base_type::halo;
Expand Down
4 changes: 4 additions & 0 deletions src/CabanaPD_ForceModels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct BaseForceModel;
template <>
struct BaseForceModel<>
{
using species_type = SingleSpecies;
double delta;

BaseForceModel(){};
Expand All @@ -40,6 +41,8 @@ struct BaseForceModel<>
template <typename... MemorySpace>
struct BaseForceModel
{
using species_type = MultiSpecies;

// Only allow one memory space.
using memory_space =
typename std::tuple_element<0, std::tuple<MemorySpace...>>::type;
Expand Down Expand Up @@ -86,6 +89,7 @@ struct BaseForceModel
template <typename TemperatureType>
struct BaseTemperatureModel
{
using species_type = SingleSpecies;
using memory_space = typename TemperatureType::memory_space;
double alpha;
double temp0;
Expand Down
41 changes: 25 additions & 16 deletions src/CabanaPD_Particles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, Dimension>
using vector_type = Cabana::MemberTypes<double[dim]>;
// volume, dilatation, weighted_volume.
using scalar_type = Cabana::MemberTypes<double>;
// no-fail.
// no-fail, type.
using int_type = Cabana::MemberTypes<int>;
// v, W, rho, damage, type.
// v, W, rho, damage.
using other_types =
Cabana::MemberTypes<double[dim], double, double, double, int>;
// Potentially needed later: body force (b), ID.
Cabana::MemberTypes<double[dim], double, double, double>;

// FIXME: add vector length.
// FIXME: enable variable aosoa.
using aosoa_u_type = Cabana::AoSoA<vector_type, memory_space, 1>;
using aosoa_y_type = Cabana::AoSoA<vector_type, memory_space, 1>;
using aosoa_vol_type = Cabana::AoSoA<scalar_type, memory_space, 1>;
using aosoa_nofail_type = Cabana::AoSoA<int_type, memory_space, 1>;
using aosoa_species_type = Cabana::AoSoA<int_type, memory_space, 1>;
using aosoa_other_type = Cabana::AoSoA<other_types, memory_space>;
// Using grid here for the particle init.
using plist_x_type =
Expand Down Expand Up @@ -356,8 +356,11 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, Dimension>
{
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" );
Expand Down Expand Up @@ -427,6 +430,7 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, Dimension>
_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();
};
Expand Down Expand Up @@ -457,7 +461,7 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, Dimension>
"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
Expand All @@ -470,14 +474,17 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, Dimension>
auto timeOutput() { return _output_timer.time(); };
auto time() { return _timer.time(); };

friend class Comm<self_type, PMB, TemperatureIndependent>;
friend class Comm<self_type, PMB, TemperatureDependent>;
friend class Comm<self_type, PMB, SingleSpecies, TemperatureIndependent>;
friend class Comm<self_type, PMB, SingleSpecies, TemperatureDependent>;
friend class Comm<self_type, PMB, MultiSpecies, TemperatureIndependent>;
friend class Comm<self_type, PMB, MultiSpecies, TemperatureDependent>;

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;
Expand Down Expand Up @@ -619,7 +626,7 @@ class Particles<MemorySpace, LPS, TemperatureIndependent, Dimension>
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
Expand All @@ -628,8 +635,10 @@ class Particles<MemorySpace, LPS, TemperatureIndependent, Dimension>
_output_timer.stop();
}

friend class Comm<self_type, PMB, TemperatureIndependent>;
friend class Comm<self_type, LPS, TemperatureIndependent>;
friend class Comm<self_type, PMB, SingleSpecies, TemperatureIndependent>;
friend class Comm<self_type, LPS, SingleSpecies, TemperatureIndependent>;
friend class Comm<self_type, PMB, MultiSpecies, TemperatureIndependent>;
friend class Comm<self_type, LPS, MultiSpecies, TemperatureIndependent>;

protected:
void init_lps()
Expand Down Expand Up @@ -761,10 +770,10 @@ class Particles<MemorySpace, PMB, TemperatureDependent, Dimension>
#endif
}

friend class Comm<self_type, PMB, TemperatureIndependent>;
friend class Comm<self_type, LPS, TemperatureIndependent>;
friend class Comm<self_type, PMB, TemperatureDependent>;
friend class Comm<self_type, LPS, TemperatureDependent>;
friend class Comm<self_type, PMB, SingleSpecies, TemperatureIndependent>;
friend class Comm<self_type, PMB, SingleSpecies, TemperatureDependent>;
friend class Comm<self_type, PMB, MultiSpecies, TemperatureIndependent>;
friend class Comm<self_type, PMB, MultiSpecies, TemperatureDependent>;

protected:
void init_temp()
Expand Down
35 changes: 32 additions & 3 deletions src/CabanaPD_Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class SolverElastic
using force_model_type = ForceModel;
using force_type = Force<exec_space, force_model_type>;
using comm_type = Comm<particle_type, typename force_model_type::base_model,
typename force_model_type::species_type,
typename force_model_type::thermal_type>;
using neighbor_type =
Cabana::VerletList<memory_space, Cabana::FullNeighborTag,
Expand All @@ -128,7 +129,10 @@ class SolverElastic
// Add ghosts from other MPI ranks.
comm = std::make_shared<comm_type>( *particles );

// Update temperature ghost size if needed.
// Update optional property ghost sizes if needed.
if constexpr ( std::is_same<typename force_model_type::species_type,
MultiSpecies>::value )
force_model.update( particles->sliceType() );
if constexpr ( std::is_same<typename force_model_type::thermal_type,
TemperatureDependent>::value )
force_model.update( particles->sliceTemperature() );
Expand Down Expand Up @@ -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<typename force_model_type::species_type,
MultiSpecies>::value )
comm->gatherSpecies();
if constexpr ( std::is_same<typename force_model_type::thermal_type,
TemperatureDependent>::value )
comm->gatherTemperature();
Expand Down Expand Up @@ -253,6 +260,11 @@ class SolverElastic
// Update ghost particles.
comm->gatherDisplacement();

// Communicate optional type.
if constexpr ( std::is_same<typename force_model_type::species_type,
MultiSpecies>::value )
comm->gatherSpecies();

// Compute internal forces.
updateForce();

Expand Down Expand Up @@ -285,6 +297,11 @@ class SolverElastic
// Update ghost particles.
comm->gatherDisplacement();

// Communicate optional properties.
if constexpr ( std::is_same<typename force_model_type::species_type,
MultiSpecies>::value )
comm->gatherSpecies();

// Compute internal forces.
updateForce();

Expand Down Expand Up @@ -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<typename force_model_type::species_type,
MultiSpecies>::value )
comm->gatherSpecies();
if constexpr ( std::is_same<typename force_model_type::thermal_type,
TemperatureDependent>::value )
comm->gatherTemperature();
Expand Down Expand Up @@ -546,6 +566,11 @@ class SolverFracture
// Update ghost particles.
comm->gatherDisplacement();

// Communicate optional type.
if constexpr ( std::is_same<typename force_model_type::species_type,
MultiSpecies>::value )
comm->gatherSpecies();

// Compute internal forces.
updateForce();

Expand Down Expand Up @@ -581,6 +606,10 @@ class SolverFracture

// Update ghost particles.
comm->gatherDisplacement();
// Communicate optional properties.
if constexpr ( std::is_same<typename force_model_type::species_type,
MultiSpecies>::value )
comm->gatherSpecies();

// Compute internal forces.
updateForce();
Expand Down
8 changes: 8 additions & 0 deletions src/CabanaPD_Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ struct Elastic
struct Fracture
{
};

struct SingleSpecies
{
};
struct MultiSpecies
{
};

struct TemperatureDependent
{
};
Expand Down
8 changes: 6 additions & 2 deletions src/force/CabanaPD_ForceModels_LPS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ template <>
struct ForceModel<LPS, Elastic> : public BaseForceModel<Kokkos::HostSpace>
{
using base_type = BaseForceModel<Kokkos::HostSpace>;
using species_type = SingleSpecies;
using base_model = LPS;
using fracture_type = Elastic;
using thermal_type = TemperatureIndependent;
Expand Down Expand Up @@ -60,6 +61,7 @@ template <>
struct ForceModel<LPS, Fracture> : public ForceModel<LPS, Elastic>
{
using base_type = ForceModel<LPS, Elastic>;
using species_type = SingleSpecies;
using base_model = typename base_type::base_model;
using fracture_type = Fracture;
using thermal_type = base_type::thermal_type;
Expand All @@ -81,11 +83,11 @@ struct ForceModel<LPS, Fracture> : public ForceModel<LPS, Elastic>
{
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 );
}
Expand All @@ -95,6 +97,7 @@ template <>
struct ForceModel<LinearLPS, Elastic> : public ForceModel<LPS, Elastic>
{
using base_type = ForceModel<LPS, Elastic>;
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;
Expand All @@ -113,6 +116,7 @@ template <>
struct ForceModel<LinearLPS, Fracture> : public ForceModel<LPS, Fracture>
{
using base_type = ForceModel<LPS, Fracture>;
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;
Expand Down
Loading

0 comments on commit 57d4112

Please sign in to comment.