/
NRPyEOS_Tabulated_known_T.c
263 lines (235 loc) · 10.9 KB
/
NRPyEOS_Tabulated_known_T.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// Thorn : NRPyEOS
// File : NRPyEOS_Tabulated_known_T.cc
// Author(s) : Leo Werneck (wernecklr@gmail.com)
// Description: This file provides wrapper functions to compute various
// tables quantities neeeded by WVUThorns from (rho,Ye,T).
#include "NRPyEOS_Tabulated_headers.h"
// -------------------------------------
// ----------- P(rho,Ye,T) -----------
// ----------- eps(rho,Ye,T) -----------
// -------------------------------------
void NRPyEOS_P_and_eps_from_rho_Ye_T( const NRPyEOS_params_tabulated *restrict eos_params,
const double rho,
const double Ye,
const double T,
double *restrict P,
double *restrict eps ) {
// Number of interpolated quantities: 2 (P and eps)
const int n = 2;
// Table variables keys
const int keys[2] = {NRPyEOS_press_key,NRPyEOS_eps_key};
// Declare error variable
NRPyEOS_error_report report;
// Set output variable array
double outvars[n];
// Get P and eps
NRPyEOS_from_rho_Ye_T_interpolate_n_quantities( eos_params, n,rho,Ye,T, keys,outvars, &report );
// Error handling
if( report.error ) {
fprintf(stderr,"(NRPyEOS) Inside NRPyEOS_P_and_eps_from_rho_Ye_T. Error message: %s (key = %d)",report.message,report.error_key);
// May want to terminate depending on the error. We'll just warn for now.
}
// Then update P and eps
*P = outvars[0];
*eps = outvars[1];
}
// -------------------------------------
// ----------- P(rho,Ye,T) -----------
// ----------- eps(rho,Ye,T) -----------
// ----------- S(rho,Ye,T) -----------
// -------------------------------------
void NRPyEOS_P_eps_and_S_from_rho_Ye_T( const NRPyEOS_params_tabulated *restrict eos_params,
const double rho,
const double Ye,
const double T,
double *restrict P,
double *restrict eps,
double *restrict S ) {
// Number of interpolated quantities: 3 (P, eps, and S)
const int n = 3;
// Table variables keys
const int keys[3] = {NRPyEOS_press_key,NRPyEOS_eps_key,NRPyEOS_entropy_key};
// Declare error variable
NRPyEOS_error_report report;
// Set output variable array
double outvars[n];
// Get P, eps, and S
NRPyEOS_from_rho_Ye_T_interpolate_n_quantities( eos_params, n,rho,Ye,T, keys,outvars, &report );
// Error handling
if( report.error ) {
fprintf(stderr,"(NRPyEOS) Inside NRPyEOS_P_eps_and_S_from_rho_Ye_T. Error message: %s (key = %d)",report.message,report.error_key);
// May want to terminate depending on the error. We'll just warn for now.
}
// Then update P, eps, and S
*P = outvars[0];
*eps = outvars[1];
*S = outvars[2];
}
// -------------------------------------
// ----------- P(rho,Ye,T) -----------
// ----------- eps(rho,Ye,T) -----------
// ----------- S(rho,Ye,T) -----------
// ----------- cs2(rho,Ye,T) -----------
// -------------------------------------
void NRPyEOS_P_eps_S_and_cs2_from_rho_Ye_T( const NRPyEOS_params_tabulated *restrict eos_params,
const double rho,
const double Ye,
const double T,
double *restrict P,
double *restrict eps,
double *restrict S,
double *restrict cs2 ) {
// Number of interpolated quantities: 3 (P, eps, S, and cs2)
const int n = 4;
// Table variables keys
const int keys[4] = {NRPyEOS_press_key,NRPyEOS_eps_key,NRPyEOS_entropy_key,NRPyEOS_cs2_key};
// Declare error variable
NRPyEOS_error_report report;
// Set output variable array
double outvars[n];
// Get P, eps, S, and cs2
NRPyEOS_from_rho_Ye_T_interpolate_n_quantities( eos_params, n,rho,Ye,T, keys,outvars, &report );
// Error handling
if( report.error ) {
fprintf(stderr,"(NRPyEOS) Inside NRPyEOS_P_eps_and_S_from_rho_Ye_T. Error message: %s (key = %d)",report.message,report.error_key);
// May want to terminate depending on the error. We'll just warn for now.
}
// Then update P, eps, S, and cs2
*P = outvars[0];
*eps = outvars[1];
*S = outvars[2];
*cs2 = outvars[3];
// Must update cs2
*cs2 = rho * (*cs2) / (rho + rho*(*eps) + (*P));
}
// ----------------------------------------
// ----------- P(rho,Ye,T) -----------
// ----------- eps(rho,Ye,T) -----------
// ----------- depsdT(rho,Ye,T) -----------
// ----------------------------------------
void NRPyEOS_P_eps_and_depsdT_from_rho_Ye_T( const NRPyEOS_params_tabulated *restrict eos_params,
const double rho,
const double Ye,
const double T,
double *restrict P,
double *restrict eps,
double *restrict depsdT ) {
// Number of interpolated quantities: 3 (P, eps, and deps/dT)
const int n = 3;
// Table variables keys
const int keys[3] = {NRPyEOS_press_key,NRPyEOS_eps_key,NRPyEOS_depsdT_key};
// Declare error variable
NRPyEOS_error_report report;
// Set output variable array
double outvars[n];
// Get P and eps
NRPyEOS_from_rho_Ye_T_interpolate_n_quantities( eos_params, n,rho,Ye,T, keys,outvars, &report );
// Error handling
if( report.error ) {
fprintf(stderr,"(NRPyEOS) Inside NRPyEOS_P_eps_and_S_from_rho_Ye_T. Error message: %s (key = %d)",report.message,report.error_key);
// May want to terminate depending on the error. We'll just warn for now.
}
// Then update P, eps, and deps/dT
*P = outvars[0];
*eps = outvars[1];
*depsdT = outvars[2];
}
// ----------------------------------------
// ---------- P(rho,Ye,T) ----------
// ---------- eps(rho,Ye,T) ----------
// ---------- dPdrho(rho,Ye,T) ----------
// ---------- dPdT(rho,Ye,T) ----------
// ---------- depsdrho(rho,Ye,T) ----------
// ---------- depsdT(rho,Ye,T) ----------
// ----------------------------------------
void NRPyEOS_P_eps_dPdrho_dPdT_depsdrho_and_depsdT_from_rho_Ye_T( const NRPyEOS_params_tabulated *restrict eos_params,
const double rho,
const double Ye,
const double T,
double *restrict P,
double *restrict eps,
double *restrict dPdrho,
double *restrict dPdT,
double *restrict depsdrho,
double *restrict depsdT ) {
// This function is a little different than the others. We need
// dP/dT and deps/drho, but we can only get from the table the
// following quantities:
//
// -> dP/drho
// -> dP/deps
// -> deps/dT
//
// Therefore we get all three of the quantities above and then compute:
// .----------------------------.
// | dP/dT = (dP/deps)(deps/dT) |
// .----------------------------.-------------------------.
// | deps/drho = (deps/dP)(dP/drho) = (dP/drho)/(dP/deps) |
// .------------------------------------------------------.
// Number of interpolated quantities: 5 (P, eps, dPdrho, depsdrho, and depsdT)
const int n = 5;
// Table variables keys (we use the table order here)
const int keys[5] = {NRPyEOS_press_key,NRPyEOS_eps_key,NRPyEOS_depsdT_key,NRPyEOS_dPdrho_key,NRPyEOS_dPdeps_key};
// Declare error variable
NRPyEOS_error_report report;
// Set output variable array
double outvars[n];
// Get P, eps, dP/drho, dP/deps, and deps/dT
NRPyEOS_from_rho_Ye_T_interpolate_n_quantities( eos_params, n,rho,Ye,T, keys,outvars, &report );
// Error handling
if( report.error ) {
fprintf(stderr,"(NRPyEOS) Inside NRPyEOS_P_eps_and_S_from_rho_Ye_T. Error message: %s (key = %d)",report.message,report.error_key);
// May want to terminate depending on the error. We'll just warn for now.
}
// Auxiliary variables
// Then update P, eps, deps/dT, and dP/drho
*P = outvars[0];
*eps = outvars[1];
*depsdT = outvars[2];
*dPdrho = outvars[3];
// Finally compute dP/dT
*dPdT = outvars[4]*(*depsdT);
// and deps/drho
*depsdrho = (*dPdrho)/outvars[4];
}
// -------------------------------------
// ---------- mu_e(rho,Ye,T) ----------
// ---------- mu_p(rho,Ye,T) ----------
// ---------- mu_n(rho,Ye,T) ----------
// ---------- muhat(rho,Ye,T) ----------
// ---------- X_p(rho,Ye,T) ----------
// ---------- X_n(rho,Ye,T) ----------
// -------------------------------------
void NRPyEOS_mue_mup_mun_muhat_Xn_and_Xp_from_rho_Ye_T( const NRPyEOS_params_tabulated *restrict eos_params,
const double rho,
const double Ye,
const double T,
double *restrict mu_e,
double *restrict mu_p,
double *restrict mu_n,
double *restrict muhat,
double *restrict X_p,
double *restrict X_n) {
// Number of interpolated quantities: 6 (mu_e, mu_p, mu_n, mu_hat, X_p, and X_n)
const int n = 6;
// Table variables keys
const int keys[6] = {NRPyEOS_muhat_key, NRPyEOS_mu_e_key, NRPyEOS_mu_p_key, NRPyEOS_mu_n_key, NRPyEOS_Xn_key, NRPyEOS_Xp_key};
// Declare error variable
NRPyEOS_error_report report;
// Set output variable array
double outvars[n];
// Get P and eps
NRPyEOS_from_rho_Ye_T_interpolate_n_quantities( eos_params, n,rho,Ye,T, keys,outvars, &report );
// Error handling
if( report.error ) {
fprintf(stderr,"(NRPyEOS) Inside NRPyEOS_mue_mup_mun_muhat_Xn_and_Xp_from_rho_Ye_T. Error message: %s (key = %d)",report.message,report.error_key);
// May want to terminate depending on the error. We'll just warn for now.
}
// Then update mu_e, mu_p, mu_n, mu_hat, X_p, and X_n
*muhat = outvars[0];
*mu_e = outvars[1];
*mu_p = outvars[2];
*mu_n = outvars[3];
*X_n = outvars[4];
*X_p = outvars[5];
}