0% found this document useful (0 votes)
17 views2 pages

SEM (For RTM)

The function SEM implements the Spectral Element Method to solve the 2D wave equation. It takes various parameters including grid dimensions, wave velocity, time steps, and initial conditions to compute the pressure field over time. The method involves constructing mass and stiffness matrices, applying boundary conditions, and performing time-stepping to evolve the wavefield.

Uploaded by

Farid Ghasemi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

SEM (For RTM)

The function SEM implements the Spectral Element Method to solve the 2D wave equation. It takes various parameters including grid dimensions, wave velocity, time steps, and initial conditions to compute the pressure field over time. The method involves constructing mass and stiffness matrices, applying boundary conditions, and performing time-stepping to evolve the wavefield.

Uploaded by

Farid Ghasemi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

function [u] = SEM(nx, ny, Lx, Ly, c, nt, dt, u0, u1)

% SEM solves the 2D wave equation using the Spectral Element Method
% Inputs:
% nx - number of points in the x-direction
% ny - number of points in the y-direction
% Lx - length of the domain in the x-direction
% Ly - length of the domain in the y-direction
% c - wave velocity in m/s
% nt - number of time steps
% dt - time step in seconds
% u0 - initial condition at t=0
% u1 - time derivative of the initial condition at t=0
% Outputs:
% u - pressure field at all time steps

% Compute the grid spacing and element size


dx = Lx/(nx-1);
dy = Ly/(ny-1);
h = dx*dy;

% Create the spectral element mesh


x = linspace(0, Lx, nx);
y = linspace(0, Ly, ny);
[X, Y] = meshgrid(x, y);
N = 3; % polynomial order
elm_size = N^2;

% Compute the quadrature rule for each element


[pts, wts] = gauss2D(N);

% Initialize the pressure field


u = zeros(nx, ny, nt);

% Apply the initial conditions


u(:,:,1) = u0;
u(:,:,2) = u0 + dt*u1;

% Compute the mass and stiffness matrices for each element


M = h/4 .* (wts * wts');
D = h/4 .* (wts * wts' .* (1./dx^2 + 1./dy^2));

% Compute the penalty factor for the boundary nodes


Kb = 1e9; % large value to enforce zero displacement
penalty = Kb/D(1,1);

% Loop over time steps


for n = 3:nt
% Compute the load vector for each element
f = zeros(nx, ny);
for i = 1:N:nx-N+1
for j = 1:N:ny-N+1
el = [i:i+N-1; j:j+N-1];
f(el(1,:), el(2,:)) = f(el(1,:), el(2,:)) +
(2/dt^2)*M*reshape(u(el(1,:), el(2,:), n-1), [], 1);
f(el(1,:), el(2,:)) = f(el(1,:), el(2,:)) - D*reshape(u(el(1,:),
el(2,:), n-2), [], 1);
end
end
% Apply the boundary conditions
f([1 end], :) = Kb*u([1 end], :, n-1);
f(:, [1 end]) = Kb*u(:, [1 end], n-1);

% Compute the global stiffness matrix


K = zeros(nx*ny);
for i = 1:N:nx-N+1
for j = 1:N:ny-N+1
el = [i:i+N-1; j:j+N-1];

% Compute the element stiffness matrix and load vector


Ke = D - penalty;
fe = f(el(1,:), el(2,:));
idx = sub2ind([nx, ny], el(1,:), el(2,:));
K(idx, idx) = K(idx, idx) + Ke;
% Add the element contributions to the global matrix and vector
%idx = nodes(i:i+N-1, j:j+N-1);
%K(idx, idx) = K(idx, idx) + Ke;
f(idx) = f(idx) + fe;
end
end

% Solve the system of equations for the wavefield


u = K \ f;

% Compute the image at the receivers


image = zeros(nrec, nt);
for i = 1:nrec
idx = nodes(recx(i), recy(i));
image(i,:) = u(idx, :);
end

% Reverse time migration


for n = 1:nt
% Compute the source term
f = zeros(nx, ny);
f(srcx, srcy) = -image(:, n)*dt^2/dx^2;

% Apply the SEM scheme


p = SEM(p, c, f, dx, dy, dt);

% Plot the image


if mod(n,100) == 0
imagesc(x, y, p);
shading interp;
xlabel('x (m)');
ylabel('y (m)');
title(['Reverse time migration at t = ' num2str(t(n)) ' s']);
colorbar;
drawnow;
end
end
end

You might also like