Transition between two sets of equations in Simscape (Fuids) Custom component
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Yifeng Tang
el 14 de Feb. de 2025
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?
Respuestas (0)
Ver también
Categorías
Más información sobre Foundation and Custom Domains en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!