-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeStepper.cpp
67 lines (59 loc) · 1.38 KB
/
timeStepper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "timeStepper.h"
timeStepper::timeStepper(elasticRod &m_rod)
{
rod = &m_rod;
kl = 10; // lower diagonals
ku = 10; // upper diagonals
freeDOF = rod->uncons;
ldb = freeDOF;
NUMROWS = 2 * kl + ku + 1;
totalForce = new double[freeDOF];
jacobianLen = (2 * kl + ku + 1) * freeDOF;
jacobian = new double[jacobianLen];
nrhs = 1;
ipiv = new int[freeDOF];
info = 0;
}
timeStepper::~timeStepper()
{
;
}
double *timeStepper::getForce()
{
return totalForce;
}
double *timeStepper::getJacobian()
{
return jacobian;
}
void timeStepper::addForce(int ind, double p)
{
if (rod->getIfConstrained(ind) == 0) // free dof
{
mappedInd = rod->fullToUnconsMap[ind];
totalForce[mappedInd] = totalForce[mappedInd] + p; // subtracting elastic force
}
}
void timeStepper::addJacobian(int ind1, int ind2, double p)
{
mappedInd1 = rod->fullToUnconsMap[ind1];
mappedInd2 = rod->fullToUnconsMap[ind2];
if (rod->getIfConstrained(ind1) == 0 && rod->getIfConstrained(ind2) == 0) // both are free
{
row = kl + ku + mappedInd2 - mappedInd1;
col = mappedInd1;
offset = row + col * NUMROWS;
jacobian[offset] = jacobian[offset] + p;
}
}
void timeStepper::setZero()
{
for (int i = 0; i < freeDOF; i++)
totalForce[i] = 0;
for (int i = 0; i < jacobianLen; i++)
jacobian[i] = 0;
}
void timeStepper::integrator()
{
dgbsv_(&freeDOF, &kl, &ku, &nrhs, jacobian, &NUMROWS, ipiv, totalForce, &ldb, &info);
}