Input/output block of a spring/damper model. A linear 1D rotational spring and damper in parallel with pure signal
interface which can be applied for
a FMU (Functional Mock-up Unit)
exchange.

within Modelica.Mechanics.Rotational.Examples.Utilities;
model SpringDamper "Input/output block of a spring/damper model"
  extends Modelica.Blocks.Icons.Block;
  parameter SI.RotationalSpringConstant c=1e4
    "Spring constant";
  parameter SI.RotationalDampingConstant d=1
    "Damping constant";
  parameter SI.Angle phi_rel0=0
    "Unstretched spring angle";

  Components.AngleToTorqueAdaptor
    angleToTorque1(use_a=false)
  Modelica.Blocks.Interfaces.RealInput phi1(unit="rad")
    "Angle of left flange of force element"
  Modelica.Blocks.Interfaces.RealInput w1(unit="rad/s")
    "Speed to left flange of force element"
  Modelica.Blocks.Interfaces.RealOutput tau1(unit="N.m")
    "Torque generated by the force element"
  SpringDamperNoRelativeStates springDamper(
    c=c,
    d=d,
    phi_rel0=phi_rel0)
  Modelica.Blocks.Interfaces.RealInput phi2(unit="rad")
    "Angle of right flange of force element"
  Modelica.Blocks.Interfaces.RealInput w2(unit="rad/s")
    "Speed to right flange of force element"
  Modelica.Blocks.Interfaces.RealOutput tau2(unit="N.m")
    "Torque generated by the force element"
  Components.AngleToTorqueAdaptor
    angleToTorque2(use_a=false)
equation

  connect(springDamper.flange_b, angleToTorque2.flange)
  connect(angleToTorque1.flange, springDamper.flange_a)
  connect(phi1, angleToTorque1.phi)
  connect(w1, angleToTorque1.w)
  connect(tau1, angleToTorque1.tau)
  connect(angleToTorque2.phi, phi2)
  connect(w2, angleToTorque2.w)
  connect(angleToTorque2.tau, tau2)
end SpringDamper;


Linear 1D rotational spring and damper in parallel (phi and w are not used as states). A spring and damper element connected in parallel.
The component can be
connected either between two masses to describe the joint elasticity
and damping, or between a mass and the housing (component Fixed),
to describe a coupling of the element with the housing via a spring/damper.

within Modelica.Mechanics.Rotational.Examples.Utilities;
model SpringDamperNoRelativeStates
  "Linear 1D rotational spring and damper in parallel (phi and w are not used as states)"
  parameter SI.RotationalSpringConstant c(final min=0, start=1.0e5) "Spring constant";
  parameter SI.RotationalDampingConstant d(final min=0, start=0) "Damping constant";
  parameter SI.Angle phi_rel0=0
    "Unstretched spring angle";
  SI.AngularVelocity w_rel(start=0)
    "Relative angular velocity(= der(phi_rel))";
  extends Modelica.Mechanics.Rotational.Interfaces.PartialCompliant;
  extends
    Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT;
protected
  SI.Torque tau_c "Spring torque";
  SI.Torque tau_d "Damping torque";
equation
  w_rel = der(phi_rel);
  tau_c = c*(phi_rel - phi_rel0);
  tau_d = d*w_rel;
  tau = tau_c + tau_d;
  lossPower = tau_d*w_rel;
end SpringDamperNoRelativeStates;


Icon of a clutch. This is the icon of a clutch from the rotational package.

within Modelica.Mechanics.Rotational.Icons;
model Clutch "Icon of a clutch"

end Clutch;


Icon of a gear box. This is the icon of a gear box from the rotational package.

within Modelica.Mechanics.Rotational.Icons;
model Gearbox "Icon of a gear box"

end Gearbox;


Icons for Rotational package

within Modelica.Mechanics.Rotational;
package Icons "Icons for Rotational package"
  extends Modelica.Icons.IconsPackage;
end Icons;


Adapter model to utilize conditional support connector. This is an adapter model to utilize a conditional
support connector
in a component. It could be applied to both textually (equations based) and graphically
defined components:

within Modelica.Mechanics.Rotational.Interfaces;
model InternalSupport
  "Adapter model to utilize conditional support connector"
  input SI.Torque tau
    "External support torque (must be computed via torque balance in model where InternalSupport is used; = flange.tau)";
  SI.Angle phi "External support angle (= flange.phi)";
  Flange_a flange
    "Internal support flange (must be connected to the conditional support connector for useSupport=true and to conditional fixed model for useSupport=false)"
equation
  flange.tau = tau;
  flange.phi = phi;
end InternalSupport;


within Modelica.Mechanics.Rotational;
package Interfaces "Connectors and partial models for 1D rotational mechanical components"

  extends Modelica.Icons.InterfacesPackage;
end Interfaces;


within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialAbsoluteSensor
  "Partial model to measure a single absolute flange variable"
  extends Modelica.Icons.RoundSensor;

  Flange_a flange
    "Flange of shaft from which sensor information shall be measured"

equation
  0 = flange.tau;
end PartialAbsoluteSensor;


Partial model for the compliant connection of two rotational 1-dim. shaft flanges. This is a 1-dim. rotational component with a compliant connection of two
rotational 1-dim. flanges where inertial effects between the two
flanges are neglected. The basic assumption is that the cut-torques
of the two flanges sum-up to zero, i.e., they have the same absolute value
but opposite sign: flange_a.tau + flange_b.tau = 0. This base class
is used to built up force elements such as springs, dampers, friction.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialCompliant
  "Partial model for the compliant connection of two rotational 1-dim. shaft flanges"

  SI.Angle phi_rel(start=0)
    "Relative rotation angle (= flange_b.phi - flange_a.phi)";
  SI.Torque tau "Torque between flanges (= flange_b.tau)";
  Flange_a flange_a "Left flange of compliant 1-dim. rotational component"
  Flange_b flange_b "Right flange of compliant 1-dim. rotational component"

equation
  phi_rel = flange_b.phi - flange_a.phi;
  flange_b.tau = tau;
  flange_a.tau = -tau;
end PartialCompliant;


Partial model for the compliant connection of two rotational 1-dim. shaft flanges where the relative angle and speed are used as preferred states. This is a 1-dim. rotational component with a compliant connection of two
rotational 1-dim. flanges where inertial effects between the two
flanges are neglected. The basic assumption is that the cut-torques
of the two flanges sum-up to zero, i.e., they have the same absolute value
but opposite sign: flange_a.tau + flange_b.tau = 0. This base class
is used to built up force elements such as springs, dampers, friction.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialCompliantWithRelativeStates
  "Partial model for the compliant connection of two rotational 1-dim. shaft flanges where the relative angle and speed are used as preferred states"

  SI.Angle phi_rel(
    start=0,
    stateSelect=stateSelect,
    nominal=if phi_nominal >= Modelica.Constants.eps then phi_nominal else
        1) "Relative rotation angle (= flange_b.phi - flange_a.phi)";
  SI.AngularVelocity w_rel(start=0, stateSelect=stateSelect)
    "Relative angular velocity (= der(phi_rel))";
  SI.AngularAcceleration a_rel(start=0)
    "Relative angular acceleration (= der(w_rel))";
  SI.Torque tau "Torque between flanges (= flange_b.tau)";
  Flange_a flange_a "Left flange of compliant 1-dim. rotational component"
  Flange_b flange_b "Right flange of compliant 1-dim. rotational component"

  parameter SI.Angle phi_nominal(
    displayUnit="rad",
    min=0.0) = 1e-4 "Nominal value of phi_rel (used for scaling)"
  parameter StateSelect stateSelect=StateSelect.prefer
    "Priority to use phi_rel and w_rel as states"

equation
  phi_rel = flange_b.phi - flange_a.phi;
  w_rel = der(phi_rel);
  a_rel = der(w_rel);
  flange_b.tau = tau;
  flange_a.tau = -tau;
end PartialCompliantWithRelativeStates;


Partial model for a component with one rotational 1-dim. shaft flange and a support used for textual modeling, i.e., for elementary models. This is a 1-dim. rotational component with one flange and a support/housing.
It is used to build up elementary components of a drive train with
equations in the text layer.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialElementaryOneFlangeAndSupport2
  "Partial model for a component with one rotational 1-dim. shaft flange and a support used for textual modeling, i.e., for elementary models"
  parameter Boolean useSupport=false
    "= true, if support flange enabled, otherwise implicitly grounded"
  Flange_b flange "Flange of shaft"
  Support support(phi=phi_support, tau=-flange.tau) if useSupport
    "Support/housing of component"
protected
  SI.Angle phi_support "Absolute angle of support flange";
equation
  if not useSupport then
    phi_support = 0;
  end if;
end PartialElementaryOneFlangeAndSupport2;


Partial model to transform rotational into translational motion. This is a 1-dim. rotational component with

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialElementaryRotationalToTranslational
  "Partial model to transform rotational into translational motion"
  parameter Boolean useSupportR=false
    "= true, if rotational support flange enabled, otherwise implicitly grounded"
  parameter Boolean useSupportT=false
    "= true, if translational support flange enabled, otherwise implicitly grounded"
  Rotational.Interfaces.Flange_a flangeR "Flange of rotational shaft"
  Modelica.Mechanics.Translational.Interfaces.Flange_b flangeT
    "Flange of translational rod"
  Rotational.Interfaces.Support supportR if useSupportR
    "Rotational support/housing of component"
  Translational.Interfaces.Support supportT if useSupportT
    "Translational support/housing of component"

protected
  Rotational.Interfaces.InternalSupport internalSupportR(tau=-flangeR.tau)
  Translational.Interfaces.InternalSupport internalSupportT(f=-flangeT.f)
  Rotational.Components.Fixed fixedR if not useSupportR
  Translational.Components.Fixed fixedT if not useSupportT
equation
  connect(internalSupportR.flange, supportR)
  connect(internalSupportR.flange, fixedR.flange)
  connect(fixedT.flange, internalSupportT.flange)
  connect(internalSupportT.flange, supportT)
end PartialElementaryRotationalToTranslational;


Partial model for a component with two rotational 1-dim. shaft flanges and a support used for textual modeling, i.e., for elementary models. This is a 1-dim. rotational component with two flanges and a support/housing.
It is used to build up elementary components of a drive train with
equations in the text layer.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialElementaryTwoFlangesAndSupport2
  "Partial model for a component with two rotational 1-dim. shaft flanges and a support used for textual modeling, i.e., for elementary models"
  parameter Boolean useSupport=false
    "= true, if support flange enabled, otherwise implicitly grounded"
  Flange_a flange_a "Flange of left shaft"
  Flange_b flange_b "Flange of right shaft"
  Support support(phi=phi_support, tau=-flange_a.tau - flange_b.tau) if
    useSupport "Support/housing of component"
protected
  SI.Angle phi_support "Absolute angle of support flange";
equation
  if not useSupport then
    phi_support = 0;
  end if;
end PartialElementaryTwoFlangesAndSupport2;


Partial model of Coulomb friction elements. Basic model for Coulomb friction that models the stuck phase in a reliable way.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialFriction "Partial model of Coulomb friction elements"

  // parameter SI.AngularVelocity w_small=1 "Relative angular velocity near to zero (see model info text)";
  parameter SI.AngularVelocity w_small=1.0e10
    "Relative angular velocity near to zero if jumps due to a reinit(..) of the velocity can occur (set to low value only if such impulses can occur)"
  // Equations to define the following variables have to be defined in subclasses
  SI.AngularVelocity w_relfric
    "Relative angular velocity between frictional surfaces";
  SI.AngularAcceleration a_relfric
    "Relative angular acceleration between frictional surfaces";
  //SI.Torque tau "Friction torque (positive, if directed in opposite direction of w_rel)";
  SI.Torque tau0 "Friction torque for w_relfric=0 and forward sliding";
  SI.Torque tau0_max "Maximum friction torque for w_relfric=0 and locked";
  Boolean free "= true, if frictional element is not active";
  // Equations to define the following variables are given in this class
  Real sa(final unit="1")
    "Path parameter of friction characteristic tau = f(a_relfric)";
  Boolean startForward(start=false, fixed=true)
    "= true, if w_relfric=0 and start of forward sliding";
  Boolean startBackward(start=false, fixed=true)
    "= true, if w_relfric=0 and start of backward sliding";
  Boolean locked(start=false) "= true, if w_rel=0 and not sliding";
  constant Integer Unknown=3 "Value of mode is not known";
  constant Integer Free=2 "Element is not active";
  constant Integer Forward=1 "w_relfric > 0 (forward sliding)";
  constant Integer Stuck=0
    "w_relfric = 0 (forward sliding, locked or backward sliding)";
  constant Integer Backward=-1 "w_relfric < 0 (backward sliding)";
  Integer mode(
    final min=Backward,
    final max=Unknown,
    start=Unknown,
    fixed=true)
    "Mode of friction (-1: backward sliding, 0: stuck, 1: forward sliding, 2: inactive, 3: unknown)";
protected
  constant SI.AngularAcceleration unitAngularAcceleration=1
  constant SI.Torque unitTorque=1
equation
  /* Friction characteristic
   locked is introduced to help the Modelica translator determining
   the different structural configurations,
   if for each configuration special code shall be generated
*/
  startForward = pre(mode) == Stuck and (sa > tau0_max/unitTorque or pre(
    startForward) and sa > tau0/unitTorque) or pre(mode) == Backward and
    w_relfric > w_small or initial() and (w_relfric > 0);
  startBackward = pre(mode) == Stuck and (sa < -tau0_max/unitTorque or pre(
    startBackward) and sa < -tau0/unitTorque) or pre(mode) == Forward and
    w_relfric < -w_small or initial() and (w_relfric < 0);
  locked = not free and not (pre(mode) == Forward or startForward or pre(
    mode) == Backward or startBackward);

  a_relfric/unitAngularAcceleration = if locked then 0 else if free then sa
    else if startForward then sa - tau0_max/unitTorque
    else if startBackward then sa + tau0_max/unitTorque
    else if pre(mode) == Forward then sa - tau0_max/unitTorque
    else if pre(mode) == Backward then sa + tau0_max/unitTorque
    else sa - sign(w_relfric)*tau0_max/unitTorque;

  /* Friction torque "tau" has to be defined in a subclass. Example for possible
     realization of a clutch utilizing interpolation by ExternalCombiTable1D see:
     Modelica.Mechanics.Rotational.Components.Clutch
*/

  // finite state machine to determine configuration
  mode = if free then Free else (if (pre(mode) == Forward or pre(mode) ==
    Free or startForward) and w_relfric > 0 then Forward else if (pre(mode)
     == Backward or pre(mode) == Free or startBackward) and w_relfric < 0
     then Backward else Stuck);
end PartialFriction;


Partial model for a component with one rotational 1-dim. shaft flange and a support used for graphical modeling, i.e., the model is build up by drag-and-drop from elementary components. This is a 1-dim. rotational component with one flange and a support/housing.
It is used e.g., to build up parts of a drive train graphically consisting
of several components.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialOneFlangeAndSupport
  "Partial model for a component with one rotational 1-dim. shaft flange and a support used for graphical modeling, i.e., the model is build up by drag-and-drop from elementary components"
  parameter Boolean useSupport=false
    "= true, if support flange enabled, otherwise implicitly grounded"
  Flange_b flange "Flange of shaft"
  Support support if useSupport "Support/housing of component"
protected
  Support internalSupport
    "Internal support/housing of component (either connected to support, if useSupport=true, or connected to fixed, if useSupport=false)"
  Components.Fixed fixed if not useSupport
    "Fixed support/housing, if not useSupport"
equation
  connect(support, internalSupport)
  connect(internalSupport, fixed.flange)
end PartialOneFlangeAndSupport;


within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialRelativeSensor
  "Partial model to measure a single relative variable between two flanges"
  extends Modelica.Icons.RoundSensor;

  Flange_a flange_a "Left flange of shaft"
  Flange_b flange_b "Right flange of shaft"

equation
  0 = flange_a.tau + flange_b.tau;
end PartialRelativeSensor;


Partial model of a torque acting at the flange (accelerates the flange). Partial model of torque that accelerates the flange.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialTorque
  "Partial model of a torque acting at the flange (accelerates the flange)"
  extends Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;
  SI.Angle phi
    "Angle of flange with respect to support (= flange.phi - support.phi)";

equation
  phi = flange.phi - phi_support;
end PartialTorque;


Partial model for a component with two rotational 1-dim. shaft flanges. This is a 1-dim. rotational component with two flanges.
It is used e.g., to build up parts of a drive train consisting
of several components.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialTwoFlanges
  "Partial model for a component with two rotational 1-dim. shaft flanges"

  Flange_a flange_a "Flange of left shaft"
  Flange_b flange_b "Flange of right shaft"
end PartialTwoFlanges;


Partial model for a component with two rotational 1-dim. shaft flanges and a support used for graphical modeling, i.e., the model is build up by drag-and-drop from elementary components. This is a 1-dim. rotational component with two flanges and a support/housing.
It is used e.g., to build up parts of a drive train graphically consisting
of several components.

within Modelica.Mechanics.Rotational.Interfaces;
partial model PartialTwoFlangesAndSupport
  "Partial model for a component with two rotational 1-dim. shaft flanges and a support used for graphical modeling, i.e., the model is build up by drag-and-drop from elementary components"
  parameter Boolean useSupport=false
    "= true, if support flange enabled, otherwise implicitly grounded"
  Flange_a flange_a "Flange of left shaft"
  Flange_b flange_b "Flange of right shaft"
  Support support if useSupport "Support/housing of component"
protected
  Support internalSupport
    "Internal support/housing of component (either connected to support, if useSupport=true, or connected to fixed, if useSupport=false)"
  Components.Fixed fixed if not useSupport
    "Fixed support/housing, if not useSupport"
equation
  connect(support, internalSupport)
  connect(internalSupport, fixed.flange)
end PartialTwoFlangesAndSupport;


Support/housing flange of a one-dimensional rotational shaft. This is a connector for 1-dim. rotational mechanical systems and models which represents
a support or housing of a shaft. The following variables are defined in this connector:

within Modelica.Mechanics.Rotational.Interfaces;
connector Support "Support/housing flange of a one-dimensional rotational shaft"
  extends Flange;
end Support;


Ideal sensor to measure the absolute angular acceleration of flange. Measures the absolute angular acceleration
of a flange in an ideal way and provides the result as
output signal a
(to be further processed with blocks of the
Modelica.Blocks library).

within Modelica.Mechanics.Rotational.Sensors;
model AccSensor
  "Ideal sensor to measure the absolute angular acceleration of flange"

  extends Rotational.Interfaces.PartialAbsoluteSensor;
  SI.AngularVelocity w "Absolute angular velocity of flange";
  Modelica.Blocks.Interfaces.RealOutput a(unit="rad/s2")
    "Absolute angular acceleration of flange as output signal"

equation
  w = der(flange.phi);
  a = der(w);
end AccSensor;


Ideal sensor to measure the absolute angle of flange. Measures the absolute angle
of a flange in an ideal way and provides the result as
output signal phi
(to be further processed with blocks of the
Modelica.Blocks library).

within Modelica.Mechanics.Rotational.Sensors;
model AngleSensor "Ideal sensor to measure the absolute angle of flange"

  extends Rotational.Interfaces.PartialAbsoluteSensor;
  Modelica.Blocks.Interfaces.RealOutput phi(unit="rad", displayUnit="deg")
    "Absolute angle of flange as output signal"
equation
  phi = flange.phi;
end AngleSensor;


Ideal sensor to measure the absolute angular velocity, torque and power between two flanges. Measures the absolute angular velocity of the flange_a and
the cut-torque and power between two flanges
in an ideal way and provides the results as output signals w,
tau and power, respectively.

within Modelica.Mechanics.Rotational.Sensors;
model MultiSensor
  "Ideal sensor to measure the absolute angular velocity, torque and power between two flanges"
  extends .Modelica.Mechanics.Rotational.Interfaces.PartialRelativeSensor;
  Modelica.Blocks.Interfaces.RealOutput power(unit="W")
    "Power in flange flange_a as output signal"
  Modelica.Blocks.Interfaces.RealOutput w(unit="rad/s")
    "Absolute angular velocity of flange_a as output signal"
  Modelica.Blocks.Interfaces.RealOutput tau(unit="N.m")
    "Torque in flange flange_a and flange_b (tau = flange_a.tau = -flange_b.tau) as output signal"
equation
  flange_a.phi = flange_b.phi;
  w = der(flange_a.phi);
  tau = flange_a.tau;
  power = tau*w;
end MultiSensor;


within Modelica.Mechanics.Rotational;
package Sensors "Sensors to measure variables in 1D rotational mechanical components"
  extends Modelica.Icons.SensorsPackage;
end Sensors;


Ideal sensor to measure the power between two flanges. Measures the power between two flanges
in an ideal way and provides the result as output signal power
(to be further processed with blocks of the
Modelica.Blocks library), i.e.

within Modelica.Mechanics.Rotational.Sensors;
model PowerSensor
  "Ideal sensor to measure the power between two flanges"

  extends Rotational.Interfaces.PartialRelativeSensor;
  Modelica.Blocks.Interfaces.RealOutput power(unit="W")
    "Power in flange flange_a as output signal"

equation
  flange_a.phi = flange_b.phi;
  power = flange_a.tau*der(flange_a.phi);
end PowerSensor;


Ideal sensor to measure the relative angular acceleration between two flanges. Measures the relative angular acceleration between two flanges
in an ideal way and provides the result as output signal a_rel
(to be further processed with blocks of the
Modelica.Blocks library).

within Modelica.Mechanics.Rotational.Sensors;
model RelAccSensor
  "Ideal sensor to measure the relative angular acceleration between two flanges"

  extends Rotational.Interfaces.PartialRelativeSensor;

  SI.Angle phi_rel
    "Relative angle between two flanges (flange_b.phi - flange_a.phi)";
  SI.AngularVelocity w_rel "Relative angular velocity between two flanges";
  Modelica.Blocks.Interfaces.RealOutput a_rel(unit="rad/s2")
    "Relative angular acceleration between two flanges as output signal"

equation
  phi_rel = flange_b.phi - flange_a.phi;
  w_rel = der(phi_rel);
  a_rel = der(w_rel);
  0 = flange_a.tau;
end RelAccSensor;


Ideal sensor to measure the relative angle between two flanges. Measures the relative angle between two flanges
in an ideal way and provides the result as output signal phi_rel
(to be further processed with blocks of the
Modelica.Blocks library).

within Modelica.Mechanics.Rotational.Sensors;
model RelAngleSensor
  "Ideal sensor to measure the relative angle between two flanges"

  extends Rotational.Interfaces.PartialRelativeSensor;
  Modelica.Blocks.Interfaces.RealOutput phi_rel(unit="rad", displayUnit="deg")
    "Relative angle between two flanges (= flange_b.phi - flange_a.phi) as output signal"

equation
  phi_rel = flange_b.phi - flange_a.phi;
  0 = flange_a.tau;
end RelAngleSensor;


Ideal sensor to measure the relative angular velocity between two flanges. Measures the relative angular velocity between two flanges
in an ideal way and provides the result as output signal w_rel
(to be further processed with blocks of the
Modelica.Blocks library).

within Modelica.Mechanics.Rotational.Sensors;
model RelSpeedSensor
  "Ideal sensor to measure the relative angular velocity between two flanges"

  extends Rotational.Interfaces.PartialRelativeSensor;

  SI.Angle phi_rel
    "Relative angle between two flanges (flange_b.phi - flange_a.phi)";
  Modelica.Blocks.Interfaces.RealOutput w_rel(unit="rad/s")
    "Relative angular velocity between two flanges (= der(flange_b.phi) - der(flange_a.phi)) as output signal"

equation
  phi_rel = flange_b.phi - flange_a.phi;
  w_rel = der(phi_rel);
  0 = flange_a.tau;
end RelSpeedSensor;


Ideal sensor to measure the absolute angular velocity of flange. Measures the absolute angular velocity
of a flange in an ideal way and provides the result as
output signal w
(to be further processed with blocks of the
Modelica.Blocks library).

within Modelica.Mechanics.Rotational.Sensors;
model SpeedSensor
  "Ideal sensor to measure the absolute angular velocity of flange"

  extends Rotational.Interfaces.PartialAbsoluteSensor;
  Modelica.Blocks.Interfaces.RealOutput w(unit="rad/s")
    "Absolute angular velocity of flange as output signal"

equation
  w = der(flange.phi);
end SpeedSensor;


Ideal sensor to measure the torque between two flanges. Measures the cut-torque between two flanges
in an ideal way and provides the result as output signal tau
(to be further processed with blocks of the
Modelica.Blocks library).

within Modelica.Mechanics.Rotational.Sensors;
model TorqueSensor
  "Ideal sensor to measure the torque between two flanges"

  extends Rotational.Interfaces.PartialRelativeSensor;
  Modelica.Blocks.Interfaces.RealOutput tau(unit="N.m")
    "Torque in flange flange_a and flange_b (tau = flange_a.tau = -flange_b.tau) as output signal"

equation
  flange_a.phi = flange_b.phi;
  flange_a.tau = tau;
end TorqueSensor;


Forced movement of a flange according to an acceleration signal. The input signal a_ref defines an angular acceleration
in [rad/s2]. Flange flange is forced to move relative to flange support with
this acceleration. The angular velocity w and the rotation angle
phi of the flange are automatically determined by integration of
the acceleration.

within Modelica.Mechanics.Rotational.Sources;
model Accelerate
  "Forced movement of a flange according to an acceleration signal"
  extends
    Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;
  SI.Angle phi(
    start=0,
    fixed=true,
    stateSelect=StateSelect.prefer)
    "Rotation angle of flange with respect to support";
  SI.AngularVelocity w(
    start=0,
    fixed=true,
    stateSelect=StateSelect.prefer)
    "Angular velocity of flange with respect to support";
  SI.AngularAcceleration a
    "Angular acceleration of flange with respect to support";

  Modelica.Blocks.Interfaces.RealInput a_ref(unit="rad/s2")
    "Absolute angular acceleration of flange with respect to support as input signal"

equation
  phi = flange.phi - phi_support;
  w = der(phi);
  a = der(w);
  a = a_ref;
end Accelerate;


Constant speed, not dependent on torque. Model of fixed angular velocity of flange, not dependent on torque.

within Modelica.Mechanics.Rotational.Sources;
model ConstantSpeed "Constant speed, not dependent on torque"
  extends Modelica.Mechanics.Rotational.Interfaces.PartialTorque;
  SI.AngularVelocity w
    "Angular velocity of flange with respect to support (= der(phi))";
  parameter SI.AngularVelocity w_fixed "Fixed speed";
equation
  w = der(phi);
  w = w_fixed;
end ConstantSpeed;


Constant torque, not dependent on speed. Model of constant torque, not dependent on angular velocity of flange.

within Modelica.Mechanics.Rotational.Sources;
model ConstantTorque "Constant torque, not dependent on speed"
  extends Rotational.Interfaces.PartialTorque;
  parameter SI.Torque tau_constant
    "Constant torque (if negative, torque is acting as load in positive direction of rotation)";
  SI.AngularVelocity w
    "Angular velocity of flange with respect to support (= der(phi))";
  SI.Torque tau
    "Accelerating torque acting at flange (= -flange.tau)";
equation
  w = der(phi);
  tau = -flange.tau;
  tau = tau_constant;
end ConstantTorque;


Simple model of a rotational eddy current brake. This is a simple model of a rotational eddy current brake. The torque versus speed characteristic is defined by Kloss' equation.

within Modelica.Mechanics.Rotational.Sources;
model EddyCurrentTorque "Simple model of a rotational eddy current brake"
  import Modelica.Electrical.Machines.Thermal.linearTemperatureDependency;
  parameter Boolean useExcitationInput=false "Enable signal input for excitation";
  parameter Real constantExcitation=1 "Excitation=1 to reach maximum torque"
  parameter SI.Torque tau_nominal "Maximum torque (always braking)";
  parameter SI.AngularVelocity w_nominal(min=Modelica.Constants.eps)
    "Nominal speed (leads to maximum torque) at reference temperature";
  parameter SI.Temperature TRef(start=293.15)
    "Reference temperature";
  parameter
    Modelica.Electrical.Machines.Thermal.LinearTemperatureCoefficient20
    alpha20(start=0) "Temperature coefficient of material";
  extends Modelica.Mechanics.Rotational.Interfaces.PartialTorque;
  extends Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPort;
  SI.Torque tau "Accelerating torque acting at flange (= flange.tau)";
  SI.AngularVelocity w "Angular velocity of flange with respect to support (= der(phi))";
  Real w_normalized "Relative speed w/w_nominal";
  Blocks.Interfaces.RealInput excitation = excitationInternal if useExcitationInput
    "Excitation"
protected
  Real excitationInternal "Excitation";
equation
  if not useExcitationInput then
    excitationInternal = constantExcitation;
  end if;
  tau = flange.tau;
  w = der(phi);
  w_normalized = w/(w_nominal*linearTemperatureDependency(1, TRef, alpha20, TheatPort));
  tau = 2*tau_nominal*excitationInternal^2*w_normalized/(1 + w_normalized*w_normalized);
  lossPower = tau*w;
end EddyCurrentTorque;


Torque reciprocal dependent on speed. Model of inverse speed dependent torque.

within Modelica.Mechanics.Rotational.Sources;
model InverseSpeedDependentTorque
  "Torque reciprocal dependent on speed"
  extends Rotational.Interfaces.PartialTorque;
  import Modelica.Constants.pi;
  parameter SI.Torque tau_nominal
    "Nominal torque (if negative, torque is acting as load in positive direction of rotation)";
  parameter Boolean TorqueDirection=true
    "Same direction of torque in both directions of rotation";
  parameter SI.AngularVelocity w_nominal(min=Modelica.Constants.eps)
    "Nominal speed";
  parameter SI.AngularVelocity w0(final min=Modelica.Constants.eps, start=0.1)
    "Regularization below w0"
  SI.AngularVelocity w
    "Angular velocity of flange with respect to support (= der(phi))";
  SI.Torque tau
    "Accelerating torque acting at flange (= -flange.tau)";
equation
  w = der(phi);
  tau = -flange.tau;
  if TorqueDirection then
    tau = if abs(w)<w0 then tau_nominal*w_nominal/w0 else tau_nominal*w_nominal/abs(w);
  else
    tau = if abs(w)<w0 then tau_nominal*w/w0 else tau_nominal*w_nominal/w;
  end if;
end InverseSpeedDependentTorque;


Linear dependency of torque versus speed. Model of torque, linearly dependent on angular velocity of flange.<br>
Parameter TorqueDirection chooses whether direction of torque is the same in both directions of rotation or not.

within Modelica.Mechanics.Rotational.Sources;
model LinearSpeedDependentTorque "Linear dependency of torque versus speed"
  extends Modelica.Mechanics.Rotational.Interfaces.PartialTorque;
  parameter SI.Torque tau_nominal
    "Nominal torque (if negative, torque is acting as load in positive direction of rotation)";
  parameter Boolean TorqueDirection=true
    "Same direction of torque in both directions of rotation";
  parameter SI.AngularVelocity w_nominal(min=Modelica.Constants.eps)
    "Nominal speed";
  SI.AngularVelocity w
    "Angular velocity of flange with respect to support (= der(phi))";
  SI.Torque tau
    "Accelerating torque acting at flange (= -flange.tau)";
equation
  w = der(phi);
  tau = -flange.tau;
  if TorqueDirection then
    tau = tau_nominal*abs(w/w_nominal);
  else
    tau = tau_nominal*(w/w_nominal);
  end if;
end LinearSpeedDependentTorque;


Forced movement of a flange according to an angle, speed and angular acceleration signal. Flange flange is forced to move relative to flange support with a predefined motion
according to the input signals:

within Modelica.Mechanics.Rotational.Sources;
model Move
  "Forced movement of a flange according to an angle, speed and angular acceleration signal"
  extends
    Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;

  SI.Angle phi
    "Rotation angle of flange with respect to support";
  Modelica.Blocks.Interfaces.RealInput u[3]
    "Angle, angular velocity and angular acceleration of flange with respect to support as input signals"
protected
  function position
    extends Modelica.Icons.Function;
    input Real q_qd_qdd[3]
      "Required values for position, speed, acceleration";
    input Real dummy
      "Just to have one input signal that should be differentiated to avoid possible problems in the Modelica tool (is not used)";
    output Real q;
  algorithm
    q := q_qd_qdd[1];
  end position;

  function position_der
    extends Modelica.Icons.Function;
    input Real q_qd_qdd[3]
      "Required values for position, speed, acceleration";
    input Real dummy
      "Just to have one input signal that should be differentiated to avoid possible problems in the Modelica tool (is not used)";
    input Real dummy_der;
    output Real qd;
  algorithm
    qd := q_qd_qdd[2];
  end position_der;

  function position_der2
    extends Modelica.Icons.Function;
    input Real q_qd_qdd[3]
      "Required values for position, speed, acceleration";
    input Real dummy
      "Just to have one input signal that should be differentiated to avoid possible problems in the Modelica tool (is not used)";
    input Real dummy_der;
    input Real dummy_der2;
    output Real qdd;
  algorithm
    qdd := q_qd_qdd[3];
  end position_der2;
equation
  phi = flange.phi - phi_support;
  phi = position(u, time);
end Move;


within Modelica.Mechanics.Rotational;
package Sources "Sources to drive 1D rotational mechanical components"
  extends Modelica.Icons.SourcesPackage;
end Sources;


Forced movement of a flange according to a reference angle signal. The input signal phi_ref defines the reference
angle in [rad]. Flange flange is forced
to move according to this reference motion relative to flange support. According to parameter
exact (default = false), this is done in the following way:

within Modelica.Mechanics.Rotational.Sources;
model Position
  "Forced movement of a flange according to a reference angle signal"
  extends Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;
  parameter Boolean exact=false
    "Is true/false for exact treatment/filtering of the input signal, respectively"
  parameter SI.Frequency f_crit=50
    "If exact=false, critical frequency of filter to filter input signal"
  SI.Angle phi(stateSelect=if exact then StateSelect.default else StateSelect.prefer)
    "Rotation angle of flange with respect to support";
  SI.AngularVelocity w(start=0,
    stateSelect=if exact then StateSelect.default else StateSelect.prefer)
    "If exact=false, Angular velocity of flange with respect to support else dummy"
  SI.AngularAcceleration a(start=0)
    "If exact=false, Angular acceleration of flange with respect to support else dummy"
  Modelica.Blocks.Interfaces.RealInput phi_ref(
    final quantity="Angle",
    final unit="rad",
    displayUnit="deg")
    "Reference angle of flange with respect to support as input signal"

protected
  parameter SI.AngularFrequency w_crit=2*Modelica.Constants.pi*f_crit "Critical frequency";
  constant Real af=1.3617 "s coefficient of Bessel filter";
  constant Real bf=0.6180 "s*s coefficient of Bessel filter";
initial equation
  if not exact then
    phi = phi_ref;
  end if;
equation
  phi = flange.phi - phi_support;
  if exact then
    phi = phi_ref;
    w = 0;
    a = 0;
  else
    // Filter: a = phi_ref*s^2/(1 + (af/w_crit)*s + (bf/w_crit^2)*s^2)
    w = der(phi);
    a = der(w);
    a = ((phi_ref - phi)*w_crit - af*w)*(w_crit/bf);
  end if;
end Position;


Quadratic dependency of torque versus speed. Model of torque, quadratic dependent on angular velocity of flange.<br>
Parameter TorqueDirection chooses whether direction of torque is the same in both directions of rotation or not.

within Modelica.Mechanics.Rotational.Sources;
model QuadraticSpeedDependentTorque
  "Quadratic dependency of torque versus speed"
  extends Modelica.Mechanics.Rotational.Interfaces.PartialTorque;
  parameter SI.Torque tau_nominal
    "Nominal torque (if negative, torque is acting as load in positive direction of rotation)";
  parameter Boolean TorqueDirection=true
    "Same direction of torque in both directions of rotation";
  parameter SI.AngularVelocity w_nominal(min=Modelica.Constants.eps)
    "Nominal speed";
  SI.AngularVelocity w
    "Angular velocity of flange with respect to support (= der(phi))";
  SI.Torque tau
    "Accelerating torque acting at flange (= -flange.tau)";
equation
  w = der(phi);
  tau = -flange.tau;
  if TorqueDirection then
    tau = tau_nominal*(w/w_nominal)^2;
  else
    tau = tau_nominal*smooth(1, if w >= 0 then (w/w_nominal)^2 else -(w/w_nominal)^2);
  end if;
end QuadraticSpeedDependentTorque;


Constant torque changing sign with speed. Model of constant torque which changes sign with direction of rotation.

within Modelica.Mechanics.Rotational.Sources;
model SignTorque "Constant torque changing sign with speed"
  extends Rotational.Interfaces.PartialTorque;
  import Modelica.Constants.pi;
  parameter SI.Torque tau_nominal
    "Nominal torque (if negative, torque is acting as load)";
  parameter Modelica.Blocks.Types.Regularization reg=Modelica.Blocks.Types.Regularization.Exp
    "Type of regularization"
  parameter SI.AngularVelocity w0(final min=Modelica.Constants.eps, start=0.1)
    "Regularization below w0";
  SI.AngularVelocity w
    "Angular velocity of flange with respect to support (= der(phi))";
  SI.Torque tau
    "Accelerating torque acting at flange (= -flange.tau)";
equation
  w = der(phi);
  tau = -flange.tau;
  if reg==Modelica.Blocks.Types.Regularization.Exp then
    tau = tau_nominal*(2/(1 + Modelica.Math.exp(-w/(0.01*w0)))-1);
  elseif reg==Modelica.Blocks.Types.Regularization.Sine then
    tau = tau_nominal*smooth(1, (if abs(w)>=w0 then sign(w) else Modelica.Math.sin(pi/2*w/w0)));
  elseif reg==Modelica.Blocks.Types.Regularization.Linear then
    tau = tau_nominal*(if abs(w)>=w0 then sign(w) else (w/w0));
  else//if reg==Modelica.Blocks.Types.Regularization.CoSine
    tau = tau_nominal*(if abs(w)>=w0 then sign(w) else sign(w)*(1 - Modelica.Math.cos(pi/2*w/w0)));
  end if;
