How to convert constants in parameters to variables in inputs in simscape?Invalid use of value 'density'.

12 vues (au cours des 30 derniers jours)
I am trying to write a Simscape component that can define a fluid with variable density. After referring to the code of the "Custom Hydraulic Fluid" block, I moved the definition of density from parameters to inputs. The modified code is as follows:
component rho_fluid
inputs
density = { 1000 , 'kg/m^3' }; % Fluid density, now an input parameter
end
parameters
viscosity_kin = { 18e-6 , 'm^2/s' }; % Kinematic viscosity
bulk = { 0.8e9 , 'Pa' }; % Bulk modulus at atm. pressure and no gas
alpha = { 0.005 , '1' }; % Relative amount of trapped air
range_error = { 2 , '1' }; % Absolute pressure below absolute zero in blocks with fluid compressibility
end
nodes
G = foundation.hydraulic.hydraulic(...
density=density, ...
viscosity_kin=viscosity_kin, ...
bulk=bulk, ...
alpha=alpha, ...
range_error=range_error); % :right
end
equations
assert(density > 0)
assert(viscosity_kin > 0)
assert(bulk > 0)
assert(alpha >= 0)
assert(alpha < 1)
end
end
After running it, an error occurred:
Invalid use of value 'density'.
Can anyone spot my mistake?
  7 commentaires
ms z
ms z le 23 Oct 2024
hi@Yifeng Tang,thank you for your suggestion,i don't care about the effect of temperature in my simulation,and i noticed that in the Thermal liquid settings(TL),the fluid property is specified in tabulated form against both temperature and pressure or against temperature alone.i wonder if i can repurpose the temperature across variable as a "concentration" variable and the density of the fluid only depend on the concentration.Will this work?
Yifeng Tang
Yifeng Tang le 24 Oct 2024
I'm pretty sure it'll work. But it's also a lot of work. See further comments in the "Answer" section.

Connectez-vous pour commenter.

Réponses (2)

Yifeng Tang
Yifeng Tang le 24 Oct 2024
Below is a summary of the discussion in the comments section:
It is not possible to use an input to assign a domain parameter. Assigning a verying density for the whole domain during the course of a simulation creates concerns like violating the conservation of mass.
The application is to "simulate the collection and transportation of minerals in the ocean. Because minerals are distributed differently, I want to use a fluid with a verying density to represent the characteristics of two-phase flow." This will require a custom Simscape domain as the existing domains do not carry a concentration of mineral as an across variable.
As temperature of the fluid is not of concern, a good starting point will be to repurpose the existing thermal liquid (TL) domain, where the other fluid properties, e.g. density, are functions of the temperature and pressure. Rewriting the temperature variable to represent the mineral concentration will allow the density to vary with the concentration.
Below is to answer the follow-up question on a custom Simscape domain for modeling an isothermal liquid with varying density depending on a mineral concentration:
You may repurpose the T variable in the TL domain to represent the mineral concentration. At the same time, the energy flow, Phi, needs to represent the mineral mass flow. Phi will have a unit of kg/s. There are a few options for the unit of T as a concentration: kg/kg of pure water, kg/kg of total mixture, kg/liquid volume, mol/volume, etc. Among these, I think kg/kg of total mixture will be the easiest to work with as domain variables.
There is a port_convection.ssc code of the TL domain that you'll need to understand and modify. It defines the behavior of how other properties (energy, concentration, etc.) may travel with a mass flow. This documentation page explains the numerical scheme behind it. Since Phi is now the mineral flow, the thermal conductivity parameter of the domain needs to be repurposed as a "diffusivity". I'm not sure what happens to the specific heat. Maybe it's no longer necessary?
Once you feel you are done with the domain definition, the fluid property setting block, and the port_convection code, I suggest that you start with the Reservoir, Flow Resistance, and Pressure Source blocks. After that, controlled reservoir, absolute reference, cap, infinite flow resistance, local restriction, sensors, and flow sources. Whenever you see a energy or power related equations, pause and think how they should look now since temperature is no longer relevant.
If you have access to Simscape Fluids, find a Interface (TL-IL) block, whose source code is visible and write yourself a similar one for between the new domain and IL. You may need it later.
Work on the volume, pipe and converter blocks the last. They all contains conservation of energy equations for the fluid volume inside can will require more careful re-derivation of the governing equations. If you don't need the converter blocks, ignore them.
Some general tips:
  • Use the same file structure as the shipping domains. Read the documentation pages on how to properly organize the custom library.
  • Test often. Test more often. Compile your library very often. Build very simple model early and run it. Test with both positive and negative pressure differences and flow directions. Test with near zero conditions as well.
  • Get a copy of the language guide form the PDF documentation page of Simscape.
It's going to be a lot of work. Good luck and have fun.

nick
nick le 13 Oct 2024
Hi @ms z,
The error message indicates that there's an issue with how the 'desnity' input is being used within the node definition. According to the documentation, the relationship between the component variables and its nodes, which carry the Through and Across variables for the domain is defined in branches and equations section respecitvely. You can refer to the following documentation to learn more about this :
The following approach should resolve the error and allow you to define a fluid with variable density in your Simscape model:
component rho_fluid
inputs
density = { 1000, 'kg/m^3' }; % Fluid density, now an input parameter
end
% Define parameters
parameters
viscosity_kin = { 18e-6, 'm^2/s' }; % Kinematic viscosity
bulk = { 0.8e9, 'Pa' }; % Bulk modulus at atm. pressure and no gas
alpha = { 0.005, '1' }; % Relative amount of trapped air
range_error = { 2, '1' }; % Absolute pressure below absolute zero in blocks with fluid compressibility
end
nodes
G = foundation.hydraulic.hydraulic; % :right
end
equations
assert(density > 0, 'Density must be positive');
% Assign input and parameter values to the node
G.density == density;
G.viscosity_kin == viscosity_kin;
G.bulk == bulk;
G.alpha == alpha;
G.range_error == range_error;
assert(viscosity_kin > 0, 'Kinematic viscosity must be positive');
assert(bulk > 0, 'Bulk modulus must be positive');
assert(alpha >= 0, 'Alpha must be non-negative');
assert(alpha < 1, 'Alpha must be less than 1');
end
end
Hope this was helpful.
  3 commentaires
nick
nick le 14 Oct 2024
Modifié(e) : nick le 14 Oct 2024
Did this error occur during using 'ssc_build' to build the component? The conversion to Simscape block worked fine in MATALB R2024a in my system. (Windows).
ms z
ms z le 14 Oct 2024
Hi , nick
I can succeesfully using 'ssc_build' to build the component,the error occured when i run the model,this is the simplified test model

Connectez-vous pour commenter.

Catégories

En savoir plus sur Foundation and Custom Domains dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by