Simscape Inheritance - Parameters as structs or objects

8 visualizaciones (últimos 30 días)
Trent Gatz
Trent Gatz el 15 de Abr. de 2025
Comentada: Trent Gatz el 24 de Abr. de 2025
Problem:
I would like to use custom structs or objects to override built-in simscape component parameters, eventually via a drop down menu (with enums).
Note, I have started by using the following documenation as a baseline. My issue seems to be with defining simscape parameters as structs or objects: https://www.mathworks.com/help/simscape/lang/subclassing-and-inheritance.html
I am trying to override the foundation.thermal_liquid.utilities.thermal_liquid_settings to essentially add my own drop down list of fluids, similar to how foundation.thermal_liquid.utilities.thermal_liquid_properties works.
I have created a namespace for all of my fluids (+fuels).
Desired Behavior:
Interface similar to foundation.thermal_liquid.utilities.thermal_liquid properties, with my own predefined fluids. My implementation works fine it users manually fill in all of the Thermal Liquid Settings parameters with the appropriate fluid.<field> and units; however, I would like to remove this step and allow them to be directly selected from a drop down menu with the rest of the implementation handled behind the scenes.
Attempted Implementation:
In my +fuels namespace, I have functions which create a structure containing the various tables required by thermal_liquid settings. As the simplest example, assume that fluid.my_fluid returns the following:
fluid = fuels.my_fluid % calling my function
>>> fluid =
struct with fields:
t_vect: [1 2 3 4 5]
I try to override these with the following:
component fuelprops < foundation.thermal_liquid.utilities.thermal_liquid_settings(...
T_TLU = {fluid.t_vect, 'K'})
parameters
fluid = fuels.my_fluid;
end
end
When I run ssc_build() on the namespace containing my fuelprops component, I recieve the following error:
No function or value named fluid.t_vect.
I initially thought this might be due to the fact that structs do not necessarily have certain fields, so I tried another implementation with an object which has the property t_vect
classdef MyFluid
properties
t_vect = [1:5]
end
methods
function self = MyFluid()
end
end
end
With this implementation, I recieve the below error:
No function or value named fluid.t_vect
Again, this issue persists even if I create a method "t_vect" which returns the desired array.
Is there any way to setup Simscape Components to take in objects or structs which override parameters from inheritent components? I full expect the above example to error as [1:5] is not a valid value for T_TLU; however, the value I am entering seems to never been seen.

Respuesta aceptada

Yifeng Tang
Yifeng Tang el 22 de Abr. de 2025
I think it's possible to mimic the code inside Thermal Liquid Properties to do what you envisions.
(1) define a class for the dropdown options
(2) define one .m file for each fluid, containing the lookup tables of the properties.
(3) write a function to grab the right fluid properties based on dropdown selection, and assign the properties to a bunch of lookup tables
(4) use something like this to assign the properties to the Simscape domain. This is visible in the Thermal Liquid Settings block.
% Assign domain parameters
nodes
A = foundation.thermal_liquid.thermal_liquid( ...
...
)
end
I understand this may be a bit difficult to implement since you can't view the Simscape code of the Thermal Liquid Properties block. Do you have access to your MathWorks account representative? Maybe reach out to them and see whether application engineering support would be possible. You may mention this post.
  1 comentario
Trent Gatz
Trent Gatz el 24 de Abr. de 2025
This worked. The only thing I'll add is that I needed to create an individual function for each parameter I wanted to extract from the struct. So the final setup ended up being:
  • Enum class to define each of the fluids
  • one function per fluid to create a structure of all lookup tables
  • one function per property to return the lookup table from the structure.
It seems that in *.ssc files, you cannot have structures, but as long as the functions are only returning arrays, evertything works fine.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by