model MassFractions "Ideal one port mass fraction sensor"
extends Modelica.Fluid.Sensors.BaseClasses.PartialAbsoluteSensor;
extends Modelica.Icons.RotationalSensor;
parameter String substanceName = "water" "Name of mass fraction";
Modelica.Blocks.Interfaces.RealOutput Xi "Mass fraction in port medium"
annotation (Placement(transformation(extent = {
{100, -10},
{120, 10}})));
protected
parameter Integer ind(fixed = false) "Index of species in vector of independent mass fractions";
Medium.MassFraction XiVec[Medium.nXi] "Mass fraction vector, needed because indexed argument for the operator inStream is not supported";
initial algorithm
ind := -1;
for i in 1:Medium.nXi loop
if Modelica.Utilities.Strings.isEqual(Medium.substanceNames[i], substanceName) then
ind := i;
end if;
end for;
assert(0 < ind, "Mass fraction '" + substanceName + "' is not present in medium '" + Medium.mediumName + "'.\n" + "Check sensor parameter and medium model.");
equation
Xi = XiVec[ind];
XiVec = inStream(port.Xi_outflow);
annotation (
defaultComponentName = "massFraction",
Icon(
coordinateSystem(
preserveAspectRatio = false,
extent = {
{-100, -100},
{100, 100}}),
graphics = {
Line(
points = {
{0, -70},
{0, -100}},
color = {0, 0, 127}),
Text(
extent = {
{-150, 80},
{150, 120}},
textString = "%name",
lineColor = {0, 0, 255}),
Text(
extent = {
{160, -30},
{60, -60}},
textString = "Xi"),
Line(
points = {
{70, 0},
{100, 0}},
color = {0, 0, 127})}),
Documentation(
info = "<html>\n<p>\nThis component monitors the mass fraction contained in the fluid passing its port.\nThe sensor is ideal, i.e., it does not influence the fluid.\n</p>\n</html>",
revisions = "<html>\n<ul>\n<li>2011-12-14: Stefan Wischhusen: Initial Release.</li>\n</ul>\n</html>"));
end MassFractions;