Transition between two sets of equations in Simscape (Fuids) Custom component

5 次查看(过去 30 天)
I am working with a custom Simscape component and have two working versions:
  • The first version is designed for a specific flow type.
  • The second version is designed for another flow type.
In reality, these flow types can transition into each other. Both implementations work correctly when tested independently. My goal is to create a single component that transitions between these two flow types based on a flow variable.
The Problem
The challenge I am facing is that:
  • The first flow type requires 10 variables (and equations).
  • The second flow type is already fully defined with just 8 variables (2 fewer).
  • Let’s call the two redundant variables in the first flow type A(x1) and B(x2).
When transitioning to the second flow type, I don’t know how to properly define A and B once the first flow type fully stops.
What I Have Tried
  • Using if statements – Setting both sides to 0 == 0, but this did not work.
I have tried this in many ways but the problem is that the first flow type requires 10 variables (and equations) while the second flow type is already fully defined with just 8 (2 less), let's call the 2 redundant ones A(x1) and B(x2). The problem is that I don't know how to defin the 2 redundant variables when the first flow type fully stops and the second flow type is true.
I also tried kind of setting some random/estimate or last values for the first flow type when transitioning/switching to the second flow type however this also does not work. As well as setting the redundant A,B functions to equal something of the second flow type, but the solver/simulation does not seem to use them, as for example A==1, and B==2 are set in the second flow type, A can still be close to first flow type values like -151 as well as B = 45. While most of the tries did simulate succesfully (just leaving A and B out of equations for flow type 2 of course results in A,B not defined when going into that flow type), the results were not as they should which I mostly see when the fully transitioned result does not equal/match the second flow type individual its result.
I also tried keeping A,B (flow type 1) variables in just giving them very small scalars (i.e. 1e-10) did also cause bad results as it seemed to just change the variables in such a way that flow type 1 still was the final outcome/behavior. the 8 other variables are the same and therefore are relatively easy to transition using some transition function like yeff = (1-alpha)*y1(x) + alpha * y2(x) where alpha in my case goes between 0 to 1. This transition function seems to work well as it does not seem to give or be the cause of any of the errors/problems that I have experienced. I am not sure if that matters but I am quite sure that flow type 2 is stiffer than type 1.
In general I already have a lot of experience with Matlab, Simulink and quite some even in Simscape (Fluids) which is why I expected to be able to solve this problem myself.
I am kind of at a loss for the solution as I haveaaa already put quite some time in this.
Is there someone that has a solution or a workaround? If two components are necessary (or even more), but for example in a combined simulink component then that is also a solution, but I could not figure out how to do that properly.
If more information is needed please ask.
  3 个评论
Paul Hermens
Paul Hermens 2025-2-13
编辑:Paul Hermens 2025-2-13
You make a difference between state and intermediate variables. In the end it comes down to the same if I am correct right, you can define a (state) variable and then use it in equations, or you can add a intermediate (variable) that not only defines the variable but also adds an equation to it immediately. The only difference that I see is that if you want you can make it possible to give a initial value, which can help in some cases if convergence is not supergood at a certain state of the system.
But to answer, yes a part of it are intermediate variables, but the ones that 'dissappear' towards the second flow type are state variables and get solved implicitely, as in there is not an equation that says A = or A==, it gets solved from the equations so to say (I hope you understand what I mean). Compared to the alternative variable in flow type 2 that is an intermediate that get assigned by: C= f(c1, c2) and D= f(d1, d2). So that is always defined no matter if it gets used in the 'final' gas properties. Which means that only flow type 1 or blending factor of 0, there are no issues, and the flow gets the behavior of flow type 1.
I am having a hard time better putting how variables A and B are calculated but for reference you can see Pipe (G). look at mdot_A and mdot_B. That is how they are defined in flow type 1. and for flow type 2, see the paragraph above this. If that is not enough then please let me know.
So the idea is that A, and B transition into C and D based on a variable which is a function of pressure. I am trying my best to convey the problem but like you might see it is a bit hard without writing or copying all the code/equations that define the variables along with it.
Yifeng Tang
Yifeng Tang 2025-2-14
Not quite sure if I totally understand your question, but maybe here is an example that's similar to what you are trying to do. In that Pipe (G), the pressure drop vs flow rate equations need to switch/transition between the laminar and turbulent regimes. In the source code (pipe.ssc), the pressure loss is calculate on lines 241-245 using a function called "foundation.gas.elements.pipe_friction". You can select the string and do a Ctrl+D to view its code.
In the "pipe_friction.ssc" code, both the laminar and the turbulent pressure drop are calculated, and they are "blended" based on Reynolds number. See line 27:
This blend function is a cubic function that transitions smoothly between 0 and 1. You can view its code as well.
does this resembles what you trying to do?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Foundation and Custom Domains 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by