Skip to content

Commit

Permalink
Convert examples to json input files
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Oct 3, 2023
1 parent 1c23aff commit 2338e7a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 72 deletions.
47 changes: 16 additions & 31 deletions examples/crack_branching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,7 @@ int main( int argc, char* argv[] )
using exec_space = Kokkos::DefaultExecutionSpace;
using memory_space = typename exec_space::memory_space;

// Plate dimensions (m)
double height = 0.1;
double width = 0.04;
double thickness = 0.002;

// Domain
std::array<int, 3> num_cell = { 400, 160, 8 }; // 400 x 160 x 8
double low_x = -0.5 * height;
double low_y = -0.5 * width;
double low_z = -0.5 * thickness;
double high_x = 0.5 * height;
double high_y = 0.5 * width;
double high_z = 0.5 * thickness;
std::array<double, 3> low_corner = { low_x, low_y, low_z };
std::array<double, 3> high_corner = { high_x, high_y, high_z };

// Time
double t_final = 43e-6;
double dt = 5e-8;
double output_frequency = 5;
CabanaPD::Inputs inputs( argv[1] );

// Material constants
double E = 72e+9; // [Pa]
Expand All @@ -61,14 +42,20 @@ int main( int argc, char* argv[] )
double delta = 0.001 + 1e-10;

// FIXME: set halo width based on delta
std::array<double, 3> low_corner = inputs["low_corner"];
std::array<double, 3> high_corner = inputs["high_corner"];
std::array<int, 3> num_cells = inputs["num_cells"];
int m = std::floor(
delta / ( ( high_corner[0] - low_corner[0] ) / num_cell[0] ) );
delta / ( ( high_corner[0] - low_corner[0] ) / num_cells[0] ) );
int halo_width = m + 1;

// Prenotch
double height = inputs["system_size"][0];
double thickness = inputs["system_size"][2];
double L_prenotch = height / 2.0;
double y_prenotch1 = 0.0;
Kokkos::Array<double, 3> p01 = { low_x, y_prenotch1, low_z };
Kokkos::Array<double, 3> p01 = { low_corner[0], y_prenotch1,
low_corner[2] };
Kokkos::Array<double, 3> v1 = { L_prenotch, 0, 0 };
Kokkos::Array<double, 3> v2 = { 0, 0, thickness };
Kokkos::Array<Kokkos::Array<double, 3>, 1> notch_positions = { p01 };
Expand All @@ -78,17 +65,13 @@ int main( int argc, char* argv[] )
using model_type =
CabanaPD::ForceModel<CabanaPD::PMB, CabanaPD::Fracture>;
model_type force_model( delta, K, G0 );
CabanaPD::Inputs<3> inputs( num_cell, low_corner, high_corner, t_final,
dt, output_frequency );
inputs.read_args( argc, argv );

// Create particles from mesh.
// Does not set displacements, velocities, etc.
using device_type = Kokkos::Device<exec_space, memory_space>;
auto particles = std::make_shared<
CabanaPD::Particles<device_type, typename model_type::base_model>>(
exec_space(), inputs.low_corner, inputs.high_corner,
inputs.num_cells, halo_width );
exec_space(), low_corner, high_corner, num_cells, halo_width );

// Define particle initialization.
auto x = particles->sliceRefPosition();
Expand All @@ -101,10 +84,12 @@ int main( int argc, char* argv[] )
double dy = particles->dx[1];
double b0 = 2e6 / dy; // Pa

