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

Preloaded Spring Modelica Text

Preloaded Spring Modelica Text

Hi,

I am new, I want to model a preload spring in Modelica. I wrote a Modelica Text for it:

model UnloadedSpring

   parameter Modelica.SIunits.TranslationalSpringConstant c(final min=0)=1000;
 
  parameter Modelica.SIunits.Length x_0=0 "First position of spring";
 
  parameter Modelica.SIunits.Length x_1=0.02 "Second position of spring";
 
  parameter Modelica.SIunits.Length x_2=0.04 "Last position of spring";
 
  parameter Real Modelica.SIunits.Length x(min=0.02, max=0.04) "Stroke between x_1 and x_2";
 
  parameter Modelica.SIunits.Force F_0=10 "Force_0 at x_0/preload";
 
  parameter Modelica.SIunits.Force F_1=20 "Force_1 at x_1";
 
  parameter Modelica.SIunits.Force F_2=50 "Force_2 at x_2";
 
  parameter Modelica.SIunits.Force F "Force at between F_1 and F_2";
 

equation
 
  F = F_0 + c * x;
 
end UnloadedSpring;

but I know that I defined x ("Stroke between x_1 and x_2") wrong. I don't want to define it like min stroke is 0.02 and max stroke is 0.04, I want to define it like I said between 0.02 to 0.04. Do you know how can I do it?

You don't have to follow my way as I said I am very unfamiliar to Modelica, I just want to take help from you how to write a preload spring text in Modelica or Dymola model also would be great. I need your all answers please help current/smile

Thank you.

Re: Preloaded Spring Modelica Text

There is certain difference in defining parameters and variables. Actually, all of them are variables and can be defines as following:

Modelica.SIunits.Length x_1 "First position";



When you add the keyword parameter in front of it, then you declare the value of this variable always constant. That is the difference between parameters and variables. I think you wanted to define F as a variable. Then you need to remove the keyword parameter while you are declaring it.


parameter Modelica.SIunits.Length x_1 "First position";
Modelica.SIunits.Force x(final min=x_1, final max=x_2) "Position of the spring";
Modelica.SIunits.Force F "Force";



As far as I understand, you need to define x as a variable as well, with certain minimum and maximum values. You need to remove keyword parameter from there too. If you have two variables in your model (F and x), you need two equations to solve them. As for the first equation, what you have written is valid. Physically thinking, the force depends on the variable x. But how is x changing over time? Or how is F changing over time? You need one more defining equation. For example, the position of the string could be changing with a sine function between the maximum and minimum points. Or you could apply a force with different characteristics.

In general, I am not sure that I understood your problem correctly. Therefore, I tried to give the fundamentals not the solution. Seeing you asked this question much earlier, probably you already found your answer. One more quick remark, I don't it is a good idea to give minimum and maximum values for variables in this way, I mean it is not a good practice.

Edited by: umutcanuguz - Sep-07-17 07:46:15
There are 0 guests and 0 other users also viewing this topic
You are here: