<?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 Unstable</title>
		<link>http://www.k-wave.org/forum/topic/simulation-unstable</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Tue, 12 May 2026 21:36:17 +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-unstable" rel="self" type="application/rss+xml" />

		<item>
			<title>ArteryLee on "Simulation Unstable"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-unstable#post-9128</link>
			<pubDate>Wed, 21 Aug 2024 16:47:26 +0000</pubDate>
			<dc:creator>ArteryLee</dc:creator>
			<guid isPermaLink="false">9128@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Bradley,&#60;/p&#62;
&#60;p&#62;Thanks very much for your reply. I have tried to remove the line &#60;code&#62;medium.alpha_mode = &#38;#39;no_dispersion&#38;#39;&#60;/code&#62;. However, it still produces all NaN matrix in the sensor in this case as long as I assign alpha coefficient to the collimator mask by &#60;code&#62;medium.alpha_coeff(collimator_mask) = alpha_collimator&#60;/code&#62;. I mean, once I comment out this line, it can produce non-NaN results with the C++/CUDA code.&#60;/p&#62;
&#60;p&#62;BTW, I just modified my code according to your advice by setting the power law exponent to 2. In this case, it can also produce non-NaN results with the C++/CUDA code. But I am not sure how to get the correct power law absorption coefficients based on my previous numbers now. Would you mind explaining more about this?&#60;/p&#62;
&#60;p&#62;Thank you!&#60;/p&#62;
&#60;p&#62;Best,&#60;br /&#62;
Artery
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bradley Treeby on "Simulation Unstable"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-unstable#post-9126</link>
			<pubDate>Sun, 18 Aug 2024 10:36:50 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">9126@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Artery, the reason is that the no dispersion input is not supported in the C++ code. Unfortunately the docs are not super clear on this. However, if you’re doing a CW simulation, you can also get no dispersion but setting the power law exponent to 2, and then adjusting the pre factor so you get the same level of absorption at your driving frequency.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ArteryLee on "Simulation Unstable"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-unstable#post-9123</link>
			<pubDate>Wed, 14 Aug 2024 19:39:54 +0000</pubDate>
			<dc:creator>ArteryLee</dc:creator>
			<guid isPermaLink="false">9123@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Bradley,&#60;/p&#62;
&#60;p&#62;I encountered a situation similar to the one Toni described above. In my simulation, I added a collimator into the medium. With &#60;code&#62;kspaceFirstOrder3DC&#60;/code&#62; or &#60;code&#62;kspaceFirstOrder3DG&#60;/code&#62;, I got all NaN in the sensor grid as long as I added the collimator. While with common &#60;code&#62;kspaceFirstOrder3D&#60;/code&#62;, whether casting data to &#60;code&#62;single&#60;/code&#62; or &#60;code&#62;gpuArray-single&#60;/code&#62;, the results were normal. Meanwhile, without adding the collimator, &#60;code&#62;kspaceFirstOrder3DC&#60;/code&#62; and &#60;code&#62;kspaceFirstOrder3DG&#60;/code&#62; work fine with pure water medium.&#60;/p&#62;
&#60;p&#62;I'm not sure how this would happen as I have used the function &#60;code&#62;checkStability&#60;/code&#62; to make sure my dt (3.3333e-08) is smaller than the dt_stability_limit (5.0456e-08).&#60;/p&#62;
&#60;p&#62;Thank you very much for taking a look into this!&#60;/p&#62;
&#60;p&#62;Best,&#60;br /&#62;
Artery&#60;/p&#62;
&#60;p&#62;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&#60;br /&#62;
% =========================================================================&#60;br /&#62;
% DEFINE LITERALS&#60;br /&#62;
% =========================================================================&#60;br /&#62;
% medium parameters&#60;br /&#62;
c0              = 1500;       % sound speed [m/s]&#60;br /&#62;
rho0            = 1000;       % density [kg/m^3]&#60;br /&#62;
alpha0          = 3.0227e-05; % water power law absorption coefficient [dB/(MHz^y cm)]&#60;/p&#62;
&#60;p&#62;% collimator parameters&#60;br /&#62;
c_collimator    = 2410;&#60;br /&#62;
rho_collimator  = 1160;&#60;br /&#62;
alpha_collimator= 9.54;&#60;/p&#62;
&#60;p&#62;% source parameters&#60;br /&#62;
source_f0       = 5e5;      % source frequency [Hz]&#60;br /&#62;
source_roc      = 59.3e-3;  % bowl radius of curvature [m]&#60;br /&#62;
source_diameter = 25.4e-3;  % bowl aperture diameter [m]&#60;br /&#62;
source_amp      = 1.4*2e4;  % source pressure [Pa]&#60;br /&#62;
focus_depth     = 38.1e-3;  % [m]&#60;/p&#62;
&#60;p&#62;% grid parameters&#60;br /&#62;
axial_size      = 70e-3;    % total grid size in the axial dimension [m]&#60;br /&#62;
lateral_size    = 70e-3;    % total grid size in the lateral dimension [m]&#60;/p&#62;
&#60;p&#62;% computational parameters&#60;br /&#62;
ppw             = 12;       % number of points per wavelength&#60;br /&#62;
t_end           = 200e-6;   % total compute time [s]&#60;br /&#62;
record_periods  = 1;        % number of periods to record&#60;br /&#62;
cfl             = 0.2;      % CFL number&#60;br /&#62;
source_x_offset = 20;       % grid points to offset the source&#60;br /&#62;
bli_tolerance   = 0.01;     % tolerance for truncation of the off-grid source points&#60;br /&#62;
upsampling_rate = 10;       % density of integration points relative to grid&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE KGRID&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% calculate the grid spacing based on the PPW and F0&#60;br /&#62;
dx = c0 / (ppw * source_f0);   % [m]&#60;/p&#62;
&#60;p&#62;% compute the size of the grid&#60;br /&#62;
Nx = roundEven(axial_size / dx) + source_x_offset;&#60;br /&#62;
Ny = roundEven(lateral_size / dx);&#60;br /&#62;
Nz = Ny;&#60;/p&#62;
&#60;p&#62;% create the computational grid&#60;br /&#62;
kgrid = kWaveGrid(Nx, dx, Ny, dx, Nz, dx);&#60;/p&#62;
&#60;p&#62;% compute points per temporal period&#60;br /&#62;
PPP = round(ppw / cfl);&#60;/p&#62;
&#60;p&#62;% compute corresponding time spacing&#60;br /&#62;
dt = 1 / (PPP * source_f0);&#60;/p&#62;
&#60;p&#62;% create the time array using an integer number of points per period&#60;br /&#62;
Nt = round(t_end / dt);&#60;br /&#62;
kgrid.setTime(Nt, dt);&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE KWAVEARRAY FOR TRANDUCER&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% set bowl position and orientation&#60;br /&#62;
bowl_pos = [kgrid.x_vec(1) + source_x_offset * kgrid.dx, 0, 0];&#60;br /&#62;
focus_pos = [bowl_pos(1) + focus_depth, 0, 0];&#60;/p&#62;
&#60;p&#62;% create empty kWaveArray&#60;br /&#62;
karray = kWaveArray('BLITolerance', bli_tolerance, 'UpsamplingRate', upsampling_rate, 'SinglePrecision', true);&#60;/p&#62;
&#60;p&#62;% add bowl shaped element&#60;br /&#62;
karray.addBowlElement(bowl_pos, source_roc, source_diameter, focus_pos);&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE SOURCE SIGNAL&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% create time varying source&#60;br /&#62;
source_sig = createCWSignals(kgrid.t_array, source_f0, source_amp, 0);&#60;/p&#62;
&#60;p&#62;% assign binary mask&#60;br /&#62;
source.p_mask = karray.getArrayBinaryMask(kgrid);&#60;/p&#62;
&#60;p&#62;% assign source signals&#60;br /&#62;
source.p = karray.getDistributedSourceSignal(kgrid, source_sig);&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE BINARY COLLIMATOR MASK&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;[OUTPUTgrid] = VOXELISE(166,166,152,'Collimator_14mm.STL','xyz');&#60;/p&#62;
&#60;p&#62;OUTPUTgrid = imrotate3(double(OUTPUTgrid), 90, [1 0 0]);&#60;br /&#62;
OUTPUTgrid = logical(OUTPUTgrid);&#60;/p&#62;
&#60;p&#62;collimator_mask = zeros(Nx, Ny, Nz, 'logical');&#60;/p&#62;
&#60;p&#62;collimator_mask(ceil(Nx/2)-ceil(size(OUTPUTgrid,1)/2)-59-14:ceil(Nx/2)+ceil(size(OUTPUTgrid,1)/2)-1-59-14, ...&#60;br /&#62;
    ceil(Ny/2)-ceil(size(OUTPUTgrid,2)/2)+1:ceil(Ny/2)+ceil(size(OUTPUTgrid,2)/2)-1+1, ...&#60;br /&#62;
    ceil(Nz/2)-ceil(size(OUTPUTgrid,3)/2)+2:ceil(Nz/2)+ceil(size(OUTPUTgrid,3)/2)-1+2) = OUTPUTgrid;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE MEDIUM&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% assign medium properties&#60;br /&#62;
