Skip to content

Instantly share code, notes, and snippets.

View hovsep's full-sized avatar
🤓
Constant learner

Ovsep Avakian hovsep

🤓
Constant learner
  • SumUp
  • Sofia, Bulgaria
View GitHub Profile
const (
restingLungVolume = 700.0 * Milliliter
ResidualLungVolume = 600.0 * Milliliter
TotalLungCapacity = 3000.0 * Milliliter
defaultLungCompliance = 100.0 * MlPerCmH2O
defaultAirwayResistance = 0.002 * CmH2OPerMlPerSecond
lungVolumeAsymmetry = 5 * Percent
const (
TidalRespiratoryRate = 12 * PerMinute
MinRespiratoryRate = 8 * PerMinute
MaxRespiratoryRate = 30 * PerMinute
BasePleuralPressure = -5 * CmH2O // resting pleural pressure at FRC
InspiratoryPressureAmplitude = 3 * CmH2O // peak swing during quiet breathing (−5 → −8 cmH₂O)
inhaleFraction = 1.0 / 3.0
// What it checks: run simulation for 100ms and check the ECG, we must see a few R-peaks
func Test_Human(t *testing.T) {
tests := []struct {
name string
assertions func(t *testing.T, sim *step_sim.Simulation)
}{
{
name: "heart is beating",
assertions: func(t *testing.T, sim *step_sim.Simulation) {
@hovsep
hovsep / autonomic_tone.go
Created March 19, 2026 19:28
Components of autonomic tone
// PackAutonomicTone builds a signal that represents autonomic tone
func PackAutonomicTone(sym, paraSym, noise, gain, cardiacBias, vascularBias, respiratoryBias, giBias float64) *signal.Signal {
return signal.New(signal.NewGroup().Add(
NewLevel(sym, common.Sympathetic),
NewLevel(paraSym, common.Parasympathetic),
NewLevel(noise, common.Noise),
NewLevel(gain, common.Gain),
NewBias(cardiacBias, common.Cardiac),
NewBias(vascularBias, common.Vascular),
NewBias(respiratoryBias, common.Respiratory),
@hovsep
hovsep / testing.go
Created February 23, 2026 20:14
testing_helper
// WithRunningSimulation is a helper function that runs the simulation and executes a callback after a given duration
func WithRunningSimulation(sim *step_sim.Simulation, duration time.Duration, f func()) {
go sim.Run()
defer func() {
sim.SendCommand(step_sim.Exit)
}()
// Let the simulation run for a while
time.Sleep(duration)
@hovsep
hovsep / time_test.go
Created February 23, 2026 20:11
time_test
func Test_Time(t *testing.T) {
tests := []struct {
name string
assertions func(t *testing.T, sim *step_sim.Simulation)
}{
{
name: "time advances in timer",
assertions: func(t *testing.T, sim *step_sim.Simulation) {
var observedSimWallTime []time.Time
@hovsep
hovsep / custom_commands.go
Created January 13, 2026 08:36
human body sim custom commands
// setMeshCommands sets the commands that can be executed on the mesh
func setMeshCommands(mesh *fmesh.FMesh, commands step_sim.MeshCommandMap) {
timeComponent := mesh.ComponentByName("time")
// Print current time
commands["time:now"] = step_sim.NewMeshCommandDescriptor("Print current time", func(_ *fmesh.FMesh) {
tickCount := timeComponent.State().Get("tick_count")
simTime := timeComponent.State().Get("sim_time")
simWallTime := timeComponent.State().Get("sim_wall_time")
fmt.Println("Current tick count:", tickCount)
@hovsep
hovsep / step_sim_wrapper.go
Last active January 13, 2026 08:31
Simulation mesh wrapped into step_sim
// I like my main func to be clean and short
func main() {
simMesh := getSimulationMesh()
// Run the mesh in a step simulation
step_sim.NewApp(simMesh, initSim).Run()
}
// Here is our step_sim wrapper, it provides REPL and some built-in commands: pause, resume, exit, help
func NewApp(fm *fmesh.FMesh, simInitFunc SimInitFunc) *Application {
@hovsep
hovsep / get_simulation.go
Created January 13, 2026 07:57
Human body simulation mesh
// getSimulationMesh returns the main mesh of the simulation
func getSimulationMesh() *fmesh.FMesh {
// Set up the world
habitat := env.NewHabitat(component.NewCollection().Add(
factor.GetTimeComponent(),
factor.GetAirComponent(),
factor.GetSunComponent(),
))
// Add human beings
@hovsep
hovsep / can_bus_main.go
Created January 9, 2026 16:06
ISO-tp frames
func main() {
fm := getMesh()
// Initialize the mesh: set diagnostic frames to USB port, so the laptop will send them
laptopInstance.SendDataToUSB(
diagnostics.FrameGetEngineDTCs,
diagnostics.FrameGetSpeed,
diagnostics.FrameGetRPM,
diagnostics.FrameGetCoolantTemperature,
diagnostics.FrameGetCalibrationID,