-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModifier.cpp
More file actions
218 lines (191 loc) · 6.75 KB
/
Modifier.cpp
File metadata and controls
218 lines (191 loc) · 6.75 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "Modifier.h"
#include <iostream>
#include <math.h>
Modifier::Modifier(void)
{
}
Modifier::~Modifier(void)
{
}
PinBackbone::PinBackbone(vector<Polymer*> sys, double initpk, double initsk, double initstiffk, int numpin)
{
this->pk = initpk;
this->sk = initsk;
this->stiffk = initstiffk;
this->linksize = 1.0;
this->numpin = numpin;
for(unsigned int i=0; i<sys.size() ; i++){
for(int j=0; j<numpin; j++){
pins.push_back(sys[i]->Loc[j]);
}
}
}
void
PinBackbone::Act(vector<Polymer*> sys, Polymer* yolk)
{
//do the chain forces for each polymer
for(unsigned int i=0; i<sys.size() ; i++){
//first the springforce backbone
for(int j=1; j<sys[i]->Length-1; j++){
f1 = sys[i]->Loc[j-1] - sys[i]->Loc[j];
f2 = sys[i]->Loc[j+1] - sys[i]->Loc[j];
mag1 = sqrt(f1*f1);
mag2 = sqrt(f2*f2);
sys[i]->Vel[j] += ((mag1-linksize)*sk/mag1)*f1 + ((mag2-linksize)*sk/mag2)*f2;
}
f1 = sys[i]->Loc[1] - sys[i]->Loc[0];
f2 = sys[i]->Loc[sys[i]->Length-2] - sys[i]->Loc[sys[i]->Length-1];
mag1 = sqrt(f1*f1);
mag2 = sqrt(f2*f2);
sys[i]->Vel[0] += ((mag1-linksize)*sk/mag1)*f1;
sys[i]->Vel[sys[i]->Length-1] += ((mag2-linksize)*sk/mag2)*f2;
//and now, the stiffness
for(int j=2; j<sys[i]->Length-2; j++){
sys[i]->Vel[j] += (sys[i]->Loc[j]*2.0 - sys[i]->Loc[j+2] - sys[i]->Loc[j-2])*stiffk;
}
sys[i]->Vel[1] += (sys[i]->Loc[1] - sys[i]->Loc[3])*stiffk;
sys[i]->Vel[0] += (sys[i]->Loc[0] - sys[i]->Loc[2])*stiffk;
sys[i]->Vel[sys[i]->Length-2] += (sys[i]->Loc[sys[i]->Length-2] - sys[i]->Loc[sys[i]->Length-4])*stiffk;
sys[i]->Vel[sys[i]->Length-1] += (sys[i]->Loc[sys[i]->Length-1] - sys[i]->Loc[sys[i]->Length-3])*stiffk;
//finally, pin the first point to its initial location
for(int j=0; j<numpin; j++){
sys[i]->Vel[j] += (pins[i*numpin + j] - sys[i]->Loc[j])*pk;
}
//cout << sys[i]->Loc[0];
//wall repulsion
for(int j=1; j<sys[i]->Length; j++){
if(sys[i]->Loc[j].zcomp() < .5){
sys[i]->Vel[j] += (-100.0 + 100.0/(sys[i]->Loc[j].zcomp()*sys[i]->Loc[j].zcomp()*sys[i]->Loc[j].zcomp()*sys[i]->Loc[j].zcomp()*16.0))*z_hat;
if(sys[i]->Loc[j].zcomp() < 0){
cout<<"warning!!!, wall broken!! " << "index:" << i <<"-"<< j << " "<< sys[i]->Loc[j].zcomp() <<endl;
}
}
}
}
}
KinesinShift::KinesinShift(double ck){
this->k = ck;
}
void
KinesinShift::Act(vector<Polymer*> sys, Polymer* yolk){
for(unsigned int i=0; i<sys.size() ; i++){
for(int j=1; j<sys[i]->Length-1; j++){
sys[i]->Vel[j] += (sys[i]->Loc[j-1] - sys[i]->Loc[j+1])*k;
}
sys[i]->Vel[0] += (sys[i]->Loc[0] - sys[i]->Loc[1])*k;
sys[i]->Vel[sys[i]->Length-1] += (sys[i]->Loc[sys[i]->Length-2] - sys[i]->Loc[sys[i]->Length-1])*k;
}
}
OseenTensor::OseenTensor(vector<Polymer*> csys, double ck){
this->k = ck;
for(unsigned int i=0; i< csys.size(); i++){
tempsys.push_back(new Polymer(csys[i]->Length));
}
}
void
OseenTensor::Act(vector<Polymer*> sys, Polymer* yolk){
for(unsigned int n=0; n < sys.size(); n++){
for(int i=0; i<sys[n]->Length; i++){
tempsys[n]->Vel[i].set(0,0,0);
//double loop all the way...
for(unsigned int m=0; m < sys.size(); m++){
for(int j=0; j<sys[m]->Length; j++){
//if looking at yourself
/*
if( i==j && m==n ){
tempsys[n]->Vel[i] += 0.3*sys[m]->Vel[j];
continue;
}
*/
//calculate some values that will be needed in the oseen tensor, and cache them temporarily
dif = sys[m]->Loc[j] - sys[n]->Loc[i];
normsq = dif*dif;
norm = sqrt(normsq);
//wall calculation caching
mirdif = dif;
mirdif.setZ(sys[m]->Loc[j].zcomp() + sys[n]->Loc[i].zcomp());
mirnormsq = mirdif*mirdif;
//mirnorm4 = mirnormsq*mirnormsq;
mirnorm = sqrt(mirnormsq);
h = sys[n]->Loc[i].zcomp();
//hminusz = h - mirdif.zcomp();
vect_d hardcore;
/*
if( norm == 0.0 ){
continue;
}
*/
if( i!=j || m!=n){
//hardcore repulsion
if( norm < .5 ){
hardcore = (1.0 - 1.0/(normsq*normsq*16.0))*dif;//tempsys[n]->Vel[i] += (1.0 - 1.0/(normsq*normsq*16.0))*dif;
}
else{
hardcore = dif*0.0;
}
if( norm < .05 ){
cout << "close " << norm<< endl;
}
//calculate the oseen tensor
tempsys[n]->Vel[i] += (sys[m]->Vel[j] + hardcore + (dif * (dif*(sys[m]->Vel[j]+hardcore)))*(1.0/normsq) )*(k/norm);
}
else{
//hardcore = dif*0.0;
tempsys[n]->Vel[i] += sys[m]->Vel[j];//+hardcore;
}
//now to include a wall
if( i!=j || m!=n ){
mirVel = sys[m]->Vel[j]+hardcore;
mirVel.setZ(-mirVel.zcomp());
mVeldotmDif = mirVel*mirdif;
tempsys[n]->Vel[i] += ( -1.0*(sys[m]->Vel[j]+hardcore +(mirdif * (mirdif*(sys[m]->Vel[j]+hardcore)))*(1.0/mirnormsq) ) //reflected oseen
+ (2*h/mirnormsq)*(
- (sys[n]->Loc[i].zcomp())*mirVel //mirrored force direction
+ (3*mVeldotmDif*sys[n]->Loc[i].zcomp()/mirnormsq - mirVel.zcomp())*mirdif //mirrored position direction
+ (mVeldotmDif)*z_hat //z_hat component correction
)
) * (k/mirnorm);
}
}
} //end inner loop
for(int j=0;j<yolk->Length;j++){
dif = sys[n]->Loc[i] - yolk->Loc[j];
normsq = dif*dif;
norm = sqrt(normsq);
//wall calculation caching
mirdif = dif;
mirdif.setZ(sys[n]->Loc[i].zcomp() + yolk->Loc[j].zcomp());
mirnormsq = mirdif*mirdif;
//mirnorm4 = mirnormsq*mirnormsq;
mirnorm = sqrt(mirnormsq);
h = yolk->Loc[j].zcomp();
vect_d hardcore;
//hardcore repulsion
if( norm < .5 ){
hardcore = (1.0 - 1.0/(normsq*normsq*16.0))*dif;//tempsys[n]->Vel[i] += (1.0 - 1.0/(normsq*normsq*16.0))*dif;
}
else{
hardcore = dif*0.0;
}
//calculate the oseen tensor
yolk->Vel[j] += (sys[n]->Vel[i] + hardcore + (dif * (dif*(sys[n]->Vel[i]+hardcore)))*(1.0/normsq) )*(k/norm);
//now to include a wall
mirVel = sys[n]->Vel[i]+hardcore;
mirVel.setZ(-mirVel.zcomp());
mVeldotmDif = mirVel*mirdif;
yolk->Vel[j] += ( -1.0*(sys[n]->Vel[i]+hardcore +(mirdif * (mirdif*(sys[n]->Vel[i]+hardcore)))*(1.0/mirnormsq) ) //reflected oseen
+ (2*h/mirnormsq)*(
- (yolk->Loc[j].zcomp())*mirVel //mirrored force direction
+ (3*mVeldotmDif*yolk->Loc[j].zcomp()/mirnormsq - mirVel.zcomp())*mirdif //mirrored position direction
+ (mVeldotmDif)*z_hat //z_hat component correction
)
) * (k/mirnorm);
}
}
} //end outer loop
for(unsigned int n=0; n < sys.size(); n++){
for(int i=0; i<sys[n]->Length; i++){
sys[n]->Vel[i] = tempsys[n]->Vel[i];
}
}
}