end SignTorque;


Forced movement of a flange according to a reference angular velocity signal. The input signal w_ref defines the reference
speed in [rad/s]. Flange flange is forced
to move relative to flange support according to this reference motion. According to parameter
exact (default = false), this is done in the following way:

within Modelica.Mechanics.Rotational.Sources;
model Speed
  "Forced movement of a flange according to a reference angular velocity signal"
  extends
    Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;
  parameter Boolean exact=false
    "Is true/false for exact treatment/filtering of the input signal, respectively"
  parameter SI.Frequency f_crit=50
    "If exact=false, critical frequency of filter to filter input signal"
  SI.Angle phi(
    start=0,
    fixed=true,
    stateSelect=StateSelect.prefer)
    "Rotation angle of flange with respect to support";
  SI.AngularVelocity w(stateSelect=if exact then StateSelect.default else
        StateSelect.prefer)
    "Angular velocity of flange with respect to support";
  SI.AngularAcceleration a
    "If exact=false, angular acceleration of flange with respect to support else dummy";
  Modelica.Blocks.Interfaces.RealInput w_ref(unit="rad/s")
    "Reference angular velocity of flange with respect to support as input signal"

protected
  parameter SI.AngularFrequency w_crit=2*Modelica.Constants.pi
      *f_crit "Critical frequency";
initial equation
  if not exact then
    w = w_ref;
  end if;
equation
  phi = flange.phi - phi_support;
  w = der(phi);
  if exact then
    w = w_ref;
    a = 0;
  else
    // Filter: a = w_ref/(1 + (1/w_crit)*s)
    a = der(w);
    a = (w_ref - w)*w_crit;
  end if;
end Speed;


Input signal acting as external torque on a flange. The input signal tau defines an external
torque in [Nm] which acts (with negative sign) at
a flange connector, i.e., the component connected to this
flange is driven by torque tau.

within Modelica.Mechanics.Rotational.Sources;
model Torque "Input signal acting as external torque on a flange"
  extends Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;
  Modelica.Blocks.Interfaces.RealInput tau(unit="N.m")
    "Accelerating torque acting at flange (= -flange.tau)"

equation
  flange.tau = -tau;
end Torque;


Input signal acting as torque on two flanges. The input signal tau defines an external
torque in [Nm] which acts at both flange connectors,
i.e., the components connected to these flanges are driven by torque tau.

within Modelica.Mechanics.Rotational.Sources;
model Torque2 "Input signal acting as torque on two flanges"
  extends Rotational.Interfaces.PartialTwoFlanges;

  Modelica.Blocks.Interfaces.RealInput tau(unit="N.m")
    "Torque driving the two flanges (a positive value accelerates the flange)"

equation
  flange_a.tau = tau;
  flange_b.tau = -tau;
end Torque2;


Constant torque, not dependent on speed. Model of a torque step at time startTime.
Positive torque accelerates in positive direction of flange rotation.

within Modelica.Mechanics.Rotational.Sources;
model TorqueStep "Constant torque, not dependent on speed"
  extends Modelica.Mechanics.Rotational.Interfaces.PartialTorque;
  parameter SI.Torque stepTorque(start=1)
    "Height of torque step (if negative, torque is acting as load)";
  parameter SI.Torque offsetTorque(start=0)
    "Offset of torque";
  parameter SI.Time startTime=0
    "Torque = offset for time < startTime";
  SI.Torque tau
    "Accelerating torque acting at flange (= -flange.tau)";

equation
  tau = -flange.tau;
  tau = offsetTorque + (if time < startTime then 0 else stepTorque);
end TorqueStep;


within Modelica.Mechanics;
package Translational "Library to model 1-dimensional, translational mechanical systems"
  extends Modelica.Icons.Package;
end Translational;


Brake based on Coulomb friction. This component models a brake, i.e., a component where a frictional
force is acting between the housing and a flange and a controlled normal
force presses the flange to the housing in order to increase friction.
The normal force fn has to be provided as input signal f_normalized in a normalized form
(0 ≤ f_normalized ≤ 1),
fn = fn_max*f_normalized, where fn_max has to be provided as parameter.
Friction in the brake is modelled in the following way:

within Modelica.Mechanics.Translational.Components;
model Brake "Brake based on Coulomb friction"
  extends Modelica.Mechanics.Translational.Interfaces.PartialElementaryTwoFlangesAndSupport2;
  extends Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT;

  import Modelica.Blocks.Types.{ExternalCombiTable1D, Extrapolation, Smoothness};
  import Modelica.Blocks.Tables.Internal.{getTable1DValue, getTable1DValueNoDer, getTable1DValueNoDer2};

  parameter Real mu_pos[:, 2]=[0, 0.5]
    "Positive sliding friction coefficient [-] as function of v [m/s] (v>=0)";
  parameter Smoothness smoothness = Smoothness.LinearSegments
    "Smoothness of interpolation in mu_pos table";
  parameter Real peak(final min=1) = 1
    "Peak for maximum value of mu at v==0 (mu0_max = peak*mu_pos[1,2])";
  parameter Real cgeo(final min=0) = 1
    "Geometry constant containing friction distribution assumption";
  parameter SI.Force fn_max(final min=0, start=1) "Maximum normal force";

  extends Translational.Interfaces.PartialFriction;

  SI.Position s "Absolute position of flange_a and of flange_b";
  SI.Force f "Brake friction force";
  SI.Velocity v "Absolute velocity of flange_a and flange_b";
  SI.Acceleration a "Absolute acceleration of flange_a and flange_b";

  Real mu "Friction coefficient";
  SI.Force fn "Normal force (=fn_max*f_normalized)";
  Modelica.Blocks.Interfaces.RealInput f_normalized
    "Normalized force signal 0..1 (normal force = fn_max*f_normalized; brake is active if > 0)"

protected
  final parameter ExternalCombiTable1D tableID = ExternalCombiTable1D(
    tableName="NoName",
    fileName="NoName",
    table=mu_pos,
    columns={2},
    smoothness=smoothness,
    extrapolation=Extrapolation.LastTwoPoints,
    verboseRead=false) "External table object for sliding friction coefficient";
  final parameter Real mu0=
    if     smoothness == Smoothness.ConstantSegments then getTable1DValueNoDer(tableID, 1, 0)
    elseif smoothness == Smoothness.LinearSegments   then getTable1DValueNoDer2(tableID, 1, 0)
    else                                                  getTable1DValue(tableID, 1, 0)
    "Friction coefficient for v=0 and forward sliding";

  Real table_signs[2]
    "Signs for sliding friction coefficient table interpolation: [sign for v, sign for mu]";

equation
  assert(size(mu_pos, 1) > 0 and size(mu_pos, 2) > 0, "Parameter mu_pos is an empty matrix");

  s = s_a;
  s = s_b;

  // Velocity and acceleration of flanges flange_a and flange_b
  v = der(s);
  a = der(v);
  v_relfric = v;
  a_relfric = a;

  // Friction force, normal force and friction force for v=0
  flange_a.f + flange_b.f - f = 0;
  fn = fn_max*f_normalized;
  f0 = mu0*cgeo*fn;
  f0_max = peak*f0;
  free = fn <= 0;

  // Friction force
  table_signs =
    if     startForward         then { 1, 1}
    elseif startBackward        then {-1,-1}
    elseif pre(mode) == Forward then { 1, 1}
    else                             {-1,-1};
  mu = table_signs[2]*(
    if     smoothness == Smoothness.ConstantSegments then getTable1DValueNoDer(tableID, 1, table_signs[1]*v)
    elseif smoothness == Smoothness.LinearSegments   then getTable1DValueNoDer2(tableID, 1, table_signs[1]*v)
    else                                                  getTable1DValue(tableID, 1, table_signs[1]*v));
  f = if locked then sa*unitForce else if free then 0 else mu*cgeo*fn;

  lossPower = f*v_relfric;
end Brake;


Linear 1D translational damper. Linear, velocity dependent damper element. It can be either connected
between a sliding mass and the housing (model Fixed), or
between two sliding masses.

within Modelica.Mechanics.Translational.Components;
model Damper "Linear 1D translational damper"
  extends Translational.Interfaces.PartialCompliantWithRelativeStates;
  parameter SI.TranslationalDampingConstant d(final min=0, start=0)
    "Damping constant";
  extends
    Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT;
equation
  f = d*v_rel;
  lossPower = f*v_rel;
end Damper;


1D translational spring damper combination with gap. This component models a spring damper combination that can lift off.
It can be connected between a sliding mass and the housing (model
Fixed),
to describe the contact of a sliding mass with the housing.

within Modelica.Mechanics.Translational.Components;
model ElastoGap "1D translational spring damper combination with gap"
  extends Modelica.Mechanics.Translational.Interfaces.PartialCompliantWithRelativeStates;
  parameter SI.TranslationalSpringConstant c(final min=0, start=1)
    "Spring constant";
  parameter SI.TranslationalDampingConstant d(final min=0, start=1)
    "Damping constant";
  parameter SI.Position s_rel0=0 "Unstretched spring length";
  parameter SI.Force f_ref(min=0) = c*s_ref "Reference spring force at s_ref"
  parameter SI.Length s_ref(min=Modelica.Constants.eps) = 1 "Reference relative compression at which f_c = f_ref"
  parameter Real n(final min=1) = 1
    "Exponent of spring force ( f_c = -f_ref*|(s_rel-s_rel0)/s_ref|^n )";
  extends Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT;

  /*
Please note that initialization might fail due to the nonlinear spring characteristic
(spring force is zero for s_rel > s_rel0)
if a positive force is acting on the element and no other force balances this force
(e.g., when setting both initial velocity and acceleration to 0)
*/
  Boolean contact "= true, if contact, otherwise no contact";
protected
  SI.Force f_c "Spring force";
  SI.Force f_d2 "Linear damping force";
  SI.Force f_d
    "Linear damping force which is limited by spring force (|f_d| <= |f_c|)";
  Real ratio "Scaling ratio of relative compression to s_ref";
equation
  // Modify contact force, so that it is only "pushing" and not
  // "pulling/sticking" and that it is continuous
  contact = s_rel < s_rel0;
  ratio = (s_rel - s_rel0)/s_ref;
  f_c = smooth(1, noEvent(if contact then -f_ref*abs(ratio)^n else 0));
  f_d2 = if contact then d*v_rel else 0;
  f_d = smooth(0, noEvent(if contact then min(max(f_d2, f_c), -f_c) else 0));
  f = f_c + f_d;
  lossPower = f_d*v_rel;         // linear contact damper force
   f_d  = if f_d2 <  f_c then  f_c else
          if f_d2 > -f_c then -f_c else f_d2;  // bounded damper force
   f    = f_c + f_d;            // contact force
end if;

Note, since |f_d| ≤ |f_c|, pulling forces cannot occur and the contact force
is always continuous, especially around the start of the penetration at s_rel = s_rel0.
On the contrary, this leads to the contact force f = 0 even if
contact = true is still indicated around the end of the penetration.
This is because contact indicates only the occurrence of geometry penetration.

In order to have consistent units for nonlinear springs, the term c*|s_rel|^n
is replaced by f_ref*|s_rel/s_ref|^n, whereby s_ref is a reference
length for the spring and f_ref is the spring force when
s_rel = s_ref. The default values s_ref = 1
and f_ref = c*s_ref lead to the same results of the two above-mentioned terms.
Setting the advanced parameters s_ref and f_ref for a nonlinear
spring directly gives a cleaner and straightforward parametrization.
For simplicity reasons, both s_ref and f_ref are considered being
positive.

In the next figure, a typical simulation with the ElastoGap model is shown
(Examples.ElastoGap)
where the different effects are visualized:

 Curve 1 (elastoGap1.f) is the unmodified contact force, i.e., the linear spring/damper
     characteristic. A pulling/sticking force is present at the end of the contact.

 Curve 2 (elastoGap2.f) is the contact force, where the force is explicitly set to
     zero when pulling/sticking occurs. The contact force is discontinuous when contact starts.

 Curve 3 (elastoGap3.f) is the ElastoGap model of this library. No discontinuity and no
     pulling/sticking occurs.

