PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
main.cpp File Reference
#include "inp/deckIncludes.h"
#include "material/materialUtil.h"
#include "periDEMModel.h"
#include "util/io.h"
#include "util/parallelUtil.h"
#include "util/point.h"
#include <cmath>
#include <cstdlib>
#include <filesystem>
#include <format>
#include <fstream>
#include <memory>
#include <stdexcept>
#include <string>
#include <thread>
#include <vector>
Include dependency graph for main.cpp:

Go to the source code of this file.

Data Structures

struct  anonymous_namespace{main.cpp}::CrackMetrics
 
struct  anonymous_namespace{main.cpp}::LawResult
 

Namespaces

namespace  anonymous_namespace{main.cpp}
 

Functions

std::string anonymous_namespace{main.cpp}::directoryPathWithTrailingSep (const std::filesystem::path &dir)
 
json anonymous_namespace{main.cpp}::buildInputJson (const std::string &output_path, const std::filesystem::path &mesh_file, double L, double mesh_size, double horizon, double final_time, size_t num_steps, const std::string &self_contact)
 
size_t anonymous_namespace{main.cpp}::applyPrecrack (PeriDEMModel &dem, double x_crack)
 
void anonymous_namespace{main.cpp}::applyRigidOpenClose (PeriDEMModel &dem, double x_crack, double u_right)
 
CrackMetrics anonymous_namespace{main.cpp}::measure (PeriDEMModel &dem, double x_crack, double band)
 
LawResult anonymous_namespace{main.cpp}::runLaw (const std::string &self_contact, const std::filesystem::path &run_dir, double L, double mesh_size, double horizon, unsigned n_threads, bool deck_only=false)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 280 of file main.cpp.

280 {
281 util::parallel::initMpi(argc, argv);
282 util::io::InputParser input(argc, argv);
283
284 unsigned int n_threads = 2;
285 if (input.cmdOptionExists("-nThreads"))
286 n_threads = static_cast<unsigned>(std::stoi(input.getCmdOption("-nThreads")));
288
289 namespace fs = std::filesystem;
290 fs::path base = fs::current_path() / "self_contact_mode1_run";
291 if (input.cmdOptionExists("-outputDir"))
292 base = input.getCmdOption("-outputDir");
293
294 const double L = 0.002;
295 const double mesh_size = L / 6.0;
296 const double horizon = 3.0 * mesh_size;
297
298 LawResult bb;
299 LawResult rg;
300 try {
301 const bool deck_only = input.cmdOptionExists("-deckOnly");
302 bb = runLaw("broken_bond_kn", base / "broken_bond_kn", L, mesh_size, horizon,
303 n_threads, deck_only);
304 rg = runLaw("reference_gap", base / "reference_gap", L, mesh_size, horizon,
305 n_threads, deck_only);
306 if (deck_only)
307 return EXIT_SUCCESS;
308 } catch (const std::exception &e) {
309 util::io::print(std::format("self-contact Mode-I failed: {}\n", e.what()));
310 return 1;
311 }
312
313 if (!(bb.close_force_amp > 0.) || !(rg.close_force_amp > 0.)) {
314 util::io::print(std::format(
315 "close did not activate self-contact: F_bb={}, F_rg={}\n", bb.close_force_amp,
316 rg.close_force_amp));
317 return 1;
318 }
319
320 const double fmax = std::max(bb.close_force_amp, rg.close_force_amp);
321 const double rel = std::abs(bb.close_force_amp - rg.close_force_amp) / fmax;
322 if (!(rel > 0.05)) {
323 util::io::print(std::format(
324 "self-contact laws did not differ enough under close: F_bb={}, F_rg={}, rel={}\n",
325 bb.close_force_amp, rg.close_force_amp, rel));
326 return 1;
327 }
328
329 util::io::print(std::format(
330 "self-contact Mode-I OK: open gaps bb={}/rg={}, close forces bb={}/rg={}, rel_diff={}\n", bb.open_min_gap,
331 rg.open_min_gap, bb.close_force_amp, rg.close_force_amp, rel));
332 return 0;
333}
Input command line argument parser.
Definition inputParser.h:28
LawResult runLaw(const std::string &self_contact, const std::filesystem::path &run_dir, double L, double mesh_size, double horizon, unsigned n_threads, bool deck_only=false)
Definition main.cpp:207
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
Definition io.h:171
void initNThreads(unsigned int nThreads=std::thread::hardware_concurrency())
Initializes MpiStatus struct.
void initMpi(int argc=0, char *argv[]=nullptr)
Initializes MPI and also creates MpiStatus struct.

References util::io::InputParser::cmdOptionExists(), util::io::InputParser::getCmdOption(), util::parallel::initMpi(), util::parallel::initNThreads(), main(), util::io::print(), and anonymous_namespace{main.cpp}::runLaw().

Here is the call graph for this function: