From 7128459575e8a5a1e16afef824c6be484ce948d9 Mon Sep 17 00:00:00 2001 From: Nicolas Tessore Date: Thu, 14 May 2015 16:56:05 +0200 Subject: [PATCH] smarter object definitions --- kernel/devauc.cl | 27 ++++++++++++++------------- kernel/eplp.cl | 14 +++++++------- kernel/eplp_plus_shear.cl | 16 ++++++++-------- kernel/exponential.cl | 23 ++++++++++++----------- kernel/gauss.cl | 25 +++++++++++++------------ kernel/nsie.cl | 37 +++++++++++++++++++------------------ kernel/nsis.cl | 17 +++++++++-------- kernel/object.cl | 21 ++++++++++++++++++--- kernel/point_mass.cl | 19 ++++++++++--------- kernel/sersic.cl | 27 ++++++++++++++------------- kernel/sie.cl | 25 +++++++++++++------------ kernel/sie_plus_shear.cl | 37 +++++++++++++++++++------------------ kernel/sis.cl | 19 ++++++++++--------- kernel/sis_plus_shear.cl | 23 ++++++++++++----------- kernel/sky.cl | 13 +++++++------ src/kernel.c | 22 +++++++++++----------- 16 files changed, 196 insertions(+), 169 deletions(-) diff --git a/kernel/devauc.cl b/kernel/devauc.cl index b934aaa..4bc3da0 100644 --- a/kernel/devauc.cl +++ b/kernel/devauc.cl @@ -1,11 +1,12 @@ -// De Vaucouleurs b param +// de Vaucouleurs b param #define DEVAUC_B 7.6692494425008039044f // (DEVAUC_B^8)/(8!) #define DEVAUC_C 296.826303766893f OBJECT(devauc) = SOURCE; -PARAMS(devauc) = { +PARAMETERS(devauc) +{ { "x" }, { "y" }, { "r" }, @@ -14,7 +15,7 @@ PARAMS(devauc) = { { "pa", true }, }; -struct devauc +DATA(devauc) { float2 x; // source position mat22 t; // coordinate transformation matric @@ -22,26 +23,26 @@ struct devauc float norm; // normalisation }; -static float devauc(constant struct devauc* data, float2 x) +BRIGHTNESS(devauc, float2 x) { - // DeVaucouleur's profile for centered and rotated coordinate system - return data->norm*exp(-DEVAUC_B*sqrt(sqrt(length(mv22(data->t, x - data->x))/data->rs))); -} + // de Vaucouleurs profile for centered and rotated coordinate system + return devauc->norm*exp(-DEVAUC_B*sqrt(sqrt(length(mv22(devauc->t, x - devauc->x))/devauc->rs))); +}; -static void set_devauc(global struct devauc* data, float x1, float x2, float r, float mag, float q, float pa) +SET(devauc, float x1, float x2, float r, float mag, float q, float pa) { float c = cos(pa*DEG2RAD); float s = sin(pa*DEG2RAD); // source position - data->x = (float2)(x1, x2); + devauc->x = (float2)(x1, x2); // transformation matrix: rotate and scale - data->t = (mat22)(q*c, q*s, -s, c); + devauc->t = (mat22)(q*c, q*s, -s, c); // scale length - data->rs = r; + devauc->rs = r; // normalisation to total luminosity - data->norm = exp(-0.4f*mag*LOG_10)/PI/r/r/q*DEVAUC_C; -} + devauc->norm = exp(-0.4f*mag*LOG_10)/PI/r/r/q*DEVAUC_C; +}; diff --git a/kernel/eplp.cl b/kernel/eplp.cl index 54ba831..3ef3381 100644 --- a/kernel/eplp.cl +++ b/kernel/eplp.cl @@ -2,7 +2,8 @@ // see Leier & Metcalf 2015 OBJECT(eplp) = LENS; -PARAMS(eplp) = { +PARAMETERS(eplp) +{ { "x" }, { "y" }, { "re" }, @@ -11,7 +12,7 @@ PARAMS(eplp) = { { "pa", true } }; -struct eplp +DATA(eplp) { float2 x; mat22 m; @@ -23,7 +24,7 @@ struct eplp float alpha; }; -static float2 eplp(constant struct eplp* eplp, float2 x) +DEFLECTION(eplp, float2 x) { float2 dy,y; float r; @@ -40,9 +41,9 @@ static float2 eplp(constant struct eplp* eplp, float2 x) y.y = a_iso * eplp->q2 * dy.y; return mv22(eplp->w, y); -} +}; -static void set_eplp(global struct eplp* eplp, float x1, float x2, float re, float alpha, float q, float pa) +SET(eplp, float x1, float x2, float re, float alpha, float q, float pa) { float c = cos(pa*DEG2RAD); float s = sin(pa*DEG2RAD); @@ -60,5 +61,4 @@ static void set_eplp(global struct eplp* eplp, float x1, float x2, float re, flo eplp->e = 1 - q*q; eplp->re = re; eplp->alpha = alpha; - -} +}; diff --git a/kernel/eplp_plus_shear.cl b/kernel/eplp_plus_shear.cl index 69df1fd..17d86c8 100644 --- a/kernel/eplp_plus_shear.cl +++ b/kernel/eplp_plus_shear.cl @@ -3,7 +3,8 @@ // see Leier & Metcalf 2015 OBJECT(eplp_plus_shear) = LENS; -PARAMS(eplp_plus_shear) = { +PARAMETERS(eplp_plus_shear) +{ { "x" }, { "y" }, { "re" }, @@ -12,10 +13,9 @@ PARAMS(eplp_plus_shear) = { { "pa", true }, { "g1" }, { "g2" } - }; -struct eplp_plus_shear +DATA(eplp_plus_shear) { float2 x; mat22 m; @@ -29,7 +29,7 @@ struct eplp_plus_shear mat22 g; }; -static float2 eplp_plus_shear(constant struct eplp_plus_shear* eplp_plus_shear, float2 x) +DEFLECTION(eplp_plus_shear, float2 x) { float2 y; @@ -46,9 +46,9 @@ static float2 eplp_plus_shear(constant struct eplp_plus_shear* eplp_plus_shear, y = mv22(eplp_plus_shear->w,y); return y + mv22(eplp_plus_shear->g, dx); -} +}; -static void set_eplp_plus_shear(global struct eplp_plus_shear* eplp_plus_shear, float x1, float x2, float re, float alpha, float q, float pa, float g1, float g2) +SET(eplp_plus_shear, float x1, float x2, float re, float alpha, float q, float pa, float g1, float g2) { float c = cos(pa*DEG2RAD); float s = sin(pa*DEG2RAD); @@ -66,6 +66,6 @@ static void set_eplp_plus_shear(global struct eplp_plus_shear* eplp_plus_shear, eplp_plus_shear->e = 1 - q*q; eplp_plus_shear->re = re; eplp_plus_shear->alpha = alpha; - + eplp_plus_shear->g = (mat22)(g1,g2,g2,-g1); -} +}; diff --git a/kernel/exponential.cl b/kernel/exponential.cl index 8f94d26..41b03ca 100644 --- a/kernel/exponential.cl +++ b/kernel/exponential.cl @@ -1,6 +1,7 @@ OBJECT(exponential) = SOURCE; -PARAMS(exponential) = { +PARAMETERS(exponential) +{ { "x" }, { "y" }, { "rs" }, @@ -9,7 +10,7 @@ PARAMS(exponential) = { { "pa", true }, }; -struct exponential +DATA(exponential) { float2 x; // source position mat22 t; // coordinate transformation matrix @@ -17,26 +18,26 @@ struct exponential float norm; // normalisation }; -static float exponential(constant struct exponential* data, float2 x) +BRIGHTNESS(exponential, float2 x) { // exponential profile for centered and rotated coordinate system - return data->norm*exp(-length(mv22(data->t, x - data->x))/data->rs); -} + return exponential->norm*exp(-length(mv22(exponential->t, x - exponential->x))/exponential->rs); +}; -static void set_exponential(global struct exponential* data, float x1, float x2, float rs, float mag, float q, float pa) +SET(exponential, float x1, float x2, float rs, float mag, float q, float pa) { float c = cos(pa*DEG2RAD); float s = sin(pa*DEG2RAD); // source position - data->x = (float2)(x1, x2); + exponential->x = (float2)(x1, x2); // transformation matrix: rotate and scale - data->t = (mat22)(q*c, q*s, -s, c); + exponential->t = (mat22)(q*c, q*s, -s, c); // scale length - data->rs = rs; + exponential->rs = rs; // normalisation to total luminosity - data->norm = exp(-0.4f*mag*LOG_10)*0.5f/PI/rs/rs/q; -} + exponential->norm = exp(-0.4f*mag*LOG_10)*0.5f/PI/rs/rs/q; +}; diff --git a/kernel/gauss.cl b/kernel/gauss.cl index 78ed7f0..e77bd0d 100644 --- a/kernel/gauss.cl +++ b/kernel/gauss.cl @@ -1,6 +1,7 @@ OBJECT(gauss) = SOURCE; -PARAMS(gauss) = { +PARAMETERS(gauss) +{ { "x" }, { "y" }, { "sigma" }, @@ -9,7 +10,7 @@ PARAMS(gauss) = { { "pa", true }, }; -struct gauss +DATA(gauss) { float2 x; // source position mat22 t; // coordinate transformation matrix @@ -17,24 +18,24 @@ struct gauss float norm; // normalisation }; -static float gauss(constant struct gauss* data, float2 x) +BRIGHTNESS(gauss, float2 x) { // Gaussian profile for centered and rotated coordinate system - float2 y = mv22(data->t, x - data->x); - return data->norm*exp(-0.5f*dot(y, y)/data->s2); -} + float2 y = mv22(gauss->t, x - gauss->x); + return gauss->norm*exp(-0.5f*dot(y, y)/gauss->s2); +}; -static void set_gauss(global struct gauss* data, float x1, float x2, float sigma, float mag, float q, float pa) +SET(gauss, float x1, float x2, float sigma, float mag, float q, float pa) { float c = cos(pa*DEG2RAD); float s = sin(pa*DEG2RAD); // source position - data->x = (float2)(x1, x2); + gauss->x = (float2)(x1, x2); // transformation matrix: rotate and scale - data->t = (mat22)(q*c, q*s, -s, c); + gauss->t = (mat22)(q*c, q*s, -s, c); - data->s2 = sigma*sigma; - data->norm = exp(-0.4f*mag*LOG_10)*0.5f/PI/data->s2/q; -} + gauss->s2 = sigma*sigma; + gauss->norm = exp(-0.4f*mag*LOG_10)*0.5f/PI/data->s2/q; +}; diff --git a/kernel/nsie.cl b/kernel/nsie.cl index 97b12bc..0d7e62d 100644 --- a/kernel/nsie.cl +++ b/kernel/nsie.cl @@ -3,7 +3,8 @@ OBJECT(nsie) = LENS; -PARAMS(nsie) = { +PARAMETERS(nsie) +{ { "x" }, { "y" }, { "r" }, @@ -12,7 +13,7 @@ PARAMS(nsie) = { { "pa", true } }; -struct nsie +DATA(nsie) { float2 x; // lens position mat22 m; // rotation matrix for position angle @@ -25,44 +26,44 @@ struct nsie float d; }; -static float2 nsie(constant struct nsie* data, float2 x) +DEFLECTION(nsie, float2 x) { float2 y; float r; // move to central coordinates - x -= data->x; + x -= nsie->x; // rotate coordinates by position angle - y = mv22(data->m, x); + y = mv22(nsie->m, x); // NSIE deflection - r = sqrt(data->q2*y.x*y.x + y.y*y.y); - y = data->d*(float2)(atan(y.x*data->e/(data->rc + r)), atanh(y.y*data->e/(data->rc*data->q2 + r))); + r = sqrt(nsie->q2*y.x*y.x + y.y*y.y); + y = nsie->d*(float2)(atan(y.x*nsie->e/(nsie->rc + r)), atanh(y.y*data->e/(nsie->rc*nsie->q2 + r))); // reverse coordinate rotation - return mv22(data->w, y); -} + return mv22(nsie->w, y); +}; -static void set_nsie(global struct nsie* data, float x1, float x2, float r, float rc, float q, float pa) +SET(nsie, float x1, float x2, float r, float rc, float q, float pa) { float c = cos(pa*DEG2RAD); float s = sin(pa*DEG2RAD); // lens position - data->x = (float2)(x1, x2); + nsie->x = (float2)(x1, x2); // rotation matrix - data->m = (mat22)(c, s, -s, c); + nsie->m = (mat22)(c, s, -s, c); // inverse rotation matrix - data->w = (mat22)(c, -s, s, c); + nsie->w = (mat22)(c, -s, s, c); // core radius - data->rc = rc; + nsie->rc = rc; // auxiliary quantities - data->q2 = q*q; - data->e = sqrt(1 - q*q); - data->d = r*sqrt(q)/sqrt(1 - q*q); -} + nsie->q2 = q*q; + nsie->e = sqrt(1 - q*q); + nsie->d = r*sqrt(q)/sqrt(1 - q*q); +}; diff --git a/kernel/nsis.cl b/kernel/nsis.cl index ab6f195..2827ea4 100644 --- a/kernel/nsis.cl +++ b/kernel/nsis.cl @@ -3,30 +3,31 @@ OBJECT(nsis) = LENS; -PARAMS(nsis) = { +PARAMETERS(nsis) +{ { "x" }, { "y" }, { "r" }, { "rc" } }; -struct nsis +DATA(nsis) { float2 x; // lens position float r; // Einstein radius float rc; // core radius }; -static float2 nsis(constant struct nsis* data, float2 x) +DEFLECTION(nsis, float2 x) { // move to central coordinates - x -= data->x; + x -= nsis->x; // NSIS deflection - return data->r/(data->rc + length(x))*x; -} + return nsis->r/(nsis->rc + length(x))*x; +}; -static void set_nsis(global struct nsis* nsis, float x1, float x2, float r, float rc) +SET(nsis, float x1, float x2, float r, float rc) { // lens position nsis->x = (float2)(x1, x2); @@ -36,4 +37,4 @@ static void set_nsis(global struct nsis* nsis, float x1, float x2, float r, floa // core radius nsis->rc = rc; -} +}; diff --git a/kernel/object.cl b/kernel/object.cl index 6c57637..1202db9 100644 --- a/kernel/object.cl +++ b/kernel/object.cl @@ -17,10 +17,25 @@ struct __attribute__ ((aligned(4))) param #define OBJECT(x) constant int object_##x // macro to simplify parameter definition for object -#define PARAMS(x) constant struct param parlst_##x[] +#define PARAMETERS(x) constant struct param parlst_##x[] = // macro to get number of parameters for object -#define NPARAMS(x) (sizeof(parlst_##x)/sizeof(struct param)) +#define NPAR(x) (sizeof(parlst_##x)/sizeof(struct param)) // macro to access specific parameter definition for object -#define PARAM(x, n) parlst_##x[n] +#define PAR(x, n) parlst_##x[n] + +// macro to simplify data struct definition for object +#define DATA(x) struct data_##x + +// macro to simplify deflection function for object +#define DEFLECTION(x, a) static float2 deflection_##x(constant DATA(x)* x, a) + +// macro to simplify surface brightness function for object +#define BRIGHTNESS(x, a) static float brightness_##x(constant DATA(x)* x, a) + +// macro to simplify foreground function for object +#define FOREGROUND(x, a) static float foreground_##x(constant DATA(x)* x, a) + +// macro to simplify setter function for object +#define SET(x, ...) static void set_##x(global DATA(x)* x, __VA_ARGS__) diff --git a/kernel/point_mass.cl b/kernel/point_mass.cl index 7b27361..7c9920f 100644 --- a/kernel/point_mass.cl +++ b/kernel/point_mass.cl @@ -2,29 +2,30 @@ OBJECT(point_mass) = LENS; -PARAMS(point_mass) = { +PARAMETERS(point_mass) +{ { "x" }, { "y" }, { "r" } }; -struct point_mass +DATA(point_mass) { float2 x; // lens position float r2; // Einstein radius squared }; -static float2 point_mass(constant struct point_mass* data, float2 x) +DEFLECTION(point_mass, float2 x) { // point mass deflection - return data->r2*normalize(x - data->x); -} + return point_mass->r2*normalize(x - point_mass->x); +}; -static void set_point_mass(global struct point_mass* data, float x1, float x2, float r) +SET(point_mass, float x, float y, float r) { // lens position - data->x = (float2)(x1, x2); + point_mass->x = (float2)(x, y); // Einstein radius squared - data->r2 = r*r; -} + point_mass->r2 = r*r; +}; diff --git a/kernel/sersic.cl b/kernel/sersic.cl index ea9b76b..390075e 100644 --- a/kernel/sersic.cl +++ b/kernel/sersic.cl @@ -1,6 +1,7 @@ OBJECT(sersic) = SOURCE; -PARAMS(sersic) = { +PARAMETERS(sersic) +{ { "x" }, { "y" }, { "r" }, @@ -10,7 +11,7 @@ PARAMS(sersic) = { { "pa", true }, }; -struct sersic +DATA(sersic) { float2 x; // source position mat22 t; // coordinate transformation matrix @@ -19,13 +20,13 @@ struct sersic float m; }; -static float sersic(constant struct sersic* data, float2 x) +BRIGHTNESS(sersic, float2 x) { - float2 y = mv22(data->t, x - data->x); - return exp(data->log0 - exp(data->log1 + data->m*log(dot(y, y)))); -} + float2 y = mv22(sersic->t, x - sersic->x); + return exp(sersic->log0 - exp(sersic->log1 + sersic->m*log(dot(y, y)))); +}; -static void set_sersic(global struct sersic* data, float x1, float x2, float r, float mag, float n, float q, float pa) +SET(sersic, float x, float y, float r, float mag, float n, float q, float pa) { float b = 1.9992f*n - 0.3271f; // approximation valid for 0.5 < n < 8 @@ -33,12 +34,12 @@ static void set_sersic(global struct sersic* data, float x1, float x2, float r, float s = sin(pa*DEG2RAD); // source position - data->x = (float2)(x1, x2); + sersic->x = (float2)(x, y); // transformation matrix: rotate and scale - data->t = (mat22)(q*c, q*s, -s, c); + sersic->t = (mat22)(q*c, q*s, -s, c); - data->log0 = -0.4f*mag*LOG_10 + 2*n*log(b) - LOG_PI - 2*log(r) - log(tgamma(2*n+1)); - data->log1 = log(b) - (0.5f*log(q) + log(r))/n; - data->m = 0.5f/n; -} + sersic->log0 = -0.4f*mag*LOG_10 + 2*n*log(b) - LOG_PI - 2*log(r) - log(tgamma(2*n+1)); + sersic->log1 = log(b) - (0.5f*log(q) + log(r))/n; + sersic->m = 0.5f/n; +}; diff --git a/kernel/sie.cl b/kernel/sie.cl index 140791d..94ce1c4 100644 --- a/kernel/sie.cl +++ b/kernel/sie.cl @@ -3,7 +3,8 @@ OBJECT(sie) = LENS; -PARAMS(sie) = { +PARAMETERS(sie) +{ { "x" }, { "y" }, { "r" }, @@ -11,7 +12,7 @@ PARAMS(sie) = { { "pa", true } }; -struct sie +DATA(sie) { float2 x; // lens position mat22 m; // rotation matrix for position angle @@ -23,32 +24,32 @@ struct sie float d; }; -static float2 sie(constant struct sie* data, float2 x) +DEFLECTION(sie, float2 x) { float2 y; float r; // move to central coordinates - x -= data->x; + x -= sie->x; // rotate coordinates by position angle - y = mv22(data->m, x); + y = mv22(sie->m, x); // SIE deflection - r = data->e/sqrt(data->q2*y.x*y.x + y.y*y.y); - y = data->d*(float2)(atan(y.x*r), atanh(y.y*r)); + r = sie->e/sqrt(sie->q2*y.x*y.x + y.y*y.y); + y = sie->d*(float2)(atan(y.x*r), atanh(y.y*r)); // reverse coordinate rotation - return mv22(data->w, y); -} + return mv22(sie->w, y); +}; -static void set_sie(global struct sie* sie, float x1, float x2, float r, float q, float pa) +SET(sie, float x, float y, float r, float q, float pa) { float c = cos(pa*DEG2RAD); float s = sin(pa*DEG2RAD); // lens position - sie->x = (float2)(x1, x2); + sie->x = (float2)(x, y); // rotation matrix sie->m = (mat22)(c, s, -s, c); @@ -60,4 +61,4 @@ static void set_sie(global struct sie* sie, float x1, float x2, float r, float q sie->q2 = q*q; sie->e = sqrt(1 - q*q); sie->d = r*sqrt(q)/sqrt(1 - q*q); -} +}; diff --git a/kernel/sie_plus_shear.cl b/kernel/sie_plus_shear.cl index 187c5db..f7400d1 100644 --- a/kernel/sie_plus_shear.cl +++ b/kernel/sie_plus_shear.cl @@ -3,7 +3,8 @@ OBJECT(sie_plus_shear) = LENS; -PARAMS(sie_plus_shear) = { +PARAMETERS(sie_plus_shear) +{ { "x" }, { "y" }, { "r" }, @@ -13,7 +14,7 @@ PARAMS(sie_plus_shear) = { { "g2" } }; -struct sie_plus_shear +DATA(sie_plus_shear) { float2 x; // lens position mat22 m; // rotation matrix for position angle @@ -26,44 +27,44 @@ struct sie_plus_shear float d; }; -static float2 sie_plus_shear(constant struct sie_plus_shear* data, float2 x) +DEFLECTION(sie_plus_shear, float2 x) { float2 y; float r; // move to central coordinates - x -= data->x; + x -= sie_plus_shear->x; // rotate coordinates by position angle - y = mv22(data->m, x); + y = mv22(sie_plus_shear->m, x); // SIE deflection - r = data->e/sqrt(data->q2*y.x*y.x + y.y*y.y); - y = data->d*(float2)(atan(y.x*r), atanh(y.y*r)); + r = sie_plus_shear->e/sqrt(sie_plus_shear->q2*y.x*y.x + y.y*y.y); + y = sie_plus_shear->d*(float2)(atan(y.x*r), atanh(y.y*r)); // reverse coordinate rotation, apply shear - return mv22(data->w, y) + mv22(data->g, x); -} + return mv22(sie_plus_shear->w, y) + mv22(sie_plus_shear->g, x); +}; -static void set_sie_plus_shear(global struct sie_plus_shear* data, float x1, float x2, float r, float q, float pa, float g1, float g2) +SET(sie_plus_shear, float x1, float x2, float r, float q, float pa, float g1, float g2) { float c = cos(pa*DEG2RAD); float s = sin(pa*DEG2RAD); // lens position - data->x = (float2)(x1, x2); + sie_plus_shear->x = (float2)(x1, x2); // rotation matrix - data->m = (mat22)(c, s, -s, c); + sie_plus_shear->m = (mat22)(c, s, -s, c); // inverse rotation matrix - data->w = (mat22)(c, -s, s, c); + sie_plus_shear->w = (mat22)(c, -s, s, c); // shear matrix - data->g = (mat22)(g1, g2, g2, -g1); + sie_plus_shear->g = (mat22)(g1, g2, g2, -g1); // auxiliary quantities - data->q2 = q*q; - data->e = sqrt(1 - q*q); - data->d = r*sqrt(q)/sqrt(1 - q*q); -} + sie_plus_shear->q2 = q*q; + sie_plus_shear->e = sqrt(1 - q*q); + sie_plus_shear->d = r*sqrt(q)/sqrt(1 - q*q); +}; diff --git a/kernel/sis.cl b/kernel/sis.cl index 3a35a37..5102886 100644 --- a/kernel/sis.cl +++ b/kernel/sis.cl @@ -3,29 +3,30 @@ OBJECT(sis) = LENS; -PARAMS(sis) = { +PARAMETERS(sis) +{ { "x" }, { "y" }, { "r" } }; -struct sis +DATA(sis) { float2 x; // lens position float r; // Einstein radius }; -static float2 sis(constant struct sis* data, float2 x) +DEFLECTION(sis, float2 x) { // SIS deflection - return data->r*normalize(x - data->x); -} + return sis->r*normalize(x - sis->x); +}; -static void set_sis(global struct sis* data, float x1, float x2, float r) +SET(sis, float x, float y, float r) { // lens position - data->x = (float2)(x1, x2); + sis->x = (float2)(x, y); // Einstein radius - data->r = r; -} + sis->r = r; +}; diff --git a/kernel/sis_plus_shear.cl b/kernel/sis_plus_shear.cl index 6dcd0ae..7f48dbd 100644 --- a/kernel/sis_plus_shear.cl +++ b/kernel/sis_plus_shear.cl @@ -2,7 +2,8 @@ OBJECT(sis_plus_shear) = LENS; -PARAMS(sis_plus_shear) = { +PARAMETERS(sis_plus_shear) +{ { "x" }, { "y" }, { "r" }, @@ -10,30 +11,30 @@ PARAMS(sis_plus_shear) = { { "g2" } }; -struct sis_plus_shear +DATA(sis_plus_shear) { float2 x; // lens position mat22 g; // shear matrix float r; // Einstein radius }; -static float2 sis_plus_shear(constant struct sis_plus_shear* data, float2 x) +DEFLECTION(sis_plus_shear, float2 x) { // move to central coordinates - x -= data->x; + x -= sis_plus_shear->x; // SIS deflection plus external shear - return data->r*normalize(x) + mv22(data->g, x); -} + return sis_plus_shear->r*normalize(x) + mv22(sis_plus_shear->g, x); +}; -static void set_sis_plus_shear(global struct sis_plus_shear* data, float x1, float x2, float r, float g1, float g2) +SET(sis_plus_shear, float x1, float x2, float r, float g1, float g2) { // lens position - data->x = (float2)(x1, x2); + sis_plus_shear->x = (float2)(x1, x2); // Einstein radius - data->r = r; + sis_plus_shear->r = r; // shear matrix - data->g = (mat22)(g1, g2, g2, -g1); -} + sis_plus_shear->g = (mat22)(g1, g2, g2, -g1); +}; diff --git a/kernel/sky.cl b/kernel/sky.cl index 477269b..4843616 100644 --- a/kernel/sky.cl +++ b/kernel/sky.cl @@ -1,24 +1,25 @@ OBJECT(sky) = FOREGROUND; -PARAMS(sky) = { +PARAMETERS(sky) +{ { "bg" }, { "dx" }, { "dy" } }; -struct sky +DATA(sky) { float bg; float2 grad; }; -static float sky(constant struct sky* sky, float2 x) +FOREGROUND(sky, float2 x) { return sky->bg + dot(sky->grad, x - (float2)(1, 1)); -} +}; -static void set_sky(global struct sky* sky, float bg, float dx, float dy) +SET(sky, float bg, float dx, float dy) { sky->bg = bg; sky->grad = (float2)(dx, dy); -} +}; diff --git a/src/kernel.c b/src/kernel.c index ac4c623..cf36a90 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -34,24 +34,24 @@ static const size_t NMAINKERNS = sizeof(MAINKERNS)/sizeof(MAINKERNS[0]); // kernel to get meta-data for object static const char METAKERN[] = - "kernel void meta_(global int* type, global ulong* size, global ulong* npars)\n" + "kernel void meta_(global int* type, global ulong* size, global ulong* npar)\n" "{\n" " *type = object_;\n" - " *size = sizeof(struct );\n" - " *npars = NPARAMS();\n" + " *size = sizeof(struct data_);\n" + " *npar = NPAR();\n" "}\n" ; // kernel to get parameters for object static const char PARSKERN[] = - "kernel void params_(global struct param* params)\n" + "kernel void params_(global struct param* par)\n" "{\n" - " for(size_t i = 0; i < NPARAMS(); ++i)\n" + " for(size_t i = 0; i < NPAR(); ++i)\n" " {\n" - " for(size_t j = 0; j < sizeof(params[i].name); ++j)\n" - " params[i].name[j] = PARAM(, i).name[j];\n" + " for(size_t j = 0; j < sizeof(par[i].name); ++j)\n" + " par[i].name[j] = PAR(, i).name[j];\n" " \n" - " params[i].wrap = PARAM(, i).wrap;\n" + " par[i].wrap = PAR(, i).wrap;\n" " }\n" "}\n" ; @@ -74,7 +74,7 @@ static const char COMPLHED[] = " // calculate deflection\n" ; static const char COMPLENS[] = - " a += %s((constant void*)(data + %zu), y);\n" + " a += deflection_%s((constant void*)(data + %zu), y);\n" ; static const char COMPDEFL[] = " \n" @@ -86,14 +86,14 @@ static const char COMPSHED[] = " // calculate surface brightness\n" ; static const char COMPSRCE[] = - " f += %s((constant void*)(data + %zu), y);\n" + " f += brightness_%s((constant void*)(data + %zu), y);\n" ; static const char COMPFHED[] = " \n" " // add foreground\n" ; static const char COMPFGND[] = - " f += %s((constant void*)(data + %zu), x);\n" + " f += foreground_%s((constant void*)(data + %zu), x);\n" ; static const char COMPFOOT[] = " \n"