Jump to content
Livio Mariano

Modelica Custom Components

Recommended Posts

From: Yubichi-San

 

An Activate user would like to model a nonlinear spring in Activate using Modelica, where the nonlinearity simply come from nonlinear relationship between force and displacement.

 

In my understanding, the Modelica library in Activate has only linear spring. If we would like to introduce such a nonlinear spring, we have to customize the Modelica code of the linear spring, don't we?

 

Are there anyone who has developed such a nonlinear Modelica spring?

Share this post


Link to post
Share on other sites

Hi Yubuchi-san.

 

"we have to customize the Modelica code of the linear spring"

 

Yes and we do it using the modelica custom component.

Please find enclosed the model you are looking for together with other examples related to other physics.

 

Best Regards,

 

Liv

 

Electrical_VariableResistance.scm

Mechanical_VariableSpring.scm

Thermal_VariableCapacitor.scm

Thermal_VariableConductor.scm

Share this post


Link to post
Share on other sites

Hi Yubuchi-san,

 

Another solution using the Modelica custom component could be:
 

model NonLinearSpring "Non-Linear 1D translational spring"
  extends Modelica.Mechanics.Translational.Interfaces.PartialCompliant;
  parameter Modelica.SIunits.TranslationalSpringConstant c(final min=0, start=1) "Spring constant";
  parameter Real c_expo(final min=0, start=1) "Spring exponent";
  parameter Modelica.SIunits.Distance s_rel0=0 "Unstretched spring length";

equation
  f = c*abs(s_rel - s_rel0)^c_expo*sign(s_rel - s_rel0);
 
end NonLinearSpring;

With c_expo you can choose the exponent in equation f = Dx^c_expo * c.

 

Best Regards,
Ronald

 

Non-Linear Spring.scm

Share this post


Link to post
Share on other sites
On ‎7‎/‎6‎/‎2018 at 4:13 PM, Livio Mariano said:

Hi Yubuchi-san.

 

"we have to customize the Modelica code of the linear spring"

 

Yes and we do it using the modelica custom component.

Please find enclosed the model you are looking for together with other examples related to other physics.

 

Best Regards,

 

Liv

 

Electrical_VariableResistance.scm

Mechanical_VariableSpring.scm

Thermal_VariableCapacitor.scm

Thermal_VariableConductor.scm

 

Livio,

 

Thank you for the answer. I got how to create nonlinear spring with Modelica custom component.

 

Let me add one more question. If I would like to introduce a nonlinear spring (nonlinear displacement-force relationship) of which curve is defined by a csv file, how do I  import the csv file into Modelica code?

 

Thanks,

Minoru Yubuchi

Share this post


Link to post
Share on other sites

Hi Yubuchi-san,

 

Modelica supports the use of tables. The code looks like this:

 

model SpringWithTable
   ...
   parameter Real table[:, :]=[0,0; 1,1] "Spring curve (displacement = 1st col; force = 2nd col)"
      annotation(Dialog(tab="Spring Curve",group="Table"));
   parameter Modelica.Blocks.Types.Smoothness smoothness=Modelica.Blocks.Types.Smoothness.LinearSegments "smoothness of table interpolation"
      annotation(Dialog(tab="Spring Curve",group="Table"));
   Real force;

// internal blocks
   Modelica.Blocks.Tables.CombiTable1Ds SpringTable(tableOnFile=false,table=table,smoothness=smoothness)
      annotation (Placement(transformation(extent={{18,-32},{-2,-12}})));

   equation   
      SpringTable.u = displacement;
      force = SpringTable.y[1];
      ...
end SpringWithTable;

 

In the parameter dialogue you can load data from file.

 

Ronald

Share this post


Link to post
Share on other sites

Livio,

 

Thank you for the model. I modified it to see its nonlinearlity by adding a ramp load, and it works well (NLSpring_Stifness.scm & Disp_Stiffness.csv). And then, I modified the model again to introduce a nonlinearlity from a displacement-force curve (not from displacement-stiffness curve) (NLSpring_DispForce.scm & Disp_Force.csv), but it issues an error. Please let me have your advice how to solve the error.

 

I guess that it was caused because the MathExpression block provides zero as a stiffness value in the first step, but I don't know how to avoid it.

 

Thanks,

Minoru Yubuchi

Disp_Force.csv

Disp_Stiffness.csv

NLSpring_Stifness.scm

NLSpring_DispForce.scm

Share this post


Link to post
Share on other sites

Ciao Yubuchi-san,

"I guess that it was caused because the MathExpression block provides zero as a stiffness value in the first step, but I don't know how to avoid it."

Yes, the problem is that in the MathExpression block you divide a number by 0 at the beginning of the simulation.

Remember that even if the condition isn't satisfied the block perform the calculation anyway (it is similar but different from an if.. else statement where if the condition isn't satisfied you do not process the script inside) .

Enclosed 2 possible solutions...

Regards,

 

Liv

NLSpring_DispForcev1.scm

NLSpring_DispForcev2.scm

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...