Skip to content

Commit

Permalink
smarter object definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Tessore committed May 15, 2015
1 parent d44e9c5 commit 7128459
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 169 deletions.
27 changes: 14 additions & 13 deletions kernel/devauc.cl
Original file line number Diff line number Diff line change
@@ -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" },
Expand All @@ -14,34 +15,34 @@ PARAMS(devauc) = {
{ "pa", true },
};

struct devauc
DATA(devauc)
{
float2 x; // source position
mat22 t; // coordinate transformation matric
float rs; // scale length
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;
};
14 changes: 7 additions & 7 deletions kernel/eplp.cl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// see Leier & Metcalf 2015
OBJECT(eplp) = LENS;

PARAMS(eplp) = {
PARAMETERS(eplp)
{
{ "x" },
{ "y" },
{ "re" },
Expand All @@ -11,7 +12,7 @@ PARAMS(eplp) = {
{ "pa", true }
};

struct eplp
DATA(eplp)
{
float2 x;
mat22 m;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;

}
};
16 changes: 8 additions & 8 deletions kernel/eplp_plus_shear.cl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// see Leier & Metcalf 2015
OBJECT(eplp_plus_shear) = LENS;

PARAMS(eplp_plus_shear) = {
PARAMETERS(eplp_plus_shear)
{
{ "x" },
{ "y" },
{ "re" },
Expand All @@ -12,10 +13,9 @@ PARAMS(eplp_plus_shear) = {
{ "pa", true },
{ "g1" },
{ "g2" }

};

struct eplp_plus_shear
DATA(eplp_plus_shear)
{
float2 x;
mat22 m;
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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);
}
};
23 changes: 12 additions & 11 deletions kernel/exponential.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
OBJECT(exponential) = SOURCE;

PARAMS(exponential) = {
PARAMETERS(exponential)
{
{ "x" },
{ "y" },
{ "rs" },
Expand All @@ -9,34 +10,34 @@ PARAMS(exponential) = {
{ "pa", true },
};

struct exponential
DATA(exponential)
{
float2 x; // source position
mat22 t; // coordinate transformation matrix
float rs; // scale length
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;
};
25 changes: 13 additions & 12 deletions kernel/gauss.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
OBJECT(gauss) = SOURCE;

PARAMS(gauss) = {
PARAMETERS(gauss)
{
{ "x" },
{ "y" },
{ "sigma" },
Expand All @@ -9,32 +10,32 @@ PARAMS(gauss) = {
{ "pa", true },
};

struct gauss
DATA(gauss)
{
float2 x; // source position
mat22 t; // coordinate transformation matrix
float s2; // variance
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;
};
37 changes: 19 additions & 18 deletions kernel/nsie.cl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

OBJECT(nsie) = LENS;

PARAMS(nsie) = {
PARAMETERS(nsie)
{
{ "x" },
{ "y" },
{ "r" },
Expand All @@ -12,7 +13,7 @@ PARAMS(nsie) = {
{ "pa", true }
};

struct nsie
DATA(nsie)
{
float2 x; // lens position
mat22 m; // rotation matrix for position angle
Expand All @@ -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);
};
17 changes: 9 additions & 8 deletions kernel/nsis.cl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,4 +37,4 @@ static void set_nsis(global struct nsis* nsis, float x1, float x2, float r, floa

// core radius
nsis->rc = rc;
}
};
Loading

0 comments on commit 7128459

Please sign in to comment.