-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.c
More file actions
365 lines (328 loc) · 11.3 KB
/
Copy pathmain.c
File metadata and controls
365 lines (328 loc) · 11.3 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#include "fstrack_flow.h"
/*
reads velocities, traces particles, and keeps track of finite strain
or texture following Kaminski and Ribe approach
uses GMT grd files to read in velocities at steady state, or at different
timesteps
performs Runge Kutta integration to follow stream lines and compute
finite strain
type 'fstrack -h' for man page and explanations
$Id: main.c,v 1.33 2010/12/31 18:59:17 becker Exp $
*/
int main(int argc, char **argv)
{
int i,j,nout,itout;
char ofname[STRLEN],prefix[400];
struct mod *model;
char timebuf[2000];
time_t t_now,t_start;
my_boolean zero_boundary_vr = TRUE;
fprintf(stderr,"%s: version $Id: main.c,v 1.33 2010/12/31 18:59:17 becker Exp $\n",
argv[0]);
fprintf(stderr,"%s: compiled on %s at %s\n",
argv[0],__DATE__,__TIME__);
model=(struct mod *)calloc(1,sizeof(struct mod));// allocate with zeroes!
//
// set the default parameters
set_defaults(model);
//
// check for command line parameters
check_for_parameters(argc,argv,model);
//
// read velocities (for this to work, the two routines above have to been called)
read_vel_grids(model,model->verbose,zero_boundary_vr);
// test input
// alayer=20;
// write_ascii_layer(model->vt,alayer,model,"vt","vt.dat",model->velscale);
// initialize the tracer field
initialize_tracers(model);
if(!model->ntracer){
PE("main: no tracers generated, exciting");
exit(-1);
}
if(MDP->strain_fraction_from_gamma)
sprintf(prefix,"tracer.er"); /* using er.i.grd alpha grids */
else
sprintf(prefix,"tracer");
itout = (int)(model->ntracer / 10.0)+1; /* output of time each itout */
// output of some tracer paths each nout
if(!model->ntout){
fprintf(stderr,"main: increasing tracer sampling to unity\n");
model->ntout = 1;
}
nout = model->ntracer/model->ntout;
if(nout == 0)nout = 1; /* make sure we're not dividing by zero */
/*
switch modes
*/
switch(model->amode){
case FORWARD_TIME:
case BACKWARD_DEPTH:
case BACKWARD_STRAIN:
case FORWARD_STRAIN:
case BACKWARD_TIME:
case BACKWARD_TIME_DEPTH:
t_start = time(NULL);strftime(timebuf,79,"%a, %F, %H:%M:%S",localtime(&t_start));
fprintf(stderr,"\nmain: starting main tracer loop at %s\n",timebuf);
for(i=0;i < model->ntracer;i++){
/*
advect tracer to bailout criterion, and save nsteps during the advection
path
*/
advect((model->tracer+i),model,model->nsteps,model->amode);
if(i%nout==0){
/*
output of tracer specific quantities along path
*/
// write history
sprintf(ofname,"hist.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,LOCATION_LLZ,
model->verbose,model);
// deformation tensor
sprintf(ofname,"def.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,DEFORMATION_TENSOR,
model->verbose,model);
// left stretch tensor components
sprintf(ofname,"strain.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,STRAIN_COMP,
model->verbose,model);
if(0){
// cartesian left stretch strain components
sprintf(ofname,"xyztL2c.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,
XYZ_STRAIN_CART_COMP,
model->verbose,model);
}
if(1){
// velocity gradient matrix
sprintf(ofname,"vgm.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,LOCATION_VGM_RTPTVGM,
model->verbose,model);
}
if(1){
// velocity gradient matrix, rtp system for coords, matrix cartesian
sprintf(ofname,"vgm.sc.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,LOCATION_VGM_RTPTVGM_CART,
model->verbose,model);
}
if(0){
// velocity gradient matrix, xyz system for coords, matrix cartesian
sprintf(ofname,"vgm.cc.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,LOCATION_VGM_XYZTVGM_CART,
model->verbose,model);
}
// sqrt(eigenvalues of left stretch strain) and eigenvectors
sprintf(ofname,"seval.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,STRAIN_EVAL,
model->verbose,model);
if(0){
// sqrt(eigenvalues of left stretch strain) and eigenvectors, all in cartesian system
sprintf(ofname,"seval.c.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,STRAIN_EVAL_CART,
model->verbose,model);
}
if(1){
/* strain-rate and vorticity */
sprintf(ofname,"sv.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,STRAINRATE_VORTICITY,
model->verbose,model);
}
if(0){
/*
compute the ISA axes for this tracer
*/
for(j=0;j<model->tracer[i].nstate;j++){
/* loop through all states */
calc_isa((model->tracer+i),j,model);
}
/* output */
sprintf(ofname,"isa.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,ISA_AXES,
model->verbose,model);
}
if(MDP->texture_mode != NO_TEXTURE){
/*
texture was computed
*/
if(model->sav_out){
/*
stiffness tensor
*/
if(MDP->drex_module != EMOD_CONST)
/* variable version, this changes the filename */
sprintf(ofname,"savd.%i.%s",i,model->ostring);
else
sprintf(ofname,"sav.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,
TEXTURE_SAV,model->verbose,model);
}
/*
best fit axis for tranverse isotropy, percentage
anisotropy derived from SAV, and l/n ratio (vsv^2/vsh^2)
*/
if(MDP->drex_module != EMOD_CONST)
sprintf(ofname,"tid.%i.%s",i,model->ostring);
else
sprintf(ofname,"ti.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,
TEXTURE_TI,model->verbose,model);
/*
Rayleigh wave 2phi and 4phi terms
*/
if(MDP->drex_module != EMOD_CONST)
sprintf(ofname,"rphid.%i.%s",i,model->ostring);
else
sprintf(ofname,"rphi.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,
TEXTURE_RAYLEIGH_RPHI,
model->verbose,model);
if(MDP->drex_compute_avg_axes){
/* statistics for a,b,c axes */
sprintf(ofname,"polestat.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,
TEXTURE_STATS,model->verbose,model);
}
if(MDP->drex_save_pole){
/*
pole figure information
*/
sprintf(ofname,"pole.%i.%s",i,model->ostring);
write_tracer_history((model->tracer+i),ofname,
TEXTURE_ODF,model->verbose,model);
}
}
}
if((i%itout) == 0){
t_now = time(NULL);
strftime(timebuf,79,"%a, %H:%M",localtime(&t_now));
fprintf(stderr,"main: done with tracer %6i out of %6i at %s, avg %11g s/tracer\n",
i+1,model->ntracer,timebuf,
difftime(t_now,t_start)/(COMP_PRECISION)(i+1));
}
} /* end i tracer loop */
/*
main output section
*/
//
// print out tracers by depth levels (layers)
//
for(j=0,i=0;i < model->ntlevels;i++){
//
// write initial tracer positions to file
//
sprintf(ofname,"%s.i.l.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1, 0,ofname,ALL_TRACER_LLZAT,
model->verbose);
//
// write final tracer positions
//
sprintf(ofname,"%s.f.l.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1,-1,ofname,ALL_TRACER_LLZAT,
model->verbose);
//
// final tracer left stretch upper right half strain components
//
sprintf(ofname,"%s.%s.%g.%s",prefix,TSFILE,ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1,-1,ofname,
ALL_TRACER_STRAIN_COMP,model->verbose);
if(0){
//
// final tracer L strain eigenvalues and vectors as angles
//
sprintf(ofname,"%s.f.e.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1,-1,ofname,
ALL_TRACER_STRAIN_EIGEN,model->verbose);
}
//
// final tracer all F deformation matrix
//
sprintf(ofname,"%s.%s.%g.%s",prefix,TFFILE,ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1,-1,ofname,
ALL_TRACER_DEFORMATION,model->verbose);
if((MDP->texture_mode != NO_TEXTURE)&&(MDP->rotate_grain_coord_sys)){
/*
LPO fabrics were computed and we are rotating into a
geographic coordinate system (local S-E-U system). if not, we
are likely debugging and don't want to confuse things
*/
/*
best fit transverse isotropy axis from texture SAV and vsh/vsv ratio
*/
if(MDP->drex_module != EMOD_CONST)
sprintf(ofname,"%s.tid.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
else
sprintf(ofname,"%s.ti.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1,-1,ofname,
ALL_TRACER_TI,model->verbose);
if(MDP->drex_module != EMOD_CONST)
sprintf(ofname,"%s.rphid.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
else
sprintf(ofname,"%s.rphi.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1,-1,ofname,
ALL_TRACER_RPHI,model->verbose);
if(model->sav_out){
/*
stiffness tensor
*/
if(MDP->drex_module != EMOD_CONST)
sprintf(ofname,"%s.savd.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
else
sprintf(ofname,"%s.sav.%g.%s",prefix,ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1,-1,ofname,
ALL_TRACER_SAV,model->verbose);
}
}
// increment tracer offset counter for each layer
j += model->ntd[i];
}
if(model->ntracer < 10000){
// all tracer histories
sprintf(ofname,"%s.hist.%s",prefix,model->ostring);
write_all_tracer_history(model,ofname,TRUE);
// all tracer histories as xyz
sprintf(ofname,"%s.hist.xyz.%s",prefix,model->ostring);
write_all_tracer_history(model,ofname,FALSE);
}else{
PE("main: skipping tracer history output");
}
break;
case ISA:
/*
compute the ISA axis
*/
PE("main: running main tracer loop for ISA");
for(i=0; i < model->ntracer;i++){
/* compute the ISA for all tracers, use state 0*/
calc_isa((model->tracer+i),0,model);
}
for(j=0,i=0;i<model->ntlevels;i++){ /* output */
sprintf(ofname,"%s.%s.%g.%s",prefix,TISAFILE,
ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1,-1,ofname,
ALL_TRACER_ISA,model->verbose);
j += model->ntd[i];
}
PE("main: ISA done");
break;
case CALC_LYAPUNOV:
if(MDP->texture_mode != NO_TEXTURE)
PEE("main: error: cannot compute Lyapunov exponents and texture at same time");
// trace Lyapunov exponents, in this case L2 of each tracer will have the
// exponents
for(i=0;i<model->ntracer;i++)
calc_lyapunov(model,i);
for(j=0,i=0;i<model->ntlevels;i++){
// write tracer positions and lyapunov exponents to file
sprintf(ofname,"tracer.f.lya.%g.%s",ZDEPTH(model->tlevel[i]),model->ostring);
write_tracer_field(model,j,j+model->ntd[i]-1, 0,ofname,ALL_TRACER_LYA,
model->verbose);
j += model->ntd[i];
}
break;
default:
PEE("main: opmode error");
break;
}
PE("main: done");
return (0);
}