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
A commit for the REFPROP backend to include the functions of satu… #2016
base: master
Are you sure you want to change the base?
Conversation
Why are you doing this in C++? What are you catching:
|
Please use consistent indentation. Recommend you use 4 spaces per tab, no tabs. |
if (_RPcheckTwophase() == false) | ||
throw ValueError("Not two phase fluid: saturation derivative is not possible"); | ||
|
||
shared_ptr<REFPROPMixtureBackend> SatL(new REFPROPMixtureBackend(this->calc_fluid_names())), SatV(new REFPROPMixtureBackend(this->calc_fluid_names())); |
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.
Definitely this won't work. You need to just call methods with given temperature and density
if (_RPcheckTwophase() == false) | ||
throw ValueError("Not two phase fluid: saturation derivative is not possible"); | ||
|
||
shared_ptr<REFPROPMixtureBackend> SatL(new REFPROPMixtureBackend(this->calc_fluid_names())), SatV(new REFPROPMixtureBackend(this->calc_fluid_names())); |
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.
Definitely this won't work. You need to just call methods with given temperature and density
SatL->update(QT_INPUTS, 0.0, _T); // <--- This looks never effecient, | ||
SatV->update(QT_INPUTS, 1.0, _T); // but just mimics the saturate states of HEOS.. | ||
|
||
shared_ptr<REFPROPMixtureBackend> Liq(new REFPROPMixtureBackend(this->calc_fluid_names())), End(new REFPROPMixtureBackend(this->calc_fluid_names())); |
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.
Definitely this won't work. You need to just call methods with given temperature and density
In my intention, it means "converting standard exceptions of logical (mathematical) error to the ValueError". |
Oops, sorry!! |
By the way, Ian(@ibell). I'm also a bit leery; please see the 3rd issue item in my original posting, and clarify whether your mention implies such a risk. So, I guess that it is possible to flatten the routines, as I mentioned in the same lines, without such a copy of state. If you still recommend a change, I'm able to try such a direction. |
I just found many trivial (but serious) mistakes not only in my commit, but also with the previous example which was nothing to do with your comment, but a test for
Eventually, I made it work. And another example of splined derivative is also successful, which is the same to the famous example http://www.coolprop.org/coolprop/LowLevelAPI-1.py except for the backend; I just applied |
Purpose
As a follow up of the issue #2013, I tried to include the missing functions which is particularly related to the saturated states.
They are critical to associated the REFPROP with the recently updated ExternalMedia library (for the Modelica platform).
Description of the Change
protected part:
(CachedElement) are declared.
_calc_saturated_liquid_output( CachedElement&)
or_calc_saturated_vapor_output( CachedElement&)
, the variable is checked whether it is already cached or not._T
and the saturated density_rhoLmolar
(liquid) or_rhoVmolar
(vapor) using the THERMdll subroutine in the REFPROP DLL._RPcheckTwophase()
is introduced.inline bool _RPcheckTwophase( void) { if (ValidNumber(_Q) && (_Q >= 0.00) && (_Q <= 1.00)) return true; }
clear()
in the base class (AbstractState) is redefined to chain the original function, and call the local (protected) one_RPclearSat()
to erase the new cached variablespublic part:
calc_saturated_liquid_keyed_output(parameters key)
andcalc_saturated_vapor_keyed_output(parameters key)
are extended for many key parameters to cope with the reqiurment ofcoolpropsolver
in the ExternalMedia library.calc_hmolar
andcalc_smolar
is implemented to specialize the calculation, particularly, in case of two-phase fluid.CoolPropDbl
output - see the Purpose section - in the saturated and two-phase state are implemented.calc_first_saturation_deriv(parameters Of1, parameters Wrt1);
calc_first_saturation_deriv(parameters Of1, parameters Wrt1, CoolPropDbl rhoL_mol, CoolPropDbl rhoV_mol);
calc_first_two_phase_deriv(parameters Of, parameters Wrt, parameters Constant);
calc_first_two_phase_deriv_splined(parameters Of, parameters Wrt, parameters Constant, CoolPropDbl x_end);
update_DmolarT_direct()
is implemented, as it is just required by the splined derivative, usingTHERMdll
subroutine.Verification Process
This is a preliminary implementation just to know whether it works, and will be developed based on the discussions.
Thus, a simple CO2 thermodynamic state model (TestCoolProp.mo) is tested successfully in OpenModelica
[modelica-3rdparty/ExternalMedia/pull/27].
I will be bring some test runs after clarifying the following issues, mainly, about some decisions to make.
Discussion for Open Issues
_RPcheckTwophase()
, which looks redundant however. Is there any possibility to actualize theGetRPphase()
function also in case of mixture? Moreover, the ExternalMedia library also requires such a strict indicator of phase as a basis. So, how can we manage that?calc_hmolar()
and so on?_calc_saturated_liquid_output( CachedElement&)
or_calc_saturated_vapor_output( CachedElement&)
for an update in case of empty state. However, it's error-prone a little bit and lengthy, because the cached element is assigned as an argument to the functions with respect to the state (liquid or vapor). So, it looks better to design a derived class of CachedElement to have a shared pointer to the host class (REFPROP backend class), and to implement an automatic checking and updating. Is it plausible?Plan of Completion
I'll revise the commit according to the conclusions of following discussions. Moreover, there will be updates based on the bug fixing with test runs.
Additional Information
In addition, I fixed the saturated quantity calculation in PQ_INPUTS and QT_INPUTS in
update()
, on the issue [/issues/1502], and a mistake of the factor 1000 with kPa unt.