Deco
view release on metacpan or search on metacpan
lib/Deco/Tissue.pm view on Meta::CPAN
$self->{previousdepth} = 0;
# some timestamps in seconds
$self->{time}->{current} = 0;
$self->{time}->{previous} = 0;
$self->{time}->{lastdepthchange} = 0;
# oxygen exposure tracking through OTU's
$self->{otu} = 0;
# haldane formula for current parameters, returns a ref to a sub
$self->{haldane} = $self->_haldanePressure();
return $self;
}
# get the tissue nr
sub nr {
my $self = shift;
croak "Tissue numbers not set yet" unless ($self->{nr});
return $self->{nr};
lib/Deco/Tissue.pm view on Meta::CPAN
croak "Depth can not be negative" unless($depth >= 0);
if ($depth != $self->{depth} ) {
$self->{previousdepth} = $self->{depth};
$self->{depth} = $depth;
# remember this depthchange on the time scale
$self->{time}->{lastdepthchange} = $self->{time}->{current};
#print "Time of last depth change is: " . $self->{time}->{lastdepthchange} ."\n";
# when depth changes we need to recalculate the Haldane formula
$self->{haldane} = $self->_haldanePressure();
}
return $self->{depth};
}
# set new timestamp in seconds
sub time {
my $self = shift;
lib/Deco/Tissue.pm view on Meta::CPAN
# convert meters to bar
# this does NOT include the starting pressure
# so 0 meters = 0 bar water pressure
sub _depth2pressure {
my $self = shift;
my $depth = shift;
my $press = $depth * $self->{waterfactor} / 10;
return $press;
}
# use haldanian formula to solve the current pressure in tissue
# as long as the depth remains constant, this formula is still valid
sub _haldanePressure {
my $self = shift;
my $gas = lc(shift) || 'n2';
croak "Asking for unsupported gas $gas" unless exists $GASES{$gas};
# we need the current tissure pressure, at t=0 for the depth
my $tissue_press0 = $self->{$gas}->{pressure};
#print "recalculating haldane formula. tissue pressure at t0 = $tissue_press0\n";
# and the alveolar pressure
my $alveolar = $self->_alveolarPressure( depth => $self->{depth} );
# the time in minutes we have been at this depth, note that internal times are in seconds!
return sub {
my $t = shift;
$alveolar + ($tissue_press0 - $alveolar ) * exp( -1 * $self->k() * $t );
}
( run in 0.545 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )