Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Issue faced while running model made from a Personal Libary

Issue faced while running model made from a Personal Libary

Hello
I am in the process of creating a new library and am stuck somewhere. I have created a library called FourBarLinkage for performing simple positional, velocity and acceleration analysis. While performing a simple positional analysis(with the 4 bar system being massless and at rest), I am facing a sight difficulty. I connect the components and simulate the model and it gives me the results. But the values of the angle it calculates seem random and are not within the standard values(0 to 2pi) . The values of the angles calculated vary from -100 rad to +200 rad. I am confused as to why this is happening and as a result I am not able to feed in and calculate the resultant angular velocities(as the angles calculated vary largely).

Please find the Library and the model code below.

Thanks
Pratyush

===================================================================================================================================
package FourBarLinkage
  import SI = Modelica.SIunits;
  package Connectors
    connector RevoluteA
      SI.Position Coordinate[2];
      flow SI.Force Reaction[2];
      annotation(Icon(graphics = {Ellipse(rotation = 0, lineColor = {0,0,255}, fillColor = {100,100,100}, pattern = LinePattern.Solid, fillPattern = FillPattern.Solid, lineThickness = 0.25, extent = {{-70,70},{70,-70}})}));
    end RevoluteA;
    connector RevoluteB
      SI.Position Coordinate[2];
      flow SI.Force Reaction[2];
      annotation(Icon(graphics = {Ellipse(rotation = 0, lineColor = {0,0,255}, fillColor = {200,200,200}, pattern = LinePattern.Solid, fillPattern = FillPattern.Solid, lineThickness = 0.25, extent = {{-70,70},{70,-70}})}));
    end RevoluteB;
    partial model BarEnds
      annotation(Diagram(), Icon());
      RevoluteB b annotation(Placement(visible = true, transformation(origin = {100,0}, extent = {{-12,-12},{12,12}}, rotation = 0), iconTransformation(origin = {100,0}, extent = {{-12,-12},{12,12}}, rotation = 0)));
      RevoluteA a annotation(Placement(visible = true, transformation(origin = {-100,0}, extent = {{-12,-12},{12,12}}, rotation = 0), iconTransformation(origin = {-100,0}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    end BarEnds;
  end Connectors;
  package Components
    model Bar
      extends FourBarLinkage.Connectors.BarEnds;
      parameter SI.Length l(min = 0) "Length of the Bar";
      SI.Angle theta "Angle with the +ve X axis";
      annotation(Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-82.6185,17.1558},{83.5214,-18.5102}}),Text(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-77.6524,-29.7968},{75.8465,-55.079}}, textString = "l=%l"),Text(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-57.3363,61.851},{53.7246,17.6072}}, textString = "%name")}));
    equation
      b.Coordinate[1] = a.Coordinate[1] + l * cos(theta);
      b.Coordinate[2] = a.Coordinate[2] + l * sin(theta);
      b.Reaction[1] = 0;
      b.Reaction[2] = 0;
    end Bar;
    model Ground
      extends FourBarLinkage.Connectors.BarEnds;
      parameter SI.Length l(min = 0) "Length of the Ground";
      annotation(Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-86.2302,24.8307},{87.1332,-28.4424}}),Text(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-75.395,27.5395},{74.0406,-17.1558}}, textString = "Ground")}));
    equation
      a.Coordinate[1] = 0;
      a.Coordinate[2] = 0;
      b.Coordinate[1] = l;
      b.Coordinate[2] = 0;
      a.Reaction[1] = 0;
      a.Reaction[2] = 0;
    end Ground;
  end Components;
end FourBarLinkage;

====================================================================================================================================

