Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simscape Tank model

606 views
Skip to first unread message

Martin

unread,
Nov 30, 2010, 7:17:06 AM11/30/10
to
Hi ,
I just started modelling with simscape and I want to build my own component in the hydraulic domain. It is a tank model with two connections (conserving ports)
It is defined by the equations:

dV/dt = q_in -q_out (1) %Volume flow trough tank
V = A*h (2) %Volume in tank
p_2 = p_amb + rho*g*(h-h1) (3) %pressure at right-hand side hole
p_1 = p_amb + rho*g*(h-h2) (4) %pressure atl eft-hand side hole
q_out = k_out *( 1/sqrt(rho)) * sqrt(p_2-p_out); (5) % outgoing volume flow

with parameters

A: Surface of tank
p_amb: ambience pressure
rho: density of water
g: acceleration
h1: height of left hole
h2: height of right hole
k_out: outflow coefficient

p_out is the incomming pressure at the right-hand side.
I wrote a working component, but in no domain ( with no conserving ports)
Now I want to integrate the component to the hydraulic domain but I didn't succeed. My model is

component Wassertonne
% Wassertonne
% Modell einer einfachen Wassertonne mit einem Einfluss und einem Ausfluss
nodes
A = foundation.hydraulic.hydraulic; %q_in:left
B = foundation.hydraulic.hydraulic; %q_out:right
end

parameters
rho = { 1000, 'kg/m^3' }; %Density
Aw = { 0.25, 'm^2' }; %Surface
g = { 9.81, 'm/s^2' }; %Gravity
k_out = { 0.000126, 'm^2' }; % outflow coefficient
p_amb = { 1e5, 'Pa' } % ambient pressure
h_1 = { 2, 'm' }; %heigth of left connection
h_2 = { 0.5, 'm' }; %heigth of right connection
end
variables
p = { 0, 'Pa' }; % pressure
h = { 0, 'm' }; %water level in tank
V = { 0, 'm^3' }; %Volume
q = { 0, 'm^3/s' }; %flow rate
end
function setup
through( q, A.q, B.q ); % q a through variable from A to B
across(p, A.p, B.p ); % p an across variable from A to B
end
equations
V == Aw * h;
if (h<h_2)
B.p == p_amb;
else
B.p == p_amb + rho* g* (h-h_2);
end
if (h<h_1)
A.p == p_amb;
else
A.p == p_amb + rho* g* (h-h_1);
end
q == k_out *( 1/sqrt(rho)) * sqrt(B.p-p_out?);

end
end

So I have some questions:

1. Do I have to write equation (1) for through variables ? (I tried "der.V = A.q-B.q" but there are always error"Unexpected function or variable 'A'.") or is this equation implicit?

2. If B.p is the pressure of the water at the hole in the tank at the right-hand side(if thats true) how do I adress the pressure comming from outside of the tank (p_out) in eq.(5)

I tested the component replacing p_out by p_amb but when simulating I get the error "Number of equations exceeds number of variables."

I would be thankful for any suggestions
Martin

Martin

unread,
Dec 1, 2010, 4:52:05 AM12/1/10
to
To make my model more clearly here is the code of my (functional) component without domain.
The tank has 2 physical ports, the incoming flow rate and the outgoing flow rate. As the outflow is not connected to another component, the incoming pressure at the outflow is the ambience pressure.

component Wassertonne2
% Wassertonne2


% Modell einer einfachen Wassertonne

inputs
q_in = {0, 'm^3/s' }; %q_in:left
end
outputs
q_out = {0, 'm^3/s' }; %q_out:right


end
parameters
rho = { 1000, 'kg/m^3' };

Aw = { 0.25, 'm^2' };
g = { 9.81, 'm/s^2' };
k_out = { 0.000126, 'm^2' };
p_amb = { 1e5, 'Pa' };
p_out = { 1e5, 'Pa' };
h_1 = { 2, 'm' };
h_2 = { 0.5, 'm' };
end
variables
p_1 = { 0, 'Pa' };
p_2 = { 0, 'Pa' };
h = { 0, 'm' };
V = { 0, 'm^3' };
end

equations
V.der == q_in - q_out; % Equation