medium.sound_speed = c0.*ones(Nx, Ny, Nz);&#60;br /&#62;
medium.sound_speed(collimator_mask) = c_collimator;&#60;br /&#62;
medium.density = rho0.*ones(Nx, Ny, Nz);&#60;br /&#62;
medium.density(collimator_mask) = rho_collimator;&#60;br /&#62;
medium.alpha_coeff = alpha0.*ones(Nx, Ny, Nz);&#60;br /&#62;
medium.alpha_coeff(collimator_mask) = alpha_collimator;&#60;/p&#62;
&#60;p&#62;medium.alpha_power = 1.001;&#60;br /&#62;
medium.alpha_mode = 'no_dispersion';&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% DEFINE SENSOR&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% set sensor mask to record central plane, not including the source point&#60;br /&#62;
sensor.mask = zeros(Nx, Ny, Nz);&#60;br /&#62;
sensor.mask(source_x_offset + 2:end, :, Nz/2 + 1) = 1; % mid-plane/central plane&#60;/p&#62;
&#60;p&#62;% record the pressure&#60;br /&#62;
sensor.record = {'p', 'p_rms'};&#60;/p&#62;
&#60;p&#62;% record only the final few periods when the field is in steady state&#60;br /&#62;
sensor.record_start_index = kgrid.Nt - record_periods * PPP + 1;&#60;/p&#62;
&#60;p&#62;% =========================================================================&#60;br /&#62;
% SIMULATION&#60;br /&#62;
% =========================================================================&#60;/p&#62;
&#60;p&#62;% set input options&#60;br /&#62;
input_args = {...&#60;br /&#62;
    'PMLSize', 'auto', ...&#60;br /&#62;
    'PMLInside', false, ...&#60;br /&#62;
    'PlotPML', false, ...&#60;br /&#62;
    'DisplayMask', 'off'};&#60;/p&#62;
&#60;p&#62;% run code&#60;br /&#62;
    sensor_data = kspaceFirstOrder3DG(kgrid, medium, source, sensor, input_args{:});&#60;br /&#62;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Bradley Treeby on "Simulation Unstable"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-unstable#post-6908</link>
			<pubDate>Tue, 25 Jun 2019 06:04:38 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">6908@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Toni,&#60;/p&#62;
&#60;p&#62;You can use the function &#60;code&#62;checkStability&#60;/code&#62; to get an estimate of the maximum stable time step, and then use this with the &#60;code&#62;setTime&#60;/code&#62; method of the &#60;code&#62;kWaveGrid&#60;/code&#62; class.&#60;/p&#62;
&#60;p&#62;Brad.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>guns2roses on "Simulation Unstable"</title>
			<link>http://www.k-wave.org/forum/topic/simulation-unstable#post-6886</link>
			<pubDate>Mon, 17 Jun 2019 14:30:25 +0000</pubDate>
			<dc:creator>guns2roses</dc:creator>
			<guid isPermaLink="false">6886@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Brad,&#60;/p&#62;
&#60;p&#62;I recently ran a simulation using &#34;kspaceFirstOrder3DG&#34; with multiple media as shown below. However, the simulation seems unstable as the result of &#34;sensor_data&#34; is a matrix full of &#34;NaN (Not-a-Number)&#34; in Matlab. I understand the differences of the &#34;speed of sound&#34; and &#34;absorption&#34; among different media are quite large which may be the reason causing simulation instability. I wonder if there is a way to tweak the values of &#34;speed of sound&#34; or &#34;absorption&#34; so that the simulation becomes stable while still maintaining certain amount of accuracy. Thanks a million! &#60;/p&#62;
&#60;p&#62;Best wishes,&#60;/p&#62;
&#60;p&#62;Toni&#60;/p&#62;
&#60;p&#62;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&#60;/p&#62;
&#60;p&#62;np2db=0.2*log10(exp(1));&#60;/p&#62;
&#60;p&#62;ppts=zeros(5,5);   % Velocity, Density, Absorption Coefficient, Power Law Exponent, Non-linearity (m/s, kg/m3, Np/cm/MHz, y, B/A)&#60;/p&#62;
&#60;p&#62;ppts(1,:)=[1561 1081 3.917*np2db 1.2598 6.756];   % heart muscle&#60;br /&#62;
ppts(2,:)=[1482 994 0.025*np2db 1 4.96];   % water&#60;br /&#62;
ppts(3,:)=[1578 1050 2.3676*np2db 1.05 6.1125];   % blood&#60;br /&#62;
ppts(4,:)=[3515 1908 54.553*np2db 1 1];   % sternum&#60;br /&#62;
ppts(5,:)=[1500 1050 161.88*np2db 1 1];   % lung&#60;/p&#62;
&#60;p&#62;% Please note that the 4th column &#34;power law exponent&#34; of matrix &#34;ppts&#34; has been disabled.&#60;br /&#62;
% Instead the &#34;medium.alpha_power&#34; is set to 1.05 for all media as recommended in the k-Wave manual.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
