PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
integrator.h
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2026 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#ifndef TIME_INT_INTEGRATOR_H
12#define TIME_INT_INTEGRATOR_H
13
14#include "data/modelData.h"
15#include "util/vecMethods.h"
16
17#include <chrono>
18#include <format>
19#include <stdexcept>
20#include <string>
21
22namespace time_int {
23
28
35public:
36 template <typename Model>
37 void integrate(Model &model) {
38 if (model.currentStep() == 0) {
39 model.applyInitialCondition();
40 if (model.performOutput())
41 model.output();
42 }
43
44 model.setCurrentDt(model.timeStep());
45 model.applyDisplacementBC();
46 model.computeForces();
48
49 while (model.currentStep() < model.numTimeSteps()) {
50 model.log(std::format("{}: Time step: {}, time: {:8.6f}, steps completed = {}%\n",
51 model.d_name, model.currentStep(), model.d_time,
52 float(model.currentStep()) * 100. / model.numTimeSteps()),
53 2, model.d_n % model.d_infoN == 0, 3);
54
55 const auto t0 = std::chrono::steady_clock::now();
56 step(model);
57 const auto dt_ms = util::methods::timeDiff(t0, std::chrono::steady_clock::now());
58 model.appendKeyData("integrate_compute_time", dt_ms, true);
59 model.log(std::format(" Integration time (ms) = {}\n", dt_ms),
60 2, model.d_n % model.d_infoN == 0, 3);
61
62 if (model.shouldOutput())
63 model.output();
64 model.checkStop();
65 }
66
67 model.log(std::format(
68 "{}: Total compute time information (s) \n"
69 " {:22s} = {:8.2f} \n"
70 " {:22s} = {:8.2f} \n"
71 " {:22s} = {:8.2f} \n"
72 " {:22s} = {:8.2f} \n"
73 " {:22s} = {:8.2f} \n"
74 " {:22s} = {:8.2f} \n"
75 " {:22s} = {:8.2f} \n"
76 " {:22s} = {:8.0f} \n",
77 model.d_name,
78 "Time integration", model.getKeyData("integrate_compute_time") * 1.e-6,
79 "Peridynamics force", model.getKeyData("pd_compute_time") * 1.e-6,
80 "Contact force", model.getKeyData("contact_compute_time") * 1.e-6,
81 "Search tree update", model.getKeyData("tree_compute_time") * 1.e-6,
82 "External force", model.getKeyData("extf_compute_time") * 1.e-6,
83 "MPI ghost exchange", model.getKeyData("mpi_exchange_time") * 1.e-6,
84 "Contact neigh update",
85 model.getKeyData("contact_neigh_update_time") * 1.e-6,
86 "MPI ghost grains", model.getKeyData("mpi_ghost_grain_count")));
87 }
88
89 template <typename Model>
90 void step(Model &model) {
91 const auto &scheme = model.timeDiscretization();
92 model.setCurrentDt(model.timeStep());
93 if (scheme == "central_difference") {
95 model.advanceTime();
96 model.applyDisplacementBC();
97 model.computeForces();
99 } else if (scheme == "velocity_verlet") {
101 model.advanceTime();
102 model.applyDisplacementBC();
103 model.computeForces();
106 } else {
107 throw std::runtime_error("Unknown time discretization: " + scheme);
108 }
109 }
110};
111
112} // namespace time_int
113
114#endif // TIME_INT_INTEGRATOR_H
A class to store model data.
Definition modelData.h:50
void step(Model &model)
Definition integrator.h:90
void integrate(Model &model)
Definition integrator.h:37
Definition contact.h:20
void updateVerletHalfKickAndDrift(data::ModelData &data)
void updateCentralDifference(data::ModelData &data)
void updateVerletSecondKick(data::ModelData &data)
void applyRigidBodyConstraint(data::ModelData &data)
float timeDiff(std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, std::string unit="microseconds")
Returns difference between two times.
Definition vecMethods.h:304