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

Virial stress #137

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
594f5cb
added virial stress variable to lines 372 and 374 (const). Adjusted l…
kinanbezem7 Oct 16, 2024
45641a9
added virial stress calculation to energy_full in force_PMB
kinanbezem7 Oct 16, 2024
a1c497a
Corrected errors in build, unsure about bond breakage criteria in the…
kinanbezem7 Oct 17, 2024
db419fb
Corrected particles.hpp which was causing NaNs in the output
kinanbezem7 Oct 17, 2024
112b5cb
output virial stress
kinanbezem7 Oct 17, 2024
c3c6c9f
cleaned up previous runs from repo
kinanbezem7 Oct 17, 2024
8cfbe4e
Moved slices outside of kernel and adjust virial stress calculations …
kinanbezem7 Oct 18, 2024
3ab38ff
fixup: format
streeve Oct 18, 2024
d5f327b
fixup: remove const on particles
streeve Oct 18, 2024
a6a3a49
Remove .vscode directory from repository
kinanbezem7 Oct 18, 2024
108f53c
Made suggested formatting changes and virial stress is now working fo…
kinanbezem7 Oct 18, 2024
75e8fbc
Virial stress added for PMB fracture problem.
kinanbezem7 Oct 22, 2024
74e5511
Applied clang-format changes to CabanaPD_Particles.hpp and Force_PMB.hpp
kinanbezem7 Oct 24, 2024
493bc3f
Changed the claculation of the stress tensor using a new reference
pabloseleson Nov 19, 2024
b63fc69
Revised commment
pabloseleson Nov 19, 2024
46d28ea
Changed stress computation adding all 9 components due to lack of sym…
pabloseleson Nov 21, 2024
bd6311d
Merge branch 'main' into virialStress
streeve Nov 21, 2024
d7d869c
Make energy/stress optional in particle lists
streeve Nov 21, 2024
d1ad096
Fixed stress dimension
pabloseleson Nov 22, 2024
3e054ef
Added stress calculation to linear PMB model
pabloseleson Nov 22, 2024
8de53b6
Finish optional energy/stress
streeve Nov 22, 2024
66ea5ad
Merge branch 'main' into virialStress
streeve Dec 4, 2024
090317e
Merge branch 'virialStress' into virialStress
streeve Dec 4, 2024
982bcec
fixup: compute free functions
streeve Dec 4, 2024
c5a598c
fixup: remove linear pmb stress
streeve Dec 4, 2024
c41e88e
Revert unneeded changes
streeve Dec 9, 2024
aef9d08
Fixed return error on stress function
kinanbezem7 Dec 18, 2024
948439e
New example file for testing stress
kinanbezem7 Dec 19, 2024
6197b95
added stress to linear PMB
kinanbezem7 Dec 19, 2024
a118af4
corrected linearized distance
kinanbezem7 Dec 20, 2024
fb87332
Added stress to LPS (not tested)
kinanbezem7 Dec 20, 2024
72469c4
format
kinanbezem7 Dec 20, 2024
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
build/
*.out
*.silo
run/
.vscode/
2 changes: 1 addition & 1 deletion examples/mechanics/crack_branching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void crackBranchingExample( const std::string filename )
// ====================================================
// Note that individual inputs can be passed instead (see other examples).
auto particles = CabanaPD::createParticles<memory_space, model_type>(
exec_space{}, inputs );
exec_space{}, inputs, CabanaPD::EnergyStressOutput{} );

// ====================================================
// Boundary conditions planes
Expand Down
33 changes: 33 additions & 0 deletions src/CabanaPD_Force.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class Force<MemorySpace, BaseForceModel>

Timer _timer;
Timer _energy_timer;
Timer _stress_timer;

public:
using neighbor_list_type =
Expand Down Expand Up @@ -276,6 +277,22 @@ double computeEnergy( ForceType& force, ParticleType& particles,
return energy;
}

template <class ForceType, class ParticleType, class ParallelType>
void computeStress( ForceType& force, ParticleType& particles,
const ParallelType& neigh_op_tag )
{
if constexpr ( is_stress_output<typename ParticleType::output_type>::value )
{
auto stress = particles.sliceStress();

// Reset stress.
Cabana::deep_copy( stress, 0.0 );

force.computeStressFull( particles, neigh_op_tag );
Kokkos::fence();
}
}

// Forces with bond breaking.
template <class ForceType, class ParticleType, class NeighborView,
class ParallelType>
Expand Down Expand Up @@ -334,6 +351,22 @@ double computeEnergy( ForceType& force, ParticleType& particles,
return energy;
}

template <class ForceType, class ParticleType, class NeighborView,
class ParallelType>
void computeStress( ForceType& force, ParticleType& particles, NeighborView& mu,
const ParallelType& neigh_op_tag )
{
if constexpr ( is_stress_output<typename ParticleType::output_type>::value )
{
auto stress = particles.sliceStress();

// Reset stress.
Cabana::deep_copy( stress, 0.0 );

force.computeStressFull( particles, mu, neigh_op_tag );
Kokkos::fence();
}
}
} // namespace CabanaPD

#endif
112 changes: 112 additions & 0 deletions src/CabanaPD_Particles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension>
return Cabana::slice<0>( _aosoa_u, "displacements" );
}
auto sliceForce() { return _plist_f.slice( CabanaPD::Field::Force() ); }

auto sliceForce() const
{
return _plist_f.slice( CabanaPD::Field::Force() );
}

