Skip to content
Snippets Groups Projects
Commit 4c8fe610 authored by Erik Schnaubelt's avatar Erik Schnaubelt
Browse files

added kG10_v2 and kKapton_v2: introduce minimum temperature

parent 97c7a4a1
No related branches found
No related tags found
No related merge requests found
Pipeline #7589729 passed with warnings
#include <math.h>
#include <float.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
static const char *error = NULL;
EXPORT int init(const char *str) {
return 1;
}
EXPORT const char * getLastError() {
return error;
}
EXPORT int eval(const char *func,
int nArgs,
const double **inReal,
const double **inImag,
int blockSize,
double *outReal,
double *outImag) {
int i;
double a0 = -4.1236;
double a1 = 13.788;
double a2 = -26.068;
double a3 = 26.272;
double a4 = -14.663;
double a5 = 4.4954;
double a6 = -0.6905;
double a7 = 0.0397;
//linear approximation parameters
double m = 0.0017;
double n = 0.097983;
double log_T;
double f_exp;
if (strcmp("CFUN_kG10_v1", func) == 0) {
if (nArgs != 1) {
error = "One argument expected";
return 0;
}
for (i = 0; i < blockSize; i++) {
double T = inReal[0][i];
// Enforce minimum temperature of 1.9 K
// The value of kG10 is not computed in this case but can be directly returned
// for increased performance.
// BEWARE: the value of outReal needs to be changed if the function is changed
if(T < 1.9) {
outReal[i] = 0.01520715036820004;
return 1;
}
if(T < 300){
log_T = log10(T);
f_exp = (a0 + a1*log_T + a2*pow(log_T,2) + a3*pow(log_T,3) + a4*pow(log_T,4) + a5*pow(log_T,5) + a6*pow(log_T,6) + a7*pow(log_T,7));
outReal[i] = pow(10,f_exp);
}
if(T >= 300){
//linear approximation
outReal[i] = m*T + n;
}
/*Output consistency check*/
if(outReal[i]!=outReal[i]){
error = "Output is nan";
return 0;
}
if (fabs(outReal[i])>DBL_MAX){
error = "Output is inf";
return 0;
}
}
return 1;
}
else {
error = "Unknown function";
return 0;
}
}
#include <math.h>
#include <float.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
static const char *error = NULL;
EXPORT int init(const char *str) {
return 1;
}
EXPORT const char * getLastError() {
return error;
}
EXPORT int eval(const char *func,
int nArgs,
const double **inReal,
const double **inImag,
int blockSize,
double *outReal,
double *outImag) {
int i;
double a = 5.73101;
double b = -39.5199;
double c = 79.9313;
double d = -83.8572;
double e = 50.9157;
double f = -17.9835;
double g = 3.42413;
double h = -0.27133;
double m = 1.6367e-04;
double log_500 = log10(500);
double f_exp_500 = (a + b*log_500 + c*pow(log_500,2) + d*pow(log_500,3) + e*pow(log_500,4) + f*pow(log_500,5) + g*pow(log_500,6) + h*pow(log_500,7));
double n = pow(10,f_exp_500) - m*500; //0.142771;
double log_T;
double f_exp;
if (strcmp("CFUN_kKapton_v1", func) == 0) {
if (nArgs != 1) {
error = "One argument expected";
return 0;
}
for (i = 0; i < blockSize; i++) {
double T = inReal[0][i];
// Enforce minimum temperature of 1.9 K
// The value of kKapton is not computed in this case but can be directly returned
// for increased performance.
// BEWARE: the value of outReal needs to be changed if the function is changed
if(T < 1.9) {
outReal[i] = 0.006839;
return 1;
}
if(T <= 4.3) {
outReal[i] = 1.0703*1e-2 - 1.61*1e-3*(4.3-T);
}
else if (T > 4.3 && T <= 500) {
if(T==0){
T = 0.001;
}
log_T = log10(T);
f_exp = (a + b*log_T + c*pow(log_T,2) + d*pow(log_T,3) + e*pow(log_T,4) + f*pow(log_T,5) + g*pow(log_T,6) + h*pow(log_T,7));
outReal[i] = pow(10,f_exp);
}
if(T > 500){
//linear approximation
outReal[i] = m*T + n;
}
/*Output consistency check*/
if(outReal[i]!=outReal[i]){
error = "Output is nan";
return 0;
}
if (fabs(outReal[i])>DBL_MAX){
error = "Output is inf";
return 0;
}
}
return 1;
}
else {
error = "Unknown function";
return 0;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment