VariableSpring

model VariableSpring "1D rotational spring with variable stiffness"
    input Modelica.Blocks.Interfaces.RealInput c(unit = "N/rad") "Variable spring constant"
        annotation (Placement(
            visible = true,
            transformation(
                origin = {0, 80},
                extent = {
                    {-20, -20}, 
                    {20, 20}},
                rotation = -90),
            iconTransformation(
                origin = {0, 80},
                extent = {
                    {-20, -20}, 
                    {20, 20}},
                rotation = -90)));

    extends Modelica.Mechanics.Rotational.Interfaces.PartialCompliant;

    parameter SI.Angle phi_rel0 = 0 "Unstretched spring angle";
equation
    tau = c * (phi_rel - phi_rel0);

    annotation (
        Documentation(info = "<html>\n                <p>\n                    A <strong>linear 1D rotational spring</strong>. The component can be connected either\n                    between two inertias/gears to describe the shaft elasticity, or between\n                    a inertia/gear and the housing (component Fixed), to describe\n                    a coupling of the element with the housing via a spring.\n                </p></html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(points = {
                    {-100, 0}, 
                    {-58, 0}, 
                    {-43, -30}, 
                    {-13, 30}, 
                    {17, -30}, 
                    {47, 30}, 
                    {62, 0}, 
                    {100, 0}}), 
                Line(
                    points = {
                        {0, -60}, 
                        {0, 60}},
                    rotation = -30), 
                Polygon(
                    origin = {30, 52},
                    rotation = -30,
                    fillPattern = FillPattern.Solid,
                    points = {
                        {0, 0}, 
                        {-5, -20}, 
                        {5, -20}, 
                        {0, 0}})}),
        Diagram(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {-68, 0}, 
                        {-68, 65}},
                    color = {128, 128, 128}), 
                Line(
                    points = {
                        {72, 0}, 
                        {72, 65}},
                    color = {128, 128, 128}), 
                Line(
                    points = {
                        {-68, 60}, 
                        {72, 60}},
                    color = {128, 128, 128}), 
                Polygon(
                    points = {
                        {62, 63}, 
                        {72, 60}, 
                        {62, 57}, 
                        {62, 63}},
                    lineColor = {128, 128, 128},
                    fillColor = {128, 128, 128},
                    fillPattern = FillPattern.Solid), 
                Text(
                    extent = {
                        {-22, 62}, 
                        {18, 87}},
                    lineColor = {0, 0, 255},
                    textString = "phi_rel"), 
                Line(
                    points = {
                        {-96, 0}, 
                        {-60, 0}, 
                        {-42, -32}, 
                        {-12, 30}, 
                        {18, -30}, 
                        {48, 28}, 
                        {62, 0}, 
                        {96, 0}},
                    color = {0, 0, 255})}));
end VariableSpring;