"),
    Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{
            100,100}}), graphics={Line(points={{-98,0},{-48,0}}, color={0,127,0}),
          Line(
              points={{-48,36},{-48,-38}},
              thickness=1,
          color={0,127,0}),                Line(
              points={{-12,-38},{-12,36}},
              thickness=1,
          color={0,127,0}),Line(points={{-12,-28},{70,-28},{70,24}}, color={0,127,0}),
                                          Line(points={{70,0},{98,0}},
                   color={0,127,0}),
          Line(points={{-12,24},{0,24},{6,34},{18,14},{30,34},{42,14},{54,34},{60,24},{70,24}}, color={0,127,0}),
          Rectangle(
              extent={{10,-6},{50,-50}},
              fillColor={192,192,192},
              fillPattern=FillPattern.Solid,
          lineColor={0,127,0}),              Line(points={{-52,-70},{28,-70}}, color={95,127,95}),
                                                                               Polygon(
          points={{58,-70},{28,-60},{28,-80},{58,-70}},
          lineColor={95,127,95},
          fillColor={95,127,95},
          fillPattern=FillPattern.Solid),    Text(
              extent={{-150,100},{150,60}},
              textString="%name",
              textColor={0,0,255}), Text(
              extent={{-150,-125},{150,-95}},
              textString="c=%c"),Text(
              extent={{-150,-160},{150,-130}},
              textString="d=%d"),
          Line(
              visible=useHeatPort,
              points={{-100,-100},{-100,-44},{22,-44},{22,-28}},
              color={191,0,0},
              pattern=LinePattern.Dot),
          Line(points={{0,-50},{50,-50},{50,-6},{0,-6}}, color={0,127,0})}));
end ElastoGap;


Fixed flange. The flange of a 1D translational mechanical system fixed
at an position s0 in the housing. May be used:

within Modelica.Mechanics.Translational.Components;
model Fixed "Fixed flange"
  parameter SI.Position s0=0 "Fixed offset position of housing";

  Interfaces.Flange_b flange
equation
  flange.s = s0;
end Fixed;


Signal adaptor for a Translational flange with position, speed, and acceleration as outputs and force as input (especially useful for FMUs). Adaptor between a flange connector and a signal representation of the flange.
This component is used to provide a pure signal interface around a Translational model
and export this model in form of an input/output block,
especially as FMU (Functional Mock-up Unit).
Examples of the usage of this adaptor are provided in
Translational.Examples.GenerationOfFMUs.
This adaptor has force as input and position, velocity and acceleration as output signals.

within Modelica.Mechanics.Translational.Components;
model GeneralForceToPositionAdaptor
  "Signal adaptor for a Translational flange with position, speed, and acceleration as outputs and force as input (especially useful for FMUs)"
  extends Modelica.Blocks.Interfaces.Adaptors.FlowToPotentialAdaptor(
    final Name_p="s",
    final Name_pder="v",
    final Name_pder2="a",
    final Name_f="f",
    final Name_fder="der(f)",
    final Name_fder2="der2(f)",
    final use_fder=false,
    final use_fder2=false,
    final p(unit="m"),
    final pder(unit="m/s"),
    final pder2(unit="m/s2"),
    final f(unit="N"),
    final fder(unit="N/s"),
    final fder2(unit="N/s2"));
  Modelica.Mechanics.Translational.Interfaces.Flange_a flange
equation
  y = flange.s "output = potential = position";
  u = flange.f "input = flow = force";
end GeneralForceToPositionAdaptor;


Signal adaptor for a Translational flange with force as output and position, speed and acceleration as input (especially useful for FMUs). Adaptor between a flange connector and a signal representation of the flange.
This component is used to provide a pure signal interface around a Translational model
and export this model in form of an input/output block,
especially as FMU (Functional Mock-up Unit).
Examples of the usage of this adaptor are provided in
Translational.Examples.GenerationOfFMUs.
This adaptor has position, velocity and acceleration as input signals and
force as output signal.

within Modelica.Mechanics.Translational.Components;
model GeneralPositionToForceAdaptor
  "Signal adaptor for a Translational flange with force as output and position, speed and acceleration as input (especially useful for FMUs)"
  extends Modelica.Blocks.Interfaces.Adaptors.PotentialToFlowAdaptor(
    final Name_p="s",
    final Name_pder="v",
    final Name_pder2="a",
    final Name_f="f",
    final Name_fder="der(f)",
    final Name_fder2="der2(f)",
    final use_fder=false,
    final use_fder2=false,
    final p(unit="m"),
    final pder(unit="m/s"),
    final pder2(unit="m/s2"),
    final f(unit="N"),
    final fder(unit="N/s"),
    final fder2(unit="N/s2"));
  Modelica.Mechanics.Translational.Interfaces.Flange_b flange
equation
  y = flange.f "output = flow = force";
  u = flange.s "input = potential = position";
end GeneralPositionToForceAdaptor;


Gearbox transforming rotational into translational motion. Couples rotational and translational motion, like a toothed wheel with a toothed rack, specifying the ratio of rotational / translational motion.

within Modelica.Mechanics.Translational.Components;
model IdealGearR2T
  "Gearbox transforming rotational into translational motion"
  extends Modelica.Mechanics.Rotational.Components.IdealGearR2T;
end IdealGearR2T;


Simple 1-dim. model of an ideal rolling wheel without inertia. Couples rotational and translational motion, like an ideal rolling wheel, specifying the wheel radius.

within Modelica.Mechanics.Translational.Components;
model IdealRollingWheel
  "Simple 1-dim. model of an ideal rolling wheel without inertia"
  extends Modelica.Mechanics.Rotational.Components.IdealRollingWheel;
end IdealRollingWheel;


Initializes a flange with pre-defined position, speed and acceleration (usually, this is reference data from a control bus). This component is used to optionally initialize the position, speed,
and/or acceleration of the flange to which this component
is connected. Via parameters use_s_start, use_v_start, use_a_start
the corresponding input signals s_start, v_start, a_start are conditionally
activated. If an input is activated, the corresponding flange property
is initialized with the input value at start time.

within Modelica.Mechanics.Translational.Components;
model InitializeFlange
  "Initializes a flange with pre-defined position, speed and acceleration (usually, this is reference data from a control bus)"
  extends Modelica.Blocks.Icons.Block;
  parameter Boolean use_s_start=true
    "= true, if initial position is defined by input s_start, otherwise not initialized";
  parameter Boolean use_v_start=true
    "= true, if initial speed is defined by input v_start, otherwise not initialized";
  parameter Boolean use_a_start=true
    "= true, if initial acceleration is defined by input a_start, otherwise not initialized";

  parameter StateSelect stateSelect=StateSelect.default
    "Priority to use flange angle and speed as states";

  Modelica.Blocks.Interfaces.RealInput s_start(unit="m") if use_s_start
    "Initial position of flange"
  Modelica.Blocks.Interfaces.RealInput v_start(unit="m/s") if use_v_start
    "Initial speed of flange"
  Modelica.Blocks.Interfaces.RealInput a_start(unit="m/s2") if use_a_start
    "Initial angular acceleration of flange"
  Interfaces.Flange_b flange "Flange that is initialized"

  SI.Position s_flange(stateSelect=stateSelect) = flange.s
    "Flange position";
  SI.Velocity v_flange(stateSelect=stateSelect) = der(
    s_flange) "= der(s_flange)";

protected
  encapsulated model Set_s_start "Set s_start"
    import Modelica;
    extends Modelica.Blocks.Icons.Block;
    Modelica.Blocks.Interfaces.RealInput s_start(unit="m") "Start position"

    Modelica.Mechanics.Translational.Interfaces.Flange_b flange
  initial equation
    flange.s = s_start;
  equation
    flange.f = 0;

  end Set_s_start;

  encapsulated model Set_v_start "Set v_start"
    import Modelica;
    extends Modelica.Blocks.Icons.Block;
    Modelica.Blocks.Interfaces.RealInput v_start(unit="m/s")
      "Start velocity"

    Modelica.Mechanics.Translational.Interfaces.Flange_b flange
  initial equation
    der(flange.s) = v_start;
  equation
    flange.f = 0;

  end Set_v_start;

  encapsulated model Set_a_start "Set a_start"
    import Modelica;
    extends Modelica.Blocks.Icons.Block;
    Modelica.Blocks.Interfaces.RealInput a_start(unit="m/s2")
      "Start acceleration"

    Modelica.Mechanics.Translational.Interfaces.Flange_b flange(s(
          stateSelect=StateSelect.avoid))
    Modelica.Units.SI.Velocity v=der(flange.s)
  initial equation
    der(v) = a_start;
  equation
    flange.f = 0;

  end Set_a_start;

  encapsulated model Set_flange_f "Set flange_f to zero"
    import Modelica;
    extends Modelica.Blocks.Icons.Block;
    Modelica.Mechanics.Translational.Interfaces.Flange_b flange
  equation
    flange.f = 0;
  end Set_flange_f;
protected
  Set_s_start set_s_start if use_s_start
  Set_v_start set_v_start if use_v_start
  Set_a_start set_a_start if use_a_start
  Set_flange_f set_flange_f
equation
  connect(set_s_start.flange, flange)
  connect(set_v_start.flange, flange)
  connect(set_a_start.flange, flange)
  connect(set_flange_f.flange, flange)
  connect(s_start, set_s_start.s_start)
  connect(v_start, set_v_start.v_start)
  connect(a_start, set_a_start.a_start)
end InitializeFlange;


Sliding mass with inertia. Sliding mass with inertia, without friction and two rigidly connected flanges.

within Modelica.Mechanics.Translational.Components;
model Mass "Sliding mass with inertia"
  parameter SI.Mass m(min=0, start=1) "Mass of the sliding mass";
  parameter StateSelect stateSelect=StateSelect.default
    "Priority to use s and v as states"
  extends Translational.Interfaces.PartialRigid(L=0,s(start=0, stateSelect=
          stateSelect));
  SI.Velocity v(start=0, stateSelect=stateSelect)
    "Absolute velocity of component";
  SI.Acceleration a(start=0) "Absolute acceleration of component";

equation
  v = der(s);
  a = der(v);
  m*a = flange_a.f + flange_b.f;
end Mass;


Sliding mass with hard stop and Stribeck friction. Basic model for Coulomb friction that models the stuck phase in a reliable way.<br>
Additionally, a left and right stop are handled.

within Modelica.Mechanics.Translational.Components;
model MassWithStopAndFriction
  "Sliding mass with hard stop and Stribeck friction"
  extends PartialFrictionWithStop;
  SI.Velocity v(start=0, stateSelect=StateSelect.always)
    "Absolute velocity of flange_a and flange_b";
  SI.Acceleration a(start=0)
    "Absolute acceleration of flange_a and flange_b";
  parameter SI.Mass m(start=1) "Mass";
  parameter Real F_prop(
    final unit="N.s/m",
    final min=0,
    start=1) "Velocity dependent friction";
  parameter SI.Force F_Coulomb(start=5)
    "Constant friction: Coulomb force";
  parameter SI.Force F_Stribeck(start=10) "Stribeck effect";
  parameter Real fexp(
    final unit="s/m",
    final min=0,
    start=2) "Exponential decay";
  extends Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT;
  Integer stopped
    "Mode of stop (-1: hard stop at flange_a, 0: no stop, +1: hard stop at flange_b";
  encapsulated partial model PartialFrictionWithStop
    "Base model of Coulomb friction elements with stop"

    import Modelica;
    import Modelica.Mechanics.Translational.Interfaces.PartialRigid;
    parameter Modelica.Units.SI.Position smax(start=25)
      "Right stop for (right end of) sliding mass";
    parameter Modelica.Units.SI.Position smin(start=-25)
      "Left stop for (left end of) sliding mass";
    parameter Modelica.Units.SI.Velocity v_small=1e-3
      "Relative velocity near to zero (see model info text)"
    // Equations to define the following variables have to be defined in subclasses
    Modelica.Units.SI.Velocity v_relfric "Relative velocity between frictional surfaces";
    Modelica.Units.SI.Acceleration a_relfric
      "Relative acceleration between frictional surfaces";
    Modelica.Units.SI.Force f
      "Friction force (positive, if directed in opposite direction of v_rel)";
    Modelica.Units.SI.Force f0 "Friction force for v=0 and forward sliding";
    Modelica.Units.SI.Force f0_max "Maximum friction force for v=0 and locked";
    Boolean free "= true, if frictional element is not active";
    // Equations to define the following variables are given in this class
    Real sa(unit="1")
      "Path parameter of friction characteristic f = f(a_relfric)";
    Boolean startForward(start=false, fixed=true)
      "= true, if v_rel=0 and start of forward sliding or v_rel > v_small";
    Boolean startBackward(start=false, fixed=true)
      "= true, if v_rel=0 and start of backward sliding or v_rel < -v_small";
    Boolean locked(start=false) "= true, if v_rel=0 and not sliding";
    extends PartialRigid(s(start=0, stateSelect=StateSelect.always));
    constant Integer Unknown=3 "Value of mode is not known";
    constant Integer Free=2 "Element is not active";
    constant Integer Forward=1 "v_rel > 0 (forward sliding)";
    constant Integer Stuck=0
      "v_rel = 0 (forward sliding, locked or backward sliding)";
    constant Integer Backward=-1 "v_rel < 0 (backward sliding)";
    Integer mode(
      final min=Backward,
      final max=Unknown,
      start=Unknown,
      fixed=true)
      "Mode of friction (-1: backward sliding, 0: stuck, 1: forward sliding, 2: inactive, 3: unknown)";
  protected
    constant Modelica.Units.SI.Acceleration unitAcceleration=1
    constant Modelica.Units.SI.Force unitForce=1
  equation
    /* Friction characteristic
   (locked is introduced to help the Modelica translator determining
   the different structural configurations,
   if for each configuration special code shall be generated)
*/
    startForward = pre(mode) == Stuck and (sa > f0_max/unitForce and s < (
      smax - L/2) or pre(startForward) and sa > f0/unitForce and s < (smax
       - L/2)) or pre(mode) == Backward and v_relfric > v_small or initial()
       and (v_relfric > 0);
    startBackward = pre(mode) == Stuck and (sa < -f0_max/unitForce and s >
      (smin + L/2) or pre(startBackward) and sa < -f0/unitForce and s > (
      smin + L/2)) or pre(mode) == Forward and v_relfric < -v_small or
      initial() and (v_relfric < 0);
    locked = not free and not (pre(mode) == Forward or startForward or pre(
      mode) == Backward or startBackward);

    a_relfric/unitAcceleration = if locked then 0 else if free then sa
       else if startForward then sa - f0_max/unitForce else if
      startBackward then sa + f0_max/unitForce else if pre(mode) == Forward
       then sa - f0_max/unitForce else sa + f0_max/unitForce;

    /* Friction force "f" has to be defined in a subclass. Example for possible
     realization of friction utilizing interpolation by ExternalCombiTable1D see:
     Modelica.Mechanics.Translational.Components.SupportFriction
*/

    // finite state machine to determine configuration
    mode = if free then Free else (if (pre(mode) == Forward or pre(mode)
       == Free or startForward) and v_relfric > 0 and s < (smax - L/2)
       then Forward else if (pre(mode) == Backward or pre(mode) == Free or
      startBackward) and v_relfric < 0 and s > (smin + L/2) then Backward
       else Stuck);
  end PartialFrictionWithStop;
