Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
kinanbezem7 committed Dec 20, 2024
1 parent fb87332 commit 72469c4
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 149 deletions.
Empty file added =0.11.1
Empty file.
Empty file added =1.0.0
Empty file.
39 changes: 21 additions & 18 deletions examples/mechanics/central_crack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,33 @@ void centralCrackExample( const std::string filename )
double crack_length = 0.01; // Crack length is 10 mm

// Assume the plate is symmetric, ranging from -0.025 to +0.025
double plate_center_x = 0.0; // Center is at 0 for symmetric coordinates
double plate_center_y = 0.0; // Center is at 0 for symmetric coordinates
double plate_center_x = 0.0; // Center is at 0 for symmetric coordinates
double plate_center_y = 0.0; // Center is at 0 for symmetric coordinates

// Define the crack start and end points for a horizontal crack
Kokkos::Array<double, 3> crack_start = {
plate_center_x - (crack_length / 2.0), // Center the crack along the x-axis
plate_center_y, // Center the crack along the y-axis
0.0 // Assume the crack lies in the z=0 plane
Kokkos::Array<double, 3> crack_start = {
plate_center_x -
( crack_length / 2.0 ), // Center the crack along the x-axis
plate_center_y, // Center the crack along the y-axis
0.0 // Assume the crack lies in the z=0 plane
};
Kokkos::Array<double, 3> crack_end = {
plate_center_x + (crack_length / 2.0), // Center the crack along the x-axis
plate_center_y, // Center the crack along the y-axis
0.0 // Assume the crack lies in the z=0 plane
Kokkos::Array<double, 3> crack_end = {
plate_center_x +
( crack_length / 2.0 ), // Center the crack along the x-axis
plate_center_y, // Center the crack along the y-axis
0.0 // Assume the crack lies in the z=0 plane
};

// Compute the vector defining the crack
Kokkos::Array<double, 3> crack_vector = {
crack_end[0] - crack_start[0],
crack_end[1] - crack_start[1],
crack_end[2] - crack_start[2]
};
Kokkos::Array<double, 3> crack_vector = { crack_end[0] - crack_start[0],
crack_end[1] - crack_start[1],
crack_end[2] - crack_start[2] };

// Define the crack using Prenotch
Kokkos::Array<Kokkos::Array<double, 3>, 2> notch_positions = { crack_start, crack_end };
CabanaPD::Prenotch<2> prenotch( crack_vector, { 0.0, 0.0, thickness }, notch_positions );
Kokkos::Array<Kokkos::Array<double, 3>, 2> notch_positions = { crack_start,
crack_end };
CabanaPD::Prenotch<2> prenotch( crack_vector, { 0.0, 0.0, thickness },
notch_positions );

// ====================================================
// Force model
Expand Down Expand Up @@ -148,7 +150,8 @@ void centralCrackExample( const std::string filename )
auto bc_op = KOKKOS_LAMBDA( const int pid, const double )
{
auto ypos = x( pid, 1 );
auto sign = (ypos > (low_corner[1] + high_corner[1]) / 2.0) ? 1.0 : -1.0;
auto sign =
( ypos > ( low_corner[1] + high_corner[1] ) / 2.0 ) ? 1.0 : -1.0;
f( pid, 1 ) += b0 * sign;
};
auto bc = createBoundaryCondition( bc_op, exec_space{}, *particles, planes,
Expand Down
2 changes: 1 addition & 1 deletion examples/mechanics/inputs/crack_branching.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"timestep_safety_factor" : {"value": 0.85},
"output_frequency" : {"value": 5},
"output_reference" : {"value": true}
}
}
2 changes: 1 addition & 1 deletion examples/mechanics/inputs/plate_tension.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"timestep_safety_factor" : {"value": 0.85},
"output_frequency" : {"value": 5},
"output_reference" : {"value": true}
}
}
168 changes: 86 additions & 82 deletions src/force/CabanaPD_Force_LPS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ class Force<MemorySpace, ForceModel<LPS, Elastic>>
auto timeEnergy() { return _energy_timer.time(); };

