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 neighbor skin distance to delay neighbor build #177

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion examples/mechanics/fragmenting_cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void fragmentingCylinderExample( const std::string filename )
{
double r_c = inputs["contact_horizon_factor"];
r_c *= dx[0];
CabanaPD::NormalRepulsionModel contact_model( delta, r_c, K );
CabanaPD::NormalRepulsionModel contact_model( delta, r_c, r_c, K );

auto cabana_pd = CabanaPD::createSolver<memory_space>(
inputs, particles, force_model, contact_model );
Expand Down
14 changes: 12 additions & 2 deletions src/CabanaPD_Force.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ class Force<MemorySpace, BaseForceModel>
{
}

// FIXME: should it be possible to update this list?
template <class ParticleType>
void update( const ParticleType&, const double, const bool = false )
{
}

unsigned getMaxLocalNeighbors()
{
auto neigh = _neigh_list;
Expand Down Expand Up @@ -234,6 +240,7 @@ class Force<MemorySpace, BaseForceModel>

auto time() { return _timer.time(); };
auto timeEnergy() { return _energy_timer.time(); };
auto timeNeighbor() { return 0.0; };
};

template <class MemorySpace>
Expand Down Expand Up @@ -276,6 +283,7 @@ class BaseFracture
******************************************************************************/
template <class ForceType, class ParticleType, class ParallelType>
void computeForce( ForceType& force, ParticleType& particles,
const double max_displacement,
const ParallelType& neigh_op_tag, const bool reset = true )
{
auto x = particles.sliceReferencePosition();
Expand All @@ -294,9 +302,11 @@ void computeForce( ForceType& force, ParticleType& particles,

// Forces only atomic if using team threading.
if ( std::is_same<decltype( neigh_op_tag ), Cabana::TeamOpTag>::value )
force.computeForceFull( f_a, x, u, particles, neigh_op_tag );
force.computeForceFull( f_a, x, u, particles, max_displacement,
neigh_op_tag );
else
force.computeForceFull( f, x, u, particles, neigh_op_tag );
force.computeForceFull( f, x, u, particles, max_displacement,
neigh_op_tag );
Kokkos::fence();
}

Expand Down
22 changes: 18 additions & 4 deletions src/CabanaPD_Integrate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,19 @@ class Integrator
~Integrator() {}

template <class ParticlesType>
void initialHalfStep( ParticlesType& p )
double initialHalfStep( ParticlesType& p )
{
_timer.start();

auto u = p.sliceDisplacement();
auto v = p.sliceVelocity();
auto f = p.sliceForce();
auto rho = p.sliceDensity();
auto u_neigh = p.sliceDisplacementNeighborBuild();

auto dt = _dt;
auto half_dt = _half_dt;
auto init_func = KOKKOS_LAMBDA( const int i )
auto init_func = KOKKOS_LAMBDA( const int i, double& max_u )
{
const double half_dt_m = half_dt / rho( i );
v( i, 0 ) += half_dt_m * f( i, 0 );
Expand All @@ -105,13 +106,26 @@ class Integrator
u( i, 0 ) += dt * v( i, 0 );
u( i, 1 ) += dt * v( i, 1 );
u( i, 2 ) += dt * v( i, 2 );

// FIXME: only used for contact: get displacement since last
// neighbor update.
u_neigh( i, 0 ) += u( i, 0 );
u_neigh( i, 1 ) += u( i, 1 );
u_neigh( i, 2 ) += u( i, 2 );
auto u_mag = Kokkos::hypot( u_neigh( i, 0 ), u_neigh( i, 1 ),
u_neigh( i, 2 ) );
if ( u_mag > max_u )
max_u = u_mag;
};
Kokkos::RangePolicy<exec_space> policy( p.frozenOffset(),
p.localOffset() );
Kokkos::parallel_for( "CabanaPD::Integrator::Initial", policy,
init_func );
double max_displacement;
Kokkos::parallel_reduce( "CabanaPD::Integrator::Initial", policy,
init_func,
Kokkos::Max<double>( max_displacement ) );

_timer.stop();
return max_displacement;
}

template <class ParticlesType>
Expand Down
68 changes: 57 additions & 11 deletions src/CabanaPD_Particles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
// no-fail.
using int_type = Cabana::MemberTypes<int>;
// v, rho, type.
using other_types = Cabana::MemberTypes<double[dim], double, int>;
using other_types = Cabana::MemberTypes<double[dim], 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_u_neigh_type = Cabana::AoSoA<vector_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 @@ -284,11 +285,11 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
auto x = sliceReferencePosition();
auto v = sliceVelocity();
auto f = sliceForce();
auto type = sliceType();
// auto type = sliceType();
auto rho = sliceDensity();
auto u = sliceDisplacement();
auto vol = sliceVolume();
auto nofail = sliceNoFail();
auto u_neigh = sliceDisplacementNeighborBuild();

// Initialize particles.
auto create_functor =
Expand All @@ -307,15 +308,15 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
Cabana::get( particle, CabanaPD::Field::ReferencePosition(),
d ) = px[d];
u( pid, d ) = 0.0;
u_neigh( pid, d ) = 0;
v( pid, d ) = 0.0;
f( pid, d ) = 0.0;
}
// Get the volume of the cell.
vol( pid ) = pv;

// FIXME: hardcoded.
type( pid ) = 0;
nofail( pid ) = 0;
// type( pid ) = 0;
rho( pid ) = 1.0;

return create;
Expand Down Expand Up @@ -353,10 +354,10 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
auto p_vol = sliceVolume();
auto v = sliceVelocity();
auto f = sliceForce();
auto type = sliceType();
// auto type = sliceType();
auto rho = sliceDensity();
auto u = sliceDisplacement();
auto nofail = sliceNoFail();
auto u_neigh = sliceDisplacementNeighborBuild();

static_assert(
Cabana::is_accessible_from<
Expand All @@ -374,11 +375,11 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
{
p_x( pid, d ) = x( pid_offset, d );
u( pid, d ) = 0.0;
u_neigh( pid, d ) = 0;
v( pid, d ) = 0.0;
f( pid, d ) = 0.0;
}
type( pid ) = 0;
nofail( pid ) = 0;
// type( pid ) = 0;
rho( pid ) = 1.0;
} );

Expand Down Expand Up @@ -447,6 +448,14 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
{
return Cabana::slice<0>( _aosoa_u, "displacements" );
}
auto sliceDisplacementNeighborBuild()
{
return Cabana::slice<0>( _aosoa_u_neigh, "displacement_since_rebuild" );
}
auto sliceDisplacementNeighborBuild() const
{
return Cabana::slice<0>( _aosoa_u_neigh, "displacement_since_rebuild" );
}
auto sliceForce() { return _plist_f.slice( CabanaPD::Field::Force() ); }
auto sliceForceAtomic()
{
Expand Down Expand Up @@ -474,8 +483,9 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
{
return Cabana::slice<1>( _aosoa_other, "density" );
}
auto sliceType() { return Cabana::slice<2>( _aosoa_other, "type" ); }
auto sliceType() const { return Cabana::slice<2>( _aosoa_other, "type" ); }
// auto sliceType() { return Cabana::slice<2>( _aosoa_other, "type" ); }
// auto sliceType() const { return Cabana::slice<2>( _aosoa_other, "type" );
// }

auto sliceNoFail()
{
Expand Down Expand Up @@ -524,10 +534,45 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
_plist_f.aosoa().resize( localOffset() );
_aosoa_other.resize( localOffset() );
_aosoa_nofail.resize( referenceOffset() );
_aosoa_u_neigh.resize( localOffset() );

size = _plist_x.size();
_timer.stop();
};

void shrink()
{
_timer.start();
_plist_x.aosoa().shrinkToFit();
_aosoa_u.shrinkToFit();
_aosoa_y.shrinkToFit();
_aosoa_vol.shrinkToFit();
_plist_f.aosoa().shrinkToFit();
_aosoa_other.shrinkToFit();
_aosoa_u_neigh.shrinkToFit();
_timer.stop();
};

template <typename KeepType>
void remove( const int num_keep, const KeepType& keep )
{
Cabana::remove( execution_space(), num_keep, keep, _plist_x.aosoa(),
numFrozen() );
Cabana::remove( execution_space(), num_keep, keep, _plist_f.aosoa(),
numFrozen() );
Cabana::remove( execution_space(), num_keep, keep, _aosoa_u,
numFrozen() );
Cabana::remove( execution_space(), num_keep, keep, _aosoa_vol,
numFrozen() );
Cabana::remove( execution_space(), num_keep, keep, _aosoa_y,
numFrozen() );
Cabana::remove( execution_space(), num_keep, keep, _aosoa_other,
numFrozen() );
Cabana::remove( execution_space(), num_keep, keep, _aosoa_u_neigh,
numFrozen() );
resize( frozen_offset + num_keep, 0 );
}

auto getPosition( const bool use_reference )
{
if ( use_reference )
Expand Down Expand Up @@ -577,6 +622,7 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>

protected:
aosoa_u_type _aosoa_u;
aosoa_u_neigh_type _aosoa_u_neigh;
aosoa_y_type _aosoa_y;
aosoa_vol_type _aosoa_vol;
aosoa_nofail_type _aosoa_nofail;
Expand Down
25 changes: 15 additions & 10 deletions src/CabanaPD_Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class Solver
comm->gatherWeightedVolume();
}
// Compute initial internal forces and energy.
updateForce();
updateForce( 0.0 );
computeEnergy( *force, *particles, neigh_iter_tag() );

if ( initial_output )
Expand Down Expand Up @@ -266,6 +266,8 @@ class Solver
init( boundary_condition, initial_output );
}

