mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-02-09 05:15:45 -05:00
First derivatives are calculated by gridded tabular backend
Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
@@ -77,37 +77,56 @@ void GriddedTableBackend::build_tables(tabular_types type)
|
||||
y = ymin + (ymax - ymin)/(Ny-1)*j;
|
||||
}
|
||||
|
||||
if (get_debug_level() > 5){std::cout << "x:" << x << " y: " << y;}
|
||||
if (xkey == iHmolar && ykey == iP){
|
||||
if (get_debug_level() > 5){std::cout << "x: " << x << " y: " << y;}
|
||||
|
||||
if (xkey == iHmolar && ykey == iP)
|
||||
{
|
||||
// --------------------
|
||||
// Update the state
|
||||
// --------------------
|
||||
try{
|
||||
// Update the state
|
||||
AS->update(HmolarP_INPUTS, x, y);
|
||||
|
||||
// Skip two-phase states - they will remain as _HUGE holes in the table
|
||||
if (AS->phase() == iphase_twophase){
|
||||
if (get_debug_level() > 5){std::cout << "2Phase" << std::endl;}
|
||||
continue;
|
||||
};
|
||||
|
||||
// Calculate each of the parameters, and their derivatives with respect to the input variables
|
||||
single_phase.T[i][j] = AS->T();
|
||||
single_phase.p[i][j] = AS->p();
|
||||
single_phase.hmolar[i][j] = AS->hmolar();
|
||||
single_phase.smolar[i][j] = AS->smolar();
|
||||
single_phase.rhomolar[i][j] = AS->rhomolar();
|
||||
if (get_debug_level() > 5){std::cout << "OK" << std::endl;}
|
||||
}
|
||||
catch(std::exception &e){
|
||||
if (get_debug_level() > 5){std::cout << e.what() << std::endl;}
|
||||
// If there is an error, go to next one
|
||||
// That failed for some reason, go to the next pair
|
||||
if (get_debug_level() > 5){std::cout << " " << e.what() << std::endl;}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip two-phase states - they will remain as _HUGE holes in the table
|
||||
if (AS->phase() == iphase_twophase){
|
||||
if (get_debug_level() > 5){std::cout << " 2Phase" << std::endl;}
|
||||
continue;
|
||||
};
|
||||
|
||||
// --------------------
|
||||
// State variables
|
||||
// --------------------
|
||||
single_phase.T[i][j] = AS->T();
|
||||
single_phase.p[i][j] = AS->p();
|
||||
single_phase.rhomolar[i][j] = AS->rhomolar();
|
||||
single_phase.hmolar[i][j] = AS->hmolar();
|
||||
single_phase.smolar[i][j] = AS->smolar();
|
||||
|
||||
// ----------------------------------------
|
||||
// First derivatives of state variables
|
||||
// ----------------------------------------
|
||||
single_phase.dTdx[i][j] = AS->first_partial_deriv(iT, xkey, ykey);
|
||||
single_phase.dTdy[i][j] = AS->first_partial_deriv(iT, ykey, xkey);
|
||||
single_phase.dpdx[i][j] = AS->first_partial_deriv(iP, xkey, ykey);
|
||||
single_phase.dpdy[i][j] = AS->first_partial_deriv(iP, ykey, xkey);
|
||||
single_phase.drhomolardx[i][j] = AS->first_partial_deriv(iDmolar, xkey, ykey);
|
||||
single_phase.drhomolardy[i][j] = AS->first_partial_deriv(iDmolar, ykey, xkey);
|
||||
single_phase.dhmolardx[i][j] = AS->first_partial_deriv(iHmolar, xkey, ykey);
|
||||
single_phase.dhmolardy[i][j] = AS->first_partial_deriv(iHmolar, ykey, xkey);
|
||||
single_phase.dsmolardx[i][j] = AS->first_partial_deriv(iSmolar, xkey, ykey);
|
||||
single_phase.dsmolardy[i][j] = AS->first_partial_deriv(iSmolar, ykey, xkey);
|
||||
|
||||
if (get_debug_level() > 5){std::cout << " OK" << std::endl;}
|
||||
}
|
||||
else{
|
||||
throw ValueError("Cannot construct this type of table");
|
||||
throw ValueError("Cannot construct this type of table (yet)");
|
||||
}
|
||||
|
||||
// Calculate the derivatives
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,27 @@ namespace CoolProp{
|
||||
struct SinglePhaseGriddedTableData{
|
||||
CoolProp::parameters xkey, ykey;
|
||||
std::vector< std::vector<double> > T, p, rhomolar, hmolar, smolar;
|
||||
std::vector< std::vector<double> > dTdx, dTdy, dpdx, dpdy, drhomolardx, drhomolardy, dhmolardx, dhmolardy, dsmolardx, dsmolardy;
|
||||
|
||||
void resize(std::size_t Nx, std::size_t Ny){
|
||||
|
||||
// State variables
|
||||
T.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
p.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
rhomolar.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
hmolar.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
smolar.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
|
||||
// First derivatives of state variables
|
||||
dTdx.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
dpdx.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
drhomolardx.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
dhmolardx.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
dsmolardx.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
dTdy.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
dpdy.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
drhomolardy.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
dhmolardy.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
dsmolardy.resize(Nx, std::vector<double>(Ny, _HUGE));
|
||||
};
|
||||
};
|
||||
class GriddedTableBackend : public AbstractState
|
||||
|
||||
Reference in New Issue
Block a user