equation
  // Constant auxiliary variables
  f0 = (F_Coulomb + F_Stribeck);
  f0_max = f0*1.001;
  free = f0 <= 0 and F_prop <= 0 and s > smin + L/2 and s < smax - L/2;
  // Velocity and acceleration of flanges
  v = der(s);
  a = der(v);
  v_relfric = v;
  a_relfric = a;
  // Equilibrium of forces
  0 = flange_a.f + flange_b.f - f - m*der(v);
  // Friction force
  f = if locked then sa*unitForce else if free then 0 else (if startForward
     then F_prop*v + F_Coulomb + F_Stribeck else if startBackward then
    F_prop*v - F_Coulomb - F_Stribeck else if pre(mode) == Forward then
    F_prop*v + F_Coulomb + F_Stribeck*Modelica.Math.exp(-fexp*abs(v)) else F_prop*v -
    F_Coulomb - F_Stribeck*Modelica.Math.exp(-fexp*abs(v)));
  lossPower = f*v_relfric;
  when (initial()) then
    assert(s > smin + L/2 or s >= smin + L/2 and v >= 0,
      "Error in initialization of hard stop. (s - L/2) must be >= smin\n"
       + "(s=" + String(s) + ", L=" + String(L) + ", smin=" + String(smin)
       + ")");
    assert(s < smax - L/2 or s <= smax - L/2 and v <= 0,
      "Error in initialization of hard stop. (s + L/2) must be <= smax\n"
       + "(s=" + String(s) + ", L=" + String(L) + ", smax=" + String(smax)
       + ")");
  end when;

  // Define events for hard stops and reinitialize the state variables velocity v and position s
  stopped = if s <= smin + L/2 then -1 else if s >= smax - L/2 then +1
     else 0;
  when stopped <> 0 then
    reinit(s, if stopped < 0 then smin + L/2 else smax - L/2);
    reinit(v, 0);
  end when;
  /*
Version 1:

  when not (s < smax - L/2) then
    reinit(s, smax - L/2);
    if (not initial() or v>0) then
      reinit(v, 0);
    end if;
  end when;

  when not (s > smin + L/2) then
    reinit(s, smin + L/2);
    if (not initial() or v<0) then
      reinit(v, 0);
    end if;
  end when;

Version 2:
        stopped := if s <= smin + L/2 then -1 else if s >= smax - L/2 then +1 else 0;
      when (initial()) then
        assert(s > smin + L/2 or s >= smin + L/2 and v >= 0,
          "Error in initialization of hard stop. (s - L/2) must be >= smin\n"+
          "(s=" + String(s) + ", L=" + String(L) + ", smin=" + String(smin) + ")");
        assert(s < smax - L/2 or s <= smax - L/2 and v <= 0,
          "Error in initialization of hard stop. (s + L/2) must be <= smax\n"+
          "(s=" + String(s) + ", L=" + String(L) + ", smax=" + String(smax) + ")");
      end when;
      when stopped <> 0 then
        reinit(s, if stopped < 0 then smin + L/2 else smax - L/2);
        if (not initial() or stopped*v>0) then
           reinit(v, 0);
        end if;
      end when;
*/
end MassWithStopAndFriction;


within Modelica.Mechanics.Translational;
package Components "Components for 1D translational mechanical drive trains"
  extends Modelica.Icons.Package;
end Components;


Definition of relative state variables. Usually, the absolute position and the absolute velocity of
Modelica.Mechanics.Translational.Inertia models are used as state variables.
In some circumstances, relative quantities are better suited, e.g.,
because it may be easier to supply initial values.
In such cases, model RelativeStates allows the definition of state variables
in the following way:

within Modelica.Mechanics.Translational.Components;
model RelativeStates "Definition of relative state variables"
  extends Translational.Interfaces.PartialTwoFlanges;
  parameter StateSelect stateSelect=StateSelect.prefer
    "Priority to use the relative angle and relative speed as states";
  SI.Position s_rel(start=0, stateSelect=StateSelect.prefer)
    "Relative position used as state variable";
  SI.Velocity v_rel(start=0, stateSelect=StateSelect.prefer)
    "Relative velocity used as state variable";
  SI.Acceleration a_rel(start=0) "Relative angular acceleration";

equation
  s_rel = flange_b.s - flange_a.s;
  v_rel = der(s_rel);
  a_rel = der(v_rel);
  flange_a.f = 0;
  flange_b.f = 0;
end RelativeStates;


Rod without inertia. A translational rod without inertia and two rigidly connected flanges.

within Modelica.Mechanics.Translational.Components;
model Rod "Rod without inertia"
  extends Translational.Interfaces.PartialRigid;

equation
  0 = flange_a.f + flange_b.f;
end Rod;


Resistance of a rolling wheel. Simplified model of the resistance of a rolling wheel,
dependent on vertical wheel load (due to gravity, i.e. static only),
inclination and rolling resistance coefficient:

within Modelica.Mechanics.Translational.Components;
model RollingResistance "Resistance of a rolling wheel"
  extends Modelica.Mechanics.Translational.Interfaces.PartialForce;
  import Modelica.Constants.pi;
  parameter SI.Force fWeight(start=0) "Wheel load due to gravity";
  parameter Boolean useCrInput=false "Enable signal input for Cr";
  parameter Real CrConstant=0.01 "Constant rolling resistance coefficient"
  parameter Boolean useInclinationInput=false "Enable signal input for inclination";
  parameter Real inclinationConstant=0 "Constant inclination = tan(angle)"
  parameter Modelica.Blocks.Types.Regularization reg=Modelica.Blocks.Types.Regularization.Exp
    "Type of regularization"
  parameter SI.Velocity v0(final min=Modelica.Constants.eps)=0.1
    "Regularization below v0";
  SI.Velocity v
    "Velocity of flange with respect to support (= der(s))";
  SI.Force f_nominal "Nominal rolling resistance without regularization";
  Blocks.Interfaces.RealInput inclination = inclination_internal if useInclinationInput
    "Inclination=tan(angle)"
  Blocks.Interfaces.RealInput cr = Cr_internal if useCrInput
    "Rolling resistance coefficient"
protected
  Real Cr_internal "Rolling resistance coefficient";
  Real inclination_internal "Inclination";
equation
  if not useCrInput then
    Cr_internal = CrConstant;
  end if;
  if not useInclinationInput then
    inclination_internal = inclinationConstant;
  end if;
  v = der(s);
  f_nominal = -Cr_internal*fWeight*cos(atan(inclination_internal));
  if reg==Modelica.Blocks.Types.Regularization.Exp then
    f = -f_nominal*(2/(1 + Modelica.Math.exp(-v/(0.01*v0)))-1);
  elseif reg==Modelica.Blocks.Types.Regularization.Sine then
    f = -f_nominal*smooth(1, (if abs(v)>=v0 then sign(v) else Modelica.Math.sin(pi/2*v/v0)));
  elseif reg==Modelica.Blocks.Types.Regularization.Linear then
    f = -f_nominal*(if abs(v)>=v0 then sign(v) else (v/v0));
  else//if reg==Modelica.Blocks.Types.Regularization.CoSine
    f = -f_nominal*(if abs(v)>=v0 then sign(v) else sign(v)*(1 - Modelica.Math.cos(pi/2*v/v0)));
  end if;
end RollingResistance;


Linear 1D translational spring. A linear 1D translational spring. The component can be connected either
between two sliding masses, or between
a sliding mass and the housing (model Fixed), to describe
a coupling of the sliding mass with the housing via a spring.

within Modelica.Mechanics.Translational.Components;
model Spring "Linear 1D translational spring"
  extends Translational.Interfaces.PartialCompliant;
  parameter SI.TranslationalSpringConstant c(final min=0, start=1)
    "Spring constant";
  parameter SI.Distance s_rel0=0 "Unstretched spring length";

equation
  f = c*(s_rel - s_rel0);
end Spring;


Linear 1D translational spring and damper in parallel. A spring and damper element connected in parallel.
The component can be
connected either between two sliding masses to describe the elasticity
and damping, or between a sliding mass and the housing (model Fixed),
to describe a coupling of the sliding mass with the housing via a spring/damper.

within Modelica.Mechanics.Translational.Components;
model SpringDamper "Linear 1D translational spring and damper in parallel"
  extends Translational.Interfaces.PartialCompliantWithRelativeStates;
  parameter SI.TranslationalSpringConstant c(final min=0, start=1)
    "Spring constant";
  parameter SI.TranslationalDampingConstant d(final min=0, start=1)
    "Damping constant";
  parameter SI.Position s_rel0=0 "Unstretched spring length";
  extends Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT;
protected
  SI.Force f_c "Spring force";
  SI.Force f_d "Damping force";
equation
  f_c = c*(s_rel - s_rel0);
  f_d = d*v_rel;
  f = f_c + f_d;
  lossPower = f_d*v_rel;
end SpringDamper;


Coulomb friction in support. This element describes Coulomb friction in support,
i.e., a frictional force acting between a flange and the housing.
The positive sliding friction force \"f\" has to be defined
by table \"f_pos\" as function of the absolute velocity \"v\".
E.g.

within Modelica.Mechanics.Translational.Components;
model SupportFriction "Coulomb friction in support"
  extends Modelica.Mechanics.Translational.Interfaces.PartialElementaryTwoFlangesAndSupport2;
  extends Modelica.Thermal.HeatTransfer.Interfaces.PartialElementaryConditionalHeatPortWithoutT;

  import Modelica.Blocks.Types.{ExternalCombiTable1D, Extrapolation, Smoothness};
  import Modelica.Blocks.Tables.Internal.{getTable1DValue, getTable1DValueNoDer, getTable1DValueNoDer2};

  parameter Real f_pos[:, 2]=[0, 1]
    "Positive sliding friction characteristic [N] as function of v [m/s] (v>=0)";
  parameter Smoothness smoothness = Smoothness.LinearSegments
    "Smoothness of interpolation in f_pos table";
  parameter Real peak(final min=1) = 1
    "Peak for maximum friction force at v==0 (f0_max = peak*f_pos[1,2])";

  extends Translational.Interfaces.PartialFriction;

  SI.Position s "= flange_a.s - support.s";
  SI.Force f "Friction force";
  SI.Velocity v "Absolute velocity of flange_a and flange_b";
  SI.Acceleration a "Absolute acceleration of flange_a and flange_b";

protected
  final parameter ExternalCombiTable1D tableID = ExternalCombiTable1D(
    tableName="NoName",
    fileName="NoName",
    table=f_pos,
    columns={2},
    smoothness=smoothness,
    extrapolation=Extrapolation.LastTwoPoints,
    verboseRead=false) "External table object for sliding friction coefficient";

  Real table_signs[2]
    "Signs for sliding friction coefficient table interpolation: [sign for v, sign for f]";

