Docs › Guide
2 Transient radiation and vibration
2.1 Radiative cooling of one thermal mass
The physical state is a single temperature in kelvin. The surface radiates \(\epsilon\sigma A(T^4-T_\infty^4)\) watts into an enclosure. The thermal capacity \(C\) is the total heat capacity in J/K. With zero heating power and \(T_\infty=0\), separation of variables gives
The ambient value of zero kelvin is an idealized reference case. For a physical enclosure supply its absolute temperature and choose a reference appropriate to that model.
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
import onesimulation_plot_theme as theme
from onesim.cad.geometry import LumpedDomain
from onesim.meshing import LumpedMesh
from onesim.numerics import Numerics
from onesim.numerics.discretization import LumpedParameters
from onesim.numerics.time import ClassicalRungeKutta4
from onesim.physics.heat_transfer import (
RadiationCooling, ThermalGreyDiffuseRadiationBoundary,
)
from onesim.results.storage import MemoryOutputSink, Output
from onesim.simulation import Problem, Simulation
from onesim.simulation.initial_conditions import InitialValue
capacity, area, emissivity = 100.0, 0.1, 0.8 # J/K, m^2, 1
T0, ambient, end, dt = 600.0, 0.0, 20.0, 0.25 # K, K, s, s
def run_lumped(domain, model, initial, fields, *, end, dt, interval):
problem = Problem(
name=type(model).__name__, geometry=domain, physics=(model,),
initial_conditions=tuple(InitialValue(ref, v) for ref, v in initial),
)
sim = Simulation(
problem=problem, mesh=LumpedMesh(domain),
numerics=Numerics(
spatial=LumpedParameters(), time_integrator=ClassicalRungeKutta4(),
),
)
sim.validate().require_valid()
sink = MemoryOutputSink()
result = sim.run(
start_time=0.0, end_time=end, time_step=dt,
output=Output(fields=fields, interval=interval, sink=sink),
)
times = np.array([float(s.time) for s in sink.snapshots])
assert times.size > 1 and np.isclose(times[-1], end)
return result, sink, times
def scalar_series(sink, ref):
return np.array([
np.asarray(s.fields[ref.field_id].values).item() for s in sink.snapshots
])
domain = LumpedDomain()
model = RadiationCooling(
domain=domain.system, heat_capacity=capacity, radiating_area=area,
radiation=ThermalGreyDiffuseRadiationBoundary(
condition_id="cooling", emissivity=emissivity,
ambient_temperature=ambient,
),
)
result, sink, t = run_lumped(
domain, model, ((model.temperature, T0),),
(model.temperature, model.radiated_power), end=end, dt=dt, interval=0.5,
)
T = scalar_series(sink, model.temperature)
P = scalar_series(sink, model.radiated_power)
sigma = 5.670374419e-8 # W/(m^2 K^4)
exact = (T0**(-3) + 3 * emissivity * sigma * area * t / capacity)**(-1 / 3)
np.testing.assert_allclose(T, exact, rtol=0, atol=1e-6)
assert np.all(np.diff(T) < 0) and np.all(P >= 0)
out = Path("onesim-output")
out.mkdir(exist_ok=True)
np.savetxt(
out / "cooling.csv", np.column_stack((t, T, exact, P)), delimiter=",",
header="time_s,temperature_K,reference_K,power_W", comments="",
)
theme.use_theme()
fig, (ax, err) = plt.subplots(
2, 1, sharex=True, figsize=(7, 5), layout="constrained",
gridspec_kw={"height_ratios": [3, 1]},
)
ax.plot(t, exact, color=theme.INK, label="Closed form")
ax.plot(t, T, "o", ms=3, color=theme.COPPER, label="RK4")
ax.set(ylabel="Temperature [K]", title="Cooling into an ideal enclosure")
ax.legend(frameon=False)
err.plot(t, 1e6 * (T - exact), color=theme.TEAL)
err.set(xlabel="Time [s]", ylabel="Error [microK]")
for panel in (ax, err):
panel.grid(alpha=0.22)
fig.savefig(out / "cooling.svg")
plt.show()

time_step controls integration. Output(interval=...) controls which times are written, and the actual times live on the snapshots. Here the interval is an integer multiple of the step and the code checks the end time. scalar_series deliberately requires exactly one value per field and snapshot. Spatial and vector results need a different extractor. The error panel exposes discrepancies that are invisible in the overlaid temperature curves.
2.2 Reuse the transient workflow for a damped oscillator
Keep the imports and helpers from the preceding example. An oscillator adds an independent velocity initial condition. With mass \(m\), stiffness \(k\) and damping \(c\), the unforced motion satisfies \(m\ddot x+c\dot x+kx=0\). In the underdamped regime, \(\alpha=c/(2m)\) and \(\omega=\sqrt{k/m-\alpha^2}\). Check displacement and velocity independently. Mechanical energy gives an additional check even when the phase of the motion is hard to see in a plot.
from onesim.physics.solid_mechanics import StructuralOscillator
mass, stiffness, damping = 1.0, 4.0, 0.2 # kg, N/m, N s/m
x0, v0 = 0.01, 0.0 # m, m/s
domain = LumpedDomain()
osc = StructuralOscillator(
domain=domain.system, mass=mass, stiffness=stiffness, damping=damping,
)
result, sink, t = run_lumped(
domain, osc, ((osc.displacement, x0), (osc.velocity, v0)),
(osc.displacement, osc.velocity, osc.mechanical_energy),
end=10.0, dt=0.01, interval=0.05,
)
x = scalar_series(sink, osc.displacement)
v = scalar_series(sink, osc.velocity)
energy = scalar_series(sink, osc.mechanical_energy)
alpha = damping / (2 * mass)
omega = np.sqrt(stiffness / mass - alpha**2)
b = (v0 + alpha * x0) / omega
shape = x0 * np.cos(omega * t) + b * np.sin(omega * t)
exact_x = np.exp(-alpha * t) * shape
exact_v = np.exp(-alpha * t) * (
-alpha * shape - x0 * omega * np.sin(omega * t)
+ b * omega * np.cos(omega * t)
)
np.testing.assert_allclose(x, exact_x, rtol=0, atol=2e-8)
np.testing.assert_allclose(v, exact_v, rtol=0, atol=5e-8)
np.testing.assert_allclose(energy, (mass * v**2 + stiffness * x**2) / 2)
assert np.max(np.diff(energy)) <= 1e-12
assert energy[-1] < energy[0]
fig, (ax, phase) = plt.subplots(1, 2, figsize=(9, 4), layout="constrained")
ax.plot(t, 1e3 * exact_x, color=theme.INK, label="Closed form")
ax.plot(t[::3], 1e3 * x[::3], "o", ms=3, color=theme.COPPER, label="RK4")
ax.set(xlabel="Time [s]", ylabel="Displacement [mm]")
ax.legend(frameon=False)
phase.plot(1e3 * x, 1e3 * v, color=theme.TEAL)
phase.set(xlabel="Displacement [mm]", ylabel="Velocity [mm/s]",
title="Phase trajectory")
fig.savefig(out / "oscillator.svg")
plt.show()

Change the damping and plot a second run with the same axes. When \(k/m-\alpha^2\) is zero or negative, replace the reference formula with the critically damped or overdamped solution. The numerical model still receives the physical parameters in SI units.