k-Wave User Forum » Topic: Large /tmp/ files
http://www.k-wave.org/forum/topic/large-tmp-files
Support for the k-Wave MATLAB toolboxen-USWed, 02 Dec 2020 02:41:11 +0000http://bbpress.org/?v=1.0.2<![CDATA[Search]]>q
http://www.k-wave.org/forum/search.php
Bradley Treeby on "Large /tmp/ files"
http://www.k-wave.org/forum/topic/large-tmp-files#post-7934
Tue, 24 Nov 2020 22:28:16 +0000Bradley Treeby7934@http://www.k-wave.org/forum/<p>Hi Bastien,</p>
<p>Thanks for your patience - it took me a while to find time to take a look. Here's my explanation.</p>
<p>To calculate the components of the average acoustic intensity, you want integrate <code>p*u</code> over an acoustic period. For a monochromatic source of frequency <code>w</code> the period is <code>T = 2*pi/w</code>. The pressure and the components of the particle velocity can be written as:</p>
<pre><code>p = a1*sin(w*t + p1)
u = a2*sin(w*t + p2)</code></pre>
<p>where <code>a1</code> and <code>a2</code> are the amplitudes, and <code>p1</code> and <code>p2</code> are the phases (similarly for all the vector components of <code>u</code>). Multiplying these together, integrating over time from 0 to T, and dividing by T to take the average then gives:</p>
<pre><code>I_avg = integral(p*u) / T
I_avg = integral(a1*sin(w*t + p1)*a2*sin(w*t + p2)) / T
I_avg = a1*a2*cos(p1 - p2)/2</code></pre>
<p>Now if the wave is fairly planar, the phase components <code>p1</code> and <code>p2</code> will be similar, and the <code>cos(p1 - p2)</code> term will be approximately one. This leaves:</p>
<p><code>I_avg ≈ a1*a2 / 2 = p_rms * u_rms</code></p>
<p>which is what you've calculated.</p>
<p>I coded this up for a simple focused field example in 2D, and the errors are on the order of 5% for this approach, compared to 10% for the plane wave approximation. I've also plotted the cosine terms, which for the <code>p*ux</code> components (which is the dominant one) is close to 1 in central part of the field. You can <a href="http://www.k-wave.org/downloads/forum_compare_intensity_calculations.m">download my code here</a>. Actually, it surprised me that it worked quite a bit better than the conventional plane wave approximation. </p>
<p>Let me know any queries or comments.</p>
<p>Brad
</p>bastg on "Large /tmp/ files"
http://www.k-wave.org/forum/topic/large-tmp-files#post-7850
Wed, 23 Sep 2020 20:12:30 +0000bastg7850@http://www.k-wave.org/forum/<p>A follow-up: The "plane wave method", which computes I_avg ~ <P>^2/(2*rho*c) gives an error of 0.0120 whereas the "separable method", which computes I_avg ~ <P>*<U>, has an error of 0.0014 (after correctly de-staggering ux, uy and uz as mentioned in previous post). This is for a 100kHz simulation, curved transducer with R=80mm and aperture=61mm in a uniform water bath.</p>
<p>This means that the separable method is ~8X more accurate than the plane wave method in this particular situation. In addition, the error of the separable method is mostly in the very near field, close to the focus the error is only ~2%.</p>
<p>I have also ran a comparison @ 500kHz, and I found an even more pronounced difference: The plane wave method error at the focus is ~48%. The error of the separable approximation at the focus is ~1%.</p>
<p>This is all anecdotal, and such a comparison should be done in a more rigorous way, but I thought it 1) could be interesting to other folks and 2) spark a discussion about why the separable method seem to work so well. I would be interested in hearing what the developers of k-wave think of this (and maybe see if they can reproduce this).</p>
<p>Thanks -- Bastien
</p>Bradley Treeby on "Large /tmp/ files"
http://www.k-wave.org/forum/topic/large-tmp-files#post-7841
Tue, 22 Sep 2020 12:38:34 +0000Bradley Treeby7841@http://www.k-wave.org/forum/<p>Hi bastg,</p>
<p>If your simulations are linear, the most memory efficient way would be using a plane wave approximation with the pressure amplitude extracted using <code>p_max_all</code>:</p>
<p><code>I = sensor_data.p_max_all.^2 ./ (2 * medium.density .* medium.sound_speed);</code></p>
<p>Provided the time step is small enough, taking the maximum pressure will be a reasonable approximation to the actual spectral amplitude.</p>
<p>If you want to record the particle velocity on the regular grid (instead of spatially staggered), you can record <code>u_non_staggered</code>. The particle velocity components are all staggered in different directions (i.e., ux is staggered in x, uy in y, etc), which is why the error goes up using your code.</p>
<p>One of Jiri's students has been working on a <a href="https://www.mdpi.com/2078-2489/9/7/155">memory efficient way</a> to extract the intensity directly using the C++ code, but I think it's a little way from the production version at this point.</p>
<p>Hope that helps,</p>
<p>Brad
</p>bastg on "Large /tmp/ files"
http://www.k-wave.org/forum/topic/large-tmp-files#post-7833
Fri, 18 Sep 2020 17:21:03 +0000bastg7833@http://www.k-wave.org/forum/<p>A follow up on this thread: I understand that the exact computation of the acoustic intensity requires dumping the entire P and U solutions (in time & space) on disk. For realistic simulations in 3D, this results in files well over 1TB (as mentioned many times on this forum), which is not feasible.</p>
<p>I wonder if there is an approximate solution to this problem. I just tried, on a small example, saving p_rms and u_rms, and then computed the averaged intensity as I_rms = abs(p_rms ) .* sqrt( ux_rms.^2 + uy_rms.^2 + uz_rms.^2 ). This is strictly speaking incorrect as this assumes that one can permute the temporal averaging with the multiplication, i.e. I am assuming that <P*U> = <P>*<U>. That being said, the error is not that bad. For F=100kHz, dt=10us and a focused transducer, I am finding a mean error of 2% and a peak error of 18%. Honestly, given that the acoustic properties are probably within ~30% of reality (I am simulating the human skull), this kind of error seems acceptable.</p>
<p>The other source of error is that P and U are staggered in space. I tried correcting this shift using the following code:<br />
>> p2 = fourierShift( p , 1/2 , 1 );<br />
>> p3 = fourierShift( p2 , 1/2 , 2 );<br />
>> p4 = fourierShift( p3 , 1/2 , 3 );<br />
and using p4 instead of p in the calculation of I_rms, but the error goes up instead of going down (it also goes up when using a -1/2 shift). I may not be correcting the spatial staggering properly...</p>
<p>My overall question is this: What is the best approximate estimate of the acoustic intensity that one can obtain using only the averaged variables (in time) that are outputted by K-WAVE?
</p>Jiri Jaros on "Large /tmp/ files"
http://www.k-wave.org/forum/topic/large-tmp-files#post-5689
Tue, 27 Sep 2016 10:40:37 +0000Jiri Jaros5689@http://www.k-wave.org/forum/<p>Hi wgrissom,</p>
<p>The problem is in the intensity 'I_avg'. The problem is that pressure and velocity are spatially and temporally staggered. So to calculate avarage intensity, we need to shift velocity and pressure in space (easy), but unfortunately in time as well. Since the GPU doesn't have enough memory to buffer more timesteps, we need to flush data on disk.</p>
<p>And this is the core of the problem. You sample the whole simulation domain, over 1362 timestep. A single timestep costs you 316 x 183 x 183 * 4B * 4 matrices ~ 160MB. Since you're sampling over 1362 timesteps, it sums up to 214 GB. </p>
<p>There are two questions:<br />
(1) Do you really have to sample intensity over the whole domain? If not, make the sensor mask smaller (just to cover the focus area).<br />
(2) Do you really have to sample intensity over the whole time period? For most of the time there's nothing in the domain (until the wave comes...). I'd recommend to sample 1 period of the signal after it reaches a steady state.</p>
<p>Jiri
</p>wgrissom on "Large /tmp/ files"
http://www.k-wave.org/forum/topic/large-tmp-files#post-5685
Thu, 22 Sep 2016 17:36:18 +0000wgrissom5685@http://www.k-wave.org/forum/<p>Hi, I am running a relatively small 3D simulation, but it generates enormous (> 100 GB) hd5 files in my /tmp/ folder, and I run out of disk space. I am using k-Wave with the multi-threaded CUDA executable on Ubuntu 16.04, calling it from MATLAB R2015a. I have about 140 GB free on the drive, and I have 96 GB of RAM and dual 6-core Xeons. </p>
<p>The output is below. My question is, should the files really be that big for this problem size? I am trying to record 'p_max', 'p_min', 'p_rms', 'I_avg' at each location in the simulated volume. Could that be my issue (i.e., I need to reduce my number of sensors, and perhaps repeat with multiple sensor positions)? Thank you for any help. </p>
<p>Running k-Wave simulation...<br />
start time: 21-Sep-2016 22:37:19<br />
reference sound speed: 1484m/s<br />
dt: 80.8625ns, t_end: 110.0539us, time steps: 1362<br />
input grid size: 316 by 183 by 183 grid points (126.4 by 73.2 by 73.2mm)<br />
maximum supported frequency: 1.855MHz by 1.8449MHz by 1.8449MHz<br />
kspaceFirstOrder_saveToDisk<br />
precomputation completed in 26.3772s<br />
saving input files to disk...<br />
completed in 1min 14.5148s<br />
┌───────────────────────────────────────────────────────────────┐<br />
│ kspaceFirstOrder3D-CUDA v1.1 │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Reading simulation configuration: Done │<br />
│ Selected GPU device id: 0 │<br />
│ GPU device name: Tesla K20c │<br />
│ Number of CPU threads: 24 │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Simulation details │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Domain dimensions: 316 x 183 x 183 │<br />
│ Simulation time steps: 1362 │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Initialization │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Memory allocation: Done │<br />
│ Data loading: Done │<br />
│ Elapsed time: 0.44s │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ FFT plans creation: Done │<br />
│ Pre-processing phase: Done │<br />
│ Elapsed time: 0.11s │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Computational resources │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Current host memory in use: 1647MB │<br />
│ Current device memory in use: 3649MB │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Simulation │<br />
├──────────┬────────────────┬──────────────┬────────────────────┤<br />
│ Progress │ Elapsed time │ Time to go │ Est. finish time │<br />
├──────────┼────────────────┼──────────────┼────────────────────┤<br />
│ 0% │ 1.665s │ 1131.926s │ 21/09/16 22:58:00 │<br />
│ 5% │ 104.034s │ 1920.166s │ 21/09/16 23:12:51 │<br />
│ 10% │ 197.664s │ 1753.197s │ 21/09/16 23:11:38 │<br />
│ 15% │ 314.691s │ 1765.936s │ 21/09/16 23:13:47 │<br />
│ 20% │ 426.971s │ 1695.417s │ 21/09/16 23:14:29 │<br />
│ 25% │ 540.264s │ 1611.315s │ 21/09/16 23:14:59 │<br />
│ 30% │ 655.427s │ 1521.870s │ 21/09/16 23:15:24 │<br />
│ 35% │ 777.675s │ 1438.210s │ 21/09/16 23:16:03 │<br />
│ 40% │ 908.100s │ 1357.161s │ 21/09/16 23:16:52 │<br />
│ 45% │ 1019.975s │ 1242.575s │ 21/09/16 23:16:49 │<br />
│ 50% │ 1135.512s │ 1128.862s │ 21/09/16 23:16:51 │<br />
└──────────┴────────────────┴──────────────┴────────────────────┘<br />
┌───────────────────────────────────────────────────────────────┐<br />
│ !!! K-Wave experienced a fatal error !!! │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Error: Could not write into "" dataset. │<br />
├───────────────────────────────────────────────────────────────┤<br />
│ Execution terminated │<br />
└───────────────────────────────────────────────────────────────┘<br />
/bin/bash: line 1: 15377 Segmentation fault (core dumped) ./kspaceFirstOrder3D-CUDA -i /tmp/kwave_input_data21-Sep-2016-22-37-19.h5 -o /tmp/kwave_output_data21-Sep-2016-22-37-19.h5 --p_max --p_min --p_rms --u_non_staggered_raw --p_raw<br />
export LD_LIBRARY_PATH=; cd /buffyexport/home/grissowa/Dropbox/code/zebrography/sim/kWave/k-wave-toolbox-version-1.1.1/k-Wave/binaries/; ./kspaceFirstOrder3D-CUDA -i /tmp/kwave_input_data21-Sep-2016-22-37-19.h5 -o /tmp/kwave_output_data21-Sep-2016-22-37-19.h5 --p_max --p_min --p_rms --u_non_staggered_raw --p_raw: Segmentation fault<br />
Error using h5readc<br />
The HDF5 library encountered an error and produced the following stack trace information:</p>
<p> H5F_super_read file signature not found<br />
H5F_open unable to read superblock<br />
H5Fopen unable to open file
</p>