Doubt in deco.c code

Robert Helling helling at atdotde.de
Fri Mar 21 05:40:56 PDT 2014


On 21.03.2014, at 11:05, Gopichand Paturi <gopichandpaturi at gmail.com> wrote:

> Hi Robert (atdotde),
> 
> I am currently trying to familiarize with the decompression code i.e deco.c.
> I have a small doubt. I see this array
> 
> const double buehlmann_He_factor_expositon_one_second[] 
>  
> in the code. I didn't understand what these constants exactly do.
> 
> I see its usage in computation of factor for  specific gas
> 
> double he_factor(int period_in_seconds, int ci)
> {
> 	static struct factor_cache cache[16];
> 
> 	if (period_in_seconds == 1)
> 		return buehlmann_He_factor_expositon_one_second[ci];
> 
> 	if (period_in_seconds != cache[ci].last_period) {
> 		cache[ci].last_period = period_in_seconds;
> 		cache[ci].last_factor = 1 - pow(2.0, -period_in_seconds / (buehlmann_He_t_halflife[ci] * 60));
> 	}
> 
> 	return cache[ci].last_factor;
> }
> 
> 
> I get that it's some kind of constant involved, but I'm not exactly understanding the supporting theory.
> Kindly, help me with this.
> 
> Thanks & Regards,
> Gopichand.
> 
> 

Gopichand,

The difference between the partial pressure of a gas in a tissue and and the partial pressure in the ambient gas is supposed to decay exponentially in time, i.e. if the pressure in the tissue is t and in the ambient gas is a then after s seconds

t_new = a + (t_old - a) 2^(-s / h)

where h is the half-life time for the tissue and the gas in question. The point of the function that you quote above is that computing 2^(-s/h) is computationally expensive while it is independent of t and a. So, it will always be the same if we compute it for the same time interval s. What the above code does is caching these values. the value of s=1sec is precomputed in the table uehlmann_He_factor_expositon_one_second[] (similar for N2), we have this since one second is the interval that is needed in plotting. In cache[] we store this factor of the last s that we computed that was not a second (as we will also often compute with constant time interval). Only if there is a cache miss, the exponential factor is actually computed. 

Linus introduced this caching in order to significantly speed up the calculation of TTS (time to surface) in the profile info box.

Best
Robert




-- 
.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oO
Robert C. Helling     Elite Master Course Theoretical and Mathematical Physics
                      Scientific Coordinator
                      Ludwig Maximilians Universitaet Muenchen, Dept. Physik
                      Phone: +49 89 2180-4523  Theresienstr. 39, rm. B339
                      http://www.atdotde.de

Enhance your privacy, use cryptography! My PGP keys have fingerprints
A9D1 A01D 13A5 31FA 6515  BB44 0820 367C 36BC 0C1D    and
DCED 37B6 251C 7861 270D  5613 95C7 9D32 9A8D 9B8F




-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20140321/0a63cbaf/attachment.sig>


More information about the subsurface mailing list