Skip to content

Commit

Permalink
Merge pull request #154 from streeve/optional_energy
Browse files Browse the repository at this point in the history
Make energy optional
  • Loading branch information
streeve authored Nov 27, 2024
2 parents 788b280 + 863e2e0 commit e5dd9e1
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 155 deletions.
81 changes: 42 additions & 39 deletions src/CabanaPD_Force.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,25 +252,27 @@ template <class ForceType, class ParticleType, class ParallelType>
double computeEnergy( ForceType& force, ParticleType& particles,
const ParallelType& neigh_op_tag )
{
auto n_local = particles.n_local;
auto x = particles.sliceReferencePosition();
auto u = particles.sliceDisplacement();
auto f = particles.sliceForce();
auto W = particles.sliceStrainEnergy();
auto vol = particles.sliceVolume();

// Reset energy.
Cabana::deep_copy( W, 0.0 );

double energy;
// if ( _half_neigh )
// energy = computeEnergy_half( force, x, u,
// n_local, neigh_op_tag );
// else
energy =
force.computeEnergyFull( W, x, u, particles, n_local, neigh_op_tag );
Kokkos::fence();

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();
auto W = particles.sliceStrainEnergy();
auto vol = particles.sliceVolume();

// Reset energy.
Cabana::deep_copy( W, 0.0 );

// if ( _half_neigh )
// energy = computeEnergy_half( force, x, u,
// n_local, neigh_op_tag );
// else
energy = force.computeEnergyFull( W, x, u, particles, n_local,
neigh_op_tag );
Kokkos::fence();
}
return energy;
}

Expand Down Expand Up @@ -303,31 +305,32 @@ void computeForce( ForceType& force, ParticleType& particles, NeighborView& mu,
Kokkos::fence();
}

// Energy and damage.
template <class ForceType, class ParticleType, class NeighborView,
class ParallelType>
double computeEnergy( ForceType& force, ParticleType& particles,
NeighborView& mu, const ParallelType& neigh_op_tag )
{
auto n_local = particles.n_local;
auto x = particles.sliceReferencePosition();
auto u = particles.sliceDisplacement();
auto f = particles.sliceForce();
auto W = particles.sliceStrainEnergy();
auto phi = particles.sliceDamage();

// Reset energy.
Cabana::deep_copy( W, 0.0 );

double energy;
// if ( _half_neigh )
// energy = computeEnergy_half( force, x, u,
// n_local, neigh_op_tag );
// else
energy = force.computeEnergyFull( W, x, u, phi, particles, mu, n_local,
neigh_op_tag );
Kokkos::fence();

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();
auto W = particles.sliceStrainEnergy();
auto phi = particles.sliceDamage();

// Reset energy.
Cabana::deep_copy( W, 0.0 );

// if ( _half_neigh )
// energy = computeEnergy_half( force, x, u,
// n_local, neigh_op_tag );
// else
energy = force.computeEnergyFull( W, x, u, phi, particles, mu, n_local,
neigh_op_tag );
Kokkos::fence();
}
return energy;
}

Expand Down
Loading

0 comments on commit e5dd9e1

Please sign in to comment.