Post by a blacksorry for the previous message this is my code
component turb
nodes
k = foundation.hydraulic.hydraulic; % +:top
l = foundation.hydraulic.hydraulic; % -:bottom
end
parameters
density = { 1000 , 'kg/m^3' }; % Fluid density
q0 = {0 , 'm^3/s' }; % initial value for q
W = {0 , 'Pa*m^3/s'}; % power
end
variables
p = { 1000 , 'Pa' }; %pressure across
q = { 0.3 , 'm^3/s' }; %flow rate through
end
function setup
across( p, k.p, l.p ); % across variable p from node k to node l
through( q, k.q, l.q ); % through variable q from k to l
end
equations
p == W/q; %equation
end
end
my problem is that when i make a simple example in simulink which includes a fixed displacement pump my model and 2 sensors one pressure sensor and one flow sensor the pressure sensor which counts the pressure before and after my model i get 0 pressure and i dont know why
The code looks OK. In fact it is very similar to the linear hydraulic resistance block from the Simscape foundation library. I suspect it's the rest of the model that is not correct, either you have not connected the sensors correctly or the model is put together such as there is no path for the flow to go. A pressure sensor needs to be connected in parallel (because pressure is an across variable) whereas a flow rate sensor needs to be connected in series (because flow rate is a through variable).
With regards to the Simscape code, I will make the following suggestions for improvement:
1) with the code as is, you are going to have numerical problems around zero flow (divide by zero). I would do something a liner interpolation around zero flow, for example:
if abs(q)<q_thresh
p == (W/q_thresh^2)*q;
else
p == W/q;
end
where q_thresh is a parameter:
q_thresh = { 1e-3, 'm^3/s'}; % Flow rate threshold
2) You can only initialise q with q0 (in the setup function) if q is a differential variable, i.e. if q.der appears somewhere in the equations, otherwise it doesn't make sense.
3) Density is a domain-wide parameter, you can inherit it from the node properties.
Define it as a private parameter:
parameters (Access = private)
density = { 1000 , 'kg/m^3'};
end
and then in the setup function, overwrite the value with the value of the domainw-die parameter:
density = k.density;
4) You probably want to do some parameter checking in the setup function, for example checking that W>0 and q_thresh>0, otherwise they can cause numerical problems.
HTH,
Arnaud