lbl-srg / modelica-buildings

Modelica Buildings library
250 stars 155 forks source link

Second derivative of sublimationPressureIce and saturationPressureLiquid #298

Closed Mathadon closed 9 years ago

Mathadon commented 9 years ago

Hi,

I have added functions for the calculation of the second derivatives of sublimationPressureIce and saturationPressureLiquid. Dymola requested these for some of my models. Is this of interest?

Filip

mwetter commented 9 years ago

If it does not negatively impact the computing time, then the 2nd derivatives may be good to have. I would however like to see what model this is as I never had Dymola requesting these derivatives and therefore like to understand whether there is an issue with this model. Are they required due to the state selection or index reduction?

Mathadon commented 9 years ago

I am actually not sure what it is needed for. It is also difficult to debug which part from the code is causing it because splitting up the model removes the requirement for these derivatives.

I am not sure if they are needed for state selection or index reduction. During translation I get the following output:

The DAE has 93733 scalar unknowns and 93733 scalar equations.

The initial conditions for variables of type Real are not fully specified.
Dymola has selected default initial conditions.

Cannot find differentiation function:
Buildings.Utilities.Math.Functions.BaseClasses.der_spliceFunction( 
Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.saturationPressureLiquid( Tsat), 
Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.sublimationPressureIce (Tsat), Tsat-273.16, 
1.0, Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.saturationPressureLiquid_der (Tsat, 
Tsat_der), Buildings.Media.PerfectGases.MoistAir.sublimationPressureIce_der (Tsat, Tsat_der), Tsat_der, 
0.0)
with respect to time

Cannot find differentiation function:
Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.saturationPressure:der(T, T_der8)
with respect to time

Statistics

Selected continuous time states

The following variables are iteration variables of the initialization problem:
floorWithHvac3.solar_ex_out.h_outflow
floorWithHvac3.wind_ex_out.h_outflow
etc.
mwetter commented 9 years ago

In the simulation tab, you can ask Dymola to log its differentiation for index reduction (Simulation Setup > Translation). I am not sure if Dymola cannot find the function Buildings.Utilities.Math.Functions.BaseClasses.der_spliceFunction as it writes "Cannot find differentiation function" or whether it indeed cannot find (or compute) the derivative of this function, which does not exist as spliceFunction is only once differentiable. I suggest you check first with the Dymola support to understand the message. Maybe it helps if you can reduce your problem and then share it.

On Wed, Oct 15, 2014 at 1:52 AM, Filip notifications@github.com wrote:

I am actually not sure what it is needed for. It is also difficult to debug which part from the code is causing it because splitting up the model removes the requirement for these derivatives.

I am not sure if they are needed for state selection or index reduction. During translation I get the following output:

The DAE has 93733 scalar unknowns and 93733 scalar equations.

The initial conditions for variables of type Real are not fully specified. Dymola has selected default initial conditions.

Cannot find differentiation function: Buildings.Utilities.Math.Functions.BaseClasses.der_spliceFunction( Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.saturationPressureLiquid( Tsat), Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.sublimationPressureIce (Tsat), Tsat-273.16, 1.0, Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.saturationPressureLiquid_der (Tsat, Tsat_der), Buildings.Media.PerfectGases.MoistAir.sublimationPressureIce_der (Tsat, Tsat_der), Tsat_der, 0.0) with respect to time

Cannot find differentiation function: Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.saturationPressure:der(T, T_der8) with respect to time

Statistics

Selected continuous time states

The following variables are iteration variables of the initialization problem: floorWithHvac3.solar_ex_out.h_outflow floorWithHvac3.wind_ex_out.h_outflow etc.

— Reply to this email directly or view it on GitHub https://github.com/lbl-srg/modelica-buildings/issues/298#issuecomment-59175814 .

Mathadon commented 9 years ago

I actually get a warning in the buildings library as well in Buildings.Fluid.Movers.Examples.FlowMachine_dp

Cannot find differentiation function:
Buildings.Media.GasesPTDecoupled.MoistAirUnsaturated.saturationPressureLiquid_der (Tsat, Tsat_der)
with respect to time
Mathadon commented 9 years ago

Changing Buildings.Fluid.Interfaces.ConservationEquation code:

T(start=T_start,
      stateSelect=if (not (energyDynamics == Modelica.Fluid.Types.Dynamics.SteadyState))
                     then StateSelect.prefer else StateSelect.default)

into:

T(start=T_start,
      stateSelect=StateSelect.default)

removes the warning.

Model execution speed seems to be unaffected.

The selected state changes from:

fan.vol.dynBal.medium.T

into

fan.vol.dynBal.U

T=f(U) which is indeed not twice differentiable. I suppose the second derivative of U is required for some calculation, although I am not sure what for.. Are Hessians being calculated for the nonlinear solver?

thorade commented 9 years ago

In this context, the Dymola flag Hidden.PrintFailureToDifferentiat=true might also be helpful (just in case you weren't aware of it already).

Mathadon commented 9 years ago

This can be closed due to issue https://github.com/lbl-srg/modelica-buildings/issues/354