<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>k-Wave User Forum &#187; Topic: Simulation of knife-edge diffraction?</title>
		<link>http://www.k-wave.org/forum/topic/simulation-of-knife-edge-diffraction</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Wed, 13 May 2026 17:20:48 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.k-wave.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.k-wave.org/forum/rss/topic/simulation-of-knife-edge-diffraction" rel="self" type="application/rss+xml" />

		<item>
			<title>Bradley Treeby on "Simulation of knife-edge diffraction?"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-of-knife-edge-diffraction#post-6496</link>
			<pubDate>Sun, 24 Jun 2018 19:04:58 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">6496@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;HI jkusumaFB,&#60;/p&#62;
&#60;p&#62;Thanks for the interesting puzzle - unfortunately, it's got us stumped! It's a stability issue related to the heterogeneous density, but we have no idea why it depends on the spatial distribution. If you have a single grid point on the left or top, it is also unstable. Fortunately, it can be solved by reducing the size of the time step, or only having a heterogeneous sound speed - the formula for stability used in the example doesn't account for the heterogeneous density.&#60;/p&#62;
&#60;p&#62;We'll keep digging and let you know if we figure it out.&#60;/p&#62;
&#60;p&#62;Brad.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jkusumaFB on "Simulation of knife-edge diffraction?"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-of-knife-edge-diffraction#post-6468</link>
			<pubDate>Thu, 17 May 2018 16:43:06 +0000</pubDate>
			<dc:creator>jkusumaFB</dc:creator>
			<guid isPermaLink="false">6468@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;I think I've figured this out -- sort of -- enough to do a small numerical experiment anyway. &#60;/p&#62;
&#60;p&#62;If I place the single barrier on the right, it works. &#60;/p&#62;
&#60;p&#62;If I place the single barrier on the left, it crashes, unless I place a tiny barrier on the right, with a wide open slit. &#60;/p&#62;
&#60;p&#62;It seems to me that this has to do with the solver, which is unfortunately beyond my ability to figure out at this point. :-(
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jkusumaFB on "Simulation of knife-edge diffraction?"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-of-knife-edge-diffraction#post-6463</link>
			<pubDate>Tue, 15 May 2018 17:19:25 +0000</pubDate>
			<dc:creator>jkusumaFB</dc:creator>
			<guid isPermaLink="false">6463@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi everybody, I'm new to k-wave and I am trying to learn by example -- in this case I'm interested in simulating a single-edge (knife-edge) diffraction simulation. &#60;/p&#62;
&#60;p&#62;I started with the built-in example &#34;example_tvsp_slit_diffraction.m&#34; that Bradley Treeby wrote, and simply removed one of the two sides of the barrier. When I do so, the simulation seems to become divergent. I tried removing the &#34;Datacast = single&#34; option and it still doesn't work. &#60;/p&#62;
&#60;p&#62;If I remove all the barriers, the simulation runs fine ... basically a homogeneous media. &#60;/p&#62;
&#60;p&#62;Can somebody help me understand why the one-sided simulation doesn't run correctly, please? Thanks in advance! &#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
% Diffraction Through A Slit Example Example&#60;br /&#62;
%&#60;br /&#62;
% This example illustrates the diffraction of a plane acoustic wave through&#60;br /&#62;
% a slit. It builds on the Monopole Point Source In A Homogeneous&#60;br /&#62;
% Propagation Medium and Simulating Transducer Field Patterns examples.&#60;br /&#62;
%&#60;br /&#62;
% author: Bradley Treeby&#60;br /&#62;
% date: 1st November 2010&#60;br /&#62;
% last update: 20th June 2017&#60;br /&#62;
%&#60;br /&#62;
% This function is part of the k-Wave Toolbox (&#60;a href=&#34;http://www.k-wave.org&#34; rel=&#34;nofollow&#34;&#62;http://www.k-wave.org&#60;/a&#62;)&#60;br /&#62;
% Copyright (C) 2010-2017 Bradley Treeby&#60;/p&#62;
&#60;p&#62;% This file is part of k-Wave. k-Wave is free software: you can&#60;br /&#62;
% redistribute it and/or modify it under the terms of the GNU Lesser&#60;br /&#62;
% General Public License as published by the Free Software Foundation,&#60;br /&#62;
% either version 3 of the License, or (at your option) any later version.&#60;br /&#62;
%&#60;br /&#62;
% k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY&#60;br /&#62;
% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS&#60;br /&#62;
% FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for&#60;br /&#62;
% more details.&#60;br /&#62;
%&#60;br /&#62;
% You should have received a copy of the GNU Lesser General Public License&#60;br /&#62;
% along with k-Wave. If not, see &#38;lt;http://www.gnu.org/licenses/&#38;gt;. &#60;/p&#62;
&#60;p&#62;clearvars;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% SIMULATION&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% create the computational grid and define the bulk medium properties&#60;br /&#62;
scale = 1;                          % change to 2 to produce higher resolution images&#60;br /&#62;
PML_size = 10;                      % size of the perfectly matched layer [grid points]&#60;br /&#62;
Nx = scale * 128 - 2 * PML_size;    % number of grid points in the x (row) direction&#60;br /&#62;
Ny = Nx;                            % number of grid points in the y (column) direction&#60;br /&#62;
dx = 50e-3 / Nx;                    % grid point spacing in the x direction [m]&#60;br /&#62;
dy = dx;                            % grid point spacing in the y direction [m]&#60;br /&#62;
c0 = 1500;                          % [m/s] speed of sound in water&#60;br /&#62;
rho0 = 1000;                        % [kg/m^3]&#60;br /&#62;
kgrid = kWaveGrid(Nx, dx, Ny, dy);&#60;/p&#62;
&#60;p&#62;% define the ratio between the barrier and background sound speed and&#60;br /&#62;
% density&#60;br /&#62;
%barrier_scale = 20;&#60;br /&#62;
barrier_scale = 20;  % lower contrast values = better diffraction contrast&#60;/p&#62;
&#60;p&#62;%% define the barrier and the source wavelength depending on the example&#60;br /&#62;
% create a mask of a barrier with a slit&#60;br /&#62;
slit_thickness = scale * 2;             % [grid points]&#60;br /&#62;
slit_width = scale * 50;                % [grid points]&#60;br /&#62;
slit_x_pos = Nx - Nx/4;                 % [grid points]&#60;br /&#62;
slit_y_end = Ny/2;                      % [grid points]&#60;br /&#62;
slit_offset = Ny/2 - slit_width/2 - 1;  % [grid points]&#60;br /&#62;
slit_mask = zeros(Nx, Ny);&#60;br /&#62;
%%% one sided -- crashes?&#60;br /&#62;
slit_mask(slit_x_pos:slit_x_pos + slit_thickness, 1:slit_y_end) = 1;  % left side only&#60;br /&#62;
%%% two slits -- works&#60;br /&#62;
% slit_mask(slit_x_pos:slit_x_pos + slit_thickness, 1:slit_offset) = 1;  % left side&#60;br /&#62;
% slit_mask(slit_x_pos:slit_x_pos + slit_thickness, end - 1:end) = 1;  % right side&#60;/p&#62;
&#60;p&#62;% define the source wavelength to be a quarter of the slit size&#60;br /&#62;
source_wavelength = 0.25 * slit_width * dx;     % [m]&#60;br /&#62;
source_freq = 500e3;                    % [Hz]&#60;br /&#62;
source_wavelength = c0/source_freq;     % [m]&#60;br /&#62;
% source_wavelength = 0.0058;&#60;/p&#62;
&#60;p&#62;% assign the slit to the properties of the propagation medium&#60;br /&#62;
medium.sound_speed = c0 * ones(Nx, Ny);&#60;br /&#62;
medium.density = rho0 * ones(Nx, Ny);&#60;br /&#62;
medium.sound_speed(slit_mask == 1) = barrier_scale * c0;&#60;br /&#62;
medium.density(slit_mask == 1) = barrier_scale * rho0;&#60;/p&#62;
&#60;p&#62;% assign the reference sound speed to the background medium&#60;br /&#62;
medium.sound_speed_ref = c0;&#60;/p&#62;
&#60;p&#62;%% prepare for simulation&#60;br /&#62;
% find the time step at the stability limit&#60;br /&#62;
c_ref = medium.sound_speed_ref;&#60;br /&#62;
c_max = barrier_scale * c0;&#60;br /&#62;
k_max = max(kgrid.k(:));&#60;br /&#62;
dt_limit = 2 / (c_ref * k_max) * asin(c_ref / c_max);&#60;/p&#62;
&#60;p&#62;% create the time array, with the time step just below the stability limit&#60;br /&#62;
dt = 0.95 * dt_limit;   % [s]&#60;br /&#62;
t_end = 40e-6;          % [s]&#60;br /&#62;
kgrid.setTime(round(t_end / dt) + 1, dt);&#60;/p&#62;
&#60;p&#62;% create a source mask of a single line&#60;br /&#62;
source.p_mask = zeros(Nx, Ny);&#60;br /&#62;
source.p_mask(end, :) = 1;&#60;/p&#62;
&#60;p&#62;% create and filter the time varying sinusoidal source&#60;br /&#62;
source_mag = 2;&#60;br /&#62;
source_freq = c0 / source_wavelength;&#60;br /&#62;
source.p = source_mag * sin(2 * pi * source_freq * kgrid.t_array);&#60;br /&#62;
source.p = filterTimeSeries(kgrid, medium, source.p);&#60;/p&#62;
&#60;p&#62;% define the field parameters to record&#60;br /&#62;
sensor.mask = ones(Nx, Ny);&#60;br /&#62;
sensor.record = {'u_final', 'p_final'};&#60;/p&#62;
&#60;p&#62;%% run simulation and display results&#60;br /&#62;
% set the input options&#60;br /&#62;
% input_args = {'PMLInside', false, 'PMLSize', PML_size, 'PlotPML', false, ...&#60;br /&#62;
%     'DisplayMask', slit_mask, 'DataCast', 'single'};&#60;br /&#62;
input_args = {'PMLInside', false, 'PMLSize', PML_size, 'PlotPML', false, ...&#60;br /&#62;
    'DisplayMask', slit_mask};&#60;/p&#62;
&#60;p&#62;% run the simulation&#60;br /&#62;
sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% VISUALISATION&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% plot the final wave-field&#60;br /&#62;
figure;&#60;br /&#62;
mx = max(abs(sensor_data.p_final(:)));&#60;br /&#62;
sensor_data.p_final(slit_mask == 1) = mx;&#60;br /&#62;
imagesc(kgrid.y_vec * 1e3, kgrid.x_vec * 1e3, sensor_data.p_final, [-mx, mx]);&#60;br /&#62;
colormap(getColorMap);&#60;br /&#62;
ylabel('x-position [mm]');&#60;br /&#62;
xlabel('y-position [mm]');&#60;br /&#62;
axis image;&#60;br /&#62;
title('p');&#60;/p&#62;
&#60;p&#62;% plot the final wave-field&#60;br /&#62;
figure;&#60;br /&#62;
mx = max(abs(sensor_data.ux_final(:)));&#60;br /&#62;
sensor_data.ux_final(slit_mask == 1) = mx;&#60;br /&#62;
imagesc(kgrid.y_vec * 1e3, kgrid.x_vec * 1e3, sensor_data.ux_final, [-mx, mx]);&#60;br /&#62;
colormap(getColorMap);&#60;br /&#62;
ylabel('x-position [mm]');&#60;br /&#62;
xlabel('y-position [mm]');&#60;br /&#62;
axis image;&#60;br /&#62;
title('ux');&#60;/p&#62;
&#60;p&#62;% plot the final wave-field&#60;br /&#62;
figure;&#60;br /&#62;
mx = max(abs(sensor_data.uy_final(:)));&#60;br /&#62;
sensor_data.uy_final(slit_mask == 1) = mx;&#60;br /&#62;
imagesc(kgrid.y_vec * 1e3, kgrid.x_vec * 1e3, sensor_data.uy_final, [-mx, mx]);&#60;br /&#62;
colormap(getColorMap);&#60;br /&#62;
ylabel('x-position [mm]');&#60;br /&#62;
xlabel('y-position [mm]');&#60;br /&#62;
axis image;&#60;br /&#62;
title('uy');
&#60;/p&#62;&#60;/blockquote&#62;</description>
		</item>

	</channel>
</rss>
