diff --git a/interfaces/matlab/toolbox/@ThermoPhase/set.m b/interfaces/matlab/toolbox/@ThermoPhase/set.m index 87dda95805..7e348643da 100644 --- a/interfaces/matlab/toolbox/@ThermoPhase/set.m +++ b/interfaces/matlab/toolbox/@ThermoPhase/set.m @@ -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 diff --git a/interfaces/matlab/toolbox/@ThermoPhase/setState_RP.m b/interfaces/matlab/toolbox/@ThermoPhase/setState_RP.m new file mode 100644 index 0000000000..4f5fe1aba6 --- /dev/null +++ b/interfaces/matlab/toolbox/@ThermoPhase/setState_RP.m @@ -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); diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index 3435bd00a1..452c04dc9c 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -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 { diff --git a/src/clib/ct.h b/src/clib/ct.h index 4da53876cb..ead3914956 100644 --- a/src/clib/ct.h +++ b/src/clib/ct.h @@ -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); diff --git a/src/matlab/thermomethods.cpp b/src/matlab/thermomethods.cpp index a0e8dc89ea..e82604d325 100644 --- a/src/matlab/thermomethods.cpp +++ b/src/matlab/thermomethods.cpp @@ -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."); }