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)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 249 of file main.cpp.

249 {
250 util::parallel::initMpi(argc, argv);
251 util::io::InputParser input(argc, argv);
252
253 unsigned int n_threads = 2;
254 if (input.cmdOptionExists("-nThreads"))
255 n_threads = static_cast<unsigned>(std::stoi(input.getCmdOption("-nThreads")));
257
258 namespace fs = std::filesystem;
259 fs::path base = fs::current_path() / "self_contact_mode1_run";
260 if (input.cmdOptionExists("-outputDir"))
261 base = input.getCmdOption("-outputDir");
262
263 const double L = 0.002;
264 const double mesh_size = L / 6.0;
265 const double horizon = 3.0 * mesh_size;
266
267 LawResult bb;
268 LawResult rg;
269 try {
270 bb = runLaw("broken_bond_kn", base / "broken_bond_kn", L, mesh_size, horizon, n_threads);
271 rg = runLaw("reference_gap", base / "reference_gap", L, mesh_size, horizon, n_threads);
272 } catch (const std::exception &e) {
273 util::io::print(std::format("self-contact Mode-I failed: {}\n", e.what()));
274 return 1;
275 }
276
277 if (!(bb.close_force_amp > 0.) || !(rg.close_force_amp > 0.)) {
278 util::io::print(std::format(
279 "close did not activate self-contact: F_bb={}, F_rg={}\n", bb.close_force_amp,
280 rg.close_force_amp));
281 return 1;
282 }
283
284 const double fmax = std::max(bb.close_force_amp, rg.close_force_amp);
285 const double rel = std::abs(bb.close_force_amp - rg.close_force_amp) / fmax;
286 if (!(rel > 0.05)) {
287 util::io::print(std::format(
288 "self-contact laws did not differ enough under close: F_bb={}, F_rg={}, rel={}\n",
289 bb.close_force_amp, rg.close_force_amp, rel));
290 return 1;
291 }
292
293 util::io::print(std::format(
294 "self-contact Mode-I OK: open gaps bb={}/rg={}, close forces bb={}/rg={}, rel_diff={}\n", bb.open_min_gap,
295 rg.open_min_gap, bb.close_force_amp, rg.close_force_amp, rel));
296 return 0;
297}
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)
Definition main.cpp:184
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
Definition io.h:128
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(), util::io::print(), and anonymous_namespace{main.cpp}::runLaw().

Here is the call graph for this function: