---
url: /dyad/stable/stdlib/MultibodyComponents/components/GasForce2.md
description: >-
  Dyad GasForce2 docs.  Rough approximation of the gas force in the cylinder of
  a combustion engine, acting between two 1D translational flanges.
---

# `GasForce2` {#GasForce2}

Rough approximation of the gas force in the cylinder of a combustion engine, acting between two 1D translational flanges.

The force is a function of the relative flange distance `s_rel = flange_b.s - flange_a.s` (the piston position) and its derivative `v_rel` (the piston velocity): compression (`v_rel < 0`) and expansion (`v_rel > 0`) follow different quartic pressure curves in the normalized position `x = 1 - s_rel/L`. The resulting cylinder pressure acts on the piston area `pi*d^2/4`. A valid operating range requires `0 <= s_rel <= L`.

## Usage {#Usage}

`MultibodyComponents.GasForce2(L, d, k0=0.01, k1=1, k=1)`

## Parameters: {#Parameters:}

| Name |                          Description | Units | Default value |
| ----:| ------------------------------------:| -----:| -------------:|
|  `L` |                   Length of cylinder |     m |               |
|  `d` |                 Diameter of cylinder |     m |               |
| `k0` | Volume offset in V = k0 + k1\*(1 - x) |     – |          0.01 |
| `k1` |  Volume scale in V = k0 + k1\*(1 - x) |     – |             1 |
|  `k` |            Gas constant in p_V = k_T |     – |             1 |

## 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 |
| -------:| ------------------------------------------------------------------:| -----:|
|     `x` |                    Normalized position of cylinder (= 1 - s_rel/L) |     – |
| `press` |                                                  Cylinder pressure |     – |
|     `V` |                                                Cylinder gas volume |     – |
|     `T` |                                           Cylinder gas temperature |     – |
| `v_rel` |    Relative piston velocity (<0: compression; >0: expansion) |   m/s |
| `s_rel` | Relative flange distance flange_b.s - flange_a.s (piston position) |     m |
|     `f` |                Internal force (positive from flange_a to flange_b) |     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) \\
x\left( t \right) &= 1 + \frac{ - \mathtt{s_rel}\left( t \right)}{L} \\
\mathtt{v_rel}\left( t \right) &= \frac{\mathrm{d}\mathtt{s_rel}\left( t \right)}{\mathrm{d}t} \\
\mathtt{press}\left( t \right) &= 1 \cdot 10^{5} ~ ifelse\left( \mathtt{v_rel}\left( t \right) < 0, ifelse\left( x\left( t \right) < 0.98606, 2.4 - 24.997 ~ x\left( t \right) + 151.83 ~ \left( x\left( t \right) \right)^{2} - 287.22 ~ \left( x\left( t \right) \right)^{3} + 177.41 ~ \left( x\left( t \right) \right)^{4}, 2129670 - 9158505 ~ x\left( t \right) + 14761814 ~ \left( x\left( t \right) \right)^{2} - 10569296 ~ \left( x\left( t \right) \right)^{3} + 2836360 ~ \left( x\left( t \right) \right)^{4} \right), ifelse\left( 0.933 < x\left( t \right), -3036495 + 12964477 ~ x\left( t \right) - 20747000 ~ \left( x\left( t \right) \right)^{2} + 14748765 ~ \left( x\left( t \right) \right)^{3} - 3929704 ~ \left( x\left( t \right) \right)^{4}, 2.4 + 17.927 ~ x\left( t \right) + 17.344 ~ \left( x\left( t \right) \right)^{2} - 131.71 ~ \left( x\left( t \right) \right)^{3} + 145.93 ~ \left( x\left( t \right) \right)^{4} \right) \right) \\
f\left( t \right) &=  - \frac{1}{4} ~ d^{2} ~ \pi ~ \mathtt{press}\left( t \right) \\
V\left( t \right) &= \mathtt{k0} + \mathtt{k1} ~ \left( 1 - x\left( t \right) \right) \\
V\left( t \right) ~ \mathtt{press}\left( t \right) &= T\left( t \right) ~ k
\end{align}
$$

## Source {#Source}

```dyad
"""
Rough approximation of the gas force in the cylinder of a combustion engine,
acting between two 1D translational flanges.

The force is a function of the relative flange distance `s_rel = flange_b.s -
flange_a.s` (the piston position) and its derivative `v_rel` (the piston
velocity): compression (`v_rel < 0`) and expansion (`v_rel > 0`) follow different
quartic pressure curves in the normalized position `x = 1 - s_rel/L`. The
resulting cylinder pressure acts on the piston area `pi*d^2/4`. A valid operating
range requires `0 <= s_rel <= L`.
"""
component GasForce2
  flange_a = Flange() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 460, "x2": 50, "y2": 560, "rot": 0}
      },
      "tags": []
    }
  }
  flange_b = Flange() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 450, "x2": 1050, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Length of cylinder"
  parameter L::Length
  "Diameter of cylinder"
  parameter d::Length
  "Volume offset in V = k0 + k1*(1 - x)"
  parameter k0::Real = 0.01
  "Volume scale in V = k0 + k1*(1 - x)"
  parameter k1::Real = 1
  "Gas constant in p*V = k*T"
  parameter k::Real = 1
  "Normalized position of cylinder (= 1 - s_rel/L)"
  variable x::Real
  "Cylinder pressure"
  variable press::Real
  "Cylinder gas volume"
  variable V::Real
  "Cylinder gas temperature"
  variable T::Real
  "Relative piston velocity (<0: compression; >0: expansion)"
  variable v_rel::Velocity
  "Relative flange distance flange_b.s - flange_a.s (piston position)"
  variable s_rel::Length
  "Internal force (positive from flange_a to flange_b)"
  variable f::Dyad.Force
relations
  s_rel = flange_b.s - flange_a.s
  flange_b.f = f
  flange_a.f = -f
  x = 1 - s_rel / L
  v_rel = der(s_rel)
  press = 1e5 * ifelse(v_rel < 0, ifelse(x < 0.986061, 177.4132 * x ^ 4 - 287.2189 * x ^ 3 + 151.8252 * x ^ 2 - 24.9973 * x + 2.4, 2836360 * x ^ 4 - 10569296 * x ^ 3 + 14761814 * x ^ 2 - 9158505 * x + 2129670), ifelse(x > 0.933, -3929704 * x ^ 4 + 14748765 * x ^ 3 - 20747000 * x ^ 2 + 12964477 * x - 3036495, 145.930 * x ^ 4 - 131.707 * x ^ 3 + 17.3438 * x ^ 2 + 17.9272 * x + 2.4))
  f = -press * pi * d ^ 2 / 4
  V = k0 + k1 * (1 - x)
  press * V = k * T
end
```

```dyad
"""
Rough approximation of the gas force in the cylinder of a combustion engine,
acting between two 1D translational flanges.

The force is a function of the relative flange distance `s_rel = flange_b.s -
flange_a.s` (the piston position) and its derivative `v_rel` (the piston
velocity): compression (`v_rel < 0`) and expansion (`v_rel > 0`) follow different
quartic pressure curves in the normalized position `x = 1 - s_rel/L`. The
resulting cylinder pressure acts on the piston area `pi*d^2/4`. A valid operating
range requires `0 <= s_rel <= L`.
"""
component GasForce2
  flange_a = Flange() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 460, "x2": 50, "y2": 560, "rot": 0}
      },
      "tags": []
    }
  }
  flange_b = Flange() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 950, "y1": 450, "x2": 1050, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Length of cylinder"
  parameter L::Length
  "Diameter of cylinder"
  parameter d::Length
  "Volume offset in V = k0 + k1*(1 - x)"
  parameter k0::Real = 0.01
  "Volume scale in V = k0 + k1*(1 - x)"
  parameter k1::Real = 1
  "Gas constant in p*V = k*T"
  parameter k::Real = 1
  "Normalized position of cylinder (= 1 - s_rel/L)"
  variable x::Real
  "Cylinder pressure"
  variable press::Real
  "Cylinder gas volume"
  variable V::Real
  "Cylinder gas temperature"
  variable T::Real
  "Relative piston velocity (<0: compression; >0: expansion)"
  variable v_rel::Velocity
  "Relative flange distance flange_b.s - flange_a.s (piston position)"
  variable s_rel::Length
  "Internal force (positive from flange_a to flange_b)"
  variable f::Dyad.Force
relations
  s_rel = flange_b.s - flange_a.s
  flange_b.f = f
  flange_a.f = -f
  x = 1 - s_rel / L
  v_rel = der(s_rel)
  press = 1e5 * ifelse(v_rel < 0, ifelse(x < 0.986061, 177.4132 * x ^ 4 - 287.2189 * x ^ 3 + 151.8252 * x ^ 2 - 24.9973 * x + 2.4, 2836360 * x ^ 4 - 10569296 * x ^ 3 + 14761814 * x ^ 2 - 9158505 * x + 2129670), ifelse(x > 0.933, -3929704 * x ^ 4 + 14748765 * x ^ 3 - 20747000 * x ^ 2 + 12964477 * x - 3036495, 145.930 * x ^ 4 - 131.707 * x ^ 3 + 17.3438 * x ^ 2 + 17.9272 * x + 2.4))
  f = -press * pi * d ^ 2 / 4
  V = k0 + k1 * (1 - x)
  press * V = k * T
metadata {}
end
```

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses
