-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cu
318 lines (272 loc) · 10.1 KB
/
main.cu
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
/*
Hello world of wave propagation in CUDA. FDTD acoustic wave propagation in homogeneous medium. Second order accurate in time and eigth in space.
Oleg Ovcharenko
Vladimir Kazei, 2019
*/
#include <rsf.hh>
#include <iostream>
#include <string>
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#include "string.h"
#include "btree.cuh"
using namespace std;
/*
Add this to c_cpp_properties.json if linting isn't working for CUDA libraries
"includePath": [
"/usr/local/cuda-10.0/targets/x86_64-linux/include",
"${workspaceFolder}/**"
],
*/
//typedef struct{
//int nShots;
//int srcPosX;
//int srcPosY;
//int firstReceptorPos;
//int nReceptors;
//int lastReceptorPos;
//int incShots;
//int incRec;
//int modelNx;
//int modelNy;
//int modelNxBorder;
//int modelNyBorder;
//float modelDx;
//float modelDy;
//int taperBorder;
//// Auxiliaries
//size_t nxy;
//size_t nbxy;
//size_t nbytes;
//} geometry;
//typedef struct{
//float *velField;
//float *extVelField;
//float *firstLayerVelField;
//float *reflecitivy;
//float maxVel;
//} velocity;
//typedef struct{
//float timeStep;
//int timeSamplesNt;
//float *seismogram;
//} seismicData;
//#include "cuwaveprop2d.cu"
//using namespace std;
//void dummyVelField(int nxb, int nyb, int nb, float *h_vpe, float *h_dvpe)
//{
//for (int i = 0; i < nyb; i++){
//for (int j = 0; j < nxb; j++){
//h_dvpe[j * nyb + i] = h_vpe[j * nyb + nb];
//}
//}
//}
//void expand(int nb, int nyb, int nxb, int nz, int nx, float *a, float *b)
//[>< expand domain of 'a' to 'b': a, size=nz*nx; b, size=nyb*nxb; ><]
//{
//int iz,ix;
//for (ix=0;ix<nx;ix++) {
//for (iz=0;iz<nz;iz++) {
//b[(nb+ix)*nyb+(nb+iz)] = a[ix*nz+iz];
//}
//}
//for (ix=0; ix<nxb; ix++) {
//for (iz=0; iz<nb; iz++) b[ix*nyb+iz] = b[ix*nyb+nb];//top
//for (iz=nz+nb; iz<nyb; iz++) b[ix*nyb+iz] = b[ix*nyb+nb+nz-1];//bottom
//}
//for (iz=0; iz<nyb; iz++){
//for(ix=0; ix<nb; ix++) b[ix*nyb+iz] = b[nb*nyb+iz];//left
//for(ix=nb+nx; ix<nxb; ix++) b[ix*nyb+iz] = b[(nb+nx-1)*nyb+iz];//right
//}
//}
//void abc_coef (int nb, float *abc)
//{
//for(int i=0; i<nb; i++){
//abc[i] = exp (-pow(0.002 * (nb - i + 1),2.0));
//}
//}
//void taper (int nx, int ny, int nb, float *abc, float *campo)
//{
//int nxb = nx + 2 * nb;
//int nyb = ny + 2 * nb;
//for(int j=0; j<nxb; j++){
//for(int i=0; i<nb; i++){
//campo[j * nyb + i] *= abc[i];
//campo[j * nyb + (nb + ny + i)] *= abc[nb - i - 1];
//}
//}
//for(int i=0; i<nyb; i++){
//for(int j=0; j<nb; j++){
//campo[j * nyb + i] *= abc[j];
//campo[(nb + nx + j) * nyb + i] *= abc[nb - j - 1];
//}
//}
//}
//sf_file createFile3D (const char *name, int dimensions[3], float spacings[3], int origins[3])
//{
//sf_file Fdata = NULL;
//Fdata = sf_output(name);
//char key_n[6],key_d[6],key_o[6];
//for (int i = 0; i < 3; i++){
//sprintf(key_n,"n%i",i+1);
//sprintf(key_d,"d%i",i+1);
//sprintf(key_o,"o%i",i+1);
//sf_putint(Fdata,key_n,dimensions[i]);
//sf_putint(Fdata,key_d,spacings[i]);
//sf_putint(Fdata,key_o,origins[i]);
//}
//return Fdata;
//}
//geometry getParameters(sf_file FvelModel, sf_file Fshots)
//{
//geometry param;
//sf_histint(Fshots,"n2",¶m.nReceptors);
//sf_histint(Fshots,"sybeg",¶m.srcPosY);
//sf_histint(Fshots,"sxbeg",¶m.srcPosX);
//sf_histint(Fshots,"gxbeg",¶m.firstReceptorPos);
//sf_histint(Fshots,"n3",¶m.nShots);
//sf_histint(Fshots,"incShots",¶m.incShots);
//sf_histint(Fshots,"incRec",¶m.incRec);
//sf_histint(FvelModel, "n1",¶m.modelNy);
//sf_histint(FvelModel, "n2", ¶m.modelNx);
//sf_histfloat(FvelModel, "d1",¶m.modelDy);
//sf_histfloat(FvelModel, "d2", ¶m.modelDx);
//param.lastReceptorPos = param.firstReceptorPos + param.nReceptors;
//param.taperBorder = 0.3 * param.modelNx;
//param.nxy = param.modelNx * param.modelNy;
//param.modelNxBorder = param.modelNx + 2 * param.taperBorder;
//param.modelNyBorder = param.modelNy + 2 * param.taperBorder;
//param.nbxy = param.modelNxBorder * param.modelNyBorder;
//param.nbytes = param.nbxy * sizeof(float); // bytes to store modelNxBorder * modelNyBorder
//return param;
//}
//velocity getVelFields(sf_file FvelModel, geometry param)
//{
//velocity h_model;
//h_model.velField = new float[param.nxy];
//sf_floatread(h_model.velField, param.nxy, FvelModel);
//h_model.extVelField = new float[param.nbxy];
//memset(h_model.extVelField,0,param.nbytes);
//expand(param.taperBorder, param.modelNyBorder, param.modelNxBorder, param.modelNy, param.modelNx, h_model.velField, h_model.extVelField);
//h_model.maxVel = h_model.velField[0];
//for(int i=1; i < param.nxy; i++){
//if(h_model.velField[i] > h_model.maxVel){
//h_model.maxVel = h_model.velField[i];
//}
//}
//h_model.firstLayerVelField = new float[param.nbxy];
//dummyVelField(param.modelNxBorder, param.modelNyBorder, param.taperBorder, h_model.extVelField, h_model.firstLayerVelField);
////printf("MODEL:\n");
////printf("\t%i x %i\t:param.modelNy x param.modelNx\n", param.modelNy, param.modelNx);
////printf("\t%f\t:param.modelDx\n", param.modelDx);
////printf("\t%f\t:h_model.velField[0]\n", h_model.velField[0]);
//return h_model;
//}
//float* tapermask(geometry param)
//{
//float *h_abc = new float[param.taperBorder];
//float *h_tapermask = new float[param.nbxy];
//for(int i=0; i < param.nbxy; i++){
//h_tapermask[i] = 1;
//}
//abc_coef(param.taperBorder, h_abc);
//taper(param.modelNx, param.modelNy, param.taperBorder, h_abc, h_tapermask);
//delete[] h_abc;
//return h_tapermask;
//}
//seismicData allocHostSeisData(geometry param, sf_file Fshots)
//{
//seismicData h_seisData;
//sf_histfloat(Fshots,"d1",&h_seisData.timeStep);
//sf_histint(Fshots,"n1",&h_seisData.timeSamplesNt);
//h_seisData.seismogram = new float[param.nShots * param.nReceptors * h_seisData.timeSamplesNt];
//sf_floatread(h_seisData.seismogram, param.nShots * param.nReceptors * h_seisData.timeSamplesNt, Fshots);
//return h_seisData;
//}
//float* fillSrc(geometry param, velocity h_model, seismicData h_seisData)
//{
//float* wavelet;
//float f0 = 10.0; // source dominawavelet.timeSamplesNt frequency, Hz <]
//float t0 = 1.2 / f0; // source padding to move wavelet from left of zero <]
//float tbytes = h_seisData.timeSamplesNt * sizeof(float);
//float* time = (float *)malloc(tbytes);
//wavelet = (float *)malloc(tbytes);
//// Fill source waveform vector
//float a = PI * PI * f0 * f0; // const for wavelet <]
//float dt2dx2 = (h_seisData.timeStep * h_seisData.timeStep) / (param.modelDx * param.modelDx); // const for fd stencil <]
//for (int it = 0; it < h_seisData.timeSamplesNt; it++)
//{
//time[it] = it * h_seisData.timeStep;
//// Ricker wavelet (Mexican hat), second derivative of Gaussian
//wavelet[it] = 1e10 * (1.0 - 2.0 * a * pow(time[it] - t0, 2)) * exp(-a * pow(time[it] - t0, 2));
//wavelet[it] *= dt2dx2;
//}
//delete[] time;
////printf("TIME STEPPING:\n");
////printf("\t%e\t:h_seisData.timeStep\n", h_seisData.timeStep);
////printf("\t%i\t:h_seisData.timeSamplesNt\n", h_seisData.timeSamplesNt);
//return wavelet;
//}
//void test_getParameters (geometry param, seismicData h_seisData)
//{
//cerr<<"param.incShots: "<<param.incShots<<endl;
//cerr<<"param.incShots: "<<param.incShots<<endl;
//cerr<<"param.modelDims nx = "<<param.modelNx<<" ny = "<<param.modelNy<<endl;
//cerr<<"param.modelDx = "<<param.modelDx<<" param.modelDy = "<<param.modelDy<<endl;
//cerr<<"param.taperBorder = "<<param.taperBorder<<endl;
//cerr<<"param.nShots "<<param.nShots<<endl;
//cerr<<"param.nReceptors "<<param.nReceptors<<endl;
//cerr<<"param.firstReceptorPos "<<param.firstReceptorPos<<endl;
//cerr<<"param.lastReceptorPos "<<param.lastReceptorPos<<endl;
//cerr<<"h_seisData.timeSamplesNt "<<h_seisData.timeSamplesNt<<endl;
//cerr<<"h_seisData.timeStep "<<h_seisData.timeStep<<endl;
//}
/*
===================================================================================
MAIN
===================================================================================
*/
int main(int argc, char *argv[])
{
/* Main program that reads and writes data and read input variables */
bool verb;
sf_init(argc,argv); // init RSF
if(! sf_getbool("verb",&verb)) verb=0;
// Setting up I/O files
sf_file Fvel=NULL;
Fvel = sf_input("vel");
sf_file Fshots=NULL;
Fshots = sf_input("shots");
// Getting command line parameters
geometry param = getParameters(Fvel, Fshots);
// Allocate memory for velocity model
velocity h_model = getVelFields (Fvel, param);
cerr<<"vp = "<<h_model.maxVel<<endl;
cerr<<"param.taperBorder = "<<param.taperBorder<<endl;
// Taper mask
float *h_tapermask = tapermask(param);
// Data
seismicData h_seisData = allocHostSeisData(param, Fshots);
// Time stepping
float* h_wavelet = fillSrc(param, h_model, h_seisData);
// Set Output files
int dimensions[3] = {param.modelNy,param.modelNx,1};
float spacings[3] = {1,1,1};
int origins[3] = {0,0,0};
sf_file Fdata = createFile3D("rtm",dimensions,spacings,origins);
test_getParameters(param, h_seisData);
// ===================MODELING======================
rtm(param, h_model, h_wavelet, h_tapermask, h_seisData, Fdata);
// =================================================
//printf("Clean memory...");
delete[] h_model.velField;
delete[] h_model.extVelField;
delete[] h_model.firstLayerVelField;
delete[] h_seisData.seismogram;
delete[] h_tapermask;
sf_close();
return 0;
}