Skip to content
LIBRARY
Examples.ElastoGap.md

Examples.ElastoGap

Demonstrate usage of ElastoGap.

Replicates the structure of Modelica.Mechanics.Translational.Examples.ElastoGap.

Two parallel systems compare the behaviour of SpringDamper (top) vs ElastoGap (bottom) for identical mass/stiffness/damping. Both masses start at the same position (s=2) and oscillate between two walls (rod ends) separated by 4 m via a Fixed at the centre.

Top system (SpringDamper): mass1 is connected between the rod ends through two SpringDampers (c=10, d=1.5, s_rel0=1). The spring-damper forces act continuously, so mass1 always feels the restoring force.

Bottom system (ElastoGap): mass2 is connected through two ElastoGaps (c=10, d=1.5, s_rel0=1.5). The gap allows mass2 to move freely in the region −0.5 m < s < 0.5 m (no contact force), which reduces the effective eigenfrequency compared to the top system.

Each ElastoGap heat port is connected to a FixedTemperature boundary so the thermal energy balance is closed.

Usage

TranslationalComponents.Examples.ElastoGap()

Behavior

julia
using TranslationalComponents #hide
using ModelingToolkit #hide
@named sys = TranslationalComponents.Examples.ElastoGap() #hide
full_equations(sys) #hide
<< @example-block not executed in draft mode >>

Source

dyad
"""
Demonstrate usage of ElastoGap.

Replicates the structure of Modelica.Mechanics.Translational.Examples.ElastoGap.

Two parallel systems compare the behaviour of SpringDamper (top) vs ElastoGap (bottom)
for identical mass/stiffness/damping. Both masses start at the same position (s=2)
and oscillate between two walls (rod ends) separated by 4 m via a Fixed at the centre.

**Top system (SpringDamper):** mass1 is connected between the rod ends through two
SpringDampers (c=10, d=1.5, s_rel0=1). The spring-damper forces act continuously,
so mass1 always feels the restoring force.

**Bottom system (ElastoGap):** mass2 is connected through two ElastoGaps (c=10,
d=1.5, s_rel0=1.5). The gap allows mass2 to move freely in the region
−0.5 m < s < 0.5 m (no contact force), which reduces the effective eigenfrequency
compared to the top system.

Each ElastoGap heat port is connected to a FixedTemperature boundary so the thermal
energy balance is closed.
"""
example component ElastoGap
  "Fixed reference at centre"
  fixed = TranslationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 360, "y1": 290, "x2": 460, "y2": 390, "rot": 0}
      },
      "tags": []
    }
  }
  "Left rod (L=2)"
  rod1 = TranslationalComponents.Components.Rod(L = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 190, "x2": 290, "y2": 290, "rot": 0}
      },
      "tags": []
    }
  }
  "Right rod (L=2)"
  rod2 = TranslationalComponents.Components.Rod(L = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 530, "y1": 190, "x2": 630, "y2": 290, "rot": 0}
      },
      "tags": []
    }
  }
  "Left spring-damper (top system)"
  spring_damper1 = TranslationalComponents.Components.SpringDamper(c = 10, s_rel0 = 1, d = 1.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 20, "x2": 290, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Right spring-damper (top system)"
  spring_damper2 = TranslationalComponents.Components.SpringDamper(c = 10, s_rel0 = 1, d = 1.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 520, "y1": 20, "x2": 620, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass for the top system"
  mass1 = TranslationalComponents.Components.Mass(m = 1, L = 0, s = initial 2, v = initial 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 350, "y1": 20, "x2": 450, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Left elasto-gap (bottom system)"
  elasto_gap1 = TranslationalComponents.Components.ElastoGap(c = 10, s_rel0 = 1.5, d = 1.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 450, "x2": 270, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Right elasto-gap (bottom system)"
  elasto_gap2 = TranslationalComponents.Components.ElastoGap(c = 10, s_rel0 = 1.5, d = 1.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 530, "y1": 450, "x2": 630, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass for the bottom system"
  mass2 = TranslationalComponents.Components.Mass(m = 1, L = 0, s = initial 2, v = initial 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 360, "y1": 450, "x2": 460, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Thermal boundary for elasto_gap1"
  thermal_ground1 = ThermalComponents.Sources.FixedTemperature(T = 293.15) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -10, "y1": 620, "x2": 90, "y2": 720, "rot": 0}
      },
      "tags": []
    }
  }
  "Thermal boundary for elasto_gap2"
  thermal_ground2 = ThermalComponents.Sources.FixedTemperature(T = 293.15) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 340, "y1": 640, "x2": 440, "y2": 740, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(spring_damper1.flange_a, rod1.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 135, "y": 70}, {"x": 135, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(spring_damper1.flange_b, mass1.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(mass1.flange_b, spring_damper2.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(spring_damper2.flange_b, rod2.flange_b) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 655, "y": 70}, {"x": 655, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(elasto_gap1.flange_a, rod1.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 135, "y": 500}, {"x": 135, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(elasto_gap1.flange_b, mass2.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(mass2.flange_b, elasto_gap2.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(elasto_gap2.flange_b, rod2.flange_b) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 655, "y": 500}, {"x": 655, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(elasto_gap1.heat_port, thermal_ground1.port) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 550}, {"x": 140, "y": 670}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(elasto_gap2.heat_port, thermal_ground2.port) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 470, "y": 550}, {"x": 470, "y": 690}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod1.flange_b, fixed.flange) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 410, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod2.flange_a, fixed.flange) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 410, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod1.flange_b, rod2.flange_a) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 5,
        "atol": {
          "elasto_gap1.v_rel": 0.01,
          "elasto_gap2.s_rel": 0.01,
          "spring_damper1.v_rel": 0.001,
          "spring_damper2.s_rel": 0.001
        },
        "expect": {
          "final": {
            "elasto_gap1.v_rel": 0.53753,
            "elasto_gap2.s_rel": 2.70789,
            "spring_damper1.v_rel": -0.00419,
            "spring_damper2.s_rel": 2.00035
          },
          "signals": [
            "elasto_gap1.v_rel",
            "elasto_gap2.s_rel",
            "spring_damper1.v_rel",
            "spring_damper2.s_rel"
          ]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Demonstrate usage of ElastoGap.

Replicates the structure of Modelica.Mechanics.Translational.Examples.ElastoGap.

Two parallel systems compare the behaviour of SpringDamper (top) vs ElastoGap (bottom)
for identical mass/stiffness/damping. Both masses start at the same position (s=2)
and oscillate between two walls (rod ends) separated by 4 m via a Fixed at the centre.

**Top system (SpringDamper):** mass1 is connected between the rod ends through two
SpringDampers (c=10, d=1.5, s_rel0=1). The spring-damper forces act continuously,
so mass1 always feels the restoring force.

**Bottom system (ElastoGap):** mass2 is connected through two ElastoGaps (c=10,
d=1.5, s_rel0=1.5). The gap allows mass2 to move freely in the region
−0.5 m < s < 0.5 m (no contact force), which reduces the effective eigenfrequency
compared to the top system.

Each ElastoGap heat port is connected to a FixedTemperature boundary so the thermal
energy balance is closed.
"""
example component ElastoGap
  "Fixed reference at centre"
  fixed = TranslationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 360, "y1": 290, "x2": 460, "y2": 390, "rot": 0}
      },
      "tags": []
    }
  }
  "Left rod (L=2)"
  rod1 = TranslationalComponents.Components.Rod(L = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 190, "x2": 290, "y2": 290, "rot": 0}
      },
      "tags": []
    }
  }
  "Right rod (L=2)"
  rod2 = TranslationalComponents.Components.Rod(L = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 530, "y1": 190, "x2": 630, "y2": 290, "rot": 0}
      },
      "tags": []
    }
  }
  "Left spring-damper (top system)"
  spring_damper1 = TranslationalComponents.Components.SpringDamper(c = 10, s_rel0 = 1, d = 1.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 20, "x2": 290, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Right spring-damper (top system)"
  spring_damper2 = TranslationalComponents.Components.SpringDamper(c = 10, s_rel0 = 1, d = 1.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 520, "y1": 20, "x2": 620, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass for the top system"
  mass1 = TranslationalComponents.Components.Mass(m = 1, L = 0, s = initial 2, v = initial 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 350, "y1": 20, "x2": 450, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Left elasto-gap (bottom system)"
  elasto_gap1 = TranslationalComponents.Components.ElastoGap(c = 10, s_rel0 = 1.5, d = 1.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 450, "x2": 270, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Right elasto-gap (bottom system)"
  elasto_gap2 = TranslationalComponents.Components.ElastoGap(c = 10, s_rel0 = 1.5, d = 1.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 530, "y1": 450, "x2": 630, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass for the bottom system"
  mass2 = TranslationalComponents.Components.Mass(m = 1, L = 0, s = initial 2, v = initial 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 360, "y1": 450, "x2": 460, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Thermal boundary for elasto_gap1"
  thermal_ground1 = ThermalComponents.Sources.FixedTemperature(T = 293.15) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -10, "y1": 620, "x2": 90, "y2": 720, "rot": 0}
      },
      "tags": []
    }
  }
  "Thermal boundary for elasto_gap2"
  thermal_ground2 = ThermalComponents.Sources.FixedTemperature(T = 293.15) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 340, "y1": 640, "x2": 440, "y2": 740, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(spring_damper1.flange_a, rod1.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 135, "y": 70}, {"x": 135, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(spring_damper1.flange_b, mass1.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(mass1.flange_b, spring_damper2.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(spring_damper2.flange_b, rod2.flange_b) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 655, "y": 70}, {"x": 655, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(elasto_gap1.flange_a, rod1.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 135, "y": 500}, {"x": 135, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(elasto_gap1.flange_b, mass2.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(mass2.flange_b, elasto_gap2.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(elasto_gap2.flange_b, rod2.flange_b) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 655, "y": 500}, {"x": 655, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(elasto_gap1.heat_port, thermal_ground1.port) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 550}, {"x": 140, "y": 670}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(elasto_gap2.heat_port, thermal_ground2.port) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 470, "y": 550}, {"x": 470, "y": 690}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod1.flange_b, fixed.flange) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 410, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod2.flange_a, fixed.flange) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 410, "y": 240}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod1.flange_b, rod2.flange_a) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 5,
        "atol": {
          "elasto_gap1.v_rel": 0.01,
          "elasto_gap2.s_rel": 0.01,
          "spring_damper1.v_rel": 0.001,
          "spring_damper2.s_rel": 0.001
        },
        "expect": {
          "final": {
            "elasto_gap1.v_rel": 0.53753,
            "elasto_gap2.s_rel": 2.70789,
            "spring_damper1.v_rel": -0.00419,
            "spring_damper2.s_rel": 2.00035
          },
          "signals": [
            "elasto_gap1.v_rel",
            "elasto_gap2.s_rel",
            "spring_damper1.v_rel",
            "spring_damper2.s_rel"
          ]
        }
      }
    }
  }
}
end


Test Cases

julia
using TranslationalComponents
using DyadInterface: TransientAnalysis, rebuild_sol, ODEAlg
using ModelingToolkit: toggle_namespacing, get_initial_conditions, @named
using CSV, DataFrames, Plots

snapshotsdir = joinpath(dirname(dirname(pathof(TranslationalComponents))), "test", "snapshots")
<< @setup-block not executed in draft mode >>

Test Case case1

julia
@named model_case1 = TranslationalComponents.Examples.ElastoGap()
model_case1 = toggle_namespacing(model_case1, false)

model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = ODEAlg.Auto(), start = 0e+0, stop = 5e+0, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)
<< @setup-block not executed in draft mode >>
julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.elasto_gap1.v_rel])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Examples.ElastoGap_case1_sig0.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.elasto_gap1.v_rel], width=2, label="Actual value of elasto_gap1.v_rel")
if !isnothing(dfr_case1)
  scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of elasto_gap1.v_rel")
end
scatter!(plt, [df_case1.t[end]], [0.53753], label="Final Condition for `elasto_gap1.v_rel`")
<< @setup-block not executed in draft mode >>
julia
plt
<< @example-block not executed in draft mode >>
julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.elasto_gap2.s_rel])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Examples.ElastoGap_case1_sig1.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.elasto_gap2.s_rel], width=2, label="Actual value of elasto_gap2.s_rel")
if !isnothing(dfr_case1)
  scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of elasto_gap2.s_rel")
end
scatter!(plt, [df_case1.t[end]], [2.70789], label="Final Condition for `elasto_gap2.s_rel`")
<< @setup-block not executed in draft mode >>
julia
plt
<< @example-block not executed in draft mode >>
julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.spring_damper1.v_rel])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Examples.ElastoGap_case1_sig2.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.spring_damper1.v_rel], width=2, label="Actual value of spring_damper1.v_rel")
if !isnothing(dfr_case1)
  scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of spring_damper1.v_rel")
end
scatter!(plt, [df_case1.t[end]], [-0.00419], label="Final Condition for `spring_damper1.v_rel`")
<< @setup-block not executed in draft mode >>
julia
plt
<< @example-block not executed in draft mode >>
julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.spring_damper2.s_rel])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Examples.ElastoGap_case1_sig3.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.spring_damper2.s_rel], width=2, label="Actual value of spring_damper2.s_rel")
if !isnothing(dfr_case1)
  scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of spring_damper2.s_rel")
end
scatter!(plt, [df_case1.t[end]], [2.00035], label="Final Condition for `spring_damper2.s_rel`")
<< @setup-block not executed in draft mode >>
julia
plt
<< @example-block not executed in draft mode >>