Skip to content

Commit

Permalink
finished neighbors in force and optional contact in base solvers;
Browse files Browse the repository at this point in the history
moved prenotch to init for simplicity
  • Loading branch information
streeve committed Nov 12, 2024
1 parent 41ff650 commit 8549846
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 82 deletions.
4 changes: 2 additions & 2 deletions examples/mechanics/crack_branching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void crackBranchingExample( const std::string filename )
// Create solver
// ====================================================
auto cabana_pd = CabanaPD::createSolverFracture<memory_space>(
inputs, particles, force_model, prenotch );
inputs, particles, force_model );

// ====================================================
// Boundary conditions
Expand All @@ -137,7 +137,7 @@ void crackBranchingExample( const std::string filename )
// ====================================================
// Simulation run
// ====================================================
cabana_pd->init();
cabana_pd->init( bc, prenotch );
cabana_pd->run( bc );
}

Expand Down
4 changes: 2 additions & 2 deletions examples/mechanics/kalthoff_winkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void kalthoffWinklerExample( const std::string filename )
// Create solver
// ====================================================
auto cabana_pd = CabanaPD::createSolverFracture<memory_space>(
inputs, particles, force_model, prenotch );
inputs, particles, force_model );

// ====================================================
// Boundary conditions
Expand All @@ -132,7 +132,7 @@ void kalthoffWinklerExample( const std::string filename )
// ====================================================
// Simulation run
// ====================================================
cabana_pd->init();
cabana_pd->init( bc, prenotch );
cabana_pd->run( bc );
}

Expand Down
15 changes: 9 additions & 6 deletions src/CabanaPD_Contact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ class Force<MemorySpace, NormalRepulsionModel>
using base_type = Force<MemorySpace, BaseForceModel>;

template <class ParticleType>
Force( const bool half_neigh, const NormalRepulsionModel model,
ParticleType& particles )
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->ghost_mesh_hi )
particles.n_local, particles.ghost_mesh_lo,
particles.ghost_mesh_hi )
, _model( model )
{
mesh_min[3] = particles->ghost_mesh_lo;
mesh_max[3] = particles->ghost_mesh_hi;
for ( int d = 0; d < particles.dim; d++ )
{
mesh_min[d] = particles.ghost_mesh_lo[d];
mesh_max[d] = particles.ghost_mesh_hi[d];
}
}

template <class ForceType, class ParticleType, class ParallelType>
Expand Down
122 changes: 62 additions & 60 deletions src/CabanaPD_Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ class SolverElastic
: inputs( _inputs )
, particles( _particles )
, _init_time( 0.0 )
{
setup( force_model );
}

SolverElastic( input_type _inputs,
std::shared_ptr<particle_type> _particles,
force_model_type force_model,
contact_model_type contact_model )
: inputs( _inputs )
, particles( _particles )
, _init_time( 0.0 )
{
setup( force_model );

_neighbor_timer.start();
contact = std::make_shared<contact_type>( inputs["half_neigh"],
*particles, contact_model );
_neighbor_timer.stop();
}

void setup( force_model_type force_model )
{
num_steps = inputs["num_steps"];
output_frequency = inputs["output_frequency"];
Expand All @@ -144,23 +165,14 @@ class SolverElastic
{
thermal_subcycle_steps = inputs["thermal_subcycle_steps"];
heat_transfer = std::make_shared<heat_transfer_type>(
inputs["half_neigh"], force_model );
inputs["half_neigh"], *particles, force_model );
}

// Create contact and primary forces as needed.
if constexpr ( is_contact<contact_model_type>::value )
{
contact = std::make_shared<contact_type>(
_inputs["half_neigh"], contact_model, *particles );
}
else
{
// This will either be PD or DEM forces.
_neighbor_timer.start();
force = std::make_shared<force_type>( inputs["half_neigh"],
force_model );
_neighbor_timer.stop();
}
// This will either be PD or DEM forces.
_neighbor_timer.start();
force = std::make_shared<force_type>( inputs["half_neigh"], *particles,
force_model );
_neighbor_timer.stop();

_init_timer.start();
unsigned max_neighbors;
Expand Down Expand Up @@ -464,8 +476,8 @@ class SolverFracture
ContactModel>
{
public:
using base_type =
SolverElastic<MemorySpace, InputType, ParticleType, ForceModel>;
using base_type = SolverElastic<MemorySpace, InputType, ParticleType,
ForceModel, ContactModel>;
using exec_space = typename base_type::exec_space;
using memory_space = typename base_type::memory_space;

Expand All @@ -479,19 +491,6 @@ class SolverFracture

using contact_model_type = ContactModel;

template <typename PrenotchType>
SolverFracture( input_type _inputs,
std::shared_ptr<particle_type> _particles,
force_model_type force_model, PrenotchType prenotch )
: base_type( _inputs, _particles, force_model )
{
init_mu();

// Create prenotch.
prenotch.create( exec_space{}, mu, *particles, force->neigh_list );
_init_time += prenotch.time();
}

SolverFracture( input_type _inputs,
std::shared_ptr<particle_type> _particles,
force_model_type force_model )
Expand Down Expand Up @@ -521,6 +520,14 @@ class SolverFracture
_init_timer.stop();
}

