clearvars;
set(gcf, 'renderer', 'opengl');
if isempty(gcp('nocreate'))
parpool;
end
% Simulation domain and grid creation
Lx = 0.42; % length in meters
Ly = 0.36; % width in meters
nx = 420; % number of grid points in x
ny = 360; % number of grid points in y
x = linspace(0, Lx, nx);
y = linspace(0, Ly, ny);
[X, Y] = meshgrid(x, y);
% Wave parameters
g = 9.84; % acceleration due to gravity in m/s^2
wavelength = 0.03; % wavelength in meters
wave_speed = sqrt(g * wavelength / (2 * pi)); % deep water wave speed
% Time-stepping parameters
dt = 0.01; % time step in seconds
t_end = 10; % end time in seconds
t = 0:dt:t_end; % time vector
% Initialize wave field
u = zeros(ny, nx);
% Loading texture image
textureImage = imread('seatexture25.jpg');
% Initialize plot for animation
figure;
insta_surface = surf(X, Y, u, 'EdgeColor', 'none', 'FaceColor', 'texturemap', 'CData', textureImage);
axis([0 Lx 0 Ly -0.01 0.01]);
ax = gca;
ax.XColor = 'blue';
ax.YColor = 'blue';
ax.ZColor = 'blue';
title('Wind-induced water waves', 'Color', 'blue');
xlabel('Fetch (m)', 'Color', 'blue');
ylabel('Cross-fetch (m)', 'Color', 'blue');
zlabel('Elevation (m)', 'Color', 'blue');
lightangle(-45, 80);
lighting phong;
material shiny;
shading interp;
% Time-stepping loop
for ti = t
% Add new wavelets periodically
if mod(ti, 1) == 0 % Adjust the modulus value to control frequency of new wavelets
num_wavelets = 18; % Number of wavelets
amplitude = 0.001; % Amplitude of the wavelets
for i = 1:num_wavelets
% Random position for the center of the wavelet
x_center = rand() * Lx;
y_center = rand() * Ly;
% Random length for the wavelet in the y-direction, not exceeding 20 cm
wavelet_length_y = min(rand() * (Ly / 2), 0.18); % Up to half the tank width or 18 cm
% Create a wavelet with an elongated Gaussian profile
sigma_x = wavelength / 2; % Standard deviation in x
sigma_y = wavelet_length_y / 2; % Standard deviation in y
% Only create wavelets if they are not longer in x than in y
if sigma_x <= sigma_y
u = u + amplitude * exp(-((X - x_center).^2 / (2 * sigma_x^2) + (Y - y_center).^2 / (2 * sigma_y^2)));
end
end
end
% Move the wavelets
u = circshift(u, [0, round(wave_speed * dt * nx / Lx)]); % Shift the wavelets to the right
% Damping (to simulate wavelets disappearing)
u = u * exp(-dt/2); % Exponential decay of the wavelets
% Update the surface plot with the new data
set(insta_surface, 'ZData', u);
title(sprintf('Time: %0.2f seconds', ti), 'Color', 'blue');
drawnow;
% Pause briefly to control the speed of the animation
% pause(0.1);
end
% Close parallel pool (if opened earlier)
delete(gcp('nocreate'));