PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
integrator.cpp
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#include "integrator.h"
12
13#include "data/modelData.h"
14#include "util/parallelUtil.h"
15
16#include <taskflow/taskflow/taskflow.hpp>
17#include <taskflow/taskflow/algorithm/for_each.hpp>
18
20 const auto &rigid = data.d_modelDeck_p->d_rigidParticles;
21 if (rigid.empty())
22 return;
23
24 // Nodal force in the integrators is a force density (acceleration = f/rho).
25 // A rigid translating body of mass M has acceleration a = sum(f_i V_i) / M,
26 // so replacing each nodal force density by rho * a reproduces that motion
27 // without touching the integrators themselves.
28 for (const auto &[pid, mass] : rigid) {
29 util::Point net(0., 0., 0.);
30 for (std::size_t II = 0; II < data.numPdForceNodes(); II++) {
31 const auto i = data.pdForceNode(II);
32 if (data.getPtId(i) != pid)
33 continue;
34 net += data.getVol(i) * data.getF(i);
35 }
36
37 const auto acc = net / mass;
38 for (std::size_t II = 0; II < data.numPdForceNodes(); II++) {
39 const auto i = data.pdForceNode(II);
40 if (data.getPtId(i) != pid)
41 continue;
42 data.getF(i) = data.getDensity(i) * acc;
43 }
44 }
45}
46
48 const auto dim = data.dimension();
49 const auto dt = data.currentDt();
50
51 tf::Executor executor(util::parallel::getNThreads());
52 tf::Taskflow taskflow;
53
54 taskflow.for_each_index(
55 (std::size_t) 0, data.numPdForceNodes(), (std::size_t) 1,
56 [&data, dim, dt](std::size_t II) {
57 const auto i = data.pdForceNode(II);
58 const auto rho = data.getDensity(i);
59 auto &v = data.getV(i);
60 auto &u = data.getU(i);
61 auto &x = data.getX(i);
62 const auto &f = data.getF(i);
63
64 for (int dof = 0; dof < dim; dof++) {
65 if (data.isDofFree(i, dof)) {
66 v[dof] += (dt / rho) * f[dof];
67 u[dof] += dt * v[dof];
68 x[dof] += dt * v[dof];
69 }
70 }
71
72 data.setVMag(i, v.length());
73 }
74 );
75
76 executor.run(taskflow).get();
77}
78
80 const auto dim = data.dimension();
81 const auto dt = data.currentDt();
82
83 tf::Executor executor(util::parallel::getNThreads());
84 tf::Taskflow taskflow;
85
86 taskflow.for_each_index(
87 (std::size_t) 0, data.numPdForceNodes(), (std::size_t) 1,
88 [&data, dim, dt](std::size_t II) {
89 const auto i = data.pdForceNode(II);
90 const auto rho = data.getDensity(i);
91 auto &v = data.getV(i);
92 auto &u = data.getU(i);
93 auto &x = data.getX(i);
94 const auto &f = data.getF(i);
95
96 for (int dof = 0; dof < dim; dof++) {
97 if (data.isDofFree(i, dof)) {
98 v[dof] += 0.5 * (dt / rho) * f[dof];
99 u[dof] += dt * v[dof];
100 x[dof] += dt * v[dof];
101 }
102 }
103
104 data.setVMag(i, v.length());
105 }
106 );
107
108 executor.run(taskflow).get();
109}
110
112 const auto dim = data.dimension();
113 const auto dt = data.currentDt();
114
115 tf::Executor executor(util::parallel::getNThreads());
116 tf::Taskflow taskflow;
117
118 taskflow.for_each_index(
119 (std::size_t) 0, data.numPdForceNodes(), (std::size_t) 1,
120 [&data, dim, dt](std::size_t II) {
121 const auto i = data.pdForceNode(II);
122 const auto rho = data.getDensity(i);
123 auto &v = data.getV(i);
124 const auto &f = data.getF(i);
125
126 for (int dof = 0; dof < dim; dof++) {
127 if (data.isDofFree(i, dof)) {
128 v[dof] += 0.5 * (dt / rho) * f[dof];
129 }
130 }
131
132 data.setVMag(i, v.length());
133 }
134 );
135
136 executor.run(taskflow).get();
137}
A class to store model data.
Definition modelData.h:50
Definition contact.h:20
void updateVerletHalfKickAndDrift(data::ModelData &data)
void updateCentralDifference(data::ModelData &data)
void updateVerletSecondKick(data::ModelData &data)
void applyRigidBodyConstraint(data::ModelData &data)
unsigned int getNThreads()
Get number of threads to be used by taskflow.
A structure to represent 3d vectors.
Definition point.h:30