-
Notifications
You must be signed in to change notification settings - Fork 176
Correct error in function Modelica.Media.Air.ReferenceMoistAir.Utilities.pd_pTX_der #3834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my latest comment in the conversation of this PR: I think the derivative is wrong, the correct one is proposed in the original thread, see comments in #3666, and here:
To me, the proposed derivative looks wrong. If the function is:
//pd := xw/(Modelica.Media.Air.ReferenceMoistAir.k_mair + xw)*p;
And for better readability, I propose a shorthand and minor re-write:
Real k = Modelica.Media.Air.ReferenceMoistAir.k_mair; //pd := xw/(k + xw)*p;
I get:
pd_der = (p*xw_der + xw*p_der)/(k + xw) - p*xw*xw_der/(k + xw)^2
Could somebody please verify this, also with the test function from Matthis?
|
@hubertus65 @thorade a gentle reminder this issue remains unresolved, Restarting the process of solving it would be really needed. |
|
@beutlich @wischhusen Did you get around making the changes suggested by @hubertus65 ? |
|
Why do we write such functions at all? Modelica has smoothOrder that automatically derive such a derivative-function from the original, and it would automatically ensure that any other differences disappear - e.g., handling of xws==-1. Thus my proposal is to just remove the functions pd_pTX_der, h_pTX_der, rho_pTX_der, and u_pTX_der and replace them with smoothOrder=1. That would avoid such errors, and reduce the maintenance burden. |
|
By applying smoothOrder=1 and avoiding the explicit derivative functions (see e3c45f2) I get a differentiation error in Dymola 2023 for the test model: model pd_der_test_smoothOrder
replaceable package Medium = Modelica.Media.Air.ReferenceMoistAir;
Real der_T = 300;
Real T = 73.15 + der_T * time;
Real der_p = -1e5;
Real p = 1e7 + der_p * time;
Real[Medium.nS] X = Medium.reference_X;
Real var_from_function = Medium.Utilities.pd_pTX(p, T, X);
Real timederiv = der(var_from_function);
annotation (experiment(StopTime=100));
end pd_der_test_smoothOrder;Is there anything I am missing? |
Possibly, I'll have to make a branch and test that. |
You can pull my branch: https://github.com/beutlich/ModelicaStandardLibrary/tree/issue3666_avoid-derivative-functions |
|
@HansOlsson @beutlich did you get around the solution. Kindly commit the fix if you have arrived at the solution. |
Hm... More detailed: Dymola currently cannot differentiate this for two reasons:
I don't know what other tools can do, I could imagine similar limitations - but I think the limitations can be overcome (for functions as argument to functions it depends on the functions). The problematic part for MSL is that the 2nd change is another bug (or simplification) so a correction needs more testing; which is another reason this should be a separate PR. |
if i am correct ,what i could understand by reading the comment is that you propose to go ahead with the changes suggested by@hubertus65 and then do the simplification work in a different PR. Kindly correct me if i am wrong. Many thanks.. |
Yes that is a correct understanding. |
|
@hubertus65 @thorade Kindly look into the changes done to the fix as per your comments. |
|
I manually derived the expression and arrived at the same result. I also tested with the test model, and the error becomes much smaller, but not zero. |
Resolves #3666 as proposed by @GaelEnee.