Skip to content

Commit

Permalink
Saturation Functions Patch (#20)
Browse files Browse the repository at this point in the history
* Patch RegionOutput(key,T,p,SatState) for results on saturation curve.

* Add error code in Mathcad wrapper for catching UNKNOWN exceptions.

* Catch IF97 exception in Mathcad wrapper when (T,p) state lies exactly on saturation curve.

* Clarify branch conditionals with {}
  • Loading branch information
henningjp authored and ibell committed Mar 3, 2017
1 parent 2d0e52c commit a97fc3b
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 13 deletions.
12 changes: 11 additions & 1 deletion IF97.h
Original file line number Diff line number Diff line change
Expand Up @@ -3919,12 +3919,22 @@ namespace IF97
return R2.output(outkey, T, p); // On saturation curve and need the Vapor phase
else
return R1.output(outkey, T, p); // otherwise, use Liquid Region 1
break;
case REGION_2: if (State == LIQUID)
return R1.output(outkey, T, p); // On saturation curve and need the Liquid phase
else
return R2.output(outkey, T, p); // otherwise, use Vapor Region 2
break;
case REGION_3: return R3.output(outkey, T, p, State);
case REGION_4: throw std::invalid_argument("Cannot use Region 4 with T and p as inputs");
break;
case REGION_4: if (State == VAPOR) {
return R2.output(outkey, T, p);
} else if (State == LIQUID) {
return R1.output(outkey, T, p);
} else {
throw std::out_of_range("Cannot use Region 4 with T and p as inputs");
}
break;
case REGION_5: return R5.output(outkey, T, p);
}
throw std::out_of_range("Unable to match region");
Expand Down
3 changes: 2 additions & 1 deletion wrapper/Mathcad/IF97.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum { MC_STRING = STRING }; // substitute enumeration variable MC_STRING for S

// Mathcad Error Codes
enum EC {MUST_BE_REAL = 1, INSUFFICIENT_MEMORY, INTERRUPTED, T_OUT_OF_RANGE, P_OUT_OF_RANGE, SATURATED, NO_SOLUTION_FOUND,
D_OUT_OF_RANGE, H_OUT_OF_RANGE, S_OUT_OF_RANGE, REGION_NOT_FOUND, NUMBER_OF_ERRORS};
D_OUT_OF_RANGE, H_OUT_OF_RANGE, S_OUT_OF_RANGE, REGION_NOT_FOUND, UNKNOWN, NUMBER_OF_ERRORS};

// Table of Error Messages
// These message strings MUST be in the order of the Error Code enumeration above, with the last being a dummy value for error count
Expand All @@ -40,6 +40,7 @@ enum EC {MUST_BE_REAL = 1, INSUFFICIENT_MEMORY, INTERRUPTED, T_OUT_OF_RANGE, P_
"Enthalpy out of Range",
"Entropy out of Range",
"Region not found",
"Exception thrown - Error Unknown",
"Error Count - Not Used"
};

Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/cptp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_CpTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/cvtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_CvTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/htp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_HTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/ktp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_KTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/mutp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_MUTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/prtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_PRTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/rhotp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ LRESULT if97_RhoTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/stp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_STP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/utp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_UTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/vtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ LRESULT if97_VTP(
catch (const std::out_of_range &e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error& ) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down
6 changes: 5 additions & 1 deletion wrapper/Mathcad/includes/wtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ LRESULT if97_WTP(
catch (const std::out_of_range& e) {
if (e.what()[0] == 'T')
return MAKELRESULT(T_OUT_OF_RANGE,1);
else // (e.what == "P")
else if (e.what()[0] == 'P')
return MAKELRESULT(P_OUT_OF_RANGE,2);
else if (e.what()[0] == 'C')
return MAKELRESULT(SATURATED,1);
else
return MAKELRESULT(UNKNOWN,1);
}
catch (const std::logic_error&) {
return MAKELRESULT(NO_SOLUTION_FOUND,1);
Expand Down

0 comments on commit a97fc3b

Please sign in to comment.