Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions ThermofluidStream/Sensors/DifferenceSensorSelect.mo
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ model DifferenceSensorSelect "Sensor for selectable quantatiy difference"
protected
Real direct_value(unit=Internal.getUnit(quantity));

function getQuantityA = Internal.getQuantity(redeclare package Medium=MediumA) "Quantity compute function A"
Internal.GetQuantity getQuantityA(redeclare package Medium=MediumA, quantity=quantity, rho_min=rho_min) "Quantity compute function"
annotation (Documentation(info="<html>
<p>This function computes the selected quantity from state. r and rho_min are neddet for the quantities r/p_total and v respectively.</p>
<p>This block computes the selected quantity from state. r and rho_min are needed for the quantities r/p_total and v respectively.</p>
</html>"));
function getQuantityB = Internal.getQuantity(redeclare package Medium=MediumB) "Quantity compute function B"
Internal.GetQuantity getQuantityB(redeclare package Medium=MediumB, quantity=quantity, rho_min=rho_min) "Quantity compute function"
annotation (Documentation(info="<html>
<p>This function computes the selected quantity from state. r and rho_min are neddet for the quantities r/p_total and v respectively.</p>
<p>This block computes the selected quantity from state. r and rho_min are needed for the quantities r/p_total and v respectively.</p>
</html>"));

initial equation
Expand All @@ -90,8 +90,14 @@ equation
inletA.m_flow = 0;
inletB.m_flow = 0;

valueA = getQuantityA(inletA.state, inletA.r, quantity, rho_min);
valueB = getQuantityB(inletB.state, inletB.r, quantity, rho_min);
getQuantityA.r = inletA.r;
getQuantityA.state = inletA.state;

getQuantityB.r = inletB.r;
getQuantityB.state = inletB.state;

valueA = getQuantityA.value;
valueB = getQuantityB.value;

direct_value = valueA - valueB;

Expand Down
57 changes: 57 additions & 0 deletions ThermofluidStream/Sensors/Internal/GetQuantity.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
within ThermofluidStream.Sensors.Internal;
block GetQuantity "Computes selected quantity from state"
extends Modelica.Blocks.Icons.Block;
replaceable package Medium = Media.myMedia.Interfaces.PartialMedium "Medium model" annotation(
choicesAllMatching = true,
Documentation(info = "<html>
<p>Medium Model for the function. Make sure it implements the needed functions.</p>
</html>"));
parameter Types.Quantities quantity;
parameter Modelica.Units.SI.Density rho_min;

input Medium.ThermodynamicState state;
input Modelica.Units.SI.Pressure r;
output Real value;
equation
if quantity == Types.Quantities.T_K then
value = Medium.temperature(state);
elseif quantity == Types.Quantities.T_C then
value = Modelica.Units.Conversions.to_degC(Medium.temperature(state));
elseif quantity == Types.Quantities.p_Pa then
value = Medium.pressure(state);
elseif quantity == Types.Quantities.p_bar then
value = Modelica.Units.Conversions.to_bar(Medium.pressure(state));
elseif quantity == Types.Quantities.r_Pa then
value = r;
elseif quantity == Types.Quantities.r_bar then
value = Modelica.Units.Conversions.to_bar(r);
elseif quantity == Types.Quantities.p_total_Pa then
value = Medium.pressure(state) + r;
elseif quantity == Types.Quantities.p_total_bar then
value = Modelica.Units.Conversions.to_bar(Medium.pressure(state) + r);
elseif quantity == Types.Quantities.h_Jpkg then
value = Medium.specificEnthalpy(state);
elseif quantity == Types.Quantities.s_JpkgK then
value = Medium.specificEntropy(state);
elseif quantity == Types.Quantities.rho_kgpm3 then
value = Medium.density(state);
elseif quantity == Types.Quantities.v_m3pkg then
value = 1/(max(rho_min, Medium.density(state)));
elseif quantity == Types.Quantities.a_mps then
value = Medium.velocityOfSound(state);
elseif quantity == Types.Quantities.cv_JpkgK then
value = Medium.specificHeatCapacityCv(state);
elseif quantity == Types.Quantities.cp_JpkgK then
value = Medium.specificHeatCapacityCp(state);
elseif quantity == Types.Quantities.kappa_1 then
value = Medium.isentropicExponent(state);
elseif quantity == Types.Quantities.MM_kgpmol then
value = Medium.molarMass(state);
else
value = 0;
end if;
annotation(
Documentation(info = "<html>
<p>Helper block to get a quantity from an Thermofluid state.</p>
</html>"));
end GetQuantity;
4 changes: 2 additions & 2 deletions ThermofluidStream/Sensors/Internal/getQuantity.mo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
within ThermofluidStream.Sensors.Internal;
function getQuantity "Computes selected quantity from state"
extends Modelica.Icons.Function;
extends Modelica.Icons.ObsoleteModel;

replaceable package Medium = Media.myMedia.Interfaces.PartialMedium
"Medium model"
Expand Down Expand Up @@ -54,7 +54,7 @@ algorithm
value :=0;
end if;

annotation (Documentation(info="<html>
annotation (Documentation(obsolete="Use Sensors.Internal.GetQuantity instead", info="<html>
<p>Helper function to get a quantity from an Thermofluid state.</p>
</html>"));
end getQuantity;
1 change: 1 addition & 0 deletions ThermofluidStream/Sensors/Internal/package.order
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Types
getQuantity
GetQuantity
getFlowQuantity
getTwoPhaseQuantity
getUnit
Expand Down
9 changes: 6 additions & 3 deletions ThermofluidStream/Sensors/SingleSensorSelect.mo
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ model SingleSensorSelect "Selectable sensor"
protected
Real direct_value(unit=Internal.getUnit(quantity));

function getQuantity = Internal.getQuantity(redeclare package Medium=Medium) "Quantity compute function"
Internal.GetQuantity getQuantity(redeclare package Medium=Medium, quantity=quantity, rho_min=rho_min) "Quantity compute function"
annotation (Documentation(info="<html>
<p>This function computes the selected quantity from state. r and rho_min are neddet for the quantities r/p_total and v respectively.</p>
<p>This block computes the selected quantity from state. r and rho_min are needed for the quantities r/p_total and v respectively.</p>
</html>"));

initial equation
Expand All @@ -70,8 +70,11 @@ initial equation
end if;

equation
getQuantity.r = inlet.r;
getQuantity.state = inlet.state;

inlet.m_flow = 0;
direct_value = getQuantity(inlet.state, inlet.r, quantity, rho_min);
direct_value = getQuantity.value;

if filter_output then
der(value) * TC = direct_value-value;
Expand Down
12 changes: 6 additions & 6 deletions ThermofluidStream/Undirected/Sensors/SingleSensorSelect.mo
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ model SingleSensorSelect "Selectable sensor"
transformation(extent={{70,50},{90,70}}),
iconTransformation(extent={{70,50},{90,70}})));

function getQuantity = ThermofluidStream.Sensors.Internal.getQuantity (
redeclare package Medium = Medium) "Quantity compute function"

ThermofluidStream.Sensors.Internal.GetQuantity getQuantity(redeclare package Medium=Medium, quantity=quantity, rho_min=rho_min) "Quantity compute function"
annotation (Documentation(info="<html>
<p>This function computes the selected quantity from state. r and rho_min are neddet for the quantities r/p_total and v respectively.</p>
<p>This block computes the selected quantity from state. r and rho_min are needed for the quantities r/p_total and v respectively.</p>
</html>"));

Real value(unit=ThermofluidStream.Sensors.Internal.getUnit(quantity));
Expand All @@ -66,10 +66,10 @@ initial equation
value = value_0;
end if;


equation

direct_value = getQuantity(state, rear.r, quantity, rho_min);
getQuantity.r = rear.r;
getQuantity.state = state;
direct_value = getQuantity.value;

if filter_output then
der(value) * TC = direct_value-value;
Expand Down