Search code examples
modelicaopenmodelica

How can I integrate a QuadraticSpeedDependentForce Component on OpenModelica?


I'm working on a Modelica model where I'm using the Modelica.Mechanics.Translational.Sources.QuadraticSpeedDependentForce component to model forces. The force magnitude (f_nominal) is calculated based on a coefficient C, a parameter A, and a reference speed vRef.

Modelica.Mechanics.Translational.Sources.QuadraticSpeedDependentForce force(
    final useSupport=true,
    final f_nominal= C * A,
    final ForceDirection=false,
    final v_nominal=vRef)
    annotation (Placement(visible=true, transformation(origin={-62, 56}, extent={{50, -40}, {70, -20}}, rotation=0)));

C, A and vRef are presented as:

Real C(unit="kN/m2");
parameter Modelica.Units.SI.Area A(start = 1);
constant Modelica.Units.SI.Velocity vRef = 1 "Reference velocity"; 

I have an integer input signal inSignal that is used to update a coefficient C dynamically based on a matrix C_matrix. Here's how I'm updating C:

indicator = inSignal + 1;
C = C_matrix[indicator, 2];

indicator and C_matrix are presented as:

Integer indicator "C matrix position indicator";
parameter Real C[2, 2] = {{1,0},{2,0.5}]

When I simulate the code I get: Component f_nominal of variability parameter has binding 'C * A[<fDrag, fDrag>]' of higher variability continuous.

I have as reference the vehicle component Modelica.Mechanics.Translational.Components.Vehicle of Modelica's library.

I'd appreciate any help on how to ensure the proper integration of the component. Thanks in advance! :)


Solution

  • You problem is, that you try to compute a parameter (be definition constant for the time of a simulation) from a variable. Namely, you try to compute the parameter f_nominal from the variable C. This is why you get the error message basically saying C has a higher variability than f_nominal.

    For more explanation on variability, read https://mbe.modelica.university/behavior/equations/variables/.

    There are some potential solutions to the issue you are having. I think the feasible ones are pointed out here: Define Model Parameter as Variable. At first sight, it seems that replacing the parameter f_nominal with an input seems to be the most simple solution. The result of this would be:

    model QuadraticSpeedDependentForceInput "Quadratic dependency of force versus speed with 'f_nominal' as input"
      extends Modelica.Mechanics.Translational.Interfaces.PartialForce;
    
      parameter Boolean ForceDirection=true
        "Same direction of force in both directions of motion";
      parameter Modelica.Units.SI.Velocity v_nominal(min=Modelica.Constants.eps) "Nominal speed";
    
      Modelica.Units.SI.Velocity v "Velocity of flange with respect to support (= der(s))";
    
      Modelica.Blocks.Interfaces.RealInput f_nominal "Nominal force (if negative, force is acting as load in positive direction of motion)"
        annotation (Placement(transformation(extent={{-140,-20},{-100,20}}), iconTransformation(extent={{-140,-20},{-100,20}})));
    
    equation 
      v = der(s);
      if ForceDirection then
        f = -f_nominal*(v/v_nominal)^2;
      else
        f = -f_nominal*smooth(1, if v >= 0 then (v/v_nominal)^2 else -(v/v_nominal)^2);
      end if;
      annotation (
        Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,
                -100},{100,100}}), graphics={
              Line(points={{-60,50},{-60,-40}}, color={192,192,192}),
              Line(points={{-75,-30},{75,-30}}, color={192,192,192}),
            Line(
              points={{-60,-30},{-40,-28},{-20,-22},{0,-10},{20,6},{40,26},{58,52}},
              color={0,0,127},
              smooth=Smooth.Bezier)}),     Documentation(info="<html>
    <p>An modified version of 
    <a href=\"Modelica.Mechanics.Translational.Sources.QuadraticSpeedDependentForce\">Modelica.Mechanics.Translational.Sources.QuadraticSpeedDependentForce</a> 
    with <code>f_nominal</code> as input instead of a parameter.</p>
    </html>"),
        uses(Modelica(version="4.0.0")));
    end QuadraticSpeedDependentForceInput;