Unit problem in a Simscape custom block

3 次查看(过去 30 天)
Hi everyone,
I'm facing a unit problem when building a Simscape custom block. I'm using the flow rate (Q) that I imported in the section 'branches' and declared as a variable specifying the unit (m^3/s). But when I use Q in the equation section it happened to be in cm^3/s which make my equation wrong. How can I fix that ?
Thanks in advance,
Nils

采纳的回答

Anushka
Anushka 2025-3-26
编辑:Anushka 2025-3-26
Hi @Nils,
According to my understanding, the error suggests that there is a mismatch or incorrect assignment of units within the component, specifically related to the flow rate 'Q'.
Here are some steps and tips to resolve unit conversion issues in Simscape:
1. Global Unit Setting in Simulink Configuration:
  • Go to the Simulink model’s Configuration Parameters window.
  • Navigate to "Simscape" and check the default units and unit conversion settings to ensure that they align with your component expectations.
  • Make changes if needed to ensure consistency in units like m^3/s for flow rate.
2. Check Variable Declarations:
  • Verify that there are no other initializations or assignments within your code that might implicitly convert units. For example, confirm that 'Q' is declared without any units indicated like cm^3/s outside of your immediate code.
3. Custom Unit Definition (if needed):
  • Create a custom unit within the Simulink model, if applicable, to specify m^3/s. This can force the system to use the desired dimension.
4. Reviewing Component Equations:
  • In your component equations, ensure all quantities used have compatible units. Check divisions and multiplications, especially those involving constants and parameters (rho,g,r).
Once the changes are made:
  • Rebuild the Model: After revising the unit settings and variable declarations, rebuild and simulate the model to check for errors.
  • Unit Verification: Utilize Simscape logging to verify the units of all variables during simulation. This logging can help ensure that 'Q' is indeed using m^3/sas intended.
Hope this helps!
  3 个评论
Anushka
Anushka 2025-3-26
Hello,
Upon reviewing your Simscape component, the issue arises due to the incorrect unit handling in the equations section. The line:
T == {eta * rho * Q * r * sqrt(H_head * g/2), 'N*m'};
is applying the unit to the entire expression, but Simscape already handles unit consistency automatically during simulation. The {} syntax is only needed for variable or parameter definitions, not in dynamic equations.
The following steps will help you resolve the issue:
  1. Fix the Equation Syntax:
Replace:
T == {eta * rho * Q * r * sqrt(H_head * g/2), 'N*m'};
With:
T == eta * rho * Q * r * sqrt(H_head * g/2);
This will ensure the units are handled correctly during simulation.
2. Force Unit Consistency (if needed):
If the issues persists, explicitly cast the units using:
T == eta * rho * unitConversionFactor(Q, 'm^3/s') * r * sqrt(H_head * g/2);
This guarantees that Q is treated in m^3/s during computation.
After making these changes , rebuild and simulate your model. You can use Simscape logging to verify the units during the simulation and confirm that Q is in m^3/s as expected.
Nils
Nils 2025-3-26
The first solution worked, thanks a lot for your help !

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by