Errors Implement someone else Custom Simscape Block

A model was sent to me with a custom Simcape Library block. The model uses a "custom constant volume chamber block" with the possibility of 7 inputs instead of the default 4 inputs. However, the custom Simscape block gives the following error when I try to run the model:
The class foundation.enum.num_ports has no Constant property or Static method named 'five'.
The custom Simscape Block just returns to the default state with 1 input and only the possibility of 4 inputs. Does anyone know what went wrong with loading the custom Simscape Block in the Simulink Model.
Here's the changes in the source code to accomadate more than 4 inputs:
component constant_volume_chamber_KMA
% Constant Volume Chamber KMA (MA) : 1.5
% This block models mass and energy storage in a moist air network. The
% chamber contains a constant volume of moist air. The pressure and
% temperature evolve based on the compressibility and thermal capacity of
% this moist air volume. Liquid water condenses out of the moist air volume
% when it reaches saturation.
%
% A, B, C, D, E, E1, E2 - Moist air conserving ports associated with the chamber
% inlets.
%
% H - Thermal conserving port associated with the thermal mass of the moist
% air volume.
%
% S - Optional moist air source conserving port for adding or removing
% moisture and trace gas.
%
% W [kg/s] - Physical signal port reporting the rate of condensation.
%
% F - Physical signal port reporting moist air volume measurements. Connect
% to a Measurement Selector (MA) block.
% Copyright 2017-2020 The MathWorks, Inc.
outputs
% Rate of condensation
W = {0, 'kg/s'}; % W:bottom
% Moist air volume measurements
F = zeros(8, 1); % F:bottom
end
nodes
A = foundation.moist_air.moist_air; % A:top
H = foundation.thermal.thermal; % H:bottom
end
nodes (ExternalAccess = none)
B = foundation.moist_air.moist_air; % B:top
C = foundation.moist_air.moist_air; % C:top
D = foundation.moist_air.moist_air; % D:top
E = foundation.moist_air.moist_air; % E:top
E1 = foundation.moist_air.moist_air; % E1:top
E2 = foundation.moist_air.moist_air; % E2:top
% Assign the same domain parameters to the moist air source domain
S = foundation.moist_air.moist_air_source( ...
trace_gas_model = A.trace_gas_model, ...
T_TLU = A.T_TLU, ...
h_w_vap_TLU = A.h_w_vap_TLU, ...
h_w_TLU = A.h_w_TLU, ...
h_g_TLU = A.h_g_TLU, ...
T_min = A.T_min, ...
T_max = A.T_max, ...
T_atm = A.T_atm); % S:bottom
end
parameters
volume = {0.001, 'm^3'}; % Chamber volume
num_ports = foundation.enum.num_ports.one; % Number of ports
% 1 - one
% 2 - two
% 3 - three
% 4 - four
% 5 - five
% 6 - six
% 7 - seven
area_A = {0.01, 'm^2'}; % Cross-sectional area at port A
end
parameters (ExternalAccess = none)
area_B = {0.01, 'm^2'}; % Cross-sectional area at port B
area_C = {0.01, 'm^2'}; % Cross-sectional area at port C
area_D = {0.01, 'm^2'}; % Cross-sectional area at port D
area_E = {0.01, 'm^2'}; % Cross-sectional area at port E
area_E1 = {0.01, 'm^2'}; % Cross-sectional area at port E1
area_E2 = {0.01, 'm^2'}; % Cross-sectional area at port E2
end
parameters
RH_ws = 1; % Relative humidity at saturation
time_constant = {1e-3, 's'}; % Condensation time constant
moisture_trace_gas_source = foundation.enum.moisture_trace_gas_source.none; % Moisture and trace gas source
% 0 - none
% 1 - constant
% 2 - controlled
end
parameters (ExternalAccess = none)
moisture_source_spec = foundation.enum.moisture_source_spec.vapor; % Moisture added or removed
% 1 - vapor
% 2 - liquid
moisture_mass_flow = {0, 'kg/s'}; % Rate of added moisture
moisture_temperature_spec = foundation.enum.temperature_spec.atmospheric; % Added moisture temperature specification
% 1 - atmospheric
% 2 - specified
moisture_temperature = {293.15, 'K' }; % Temperature of added moisture
trace_gas_mass_flow = {0, 'kg/s'}; % Rate of added trace gas
trace_gas_temperature_spec = foundation.enum.temperature_spec.atmospheric; % Added trace gas temperature specification
% 1 - atmospheric
% 2 - specified
trace_gas_temperature = {293.15, 'K' }; % Temperature of added trace gas
end
parameters (Access = private)
x_ag_min = 0.01; % Minimum threshold in denominator of humidity ratio calculation
end
% Parameter groups
annotations
UILayout = [UIGroup('physmod:simscape:library:gui:groups:Main', ...
volume, num_ports, area_A, area_B, area_C, area_D, area_E, area_E1, area_E2)
UIGroup('physmod:simscape:library:tabs:MoistureAndTraceGas', ...
RH_ws, time_constant, moisture_trace_gas_source, moisture_source_spec, ...
moisture_mass_flow, moisture_temperature_spec, moisture_temperature, ...
trace_gas_mass_flow, trace_gas_temperature_spec, trace_gas_temperature)]
end
% Icons
if moisture_trace_gas_source ~= foundation.enum.moisture_trace_gas_source.controlled
if num_ports == foundation.enum.num_ports.one
annotations
Icon = 'constant_volume_chamber.svg';
end
elseif num_ports == foundation.enum.num_ports.two
annotations
Icon = 'constant_volume_chamber_2ports.svg';
end
elseif num_ports == foundation.enum.num_ports.three
annotations
Icon = 'constant_volume_chamber_3ports.svg';
end
elseif num_ports == foundation.enum.num_ports.four
annotations
Icon = 'constant_volume_chamber_4ports.svg';
end
elseif num_ports == foundation.enum.num_ports.five
annotations
Icon = 'constant_volume_chamber_5ports.svg';
end
elseif num_ports == foundation.enum.num_ports.six
annotations
Icon = 'constant_volume_chamber_6ports.svg';
end
else % num_ports == foundation.enum.num_ports.seven
annotations
Icon = 'constant_volume_chamber_7ports.svg';
end
end
else % moisture_trace_gas_source == foundation.enum.moisture_trace_gas_source.controlled
if num_ports == foundation.enum.num_ports.one
annotations
Icon = 'constant_volume_chamber_moisture.svg';
end
elseif num_ports == foundation.enum.num_ports.two
annotations
Icon = 'constant_volume_chamber_2ports_moisture.svg';
end
elseif num_ports == foundation.enum.num_ports.three
annotations
Icon = 'constant_volume_chamber_3ports_moisture.svg';
end
elseif num_ports == foundation.enum.num_ports.four
annotations
Icon = 'constant_volume_chamber_4ports_moisture.svg';
end
elseif num_ports == foundation.enum.num_ports.five
annotations
Icon = 'constant_volume_chamber_5ports_moisture.svg';
end
elseif num_ports == foundation.enum.num_ports.six
annotations
Icon = 'constant_volume_chamber_6ports_moisture.svg';
end
else % num_ports == foundation.enum.num_ports.seven
annotations
Icon = 'constant_volume_chamber_7ports_moisture.svg';
end
end
end
% Parameter visibility
if num_ports > 1.5
annotations
[B, area_B] : ExternalAccess = modify;
[mdot_B, Phi_B, mdot_w_B, mdot_g_B] : ExternalAccess = observe;
end
equations
assert(area_B > 0)
end
end
if num_ports > 2.5
annotations
[C, area_C] : ExternalAccess = modify;
[mdot_C, Phi_C, mdot_w_C, mdot_g_C] : ExternalAccess = observe;
end
equations
assert(area_C > 0)
end
end
if num_ports > 3.5
annotations
[D, area_D] : ExternalAccess = modify;
[mdot_D, Phi_D, mdot_w_D, mdot_g_D] : ExternalAccess = observe;
end
equations
assert(area_D > 0)
end
end
if num_ports > 4.5
annotations
[E, area_E] : ExternalAccess = modify;
[mdot_E, Phi_E, mdot_w_E, mdot_g_E] : ExternalAccess = observe;
end
equations
assert(area_E > 0)
end
end
if num_ports > 5.5
annotations
[E1, area_E1] : ExternalAccess = modify;
[mdot_E1, Phi_E1, mdot_w_E1, mdot_g_E1] : ExternalAccess = observe;
end
equations
assert(area_E1 > 0)
end
end
if num_ports > 6.5
annotations
[E2, area_E2] : ExternalAccess = modify;
[mdot_E2, Phi_E2, mdot_w_E2, mdot_g_E2] : ExternalAccess = observe;
end
equations
assert(area_E2 > 0)
end
end
if moisture_trace_gas_source == foundation.enum.moisture_trace_gas_source.constant
annotations
[moisture_source_spec, moisture_mass_flow, moisture_temperature_spec, ...
trace_gas_mass_flow, trace_gas_temperature_spec] : ExternalAccess = modify;
[Phi_S, mdot_w_S, mdot_g_S] : ExternalAccess = observe;
end
if moisture_temperature_spec == foundation.enum.temperature_spec.specified
annotations
moisture_temperature : ExternalAccess = modify;
end
end
if trace_gas_temperature_spec == foundation.enum.temperature_spec.specified
annotations
trace_gas_temperature : ExternalAccess = modify;
end
end
components (ExternalAccess = none)
moisture_source = foundation.moist_air.sources.moisture_trace_gas.moisture_source( ...
moisture_source_spec = moisture_source_spec, ...
moisture_mass_flow = moisture_mass_flow, ...
temperature_spec = moisture_temperature_spec, ...
moisture_temperature = moisture_temperature);
trace_gas_source = foundation.moist_air.sources.moisture_trace_gas.trace_gas_source( ...
trace_gas_mass_flow = trace_gas_mass_flow, ...
temperature_spec = trace_gas_temperature_spec, ...
trace_gas_temperature = trace_gas_temperature);
end
connections
connect(S, moisture_source.S, trace_gas_source.S)
end
elseif moisture_trace_gas_source == foundation.enum.moisture_trace_gas_source.controlled
annotations
S : ExternalAccess = modify;
[Phi_S, mdot_w_S, mdot_g_S] : ExternalAccess = observe;
end
end
% Parameter checks
equations
assert(volume > 0)
assert(area_A > 0)
assert(RH_ws > 0)
assert(time_constant > 0)
assert(x_ag_min > 0)
assert(x_ag_min < 1)
end
variables
% Default initial conditions
p_I = {value = {0.101325, 'MPa'}, priority = priority.high}; % Pressure of moist air volume
T_I = {value = {293.15, 'K' }, priority = priority.high}; % Temperature of moist air volume
RH_I = {value = 0, priority = priority.high}; % Relative humidity of moist air volume
x_w_I = 0; % Specific humidity of moist air volume
y_w_I = 0; % Water vapor mole fraction of moist air volume
HR_I = 0; % Humidity ratio of moist air volume
x_g_I = {value = 0, priority = priority.high}; % Trace gas mass fraction of moist air volume
y_g_I = 0; % Trace gas mole fraction of moist air volume
end
variables (Access = protected)
mdot_A = {0, 'kg/s'}; % Mixture mass flow rate into port A
Phi_A = {0, 'kW' }; % Mixture energy flow rate into port A
mdot_w_A = {0, 'kg/s'}; % Water vapor mass flow rate into port A
mdot_g_A = {0, 'kg/s'}; % Trace gas mass flow rate into port A
Q_H = {0, 'kW' }; % Heat flow rate into port H
end
variables (Access = protected, ExternalAccess = none)
mdot_B = {0, 'kg/s'}; % Mixture mass flow rate into port B
mdot_C = {0, 'kg/s'}; % Mixture mass flow rate into port C
mdot_D = {0, 'kg/s'}; % Mixture mass flow rate into port D
mdot_E = {0, 'kg/s'}; % Mixture mass flow rate into port E
mdot_E1 = {0, 'kg/s'}; % Mixture mass flow rate into port E1
mdot_E2 = {0, 'kg/s'}; % Mixture mass flow rate into port E2
Phi_B = {0, 'kW' }; % Mixture energy flow rate into port B
Phi_C = {0, 'kW' }; % Mixture energy flow rate into port C
Phi_D = {0, 'kW' }; % Mixture energy flow rate into port D
Phi_E = {0, 'kW' }; % Mixture energy flow rate into port E
Phi_E1 = {0, 'kW' }; % Mixture energy flow rate into port E1
Phi_E2 = {0, 'kW' }; % Mixture energy flow rate into port E2
Phi_S = {0, 'kW' }; % Mixture energy flow rate into port S
mdot_w_B = {0, 'kg/s'}; % Water vapor mass flow rate into port B
mdot_w_C = {0, 'kg/s'}; % Water vapor mass flow rate into port C
mdot_w_D = {0, 'kg/s'}; % Water vapor mass flow rate into port D
mdot_w_E = {0, 'kg/s'}; % Water vapor mass flow rate into port E
mdot_w_E1 = {0, 'kg/s'}; % Water vapor mass flow rate into port E1
mdot_w_E2 = {0, 'kg/s'}; % Water vapor mass flow rate into port E2
mdot_w_S = {0, 'kg/s'}; % Water vapor mass flow rate into port S
mdot_g_B = {0, 'kg/s'}; % Trace gas mass flow rate into port B
mdot_g_C = {0, 'kg/s'}; % Trace gas mass flow rate into port C
mdot_g_D = {0, 'kg/s'}; % Trace gas mass flow rate into port D
mdot_g_E = {0, 'kg/s'}; % Trace gas mass flow rate into port E
mdot_g_E1 = {0, 'kg/s'}; % Trace gas mass flow rate into port E1
mdot_g_E2 = {0, 'kg/s'}; % Trace gas mass flow rate into port E2
mdot_g_S = {0, 'kg/s'}; % Trace gas mass flow rate into port S
end
branches
mdot_A : A.mdot -> *;
mdot_B : B.mdot -> *;
mdot_C : C.mdot -> *;
mdot_D : D.mdot -> *;
mdot_E : E.mdot -> *;
mdot_E1 : E1.mdot -> *;
mdot_E2 : E2.mdot -> *;
Phi_A : A.Phi -> *;
Phi_B : B.Phi -> *;
Phi_C : C.Phi -> *;
Phi_D : D.Phi -> *;
Phi_E : E.Phi -> *;
Phi_E1 : E1.Phi -> *;
Phi_E2 : E2.Phi -> *;
Phi_S : S.Phi -> *;
mdot_w_A : A.mdot_w -> *;
mdot_w_B : B.mdot_w -> *;
mdot_w_C : C.mdot_w -> *;
mdot_w_D : D.mdot_w -> *;
mdot_w_E : E.mdot_w -> *;
mdot_w_E1 : E1.mdot_w -> *;
mdot_w_E2 : E2.mdot_w -> *;
mdot_w_S : S.mdot_w -> *;
mdot_g_A : A.mdot_g -> *;
mdot_g_B : B.mdot_g -> *;
mdot_g_C : C.mdot_g -> *;
mdot_g_D : D.mdot_g -> *;
mdot_g_E : E.mdot_g -> *;
mdot_g_E1 : E1.mdot_g -> *;
mdot_g_E2 : E2.mdot_g -> *;
mdot_g_S : S.mdot_g -> *;
Q_H : H.Q -> *;
end
intermediates (Access = private, ExternalAccess = none)
% Domain parameters
trace_gas_model = A.trace_gas_model;
R_a = A.R_a;
R_w = A.R_w;
R_g = A.R_g;
T_TLU = A.T_TLU;
log_p_ws_TLU = A.log_p_ws_TLU;
h_w_vap_TLU = A.h_w_vap_TLU;
h_a_TLU = A.h_a_TLU;
h_w_TLU = A.h_w_TLU;
h_g_TLU = A.h_g_TLU;
cp_a_coeff = A.cp_a_coeff;
cp_w_coeff = A.cp_w_coeff;
cp_g_coeff = A.cp_g_coeff;
% Set trace gas to zero when there is no trace gas
[x_g_used, y_g_used] = ...
if trace_gas_model == foundation.enum.trace_gas_model.none, ...
0; ...
0 ...
else ...
x_g_I; ...
y_g_I ...
end;
% Mixture specific gas constant
R_I = foundation.moist_air.mixture_property(R_a, R_w, R_g, x_w_I, x_g_used, trace_gas_model);
% Specific enthalpy
h_a_I = tablelookup(T_TLU, h_a_TLU, T_I, interpolation = linear, extrapolation = linear);
h_w_I = tablelookup(T_TLU, h_w_TLU, T_I, interpolation = linear, extrapolation = linear);
h_g_I = tablelookup(T_TLU, h_g_TLU, T_I, interpolation = linear, extrapolation = linear);
% Specific internal energy
u_a_I = h_a_I - R_a*T_I;
u_w_I = h_w_I - R_w*T_I;
u_g_I = h_g_I - R_g*T_I;
u_I = h_I - R_I*T_I;
% Mixture specific heat
T_I_val = value(simscape.function.limit(T_I, A.T_min, A.T_max, false), 'K');
T_I_vec = [1, T_I_val, T_I_val^2];
cp_I = foundation.moist_air.mixture_property( ...
T_I_vec * cp_a_coeff, ...
T_I_vec * cp_w_coeff, ...
T_I_vec * cp_g_coeff, ...
x_w_I, x_g_used, trace_gas_model);
% Mass fraction of dry air plus trace gas
% Protect against going to zero
x_ag_I = ...
if ge(1 - x_w_I, x_ag_min), ...
1 - x_w_I ...
elseif ge(1 - x_w_I, -10*x_ag_min), ...
x_ag_min*exp((1 - x_w_I - x_ag_min)/x_ag_min) ...
else ...
x_ag_min*exp(-11) ...
end;
% Gas constant for dry air plus trace gas
R_ag_I = R_a + x_g_used/x_ag_I*(R_g - R_a);
% Ratio of pressure to water vapor saturation pressure
p_ws_ratio_I = exp(log(value(p_I, 'Pa')) - tablelookup(T_TLU, log_p_ws_TLU, T_I, interpolation = linear, extrapolation = linear)); % Ratio of pressure to water vapor saturation pressure
% Specific humidity at saturation
x_ws_I = ...
if ge(p_ws_ratio_I, RH_ws), ...
R_ag_I / (R_ag_I + R_w*(p_ws_ratio_I/RH_ws - 1)) ...
else ...
1 ...
end;
% Rate of condensation
% Smooth transition for specific humidity exceeding saturation value
mdot_w_condense = simscape.function.blend(0, x_w_I - x_ws_I, 0, 0.01*x_ws_I, x_w_I - x_ws_I) ...
* rho_I * volume / time_constant;
% Water specific enthalpy of vaporization
h_w_vap_I = tablelookup(T_TLU, h_w_vap_TLU, T_I, interpolation = linear, extrapolation = linear);
% Liquid water specific enthalpy removed due to condensation
Phi_w_condense = mdot_w_condense*(h_w_I - h_w_vap_I);
% Net flow rates
mdot_total = ...
if trace_gas_model == foundation.enum.trace_gas_model.none, ...
mdot_A + mdot_B + mdot_C + mdot_D + mdot_E + mdot_E1 + mdot_E2 + mdot_w_S - mdot_w_condense ...
else ...
mdot_A + mdot_B + mdot_C + mdot_D + mdot_E + mdot_E1 + mdot_E2 + mdot_w_S + mdot_g_S - mdot_w_condense ...
end;
Phi_total = Phi_A + Phi_B + Phi_C + Phi_D + Phi_E + Phi_E1 + Phi_E2 + Q_H + Phi_S - Phi_w_condense;
mdot_w_total = mdot_w_A + mdot_w_B + mdot_w_C + mdot_w_D + mdot_w_E + mdot_w_E1 + mdot_w_E2 + mdot_w_S - mdot_w_condense;
mdot_g_total = ...
if trace_gas_model == foundation.enum.trace_gas_model.none, ...
0 ...
else ...
mdot_g_A + mdot_g_B + mdot_g_C + mdot_g_D + mdot_g_E + mdot_g_E1 + mdot_g_E2 + mdot_g_S ...
end;
end
% For logging
intermediates (Access = private)
rho_I = p_I / (R_I * T_I); % Mixture density of moist air volume
h_I = foundation.moist_air.mixture_property(h_a_I, h_w_I, h_g_I, x_w_I, x_g_used, trace_gas_model); % Mixture specific enthalpy of moist air volume
x_a_I = 1 - x_w_I - x_g_used; % Dry air mass fraction of moist air volume
end
equations
% Assume no flow resistance
A.p == p_I;
B.p == p_I;
C.p == p_I;
D.p == p_I;
E.p == p_I;
E1.p == p_I;
E2.p == p_I;
% Assume no thermal resistance
H.T == T_I;
% Mixture mass conservation
(der(p_I)/p_I - der(T_I)/T_I)*rho_I*volume ...
+ (R_a - R_w)/R_I * (mdot_w_total - x_w_I*mdot_total) ...
+ (R_a - R_g)/R_I * (mdot_g_total - x_g_used*mdot_total) ...
== mdot_total;
% Mixture energy conservation
der(T_I)*(cp_I - R_I)*rho_I*volume ...
+ (u_w_I - u_a_I)*(mdot_w_total - x_w_I*mdot_total) ...
+ (u_g_I - u_a_I)*(mdot_g_total - x_g_used*mdot_total) ...
+ u_I*mdot_total ...
== Phi_total;
% Water vapor mass conservation
der(x_w_I)*rho_I*volume + x_w_I*mdot_total == mdot_w_total;
% Trace gas mass conservation
if trace_gas_model == foundation.enum.trace_gas_model.none
der(x_g_I) == 0;
else
der(x_g_I)*rho_I*volume + x_g_I*mdot_total == mdot_g_total;
end
% Relative humidity
RH_I * R_I / R_w == x_w_I * p_ws_ratio_I;
% Water vapor mole fraction
y_w_I * R_I / R_w == x_w_I;
% Humidity ratio
HR_I * x_ag_I == x_w_I;
% Trace gas mole fraction
y_g_I * R_I / R_g == x_g_I;
% Rate of condensation
W == mdot_w_condense;
% Moist air volume measurements
F == [value(p_I, 'Pa'); value(T_I, 'K'); RH_I; x_w_I; y_w_I; HR_I; x_g_used; y_g_used];
% Moist air source conserving port
S.T == T_I;
S.x_w == x_w_I;
S.x_g == x_g_used;
% Run-time variable checks
assert(ge(mdot_w_S, 0) || gt(x_w_I, 0), message('physmod:simscape:library:moist_air:CannotRemoveMoisture'))
assert(ge(mdot_g_S, 0) || gt(x_g_used, 0), message('physmod:simscape:library:moist_air:CannotRemoveTraceGas'))
assert(p_I >= A.p_min)
assert(p_I <= A.p_max)
assert(T_I >= A.T_min)
assert(T_I <= A.T_max)
end
% Variable checks for initial condition solve
equations (Initial = true)
assert(RH_I <= p_ws_ratio_I)
assert(RH_I <= RH_ws)
assert(x_w_I <= 1)
if trace_gas_model == foundation.enum.trace_gas_model.none
else
assert(x_g_I <= 1)
end
assert(x_a_I >= 0)
end
% Internal component that calculates convection at port A
% Convection for mixture energy flow rate, water vapor mass flow rate, and trace gas mass flow rate
components (ExternalAccess = none)
convection_A = foundation.moist_air.port_convection(flow_area = area_A, length_scale = sqrt(4*area_A/pi));
end
connections
connect(A, convection_A.port)
end
% Equate variables for internal component that calculates convection at port A
equations
convection_A.mdot == mdot_A;
convection_A.Phi == Phi_A;
convection_A.mdot_w == mdot_w_A;
convection_A.mdot_g == mdot_g_A;
convection_A.ht_I == h_I + (R_I*T_I/p_I)*abs(R_I*T_I/p_I)*(mdot_A/area_A)^2/2;
convection_A.x_w_I == simscape.function.limit(x_w_I, 0, 1, false);
convection_A.x_g_I == simscape.function.limit(x_g_used, 0, 1, false);
end
if num_ports > 1.5
% Internal component that calculates convection at port B
% Convection for mixture energy flow rate, water vapor mass flow rate, and trace gas mass flow rate
components (ExternalAccess = none)
convection_B = foundation.moist_air.port_convection(flow_area = area_B, length_scale = sqrt(4*area_B/pi));
end
connections
connect(B, convection_B.port)
end
% Equate variables for internal component that calculates convection at port B
equations
convection_B.mdot == mdot_B;
convection_B.Phi == Phi_B;
convection_B.mdot_w == mdot_w_B;
convection_B.mdot_g == mdot_g_B;
convection_B.ht_I == h_I + (R_I*T_I/p_I)*abs(R_I*T_I/p_I)*(mdot_B/area_B)^2/2;
convection_B.x_w_I == simscape.function.limit(x_w_I, 0, 1, false);
convection_B.x_g_I == simscape.function.limit(x_g_used, 0, 1, false);
end
else
equations
B.T == T_I;
B.x_w == x_w_I;
B.x_g == x_g_used;
end
end
if num_ports > 2.5
% Internal component that calculates convection at port C
% Convection for mixture energy flow rate, water vapor mass flow rate, and trace gas mass flow rate
components (ExternalAccess = none)
convection_C = foundation.moist_air.port_convection(flow_area = area_C, length_scale = sqrt(4*area_C/pi));
end
connections
connect(C, convection_C.port)
end
% Equate variables for internal component that calculates convection at port C
equations
convection_C.mdot == mdot_C;
convection_C.Phi == Phi_C;
convection_C.mdot_w == mdot_w_C;
convection_C.mdot_g == mdot_g_C;
convection_C.ht_I == h_I + (R_I*T_I/p_I)*abs(R_I*T_I/p_I)*(mdot_C/area_C)^2/2;
convection_C.x_w_I == simscape.function.limit(x_w_I, 0, 1, false);
convection_C.x_g_I == simscape.function.limit(x_g_used, 0, 1, false);
end
else
equations
C.T == T_I;
C.x_w == x_w_I;
C.x_g == x_g_used;
end
end
if num_ports > 3.5
% Internal component that calculates convection at port D
% Convection for mixture energy flow rate, water vapor mass flow rate, and trace gas mass flow rate
components (ExternalAccess = none)
convection_D = foundation.moist_air.port_convection(flow_area = area_D, length_scale = sqrt(4*area_D/pi));
end
connections
connect(D, convection_D.port)
end
% Equate variables for internal component that calculates convection at port D
equations
convection_D.mdot == mdot_D;
convection_D.Phi == Phi_D;
convection_D.mdot_w == mdot_w_D;
convection_D.mdot_g == mdot_g_D;
convection_D.ht_I == h_I + (R_I*T_I/p_I)*abs(R_I*T_I/p_I)*(mdot_D/area_D)^2/2;
convection_D.x_w_I == simscape.function.limit(x_w_I, 0, 1, false);
convection_D.x_g_I == simscape.function.limit(x_g_used, 0, 1, false);
end
else
equations
D.T == T_I;
D.x_w == x_w_I;
D.x_g == x_g_used;
end
end
if num_ports > 4.5
% Internal component that calculates convection at port E
% Convection for mixture energy flow rate, water vapor mass flow rate, and trace gas mass flow rate
components (ExternalAccess = none)
convection_E = foundation.moist_air.port_convection(flow_area = area_E, length_scale = sqrt(4*area_E/pi));
end
connections
connect(E, convection_E.port)
end
% Equate variables for internal component that calculates convection at port E
equations
convection_E.mdot == mdot_E;
convection_E.Phi == Phi_E;
convection_E.mdot_w == mdot_w_E;
convection_E.mdot_g == mdot_g_E;
convection_E.ht_I == h_I + (R_I*T_I/p_I)*abs(R_I*T_I/p_I)*(mdot_E/area_E)^2/2;
convection_E.x_w_I == simscape.function.limit(x_w_I, 0, 1, false);
convection_E.x_g_I == simscape.function.limit(x_g_used, 0, 1, false);
end
else
equations
E.T == T_I;
E.x_w == x_w_I;
E.x_g == x_g_used;
end
end
if num_ports > 5.5
% Internal component that calculates convection at port E1
% Convection for mixture energy flow rate, water vapor mass flow rate, and trace gas mass flow rate
components (ExternalAccess = none)
convection_E1 = foundation.moist_air.port_convection(flow_area = area_E1, length_scale = sqrt(4*area_E1/pi));
end
connections
connect(E1, convection_E1.port)
end
% Equate variables for internal component that calculates convection at port E1
equations
convection_E1.mdot == mdot_E1;
convection_E1.Phi == Phi_E1;
convection_E1.mdot_w == mdot_w_E1;
convection_E1.mdot_g == mdot_g_E1;
convection_E1.ht_I == h_I + (R_I*T_I/p_I)*abs(R_I*T_I/p_I)*(mdot_E1/area_E1)^2/2;
convection_E1.x_w_I == simscape.function.limit(x_w_I, 0, 1, false);
convection_E1.x_g_I == simscape.function.limit(x_g_used, 0, 1, false);
end
else
equations
E1.T == T_I;
E1.x_w == x_w_I;
E1.x_g == x_g_used;
end
end
if num_ports > 6.5
% Internal component that calculates convection at port E2
% Convection for mixture energy flow rate, water vapor mass flow rate, and trace gas mass flow rate
components (ExternalAccess = none)
convection_E2 = foundation.moist_air.port_convection(flow_area = area_E2, length_scale = sqrt(4*area_E2/pi));
end
connections
connect(E2, convection_E2.port)
end
% Equate variables for internal component that calculates convection at port E2
equations
convection_E2.mdot == mdot_E2;
convection_E2.Phi == Phi_E2;
convection_E2.mdot_w == mdot_w_E2;
convection_E2.mdot_g == mdot_g_E2;
convection_E2.ht_I == h_I + (R_I*T_I/p_I)*abs(R_I*T_I/p_I)*(mdot_E2/area_E2)^2/2;
convection_E2.x_w_I == simscape.function.limit(x_w_I, 0, 1, false);
convection_E2.x_g_I == simscape.function.limit(x_g_used, 0, 1, false);
end
else
equations
E2.T == T_I;
E2.x_w == x_w_I;
E2.x_g == x_g_used;
end
end
end

Answers (0)

Products

Release

R2021a

Asked:

on 7 Feb 2022

Community Treasure Hunt

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

Start Hunting!