17 #include "thermometer.h"
21 XThermometerList::XThermometerList(
const char *name,
bool runtime) :
27 REGISTER_TYPE(XThermometerList, ScientificInstruments, "Scientific Instruments")
29 REGISTER_TYPE(XThermometerList, ApproxThermometer, "Cubic-spline")
35 trans( *tempMin()) = 1e-3;
36 trans( *tempMax()) = 1e3;
39 XLakeShore::XLakeShore(
const char *name,
bool runtime) :
41 m_resMax(create<
XDoubleNode> (
"RMax", false)), m_zu(create<
42 XDoubleListNode> (
"Zu", false)), m_zl(create<XDoubleListNode> (
43 "Zl", false)), m_ai(create<XDouble2DNode> (
"Ai", false)) {
46 double XLakeShore::getRawValue(
double temp)
const {
49 double x, y, dypdx, val;
50 if(temp < shot[ *tempMin()])
51 return shot[ *resMax()];
52 if(temp > shot[ *tempMax()])
53 return shot[ *resMin()];
55 val = shot[ *resMin()];
56 for(
double dy = 0.0001;; dy *= 2) {
58 return shot[ *resMin()];
59 double t = randMT19937();
60 x = (log10(shot[ *resMax()]) * t + log10(shot[ *resMin()]) * (1 - t));
61 for(
int i = 0; i < 100; i++) {
62 y = getTemp(pow(10, x)) - temp;
67 dypdx = (y - (getTemp(pow(10, x - 0.00001)) - temp)) / 0.00001;
70 if((x > log10(shot[ *resMax()])) || (x < log10(shot[ *resMin()]))
72 double t = randMT19937();
73 x = (log10(shot[ *resMax()]) * t + log10(shot[ *resMin()]) * (1 - t));
80 double XLakeShore::getTemp(
double res)
const {
82 double temp = 0, z, u = 0;
83 if(res > shot[ *resMax()])
84 return shot[ *tempMin()];
85 if(res < shot[ *resMin()])
86 return shot[ *tempMax()];
91 const auto &zu_list( *shot.list(zu()));
94 const auto &zl_list( *shot.list(zl()));
95 for(n = 0; n < zu_list.size(); n++) {
96 double zu = shot[ *static_pointer_cast<
XDoubleNode> (zu_list.at(n))];
97 double zl = shot[ *static_pointer_cast<
XDoubleNode> (zl_list.at(n))];
98 u = (z - zu + z - zl) / (zu - zl);
99 if ((u >= -1) && (u <= 1))
102 if(n >= zu_list.size())
104 if( !shot.size(ai()))
106 const auto &ai_list( *shot.list(ai()));
107 if( !shot.size(ai_list[n]))
109 const auto &ai_n_list( *shot.list(ai_list[n]));
110 for (
unsigned int i = 0; i < ai_n_list.size(); i++) {
111 double ai_n_i = shot[ *static_pointer_cast<
XDoubleNode> (ai_n_list.at(i))];
112 temp += ai_n_i * cos(i * acos(u));
117 XScientificInstruments::XScientificInstruments(
const char *name,
bool runtime) :
119 m_resMax(create<
XDoubleNode> (
"RMax", false)), m_abcde(create<
120 XDoubleListNode> (
"ABCDE", false)), m_abc(create<XDoubleListNode> (
121 "ABC", false)), m_rCrossover(create<
XDoubleNode> (
"RCrossover",
125 double XScientificInstruments::getRawValue(
double temp)
const {
128 double x, y, dypdx, val;
129 if(temp < shot[ *tempMin()])
130 return shot[ *resMax()];
131 if(temp > shot[ *tempMax()])
132 return shot[ *resMin()];
134 val = shot[ *resMin()];
135 for(
double dy = 0.0001;; dy *= 2) {
137 return shot[ *resMin()];
138 double t = randMT19937();
139 x = (log10(shot[ *resMax()]) * t + log10(shot[ *resMin()]) * (1 - t));
140 for(
int i = 0; i < 100; i++) {
141 y = getTemp(pow(10, x)) - temp;
146 dypdx = (y - (getTemp(pow(10, x - 0.00001)) - temp)) / 0.00001;
149 if((x > log10(shot[ *resMax()])) || (x < log10(shot[ *resMin()]))
151 double t = randMT19937();
152 x = (log10(shot[ *resMax()]) * t + log10(shot[ *resMin()]) * (1 - t));
159 double XScientificInstruments::getTemp(
double res)
const {
161 if(res > shot[ *resMax()])
162 return shot[ *tempMin()];
163 if(res < shot[ *resMin()])
164 return shot[ *tempMax()];
166 double lx = log(res);
167 if(res > shot[ *rCrossover()]) {
168 if( !shot.size(abcde()))
return 0;
169 const auto &abcde_list( *shot.list(abcde()));
170 if(abcde_list.size() >= 5) {
171 double a = shot[ *static_pointer_cast<
XDoubleNode> (abcde_list.at(0))];
172 double b = shot[ *static_pointer_cast<
XDoubleNode> (abcde_list.at(1))];
173 double c = shot[ *static_pointer_cast<
XDoubleNode> (abcde_list.at(2))];
174 double d = shot[ *static_pointer_cast<
XDoubleNode> (abcde_list.at(3))];
175 double e = shot[ *static_pointer_cast<
XDoubleNode> (abcde_list.at(4))];
176 y = (a + c * lx + e * lx * lx) / (1.0 + b * lx + d * lx * lx);
180 if( !shot.size(abc()))
return 0;
181 const auto &abc_list( *shot.list(abc()));
182 if(abc_list.size() >= 3) {
183 double a = shot[ *static_pointer_cast<
XDoubleNode> (abc_list.at(0))];
184 double b = shot[ *static_pointer_cast<
XDoubleNode> (abc_list.at(1))];
185 double c = shot[ *static_pointer_cast<
XDoubleNode> (abc_list.at(2))];
186 y = 1.0 / (a + b * res * lx + c * res * res);
192 XApproxThermometer::XApproxThermometer(
const char *name,
bool runtime) :
193 XThermometer(name, runtime), m_resList(create<XDoubleListNode> (
"ResList",
194 false)), m_tempList(create<XDoubleListNode> (
"TempList", false)) {
197 double XApproxThermometer::getTemp(
double res)
const {
201 std::map<double, double> pts;
202 if( !shot.size(m_resList))
205 if( !shot.size(m_tempList))
207 const auto &temp_list( *shot.list(m_tempList));
208 for(
unsigned int i = 0; i < std::min(res_list.size(), temp_list.size()); i++) {
209 double res = shot[ *static_pointer_cast<
XDoubleNode> (res_list.at(i))];
210 double temp = shot[ *static_pointer_cast<
XDoubleNode> (temp_list.at(i))];
211 pts.insert(std::pair<double, double>(log(res), log(temp)));
215 "XApproxThermometer, Too small number of points"), __FILE__, __LINE__);
219 return exp(approx->approx(log(res)));
221 double XApproxThermometer::getRawValue(
double temp)
const {
225 std::map<double, double> pts;
226 if( !shot.size(m_resList))
228 const auto &res_list( *shot.list(m_resList));
229 if( !shot.size(m_tempList))
231 const auto &temp_list( *shot.list(m_tempList));
232 for(
unsigned int i = 0; i < std::min(res_list.size(), temp_list.size()); i++) {
233 double res = shot[ *static_pointer_cast<
XDoubleNode> (res_list.at(i))];
234 double temp = shot[ *static_pointer_cast<
XDoubleNode> (temp_list.at(i))];
235 pts.insert(std::pair<double, double>(log(temp), log(res)));
239 "XApproxThermometer, Too small number of points"), __FILE__, __LINE__);
241 m_approx_inv = approx;
243 return exp(approx->approx(log(temp)));