---
url: /dyad/dev/stdlib/TranslationalComponents/components/Components.Spring.md
description: >-
  Dyad Components.Spring docs.  Linear 1D translational spring relating force to
  displacement via Hooke's Law.
---

# `Components.Spring` {#Components.Spring}

Linear 1D translational spring relating force to displacement via Hooke's Law.

This component represents a one-dimensional translational mechanical spring. It models the linear relationship between the force ($f$) exerted by the spring and its deformation ($s\_{rel}$) relative to an unstretched length ($s\_{rel0}$). The governing equation is Hooke's Law:

$$f = c \cdot (s\_{rel} - s\_{rel0})$$

Here, `c` is the spring constant (stiffness), $s\_{rel}$ is the current relative displacement between the spring's two connection flanges (typically inherited from `PartialCompliant`), and $s\_{rel0}$ is the relative displacement at which the spring exerts no force.

This component extends from [`TranslationalComponents.Interfaces.PartialCompliant`](../types/Interfaces.PartialCompliant.md)

## Usage {#Usage}

`TranslationalComponents.Components.Spring(c, s_rel0=0)`

## Parameters: {#Parameters:}

|     Name |                                                                      Description | Units | Default value |
| --------:| --------------------------------------------------------------------------------:| -----:| -------------:|
|      `c` |                       Spring constant, representing the stiffness of the spring. |   N/m |               |
| `s_rel0` | Unstretched relative displacement of the spring, where the spring force is zero. |     m |             0 |

## Connectors {#Connectors}

* `flange_a` - This connector represents a mechanical flange with position and force as the potential and flow variables, respectively. ([`Flange`](/stdlib/Dyad/connectors/Flange#Flange))

* `flange_b` - This connector represents a mechanical flange with position and force as the potential and flow variables, respectively. ([`Flange`](/stdlib/Dyad/connectors/Flange#Flange))

## Variables {#Variables}

|    Name |                                                                          Description | Units |
| -------:| ------------------------------------------------------------------------------------:| -----:|
| `s_rel` |                                  Relative distance between `flange_b` and `flange_a` |     m |
|     `f` | Internal force exerted by the compliant connection on flange_b (and -f on flange_a). |     N |

## Behavior {#Behavior}

$$ \begin{align}
\mathtt{s_rel}\left( t \right) &=  - \mathtt{flange_a.s}\left( t \right) + \mathtt{flange_b.s}\left( t \right) \\
\mathtt{flange_b.f}\left( t \right) &= f\left( t \right) \\
\mathtt{flange_a.f}\left( t \right) &=  - f\left( t \right) \\
f\left( t \right) &= c ~ \left( \mathtt{s_rel}\left( t \right) - \mathtt{s_rel0} \right)
\end{align}
$$

## Source {#Source}

````dyad
"""
Linear 1D translational spring relating force to displacement via Hooke's Law.

This component represents a one-dimensional translational mechanical spring.
It models the linear relationship between the force ($f$) exerted by the
spring and its deformation ($s_{rel}$) relative to an unstretched length ($s_{rel0}$).
The governing equation is Hooke's Law:
```math
f = c \cdot (s_{rel} - s_{rel0})
```
Here, `c` is the spring constant (stiffness), $s_{rel}$ is the current
relative displacement between the spring's two connection flanges (typically
inherited from `PartialCompliant`), and $s_{rel0}$ is the relative displacement
at which the spring exerts no force.
"""
component Spring
  extends TranslationalComponents.Interfaces.PartialCompliant
  "Spring constant, representing the stiffness of the spring."
  parameter c::TranslationalSpringConstant(min = 0)
  "Unstretched relative displacement of the spring, where the spring force is zero."
  parameter s_rel0::Distance = 0
relations
  f = c * (s_rel - s_rel0)
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Spring.svg"},
    "labels": [{"label": "$(instance)", "layer": "icon", "x": 500, "y": 921, "rot": 0}]
  }
}
end
````

````dyad
"""
Linear 1D translational spring relating force to displacement via Hooke's Law.

This component represents a one-dimensional translational mechanical spring.
It models the linear relationship between the force ($f$) exerted by the
spring and its deformation ($s_{rel}$) relative to an unstretched length ($s_{rel0}$).
The governing equation is Hooke's Law:
```math
f = c \cdot (s_{rel} - s_{rel0})
```
Here, `c` is the spring constant (stiffness), $s_{rel}$ is the current
relative displacement between the spring's two connection flanges (typically
inherited from `PartialCompliant`), and $s_{rel0}$ is the relative displacement
at which the spring exerts no force.
"""
component Spring
  "Left mechanical translational flange (connector)"
  flange_a = Flange() {"Dyad": {"placement": {"icon": {"x1": -50, "y1": 450, "x2": 50, "y2": 550}}}}
  "Right mechanical translational flange (connector)"
  flange_b = Flange() {"Dyad": {"placement": {"icon": {"x1": 950, "y1": 450, "x2": 1050, "y2": 550}}}}
  "Relative distance between `flange_b` and `flange_a`"
  variable s_rel::Distance
  "Internal force exerted by the compliant connection on flange_b (and -f on flange_a)."
  variable f::Dyad.Force
  "Spring constant, representing the stiffness of the spring."
  parameter c::TranslationalSpringConstant(min = 0)
  "Unstretched relative displacement of the spring, where the spring force is zero."
  parameter s_rel0::Distance = 0
relations
  s_rel = flange_b.s - flange_a.s
  flange_b.f = f
  flange_a.f = -f
  f = c * (s_rel - s_rel0)
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Spring.svg"},
    "labels": [{"label": "$(instance)", "layer": "icon", "x": 500, "y": 921, "rot": 0}]
  }
}
end
````

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`AllComponents`](Components.Spring.md)

  * [`MassDamperSpringFixed`](Components.Spring.md)