equation
  assert(size(f_pos, 1) > 0 and size(f_pos, 2) > 0, "Parameter f_pos is an empty matrix");

  // Constant auxiliary variables
  f0 =
    if     smoothness == Smoothness.ConstantSegments then getTable1DValueNoDer(tableID, 1, 0)
    elseif smoothness == Smoothness.LinearSegments   then getTable1DValueNoDer2(tableID, 1, 0)
    else                                                  getTable1DValue(tableID, 1, 0);
  f0_max = peak*f0;
  free = false;

  s = flange_a.s - s_support;
  flange_a.s = flange_b.s;

  // Velocity and acceleration of flanges
  v = der(s);
  a = der(v);
  v_relfric = v;
  a_relfric = a;

  // Force balance
  flange_a.f + flange_b.f - f = 0;

  // Friction force
  table_signs =
    if     startForward         then { 1, 1}
    elseif startBackward        then {-1,-1}
    elseif pre(mode) == Forward then { 1, 1}
    else                             {-1,-1};
  f = if locked then sa*unitForce else table_signs[2]*(
    if     smoothness == Smoothness.ConstantSegments then getTable1DValueNoDer(tableID, 1, table_signs[1]*v)
    elseif smoothness == Smoothness.LinearSegments   then getTable1DValueNoDer2(tableID, 1, table_signs[1]*v)
    else                                                  getTable1DValue(tableID, 1, table_signs[1]*v));

  lossPower = f*v_relfric;
end SupportFriction;


Simple vehicle model. This is a simple model of a ground vehicle, comprising the mass, the aerodynamic drag, the rolling resistance and
the inclination resistance (caused by the road grade).
For all particular resistances, significant variables can be either given by a parameter or input by a time-variable signal.

within Modelica.Mechanics.Translational.Components;
model Vehicle "Simple vehicle model"
  parameter SI.Mass m "Total mass of vehicle";
  parameter SI.Acceleration g=Modelica.Constants.g_n "Constant gravity acceleration";
  parameter SI.Inertia J "Total rotational inertia of drive train";
  parameter SI.Length R "Wheel radius";
  parameter SI.Area A(start=1) "Cross section of vehicle"
  parameter Real Cd(start=0.5) "Drag resistance coefficient"
  parameter SI.Density rho=1.2 "Density of air"
  parameter Boolean useWindInput=false "Enable signal input for wind velocity"
  parameter SI.Velocity vWindConstant=0 "Constant wind velocity"
  parameter Boolean useCrInput=false "Enable signal input for Cr"
  parameter Real CrConstant=0.015 "Constant rolling resistance coefficient"
  parameter SI.Velocity vReg=1e-3 "Velocity for regularization around 0"
  parameter Boolean useInclinationInput=false "Enable signal input for inclination"
  parameter Real inclinationConstant=0 "Constant inclination = tan(angle)"
  SI.Position s(displayUnit="km", start=0)=mass.s "Position of vehicle";
  SI.Velocity v(displayUnit="km/h", start=0)=mass.v "Velocity of vehicle";
  SI.Acceleration a=mass.a "Acceleration of vehicle";
protected
  constant SI.Velocity vRef=1 "Reference velocity for air drag";
public
  Sources.QuadraticSpeedDependentForce fDrag(
    final useSupport=true,
    final f_nominal=-Cd*A*rho*vRef^2/2,
    final ForceDirection=false,
    final v_nominal=vRef) "Drag resistance"
  RollingResistance fRoll(
    final fWeight=m*g,
    final useCrInput=useCrInput,
    final CrConstant=CrConstant,
    final useInclinationInput=useInclinationInput,
    final inclinationConstant=inclinationConstant,
    final reg=Modelica.Blocks.Types.Regularization.Linear,
    final v0=vReg) "Rolling resistance"
  Sources.Force fGrav "Inclination resistance"
  Modelica.Mechanics.Translational.Interfaces.Flange_b flangeT "Translational flange"
  Modelica.Mechanics.Rotational.Interfaces.Flange_a flangeR "Rotational flange"
  Rotational.Components.Inertia inertia(final J=J)
  IdealRollingWheel idealRollingWheel(final radius=R)
  Mass mass(final m=m)
  Modelica.Blocks.Interfaces.RealInput inclination if useInclinationInput
    "Inclination=tan(angle)"
  Modelica.Blocks.Interfaces.RealInput cr if useCrInput
    "Rolling resistance coefficient"
  Modelica.Blocks.Interfaces.RealInput vWind(unit="m/s") if useWindInput
    "Wind velocity"
  Sources.Speed windSpeed(s(fixed=true))
  Blocks.Math.Gain gravForceGain(final k=-m*g)
protected
  Modelica.Blocks.Sources.Constant constInclination(k=inclinationConstant) if not useInclinationInput
  Modelica.Blocks.Sources.Constant constWindSpeed(k=vWindConstant) if not useWindInput
public
  Blocks.Math.Atan atan
  Blocks.Math.Sin sin

equation
  connect(idealRollingWheel.flangeT, mass.flange_a)
  connect(constWindSpeed.y, windSpeed.v_ref)
  connect(vWind, windSpeed.v_ref)
  connect(fDrag.support, windSpeed.flange)
  connect(mass.flange_b, flangeT)
  connect(sin.u, atan.y)
  connect(gravForceGain.u, sin.y)
  connect(gravForceGain.y, fGrav.f)
  connect(mass.flange_b, fDrag.flange)
  connect(mass.flange_b, fRoll.flange)
  connect(mass.flange_b, fGrav.flange)
  connect(inertia.flange_b, idealRollingWheel.flangeR)
  connect(flangeR, inertia.flange_a)
  connect(cr,fRoll.cr)
  connect(inclination, fRoll.inclination)
  connect(inclination, atan.u)
  connect(atan.u, constInclination.y)
end Vehicle;


Use of model accelerate. Demonstrate usage of component
Sources.Accelerate
by moving a mass with a predefined acceleration.

within Modelica.Mechanics.Translational.Examples;
model Accelerate "Use of model accelerate"

  extends Modelica.Icons.Example;
  Translational.Sources.Accelerate accelerate
  Translational.Components.Mass mass(L=1, m=1)
  Modelica.Blocks.Sources.Constant constantAcc(k=1)
equation
  connect(accelerate.flange, mass.flange_a)
  connect(constantAcc.y, accelerate.a_ref)
end Accelerate;


Demonstrate braking of a translational moving mass. This model consists of a mass with an initial velocity of 1 m/s.
After 0.1 s, a brake is activated and it is shown that the mass decelerates until
it arrives at rest and remains at rest. Two versions of this system are present,
one where the brake is implicitly grounded and one where it is grounded explicitly.

within Modelica.Mechanics.Translational.Examples;
model Brake "Demonstrate braking of a translational moving mass"
  extends Modelica.Icons.Example;

  Modelica.Mechanics.Translational.Components.Brake brake(fn_max=1,
      useSupport=false)
  Modelica.Mechanics.Translational.Components.Mass mass1(
    m=1,
    s(fixed=true),
    v(start=1, fixed=true))
  Modelica.Blocks.Sources.Step step(startTime=0.1, height=2)
  Modelica.Mechanics.Translational.Components.Brake brake1(fn_max=1,
      useSupport=true)
  Modelica.Mechanics.Translational.Components.Mass mass2(
    m=1,
    s(fixed=true),
    v(start=1, fixed=true))
  Modelica.Mechanics.Translational.Components.Fixed fixed
equation
  connect(mass1.flange_b, brake.flange_a)
  connect(step.y, brake.f_normalized)
  connect(mass2.flange_b, brake1.flange_a)
  connect(step.y, brake1.f_normalized)
  connect(fixed.flange, brake1.support)
end Brake;


Compare different braking forces. Compare the effect of different braking forces on mass' velocity
(massN.v, N = {1, 2, 3, 4}):

within Modelica.Mechanics.Translational.Examples;
model CompareBrakingForce "Compare different braking forces"
  extends Modelica.Icons.Example;
  parameter SI.Mass m=1 "Mass";
  parameter SI.Velocity v_start=100 "Initial speed of mass";
  parameter SI.Force f_nominal=100 "Nominal force";
  parameter SI.Velocity v_nominal=abs(v_start) "Nominal speed";
  parameter SI.Velocity v0=1 "Speed limit for regularization";
  Modelica.Mechanics.Translational.Components.Mass mass1(
    m=m,
    s(fixed=true, start=0),
    v(fixed=true, start=v_start))
  Modelica.Mechanics.Translational.Sources.SignForce signForce(
    f_nominal=-f_nominal,
    reg=Modelica.Blocks.Types.Regularization.Linear,
    v0=v0)
  Modelica.Mechanics.Translational.Components.Mass mass2(
    m=m,
    s(fixed=true, start=0),
    v(fixed=true, start=v_start))
  Modelica.Mechanics.Translational.Sources.LinearSpeedDependentForce
    linearSpeedDependentForce(
    f_nominal=-f_nominal,
    ForceDirection=false,
    v_nominal=v_nominal)
  Modelica.Mechanics.Translational.Components.Mass mass3(
    m=m,
    s(fixed=true, start=0),
    v(fixed=true, start=v_start))
  Modelica.Mechanics.Translational.Sources.QuadraticSpeedDependentForce
    quadraticSpeedDependentForce(
    f_nominal=-f_nominal,
    ForceDirection=false,
    v_nominal=v_nominal)
  Modelica.Mechanics.Translational.Components.Mass mass4(
    m=m,
    s(fixed=true, start=0),
    v(fixed=true, start=v_start))
  Modelica.Mechanics.Translational.Sources.InverseSpeedDependentForce
    inverseSpeedDependentForce(
    f_nominal=-f_nominal,
    ForceDirection=false,
    v_nominal=v_nominal,
    v0=v0)
equation
  connect(signForce.flange, mass1.flange_a)
  connect(linearSpeedDependentForce.flange, mass2.flange_a)
  connect(quadraticSpeedDependentForce.flange, mass3.flange_a)
  connect(inverseSpeedDependentForce.flange, mass4.flange_a)
end CompareBrakingForce;


Use of damper models. Demonstrate usage of a translational damper component in various configurations.

within Modelica.Mechanics.Translational.Examples;
model Damper "Use of damper models"

  extends Modelica.Icons.Example;

  Translational.Components.Mass mass1(
    L=1,
    s(start=3, fixed=true),
    v(start=10, fixed=true),
    m=1)
  Translational.Components.Damper damper1(d=25)
  Translational.Components.Fixed fixed1(s0=4.5)
  Translational.Components.Mass mass2(
    L=1,
    s(start=3, fixed=true),
    v(start=10, fixed=true),
    m=1)
  Translational.Components.Damper damper2(d=25)
  Translational.Components.Fixed fixed2(s0=4.5)
  Translational.Components.Mass mass3(
    L=1,
    s(start=3, fixed=true),
    v(start=10, fixed=true),
    m=1)
  Translational.Components.Fixed fixed3(s0=4.5)
  Translational.Components.Spring spring2(s_rel0=1, c=1)
  Translational.Components.SpringDamper springDamper3(
    s_rel0=1,
    d=25,
    c=1)
equation
  connect(mass1.flange_b, damper1.flange_a)
  connect(mass2.flange_b, damper2.flange_a)
  connect(damper2.flange_b, spring2.flange_b)
  connect(damper2.flange_a, spring2.flange_a)
  connect(mass3.flange_b, springDamper3.flange_a)
  connect(damper1.flange_b, fixed1.flange)
  connect(damper2.flange_b, fixed2.flange)
  connect(springDamper3.flange_b, fixed3.flange)
end Damper;


Demonstrate the usage of the translational eddy current brake.

within Modelica.Mechanics.Translational.Examples;
model EddyCurrentBrake "Demonstrate the usage of the translational eddy current brake"
  extends Modelica.Icons.Example;
  Modelica.Mechanics.Translational.Sources.EddyCurrentForce
    eddyCurrentForce(
    useExcitationInput=true,
    f_nominal=100,
    v_nominal=10,
    useHeatPort=true,
    TRef=293.15,
    alpha20(displayUnit="1/K") = Modelica.Electrical.Machines.Thermal.Constants.alpha20Copper)
  Modelica.Mechanics.Translational.Components.Mass mass(
    m=1,
    s(fixed=true, start=0),
    v(fixed=true, start=20))
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heatCapacitor(C=1, T(
        fixed=true))
  Blocks.Sources.Ramp ramp(
    height=1,
    duration=0.1,
    offset=0,
    startTime=0.1)
equation
  connect(eddyCurrentForce.flange, mass.flange_a)
  connect(eddyCurrentForce.heatPort, heatCapacitor.port)
  connect(ramp.y, eddyCurrentForce.excitation)
end EddyCurrentBrake;


Demonstrate usage of ElastoGap. This model demonstrates the effect of ElastoGaps on eigenfrequency:
Plot mass1.s and mass2.s as well as mass1.v and mass2.v to see that effect.