auto sliceForceAtomic()
{
auto f = sliceForce();
Expand Down Expand Up @@ -864,6 +870,112 @@ class Particles<MemorySpace, ModelType, ThermalType, EnergyOutput, Dimension>
aosoa_output_type _aosoa_output;
};

template <class MemorySpace, class ModelType, class ThermalType, int Dimension>
class Particles<MemorySpace, ModelType, ThermalType, EnergyStressOutput,
Dimension>
: public Particles<MemorySpace, ModelType, ThermalType, EnergyOutput,
Dimension>
{
public:
using self_type = Particles<MemorySpace, ModelType, ThermalType,
EnergyStressOutput, Dimension>;
using base_type =
Particles<MemorySpace, ModelType, ThermalType, EnergyOutput, Dimension>;
using thermal_type = typename base_type::thermal_type;
using output_type = EnergyStressOutput;
using memory_space = typename base_type::memory_space;
using base_type::dim;

// Per particle.
using base_type::n_ghost;
using base_type::n_global;
using base_type::n_local;
using base_type::size;

using output_types = Cabana::MemberTypes<double[dim][dim]>;
using aosoa_output_type = Cabana::AoSoA<output_types, memory_space, 1>;

// Per type.
using base_type::n_types;

// Simulation total domain.
using base_type::global_mesh_ext;

// Simulation sub domain (single MPI rank).
using base_type::ghost_mesh_hi;
using base_type::ghost_mesh_lo;
using base_type::local_mesh_ext;
using base_type::local_mesh_hi;
using base_type::local_mesh_lo;

using base_type::dx;
using base_type::local_grid;

using base_type::halo_width;

// Default constructor.
Particles()
: base_type()
{
_aosoa_output = aosoa_output_type( "Particle Stress Output", 0 );
}

// Constructor which initializes particles on regular grid.
template <class ExecSpace>
Particles( const ExecSpace& exec_space, std::array<double, dim> low_corner,
std::array<double, dim> high_corner,
const std::array<int, dim> num_cells, const int max_halo_width )
: base_type( exec_space, low_corner, high_corner, num_cells,
max_halo_width )
{
_aosoa_output = aosoa_output_type( "Particle Stress Output", n_local );
init_output();
}

template <typename... Args>
void createParticles( Args&&... args )
{
// Forward arguments to standard or custom particle creation.
base_type::createParticles( std::forward<Args>( args )... );
_aosoa_output.resize( n_local );
}

auto sliceStress() { return Cabana::slice<0>( _aosoa_output, "stress" ); }
auto sliceStress() const
{
return Cabana::slice<0>( _aosoa_output, "stress" );
}

void resize( int new_local, int new_ghost )
{
base_type::resize( new_local, new_ghost );
_aosoa_output.resize( new_local + new_ghost );
}

template <typename... OtherFields>
void output( const int output_step, const double output_time,
const bool use_reference, OtherFields&&... other )
{
base_type::output( output_step, output_time, use_reference,
sliceStress(),
std::forward<OtherFields>( other )... );
}

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>;

protected:
void init_output()
{
auto stress = sliceStress();
Cabana::deep_copy( stress, 0.0 );
}

aosoa_output_type _aosoa_output;
};

template <typename MemorySpace, typename ModelType, typename ExecSpace,
typename OutputType>
auto createParticles( ExecSpace exec_space, CabanaPD::Inputs inputs,
Expand Down
4 changes: 4 additions & 0 deletions src/CabanaPD_Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class SolverElastic
// Compute initial internal forces and energy.
updateForce();
computeEnergy( *force, *particles, neigh_iter_tag() );
computeStress( *force, *particles, neigh_iter_tag() );

if ( initial_output )
particles->output( 0, 0.0, output_reference );
Expand Down Expand Up @@ -320,6 +321,7 @@ class SolverElastic
if ( step % output_frequency == 0 )
{
auto W = computeEnergy( *force, *particles, neigh_iter_tag() );
computeStress( *force, *particles, neigh_iter_tag() );

particles->output( step / output_frequency, step * dt,
output_reference );
Expand Down Expand Up @@ -494,6 +496,7 @@ class SolverFracture
// Compute initial internal forces and energy.
updateForce();
computeEnergy( *force, *particles, mu, neigh_iter_tag() );
computeStress( *force, *particles, mu, neigh_iter_tag() );

if ( initial_output )
particles->output( 0, 0.0, output_reference );
Expand Down Expand Up @@ -619,6 +622,7 @@ class SolverFracture
if ( step % output_frequency == 0 )
{
auto W = computeEnergy( *force, *particles, mu, neigh_iter_tag() );
computeStress( *force, *particles, mu, neigh_iter_tag() );

particles->output( step / output_frequency, step * dt,
output_reference );
Expand Down
16 changes: 16 additions & 0 deletions src/CabanaPD_Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ struct BaseOutput
struct EnergyOutput
{
};
struct EnergyStressOutput
{
};

template <class>
struct is_energy_output : public std::false_type
Expand All @@ -87,6 +90,19 @@ template <>
struct is_energy_output<EnergyOutput> : public std::true_type
{
};
template <>
struct is_energy_output<EnergyStressOutput> : public std::true_type
{
};

template <class>
struct is_stress_output : public std::false_type
{
};
template <>
struct is_stress_output<EnergyStressOutput> : public std::true_type
{
};

} // namespace CabanaPD
#endif
Loading
Loading