-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbounds.c
71 lines (60 loc) · 1.91 KB
/
bounds.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
freesteam - IAPWS-IF97 steam tables library
Copyright (C) 2004-2009 John Pye
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*//** @file
Functions to return SteamState objects for points on the
boundary of the ...
*/
#define FREESTEAM_BUILDING_LIB
#include "bounds.h"
#include "region3.h"
#include "region1.h"
#include "region2.h"
#include "b23.h"
#include "zeroin.h"
#include <stdlib.h>
typedef struct{
double p, T;
} SteamPTData;
static double pT3_fn(double rho, void *user_data){
#define D ((SteamPTData *)user_data)
return D->p - freesteam_region3_p_rhoT(rho, D->T);
#undef D
}
SteamState freesteam_bound_pmax_T(double T){
SteamState S;
if(T <= REGION1_TMAX){
S.region = 1;
S.R1.p = IAPWS97_PMAX;
S.R1.T = T;
}else if(T > freesteam_region2_s_pT(IAPWS97_PMAX,freesteam_b23_T_p(IAPWS97_PMAX))){
S.region = 2;
S.R2.p = IAPWS97_PMAX;
S.R2.T = T;
}else{
S.region = 3;
S.R3.T = T;
SteamPTData D = {IAPWS97_PMAX, T};
double tol = 1e-7;
double sol, err = 0;
double lb = 1./freesteam_region2_v_pT(freesteam_b23_p_T(T),T);
double ub = 1./freesteam_region1_v_pT(IAPWS97_PMAX,REGION1_TMAX);
if(zeroin_solve(&pT3_fn, &D, lb, ub, tol, &sol, &err)){
fprintf(stderr,"%s (%s:%d): failed to solve for rho\n",__func__,__FILE__,__LINE__);
exit(1);
}
S.R3.rho = sol;
}
return S;
}