model Test
  FourBarLinkage.Components.Ground ground1(l = 0.4) annotation(Placement(visible = true, transformation(origin = {-7.67494,-23.4763}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  FourBarLinkage.Components.Bar bar1(l = 0.2) annotation(Placement(visible = true, transformation(origin = {-35.6659,20.7675}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  FourBarLinkage.Components.Bar bar2(l = 0.4) annotation(Placement(visible = true, transformation(origin = {23.4763,48.307}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  FourBarLinkage.Components.Bar bar3(l = 0.5) annotation(Placement(visible = true, transformation(origin = {47.8555,6.77201}, extent = {{-12,-12},{12,12}}, rotation = 0)));
equation
  connect(bar3.b,ground1.b) annotation(Line(points = {{59.8555,6.77201},{74.7938,6.77201},{74.7938,-23.1015},{4.32506,-23.1015},{4.32506,-23.4763}}));
  connect(bar2.b,bar3.a) annotation(Line(points = {{35.4763,48.307},{43.9157,48.307},{43.9157,19.2131},{26.9898,19.2131},{26.9898,7.09055},{35.8555,7.09055},{35.8555,6.77201}}));
  connect(bar1.b,bar2.a) annotation(Line(points = {{-23.6659,20.7675},{0,20.7675},{0,48.307},{11.4763,48.307},{11.4763,48.307}}));
  connect(ground1.a,bar1.a) annotation(Line(points = {{-19.6749,-23.4763},{-62.754,-23.4763},{-62.754,20.7675},{-47.6659,20.7675},{-47.6659,20.7675}}));
  bar1.theta = 1.00;
end Test;

Edited by: Pratyush - Feb-27-13 19:51:21

Re: Issue faced while running model made from a Personal Libary

I looked at the system (use +simCodeTarget=Dump or +d=dumpindxdae), and found one non-linear block of equations:
Nonlinear System (index 25)
Solves for variables (2 variables, 0 equations): bar3.theta, bar2.theta

So I assumed these were the variables you were having problem with. They are solved implicitly, which means a non-linear solver doesn't know that you expect values in the range 0..2pi.

Code:

bar2.b.Coordinate[1] = bar1.b.Coordinate[1] + bar2.l * cos(bar2.theta)

bar2.b.Coordinate[2] = bar1.b.Coordinate[2] + bar2.l * sin(bar2.theta)
0.0 = ground1.l + (-bar3.l) * cos(bar3.theta) - bar2.b.Coordinate[1]
0.0 = bar2.b.Coordinate[2] + bar3.l * sin(bar3.theta)

In fact, there are very many values that solve the system (and yes, 4 equations for 2 variables solved is weird, but it's a torn non-linear system).

There are ways in which you could get the value you want.

Try (in model Bar):

Code:

      SI.Angle theta(min = 0, max = 2*Modelica.Constants.pi) "Angle with the +ve X axis"; 

And use a non-linear solver that accepts boundary conditions:

Code:

loadModel(Modelica);getErrorString();

loadFile("a.mo");
simulate(Test,simflags="-nls=kinsol");
plot(bar3.theta);

Re: Issue faced while running model made from a Personal Libary

Hello

I tried to use the non linear solver as you mentioned and changed the value of theta in the bar model to get the desired values. Thank You very much for that!
Further I wanted to know how to use the non linear solver ("-nls=kinsol") in OMEdit ? I am able to do so in OMShell but not OMEdit. I click the Simulate button and go to the simulation flags window but do not know what to do next. I am using OMEdit Version 1.9.0 connected to r14576.

Also in OMShell I tried to introduce the concept of angular velocity as der(theta). I try to simulate it giving the initial velocity of the crank but it gives a simulation error -

stdout            | warning | kinsol failed [error_code=-2]. see last warning. use [-lv LOG_NLS] for more output.

Is there any thing I am missing ? I am attaching the code below.

The following is the library.

Code:



package FourBarLinkage
  import SI = Modelica.SIunits;
  package Connectors
    connector RevoluteA
      SI.Position Coordinate[2];
      flow SI.Force Reaction[2];
      annotation(Icon(graphics = {Ellipse(rotation = 0, lineColor = {0,0,255}, fillColor = {100,100,100}, pattern = LinePattern.Solid, fillPattern = FillPattern.Solid, lineThickness = 0.25, extent = {{-70,70},{70,-70}})}));
    end RevoluteA;
    connector RevoluteB
      SI.Position Coordinate[2];
      flow SI.Force Reaction[2];
      annotation(Icon(graphics = {Ellipse(rotation = 0, lineColor = {0,0,255}, fillColor = {200,200,200}, pattern = LinePattern.Solid, fillPattern = FillPattern.Solid, lineThickness = 0.25, extent = {{-70,70},{70,-70}})}));
    end RevoluteB;
    partial model BarEnds
      annotation(Diagram(), Icon());
      RevoluteB b annotation(Placement(visible = true, transformation(origin = {100,0}, extent = {{-12,-12},{12,12}}, rotation = 0), iconTransformation(origin = {100,0}, extent = {{-12,-12},{12,12}}, rotation = 0)));
      RevoluteA a annotation(Placement(visible = true, transformation(origin = {-100,0}, extent = {{-12,-12},{12,12}}, rotation = 0), iconTransformation(origin = {-100,0}, extent = {{-12,-12},{12,12}}, rotation = 0)));
    end BarEnds;
  end Connectors;
  package Components
    model Ground
      extends FourBarLinkage.Connectors.BarEnds;
      parameter SI.Length l(min = 0) "Length of the Ground";
      annotation(Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-86.2302,24.8307},{87.1332,-28.4424}}),Text(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-75.395,27.5395},{74.0406,-17.1558}}, textString = "Ground")}));
    equation
      a.Coordinate[1] = 0;
      a.Coordinate[2] = 0;
      b.Coordinate[1] = l;
      b.Coordinate[2] = 0;
      a.Reaction[1] = 0;
      a.Reaction[2] = 0;
    end Ground;
    model Bar
      extends FourBarLinkage.Connectors.BarEnds;
      parameter SI.Length l(min = 0) "Length of the Bar";
      SI.Angle theta(start = 0, min = -Modelica.Constants.pi, max = Modelica.Constants.pi) "Angle with the +ve X axis";
      SI.AngularVelocity omega "Angular Velocity";
      annotation(Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-82.6185,17.1558},{83.5214,-18.5102}}),Text(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-77.6524,-29.7968},{75.8465,-55.079}}, textString = "l=%l"),Text(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,255}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-57.3363,61.851},{53.7246,17.6072}}, textString = "%name")}));
    equation
      omega = der(theta);
      b.Coordinate[1] = a.Coordinate[1] + l * cos(theta);
      b.Coordinate[2] = a.Coordinate[2] + l * sin(theta);
      b.Reaction[1] = 0;
      b.Reaction[2] = 0;
    end Bar;
  end Components;
