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

Make energy optional #154

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
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