CabanaPD::RegionBoundary plane1( low_x, high_x, low_y - dy, low_y + dy,
low_z, high_z );
CabanaPD::RegionBoundary plane2( low_x, high_x, high_y - dy,
high_y + dy, low_z, high_z );
CabanaPD::RegionBoundary plane1(
low_corner[0], high_corner[0], low_corner[1] - dy,
high_corner[1] + dy, low_corner[2], high_corner[2] );
CabanaPD::RegionBoundary plane2(
low_corner[0], high_corner[0], low_corner[1] - dy,
high_corner[1] + dy, low_corner[2], high_corner[2] );
std::vector<CabanaPD::RegionBoundary> planes = { plane1, plane2 };
auto bc =
createBoundaryCondition( CabanaPD::ForceCrackBranchBCTag{},
Expand Down
22 changes: 8 additions & 14 deletions examples/elastic_wave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ int main( int argc, char* argv[] )
using exec_space = Kokkos::DefaultExecutionSpace;
using memory_space = typename exec_space::memory_space;

std::array<int, 3> num_cell = { 41, 41, 41 };
std::array<double, 3> low_corner = { -0.5, -0.5, -0.5 };
std::array<double, 3> high_corner = { 0.5, 0.5, 0.5 };
double t_final = 0.6;
double dt = 0.01;
int output_frequency = 5;
CabanaPD::Inputs inputs( argv[1] );

double K = 1.0;
double G = 0.5;
double delta = 0.075;
std::array<double, 3> low_corner = inputs["low_corner"];
std::array<double, 3> high_corner = inputs["high_corner"];
std::array<int, 3> num_cells = inputs["num_cells"];
int m = std::floor(
delta / ( ( high_corner[0] - low_corner[0] ) / num_cell[0] ) );
delta / ( ( high_corner[0] - low_corner[0] ) / num_cells[0] ) );
int halo_width = m + 1; // Just to be safe.

// Choose force model type.
Expand All @@ -50,18 +49,13 @@ int main( int argc, char* argv[] )
CabanaPD::ForceModel<CabanaPD::LinearLPS, CabanaPD::Elastic>;
model_type force_model( delta, K, G );

CabanaPD::Inputs<3> inputs( num_cell, low_corner, high_corner, t_final,
dt, output_frequency );
inputs.read_args( argc, argv );

// Create particles from mesh.
// Does not set displacements, velocities, etc.
// FIXME: use createSolver to switch backend at runtime.
using device_type = Kokkos::Device<exec_space, memory_space>;
auto particles = std::make_shared<
CabanaPD::Particles<device_type, typename model_type::base_model>>(
exec_space(), inputs.low_corner, inputs.high_corner,
inputs.num_cells, halo_width );
exec_space(), low_corner, high_corner, num_cells, halo_width );

// Define particle initialization.
auto x = particles->sliceRefPosition();
Expand Down Expand Up @@ -98,7 +92,7 @@ int main( int argc, char* argv[] )

x = particles->sliceRefPosition();
u = particles->sliceDisplacement();
double num_cell_x = inputs.num_cells[0];
int num_cell_x = num_cells[0];
auto profile = Kokkos::View<double* [2], memory_space>(
Kokkos::ViewAllocateWithoutInitializing( "displacement_profile" ),
num_cell_x );
Expand Down
7 changes: 7 additions & 0 deletions examples/inputs/crack_branching.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"num_cells": [400, 160, 8],
"system_size": [0.1, 0.04, 0.002],
"final_time": 43e-6,
"timestep": 5e-8,
"output_frequency": 5
}
7 changes: 7 additions & 0 deletions examples/inputs/elastic_wave.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"num_cells": [41, 41, 41],
"system_size": [1.0, 1.0, 1.0],
"final_time": 0.6,
"timestep": 0.01,
"output_frequency": 5
}
7 changes: 7 additions & 0 deletions examples/inputs/kalthoff_winkler.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"num_cells": [151, 301, 14],
"system_size": [0.1, 0.2, 0.009],
"final_time": 70e-6,
"timestep": 0.133e-6,
"output_frequency": 10
}
39 changes: 12 additions & 27 deletions examples/kalthoff_winkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,7 @@ int main( int argc, char* argv[] )
using exec_space = Kokkos::DefaultExecutionSpace;
using memory_space = typename exec_space::memory_space;