end FourBarLinkage;

\

The following is the Model and the Simulation command

Code:


model Test1
  FourBarLinkage.Components.Bar bar1(l = 0.2, theta(start = 1)) annotation(Placement(visible = true, transformation(origin = {-46.4925,16.5062}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  FourBarLinkage.Components.Bar bar3(l = 0.5) annotation(Placement(visible = true, transformation(origin = {22.2834,14.3054}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  FourBarLinkage.Components.Ground ground1(l = 0.4) annotation(Placement(visible = true, transformation(origin = {-14.8556,-9.90371}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  FourBarLinkage.Components.Bar bar2(l = 0.4) annotation(Placement(visible = true, transformation(origin = {-9.90375,54.7456}, extent = {{-12,-12},{12,12}}, rotation = 0)));
equation
  connect(bar1.b,bar2.a) annotation(Line(points = {{-34.4925,16.5062},{-29.1609,16.5062},{-29.1609,54.7456},{-21.9038,54.7456}}));
  connect(bar2.b,bar3.a) annotation(Line(points = {{2.09625,54.7456},{10.4539,54.7456},{10.4539,14.3054},{10.2834,14.3054}}));
  connect(ground1.a,bar1.a) annotation(Line(points = {{-26.8556,-9.90371},{-58.8721,-9.90371},{-58.8721,16.5062},{-58.4925,16.5062}}));
  connect(bar3.b,ground1.b) annotation(Line(points = {{34.2834,14.3054},{45.392,14.3054},{45.392,-9.90371},{-2.85555,-9.90371},{-2.85555,-9.90371}}));
  bar1.theta = 1.0;
  //bar1.omega = 1.0;
end Test1;


simulate(Test1,startTime=0,stopTime=1,simflags="-nls=kinsol")


The error it gives as mentioned above

stdout            | warning | kinsol failed [error_code=-2]. see last warning. use [-lv LOG_NLS] for more output.

Thanks
Pratyush

There are 0 guests and 0 other users also viewing this topic
You are here: