-
Notifications
You must be signed in to change notification settings - Fork 1
/
tdlscompute.edp
240 lines (238 loc) · 8.45 KB
/
tdlscompute.edp
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//
// tdlscompute.edp
// Chris Douglas
//
// EXAMPLE USAGE:
// Compute time-domain linear simulation with IC from input file:
// ff-mpirun -np 4 tdlscompute.edp -fi <FILEIN> -fo <FILEOUT>
//
// NOTE: This file should not be changed unless you know what you're doing.
//
load "iovtk"
load "PETSc-complex"
include "settings.idp"
include "macros_bifbox.idp"
// arguments
string meshin = getARGV("-mi", ""); // input meshfile with extension
string filein = getARGV("-fi", "");
string basefilein = getARGV("-bfi", "");
string fileout = getARGV("-fo", filein);
string symstr = getARGV("-sym", "0");
bool adj = getARGV("-adj", 0);
real amplitude = abs(getARGV("-amp", 1.0));
int select = getARGV("-select", 1);
int count = getARGV("-count", 0);
int savecount = getARGV("-scount", 1);
int maxcount = getARGV("-maxcount", 100);
string tstype = getARGV("-ts_type", "bdf");
int tsmaxsnesfailures = getARGV("-ts_max_snes_failures", -1);
real tsdt = getARGV("-ts_dt", 0.01);
string tsadapttype = getARGV("-ts_adapt_type", "none");
string sneslinesearchtype = getARGV("-snes_linesearch_type","basic");
// Load mesh, make FE basis
string fileroot, fileext = parsefilename(filein, fileroot); //extract file name and extension
parsefilename(fileout, fileout); // trim extension from output file, if given
string basefileroot, basefileext = parsefilename(basefilein, basefileroot);
if((fileext == "mode" || fileext == "resp" || fileext == "rslv" || fileext == "tdls") && basefilein == ""){
basefilein = readbasename(workdir + filein);
basefileext = parsefilename(basefilein, basefileroot);
}
if(meshin == "") meshin = readmeshname(workdir + filein); // get mesh file
string meshroot, meshext = parsefilename(meshin, meshroot);
if(count > 0) {
fileroot = fileroot(0:fileroot.rfind("_" + count)-1); // get file root
meshroot = meshroot(0:meshroot.rfind("_" + count)-1); // get file root
}
Th = readmeshN(workdir + meshin);
Thg = Th;
buildDmesh(Th);
restu = restrict(XMh, XMhg, n2o);
XMh defu(ub), defu(um2), defu(um3);
XMh<complex> defu(um);
real time = 0.0;
if (count == 0){
if(fileext == "mode") {
complex eigenvalue;
um[] = loadmode(fileroot, meshin, sym, eigenvalue);
}
else if(fileext == "resp") {
real omega;
um[] = loadresp(fileroot, meshin, sym, omega);
}
else if(fileext == "rslv") {
real omega, gain;
complex[int] fm;
um[] = loadrslv(fileroot, meshin, fm, sym, omega, gain);
}
else if(fileext == "tdls") {
real time;
um[] = loadtdls(fileroot, meshin, sym, time);
}
else if(fileext == "fold") {
real[string] alpha;
real beta;
real[int] qm(um[].n), qma(um[].n);
ub[] = loadfold(fileroot, meshin, qm, qma, alpha, beta);
if(adj) qm = qma;
um[].re = qm;
}
else if(fileext == "hopf") {
real omega;
complex[string] alpha;
complex beta;
complex[int] qma(um[].n);
ub[] = loadhopf(fileroot, meshin, um[], qma, sym, omega, alpha, beta);
if(adj) um[] = qma;
}
else if(fileext == "foho") {
real omega;
complex[string] alpha1;
real[string] alpha2;
complex beta1, gamma12, gamma13;
real beta22, beta23, gamma22, gamma23;
complex[int] q1ma(um[].n);
real[int] q2m(um[].n), q2ma(um[].n);
ub[] = loadfoho(fileroot, meshin, um[], q1ma, q2m, q2ma, sym, omega, alpha1, alpha2, beta1, beta22, beta23, gamma12, gamma13, gamma22, gamma23);
if (select == 1){
if(adj) um[] = q1ma;
}
else if(select == 2){
um[].re = q2m;
if(adj) um[].re = q2ma;
um[].im = 0.0;
sym = 0.0;
}
}
else if(fileext == "hoho") {
real[int] sym2(sym.n);
real omega1, omega2;
complex[string] alpha1, alpha2;
complex beta1, beta2, gamma1, gamma2, gamma12, gamma13, gamma22, gamma23;
complex[int] q1ma(um[].n), q2m(um[].n), q2ma(um[].n);
ub[] = loadhoho(fileroot, meshin, um[], q1ma, q2m, q2ma, sym, sym2, omega1, omega2, alpha1, alpha2, beta1, beta2, gamma1, gamma2, gamma12, gamma13, gamma22, gamma23);
if(select == 1 && adj) um[] = q1ma;
else if (select == 2 && !adj) um[] = q2m;
else if (select == 2 && adj) um[] = q2ma;
if(select == 2) sym = sym2;
}
else if(fileext == "porb") {
int Nh;
real omega;
complex[int, int] qh(um[].n, Nh);
ub[] = loadporb(fileroot, meshin, qh, sym, omega, Nh);
for (int nh = 0; nh < Nh; nh++) um[] += qh(:,nh);
}
um[] *= amplitude;
}
else {
um[] = loadtdls(fileroot + "_" + count, meshin, sym, time);
}
if (basefileext == "base") {
ub[] = loadbase(basefileroot, meshin);
}
else if(basefileext == "fold") {
real[string] alpha;
real beta;
real[int] qm, qma;
ub[] = loadfold(basefileroot, meshin, qm, qma, alpha, beta);
}
else if(basefileext == "hopf") {
real omega;
real[int] sym1(sym.n);
complex[string] alpha;
complex beta;
complex[int] qm, qma;
ub[] = loadhopf(basefileroot, meshin, qm, qma, sym1, omega, alpha, beta);
}
else if(basefileext == "foho") {
real omega;
real[int] sym1(sym.n);
complex[string] alpha1;
complex beta1, gamma12, gamma13;
real[string] alpha2;
real beta22, beta23, gamma22, gamma23;
complex[int] q1m, q1ma;
real[int] q2m, q2ma;
ub[] = loadfoho(basefileroot, meshin, q1m, q1ma, q2m, q2ma, sym1, omega, alpha1, alpha2, beta1, beta22, beta23, gamma12, gamma13, gamma22, gamma23);
}
else if(basefileext == "hoho") {
real[int] sym1(sym.n), sym2(sym.n);
real omega1, omega2;
complex[string] alpha1, alpha2;
complex beta1, beta2, gamma1, gamma2, gamma12, gamma13, gamma22, gamma23;
complex[int] q1m, q1ma, q2m, q2ma;
ub[] = loadhoho(basefileroot, meshin, q1m, q1ma, q2m, q2ma, sym1, sym2, omega1, omega2, alpha1, alpha2, beta1, beta2, gamma1, gamma2, gamma12, gamma13, gamma22, gamma23);
}
else if(basefileext == "tdns") {
real time;
ub[] = loadtdns(basefileroot, meshin, time);
}
else if(basefileext == "porb") {
int Nh=1;
real[int] sym1(sym.n);
real omega;
complex[int, int] qh(um[].n, Nh);
ub[] = loadporb(basefileroot, meshin, qh, sym1, omega, Nh);
}
// Create distributed Mat
Mat<complex> J;
createMatu(Th, J, Pk);
Mat<complex> M(J), Js(J);
complex[int] ik(sym.n), ik2(sym.n), ik3(sym.n);
real iomega = 0.0, iomega2 = 0.0, iomega3 = 0.0;
include "eqns.idp" // load equations
// initialize
complex[int] q(ub[].n), qc(J.n);
q.re = ub[];
ChangeNumbering(J, q, qc);
ChangeNumbering(J, q, qc, inverse = true, exchange = true);
ub[] = q.re;
ChangeNumbering(J, um[], qc);
if (count == 0){
ChangeNumbering(J, um[], qc, inverse = true);
basefilein = (basefilein == "") ? filein : basefilein;
savetdls(fileout + "_0", (savecount > 0 ? fileout : ""), meshin, basefilein, filein, sym, time, true);
}
Js = vJ(XMh, XMh, tgv = -10);
M = vM(XMh, XMh, tgv = -10);
// Function to build residual "F(t,u,\dot{u})" operator in PETSc numbering
func PetscScalar[int] funcF(real t, PetscScalar[int]& qPETSc, PetscScalar[int]& qdotPETSc) {
PetscScalar[int] temp(qPETSc.n), FPETSc(qPETSc.n);
MatMult(Js, qPETSc, FPETSc);
MatMult(M, qdotPETSc, temp);
FPETSc += temp;
return FPETSc;
}
// Function to build Jacobian operator in PETSc numbering
func int funcJ(real t, PetscScalar[int]& qPETSc, PetscScalar[int]& qdotPETSc, real a) {
if(abs(a - iomega) > 1.0e-10) {
iomega = a;
J = vJ(XMh, XMh, tgv = -1);
}
return 0;
}
// Function to monitor solution progress
func int funcMon(int s, real t, PetscScalar[int]& in) {
if(s > 0){
tsdt = t - time;
count++;
if(mpirank == 0) cout << " " << count + ":\tdt = " + tsdt + ",\ttime = " + t << endl;
ChangeNumbering(J, um[], in, inverse = true);
savetdls(fileout + "_" + count, ((savecount > 0) ? fileout : ""), meshin, basefilein, filein, sym, t, (count % savecount == 0))
}
time = t;
return 0;
}
// set up Mat parameters
IFMACRO(Jprecon) Jprecon(0); ENDIFMACRO
set(J, IFMACRO(Jsetargs) Jsetargs, ENDIFMACRO sparams = KSPparams);
TSSolve(J, funcJ, funcF, qc, monitor = funcMon, sparams = " -ts_init_time " + time
+ " -ts_type " + tstype
+ " -ts_max_snes_failures " + tsmaxsnesfailures
+ " -ts_dt " + tsdt
+ " -ts_max_steps " + (maxcount-count)
+ " -ts_adapt_type " + tsadapttype
+ " -snes_linesearch_type " + sneslinesearchtype
+ " -options_left no "
);