Skip to content

Commit

Permalink
Add MATLAB interface to the setState_RP function
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwweber authored and speth committed Jun 15, 2015
1 parent ca6e228 commit 6082726
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions interfaces/matlab/toolbox/@ThermoPhase/set.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ function set(tp, varargin)
elseif nt == 1 && np == 1
setTemperature(tp, tval);
setPressure(tp, pval);
elseif np == 1 && nv == 1
setState_RP(tp, [1.0/vval, pval])
elseif nt == 1 && nq == 1
setState_Tsat(tp, [tval,qval]);
elseif np == 1 && nq == 1
Expand Down
16 changes: 16 additions & 0 deletions interfaces/matlab/toolbox/@ThermoPhase/setState_RP.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function setState_RP(tp, rp)
% SETSTATE_RP Set the density and pressure.
% setState_RP(tp, [density,p])
% The density is set first, then the pressure is set by
% changing the temperature holding the density and
% chemical composition fixed.
%
% :param tp:
% Instance of class :mat:func:`ThermoPhase` (or another
% class derived from ThermoPhase)
% :param rp:
% Vector of length 2 containing the desired values for the density (kg/m^3)
% and pressure (Pa)
%

thermo_set(tp.tp_id, 26, rp);
10 changes: 10 additions & 0 deletions src/clib/ct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,16 @@ extern "C" {
}
}

int th_set_RP(int n, double* vals)
{
try{
ThermoCabinet::item(n).setState_RP(vals[0], vals[1]);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
}
}

int th_set_HP(int n, double* vals)
{
try {
Expand Down
1 change: 1 addition & 0 deletions src/clib/ct.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extern "C" {
CANTERA_CAPI int th_getEntropies_R(int n, size_t lenm, double* s_r);
CANTERA_CAPI int th_getCp_R(int n, size_t lenm, double* cp_r);
CANTERA_CAPI int th_setElectricPotential(int n, double v);
CANTERA_CAPI int th_set_RP(int n, double* vals);
CANTERA_CAPI int th_set_HP(int n, double* vals);
CANTERA_CAPI int th_set_UV(int n, double* vals);
CANTERA_CAPI int th_set_SV(int n, double* vals);
Expand Down
3 changes: 3 additions & 0 deletions src/matlab/thermomethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ static void thermoset(int nlhs, mxArray* plhs[],
case 25:
ierr = th_setState_Tsat(th,ptr[0],ptr[1]);
break;
case 26:
ierr = th_set_RP(th,ptr);
break;
default:
mexErrMsgTxt("unknown pair attribute.");
}
Expand Down

0 comments on commit 6082726

Please sign in to comment.