Este documento describe métodos para imponer condiciones de frontera absorbentes al resolver numéricamente la ecuación de onda acústica en dominios espaciales finitos, con el fin de evitar reflexiones no deseadas cerca de los bordes. También presenta técnicas para paralelizar el código utilizando OpenMP y describe el uso de SConstruct para controlar el flujo de procesamiento de datos.
Marzal, Manuel M. - Historia de la antropología. Vol. I. Antropología Indigen...
Parte03
1. Taller Madagascar
Ecuaci´on de Onda Ac´ustica 2D/3D
Herling Gonzalez Alvarez
Instituto Colombiano del Petroleo, Universidad Industrial de Santander
2 de Octubre de 2015
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 1 / 32
2. Condici´on de frontera absorbente
Hasta el momento hemos solucionado num´ericamente la ecuaci´on de onda
en el dominio espacial finito. Sin embargo, la soluci´on en la vecindad de la
frontera genera reflexiones no deseadas que no est´an asociadas con el
modelo geof´ısico de inter´es. Se hace necesario restringir el problema a un
subdominio acotado e imponer condiciones de frontera artificiales de
manera absorbente.
0.86
0.88
0.9
0.92
0.94
0.96
0.98
1
0 5 10 15 20 25 30
Frontera Absorbente
exp(-(alpha[cel-x])
2
)
Id(p,i,j)=Id(p,i,j) exp[-(alpha(cell-i))^2]
Id(p,i,j)=Id(p,i,j) exp[-(alpha(Nz-Cell-j))^2]
for(i=0; i<cells; i++)
for(j=0; j<Nz; j++)
for(j=Nz-cells; j<Nz; j++)
for(i=0; i<Nx; i++)
cells
Nz-cells
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 2 / 32
3. Condici´on de Frontera Absorbente 2D
A continuaci´on se presenta una adaptaci´on del articulo cl´asico (Cerjan,
Kosloft, Kosloff, and Resheq 1985) para evitar estos efectos de frontera,
caso 2D.
#define Id(A,i,j) (A)[ (i)*nz + (j) ]
...
int cells = 20,i,j; /* cells atenuation */
float alpha = 0.015; /* absorbing factor */
float taper;
..
/** left side **/
for(i=0;i<cells;i++){
for(j=0;j<nz;j++){
taper = exp(-( alpha *(cells -i))*( alpha *(cells -i)));
Id(p2 ,i,j) *= taper;
}
}
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 3 / 32
4. Condici´on de Frontera Absorbente 3D
Para el caso 3D, las condiciones de frontera absorbente ser´ıan:
#define Id(A,i,j,k) (A)[ ((i)*ny + (j))*nz + (k) ]
...
int cells = 20,i,j,k; /*cells atenuation*/
float alpha = 0.015; /*absorbing factor*/
float taper;
...
//rear side
for(i=0;i<cells;i++){
for(j=0;j<ny;j++){
for(k=0;k<nz;k++){
taper = exp(-(a*(cells-i))*(a*(cells-i)));
Id(p2,i,j,k) *= taper;
}
}
}
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 4 / 32
5. OpenMP (Multi-procesamiento)
El flujo multi-hebra (multithreading), es un paradigma soportado por
hardware para ejecutar m´ultiples hilos o hebras de manera eficiente y
paralela.
Ejemplo Multi-Hebra con OpenMP+C
#include<omp.h>
int main(int argc, char* argv[])
{
int i, a[3];
#pragma omp parallel for
for (i=0; i<3; i++){
a[i]=i*i;
}
return(0);
} Return
a[0]
a[2]
a[1]
Flujo secuencial
Tradicional
a[0] a[2]a[1]
Flujo Multi-Hebra
Return
Este tipo de paralelizaci´on distribuye ejecuciones de manera independientes
tantos n´ucleos en el CPU existan. 1
1
http: /www.ibm.com/developerworks/rational/library/parallelize-ccpp-code-zOS-
OpenMP/index.html
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 5 / 32
6. T´ecnica OpenMP para la Ecuaci´on de Onda
#pragma omp parallel for default(shared) private(i,j,k,G)
for (i=1; i<nx-1; i++){
for (j=1; j<ny-1; j++){
for (k=1; k<nz-1; k++){
G=Id(c,i,j,k)*dt/dh;
Id(p1,i,j,k) = (2-6*G*G)*Id(p2,i,j,k) + G*G*(
Id(p2,i+1,j,k) + Id(p2,i-1,j,k) +
Id(p2,i,j+1,k) + Id(p2,i,j-1,k) +
Id(p2,i,j,k+1) + Id(p2,i,j,k-1) )- Id(p1,i,j,k);
}
}
}
Para compilar ejecutamos: gcc -fopenmp acoustic3d.c -lm
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 6 / 32
7. T´ecnica OpenMP para la Ecuaci´on de Onda
Tambi´en podemos escribir nuestro archivo SConstruct para compilar con
las siguientes instrucciones:
import os
RSFROOT=os.environ['RSFROOT']
env = Environment(LIBS=['m','rsf'],
CFLAGS=['-Wall','-g','-fopenmp'],
LIBPATH=['/usr/lib',RSFROOT+'/lib'],
CPPPATH=['/usr/include', RSFROOT+'/include'])
env.Append(LINKFLAGS=['-fopenmp'])
env.Program(target='Acous2d', source='acous2d.c' )
Y ejecutamos: scons -c; scons
www.scons.org/doc/production/HTML/scons-man.htm
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 7 / 32
8. Fundamentalmente, SConstruct como flujo de procesamiento de datos
est´a compuesto por cuatro instrucciones:
Flow: relaciona el flujo de entrada y salida de datos.
Flow(output file,input file,command)
Los archivos de entrada y salida no necesitan incluir la extensi´on“.rsf”
SCons autom´aticamente agrega el sufijo.
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 8 / 32
9. Para visualizar los datos RSF tenemos las siguientes instrucciones Plot y
Result.
Plot: Visualiza mientras ejecuta el script.
Plot(input file, command)
Result: Generar un archivo VPLOT en el subdirectorio llamado Fig
de manera local mientras se ejecuta.
Result(output vpl file, input file, command).
Los siguientes son los comandos para graf´ıcar: sfgraph, sfgraph3, sfgrey,
sfgrey3, sfgrey4, sfcontour .
VPLOT, es un entorno gr´afico meta-lenguaje con distintos ambientes de
salida (PNG,JPG,EPS,PDF,SVG,GIF,etc).
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 9 / 32
10. Fetch: Permite la conexi´on con el servidor de datos p´ublicos. Ubicado
en la siguiente direcci´on: http://www.ahay.org/data/
from rsf.proj import *
# Download the input data file
Fetch('lena.img','imgs' )
# Create RSF header
Flow('lena.hdr','lena.img','''echo n1=512 n2=513 in=$SOURCE
data_format=native_uchar''', stdin=0)
# Convert to float binary data
Flow('lena','lena.hdr','''sfdd type=float ''')
# Display0
Result('lena',''' sfgrey title="Lena Soderberg" transp=n
color=b bias=128 clip=100 screenratio=1 ''')
End()
Historia sobre la imagen:
http://es.wikipedia.org/wiki/Lenna
http://www.lenna.org
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 10 / 32
11. Un ejemplo de procesamiento es agregado en el siguiente fragmento:
def grey(title,allpos=1):
return ''' grey transp=n allpos= %d title=" %s"
screenratio=1 wantaxis=n ''' % (allpos,title)
Flow('slena','lena', ''' transp | put d1=0.004 d2=0.01 o2=0 o1=0 |
fft1 | fft3 | dipfilter v1=-1.5 v2=-1
v3=1 v4=1.5 taper=2 pass=0 | fft3 inv=y |
fft1 inv=y | bandpass flo=15 fhi=45 | transp
''')
Result('slena',grey('Seismic Lena',0))
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 11 / 32
12. Resumen Flujo de control SConstruct
Fecth(data file,dir[,ftp server info])
Descarga <data file> desde un directorio <dir> de un servidor ftp <ftp server info>
Flow(target[s],source[s],command[s][,stdin][,stdout])
Instrucci´on para generar <target[s]> desde <source[s]> usando comando[s]
Plot(intermediate plot[,source],plot command) ´o
Plot(intermediate plot,intermediate plots,plot command)
Instrucci´on para generar <intermediate plot> de manera local
Result(plot[,source],plot command) ´o
Result(plot,intermediate plots,combination)
Instrucci´on para generar un archivo <plot> en el directorio Fig
End()
Finalizaci´on de instrucciones
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 12 / 32
13. Propagaci´on para un modelo cl´asico
El modelo geof´ısico de Marmousi, fue creado inicialmente por el Instituto
Franc´es del Petr´oleo (IFP), y es usado para aspectos pr´acticos en
procesamiento de datos s´ısmicos como migraci´on e inversi´on. Los datos
utilizados como velocidad y densidad se basan en una segunda versi´on del
modelo conocido como Marmousi2 (Martin, Larsen, and Marfurt 2006).
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 13 / 32
14. Descarga del modelo de velocidad de onda P Marmousi2
from rsf.proj import *
segy=['vp_marmousi-ii.segy']
Fetch(segy,"marm2")
# convierte de formato SEGY a RSF, y se submuestrea
# los datos (sfwindow), para disminuir su tamagno.
Flow ('Vp tfile_vp',segy,
'''segyread tape=${SOURCES[0]} tfile=${TARGETS[1]} | scale rscale=1000
| put d1=1.25 d2=1.25 o1=0 o2=0 label1=Depth label2=Coordinates
unit 1=m unit2=m | window j1=8 j2=8
''' )
Result('Vp','''grey color=j mean=y scalebar=y screenratio=0.25
title="P-velocity model [m/s]" barreverse=y ''')
End()
El directorio para descargase se encuentra en la siguiente direcci´on
http://www.reproducibility.org/data/marm2/
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 14 / 32
15. Directorio y archivos para “flujo 3”
Ejecute dentro de flujo 3/
sftour scons -c && scons -c
sftour scons && scons && scons view
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 15 / 32
18. Taller: Adicione otros par´ametros en acous2d mp.c que permitan definir
el numero de celdas y factor de absorci´on en las condiciones de frontera
(left, right, botton).
Incluya una funci´on ABC (Absorbing Boundary Condiction) para las
otras fronteras:
void abc(int Nx,int Nz,int cells,float a,float *field) {
int i,j;
float taper;
#pragma omp parallel for default(shared) private(i,j,taper)
for(i=0;i<cells;i++){
for(j=0;j<Nz;j++){
taper = exp(-(a*(cells-i))*(a*(cells-i))); //left side
Id(field,i,j) *= taper;
}
}
...
}
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 18 / 32
19. Campo de velocidad 3D “Overthrust SEG/EAGE”
http://geodus1.ta.tudelft.nl/seage3dm/
http://www.ahay.org/RSF/book/tccs/psp/overthrust.html
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 19 / 32
20. Campo de velocidad 3D “Overthrust SEG/EAGE”
from rsf.proj import *
Flow('overthrust',['overthrust.vites.h','overthrust.vites'],
'''
(cat ${SOURCES[0]} ; echo data_format=xdr_float) |
dd form=native | put label1=X label2=Y label3=Z
unit1=m unit2=m unit3=m label=Velocity
unit=m/s d1=25 d2=25 d3=25
''',stdin=0)
# submuestrea volumen de datos y transpone los ejes X-Z
Flow('overthrust_sample','overthrust',
'''window j1=2 j2=2 j3=2 | transp plane=31 ''')
Result('overthrust_sample',
'''
byte gainpanel=all mean=y | transp plane=23 |
grey3 flat=n frame1=5 frame2=50 frame3=50
title="SEG/EAGE Overthrust Model"
color=j point1=0.6 point2=0.6
screenratio=0.31
''')
End()
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 20 / 32
21. Haciendo un diagnostico en los datos (sfin, sfattr)
sfin overthrust.rsf
overthrust.rsf:
in="/home/usuario/Data/Overthrust/overthrust.rsf@"
esize=4 type=float form=native label="Velocity" unit="m/s"
n1=801 d1=25 o1=0 label1="X" unit1="m"
n2=801 d2=25 o2=0 label2="Y" unit2="m"
n3=187 d3=25 o3=0 label3="Z" unit3="m"
119979387 elements 479917548 bytes
sfin overthrust sample.rsf
overthrust_sample.rsf:
in="/home/usuario/Data/Overthrust/overthrust_sample.rsf@"
esize=4 type=float form=native label="Velocity" unit="m/s"
n1=94 d1=50 o1=0 label1="Z" unit1="m"
n2=401 d2=50 o2=0 label2="Y" unit2="m"
n3=401 d3=50 o3=0 label3="X" unit3="m"
15115294 elements 60461176 bytes
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 21 / 32
22. Haciendo un diagnostico en los datos (Fortran & C)
do j=1,ny
do i=1,nx
A(i,j) = B(i,j)
end do
end do
for(i=0;i<nx;i++){
for(j=0;j<ny;j++){
Id(A,i,j) = B[i*ny+j];
}
}
do k=1,nz
do j=1,ny
do i=1,nx
A(i,j,k) = B(i,j,k)
end do
end do
end do
for(i=0;i<nx;i++){
for(j=0;j<ny;j++){
for(k=0;k<nz;k++){
Id(A,i,j,k) = B[(i*ny+j)*nz+k];
}
}
}
..Que eje X,Y,Z no ha cambiado de orden en Fortran y C?
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 22 / 32
23. sfattr < overthrust.rsf
*******************************************
rms = 4607.19
mean = 4479.92
2-norm = 5.04649e+07
variance = 1.15655e+06
std dev = 1075.43
max = 6000 at 442 413 139
min = 2178.83 at 486 764 1
nonzero samples = 119979387
total samples = 119979387
sfattr < overthrust sample.rsf
*******************************************
rms = 4607.75
mean = 4479.75
2-norm = 1.79142e+07
variance = 1.16323e+06
std dev = 1078.53
max = 6000 at 73 1 1
min = 2179.07 at 1 383 243
nonzero samples = 15115294
total samples = 15115294
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 23 / 32
24. Sacando una tajada a los datos (sfwindow)
En la consola:
sfwindow < overthrust sample.rsf f3=15 n3=1 | sfgrey
color=j scalebar=y mean=y | sfpen
o dentro SConstruct:
Result ('tajadaZ','overthrust_sample','''window f3=15 n3=1 | grey color=j
scalebar=y mean=y''')
¿Que sucede cuando cambiamos los
par´ametros de “sfwindow”, n3=1
por n3=10 ?
¿C´omo est´an distribuidos los datos,
en t´erminos de n1, n2, n3, como
RSF?
¿[(i ∗ n2 + j) ∗ n1 + k]?
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 24 / 32
25. http://www.ahay.org/wiki/Tutorial
sfwindow is used to select subsets of the data contained in an RSF file for
computation elsewhere. Typically, you specify the data subset you want to
keep using, the n, j, and f parameters which specify the number of indices
in the arrays to keep, the jump in indices, and the first index to keep from
the file in the respective dimension.
For example if we want to keep the 15th-30th time samples from the first
axis in file.rsf, we might use the following command:
sfwindow < file.rsf f1=15 n1=15 j1=1 > file-win.rsf
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 25 / 32
26. Sacando una tajada a los datos (sfwindow)
sftransp < overthrust sample.rsf plane=23 | sfwindow f3=50
n3=1 | sfgrey color=j scalebar=y mean=y screenratio=0.23 |
sfpen
Flow('tajadaY','overthrust_sample','''transp plane=23 | window f3=50 n3=1''')
Result('tajadaY','''grey color=j scalebar=y title="Seismic Section XZ"
mean=y screenratio=0.23''')
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 26 / 32
27. Directorio y archivos para “flujo 4”
Terminar de escribir el c´odigo para modelar la propagaci´on de onda
ac´ustica 3D, con diferencias finitas de 2do orden en tiempo y 4to orden el
espacio. Tomar como gu´ıa el c´odigo 2D del flujo 3.
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 27 / 32
28. Tener en cuenta...
//Read axes-rsf-data parameters
if (!sf_histint (Fw,"n1",&nt)) sf_error("No n1= in wav");
if (!sf_histfloat(Fw,"d1",&dt)) sf_error("No d1= in wav");
if (!sf_histint (Fv,"n1",&nz)) sf_error("No nz= in inp");
if (!sf_histint (Fv,"n2",&ny)) sf_error("No ny= in inp");
if (!sf_histint (Fv,"n3",&nx)) sf_error("No nx= in inp");
if (!sf_histfloat(Fv,"d1",&dz)) sf_error("No dz= in inp");
if (!sf_histfloat(Fv,"d2",&dy)) sf_error("No dy= in inp");
if (!sf_histfloat(Fv,"d3",&dx)) sf_error("No dx= in inp");
//Write axes-rsf-data parameters (4D)
sf_putint(Fo,"n4",nt/skip);
sf_putfloat(Fo,"d4",dt*skip);
sf_putfloat(Fo,"o4",0.0);
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 28 / 32
29. ...
timesteps=500 # timesteps*0.001=sec
Vmin = 2179.0 # vel. minima [Km/s]
Vmax = 6000.0 # vel. maxima [Km/s]
dh = 50. # tamagno de malla [Km]
dt = dh/(Vmax*2.) # paso de tiempo calculado
Nl = 6 # numero de puntos por logitud de onda
Fq = Vmin/(dh*Nl) # frequencia central [Hz]
t0=1./Fq # time offset
...
model='overthrust/overthrust_sample'
Flow('field',model,'''./acoustic/Acous3d wav=Ricker.rsf Sz=200
Sy=10000 Sx=10000 Skip=20''')
Result('movie3D','field',
'''byte clip=0.01 | grey4 color=x screenratio=0.5 frame1=5
frame2=200 frame3=200 flat=n title="dt= %g[s], dh= %g[m] at %g Hz"
screenratio=0.31 point1=0.6 point2=0.6
''' %(dt,dh,Fq))
...
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 29 / 32
30. Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 30 / 32
31. Cerjan, C., D. Kosloft, R. Kosloff, and M. Resheq (1985).
A nonreflecting boundary condition for discrete acoustic and elastic wave equations.
Geophysics 50, 705–708.
Martin, G., S. Larsen, and K. Marfurt (2006).
Marmousi2: An elastic upgrade for marmousi.
The Leading Edge 25, 156–166.
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 31 / 32
32. Atribuci´on-NoComercial 4.0 Internacional
Usted es libre de:
Compartir: copiar y redistribuir el material en cualquier medio o
formato.
Adaptar: re-mezclar, transformar y crear a partir del material.
Bajo las siguientes t´erminos:
Atribuci´on. Usted debe reconocer el cr´edito de una obra de
manera adecuada, proporcionar un enlace a la licencia, e indicar si
se han realizado cambios. El licenciamiento lo recibe por el uso que
hace.
No Comercial. Usted no puede hacer uso del material con
fines comerciales.
No hay restricciones adicionales. Aprenda m´as sobre el licenciamiento CC,
en el siguiente enlace.
http://creativecommons.org/licenses/by-nc/4.0/deed.es
Herling G. A. (Geof´ısica-ICP-Ecopetrol) Taller RSF 2/10/15 32 / 32