food_chain/ecology/metabolism.js
2026-09-29 23:45:12 +09:00

23 lines
1.1 KiB
JavaScript

import {KELVIN_OFFSET, clamp} from './units.js?v=45';
const B0 = Object.freeze({ectotherm: 42, endotherm: 310}); // kJ d^-1 at 1 kg, simulator calibration
const ACTIVATION_EV = 0.65;
const BOLTZMANN_EV = 8.617333262e-5;
export function ectothermTemperatureMultiplier(temperatureC,referenceC=20){
const t=clamp(temperatureC+KELVIN_OFFSET,180,350),ref=referenceC+KELVIN_OFFSET;
return Math.exp((-ACTIVATION_EV/BOLTZMANN_EV)*(1/t-1/ref));
}
export function basalMetabolismKJPerDay(massKg,temperatureC,physiology='ectotherm'){
const mass=Math.max(1e-4,massKg),temp=physiology==='ectotherm'?ectothermTemperatureMultiplier(temperatureC):1;
return B0[physiology] * Math.pow(mass,.75) * temp;
}
export function starvationHazardPerDay(energyFraction){
if(energyFraction>=.18)return 0;
return 0.018 + 0.34*Math.pow((.18-Math.max(0,energyFraction))/.18,2);
}
export function thermalHazardPerDay(temperatureC,preferredC,toleranceC,physiology='ectotherm'){
const excess=Math.max(0,Math.abs(temperatureC-preferredC)-Math.max(1,toleranceC));
if(!excess)return 0;
return (physiology==='endotherm'?.00025:.0008)*excess*excess;
}