within Modelica.Mechanics.Translational.Examples;
model ElastoGap "Demonstrate usage of ElastoGap"
  extends Modelica.Icons.Example;
  Components.Fixed fixed
  Components.Rod rod1(L=2)
  Components.Rod rod2(L=2)
  Components.SpringDamper springDamper1(
    c=10,
    s_rel0=1,
    s_rel(fixed=false, start=1),
    d=1.5)
  Components.SpringDamper springDamper2(
    c=10,
    s_rel0=1,
    s_rel(fixed=false, start=1),
    d=1.5)
  Components.Mass mass1(
    s(fixed=true, start=2),
    L=0,
    m=1,
    v(fixed=true))
  Components.ElastoGap elastoGap1(
    c=10,
    s_rel(fixed=false, start=1.5),
    s_rel0=1.5,
    d=1.5)
  Components.ElastoGap elastoGap2(
    c=10,
    s_rel(fixed=false, start=1.5),
    s_rel0=1.5,
    d=1.5)
  Components.Mass mass2(
    s(fixed=true, start=2),
    L=0,
    m=1,
    v(fixed=true))
  parameter SI.TranslationalDampingConstant d=1.5 "Damping constant";
equation

  connect(rod1.flange_b, fixed.flange)
  connect(fixed.flange, rod2.flange_a)
  connect(springDamper1.flange_a, rod1.flange_a)
  connect(springDamper2.flange_b, rod2.flange_b)
  connect(springDamper1.flange_b, mass1.flange_a)
  connect(mass1.flange_b, springDamper2.flange_a)
  connect(rod1.flange_a, elastoGap1.flange_a)
  connect(rod2.flange_b, elastoGap2.flange_b)
  connect(elastoGap1.flange_b, mass2.flange_a)
  connect(mass2.flange_b, elastoGap2.flange_a)
end ElastoGap;


Use of model Stop.

within Modelica.Mechanics.Translational.Examples;
model Friction "Use of model Stop"
  extends Modelica.Icons.Example;
  Modelica.Mechanics.Translational.Components.MassWithStopAndFriction stop1(
    L=1,
    s(fixed=true),
    v(fixed=true),
    smax=25,
    smin=-25,
    m=1,
    F_prop=1,
    F_Coulomb=5,
    F_Stribeck=10,
    fexp=2)
  Translational.Sources.Force force
  Modelica.Blocks.Sources.Sine sineForce(amplitude=25, f=0.25)
  Modelica.Mechanics.Translational.Components.MassWithStopAndFriction stop2(
    L=1,
    smax=0.9,
    smin=-0.9,
    F_Coulomb=3,
    F_Stribeck=5,
    s(start=0, fixed=true),
    m=1,
    F_prop=1,
    fexp=2,
    v(start=-5, fixed=true))
  Translational.Components.Spring spring(s_rel0=1, c=500)
  Translational.Components.Fixed fixed2(s0=-1.75)
  Translational.Sources.Force force2
  Components.Mass mass(
    m=1,
    L=1,
    s(fixed=true),
    v(fixed=true))
  Components.SupportFriction supportFriction(f_pos=Examples.Utilities.GenerateStribeckFrictionTable(
            F_prop=1,
            F_Coulomb=5,
            F_Stribeck=10,
            fexp=2,
            v_max=12,
            nTable=50))
equation
  connect(spring.flange_b, stop2.flange_a)
  connect(sineForce.y, force.f)
  connect(spring.flange_a, fixed2.flange)
  connect(force.flange, stop1.flange_a)
  connect(force2.flange, mass.flange_a)
  connect(mass.flange_b, supportFriction.flange_a)
  connect(sineForce.y, force2.f)
end Friction;


Example to demonstrate variants to generate FMUs (Functional Mock-up Units). This example demonstrates how to generate an input/output block (e.g. in form of an
FMU - Functional Mock-up Unit) from various Translational components.
The goal is to export such an input/output block from Modelica and import
it in another modeling environment. The essential issue is that before
exporting it must be known in which way the component is utilized in the
target environment. Depending on the target usage, different flange variables
need to be in the interface with either input or output causality.
Note, this example model can be used to test the FMU export/import of a Modelica tool.
Just export the components marked in the icons as \"toFMU\" as FMUs and import
them back. The models should then still work and give the same results as a
pure Modelica model.

within Modelica.Mechanics.Translational.Examples;
model GenerationOfFMUs
  "Example to demonstrate variants to generate FMUs (Functional Mock-up Units)"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine sine1(f=2, amplitude=10)
  Modelica.Mechanics.Translational.Examples.Utilities.DirectMass directMass(
      m=1.1)
  Modelica.Mechanics.Translational.Examples.Utilities.InverseMass
    inverseMass(m=2.2)
  Modelica.Mechanics.Translational.Examples.Utilities.SpringDamper
    springDamper(c=1e4, d=100)
  Modelica.Mechanics.Translational.Components.Mass mass2a(
    m=1.1,
    s(fixed=true, start=0),
    v(fixed=true, start=0))
  Modelica.Mechanics.Translational.Sources.Force force2
  Modelica.Mechanics.Translational.Components.GeneralForceToPositionAdaptor forceToPosition2a(use_pder2=false)
  Modelica.Mechanics.Translational.Components.Mass mass2b(
    m=2.2,
    s(fixed=true, start=0),
    v(fixed=true, start=0))
  Modelica.Mechanics.Translational.Components.GeneralForceToPositionAdaptor forceToPosition2b(use_pder2=false)
  Modelica.Mechanics.Translational.Examples.Utilities.Spring spring(c=1e4)
  Modelica.Mechanics.Translational.Components.Mass mass3a(
    m=1.1,
    s(fixed=true, start=0),
    v(fixed=true, start=0))
  Modelica.Mechanics.Translational.Sources.Force force3
  Modelica.Mechanics.Translational.Components.GeneralForceToPositionAdaptor forceToPosition3a(use_pder=false, use_pder2=false)
  Modelica.Mechanics.Translational.Components.Mass mass3b(
    m=2.2,
    s(fixed=true, start=0),
    v(fixed=true, start=0))
  Modelica.Mechanics.Translational.Components.GeneralForceToPositionAdaptor forceToPosition3b(use_pder=false, use_pder2=false)
equation
  connect(sine1.y, directMass.fDrive)
  connect(directMass.s, inverseMass.s)
  connect(directMass.v,inverseMass.v)
  connect(directMass.a, inverseMass.a)
  connect(inverseMass.f, directMass.f)
  connect(force2.flange, mass2a.flange_a)
  connect(mass2a.flange_b, forceToPosition2a.flange)
  connect(forceToPosition2b.flange, mass2b.flange_a)
  connect(force3.flange, mass3a.flange_a)
  connect(mass3a.flange_b, forceToPosition3a.flange)
  connect(forceToPosition3b.flange, mass3b.flange_a)
  connect(forceToPosition2a.f, springDamper.f1)
  connect(springDamper.f2, forceToPosition2b.f)
  connect(forceToPosition3a.f, spring.f1)
  connect(spring.f2, forceToPosition3b.f)
  connect(forceToPosition3a.p, spring.s1)
  connect(spring.s2, forceToPosition3b.p)
  connect(forceToPosition2a.p, springDamper.s1)
  connect(forceToPosition2a.pder, springDamper.v1)
  connect(springDamper.s2, forceToPosition2b.p)
  connect(forceToPosition2b.pder, springDamper.v2)
  connect(sine1.y, force2.f)
  connect(sine1.y, force3.f)
end GenerationOfFMUs;


Demonstrate the modeling of heat losses. This model demonstrates how to model the dissipated power of a Translational model,
by enabling the heatPort of all components and connecting these heatPorts via
a convection element to the environment. The total heat flow generated by the
elements and transported to the environment
is present in variable convection.fluid.

within Modelica.Mechanics.Translational.Examples;
model HeatLosses "Demonstrate the modeling of heat losses"
  extends Modelica.Icons.Example;
  Components.Mass mass1(
    m=1,
    s(fixed=true),
    L=0.1,
    v(fixed=true))
  Components.SpringDamper springDamper(
    s_rel(fixed=true),
    v_rel(fixed=true),
    c=100,
    d=10,
    useHeatPort=true)
  Components.Damper damper(d=10, useHeatPort=true)
  Components.ElastoGap elastoGap(
    c=100,
    d=20,
    s_rel0=-0.02,
    useHeatPort=true)
  Components.Fixed fixed1
  Sources.Force force
  Blocks.Sources.Sine sine1(f=1, amplitude=20)
  Components.Mass mass2(
    m=1,
    L=0.1,
    s(fixed=false),
    v(fixed=false))
  Components.SupportFriction supportFriction(useHeatPort=true)
  Components.Spring spring(c=100, s_rel(fixed=true))
  Components.Mass mass3(
    m=1,
    L=0.1,
    s(fixed=false),
    v(fixed=true))
  Components.Brake brake(fn_max=10, useHeatPort=true)
  Blocks.Sources.Sine sine2(amplitude=10, f=2)
  Components.MassWithStopAndFriction massWithStopAndFriction(
    L=0.1,
    m=1,
    F_prop=0.5,
    F_Coulomb=1,
    F_Stribeck=2,
    fexp=2,
    smin=0,
    smax=0.4,
    v(fixed=true),
    useHeatPort=true)
  Thermal.HeatTransfer.Components.Convection convection
  Blocks.Sources.Constant const(k=20)
  Thermal.HeatTransfer.Celsius.FixedTemperature TAmbient(T=25)
    "Ambient temperature"
  Components.Fixed fixed2
  Components.SpringDamper springDamper1(
    c=10000,
    d=1000,
    useHeatPort=true,
    s_rel(fixed=true))
equation

  connect(mass1.flange_b, springDamper.flange_a)
  connect(sine1.y, force.f)
  connect(force.flange, mass1.flange_a)
  connect(mass1.flange_a, damper.flange_a)
  connect(damper.flange_b, fixed1.flange)
  connect(springDamper.flange_b, mass2.flange_a)
  connect(mass2.flange_b, supportFriction.flange_a)
  connect(supportFriction.flange_b, spring.flange_a)
  connect(spring.flange_b, mass3.flange_a)
  connect(mass3.flange_b, brake.flange_a)
  connect(sine2.y, brake.f_normalized)
  connect(elastoGap.flange_b, mass1.flange_a)
  connect(const.y, convection.Gc)
  connect(TAmbient.port, convection.fluid)
  connect(elastoGap.flange_a, fixed2.flange)
  connect(elastoGap.heatPort, convection.solid)
  connect(damper.heatPort, convection.solid)
  connect(springDamper.heatPort, convection.solid)
  connect(supportFriction.heatPort, convection.solid)
  connect(brake.heatPort, convection.solid)
  connect(massWithStopAndFriction.heatPort, convection.solid)
  connect(brake.flange_b, springDamper1.flange_a)
  connect(springDamper1.flange_b, massWithStopAndFriction.flange_a)
  connect(springDamper1.heatPort, convection.solid)
end HeatLosses;


Setting of initial conditions. There are several ways to set initial conditions.
In the first system the position of the mass m3 was defined
by using the modifier s(start=4.5), the position of m4 by s(start=12.5).
These positions were chosen such that the system is at rest. To calculate
these values start at the left (fixed2) with a value of 1 m. The spring s2
has an unstretched length of 2 m and m3 an length of 3 m, which leads to

within Modelica.Mechanics.Translational.Examples;
model InitialConditions "Setting of initial conditions"

  extends Modelica.Icons.Example;

  Translational.Components.Fixed fixed2(s0=1)
  Translational.Components.Spring s2(s_rel0=2, c=1e3)
  Translational.Components.Mass m3(
    L=3,
    s(start=4.5, fixed=true),
    v(fixed=true),
    m=1)
  Translational.Components.SpringDamper sd2(
    s_rel0=4,
    c=111,
    d=1)
  Translational.Components.Mass m4(
    L=5,
    s(start=12.5, fixed=true),
    v(fixed=true),
    m=1)

  Translational.Components.Fixed fixed1(s0=-1)
  Translational.Components.Spring s1(
    s_rel0=1,
    c=1e3,
    s_rel(start=0.5, fixed=true))
  Translational.Components.Mass m1(
    L=1,
    v(fixed=true),
    m=1)
  Translational.Components.SpringDamper sd1(
    s_rel0=1,
    c=111,
    s_rel(start=1, fixed=true),
    v_rel(fixed=true),
    d=1)
  Translational.Components.Mass m2(L=2, m=1)
equation
  connect(s2.flange_a, fixed2.flange)
  connect(s1.flange_a, fixed1.flange)
  connect(m1.flange_a, s1.flange_b)
  connect(sd1.flange_a, m1.flange_b)
  connect(m2.flange_a, sd1.flange_b)
  connect(m4.flange_a, sd2.flange_b)
  connect(sd2.flange_a, m3.flange_b)
  connect(m3.flange_a, s2.flange_b)
end InitialConditions;