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

Instantiation of equation

Instantiation of equation

Hi together,

I am quite new here in the community and just face my first serious problem.

Let me explain the background at first:
I want to create a small library for special fluid applications (lubrication).
For this library, I also need basic components such as pipes. To calculate the pressure drop in a pipe, I need the friction factor. Up to now, I used approximated equations that could be solved easily, since the wanted variable was already separated on the left side. But now, I'd like to use those equations that can be found in literature, e.g. the Prandtl-Karman-equation:

1/sqrt(lambda) = 2 * log10(Re * sqrt(lambda) / 2.51)
lambda: friction factor
Re: Reynoldsnumber

Obviously, this equation has to be solved iteratively. I managed to do so by using the Modelica Standard library: Modelica.Math.Nonlinear.solveOneNonlinearEquation. I get the correct result.

And here's my problem: I now want to use this component (e.g. a pipe) in another model (a network consisting of several pipes and so on), but I get the error message:
Failed to instantiate equation
lambda = Modelica.Math.Nonlinear.solveOneNonlinearEquation(function OilCircuit.Functions.FrictionFactor.Smooth.PrandtlKarman(Re = 27000), 0.0001, 0.1, 0.001);.

Well, it seems that one can't instatiate an equation. But I can't find any other solution to solve this.
Can anyone help?

Thank you very much! Regards, Jan

Re: Instantiation of equation

Ok, I think I found the solution by myself.

What I did first:
- I created a new function (FunNonLinear), e.g. the one for the friction factor lambda:  y := 2 * sqrt(lambda) * Modelica.Math.log10(Re * sqrt(lambda) / 2.51) - 1;
- I tried to solve this equation by adding the function call {lambda := Modelica.Math.Nonlinear.solveOneNonlinearEquation(function FunNonLinear(Re = 27000), 0.0001, 0.1, 0.001);} in the pipe model
>>> It didn't work this way.

"Unfortunately", the solution seems to be quite simple:
- I still use the mentioned funcion "FunNonLinear": y := 2 * sqrt(lambda) * Modelica.Math.log10(Re * sqrt(lambda) / 2.51) - 1
- I then created another function (FunCall) which includes the function call: lambda := Modelica.Math.Nonlinear.solveOneNonlinearEquation(function FunNonLinear(Re = a), 0.0001, 0.1, 0.001); where a is a parameter that can be chosen by the user
- to get the wanted value for lambda, I now call the 2nd function (FunCall) out of my model, e.g. by: lambda = FunCall(a=27000);
>>> It is now possible to create an instance of this model

I hope that you can understand my poor English and maybe someone else has a problem similiar to this one...

Regards, Jan

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