I am currently creating a pipe based on Modelica.Fluid.Pipes.StaticPipe in OpenModelica. The model I am creating is quite similar, but I'm trying to implement the method of characteristics instead.
When I check the model it counts 38 equations and 10 variables, and the system is therefore overdetermined. As far as I know I need every equation that I have coded, and I therefore think that variables and constants are declared wrong.
This is how I generally declare variables and constants:
- When defining things I want the user to change (in the GUI in OpenModelica) I use
parameter
, e.gparameter SIunits.Length length=1;
. - When defining things I don't want the user to change I use
final parameter
, e.gfinal parameter SIunits.Area crossArea=Modelica.Constants.pi*diameter*diameter/4;
. - When declaring things I need to use in
equation
I only use the correct type, e.gReal f "Darcy-Weisbach friction factor";
. I typically have seperate functions which are stored in these variables later inequation
. - When declaring arrays which are used in
equation
I usefinal parameter
, e.gfinal parameter Real f_array[j_length,i_length];
- In
equation
, when storing variables in arrays I do this:f_array[j,i] = Functions.Friction(v=v,D=diameter,rho=rho, mu=mu, eps=roughness);
.
Below is a simplified snippet of my code. I've left out a number of declarations in order to make it easier to read.
model pipe_MSL
outer Modelica.Fluid.System system;
extends Modelica.Fluid.Interfaces.PartialTwoPort;
// Geometry
parameter SI.Length length=1 "Length";
final parameter SI.Area crossArea=Modelica.Constants.pi*diameter*diameter/4;
// Initialization
final parameter Medium.AbsolutePressure p_a_start=system.p_start;
// Method of Characteristics declarations
Real f "Darcy-Weisbach friction factor";
Real B "Impedance from MOC";
Real R "Resistance from MOC";
final parameter Real dx = length/3
final parameter Integer N = integer(length/dx)
final parameter Real dt = dx/a "Time step";
Real v "Water velocity";
// Local array storage declarations.
final parameter Real B_array[T,N];
initial equation
//Initial condition
B_array[1,:] = {Functions.B_Impedance(a=a, A=crossArea, g=system.g)*k for k in 1:N};
equation
for j in 1:T loop
//Left boundary condition
Cm_array[j+1,1] = OpenWPL.Functions.C_minus(Hb=H_array[j,2], B=Bm_array[j,1], Qb=Q_array[j,2]);
for i in 1:(N-1) loop
B_array[j,i] = Functions.B_Impedance(a=a, A=crossArea, g=system.g) + R_array[j,i]*abs(Q_array[j,i-1]);;
end for;
end for;
end pipe_MSL;
My questions are:
- Am I using
parameter / final parameter / Real
and other declarations correctly? I've read the guide from Michael Tiller on variables over and over, but I cannot figure out if I use them correctly. - Any specific tips on how to make the system not overdetermined?
- When simulating (even though the system is overdetermined) I get the error
Internal error Cm_array[2,1] = OpenWPL.Functions.C_minus(H_array[1,2], Bm_array[1,1], Q_array[1,2]) has size size 1 but 0 variables ()
. Any idea how to solve this?
I can post the full version of my code if it is needed. Thanks in advance.
final parameter
fromfinal parameter Real dx = length/3
(which is constant throughout the whole simulation) I get the errorDimensions must be parameter or constant expression (in N).
inReal fp_array[T,N];
. Do you know how to counter this? – Jonasfinal parameter
the last error disappeared, as you mentioned. I have also declared another boundary condition (which I left out in my original post) which isH_array[j+1,1]=1;
under//Left boundary condition
inequation
. The same error (Internal error pipe.H_array[3,1] = 1.0 has size size 1 but 0 variables ()
) now appears here. Do you know how to solve this as well? Thank you for your reply! – Jonas