LALInspiral 5.0.3.1-eeff03c
NDTemplateBank.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Chad Hanna, Jolien Creighton, Benjamin Owen, Reinhard Prix
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/**
21 * \author Hanna, C. R.
22 * \file
23 * \ingroup TemplateBankGeneration_h
24 *
25 * \brief This module handles template bank generation for up to searches with
26 * \f$<=\f$ 12 dimensional parameter spaces.
27 *
28 * ### Prototypes ###
29 *
30 * <tt>LALNDTemplateBank()</tt>
31 *
32 * ### Description ###
33 *
34 * This module tiles up to a 12 dimensional space when given a metric and a
35 * function that determines the search region.
36 *
37 * ### Algorithm ###
38 *
39 * The algorithm first draws a rectilinear box in the primed coordinates
40 * which includes the distorted box, then steps through along the directions
41 * of the primed coordinates. At each point it tests if the point lies
42 * within the distorted box. If the point is inside the distorted box, the
43 * algorithm adds a template to the linked list. If not, it continues.
44 *
45 * ### Uses ###
46 *
47 * \code
48 * LALCalloc()
49 * LALFree()
50 * \endcode
51 *
52 * ### Notes ###
53 *
54 */
55
56#include <math.h>
57#include <lal/LALStdlib.h>
58#include <lal/LALStatusMacros.h>
59#include <lal/AVFactories.h>
60#include <lal/LALConfig.h>
61#include <lal/LALConstants.h>
62#include <lal/LALDatatypes.h>
63#include <lal/LALMalloc.h>
64#include <lal/MatrixUtils.h>
65#include <lal/TemplateBankGeneration.h>
66
67static REAL4 DotProduct(REAL4 *EV, REAL4 *DX){
68 INT2 loop = 0;
69 REAL4 dot = 0.0;
70
71 for (loop = 0; loop < 12; loop++){
72 dot += EV[loop] * DX[loop];
73 }
74 return dot;
75 }
76
77
78
79void
80
83 NDTemplateBankFunctionPtrs *functionPtrs,
84 NDTemplateBankOutput **output)
85
86{
87
88 INT2 Dimension = input->dimension;
89 REAL4Array *metric = NULL; /* parameter-space metric */
90 REAL4Array *inverse = NULL;
91 REAL4 det = 0;
92 UINT4Vector *metricDimensions = NULL; /* contains the dimension of metric */
93 REAL4Vector *eigenval = NULL; /* eigenvalues of metric */
94 NDTemplateBankOutput *bank = NULL; /* the template bank */
95 NDTemplateBankOutput *first = NULL;
96 INT2 dimLoop = 0;
97 INT2 loop = 0;
98 INT2 testFlag = 0;
99 REAL4 dxLoop[12] = {0};
100 REAL4 coordinatedxs[12] = {1,1,1,1,1,1,1,1,1,1,1,1};
101 REAL4 EV[12][12] = {{0}};
102 REAL4 EVinv[12][12] = {{0}};
103 REAL4 minX[12] = {0};
104 REAL4 maxX[12] = {0};
105 REAL4 temp = 0;
106 INT4 cnt = 0;
107 /* INT4 bccFlag = 0; */
108
111
112
113 /* Initialize unused portions of input arrays */
114 for(dimLoop = Dimension; dimLoop < 12; dimLoop++){
115 input->minCoordinates[dimLoop] = 0.0;
116 input->maxCoordinates[dimLoop] = 0.0;
117 input->minParameters[dimLoop] = 0.0;
118 input->maxParameters[dimLoop] = 0.0;
119 }
120
121
122 /* Set up the metric stuff */
123 LALSCreateVector( status->statusPtr, &eigenval, (UINT4) Dimension);
124 LALU4CreateVector( status->statusPtr, &metricDimensions, (UINT4) 2 );
125 metricDimensions->data[1] = metricDimensions->data[0] = Dimension;
126 LALSCreateArray( status->statusPtr, &metric, metricDimensions );
127 LALSCreateArray( status->statusPtr, &inverse, metricDimensions );
128
129
130 /* Call Metric Function */
131 functionPtrs->metric(status->statusPtr, input, metric);
132
133 /* Begin all the diagonalization business */
134 LALSSymmetricEigenVectors( status->statusPtr, eigenval, metric );
135 /* Extract eigenvectors and determine displacements*/
136 for (dimLoop = 0; dimLoop < Dimension; dimLoop++){
137 for (loop = 0; loop < Dimension; loop++){
138 EV[dimLoop][loop] = metric->data[loop*Dimension + dimLoop];
139 }
140 }
141
142/*
143 if (Dimension == 3){
144 coordinatedxs[0] = 1.3333333 * sqrt(2.0*input->mm/(eigenval->data[0]));
145 coordinatedxs[1] = 1.3333333 * sqrt(2.0*input->mm/(eigenval->data[1]));
146 coordinatedxs[2] = 0.6666667 * sqrt(2.0*input->mm/(eigenval->data[2]));
147 }
148*/
149
150 for (dimLoop = 0; dimLoop < Dimension; dimLoop++){
151 coordinatedxs[dimLoop] = sqrt(2.0*input->mm/((REAL4) Dimension * eigenval->data[dimLoop]));
152 }
153
154 printf("\nCoordinatedxs = %f,%f,%f\n", coordinatedxs[0], coordinatedxs[1], coordinatedxs[2]);
155
156 /* invert the transformation matrix */
157 TRY(LALSMatrixInverse(status->statusPtr, &det, metric, inverse), status);
158
159
160 for (dimLoop = 0; dimLoop < Dimension; dimLoop++){
161 for (loop = 0; loop < Dimension; loop++){
162 EVinv[dimLoop][loop] = inverse->data[loop*Dimension + dimLoop];
163 }
164 }
165
166
167
168 printf("\nmin and max coordinates before transformation\n");
169 for (dimLoop = 0; dimLoop < Dimension; dimLoop++){
170 printf("MinX[%i] = %f\tMaxX[%i] = %f\n", dimLoop, input->minCoordinates[dimLoop], dimLoop, input->maxCoordinates[dimLoop]);
171 }
172
173 printf("\nmin and max coordinates after transformation\n");
174
175 /* transform initial coordinates */
176 for (dimLoop = 0; dimLoop < Dimension; dimLoop++){
177 minX[dimLoop] = DotProduct(EVinv[dimLoop], input->minCoordinates);
178 maxX[dimLoop] = DotProduct(EVinv[dimLoop], input->maxCoordinates);
179 printf("MinX[%i] = %f\tMaxX[%i] = %f\n", dimLoop, minX[dimLoop], dimLoop, maxX[dimLoop]);
180 }
181
182
183 /*switch around the bounds according to sign */
184 for (dimLoop = 0; dimLoop < Dimension; dimLoop++){
185 if (minX[dimLoop] > maxX[dimLoop]){
186 temp = minX[dimLoop];
187 minX[dimLoop] = maxX[dimLoop];
188 maxX[dimLoop] = temp;
189 }
190 }
191
192
193 /* allocate first template bank node */
194 first = bank = (NDTemplateBankOutput *) LALCalloc(1, sizeof(NDTemplateBankOutput));
195 for(dxLoop[11] = minX[11];
196 dxLoop[11] <= maxX[11];
197 dxLoop[11] += coordinatedxs[11]){
198 for(dxLoop[10] = minX[10];
199 dxLoop[10] <= maxX[10];
200 dxLoop[10] += coordinatedxs[10]){
201 for(dxLoop[9] = minX[9];
202 dxLoop[9] <= maxX[9];
203 dxLoop[9] += coordinatedxs[9]){
204 for(dxLoop[8] = minX[8];
205 dxLoop[8] <= maxX[8];
206 dxLoop[8] += coordinatedxs[8]){
207 for(dxLoop[7] = minX[7];
208 dxLoop[7] <= maxX[7];
209 dxLoop[7] += coordinatedxs[7]){
210 for(dxLoop[6] = minX[6];
211 dxLoop[6] <= maxX[6];
212 dxLoop[6] += coordinatedxs[6]){
213 for(dxLoop[5] = minX[5];
214 dxLoop[5] <= maxX[5];
215 dxLoop[5] += coordinatedxs[5]){
216 for(dxLoop[4] = minX[4];
217 dxLoop[4] <= maxX[4];
218 dxLoop[4] += coordinatedxs[4]){
219 for(dxLoop[3] = minX[3];
220 dxLoop[3] <= maxX[3];
221 dxLoop[3] += coordinatedxs[3]){
222 for(dxLoop[2] = minX[2];
223 dxLoop[2] <= maxX[2];
224 dxLoop[2] += coordinatedxs[2]){
225 for(dxLoop[1] = minX[1];
226 dxLoop[1] <= maxX[1];
227 dxLoop[1] += coordinatedxs[1]){
228 for(dxLoop[0] = minX[0];
229 dxLoop[0] <= maxX[0];
230 dxLoop[0] += coordinatedxs[0]){
231 /* test spot */
232 for(dimLoop=0; dimLoop < Dimension; dimLoop++){
233 bank->coordinateVals[dimLoop] = DotProduct(EV[dimLoop], dxLoop);
234 }
235 functionPtrs->test(status->statusPtr, input, bank, &testFlag);
236 if (testFlag){
237 bank = bank->next = (NDTemplateBankOutput *) LALCalloc(1, sizeof(NDTemplateBankOutput));
238 }
239
240 /* go dx behind */
241 for(dimLoop=0; dimLoop < Dimension; dimLoop++){
242 bank->coordinateVals[dimLoop] = DotProduct(EV[dimLoop], dxLoop) - DotProduct(EV[dimLoop], coordinatedxs);
243 /* set the other values to loop values */
244 for(loop=0; loop < dimLoop; loop++){
245 bank->coordinateVals[loop] = DotProduct(EV[loop], dxLoop);
246 }
247 /* test the next spot */
248 functionPtrs->test(status->statusPtr, input, bank, &testFlag);
249 /* if it fails test the halfway point */
250 if (!testFlag){
251 bank->coordinateVals[dimLoop] = DotProduct(EV[dimLoop], dxLoop) - 0.5 * DotProduct(EV[dimLoop], coordinatedxs);
252 functionPtrs->test(status->statusPtr, input, bank, &testFlag);
253 /* if the halfway point passes add it */
254 if (testFlag){
255 cnt++;
256 bank = bank->next = (NDTemplateBankOutput *) LALCalloc(1, sizeof(NDTemplateBankOutput));
257 }
258 }
259 }
260 /* go dx ahead */
261 for(dimLoop=0; dimLoop < Dimension; dimLoop++){
262 bank->coordinateVals[dimLoop] = DotProduct(EV[dimLoop], dxLoop) + DotProduct(EV[dimLoop], coordinatedxs);
263 /* set the other values to loop values */
264 for(loop=0; loop < dimLoop; loop++){
265 bank->coordinateVals[loop] = DotProduct(EV[loop], dxLoop);
266 }
267 /* test the next spot */
268 functionPtrs->test(status->statusPtr, input, bank, &testFlag);
269 /* if it fails test the halfway point */
270 if (!testFlag){
271 bank->coordinateVals[dimLoop] = DotProduct(EV[dimLoop], dxLoop) + 0.5 * DotProduct(EV[dimLoop], coordinatedxs);
272 functionPtrs->test(status->statusPtr, input, bank, &testFlag);
273 /* if the halfway point passes add it */
274 if (testFlag){
275 cnt++;
276 bank = bank->next = (NDTemplateBankOutput *) LALCalloc(1, sizeof(NDTemplateBankOutput));
277 }
278 }
279 }
280
281 }
282 }
283 }
284 }
285 }
286 }
287 }
288 }
289 }
290 }
291 }
292 }
293
294
295 printf("\nExtra templates added = %i\n", cnt);
296 /* setting the output to the first template bank tile */
297 bank->next = NULL;
298 *output = first;
299
300 /* if(testFlag) LALFree(bank) */;
302 RETURN(status);
303
304}
#define LALCalloc(m, n)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
static REAL4 DotProduct(REAL4 *EV, REAL4 *DX)
void LALSCreateArray(LALStatus *, REAL4Array **, UINT4Vector *)
void LALSMatrixInverse(LALStatus *stat, REAL4 *det, REAL4Array *matrix, REAL4Array *inverse)
void LALSSymmetricEigenVectors(LALStatus *stat, REAL4Vector *values, REAL4Array *matrix)
int16_t INT2
uint32_t UINT4
int32_t INT4
float REAL4
void LALNDTemplateBank(LALStatus *status, NDTemplateBankInput *input, NDTemplateBankFunctionPtrs *functionPtrs, NDTemplateBankOutput **output)
void LALU4CreateVector(LALStatus *, UINT4Vector **, UINT4)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
NDTemplateBankTestPtr test
Ptr boundary test fct
NDTemplateBankMetricPtr metric
Ptr to metric function.
REAL4 minCoordinates[12]
Psi0, Psi3, etc
REAL4 maxParameters[12]
mass, eta, etc
REAL4 minParameters[12]
mass, eta, etc
INT2 dimension
3D?, 4D? -> ND!
REAL4 maxCoordinates[12]
Psi0, Psi3, etc
struct tagNDTemplateBankOutput * next
REAL4 * data
REAL4 * data
UINT4 * data
char output[FILENAME_MAX]