Function | // Return zero if stored volume is zero
if (Scientific::equals([VFL:m3], 0)) return 0.0;
// Return unit height if stored volume equals unit volume
if (Scientific::equals([VFL:m3], [V:m3])) return [h:m] + [DC:m];
// Initialize
$d2 = [D:m] * [D:m];
$dc2 = [DC:m] * [DC:m];
// Check if fill height is within the lower spheroidal section
if ([VFL:m3] <= M_PI / 12 * $d2 * [DC:m]) {
// Solve by Newton's rule
$x = [DC:m] / 4;
while (TRUE) {
$y = M_PI / 3 * $d2 * $x * $x / $dc2 * (3 * [DC:m] / 2 - $x) - [VFL:m3];
if (Scientific::equals($y, 0)) return $x;
$x = M_PI * $d2 / [DC:m] * $x * (1 - $x / [DC:m]);
}
}
// Check if fill height is within the cylindrical section
if ([VFL:m3] <= M_PI / 4 * $d2 * ([DC:m] / 3 + [h:m])) {
// Return analytical solution
return 4 * [VFL:m3] / (M_PI * $d2) + [DC:m] / 6;
}
// Solve by Newton's rule
$x = [h:m] + 3 * [DC:m] / 4;
while (TRUE) {
$y = M_PI * $d2 * (pow($x - [h:m], 2) / (3 * $dc2) * (3 * [DC:m] / 2 - $x + [h:m]) + [h:m] / 4) - [VFL:m3];
if (Scientific::equals($y, 0)) return $x;
$x = $x - $y / (M_PI * $d2 / $dc2 * ($x - [h:m]) * ([DC:m] - $x + [h:m]));
}
|
---|