Changeset 1947

Show
Ignore:
Timestamp:
12/05/2008 01:55:51 AM (5 weeks ago)
Author:
mwetter
Message:

Added sensors to measure trace substances.
Added test model for new sensors.
These sensors are needed, for example, to model CO2-based room ventilation.

Location:
Modelica_Fluid/branches/StreamConnector/Modelica_Fluid
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Sensors.mo

    r1927 r1947  
    2828      revisions="<html> 
    2929<ul> 
     30<li><i>4 Dec 2008</i> 
     31    by Michael Wetter<br> 
     32       included sensors for trace substance</li> 
    3033<li><i>31 Oct 2007</i> 
    3134    by Carsten Heinrich<br> 
     
    553556    end if; 
    554557  end SpecificEntropyTwoPort; 
     558 
     559  model TraceSubstancesOnePort "Ideal one port trace substances sensor" 
     560    extends Sensors.BaseClasses.PartialAbsoluteSensor; 
     561    extends Modelica.Icons.RotationalSensor; 
     562    parameter String substanceName = "CO2" "Name of trace substance"; 
     563 
     564    Modelica.Blocks.Interfaces.RealOutput C "Trace substance in port medium"  
     565      annotation (Placement(transformation(extent={{100,-10},{120,10}}, 
     566            rotation=0))); 
     567 
     568  annotation (defaultComponentName="traceSubstance", 
     569    Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{ 
     570              100,100}}), graphics), 
     571    Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100, 
     572              100}}), graphics={ 
     573          Line(points={{0,-70},{0,-100}}, color={0,0,127}), 
     574          Text( 
     575            extent={{-150,80},{150,120}}, 
     576            textString="%name", 
     577            lineColor={0,0,255}), 
     578          Text( 
     579            extent={{170,-55},{10,-107}}, 
     580            lineColor={0,0,0}, 
     581            textString="C"), 
     582          Line(points={{70,0},{100,0}}, color={0,0,127})}), 
     583    Documentation(info="<HTML> 
     584<p> 
     585This component monitors the trace substance of the medium in the flow 
     586between fluid ports. The sensor is ideal, i.e., it does not influence the fluid. 
     587</p> 
     588</HTML> 
     589")); 
     590  protected 
     591    parameter Integer ind(fixed=false) 
     592      "Index of species in vector of auxiliary substances"; 
     593    Medium.ExtraProperty CVec[Medium.nC]( 
     594        quantity=Medium.extraPropertiesNames) 
     595      "Trace substances vector, needed because indexed argument for the operator inStream is not supported"; 
     596  initial algorithm 
     597    ind:= -1; 
     598    for i in 1:Medium.nC loop 
     599      if ( Modelica.Utilities.Strings.isEqual(Medium.extraPropertiesNames[i], substanceName)) then 
     600        ind := i; 
     601      end if; 
     602    end for; 
     603    assert(ind > 0, "Trace substance '" + substanceName + "' is not present in medium '" 
     604           + Medium.mediumName + "'.\n" 
     605           + "Check sensor parameter and medium model."); 
     606  equation 
     607    CVec = inStream(port.C_outflow); 
     608    C = CVec[ind]; 
     609  end TraceSubstancesOnePort; 
     610 
     611  model TraceSubstancesTwoPort "Ideal two port sensor for trace substance" 
     612    extends Sensors.BaseClasses.PartialFlowSensor; 
     613    extends Modelica.Icons.RotationalSensor; 
     614    Modelica.Blocks.Interfaces.RealOutput C 
     615      "Trace substance of the passing fluid"  
     616      annotation (Placement(transformation( 
     617          origin={0,-110}, 
     618          extent={{-10,-10},{10,10}}, 
     619          rotation=270))); 
     620    parameter String substanceName = "CO2" "Name of trace substance"; 
     621    parameter Medium.MassFlowRate m_flow_small(min=0) = 1e-4 
     622      "For bi-directional flow, trace substance is regularized in the region |m_flow| < m_flow_small (m_flow_small > 0 required)" 
     623      annotation(Dialog(tab="Advanced")); 
     624 
     625  annotation (defaultComponentName="traceSubstance", 
     626    Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{ 
     627              100,100}}), graphics), 
     628    Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100, 
     629              100}}), graphics={ 
     630          Text( 
     631            extent={{-150,80},{150,120}}, 
     632            textString="%name", 
     633            lineColor={0,0,255}), 
     634          Text( 
     635            extent={{168,-71},{8,-123}}, 
     636            lineColor={0,0,0}, 
     637            textString="C"), 
     638          Line(points={{0,-70},{0,-100}}, color={0,0,127}), 
     639          Line(points={{-100,0},{-70,0}}, color={0,128,255}), 
     640          Line(points={{70,0},{100,0}}, color={0,128,255}), 
     641          Line( 
     642            points={{30,-19},{-60,-19}}, 
     643            color={0,128,255}, 
     644            smooth=Smooth.None), 
     645          Polygon( 
     646            points={{20,-4},{60,-19},{20,-34},{20,-4}}, 
     647            lineColor={0,128,255}, 
     648            smooth=Smooth.None, 
     649            fillColor={0,128,255}, 
     650            fillPattern=FillPattern.Solid)}), 
     651    Documentation(info="<HTML> 
     652<p> 
     653This component monitors the trace substance of the passing fluid.  
     654The sensor is ideal, i.e. it does not influence the fluid. 
     655</p> 
     656</HTML> 
     657")); 
     658  protected 
     659    parameter Integer ind(fixed=false) 
     660      "Index of species in vector of auxiliary substances"; 
     661  initial algorithm 
     662    ind:= -1; 
     663    for i in 1:Medium.nC loop 
     664      if ( Modelica.Utilities.Strings.isEqual(Medium.extraPropertiesNames[i], substanceName)) then 
     665        ind := i; 
     666      end if; 
     667    end for; 
     668    assert(ind > 0, "Trace substance '" + substanceName + "' is not present in medium '" 
     669           + Medium.mediumName + "'.\n" 
     670           + "Check sensor parameter and medium model."); 
     671  equation 
     672    if allowFlowReversal then 
     673       C = Modelica_Fluid.Utilities.regStep(port_a.m_flow, port_b.C_outflow[ind], port_a.C_outflow[ind], m_flow_small); 
     674    else 
     675       C = port_b.C_outflow[ind]; 
     676    end if; 
     677  end TraceSubstancesTwoPort; 
    555678 
    556679  model MassFlowRate "Ideal sensor for mass flow rate"