Skip to content

Commit

Permalink
Enable variable dimension (2d/3d)
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Sep 28, 2023
1 parent d040a8f commit 7ce867e
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 217 deletions.
6 changes: 3 additions & 3 deletions examples/crack_branching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ int main( int argc, char* argv[] )
using model_type =
CabanaPD::ForceModel<CabanaPD::PMB, CabanaPD::Fracture>;
model_type force_model( delta, K, G0 );
CabanaPD::Inputs inputs( num_cell, low_corner, high_corner, t_final, dt,
output_frequency );
CabanaPD::Inputs<3> inputs( num_cell, low_corner, high_corner, t_final,
dt, output_frequency );
inputs.read_args( argc, argv );

// Create particles from mesh.
Expand All @@ -98,7 +98,7 @@ int main( int argc, char* argv[] )
auto nofail = particles->sliceNoFail();

// Relying on uniform grid here.
double dy = particles->dy;
double dy = particles->dx[1];
double b0 = 2e6 / dy; // Pa

CabanaPD::RegionBoundary plane1( low_x, high_x, low_y - dy, low_y + dy,
Expand Down
4 changes: 2 additions & 2 deletions examples/elastic_wave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ int main( int argc, char* argv[] )
CabanaPD::ForceModel<CabanaPD::LinearLPS, CabanaPD::Elastic>;
model_type force_model( delta, K, G );

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

// Create particles from mesh.
Expand Down
6 changes: 3 additions & 3 deletions examples/kalthoff_winkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ 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 inputs( num_cell, low_corner, high_corner, t_final, dt,
output_frequency );
CabanaPD::Inputs<3> inputs( num_cell, low_corner, high_corner, t_final,
dt, output_frequency );
inputs.read_args( argc, argv );

// Create particles from mesh.
Expand All @@ -100,7 +100,7 @@ int main( int argc, char* argv[] )
auto f = particles->sliceForce();
auto rho = particles->sliceDensity();

double dx = particles->dx;
double dx = particles->dx[0];

double x_bc = -0.5 * height;
CabanaPD::RegionBoundary plane(
Expand Down
8 changes: 3 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ configure_file(CabanaPD_config.hpp.cmakein CabanaPD_config.hpp @ONLY)

file(GLOB HEADERS GLOB *.hpp)

file(GLOB SOURCES *.cpp)

install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CabanaPD_config.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

add_library(CabanaPD ${SOURCES})
add_library(CabanaPD INTERFACE)

target_include_directories(CabanaPD PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
target_include_directories(CabanaPD INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

target_link_libraries(CabanaPD Cabana::cabanacore Cabana::Cajita)
target_link_libraries(CabanaPD INTERFACE Cabana::cabanacore Cabana::Cajita)

install(TARGETS CabanaPD DESTINATION ${CMAKE_INSTALL_LIBDIR})
140 changes: 0 additions & 140 deletions src/CabanaPD_Input.cpp

This file was deleted.

83 changes: 75 additions & 8 deletions src/CabanaPD_Input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@

#include <string>

#include <CabanaPD_Output.hpp>

namespace CabanaPD
{
template <int Dim = 3>
class Inputs
{
public:
std::string output_file = "cabanaPD.out";
std::string error_file = "cabanaPD.err";
std::string device_type = "SERIAL";

std::array<int, 3> num_cells;
std::array<double, 3> low_corner;
std::array<double, 3> high_corner;
std::array<int, Dim> num_cells;
std::array<double, Dim> low_corner;
std::array<double, Dim> high_corner;

std::size_t num_steps;
double final_time;
Expand All @@ -34,11 +37,75 @@ class Inputs

bool half_neigh = false;

Inputs( const std::array<int, 3> nc, std::array<double, 3> lc,
std::array<double, 3> hc, const double t_f, const double dt,
const int output_freq );
~Inputs();
void read_args( int argc, char* argv[] );
Inputs( const std::array<int, Dim> nc, std::array<double, Dim> lc,
std::array<double, Dim> hc, const double t_f, const double dt,
const int of )
: num_cells( nc )
, low_corner( lc )
, high_corner( hc )
, final_time( t_f )
, timestep( dt )
, output_frequency( of )
{
num_steps = final_time / timestep;
}
~Inputs(){};

void read_args( int argc, char* argv[] )
{
for ( int i = 1; i < argc; i++ )
{
// Help command.
if ( ( strcmp( argv[i], "-h" ) == 0 ) ||
( strcmp( argv[i], "--help" ) == 0 ) )
{
if ( print_rank() )
{
log( std::cout, "CabanaPD\n", "Options:" );
log( std::cout, " -o [FILE] (OR)\n"
" --output-file [FILE]: Provide output "
"file name\n" );
log(
std::cout,
" -e [FILE] (OR)\n"
" --error-file [FILE]: Provide error file name\n" );
/* Not yet enabled.
log(
std::cout,
" --device-type [TYPE]: Kokkos device type to run
", "with\n", " (SERIAL,
PTHREAD, OPENMP, " "CUDA, HIP)" );
*/
}
}
// Output file names.
else if ( ( strcmp( argv[i], "-o" ) == 0 ) ||
( strcmp( argv[i], "--output-file" ) == 0 ) )
{
output_file = argv[i + 1];
++i;
}
else if ( ( strcmp( argv[i], "-e" ) == 0 ) ||
( strcmp( argv[i], "--error-file" ) == 0 ) )
{
error_file = argv[i + 1];
++i;
}

// Kokkos device type.
else if ( ( strcmp( argv[i], "--device-type" ) == 0 ) )
{
device_type = argv[i + 1];
++i;
}

else if ( ( strstr( argv[i], "--kokkos-" ) == NULL ) )
{
log_err( std::cout,
"Unknown command line argument: ", argv[i] );
}
}
}
};

} // namespace CabanaPD
Expand Down
Loading

0 comments on commit 7ce867e

Please sign in to comment.