astrophysics.sleela
lib/user-interface/example/science/astrophysics.sleela · 75 line(s) · sleela
<<
example/science/astrophysics.sleela
A runnable SLeeLa ASTROPHYSICS program on the native `astrophysics` subject
library (import astrophysics;). It exercises the subject library's formula
family directly via qualified calls like astrophysics.redshift(...).
Astrophysics depends on Math, so the subject library requires `import math;`.
Facade (impl/subjects/astrophysics/astrophysics_native.cpp):
flux_from_luminosity(L, r) inverse-square flux, W/m^2
redshift(observed, rest) dimensionless z
observed_wavelength(rest, z) rest * (1 + z)
wien_peak(temperature) peak wavelength, m
kepler_period(a, mass) orbital period, s
escape_velocity(mass, radius) m/s
Inputs are grounded in churn/2/data/solar-system.json (Earth, 1 AU) and
standard public astronomical figures (the Sun's luminosity, radius, and
surface temperature; the hydrogen-alpha line at 656.3 nm).
Run:
SLEELA_SHEET=./SHEET.sheet \
SLEELA_SHA256_MANIFEST=./security/sha256-manifest.json \
./impl/build/sleela run example/science/astrophysics.sleela
>>
#sleela 2.5
material;
import math;
import astrophysics;
class ScienceAstrophysics {
void banner(String t) {
print("================================================================");
print(" " + t);
print("================================================================");
}
void main() {
banner("SLeeLa Science — Astrophysics (import astrophysics;)");
// The Sun (public reference values).
double lSun = 3.828 * math.pow(10.0, 26.0); // W, IAU nominal solar luminosity
double tSun = 5772.0; // K, effective temperature
double mSun = 1.989 * math.pow(10.0, 30.0); // kg
// Earth's orbit, from churn/2/data/solar-system.json (1 AU).
double au = 1.495978707 * math.pow(10.0, 11.0); // m
double mEarth = 5.97 * math.pow(10.0, 24.0); // kg
double rEarth = 6.3781 * math.pow(10.0, 6.0); // m
// H-alpha line.
double rest = 656.3 * math.pow(10.0, -9.0);
double observed = 660.0 * math.pow(10.0, -9.0);
double z = astrophysics.redshift(observed, rest);
print("[radiation]");
print(" flux at 1 AU from the Sun = " + astrophysics.flux_from_luminosity(lSun, au) + " W/m^2");
print(" (the solar constant, ~1361 W/m^2)");
print(" wien_peak(Sun, 5772 K) = " + astrophysics.wien_peak(tSun) + " m");
print(" (~502 nm, green-peaked visible light)");
print("[spectroscopy] H-alpha rest = 656.3 nm");
print(" redshift(observed 660 nm, rest) = " + z);
print(" observed_wavelength(rest, z) = " + astrophysics.observed_wavelength(rest, z) + " m");
print("[orbits & gravity]");
print(" kepler_period(1 AU, Sun) = " + astrophysics.kepler_period(au, mSun) + " s");
print(" (~3.156e7 s, i.e. one year)");
print(" escape_velocity(Earth) = " + astrophysics.escape_velocity(mEarth, rEarth) + " m/s");
banner("Done");
print("Astrophysics is a native subject library (import astrophysics;); it builds on math.");
}
}