template <class ParticleType, class ParallelType>
void computeStressFull(ParticleType& particles, const MuView& mu, ParallelType& neigh_op_tag)
void computeStressFull( ParticleType& particles, const MuView& mu,
ParallelType& neigh_op_tag )
{
_stress_timer.start();

Expand All @@ -269,57 +270,59 @@ class Force<MemorySpace, ForceModel<LPS, Elastic>>
const auto m = particles.sliceWeightedVolume();
auto stress = particles.sliceStress();

auto stress_full = KOKKOS_LAMBDA(const int i)
auto stress_full = KOKKOS_LAMBDA( const int i )
{
std::size_t num_neighbors =
Cabana::NeighborList<neighbor_list_type>::numNeighbor(
neigh_list, i);
for (std::size_t n = 0; n < num_neighbors; n++)
neigh_list, i );
for ( std::size_t n = 0; n < num_neighbors; n++ )
{
std::size_t j =
Cabana::NeighborList<neighbor_list_type>::getNeighbor(
neigh_list, i, n);
if (mu(i, n) > 0) // Only compute stress for unbroken bonds
neigh_list, i, n );

if ( mu( i, n ) > 0 ) // Only compute stress for unbroken bonds
{
double xi, r, s;
double rx, ry, rz;
getDistanceComponents(x, u, i, j, xi, r, s, rx, ry, rz);
getDistanceComponents( x, u, i, j, xi, r, s, rx, ry, rz );

const double coeff =
(model.theta_coeff * (theta(i) / m(i) + theta(j) / m(j)) +
model.s_coeff * s * (1.0 / m(i) + 1.0 / m(j))) *
model.influence_function(xi) * xi * vol(j) * vol(j);
const double coeff =
( model.theta_coeff *
( theta( i ) / m( i ) + theta( j ) / m( j ) ) +
model.s_coeff * s *
( 1.0 / m( i ) + 1.0 / m( j ) ) ) *
model.influence_function( xi ) * xi * vol( j ) *
vol( j );

double muij = mu(i, n);
double muij = mu( i, n );
double fx_i = muij * coeff * rx / r;
double fy_i = muij * coeff * ry / r;
double fz_i = muij * coeff * rz / r;

// Update stress tensor components
stress(i, 0, 0) += fx_i * rx;
stress(i, 1, 1) += fy_i * ry;
stress(i, 2, 2) += fz_i * rz;
stress( i, 0, 0 ) += fx_i * rx;
stress( i, 1, 1 ) += fy_i * ry;
stress( i, 2, 2 ) += fz_i * rz;

stress(i, 0, 1) += fx_i * ry;
stress(i, 1, 0) += fy_i * rx;
stress( i, 0, 1 ) += fx_i * ry;
stress( i, 1, 0 ) += fy_i * rx;

stress(i, 0, 2) += fx_i * rz;
stress(i, 2, 0) += fz_i * rx;
stress( i, 0, 2 ) += fx_i * rz;
stress( i, 2, 0 ) += fz_i * rx;

stress(i, 1, 2) += fy_i * rz;
stress(i, 2, 1) += fz_i * ry;
stress( i, 1, 2 ) += fy_i * rz;
stress( i, 2, 1 ) += fz_i * ry;
}
}
};

Kokkos::RangePolicy<exec_space> policy(0, particles.n_local);
Kokkos::parallel_for("CabanaPD::ForceLPSFracture::computeStressFull",
policy, stress_full);
Kokkos::RangePolicy<exec_space> policy( 0, particles.n_local );
Kokkos::parallel_for( "CabanaPD::ForceLPSFracture::computeStressFull",
policy, stress_full );

_stress_timer.stop();
}

};

template <class MemorySpace>
Expand Down Expand Up @@ -570,9 +573,10 @@ class Force<MemorySpace, ForceModel<LPS, Fracture>>
_energy_timer.stop();
return strain_energy;
}

template <class ParticleType, class ParallelType>
void computeStressFull(ParticleType& particles, const MuView& mu, ParallelType& neigh_op_tag)
void computeStressFull( ParticleType& particles, const MuView& mu,
ParallelType& neigh_op_tag )
{
_stress_timer.start();

Expand All @@ -585,58 +589,59 @@ class Force<MemorySpace, ForceModel<LPS, Fracture>>
const auto m = particles.sliceWeightedVolume();
auto stress = particles.sliceStress();

auto stress_full = KOKKOS_LAMBDA(const int i)
auto stress_full = KOKKOS_LAMBDA( const int i )
{
std::size_t num_neighbors =
Cabana::NeighborList<neighbor_list_type>::numNeighbor(
neigh_list, i);
for (std::size_t n = 0; n < num_neighbors; n++)
neigh_list, i );
for ( std::size_t n = 0; n < num_neighbors; n++ )
{
std::size_t j =
Cabana::NeighborList<neighbor_list_type>::getNeighbor(
neigh_list, i, n);
if (mu(i, n) > 0) // Only compute stress for unbroken bonds
neigh_list, i, n );

if ( mu( i, n ) > 0 ) // Only compute stress for unbroken bonds
{
double xi, r, s;
double rx, ry, rz;
getDistanceComponents(x, u, i, j, xi, r, s, rx, ry, rz);
getDistanceComponents( x, u, i, j, xi, r, s, rx, ry, rz );

const double coeff =
(model.theta_coeff * (theta(i) / m(i) + theta(j) / m(j)) +
model.s_coeff * s * (1.0 / m(i) + 1.0 / m(j))) *
model.influence_function(xi) * xi * vol(j) * vol(j);
const double coeff =
( model.theta_coeff *
( theta( i ) / m( i ) + theta( j ) / m( j ) ) +
model.s_coeff * s *
( 1.0 / m( i ) + 1.0 / m( j ) ) ) *
model.influence_function( xi ) * xi * vol( j ) *
vol( j );

double muij = mu(i, n);
double muij = mu( i, n );
double fx_i = muij * coeff * rx / r;
double fy_i = muij * coeff * ry / r;
double fz_i = muij * coeff * rz / r;

// Update stress tensor components
stress(i, 0, 0) += fx_i * rx;
stress(i, 1, 1) += fy_i * ry;
stress(i, 2, 2) += fz_i * rz;
stress( i, 0, 0 ) += fx_i * rx;
stress( i, 1, 1 ) += fy_i * ry;
stress( i, 2, 2 ) += fz_i * rz;

stress(i, 0, 1) += fx_i * ry;
stress(i, 1, 0) += fy_i * rx;
stress( i, 0, 1 ) += fx_i * ry;
stress( i, 1, 0 ) += fy_i * rx;

stress(i, 0, 2) += fx_i * rz;
stress(i, 2, 0) += fz_i * rx;
stress( i, 0, 2 ) += fx_i * rz;
stress( i, 2, 0 ) += fz_i * rx;

stress(i, 1, 2) += fy_i * rz;
stress(i, 2, 1) += fz_i * ry;
stress( i, 1, 2 ) += fy_i * rz;
stress( i, 2, 1 ) += fz_i * ry;
}
}
};

Kokkos::RangePolicy<exec_space> policy(0, particles.n_local);
Kokkos::parallel_for("CabanaPD::ForceLPSFracture::computeStressFull",
policy, stress_full);
Kokkos::RangePolicy<exec_space> policy( 0, particles.n_local );
Kokkos::parallel_for( "CabanaPD::ForceLPSFracture::computeStressFull",
policy, stress_full );

_stress_timer.stop();
}


};

template <class MemorySpace>
Expand Down Expand Up @@ -766,7 +771,8 @@ class Force<MemorySpace, ForceModel<LinearLPS, Elastic>>
}

template <class ParticleType, class ParallelType>
void computeStressFull(ParticleType& particles, ParallelType& neigh_op_tag)
void computeStressFull( ParticleType& particles,
ParallelType& neigh_op_tag )
{
_stress_timer.start();

Expand All @@ -779,58 +785,56 @@ class Force<MemorySpace, ForceModel<LinearLPS, Elastic>>
const auto m = particles.sliceWeightedVolume();
auto stress = particles.sliceStress();

auto stress_full = KOKKOS_LAMBDA(const int i)
auto stress_full = KOKKOS_LAMBDA( const int i )
{
std::size_t num_neighbors =
Cabana::NeighborList<neighbor_list_type>::numNeighbor(
neigh_list, i);
for (std::size_t n = 0; n < num_neighbors; n++)
neigh_list, i );
for ( std::size_t n = 0; n < num_neighbors; n++ )
{
std::size_t j =
Cabana::NeighborList<neighbor_list_type>::getNeighbor(
neigh_list, i, n);
neigh_list, i, n );

// Get the bond distance, displacement, and stretch
double xi, r, s;
double rx, ry, rz;
getLinearizedDistanceComponents(x, u, i, j, xi, r, s, rx, ry, rz);
getLinearizedDistanceComponents( x, u, i, j, xi, r, s, rx, ry,
rz );

// LPS specific coefficients
const double coeff =
(model.theta_coeff * (theta(i) / m(i) + theta(j) / m(j)) +
model.s_coeff * s * (1.0 / m(i) + 1.0 / m(j))) *
model.influence_function(xi) * xi * vol(j) * vol(j);
const double coeff =
( model.theta_coeff *
( theta( i ) / m( i ) + theta( j ) / m( j ) ) +
model.s_coeff * s * ( 1.0 / m( i ) + 1.0 / m( j ) ) ) *
model.influence_function( xi ) * xi * vol( j ) * vol( j );

double fx_i = coeff * rx / r;
double fy_i = coeff * ry / r;
double fz_i = coeff * rz / r;

// Update stress tensor components
stress(i, 0, 0) += fx_i * rx;
stress(i, 1, 1) += fy_i * ry;
stress(i, 2, 2) += fz_i * rz;
stress( i, 0, 0 ) += fx_i * rx;
stress( i, 1, 1 ) += fy_i * ry;
stress( i, 2, 2 ) += fz_i * rz;

stress(i, 0, 1) += fx_i * ry;
stress(i, 1, 0) += fy_i * rx;
stress( i, 0, 1 ) += fx_i * ry;
stress( i, 1, 0 ) += fy_i * rx;

stress(i, 0, 2) += fx_i * rz;
stress(i, 2, 0) += fz_i * rx;
stress( i, 0, 2 ) += fx_i * rz;
stress( i, 2, 0 ) += fz_i * rx;

stress(i, 1, 2) += fy_i * rz;
stress(i, 2, 1) += fz_i * ry;
stress( i, 1, 2 ) += fy_i * rz;
stress( i, 2, 1 ) += fz_i * ry;
}
};

Kokkos::RangePolicy<exec_space> policy(0, particles.n_local);
Kokkos::parallel_for("CabanaPD::ForceLPS::computeStressFull",
policy, stress_full);
Kokkos::RangePolicy<exec_space> policy( 0, particles.n_local );
Kokkos::parallel_for( "CabanaPD::ForceLPS::computeStressFull", policy,
stress_full );

_stress_timer.stop();
}




}
};

} // namespace CabanaPD
Expand Down
Loading

0 comments on commit 72469c4

Please sign in to comment.