V == Aw * h;
if (h<h_2)

p_2 == p_amb;
else
p_2 == p_amb + rho* g* (h-h_2);
end
if (h<h_1)
p_1 == p_amb;
else
p_1 == p_amb + rho* g* (h-h_1);
end
q_out == k_out * (1/sqrt(rho)) * sqrt(p_2 - p_out);
end
end

so how can I integrate that component to the hydraulic domain?

cheers, martin

Arnaud Miege

unread,
Dec 3, 2010, 10:41:06 AM12/3/10
to
"Martin " <marti...@googlemail.com> wrote in message <id2q02$nus$1...@fred.mathworks.com>...

> Hi ,
> I just started modelling with simscape and I want to build my own component in the hydraulic domain. It is a tank model with two connections (conserving ports)
> It is defined by the equations:
>
> dV/dt = q_in -q_out (1) %Volume flow trough tank
> V = A*h (2) %Volume in tank
> p_2 = p_amb + rho*g*(h-h1) (3) %pressure at right-hand side hole
> p_1 = p_amb + rho*g*(h-h2) (4) %pressure atl eft-hand side hole
> q_out = k_out *( 1/sqrt(rho)) * sqrt(p_2-p_out); (5) % outgoing volume flow
>
> with parameters
>
> A: Surface of tank
> p_amb: ambience pressure
> rho: density of water
> g: acceleration
> h1: height of left hole
> h2: height of right hole
> k_out: outflow coefficient
>
> p_out is the incomming pressure at the right-hand side.
> I wrote a working component, but in no domain ( with no conserving ports)
> Now I want to integrate the component to the hydraulic domain but I didn't succeed. My model is
>
<snip>

> So I have some questions:
>
> 1. Do I have to write equation (1) for through variables ? (I tried "der.V = A.q-B.q" but there are always error"Unexpected function or variable 'A'.") or is this equation implicit?
>
> 2. If B.p is the pressure of the water at the hole in the tank at the right-hand side(if thats true) how do I adress the pressure comming from outside of the tank (p_out) in eq.(5)
>
> I tested the component replacing p_out by p_amb but when simulating I get the error "Number of equations exceeds number of variables."
>
> I would be thankful for any suggestions
> Martin

1. equation (1) should be written as V.der == q; unless I'm mistaken
2. I don't understand the difference between B.p and p_out. Is p_out a parameter or a variable? If a parameter, define it as such. The same if it is a variable. If a avriable, you probably need an additional equation.

The error is probably because you are missing the equation linking V to q. Because you are dealing with absolute pressures, rather than a pressure differential between the A and B ports, here's how I would define my variables:

variables
p_1 = { 0, 'Pa' }; %pressure at left-hand side hole
p_2 = { 0, 'Pa' }; %pressure at right-hand side hole


h = { 0, 'm' }; %water level in tank
V = { 0, 'm^3' }; %Volume

q = { 0, 'm^3/s' }; %flow rate from left to right-hand side
end

and then the setup function would be as follows:


function setup
through( q, A.q, B.q ); % q a through variable from A to B

across(p_1, A.p, [] ); % p an across variable at node A
across(p_2, B.p, [] ); % p an across variable at node B
end

It may be that your current way of defining the through and across variables works, I'm not sure. What is definitely missing is the V = f(q) equation and the definition of p_out.

HTH,

Arnaud

PS: there are various tank models available in SimHydraulics

Arnaud_Miege

unread,
Dec 3, 2010, 10:55:43 AM12/3/10
to

"Arnaud Miege" <arnaud...@nospam.mathworks.co.uk> wrote in message
news:idb32i$s41$1...@fred.mathworks.com...

Obviously, replace A.p by p_1 and B.p by p_2 in the equations section.

HTH,

Arnaud

Martin

