modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
479 stars 169 forks source link

Guess value for thermodynamicstate.X #1509

Closed modelica-trac-importer closed 7 years ago

modelica-trac-importer commented 7 years ago

Reported by filip.jorissen on 10 Jun 2014 16:55 UTC I have a model where 'X[2]' of a moist air was chosen by Dymola as the iteration variable of a nonlinear system of equations. The default guess value is 0, which causes an error:

The following error was detected at time: 0

Model error - power: (r1) ** (n[1]) = (-3.83338) ** (-1.5)

The stack of functions is:
Buildings.Media.PerfectGases.MoistAir.sublimationPressureIce
Buildings.Media.PerfectGases.MoistAir.saturationPressure
Buildings.Media.GasesPTDecoupled.MoistAir.T_phX
Buildings.Media.GasesPTDecoupled.MoistAir.T_phX(menergaAdsolair.heating.state_a1_inflow.p, menergaAdsolair.filter.port_b.h_outflow, menergaAdsolair.filter.port_b.Xi_outflow)
First evaluation failed for non-linear solver.

etc etc

ERROR: Failed to solve non-linear system using Newton solver.
To get more information: Turn on Simulation/Setup/Debug/Nonlinear solver diagnostics/Details
Solution to systems of equations not found at time = 0
   Nonlinear system of equations number = 15
   Failed to evaluate any residual. Try to give better start-values.
   Iteration is not making good progress.
   Accumulated number of residue calculations: 4
   Last values of solution vector:
menergaAdsolair.heating.state_a1_inflow.X[2] = 1E-09
menergaAdsolair.thermostatic3WayValve.k = 0.5
menergaAdsolair.filter.port_b.h_outflow = 45301
Error: could not solve simplified initialization for homotopy method.
Error: could not solve simplified initialization for homotopy method.
Error: Failed to start model.

I solved this by setting the initial guess value for ThermodynamicState.X equal to reference_X. I suggest to implement this by default in MSL and possibly also for p, T and h.

The hotfix for my own package was:

redeclare record extends ThermodynamicState(X(start=reference_X)) 
  "ThermodynamicState record for moist air"
end ThermodynamicState;

Migrated-From: https://trac.modelica.org/Modelica/ticket/1509

modelica-trac-importer commented 7 years ago

Comment by hubertus on 10 Jun 2014 17:55 UTC Thanks for the report, this is actually the intention of the variable reference_X. I am not sure whether it shoudl be set int the library though: the problem is that the mere existence of a value for the start attribute influences a number of algorithms (e.g. state selection, afaik at least in some tools), so that there can be unintended consequences from adding it. I'll think a bit about this and might introduce your fix.

For that matter: it would probably be nicer if setting start values would have no other effects than exactly setting a start value. In that case, the fix shoudl of course be applied

modelica-trac-importer commented 7 years ago

Comment by fcasella on 31 Aug 2015 11:24 UTC I got a similar request on Stackoverflow (http://stackoverflow.com/questions/31644258/fluidport-connector-with-start-values-for-composition) which suggests adding reference_X as a default start value for connector variables.

In fact, a better choice would be to add start = reference_X to MassFraction type definition of the medium, which would cover all the cases at once.

I am also unsure that this might trigger negative consequences on existing models. Maybe it would be worth trying on the existing testuites. What do you think?

modelica-trac-importer commented 7 years ago

Comment by hubertus on 12 Dec 2015 22:53 UTC Francesco, your ideas does not work because the mass fraction type is not a vector. It maybe should be and should be used, but that would not be an allowed change for a minor version number update.

modelica-trac-importer commented 7 years ago

Comment by hubertus on 12 Dec 2015 23:03 UTC Fixed in trunk in 67ba73b85115cf06cc6707d83b8dd1c55253335a

modelica-trac-importer commented 7 years ago

Changelog modified by hubertus on 12 Dec 2015 23:03 UTC Fixes missing start value for composition vector in ThermodynamicState

modelica-trac-importer commented 7 years ago

Modified by beutlich on 13 Dec 2015 08:26 UTC

modelica-trac-importer commented 7 years ago

Changelog modified by beutlich on 13 Dec 2015 08:26 UTC Fixed missing start value for composition vector in ThermodynamicState

modelica-trac-importer commented 7 years ago

Comment by fcasella on 14 Dec 2015 13:55 UTC Replying to [comment:3 hubertus]:

Francesco, your ideas does not work because the mass fraction type is not a vector. It maybe should be and should be used, but that would not be an allowed change for a minor version number update.

You're right, I overlooked this.