Skip to content

Commit

Permalink
Add particle class methods for sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Dec 14, 2024
1 parent 7939778 commit b263b6b
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 93 deletions.
4 changes: 2 additions & 2 deletions src/CabanaPD_BodyTerm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ struct BodyTerm
void apply( ExecSpace, ParticleType& particles, const double time )
{
_timer.start();
Kokkos::RangePolicy<ExecSpace> policy( particles.n_frozen,
particles.n_local );
Kokkos::RangePolicy<ExecSpace> policy( particles.numFrozen(),
particles.numLocal() );
auto user = _user_functor;
Kokkos::parallel_for(
"CabanaPD::BodyTerm::apply", policy,
Expand Down
4 changes: 2 additions & 2 deletions src/CabanaPD_Boundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct BoundaryIndexSpace<MemorySpace, RegionBoundary<GeometryType>>
_timer.start();

_view = index_view_type( "boundary_indices",
particles.n_local * initial_guess );
particles.numLocal() * initial_guess );
_count = index_view_type( "count", 1 );

for ( RegionBoundary plane : planes )
Expand Down Expand Up @@ -169,7 +169,7 @@ struct BoundaryIndexSpace<MemorySpace, RegionBoundary<GeometryType>>
auto index_space = _view;
auto count = _count;
auto x = particles.sliceReferencePosition();
Kokkos::RangePolicy<ExecSpace> policy( 0, particles.n_local );
Kokkos::RangePolicy<ExecSpace> policy( 0, particles.numLocal() );
auto index_functor = KOKKOS_LAMBDA( const std::size_t pid )
{
if ( region.inside( x, pid ) )
Expand Down
2 changes: 1 addition & 1 deletion src/CabanaPD_Comm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class Comm<ParticleType, PMB, TemperatureIndependent>

// Create the Cabana Halo.
halo = std::make_shared<halo_type>( local_grid->globalGrid().comm(),
particles.n_local, halo_ids._ids,
particles.numLocal(), halo_ids._ids,
halo_ids._destinations, topology );

particles.resize( halo->numLocal(), halo->numGhost() );
Expand Down
2 changes: 1 addition & 1 deletion src/CabanaPD_DisplacementProfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void createOutputProfile( MPI_Comm comm, const int num_cell,
}
};
Kokkos::RangePolicy<typename memory_space::execution_space> policy(
0, particles.n_local );
0, particles.numLocal() );
Kokkos::parallel_for( "displacement_profile", policy, measure_profile );
auto count_host =
Kokkos::create_mirror_view_and_copy( Kokkos::HostSpace{}, count );
Expand Down
28 changes: 11 additions & 17 deletions src/CabanaPD_Force.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Force<MemorySpace, BaseForceModel>
const ParticleType& particles, const double tol = 1e-14 )
: _half_neigh( half_neigh )
, _neigh_list( neighbor_list_type( particles.sliceReferencePosition(),
0, particles.n_local, delta + tol,
0, particles.numLocal(), delta + tol,
1.0, particles.ghost_mesh_lo,
particles.ghost_mesh_hi ) )
{
Expand Down Expand Up @@ -239,7 +239,6 @@ template <class ForceType, class ParticleType, class ParallelType>
void computeForce( ForceType& force, ParticleType& particles,
const ParallelType& neigh_op_tag, const bool reset = true )
{
auto n_local = particles.n_local;
auto x = particles.sliceReferencePosition();
auto u = particles.sliceDisplacement();
auto f = particles.sliceForce();
Expand All @@ -251,14 +250,14 @@ void computeForce( ForceType& force, ParticleType& particles,

// if ( half_neigh )
// Forces must be atomic for half list
// computeForce_half( f_a, x, u, n_local,
// computeForce_half( f_a, x, u,
// neigh_op_tag );

// 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, n_local, neigh_op_tag );
force.computeForceFull( f_a, x, u, particles, neigh_op_tag );
else
force.computeForceFull( f, x, u, particles, n_local, neigh_op_tag );
force.computeForceFull( f, x, u, particles, neigh_op_tag );
Kokkos::fence();
}

Expand All @@ -269,7 +268,6 @@ double computeEnergy( ForceType& force, ParticleType& particles,
double energy = 0.0;
if constexpr ( is_energy_output<typename ParticleType::output_type>::value )
{
auto n_local = particles.n_local;
auto x = particles.sliceReferencePosition();
auto u = particles.sliceDisplacement();
auto f = particles.sliceForce();
Expand All @@ -281,10 +279,9 @@ double computeEnergy( ForceType& force, ParticleType& particles,

// if ( _half_neigh )
// energy = computeEnergy_half( force, x, u,
// n_local, neigh_op_tag );
// neigh_op_tag );
// else
energy = force.computeEnergyFull( W, x, u, particles, n_local,
neigh_op_tag );
energy = force.computeEnergyFull( W, x, u, particles, neigh_op_tag );
Kokkos::fence();
}
return energy;
Expand All @@ -296,7 +293,6 @@ template <class ForceType, class ParticleType, class NeighborView,
void computeForce( ForceType& force, ParticleType& particles, NeighborView& mu,
const ParallelType& neigh_op_tag, const bool reset = true )
{
auto n_local = particles.n_local;
auto x = particles.sliceReferencePosition();
auto u = particles.sliceDisplacement();
auto f = particles.sliceForce();
Expand All @@ -308,15 +304,14 @@ void computeForce( ForceType& force, ParticleType& particles, NeighborView& mu,

// if ( half_neigh )
// Forces must be atomic for half list
// computeForce_half( f_a, x, u, n_local,
// computeForce_half( f_a, x, u,
// neigh_op_tag );

// 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, mu, n_local,
neigh_op_tag );
force.computeForceFull( f_a, x, u, particles, mu, neigh_op_tag );
else
force.computeForceFull( f, x, u, particles, mu, n_local, neigh_op_tag );
force.computeForceFull( f, x, u, particles, mu, neigh_op_tag );
Kokkos::fence();
}

Expand All @@ -328,7 +323,6 @@ double computeEnergy( ForceType& force, ParticleType& particles,
double energy = 0.0;
if constexpr ( is_energy_output<typename ParticleType::output_type>::value )
{
auto n_local = particles.n_local;
auto x = particles.sliceReferencePosition();
auto u = particles.sliceDisplacement();
auto f = particles.sliceForce();
Expand All @@ -340,9 +334,9 @@ double computeEnergy( ForceType& force, ParticleType& particles,

// if ( _half_neigh )
// energy = computeEnergy_half( force, x, u,
// n_local, neigh_op_tag );
// neigh_op_tag );
// else
energy = force.computeEnergyFull( W, x, u, phi, particles, mu, n_local,
energy = force.computeEnergyFull( W, x, u, phi, particles, mu,
neigh_op_tag );
Kokkos::fence();
}
Expand Down
20 changes: 10 additions & 10 deletions src/CabanaPD_HeatTransfer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class HeatTransfer : public Force<MemorySpace, BaseForceModel>

template <class TemperatureType, class PosType, class ParticleType,
class ParallelType>
void
computeHeatTransferFull( TemperatureType& conduction, const PosType& x,
const PosType& u, const ParticleType& particles,
const int n_local, ParallelType& neigh_op_tag )
void computeHeatTransferFull( TemperatureType& conduction, const PosType& x,
const PosType& u,
const ParticleType& particles,
ParallelType& neigh_op_tag )
{
_timer.start();

Expand All @@ -70,7 +70,8 @@ class HeatTransfer : public Force<MemorySpace, BaseForceModel>
coeff * ( temp( j ) - temp( i ) ) / xi / xi * vol( j );
};

Kokkos::RangePolicy<exec_space> policy( particles.n_frozen, n_local );
Kokkos::RangePolicy<exec_space> policy( particles.numFrozen(),
particles.numLocal() );
Cabana::neighbor_parallel_for(
policy, temp_func, _neigh_list, Cabana::FirstNeighborsTag(),
neigh_op_tag, "CabanaPD::HeatTransfer::computeFull" );
Expand All @@ -86,12 +87,12 @@ class HeatTransfer : public Force<MemorySpace, BaseForceModel>
const auto rho = particles.sliceDensity();
const auto conduction = particles.sliceTemperatureConduction();
auto temp = particles.sliceTemperature();
auto n_local = particles.n_local;
auto euler_func = KOKKOS_LAMBDA( const int i )
{
temp( i ) += dt / rho( i ) / model.cp * conduction( i );
};
Kokkos::RangePolicy<exec_space> policy( particles.n_frozen, n_local );
Kokkos::RangePolicy<exec_space> policy( particles.numFrozen(),
particles.numLocal() );
Kokkos::parallel_for( "CabanaPD::HeatTransfer::forwardEuler", policy,
euler_func );
_euler_timer.stop();
Expand All @@ -104,7 +105,6 @@ void computeHeatTransfer( HeatTransferType& heat_transfer,
ParticleType& particles,
const ParallelType& neigh_op_tag, const double dt )
{
auto n_local = particles.n_local;
auto x = particles.sliceReferencePosition();
auto u = particles.sliceDisplacement();
auto conduction = particles.sliceTemperatureConduction();
Expand All @@ -116,10 +116,10 @@ void computeHeatTransfer( HeatTransferType& heat_transfer,
// Temperature only needs to be atomic if using team threading.
if ( std::is_same<decltype( neigh_op_tag ), Cabana::TeamOpTag>::value )
heat_transfer.computeHeatTransferFull( conduction_a, x, u, particles,
n_local, neigh_op_tag );
neigh_op_tag );
else
heat_transfer.computeHeatTransferFull( conduction, x, u, particles,
n_local, neigh_op_tag );
neigh_op_tag );
Kokkos::fence();

heat_transfer.forwardEuler( particles, dt );
Expand Down
4 changes: 2 additions & 2 deletions src/CabanaPD_Integrate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Integrator
u( i, 1 ) += dt * v( i, 1 );
u( i, 2 ) += dt * v( i, 2 );
};
Kokkos::RangePolicy<exec_space> policy( p.n_frozen, p.n_local );
Kokkos::RangePolicy<exec_space> policy( p.numFrozen(), p.numLocal() );
Kokkos::parallel_for( "CabanaPD::Integrator::Initial", policy,
init_func );

Expand All @@ -130,7 +130,7 @@ class Integrator
v( i, 1 ) += half_dt_m * f( i, 1 );
v( i, 2 ) += half_dt_m * f( i, 2 );
};
Kokkos::RangePolicy<exec_space> policy( p.n_frozen, p.n_local );
Kokkos::RangePolicy<exec_space> policy( p.numFrozen(), p.numLocal() );
Kokkos::parallel_for( "CabanaPD::Integrator::Final", policy,
final_func );

Expand Down
6 changes: 6 additions & 0 deletions src/CabanaPD_Particles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
_timer.stop();
}

auto numFrozen() const { return n_frozen; }
auto numLocal() const { return n_local; }
auto numGhost() const { return n_ghost; }
auto numReference() const { return size; }
auto numGlobal() const { return n_global; }

auto sliceReferencePosition()
{
return _plist_x.slice( CabanaPD::Field::ReferencePosition() );
Expand Down
22 changes: 11 additions & 11 deletions src/CabanaPD_Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class SolverElastic
print = print_rank();
if ( print )
{
log( std::cout, "Local particles: ", particles->n_local,
log( std::cout, "Local particles: ", particles->numLocal(),
", Maximum neighbors: ", max_neighbors );
log( std::cout, "#Timestep/Total-steps Simulation-time" );

Expand All @@ -212,8 +212,8 @@ class SolverElastic
exec_space().print_configuration( out );

log( out, "Local particles, Ghosted particles, Global particles\n",
particles->n_local, ", ", particles->n_ghost, ", ",
particles->n_global );
particles->numLocal(), ", ", particles->numGhost(), ", ",
particles->numGlobal() );
log( out, "Maximum neighbors: ", max_neighbors,
", Total neighbors: ", total_neighbors, "\n" );
out.close();
Expand Down Expand Up @@ -407,7 +407,7 @@ class SolverElastic
double energy_time = force->timeEnergy();
double output_time = particles->timeOutput();
_total_time += step_time;
auto rate = static_cast<double>( particles->n_global *
auto rate = static_cast<double>( particles->numGlobal() *
output_frequency / ( step_time ) );
_step_timer.reset();
log( out, std::fixed, std::setprecision( 6 ), step, "/", num_steps,
Expand All @@ -434,15 +434,15 @@ class SolverElastic
energy_time + output_time + particles->time();

double steps_per_sec = 1.0 * num_steps / _total_time;
double p_steps_per_sec = particles->n_global * steps_per_sec;
double p_steps_per_sec = particles->numGlobal() * steps_per_sec;
log( out, std::fixed, std::setprecision( 2 ),
"\n#Procs Particles | Total Force Comm Integrate Energy "
"Output Init Init_Neighbor |\n",
comm->mpi_size, " ", particles->n_global, " | \t", _total_time,
" ", force_time, " ", comm_time, " ", integrate_time, " ",
energy_time, " ", output_time, " ", _init_time, " ",
neighbor_time, " | PERFORMANCE\n", std::fixed, comm->mpi_size,
" ", particles->n_global, " | \t", 1.0, " ",
comm->mpi_size, " ", particles->numGlobal(), " | \t",
_total_time, " ", force_time, " ", comm_time, " ",
integrate_time, " ", energy_time, " ", output_time, " ",
_init_time, " ", neighbor_time, " | PERFORMANCE\n", std::fixed,
comm->mpi_size, " ", particles->numGlobal(), " | \t", 1.0, " ",
force_time / _total_time, " ", comm_time / _total_time, " ",
integrate_time / _total_time, " ", energy_time / _total_time,
" ", output_time / _total_time, " ", _init_time / _total_time,
Expand Down Expand Up @@ -531,7 +531,7 @@ class SolverFracture
auto max_neighbors = force->getMaxLocalNeighbors();
mu = NeighborView(
Kokkos::ViewAllocateWithoutInitializing( "broken_bonds" ),
particles->n_local, max_neighbors );
particles->numLocal(), max_neighbors );
Kokkos::deep_copy( mu, 1 );
_init_timer.stop();
}
Expand Down
5 changes: 3 additions & 2 deletions src/force/CabanaPD_Force_Contact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Force<MemorySpace, NormalRepulsionModel>
Force( const bool half_neigh, const ParticleType& particles,
const NormalRepulsionModel model )
: base_type( half_neigh, model.Rc, particles.sliceCurrentPosition(),
particles.n_local, particles.ghost_mesh_lo,
particles.numLocal(), particles.ghost_mesh_lo,
particles.ghost_mesh_hi )
, _model( model )
{
Expand All @@ -49,14 +49,15 @@ class Force<MemorySpace, NormalRepulsionModel>
template <class ForceType, class PosType, class ParticleType,
class ParallelType>
void computeForceFull( ForceType& fc, const PosType& x, const PosType& u,
const ParticleType& particles, const int n_local,
const ParticleType& particles,
ParallelType& neigh_op_tag )
{
auto delta = _model.delta;
auto Rc = _model.Rc;
auto c = _model.c;
const auto vol = particles.sliceVolume();
const auto y = particles.sliceCurrentPosition();
const int n_local = particles.numLocal();

_neigh_timer.start();
_neigh_list.build( y, 0, n_local, Rc, 1.0, mesh_min, mesh_max );
Expand Down
Loading

0 comments on commit b263b6b

Please sign in to comment.