unread,
Dec 9, 2010, 6:50:04 AM12/9/10
to
"Arnaud Miege" <arnaud...@nospam.mathworks.co.uk> wrote in message
> 1. equation (1) should be written as V.der == q; unless I'm mistaken
> 2. I don't understand the difference between B.p and p_out. Is p_out a parameter or a variable? If a parameter, define it as such. The same if it is a variable. If a avriable, you probably need an additional equation.
>
> The error is probably because you are missing the equation linking V to q. Because you are dealing with absolute pressures, rather than a pressure differential between the A and B ports, here's how I would define my variables:
>
> variables
> p_1 = { 0, 'Pa' }; %pressure at left-hand side hole
> p_2 = { 0, 'Pa' }; %pressure at right-hand side hole
> h = { 0, 'm' }; %water level in tank
> V = { 0, 'm^3' }; %Volume
> q = { 0, 'm^3/s' }; %flow rate from left to right-hand side
> end
>
> and then the setup function would be as follows:
> function setup
> through( q, A.q, B.q ); % q a through variable from A to B
> across(p_1, A.p, [] ); % p an across variable at node A
> across(p_2, B.p, [] ); % p an across variable at node B
> end
>
> It may be that your current way of defining the through and across variables works, I'm not sure. What is definitely missing is the V = f(q) equation and the definition of p_out.

hello Arnaud,
thank you for your reply.

I tried your solution but I get an error (number of equations exeeds number of variables) I conneted my tank to an Hydraulic Flow Rate Source and an Hydraulic Flow Rate Sensor.

Concerning your question about p_out, in the hydraulic domain, p_out should be the pressure that is coming from the component to which I want to connect my tank to. If my tank is not connected, p_out is the ambience pressure and a parameter.
You can take a look at my model here, also I added one more equation:

http://www.scribd.com/full/44965377?access_key=key-1jnjrwxe0ikw5nypkf3u

So maybe you could tell me for that model, how to declare the variables p_1, p_2, P_out, p_in.

Thanks in advance
martin

Arnaud Miege

unread,
Dec 9, 2010, 10:08:06 AM12/9/10
to
"Martin " <marti...@googlemail.com> wrote in message <idqfpc$htu$1...@fred.mathworks.com>...

> hello Arnaud,
> thank you for your reply.
>
> I tried your solution but I get an error (number of equations exeeds number of variables) I conneted my tank to an Hydraulic Flow Rate Source and an Hydraulic Flow Rate Sensor.
>
> Concerning your question about p_out, in the hydraulic domain, p_out should be the pressure that is coming from the component to which I want to connect my tank to. If my tank is not connected, p_out is the ambience pressure and a parameter.
> You can take a look at my model here, also I added one more equation:
>
> http://www.scribd.com/full/44965377?access_key=key-1jnjrwxe0ikw5nypkf3u
>
> So maybe you could tell me for that model, how to declare the variables p_1, p_2, P_out, p_in.
>
> Thanks in advance
> martin

I think based on your diagram, p_1 and p_2 are internal variables corresponding to the pressures inside the tank at the input and output ports. If I were to write it in Simscape, I would write it as follows:

component Wassertonne
% Wassertonne
% Modell einer einfachen Wassertonne mit einem Einfluss und einem Ausfluss
nodes

A = foundation.hydraulic.hydraulic; %in:left
B = foundation.hydraulic.hydraulic; %out:right
end

parameters
Aw = { 0.25, 'm^2' }; % Surface
k_in = { 0.000126, 'm^2' }; % Inflow coefficient
k_out = { 0.000126, 'm^2' }; % Outflow coefficient
p_amb = { 1e5, 'Pa' } % Ambient pressure
h_1 = { 2, 'm' }; % Heigth of left connection
h_2 = { 0.5, 'm' }; % Heigth of right connection
V_init = { 0 , 'm^3'}; % Initial volume
end

parameters(Access = private)


rho = { 1000, 'kg/m^3' }; %Density

g = { 9.81, 'm/s^2' }; %Gravity

end

variables
% Through and across variables
p_in = { 0, 'Pa' }; %pressure at left-hand side hole
p_out = { 0, 'Pa' }; %pressure at right-hand side hole
q_in = { 0, 'm^3/s' }; %flow rate in
q_out = { 0 , 'm^3/s'}; % flow rate out

% Internal variables
h = { 0, 'm' }; % Water level in tank


V = { 0, 'm^3' }; % Volume

p_1 = { 0 , 'Pa'}; % Internal pressure at input port
p_2 = { 0 , 'Pa'}; % Internal pressure at output port
end

function setup
% Through and across variables
through(q_in, A.q, []); % q_in through variable at node A
through(q_out, B.q, []); % q_out through variable at node B
across(p_in, A.p, [] ); % p_in across variable at node A
across(p_out, B.p, [] ); % p_out across variable at node B

% Parameter checking
if Aw<=0
error('Area must be strictly positive.')
end
if (h_1<0)||(h_2<0)
error('Height must be positive.')
end
if (p_amb<0)
error('Ambient pressure must be positive.')
end

% Derived parameters
rho = A.density; % inherit the domain-wide parameter "density" from node A

% Initialisation
V = V_init;
end

equations
% Equation 1


V.der == q_in - q_out;

% Equation 2

V == Aw * h;

% Equation 3


if (h<h_2)
p_2 == p_amb;
else

p_2 == p_amb + rho* g* (h-h_2);
end

% Equation 4
q_out == k_out * sqrt((p_2 - p_out)/rho);

% Equation 5
q_in == k_in * sqrt((p_in - p_1)/rho);

% Equation 6

if (h<h_1)
p_1 == p_amb;
else

p_1 == p_amb + rho* g* (h-h_1);
end
end
end

Note that I have defined g and rho as private parameters and used the domain-wide parameter to overwrite the value of rho. This means that rho is actually defined in either the "Custom Hydraulic Fluid" block from the Simscape foundation library or in the "Hydraulic Fluid" block from SimHydraulics. If you don't have any of these blocks attached to your Simscape network, then it take the default value in the hydraulic domain definition, i.e. 850 kg/m^3. This is the correct way to ensure that the fluid properties are propagated thoughout the various components in your Simscape network.

I have also added an additional parameter to initialise the volume V, which is a differential variable, as well as some parameter checking in the setup function.

HTH,

Arnaud

Martin

unread,
Dec 10, 2010, 8:33:05 AM12/10/10
to

> Note that I have defined g and rho as private parameters and used the domain-wide parameter to overwrite the value of rho. This means that rho is actually defined in either the "Custom Hydraulic Fluid" block from the Simscape foundation library or in the "Hydraulic Fluid" block from SimHydraulics. If you don't have any of these blocks attached to your Simscape network, then it take the default value in the hydraulic domain definition, i.e. 850 kg/m^3. This is the correct way to ensure that the fluid properties are propagated thoughout the various components in your Simscape network.
>
> I have also added an additional parameter to initialise the volume V, which is a differential variable, as well as some parameter checking in the setup function.
>
> HTH,
>
> Arnaud

Dear Arnaud,
thanks a lot for the time you took, now I understand the concept of the through and across variables much better.
Now the simulation is running without error, unfortunatly the result is not what I expected. Probably there is something wrong in my .mdl model. Maybe you have an idea where the mistake could be. I added a picture of my model. The first picture shows how the result should look like without conserving ports.
So if you have time to take another look at my model i would appreciate that.

http://www.scribd.com/full/45037721?access_key=key-9y3hgocvfbf5fl8w0fz

This Really Helped
martin

Arnaud Miege

unread,
Dec 10, 2010, 9:23:20 AM12/10/10
to
"Martin " <marti...@googlemail.com> wrote in message <idta6h$5ti$1...@fred.mathworks.com>...

How do you define the "no domain" component with the inputs and outputs. I have tried it and got the same results. p_in and p_out now need to be parameters rather than variables and equation (5) related to q_in should be removed as q_in is now an input to the block. For the model, you will need to add a "Custom Hydraulic Fluid" block connected to a hydraulic line, where the density is specified to 1000 kg/m^3 (remember my previous post).

Finally, and that's probably the most important part, if you connect a hydraulic reference block to the q_out hydraulic port as you have done, that will impose a pressure p_out of 0 (have a look at the source code for the hydraulic reference block). Similary, if you measure the pressure on the q_in side with a pressure sensor block, this is the pressure you need to enter for the p_in parameter in the "no domain" block, to make sure you are comparing like for like.

Here is the code I used for the "no domain" version:

component Wassertonne_ps
% Wassertonne PS


% Modell einer einfachen Wassertonne mit einem Einfluss und einem Ausfluss

inputs
q_in = { 0, 'm^3/s' }; % q_in:left
end

outputs

q_out = { 0 , 'm^3/s'}; % q_out:right
end

parameters

rho = { 1000, 'kg/m^3' }; %Density

Aw = { 0.25, 'm^2' }; % Surface

k_out = { 0.000126, 'm^2' }; % Outflow coefficient
p_amb = { 1e5, 'Pa' } % Ambient pressure
h_1 = { 2, 'm' }; % Heigth of left connection
h_2 = { 0.5, 'm' }; % Heigth of right connection
V_init = { 0 , 'm^3'}; % Initial volume

p_in = { 0, 'Pa' }; %pressure at left-hand side hole
p_out = { 0, 'Pa' }; %pressure at right-hand side hole

end

parameters(Access = private)

g = { 9.81, 'm/s^2' }; %Gravity
end

variables

h = { 0, 'm' }; % Water level in tank
V = { 0, 'm^3' }; % Volume
p_1 = { 0 , 'Pa'}; % Internal pressure at input port
p_2 = { 0 , 'Pa'}; % Internal pressure at output port
end

function setup

% Parameter checking
if Aw<=0
error('Area must be strictly positive.')
end
if (h_1<0)||(h_2<0)
error('Height must be positive.')
end
if (p_amb<0)
error('Ambient pressure must be positive.')
end

% Initialisation
V = V_init;
end

equations
% Equation 1
V.der == q_in - q_out;

% Equation 2
V == Aw * h;

% Equation 3
if (h<h_2)
p_2 == p_amb;
else
p_2 == p_amb + rho* g* (h-h_2);
end

% Equation 4
q_out == k_out * sqrt((p_2 - p_out)/rho);

% Equation 5

%q_in == k_in * sqrt((p_in - p_1)/rho);



% Equation 6
if (h<h_1)
p_1 == p_amb;
else
p_1 == p_amb + rho* g* (h-h_1);
end
end
end

With all the default parameters, except for p_in set to 1e5 Pa, I get the same constant flow rate out (you'll need to change the orientation of the flow rate sensor) 1.26e-3 m^3/s.

HTH,

Arnaud

Martin

unread,
Dec 12, 2010, 8:15:05 AM12/12/10
to
"Arnaud Miege" <arnaud...@nospam.mathworks.co.uk> wrote in message <idtd4o$slo$1...@fred.mathworks.com>...

My code for the "no Domain" tank is very similar to yours, it was in my 2. post.
the result is the same, for p_out = 1e5 (ambience pressure).
And of course as you pointed out I don't need equation 5 for this model and p_out is a parameter.

But I need this equation if the tank is connected to other components, either simscape components or own components in the hydraulic domain. So in the next steps, my tank will be connected to another tank with a tube an so on.

So finally my hydraulic component is functional, thanks to your advice concerning the pressure. What confused me was the description of the hyd. reference block that said the block should be used if a component is connected to the atmosphere. In my understandig this should be atmosphere pressure, but in the source code I saw it is zero, thanks to your hint.
So if I want to test my tank standalone of course I need a pressure source, representing the ambience pressure.

So in case someone followed this thread and is interested in the functional model follow the link:

http://www.scribd.com/full/45143342?access_key=key-5y3cx8ol4667ehpa5z8

So thanks again Arnaud for the great support
martin

Arnaud Miege

unread,
Dec 13, 2010, 3:58:04 AM12/13/10
to
"Martin " <marti...@googlemail.com> wrote in message <ie2hso$eu6$1...@fred.mathworks.com>...

> My code for the "no Domain" tank is very similar to yours, it was in my 2. post.
> the result is the same, for p_out = 1e5 (ambience pressure).
> And of course as you pointed out I don't need equation 5 for this model and p_out is a parameter.
>
> But I need this equation if the tank is connected to other components, either simscape components or own components in the hydraulic domain. So in the next steps, my tank will be connected to another tank with a tube an so on.
>
> So finally my hydraulic component is functional, thanks to your advice concerning the pressure. What confused me was the description of the hyd. reference block that said the block should be used if a component is connected to the atmosphere. In my understandig this should be atmosphere pressure, but in the source code I saw it is zero, thanks to your hint.
> So if I want to test my tank standalone of course I need a pressure source, representing the ambience pressure.
>
> So in case someone followed this thread and is interested in the functional model follow the link:
>
> http://www.scribd.com/full/45143342?access_key=key-5y3cx8ol4667ehpa5z8
>
> So thanks again Arnaud for the great support
> martin

Yes, Simscape and SimHydraulics use relative (gauge) pressures, whereas your component use absolute pressures, hence the difference.

Arnaud

Martin

unread,
Dec 22, 2010, 9:23:05 AM12/22/10
to

> > So finally my hydraulic component is functional, thanks to your advice concerning the pressure. What confused me was the description of the hyd. reference block that said the block should be used if a component is connected to the atmosphere. In my understandig this should be atmosphere pressure, but in the source code I saw it is zero, thanks to your hint.
> > So if I want to test my tank standalone of course I need a pressure source, representing the ambience pressure.
> >
> > So in case someone followed this thread and is interested in the functional model follow the link:
> >
> > http://www.scribd.com/full/45143342?access_key=key-5y3cx8ol4667ehpa5z8
> >
> > So thanks again Arnaud for the great support
> > martin
>
> Yes, Simscape and SimHydraulics use relative (gauge) pressures, whereas your component use absolute pressures, hence the difference.
>
> Arnaud


So the first step is done and my component is functional.
But unfortunatly, the extension of my model does not work.
So if I connect two of my components in row instead of one, there is no outflow at the second tank .

The integration of my component in the hydraulic domain does not work, too.
If I want to fill the "constant head tank" from Simhydraulics, the behaviour is not right.
The water level is rising at t = 0, but the outflow at my tank starts at t = 240.
So is it possible that if I want to work in the hydraulic domain I have to define my equations with relative pressures?

martin

Arnaud Miege

unread,
Jan 6, 2011, 11:28:05 AM1/6/11
to
"Martin" wrote in message <iet1k9$2sa$1...@fred.mathworks.com>...

>
> So the first step is done and my component is functional.
> But unfortunatly, the extension of my model does not work.
> So if I connect two of my components in row instead of one, there is no outflow at the second tank .
>
> The integration of my component in the hydraulic domain does not work, too.
> If I want to fill the "constant head tank" from Simhydraulics, the behaviour is not right.
> The water level is rising at t = 0, but the outflow at my tank starts at t = 240.
> So is it possible that if I want to work in the hydraulic domain I have to define my equations with relative pressures?
>
> martin

It's difficult to say why putting two components in series does not work without seeing the model. With regards to the constant head tank, have a look at the Water Supply System demo (sh_water_supply_system.mdl). Again, it's difficult to comment without seeing the model.

Arnaud

Martin

unread,
Jan 8, 2011, 2:52:05 PM1/8/11
to
"Arnaud Miege" wrote in message <ig4qil$fsd$1...@fred.mathworks.com>...

The model is the same as the model in the link two posts above, only with two of the components in a row instead of one. The code of the component is some posts above.
There is an outflow at the first tank (shown in the link) so I have no idea why this is not working for two tanks.

The model of the Water Supply System is very interesting but my aim here is not mainly the tank system. It is just one example of a physical sytem I want to simulate with different simulation tools (Simulink, Dymola/Modelica, Simscape) and compare the tools with respect to difficulty, accuracy, performance, etc...

Sorry for my bad english
martin

Arnaud Miege

unread,
Jan 10, 2011, 5:54:05 AM1/10/11
to
"Martin" wrote in message <igaf95$iqd$1...@fred.mathworks.com>...

> > Arnaud
>
> The model is the same as the model in the link two posts above, only with two of the components in a row instead of one. The code of the component is some posts above.
> There is an outflow at the first tank (shown in the link) so I have no idea why this is not working for two tanks.
>
> The model of the Water Supply System is very interesting but my aim here is not mainly the tank system. It is just one example of a physical sytem I want to simulate with different simulation tools (Simulink, Dymola/Modelica, Simscape) and compare the tools with respect to difficulty, accuracy, performance, etc...
>
> Sorry for my bad english
> martin

I tried it and it worked for me. I put two tanks in series and I can see some flow out of the second one. Here are the parameters I used for the first water tank:

Surface: 0.25 m^2
Inflow coefficient: 1.26e-4 m^2
Outflow coefficient: 1.26e-4 m^2
Ambient pressure: 1e5 Pa
Height of left connection: 2m
Height of right connection: 0.5m
Initial volume: 0 m^3

The second one had identical parameters, except for the height of the left and right connections (left set to 0.5m to match the right connection of the first tank, and right to 0.1m). I had to insert a small hydraulic resistance (1e4 Pa/(m^3/s)) in between the two tanks to allow the solver to solve for the initial conditions. The first tank inlet is connected to an hydraulic flow rate source of 1e-3 m^3/s, while the outlet of the second tank is connected to the hydraulic reference block. In those conditions, I see a constant flow rate out of the second tank of 1.26e-3 m^3/s. The fluid properties are set (through the Custom Hydraulic Fluid block) to the following values:

Density: 1000 kg/m^3
Kinematic viscosity: 1.8e-5 m^2/s
Bulk modulus: 8e8 Pa
Relative amount of trapped 0.005

I used the ode23t solver with a relative tolerance of 1e-3 and an absolute tolerance of 1e-4.

HTH,

Arnaud

Martin

unread,
Jan 11, 2011, 9:07:04 AM1/11/11
to
"Arnaud Miege" wrote in message <igeogd$hdv$1...@fred.mathworks.com>...

Hello Arnaud, thx for taking the time to test the model.

First I wanted to test your solution, but I get an error: Warning: Unable to reduce the step size without violating minimum step size....
When I change the value of the hydraulic resistance slightly, the solver finds a solution, but not the right one.

When I take a look at your result (constant flow rate out of the second tank of 1.26e-3 m^3/s.) this seems not right anyway. Or I should better say this is not what I expect. Because I have to admitt that I didn't realy understand the description of the flow rate source that says " ...that is powerful enough to maintain specified flow rate at its outlet regardless of the pressure differential across the source...". Is this causing a constant flow rate?

What I expect is a flow rate analog to the flow rate of one tank, only more flat and at a later point in time.
One thing I did was a change in the component in equation 5:
% Equation 5
if (q_in == 0)
p_in == p_amb;
else
p_in == q_in^2*rho/k_in^2 + p_1;
end
Further I've choosen ode5 fixed step solver (the only solver that found a result).
The results, also with different tools is shown here:

http://www.scribd.com/full/46653246?access_key=key-2bx0c14pglnd4o1pksxy

The quality is not very good,sorry, but the result from the simulation with Dymola and Simulink from tank 2 are the same, only the result from Simscape has some deviation.

Unfortunatly, this simscape model is not very stable, too, giving a step on the source, no result will be found.

Nevertheless, my understanding of simscape is growing (slowly ;-)).

martin

Arnaud_Miege

unread,
Jan 11, 2011, 9:49:13 AM1/11/11
to

"Martin " <marti...@googlemail.com> wrote in message

news:igho68$6s6$1...@fred.mathworks.com...

Hi Martin,

How have you parameterised your model? In my model, the outlet of the second
tank was connected to a hydraulic reference block rather than a hydraulic
pressure source of 1e5 Pa. I have made the changes in the code and also
connected the outlet of the second tank to a pressure source at 1e5 Pa, but
now I don't see any flow rate at all at the outlet of the second tank. The
pressure at the inlet of the first tank is now approx. 1.63e5 Pa.

To answer your question, a hydraulic flow rate source is just that, i.e. it
provides the flow rate you specify as input to the block, regardless of what
the pressure differential across the source is. Because you have connected
it to a constant block, then yes, it is causing a constant flow rate. You
can double-check that by placing a flow rate sensor in series between the
source and the first tank.

I'll also make a couple of suggestions:
* I would avoid doing an equality test on a double-precision number, as it
will never be quite zero. Instead, I would do something like if (abs(q_in)
<= {1e-6, 'm^3/s'}) ...
* don't use a fixed-step solver with a physical model. Use either ode15s or
ode23t, which are stiff solver well suited for physical models. The only
reason why you'd use a a fixed-step solver with a physical model is for
running in real-time, in conjunction with the Simscape local solver. I don't
think this applies to your case.

How is the Dymola model constructed? Make sure you are comparing like for
like. What about the Simulink one? What does it look like?

HTH,

Arnaud

Martin

unread,
Jan 11, 2011, 9:54:05 AM1/11/11
to
ps the hydraulic resistance in my model is 1e5 Pa/(m^3/2)

Arnaud_Miege

unread,
Jan 11, 2011, 9:58:54 AM1/11/11
to

"Martin " <marti...@googlemail.com> wrote in message

news:ighqud$63n$1...@fred.mathworks.com...


> ps the hydraulic resistance in my model is 1e5 Pa/(m^3/2)
>

Actually, I didn't realise you were running for 1000s. I was only running
for 10s, so no wonder I wasn't seeing anything. I need to look into it a bit
more.

HTH,

Arnaud

Arnaud_Miege

unread,
Jan 11, 2011, 10:25:46 AM1/11/11
to

"Martin " <marti...@googlemail.com> wrote in message

news:ighqud$63n$1...@fred.mathworks.com...


> ps the hydraulic resistance in my model is 1e5 Pa/(m^3/2)
>

What about the other (tank) parameters? With a resistance of 1e4 Pa/(m^3/s),
my model runs if I use the adaptive zero crossing:
http://www.mathworks.com/help/toolbox/simulink/ug/f7-8243.html#f7-9506

I also used the Simscape Simulation Results Explorer
(http://www.mathworks.co.uk/matlabcentral/fileexchange/28184-simscape-simulation-results-explorer)
to look at the internal variables of the tanks. I see flow *into* the first
tank at the outlet similar to yours, and the height of water inside the
tanks increases to about 3m, but in the second tank, the height of water
*decreases", and water flows out of the tank via the inlet port (the flow
rate is negative). There is no flow rate at the outlet of the second tank.

If I change the hydraulic resistance to 1e5, the model stalls at around t =
250s. The problem seems to be when the height of water in the second tank
gets above the height of the outlet. I can get it to run with the Simscape
local solver, but there a lot of high-frequency oscillations. I think you
need to make sure that you compare like for like, that the equations between
the different models are the same, the parameters are the same, etc...

HTH,

Arnaud

Martin

unread,
Jan 13, 2011, 4:55:29 PM1/13/11
to
"Arnaud_Miege" <ami...@mathworks.com> wrote in message <ighspq$765$1...@fred.mathworks.com>...

Hi Arnaud,

thx for the link to the simscape model explorer, this is realy helpful!!!

concerning the tank model parameters, I always take the same parameters, with the same heigths as you did. I

My Simulink model is a little bit different as the simscape model, so you are right that I have to care what I compare. I use the same equations and parameters, but I have two different models for the two tanks, because p_in is not needed for the first tank, because q_in is a parameter, so we need only 5 equations. You can take a look at the model here:

http://www.scribd.com/full/46815379?access_key=key-18ijb5hjpn7164pe4ps4

This would be possible in Simscape, too, but the aim is to create just one model (component) and then make instances of this component, to make modeling easier.

About Dymola, the parameters/equations of the tank are the same. I have a flow rate source at the first tank and a pressure source for p_out at the second tank. I use a connector for p and q. Unfortunatly I'm very busy with other stuff but next week I will take a closer look at the different values, I think I will start with only one tank, so the results can be compared better. So if you are interested I will post the results here.

martin

Martin

unread,
Jan 18, 2011, 10:53:04 AM1/18/11
to
Ok, the simulation of one single tank shows the same results in Simulink, Dymola and Simscape. Putting two tanks in series shows (almost) the same results in Dymola and Simulink, but I can't get a valid result in Simscape.

When I examined my previous result I saw, that there are some incongruities, there is a negative flow rate at tank1.

I also tried to work with relative pressure and changed the equations. Then a pressure source is no longer necessary and the tank can be connected to a reference block. But still no result for two tanks in series.

martin


0 new messages