void updateNeighbors() { force->update( *particles, 0.0, true ); }

template <typename BoundaryType>
void run( BoundaryType boundary_condition )
{
Expand All @@ -277,7 +279,7 @@ class Solver
_step_timer.start();

// Integrate - velocity Verlet first half.
integrator->initialHalfStep( *particles );
auto max_displacement = integrator->initialHalfStep( *particles );

// Update ghost particles.
comm->gatherDisplacement();
Expand All @@ -300,10 +302,11 @@ class Solver
comm->gatherTemperature();

// Compute internal forces.
updateForce();
updateForce( max_displacement );

if constexpr ( is_contact<contact_model_type>::value )
computeForce( *contact, *particles, neigh_iter_tag{}, false );
computeForce( *contact, *particles, max_displacement,
neigh_iter_tag{}, false );

// Add force boundary condition.
if ( boundary_condition.forceUpdate() )
Expand All @@ -329,16 +332,17 @@ class Solver
_step_timer.start();

// Integrate - velocity Verlet first half.
integrator->initialHalfStep( *particles );
auto max_displacement = integrator->initialHalfStep( *particles );

// Update ghost particles.
comm->gatherDisplacement();

// Compute internal forces.
updateForce();
updateForce( max_displacement );

if constexpr ( is_contact<contact_model_type>::value )
computeForce( *contact, *particles, neigh_iter_tag{}, false );
computeForce( *contact, *particles, max_displacement,
neigh_iter_tag{}, false );

if constexpr ( is_temperature_dependent<
typename force_model_type::thermal_type>::value )
Expand All @@ -356,7 +360,7 @@ class Solver

// Compute and communicate fields needed for force computation and update
// forces.
void updateForce()
void updateForce( const double max_displacement )
{
// Compute and communicate weighted volume for LPS (does nothing for
// PMB). Only computed once without fracture.
Expand All @@ -371,7 +375,7 @@ class Solver
comm->gatherDilatation();

// Compute internal forces.
computeForce( *force, *particles, neigh_iter_tag{} );
computeForce( *force, *particles, max_displacement, neigh_iter_tag{} );
}

void output( const int step )
Expand Down Expand Up @@ -419,6 +423,7 @@ class Solver
double integrate_time = integrator->time();
double force_time = force->time();
double energy_time = force->timeEnergy();
double neigh_time = force->timeNeighbor();
double output_time = particles->timeOutput();
_total_time += step_time;
auto rate = static_cast<double>( particles->numGlobal() *
Expand All @@ -428,7 +433,7 @@ class Solver
" ", std::scientific, std::setprecision( 2 ), step * dt, " ",
W, " ", std::fixed, _total_time, " ", force_time, " ",
comm_time, " ", integrate_time, " ", energy_time, " ",
output_time, " ", std::scientific, rate );
neigh_time, " ", output_time, " ", std::scientific, rate );
out.close();
}
}
Expand Down
Loading
Loading