title: Limit tank flow when level <= 0 in Modelica
body: <p>I have a model of a tank that I am creating as follows:</p>
  
  <pre><code>model Tank "Simple model of a tank"
    parameter Real volume=1 "tank volume (m^3)";
      parameter Integer num_ports=1 "Number of ports";
      parameter Real static_pressure=1 "Internal Tank Pressure";
      parameter Real initial_level = 0;
      Stream[num_ports] ports "Stream Connectors";
      Real level "Level in % 0-100";
      protected
      Real vol "Volume of medium in the tank";
      Real pressure(start=static_pressure) "Pressure inside the tank";
  
    initial equation
      level = initial_level;
  
      /* Pressure */
      equation
        pressure = vol * 0.01;  // Add correct factor here to get from volume to pressure change (based on height and head)
        for i in 1:num_ports loop
          ports[i].pressure = static_pressure + pressure;
        end for;
  
      /* Volume Flow */
      equation
        der(vol) = sum(ports.m_flow);  // Add density factor to get form mass flow to Volume Flow
        level = vol * 100 / volume;
  
    end Tank;
  </code></pre>
  
  <p>How can I make it so that when the level &lt;=0 the tank will not allow any flows with a negative value (no ports can have fluid leaving, but fluid can still enter)? I feel like I am missing something trivial, but can't seem to find a way without having too many equations (over-determined system).</p>
  
  <p>Thanks</p>