lbl-srg / modelica-buildings

Modelica Buildings library
258 stars 160 forks source link

Separate energy dynamics for heat exchanger solid in Buildings.Fluid.Storage.StratifiedEnhancedInternalHex #434

Closed Mathadon closed 8 years ago

Mathadon commented 9 years ago

The heat exchanger capacitor in Buildings.Fluid.Storage.BaseClasses.IndirectTankHeatExchanger is removed when energyDynamics are steady state. I'd like to have a separate parameter for controlling the energyDynamics of this capacitor and the mixing volume since they can have very different time constants.

I'll make a pull request for this.

mwetter commented 9 years ago

@Mathadon : I added a few more changes to your version on the branch issue434_tanDyn.

In general, the changes are fine, but I wonder if there is a real application that needs this complexity to be added to the library. What is the use case for wanting to have the metal of the heat exchanger using a different dynamic balance than what is used for the fluid inside the heat exchanger? I would think you either are interested in fast dynamics, in which both the fluid and the metal should be modeled dynamically, or you are not, in which case both should be modeled steady-state, and the only dynamics will be the water inside the tank. In view of this, is this really needed to be added to the library?

PartialHexElement also does everything dynamic or everything steady-state.

Mathadon commented 9 years ago

The reason I need this is because the dynamics of the mixing volume are still quite a lot faster than the metal, and this limits the time steps I can take with a fixed time step solver. The metal time constant is relatively large and setting it to steady state therefore also introduces a relatively large error when setting it to steady state. So it's really about optimising speed vs accuracy. So I agree this is a very specific case, but still it's there of course :) Moreover in general it's not good practice to use the same parameter to set two different options. Although you may of course argue about the options being different.

Mathadon commented 9 years ago

Maybe it's better to set energyDynamicsHexSolid = energyDynamicsHex by default to avoid confusion. Edit: I see you already did this.

Mathadon commented 9 years ago

During the Annex meeting in Galway someone was asking for models with multiple levels of detail. The storage tank model may now actually be interesting for them to have a look at, since you can play with the number of segments and the types of energy dynamics?

mwetter commented 9 years ago

@Mathadon : We have two problems with the heat exchanger in the tank, which are both visible from Buildings.Fluid.Storage.Examples.StratifiedEnhancedInternalHex which I reimplemented to test the different heat exchanger configurations.

  1. Using a steady-state energy balance in the heat exchanger will not work for this reason: The fluid temperature is computed using inStream(port_a.h_outflow) (here assuming no flow reversal, but this does not matter as the fluid temperature has to be obtained from some boundary or dynamic volume outside of this component). In this example, the fluid temperature is 80 degC, and the tank is 20 degC. The convection coefficient is non-zero, which is physically correct. Hence, we have a heat flow rate from the heat exchanger into the tank, which is incorrect. I currently don't see how this can be fixed reliably if we allow a steady-state heat energy balance for one side of the heat transfer but not the other. Setting the convection coefficient to zero is probably not a robust solution.
  2. The implementation that avoids using the m_flowInv does not work. You can test it by running the example after you set use_safeDivision=false. The reason is that m_flow * (inStream(h_a) - h_b) = Q_flow, with m_flow=0 at the start of the simulation but Q_flow != 0. Hence, Dymola stops with an inconsistent scalar system (as it should). The implementation with m_flowInv computes, but it is not robust at it requires m_flow to be exactly zero, which we cannot rely on in general.

We may need to require that the fluid is always modeled dynamic if the heat transfer is connected to another temperature that is a state variable. This may also affect other models such as the borehole heat exchanger, the radiator (which usually is connected to a dynamic room air volume), and the BoilerPolynomial (if its heat port is connected to a room that gets the heat loss). We also need to work out the details of what happens at zero flow rate if two steady-state fluid streams (modeled as steady-state volume as we do it now) exchange heat using Q_flow = k * (T_medium1-T_medium2) where k is a constant and the temperatures are of the respective medium.

Mathadon commented 9 years ago

@mwetter 1) This is indeed how I noticed that there was a bug, and why I created https://github.com/iea-annex60/modelica-annex60/issues/282 Note that Q_flow = h * dT and dT=0 when solving using the correct equations, so Q_flow does become zero. 2) If you also set

if allowFlowReversal then
        port_a.m_flow * (inStream(port_b.h_outflow) - port_a.h_outflow) = +Q_flow;
      else
        port_a.h_outflow=0;
      end if;

as suggested in the issue then you do not get a division by zero and the model runs fine.

Regarding the case with the two connected mixing volumes: if there's a problem in an example model we can surely have a look at it!

mwetter commented 8 years ago

@Mathadon : I added a test case for zero mass flow rate with dynamic and steady-state heat exchanger. The test case is Fluid.Storage.Validation.HeatExchangerDynamic and works well. I will therefore close this issue when I merge the code to the master.

mwetter commented 8 years ago

Closed as this is now on the master