<?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: Calculation in a loop</title>
		<link>http://www.k-wave.org/forum/topic/calculation-in-a-loop</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Tue, 12 May 2026 22:28:46 +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/calculation-in-a-loop" rel="self" type="application/rss+xml" />

		<item>
			<title>lfura on "Calculation in a loop"</title>
			<link>http://www.k-wave.org/forum/topic/calculation-in-a-loop#post-9135</link>
			<pubDate>Thu, 29 Aug 2024 08:11:40 +0000</pubDate>
			<dc:creator>lfura</dc:creator>
			<guid isPermaLink="false">9135@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;I would like to simulate the oscillations of the microbubbles exposed to ultrasound. So I thought that I will simulate the distribution of acoustic pressure in k-wave in every step and then take this pressure and put it into Rayleigh-Plesset equation as the external acoustic pressure. The result would be a change in the radius of the microbubble, which could be treated as a wave source and introduced as a wave source in the next step of the k-wave simulation. In this way, I wanted to link the k-wave simulations to the Rayleigh-Plesset equation in a loop for the entire simulation space. Of course, there is still the problem of scattering by the microbubble, but I wanted to leave that out for now.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bencox on "Calculation in a loop"</title>
			<link>http://www.k-wave.org/forum/topic/calculation-in-a-loop#post-9131</link>
			<pubDate>Wed, 28 Aug 2024 18:15:34 +0000</pubDate>
			<dc:creator>bencox</dc:creator>
			<guid isPermaLink="false">9131@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi Ifura,&#60;/p&#62;
&#60;p&#62;No, it's not the same. What is it that you would like to simulate?&#60;/p&#62;
&#60;p&#62;Best wishes&#60;br /&#62;
Ben
&#60;/p&#62;</description>
		</item>
		<item>
			<title>lfura on "Calculation in a loop"</title>
			<link>http://www.k-wave.org/forum/topic/calculation-in-a-loop#post-9122</link>
			<pubDate>Tue, 06 Aug 2024 13:54:14 +0000</pubDate>
			<dc:creator>lfura</dc:creator>
			<guid isPermaLink="false">9122@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi, &#60;/p&#62;
&#60;p&#62;Is it possible in k-wave to calculate the sound pressure distribution after N time steps by running simulations in a loop after 1 time step? The loop runs kspaceFirstOrder where at each grid node the wave source is the value from the previous time step in the loop. It seems to me that this should work, but maybe I'm missing something and it's not working. I have attached my code below.&#60;/p&#62;
&#60;p&#62;Kind regards&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;pml_size = 20;              % [grid points]

% define the grid parameters
Nx = 512 - 2 * pml_size;    % [grid points]
Ny = 512 - 2 * pml_size;    % [grid points]
dx = 10e-6;               % [m]
dy = 10e-6;               % [m]

% create the computational grid
kgrid = kWaveGrid(Nx, dx, Ny, dy);
%%

% define the properties of the propagation medium
medium.sound_speed = 1480;  % [m/s]
medium.density     = 1000;  % [kg/m^3]
medium.alpha_coeff = 0.02;  % [dB/(MHz^y cm)]
medium.alpha_power = 1.1;

% define the source parameters
diameter = 4e-3;           % [m]
radius   = 3e-3;           % [m]
freq     = 1.05e6;             % [Hz]
amp      = 0.1e6;           % [Pa]

mask= logical(zeros(Nx,Ny));
mask(Nx/2,Ny/2) = 1;

source.p_mask = zeros(Nx,Ny);
source.p_mask(mask) = 1;

% calculate the time step using an integer number of points per period
ppw = medium.sound_speed / (freq * dx); % points per wavelength
cfl = 0.3;                              % cfl number
ppp = ceil(ppw / cfl);                  % points per period
T   = 1 / freq;                         % period [s]
dt  = T / ppp;                          % time step [s]

% calculate the number of time steps to reach steady state
t_end = sqrt( kgrid.x_size.^2 + kgrid.y_size.^2 ) / medium.sound_speed;
Nt = round(t_end / dt);

kgrid.setTime(Nt, dt);
% define the input signal
input_signal = createCWSignals(kgrid.t_array, freq, amp, 0);

% create the time array
kgrid.setTime(1, dt);

source.p = zeros(1,1);
source.p = input_signal(:,1);

% set the sensor mask to cover the entire grid
sensor.mask = ones(Nx, Ny);
sensor.record = {&#38;#39;p&#38;#39;};

% record one point
sensor.record_start_index = 1;

% set the input arguements
input_args = {&#38;#39;PMLInside&#38;#39;, false, &#38;#39;PlotPML&#38;#39;, false, &#38;#39;DisplayMask&#38;#39;, ...
    &#38;#39;off&#38;#39;, &#38;#39;PlotScale&#38;#39;, [-1, 1] * amp, ...
    &#38;#39;PlotSim&#38;#39;, false, &#38;#39;DataCast&#38;#39;, &#38;#39;gpuArray-single&#38;#39;};

% run the acoustic simulation
sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});

% % reshape the data
p = reshape(sensor_data.p, Nx, Ny,1);
%%
source.p_mask = ones(Nx,Ny);
f = waitbar(0);
for i=2:length(input_signal)

    source.p = p(:,:,i-1);
    source.p = source.p(:);
    source.p(mask(:)) = input_signal(:,i);

    % run the acoustic simulation
    sensor_data = kspaceFirstOrder2D(kgrid, medium, source, sensor, input_args{:});

    % % reshape the data
    p (:,:,i) = reshape(sensor_data.p, Nx, Ny,1);
    waitbar(i/(length(input_signal)),f)
end
close(f)&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
