Closed saroele closed 10 years ago
I also get something similar for Buildings.Media.GasesPTDecoupled.MoistAir:
Failed to differentiate the equation
floor0.zone3.heatCap.T = Buildings.Media.GasesPTDecoupled.MoistAir.T_phX( 101325.0, floor0.port_b[6].h_outflow, cat(1, floor0.zone3.vol.Xi, {1-sum( floor0.zone3.vol.Xi)}));
in order to reduce the DAE index.
Failed to reduce the DAE index.
is this the same error?
Buildings.Media.PerfectGases.MoistAirUnsaturated works as well
Yes, the error was similar (failed to differentiate an equation in order to reduce DAE index).
On Thu, Jun 12, 2014 at 9:30 AM, Filip notifications@github.com wrote:
Buildings.Media.PerfectGases.MoistAirUnsaturated works as well
— Reply to this email directly or view it on GitHub https://github.com/open-ideas/IDEAS/issues/65#issuecomment-45837905.
The problem seems to be (such as the error message states) that sometimes the function is not differentiable since it uses a relatively complex algorithm (iterative solving of a state using Internal.solve()). For MoistAirUnsaturated and IDEAS.Media.Air a simple algorithm is used: Air:
algorithm
T := reference_T + (h - h_fg * X[Water])
/((1 - X[Water])*dryair.cp + X[Water] * steam.cp);
MoistAirUnsaturated:
T := 273.15 + (h-2501014.5 * X[Water])/(dryair.cp * (1 - X[Water])+steam.cp*X[Water]);
These Media can therefor be solved.
For Buildings.Media.PerfectGases.MoistAir.T_phX however:
T := 273.15 + (h - 2501014.5 * X[Water])/((1 - X[Water])*dryair.cp + X[Water] *
Buildings.Media.PerfectGases.Common.SingleGasData.H2O.cp);
// check for saturation
p_steam_sat :=saturationPressure(T);
x_sat :=k_mair*p_steam_sat/(p - p_steam_sat);
// If the state is in the fog region, then the above equation is not valid, and
// T is computed by inverting h_pTX(), which is much more costly.
// For Buildings.Fluid.HeatExchangers.Examples.WetEffectivenessNTUPControl, the
// computation above reduces the computing time by about a factor of 2.
if (X[Water] > x_sat/(1 + x_sat)) then
T := Internal.solve(h, TMin, TMax, p, X[1:nXi], steam);
end if;
Modelica.Media.IdealGases.Common.MixtureGasNasa.T_hX:
T := Internal.solve(h, 200, 6000, 1.0e5, Xfull, data[1]);
Here the function can apparently not be differentiated.
We may be able to change the model so the derivative is not required. For instance adding a thermal conductor between the capacity and mixing volume in the zone model fixes the problem. Since this is also physically sensible it may be worth considering this?
@Mathadon it would be interesting to report that to the Buildings forum
I guess that Michael is aware that some of the Media packages are not differentiable? If you think it's worth it then I'll report it :)
He is indeed aware of it, but it is important to report such limitations with examples, as we are working on the Media and its numerical efficiency.
This problems is known. If the model uses Internal.solve(...)
, then the automatic differentiation does not work. It would be quite involved to implement an automatic differentiation since the derivative function would need to use the same number of iterations as the function evaluation for the same arguments.
I suggest to not use MoistAir
, but rather use the variant MoistAirUnsaturated
which does not require a call to Internal.solve(...)
.
In the Annex 60 library, we only use MoistAirUnsaturated
, but call it (for simplicity) Air
.
I will close https://github.com/lbl-srg/modelica-buildings/issues/243
@saroele can this be closed?
Yes, I think Michael's explanation is clear and the solution is rather easy: just use MoistAirUnsaturated
. Is this mentioned in a logic place in the documentation of the libraries? Thanks
The easiest is probably to remove Buildings.Media.GasesPTDecoupled.MoistAir
(and any other *MoistAir
) so that users can only use the *MoistAirUnsaturated
versions. This is the approach we are going with the Annex60
library.
If Leuven has a good reason for keeping the *MoistAir
versions, we should discuss and consider putting it into the Annex60
library as well.
Is it normal that I cannot simulate a building with any other air from the MSL ? I have tried these, and they all fail:
An adaptation of the last model with different boundaries did work, but it's probably not very valid ...