template <std::size_t NumPrenotch>
void init_prenotch( Prenotch<NumPrenotch> prenotch )
{
// Create prenotch.
prenotch.create( exec_space{}, mu, *particles, force->neigh_list );
_init_time += prenotch.time();
}

void init( const bool initial_output = true )
{
// Compute initial internal forces and energy.
Expand All @@ -531,6 +538,14 @@ class SolverFracture
particles->output( 0, 0.0, output_reference );
}

template <std::size_t NumPrenotch>
void init( Prenotch<NumPrenotch> prenotch,
const bool initial_output = true )
{
init_prenotch( prenotch );
init( initial_output );
}

template <typename BoundaryType>
void init( BoundaryType boundary_condition,
const bool initial_output = true )
Expand All @@ -555,6 +570,14 @@ class SolverFracture
particles->output( 0, 0.0, output_reference );
}

template <typename BoundaryType, std::size_t NumPrenotch>
void init( BoundaryType boundary_condition, Prenotch<NumPrenotch> prenotch,
const bool initial_output = true )
{
init_prenotch( prenotch );
init( boundary_condition, initial_output );
}

template <typename BoundaryType>
void run( BoundaryType boundary_condition )
{
Expand Down Expand Up @@ -695,47 +718,26 @@ class SolverFracture
// ===============================================================

template <class MemorySpace, class InputsType, class ParticleType,
class ForceModel, class ContactModel = void>
class ForceModel, class... ContactModelType>
auto createSolverElastic( InputsType inputs,
std::shared_ptr<ParticleType> particles,
ForceModel model )
{
return std::make_shared<
SolverElastic<MemorySpace, InputsType, ParticleType, ForceModel>>(
inputs, particles, model );
}

template <class MemorySpace, class InputsType, class ParticleType,
class ForceModel, class ContactModel = void>
auto createSolverElastic( InputsType inputs,
std::shared_ptr<ParticleType> particles,
ForceModel model, ContactModel contact )
ForceModel model, ContactModelType... contact_model )
{
return std::make_shared<SolverElastic<MemorySpace, InputsType, ParticleType,
ForceModel, ContactModel>>(
inputs, particles, model, contact );
}

template <class MemorySpace, class InputsType, class ParticleType,
class ForceModel>
auto createSolverFracture( InputsType inputs,
std::shared_ptr<ParticleType> particles,
ForceModel model )
{
return std::make_shared<
SolverFracture<MemorySpace, InputsType, ParticleType, ForceModel>>(
inputs, particles, model );
ForceModel, ContactModelType...>>(
inputs, particles, model, contact_model... );
}

template <class MemorySpace, class InputsType, class ParticleType,
class ForceModel, class PrenotchType>
class ForceModel, class... ContactModelType>
auto createSolverFracture( InputsType inputs,
std::shared_ptr<ParticleType> particles,
ForceModel model, PrenotchType prenotch )
ForceModel model, ContactModelType... contact_model )
{
return std::make_shared<
SolverFracture<MemorySpace, InputsType, ParticleType, ForceModel>>(
inputs, particles, model, prenotch );
SolverFracture<MemorySpace, InputsType, ParticleType, ForceModel,
ContactModelType...>>( inputs, particles, model,
contact_model... );
}

} // namespace CabanaPD
Expand Down
8 changes: 1 addition & 7 deletions src/CabanaPD_Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ struct Fracture
};

// Contact and DEM (contact without PD) tags.
struct DEM
{
};

struct Contact
{
};
Expand All @@ -40,10 +38,6 @@ template <>
struct is_contact<Contact> : public std::true_type
{
};
template <>
struct is_contact<DEM> : public std::true_type
{
};

// Thermal tags.
struct TemperatureIndependent
Expand Down
5 changes: 3 additions & 2 deletions src/force/CabanaPD_Force_LPS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ class Force<MemorySpace, ForceModel<LPS, Fracture>>
using base_type::neigh_list;

template <class ParticleType>
Force( const bool half_neigh, const ForceModel<LPS, Fracture> model )
: base_type( half_neigh, model )
Force( const bool half_neigh, const ParticleType& particles,
const ForceModel<LPS, Fracture> model )
: base_type( half_neigh, particles, model )
, _model( model )
{
}
Expand Down
6 changes: 3 additions & 3 deletions unit_test/tstForce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,15 @@ struct NoDamageTag
{
};

template <class ForceType, class ParticleType, class NeighborList>
template <class ForceType, class ParticleType>
double computeEnergyAndForce( NoDamageTag, ForceType force,
ParticleType& particles, const int )
{
computeForce( force, particles, Cabana::SerialOpTag() );
double Phi = computeEnergy( force, particles, Cabana::SerialOpTag() );
return Phi;
}
template <class ForceType, class ParticleType, class NeighborList>
template <class ForceType, class ParticleType>
double computeEnergyAndForce( DamageTag, ForceType force,
ParticleType& particles, const int max_neighbors )
{
Expand Down Expand Up @@ -701,7 +701,7 @@ void testForce( ModelType model, const DamageType damage_tag, const double dx,
initializeForce( model, force, particles );

unsigned int max_neighbors;
unsigned int total_neighbors;
unsigned long long total_neighbors;
force.getNeighborStatistics( max_neighbors, total_neighbors );
double Phi =
computeEnergyAndForce( damage_tag, force, particles, max_neighbors );
Expand Down

0 comments on commit 8549846

Please sign in to comment.