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
  • Index
  • » Users
  • » Pratyush
  • » Profile

Posts

Posts

Jun-20-13 07:30:11
No clue how to use CombiTable1Ds

I too am experiencing something similar.
Anyone have any Idea about this ?

Thanks
Pratyush

Yup, I got it !
Thanks a lot !!

Pratyush

Hello

I'm creating a custom library in OMEdit 1.9.0 and I want to have a component wherein I can enter all my parameters which will be used throughout other components i.e The parameters would be globally accessible. I also want to avoid the usage of connectors as it would make the final model very messy and would require a lot of connections.
I am currently trying to use the extends command which seems to work fine but it also inherits the Icon profile of the component and overrides it over the icons of the other components. Is there any way I can avoid this ? Also is there a better way of having globally accessible variables which can be entered in through a component ?

I unfortunately cannot attach the original code but I have made a small similar example of the same. Hope it explains the problem well enough.

Thank You
Pratyush

This is Package which has all the components -

Code:


package Package

  model a
  annotation(Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,0}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-100,50},{100,-50}})}));
  parameter Real x(start = 4);
  parameter Real x1(start = 41);
  end a;

  model b
  annotation(Icon(graphics = {Rectangle(rotation = 0, lineColor = {0,0,255}, fillColor = {0,0,0}, pattern = LinePattern.Solid, fillPattern = FillPattern.None, lineThickness = 0.25, extent = {{-50,100},{50,-100}})}));
  parameter Real p(start = 15);
  Real q;
  Real r;
  extends Package.a;
  equation
    q = x * x1;
    r = q * p;
  end b;
 
end Package;

This is the model which contains the components from the Package

Code:



model Test
  Package.a a1 annotation(Placement(visible = true, transformation(origin = {-20,60}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  Package.b b1 annotation(Placement(visible = true, transformation(origin = {-20,15}, extent = {{-12,-12},{12,12}}, rotation = 0)));
  annotation(experiment(StartTime = 0.0, StopTime = 4, Tolerance = 0.000001));
end Test;

Hello

I'm running a model for which I have built a custom library. I want to improve the post-processing in the model by plotting some key values as soon as the model completes simulation. The current way of plotting works just fine but I would like to know if there is a way to use the plot() and the plotParametric() command within the program itself so that the plots appear right in front of me as soon as the simulation is done. This will enable me to save time in trying to locate the variables on the Plot Variables command window.

I am using the OpenModelica Connection Editor Version 1.9.0 - Connected to OpenModelica 1.9.0 Beta2(r14576)

Any help is this regard is very much appreciated.

Thank You

Pratyush

Hello

I am noticing a problem with the If-statement while writing my program. I eventually managed to correct it by using the sign function.

The problem observed is the value of variable 'a' when the variable 'fraction' becomes 1.

Please find attached both the codes below. Do notice the abrupt change in the value of 'a' when plotted against time.

Code:


model Test
  Real a;
  Real b;
  Real c(start = 90000);
  Real fraction;
  parameter Real d(start = 100000);
  annotation(experiment(StartTime = 0.0, StopTime = 3, Tolerance = 0.000001));
equation
  der(c) = 7500;
  fraction = c / d;
  if fraction <= 1 then
    b = 1;
  else
    b = -1;
  end if;
  a = fraction ^ (b / 2) * (4 * (1 - fraction ^ (b * 0.5))) ^ 0.5;
end Test;

The above code is the one containing the If-statement and the result is a sudden jump in the observed value of 'a'
Below is the code with the sign() function

Code:


model Test
  Real a;
  Real b;
  Real c(start = 90000);
  Real fraction;
  parameter Real d(start = 100000);
  annotation(experiment(StartTime = 0.0, StopTime = 3.0, Tolerance = 0.000001));
equation
  der(c) = 7500;
  fraction = c / d;
  b = sign(d - c);
  a = fraction ^ (b / 2) * (4 * (1 - fraction ^ (b * 0.5))) ^ 0.5;
end Test;

Thank you for going through the codes. The only difference is in the way the variable 'b' is assigned.

If anyone can help me and explain as to why this is happening I would be very grateful.

Also I wanted to know if this is a problem with the usage of equations and not algorithms whilst using the If-statement.

Thank You
Pratyush

I noticed that the problem didn't exist with that particular example alone.
Here's a elementary piece of code that I ran -

Code:


model Test
parameter Real a1(start =1);
Real a2;
Real a3;
equation
a2 = -a1;
a3 = -a2;
end Test;

Only to notice that the values of a3 and a2 are coming out to be the same.
If I change the multiplying factor of a2 in the 2nd equation from -1 to any other value, it solves and gives me the answer.

I do not face this problem when I use the algorithm.

Code:


model Test
parameter Real a1(start =1);
Real a2;
Real a3;
algorithm
a2 := -a1;
a3 := -a2;
end Test;

I tried finding out what the problem could be while solving the equation but couldn't do so.
Anyone has any idea as to what could be the problem ?

Thank You 
Pratyush

Hello

I am creating a custom library and have therefore created custom components and connectors for the same. I am facing a problem though. The flow variable in the connector does not seem to obey the flow equation  (component1.flow_variable + component2.flow_variable = 0 ).
I am actually assigning the flow variable in component one by equating it to a parameter. The parameter value is positive and the equation I'm using is -
component2.flow_variable = - parameter_value ;
Then it gives the output of both the flow variables to be negative and does not obey the flow variable equation, the cause of which I am not able to understand.
But if I take the parameter to be negative and assign the flow variable as -
component2.flow_variable =  parameter_value ;
Then it solves the system properly and obeys the flow variable equation.
I'm not able to understand as to why this is happening.

Any help on this is appreciated.

Thank You
Pratyush

Oh I see. Anyways are you aware of any other method in which we can store the value of a variable in the middle of a simulation ?
I am actually making a library in OMEdit and one the components needs to have the intermediate values of a variable for further use.

Thanks Again!

That worked out pretty well. I entered your code in OMShell and it worked just as you had said. Thanks!

I tried to introduce the code into OMedit as the value which I need is to be used further but to no avail. I am getting confused as I don't know where to enter the code. Is there a way of doing so ?

Thanks a lot !
Pratyush

Hello
I wish to check the instantaneous value of a variable at a particular time instant. I am currently unable to do so. I am new to the modeling environment, so please excuse me if the question seems rather silly.
I am attaching a sample code below. Its a function x which varies as the square of time. I wish to find the value of x (at say time = 0.4 sec) and store it in another variable (say y) which would be constant. I would like to know the procedure and the syntax to obtain the desired value of y. For example in the following case the value of y should be 0.08.

Code:


model test
Real x;
equation
der(x) = time;
end test;

Thank You for your assistance.

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

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;

import Modelica.Mechanics.Translational.Interfaces did work!!

I am still not able to figure out what I was doing earlier that made the model unable to simulate. I feel stupid now! 

Anyways Thanks a Lot! current/smile

Ya I was trying to import SIunits and Modelica.Mechanics.Translational.Interfaces into my new library.

I tried using -
package Interfaces = Modelica.Mechanics.Translational.Interfaces 
but to no avail.

How do I link the above Interfaces package so that I am able to use it in my NewLib ?

Thanks a Lot !

I am trying to create a new user library for custom components and wish to use some existing modelica components for the same (like interfaces, SIunits etc.). I am using the extends command in order to import those classes.

eg. extends Modelica.SIunits

I am able to check my package without errors and managed to save the library. Then, I proceed to the graphical editor and drag the components to make a model. But I am not able to connect the components to each other.

The error window shows something like -

Class SIunits.Mass not found in scope of NewLib.NewMass (Where NewLib is my library and NewMass is the custom component made)

I am saving the library created in the /omlibrary folder. I tried placing it in the /omlibrary/modelica folder but then OMEdit is unable to load the modelica package.

Pardon me for my ignorance as I am new user to the modeling and simulation environment. Any help will be very much appreciated.

Thanks

Thank you for your prompt reply.
Pardon my ignorance but is creating a new library same as defining a new package ?
Also, once created, can the new library incorporate components, interfaces from the modelica standard library or will I have to redefine them again ?

Thanks

Hi,
I am a new user trying to use OpenModelica. I am trying to create a custom component in OMEdit. For eg. I want to create a new component called Mass2 in the Mechanics.Translational.Components Package. I am unable to do so. I use the standard interfaces that are present in order to complete the component(or model).
I try to run it and it gives me errors saying
" Class SI.Mass is not found in scope Mass2 "

I am confused and when I try loading the modelica library in OMEdit by typing "loadModel(Modelica)", it gives an error. 

Any help in this regard would be very much appreciated.
Thank You

  • Index
  • » Users
  • » Pratyush
  • » Profile
You are here: