Custom Simscape Language Valve

2 次查看(过去 30 天)
David Yu
David Yu 2015-9-7
Hi!
I am doing a school project regarding a valve, I have a question concerning the Simscape language, maybe you can help me :)
I just need to set a valve with a given equation, this valve decides the amount of volume flow through a system given some parameters. I have the following written, although I am encountering problems with the result it is giving. The problem I have is that the parameters "p_1" and "p_2" should be automatically calculated (it is the pressure before and after the valve respectively) instead of being an input for the block.
I am not sure if I need to set the "nodes" and "branches" not quite sure for what are the used for.
component valve
parameters
K = { 0, 'm^2' }; % K coefficient
rho = { 0, 'kg/m^3' }; % Density
p_1 = { 0, 'bar' }; % Inlet pressure
p_2 = { 0, 'bar' }; % Outlet pressure
end
equations
q == K*sqrt((1000*(p_1-p_2))/rho) ;
end
end

回答(1 个)

Sebastian Castro
Sebastian Castro 2015-9-10
You definitely need the "nodes" section if you want your custom valve to connect to one of the pre-existing domains. For example, for the hydraulic domain:
nodes
A = foundation.hydraulic.hydraulic; % A:left
B = foundation.hydraulic.hydraulic; % B:right
end
In addition, you do not need to use two variables named "p1" and "p2" if you are using hydraulic nodes. You simply define one variable "p" which can then be defined in the "equations" section using the nodes you set up above.
p == A.p - B.p;
Finally, "branches" will define the sign convention of the other variable -- which is flow rate. In other words, is flow positive from A to B or from B to A?
branches
q : A.q -> B.q;
end
I think you should look at the existing .ssc source code for a similar block. For instance, you can double-click a Constant Area Hydraulic Orifice block and use the "Source code" hyperlink to see its implementation. Then, right-click the "foundation.hydraulic.branch" to look into some more of the code. The orifice block "inherits" from that branch template and fills in the remaining details to complete the orifice model and dialog/parameters.
- Sebastian

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by