// Plate dimension)
double height = 0.1; // [m] (100 mm)
double width = 0.2; // [m] (200 mm)
double thickness = 0.009; // [m] ( 9 mm)

// Domain
// This is a relatively large example for CPU - reduce the number of
// cells and increase delta if needed. Note this is also a relatively
// small example for GPU.
std::array<int, 3> num_cell = { 151, 301, 14 };
std::array<double, 3> low_corner = { -0.5 * height, -0.5 * width,
-0.5 * thickness };
std::array<double, 3> high_corner = { 0.5 * height, 0.5 * width,
0.5 * thickness };
double t_final = 70e-6;
double dt = 0.133e-6;
int output_frequency = 10;
CabanaPD::Inputs inputs( argv[1] );

// Material constants
double E = 191e+9; // [Pa]
Expand All @@ -59,19 +43,23 @@ int main( int argc, char* argv[] )
double L_prenotch = 0.05; // [m] (50 mm)
double y_prenotch1 = -0.025; // [m] (-25 mm)
double y_prenotch2 = 0.025; // [m] ( 25 mm)
Kokkos::Array<double, 3> p01 = { low_corner[0], y_prenotch1,
low_corner[2] };
Kokkos::Array<double, 3> p02 = { low_corner[0], y_prenotch2,
low_corner[2] };
double low_x = inputs["low_corner"][0];
double low_z = inputs["low_corner"][2];
Kokkos::Array<double, 3> p01 = { low_x, y_prenotch1, low_z };
Kokkos::Array<double, 3> p02 = { low_x, y_prenotch2, low_z };
Kokkos::Array<double, 3> v1 = { L_prenotch, 0, 0 };
double thickness = inputs["system_size"][2];
Kokkos::Array<double, 3> v2 = { 0, 0, thickness };
Kokkos::Array<Kokkos::Array<double, 3>, 2> notch_positions = { p01,
p02 };
CabanaPD::Prenotch<2> prenotch( v1, v2, notch_positions );

double delta = 0.0020000001;
std::array<double, 3> low_corner = inputs["low_corner"];
std::array<double, 3> high_corner = inputs["high_corner"];
std::array<int, 3> num_cells = inputs["num_cells"];
int m = std::floor(
delta / ( ( high_corner[0] - low_corner[0] ) / num_cell[0] ) );
delta / ( ( high_corner[0] - low_corner[0] ) / num_cells[0] ) );
int halo_width = m + 1; // Just to be safe.

// Choose force model type.
Expand All @@ -81,18 +69,14 @@ int main( int argc, char* argv[] )
// using model_type =
// CabanaPD::ForceModel<CabanaPD::LPS, CabanaPD::Fracture>;
// model_type force_model( delta, K, G, G0 );
CabanaPD::Inputs<3> inputs( num_cell, low_corner, high_corner, t_final,
dt, output_frequency );
inputs.read_args( argc, argv );

// Create particles from mesh.
// Does not set displacements, velocities, etc.
// FIXME: use createSolver to switch backend at runtime.
using device_type = Kokkos::Device<exec_space, memory_space>;
auto particles = std::make_shared<
CabanaPD::Particles<device_type, typename model_type::base_model>>(
exec_space(), inputs.low_corner, inputs.high_corner,
inputs.num_cells, halo_width );
exec_space(), low_corner, high_corner, num_cells, halo_width );

// Define particle initialization.
auto x = particles->sliceRefPosition();
Expand All @@ -102,6 +86,7 @@ int main( int argc, char* argv[] )

double dx = particles->dx[0];

double height = inputs["system_size"][0];
double x_bc = -0.5 * height;
CabanaPD::RegionBoundary plane(
x_bc - dx, x_bc + dx * 1.25, y_prenotch1 - dx * 0.25,
Expand Down

0 comments on commit 2338e7a

Please sign in to comment.