diff --git a/examples/crack_branching.cpp b/examples/crack_branching.cpp index e0c80731..cb789970 100644 --- a/examples/crack_branching.cpp +++ b/examples/crack_branching.cpp @@ -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 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 low_corner = { low_x, low_y, low_z }; - std::array 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] @@ -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 low_corner = inputs["low_corner"]; + std::array high_corner = inputs["high_corner"]; + std::array 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 p01 = { low_x, y_prenotch1, low_z }; + Kokkos::Array p01 = { low_corner[0], y_prenotch1, + low_corner[2] }; Kokkos::Array v1 = { L_prenotch, 0, 0 }; Kokkos::Array v2 = { 0, 0, thickness }; Kokkos::Array, 1> notch_positions = { p01 }; @@ -78,17 +65,13 @@ int main( int argc, char* argv[] ) using model_type = CabanaPD::ForceModel; model_type force_model( delta, K, G0 ); - CabanaPD::Inputs 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; auto particles = std::make_shared< CabanaPD::Particles>( - 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(); @@ -101,10 +84,12 @@ int main( int argc, char* argv[] ) double dy = particles->dy; 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 planes = { plane1, plane2 }; auto bc = createBoundaryCondition( CabanaPD::ForceCrackBranchBCTag{}, diff --git a/examples/elastic_wave.cpp b/examples/elastic_wave.cpp index 58af9524..12b36e32 100644 --- a/examples/elastic_wave.cpp +++ b/examples/elastic_wave.cpp @@ -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 num_cell = { 41, 41, 41 }; - std::array low_corner = { -0.5, -0.5, -0.5 }; - std::array 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 low_corner = inputs["low_corner"]; + std::array high_corner = inputs["high_corner"]; + std::array 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. @@ -50,18 +49,13 @@ int main( int argc, char* argv[] ) CabanaPD::ForceModel; model_type force_model( delta, K, G ); - CabanaPD::Inputs 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; auto particles = std::make_shared< CabanaPD::Particles>( - 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(); @@ -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( Kokkos::ViewAllocateWithoutInitializing( "displacement_profile" ), num_cell_x ); diff --git a/examples/inputs/crack_branching.json b/examples/inputs/crack_branching.json new file mode 100644 index 00000000..6c0cf6b1 --- /dev/null +++ b/examples/inputs/crack_branching.json @@ -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 +} diff --git a/examples/inputs/elastic_wave.json b/examples/inputs/elastic_wave.json new file mode 100644 index 00000000..773209ac --- /dev/null +++ b/examples/inputs/elastic_wave.json @@ -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 +} diff --git a/examples/inputs/kalthoff_winkler.json b/examples/inputs/kalthoff_winkler.json new file mode 100644 index 00000000..513a7986 --- /dev/null +++ b/examples/inputs/kalthoff_winkler.json @@ -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 +} diff --git a/examples/kalthoff_winkler.cpp b/examples/kalthoff_winkler.cpp index 9b2e6fda..daaeea7d 100644 --- a/examples/kalthoff_winkler.cpp +++ b/examples/kalthoff_winkler.cpp @@ -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 num_cell = { 151, 301, 14 }; - std::array low_corner = { -0.5 * height, -0.5 * width, - -0.5 * thickness }; - std::array 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] @@ -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 p01 = { low_corner[0], y_prenotch1, - low_corner[2] }; - Kokkos::Array 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 p01 = { low_x, y_prenotch1, low_z }; + Kokkos::Array p02 = { low_x, y_prenotch2, low_z }; Kokkos::Array v1 = { L_prenotch, 0, 0 }; + double thickness = inputs["system_size"][2]; Kokkos::Array v2 = { 0, 0, thickness }; Kokkos::Array, 2> notch_positions = { p01, p02 }; CabanaPD::Prenotch<2> prenotch( v1, v2, notch_positions ); double delta = 0.0020000001; + std::array low_corner = inputs["low_corner"]; + std::array high_corner = inputs["high_corner"]; + std::array 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. @@ -81,9 +69,6 @@ int main( int argc, char* argv[] ) // using model_type = // CabanaPD::ForceModel; // model_type force_model( delta, K, G, G0 ); - CabanaPD::Inputs 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. @@ -91,8 +76,7 @@ int main( int argc, char* argv[] ) using device_type = Kokkos::Device; auto particles = std::make_shared< CabanaPD::Particles>( - 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(); @@ -102,6 +86,7 @@ int main( int argc, char* argv[] ) double dx = particles->dx; + 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,