comparison Discovery/Src/buehlmann.c @ 249:cefee1448ea6

Merged in janlmulder/ostc4/bm-1 (pull request #16) Replace Relative GF by saturation
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Thu, 11 Apr 2019 10:26:22 +0000
parents 3949781096d4
children 822416168585
comparison
equal deleted inserted replaced
245:c282f9e88c66 249:cefee1448ea6
404 global_ceiling = ceiling; 404 global_ceiling = ceiling;
405 } 405 }
406 return global_ceiling; 406 return global_ceiling;
407 } 407 }
408 408
409 // hw 161121 for relative gradient 409 void buehlmann_super_saturation_calculator(SLifeData* pLifeData, SDecoinfo * pDecoInfo)
410 float tissue_tolerance_without_gf_correction(float *tissue_inertgas_saturation_output)
411 { 410 {
412 float tissue_inertgas_saturation; 411 float tissue_inertgas_saturation;
413 float inertgas_a; 412 float inertgas_a;
414 float inertgas_b; 413 float inertgas_b;
415 float ceiling; 414 float ceiling;
416 float global_ceiling; 415 float super_saturation;
416 float pres_respiration = pLifeData->pressure_ambient_bar;
417 int ci; 417 int ci;
418 418
419 global_ceiling = -1; 419 pDecoInfo->super_saturation = 0;
420 420
421 for (ci = 0; ci < 16; ci++) 421 for (ci = 0; ci < 16; ci++)
422 { 422 {
423 if(gTissue_helium_bar[ci] == 0) 423 if(gTissue_helium_bar[ci] == 0)
424 { 424 {
425 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci]; 425 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci];
426 //
427 inertgas_a = buehlmann_N2_a[ci]; 426 inertgas_a = buehlmann_N2_a[ci];
428 inertgas_b = buehlmann_N2_b[ci]; 427 inertgas_b = buehlmann_N2_b[ci];
429 } 428 }
430 else 429 else
431 { 430 {
432 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci]; 431 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci];
433 //
434 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; 432 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation;
435 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; 433 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation;
436 } 434 }
437 // 435
438 ceiling = inertgas_b * ( tissue_inertgas_saturation - inertgas_a ); 436 ceiling = pres_respiration / inertgas_b + inertgas_a;
439 if(ceiling > global_ceiling) 437 if(tissue_inertgas_saturation > pres_respiration)
440 { 438 {
441 global_ceiling = ceiling; 439 super_saturation =
442 if(tissue_inertgas_saturation_output) 440 (tissue_inertgas_saturation - pres_respiration) / (ceiling - pres_respiration);
443 { 441
444 *tissue_inertgas_saturation_output = tissue_inertgas_saturation; 442 if (super_saturation > pDecoInfo->super_saturation)
445 } 443 pDecoInfo->super_saturation = super_saturation;
446 } 444 }
447 } 445 }
448 return global_ceiling;
449 } 446 }
450 447
451 448
452 uint8_t buehlmann_tissue_test_tolerance(float depth_in_bar_absolute) 449 uint8_t buehlmann_tissue_test_tolerance(float depth_in_bar_absolute)
453 { 450 {
787 else 784 else
788 { 785 {
789 pDecoInfo->output_ceiling_meter = 999; 786 pDecoInfo->output_ceiling_meter = 999;
790 } 787 }
791 } 788 }
792
793
794 void buehlmann_relative_gradient_calculator(SLifeData* pLifeData, SDiveSettings * pDiveSettings, SDecoinfo * pDecoInfo)
795 {
796 float gf_low;
797 float gf_high;
798 float gf_delta;
799 int dv_gf_low_stop_meter;
800
801 float rgf; // relative gradient factor by hwOS p2_deco.c
802 float temp_tissue;
803 float limit;
804 float pres_respiration;
805 float gf;
806
807 gf_low = pDiveSettings->gf_low;
808 gf_high = pDiveSettings->gf_high;
809
810 dv_gf_low_stop_meter = (int)((pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero - pLifeData->pressure_surface_bar) * 10);
811
812 if(dv_gf_low_stop_meter < 1)
813 {
814 gf_delta = 0;
815 }
816 else
817 {
818 gf_delta = gf_high - gf_low;
819 gf_delta /= dv_gf_low_stop_meter; // gf_delta is delta for each meter now!!
820 }
821
822
823 limit = tissue_tolerance_without_gf_correction(&temp_tissue);
824 pres_respiration = pLifeData->pressure_ambient_bar;
825
826 if( temp_tissue <= pres_respiration )
827 {
828 gf = 0.0;
829 }
830 else
831 {
832 gf = (temp_tissue - pres_respiration)
833 / (temp_tissue - limit)
834 * 100.0f;
835 }
836
837 if(dv_gf_low_stop_meter < 1)
838 {
839 rgf = gf_high;
840 }
841 else
842 {
843 float temp1 = dv_gf_low_stop_meter;
844 float temp2 = pLifeData->depth_meter;
845
846 if (temp2 <= 0)
847 rgf = gf_high;
848 else if (temp2 >= temp1)
849 rgf = gf_low;
850 else
851 rgf = gf_low + (temp1 - temp2)*gf_delta;
852 }
853
854 rgf = gf / rgf;
855
856 // avoid discussions about values > 100 below next deco stop
857 if((rgf > 1.0f) && (pLifeData->depth_meter >= pDecoInfo->output_ceiling_meter))
858 rgf = 1.0f;
859
860 pDecoInfo->output_relative_gradient = rgf;
861 }