examples_ug_optics.cc 89.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10


#include "../mympi.h"
#include "../abbrevi.h"
#include "../parameter.h"
#include "../math_lib/math_lib.h"
#include "../basics/basic.h"
#include "elements.h"
#include "parti.h"
#include "ug.h"
11
#include <algorithm>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "examples_ug_optics.h"

////////////////////////////////////////////////////////////////////
// cylinder : params already defined, but for understanding the code (me, phillip) this stays here.
////////////////////////////////////////////////////////////////////

D3vector transform_quadrangle_NULL( double t1,double t2, double* pointer_global_data ) {
  return D3vector (0,0,0);
}

D3vector transform_outer_boundary_SE( double t1,double t2, double* pointer_global_data ) {

    double R_global_data = pointer_global_data[0];
    double x = (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    double y = -( sin ( t1*0.5*M_PI )-t1);
    double z = 0;
    return R_global_data*D3vector ( x,y,z);
}
D3vector transform_outer_boundary_SW( double t1,double t2, double* pointer_global_data ) {

    double R_global_data = pointer_global_data[0];
    double x = -(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    double y = -( sin ( t1*0.5*M_PI )-t1);
    double z = 0;
    return R_global_data*D3vector ( x,y,z);
}

D3vector transform_outer_boundary_NE( double t1,double t2, double* pointer_global_data ) {

    double R_global_data = pointer_global_data[0];
    double x = (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    double y = ( sin ( t1*0.5*M_PI )-t1);
    double z = 0;
    return R_global_data*D3vector ( x,y,z);
}
D3vector transform_outer_boundary_NW( double t1,double t2, double* pointer_global_data ) {

    double R_global_data = pointer_global_data[0];
    double x = -( sin ( t1*0.5*M_PI )-t1);
    double y = (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    double z = 0;
    return R_global_data*D3vector ( x,y,z);
}

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
D3vector transform_outer_boundary_SE_cut( double t1,double t2, double* pointer_global_data ) {

    double R_outer = pointer_global_data[12];
    double x = (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    double y = -( sin ( t1*0.5*M_PI )-t1);
    double z = 0;
    return R_outer*D3vector ( x,y,z);
}
D3vector transform_outer_boundary_SW_cut( double t1,double t2, double* pointer_global_data ) {

    double R_outer = pointer_global_data[12];
    double x = -(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    double y = -( sin ( t1*0.5*M_PI )-t1);
    double z = 0;
    return R_outer*D3vector ( x,y,z);
}

D3vector transform_outer_boundary_NE_cut( double t1,double t2, double* pointer_global_data ) {

    double R_outer = pointer_global_data[12];
    double x = (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    double y = ( sin ( t1*0.5*M_PI )-t1);
    double z = 0;
    return R_outer*D3vector ( x,y,z);
}
D3vector transform_outer_boundary_NW_cut( double t1,double t2, double* pointer_global_data ) {

    double R_outer = pointer_global_data[12];
    double x = -( sin ( t1*0.5*M_PI )-t1);
    double y = (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    double z = 0;
    return R_outer*D3vector ( x,y,z);
}

90
91
92
93
94
95
D3vector transform_right_lens_diag_NW_quad ( double t1, double t2, double* pointer_global_data) {

    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
96
    double thickness_global_data      = pointer_global_data[4];
97
98
99
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
100
101
102
103
104
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double cut_edge_from_left         = pointer_global_data[10];
    double cut_edge_from_right        = pointer_global_data[11];

105
106
107
108
109
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
   // t2 = (1-t2);
110
    double x = -R_global_data*( sin ( t1*0.5*M_PI )-t1);
111
    x = x*t2;
112
    double y = R_global_data*(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
113
114
115
116
117
    y = y*t2;
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;

    actualX = -actualX;
118
    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));
119
120
121
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;

    double z = offsetZ_global_data+
122
123
124
                sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                               radiusSquared)
                          + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));
125

126
127

    if (std::isnan(z))
128
    {
129
        z = 0;
130
131
132
    }


133
    return D3vector ( x,y,z);
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152

}

D3vector transform_right_lens_inner_quad ( double t1, double t2, double* pointer_global_data) {
    double R_global_data = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data          = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
    t2 = (1-t2);
153

154
155
156
157
158
159
160
161
162
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;


    double actualX = + r_global_data * t1 - r_global_data * t2;
    double actualY = - r_global_data * t1 - r_global_data * t2 + r_global_data;

    actualY = -actualY;
    actualX = -actualX;

163
    double radiusSquared = (actualY*actualY+actualX*actualX);
164

165
166
    double z = offsetZ_global_data
            +sign*(( sqrt(pow(curvatureRight_global_data,2)- radiusSquared) //pow(r_global_data,2) * (t*t + (1-t)*(1-t)))
167
168
169
170
                     +sign*(- curvatureRight_global_data + (thickness_global_data-z_right_inner_global_data)) ));
    if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
    {
        //cout << "x " << actualX << " y " << actualY <<endl;
171
172
173
174
//        if ( fabs(z) > 1e-8)
//        {
//            cout << " stop  "<<endl;
//        }
175
    }
176

177
178

    //return D3vector (0 , 0 , fabs((t1-0)*(t2-0)*(t1-1)*(t2-1)) * 10);
179
        return D3vector (0 , 0 , z);
180
181
182
}

D3vector transform_left_lens_inner_quad ( double t1, double t2, double* pointer_global_data) {
183
    double R_global_data              = pointer_global_data[0];
184
185
186
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
187
    double thickness_global_data      = pointer_global_data[4];
188
189
190
191
192
193
194
195
196
197
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
    t2 = (1-t2);
198
199
200



201
    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
202
203
204
205
206
207
208
209
210
211
212
213
214


    double actualX = + r_global_data * t1 - r_global_data * t2;
    double actualY = - r_global_data * t1 - r_global_data * t2 + r_global_data;

    actualY = -actualY;
    actualX = -actualX;

    double actualRadius = (actualY*actualY+actualX*actualX);

    double z = 0;


215
216
217
218
219
    z = offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-actualRadius) - sign* (curvatureLeft_global_data - z_left_inner_global_data)) );

    if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
    {
        //cout << "x " << actualX << " y " << actualY <<endl;
220
221
222
223
//        if ( fabs(z) > 1e-8)
//        {
//            cout << " stop  "<<endl;
//        }
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
    }
        return D3vector (0 , 0 , z);

}

D3vector transform_left_lens_diag_NW_quad ( double t1, double t2, double* pointer_global_data) {
    double R_global_data = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
   // t2 = (1-t2);
    double x = -R_global_data*( sin ( t1*0.5*M_PI )-t1);
    x = x*t2;
    double y = R_global_data*(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    y = y*t2;
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;

    actualX = -actualX;
    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;

    double z =offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-radiusSquared) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
     if (std::isnan(z))
     {z = 0;}

     return D3vector ( x,y,z);
}





D3vector transform_right_lens_diag_SW_quad ( double t1, double t2, double* pointer_global_data) {
    double R_global_data = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
    double x = -R_global_data *( sin ( t1*0.5*M_PI )-t1);
    x = x*t2;
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    y = y*t2;
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    actualY = -actualY;
    actualX = -actualX;
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;

    double z = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                           ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY)))
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));


    if (std::isnan(z))
    {        z = 0;    }
    return D3vector ( x,y,z);

}

D3vector transform_left_lens_diag_SW_quad ( double t1, double t2, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
    double x = -R_global_data *( sin ( t1*0.5*M_PI )-t1);
    x = x*t2;
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    y = y*t2;
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    actualY = -actualY;
    actualX = -actualX;

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;

    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));

    double z =offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-radiusSquared) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
     if (std::isnan(z))
     {z = 0;}

     return D3vector ( x,y,z);
}


D3vector transform_left_lens_diag_SE_quad ( double t1, double t2, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
    double x =R_global_data * ( sin ( t1*0.5*M_PI )-t1);
    x = x*t2;
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    y = y*t2;

    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    actualY = -actualY;

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));

    //std::cout << "radius inner " << sqrt(radiusSquared ) << std::endl;
    double z =offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-radiusSquared) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
     if (std::isnan(z))
     {z = 0;}

     return D3vector ( x,y,z);
}

D3vector transform_right_lens_diag_SE_quad ( double t1, double t2, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
    double x =R_global_data * ( sin ( t1*0.5*M_PI )-t1);
    x = x*t2;
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    y = y*t2;

    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    actualY = -actualY;
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;

    double z = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                           ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY)))
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));


    if (std::isnan(z))
    {
    z = 0;}
    return D3vector ( x,y,z);

}

D3vector transform_left_lens_diag_NE_quad ( double t1, double t2, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;

    t1 = t2;
    t2 = temp;
    double t = t2;

    double x = R_global_data * ( sin ( t1*0.5*M_PI )-t1);

    x = x*t2;
    double y = R_global_data *  (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    y = y*t2;

    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;

    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));


    double z  =offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-radiusSquared) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
    if (std::isnan(z))
    {z = 0;}

    return D3vector ( x,y,z);
}

D3vector transform_diag_inner_faces_NE_quad( double t1, double t2, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    bool invertT1T2 = true;
    if (invertT1T2)
    {

        double temp = t1;
        t1 = t2;
        t2 = temp;
    }
    double t = t2;



    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;
    double signLeft = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;

    double radiusSquared = r_global_data + (R_global_data-r_global_data)* (t2);



    radiusSquared = radiusSquared * radiusSquared;



    double zRight = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                          ( radiusSquared))
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));
    double zLeft =   offsetZ_global_data
                    +signLeft*(-1*( sqrt(pow(curvatureLeft_global_data,2)-
                            radiusSquared)
                        +signLeft *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));



   double z = zRight * (t1) + zLeft * (1-t1) ;
    if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
    {
500
501
502
503
//        if (  fabs(z) > 1e-8)
//        {
//            cout << "stop  "<<endl;
//        }
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
    }
        return D3vector (   0 ,0 ,z);

}

D3vector transform_diag_inner_faces_NE_quad_cut( double t1, double t2, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];

    double z_right_edge_global_data    = pointer_global_data[10];
    double z_left_edge_global_data     = pointer_global_data[11];
    double R_outer_global_data        = pointer_global_data[12];




    bool invertT1T2 = true;
    if (invertT1T2)
    {

        double temp = t1;
        t1 = t2;
        t2 = temp;
    }
    double t = t2;



    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;
    double signLeft = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;

    double radiusSquared = R_global_data + (R_outer_global_data-R_global_data)* (t2);
    radiusSquared = radiusSquared * radiusSquared;

    double zRight = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                          ( radiusSquared))
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_outer_global_data) + t * (thickness_global_data-z_right_edge_global_data)))));

    if (z_right_outer_global_data == z_right_edge_global_data)
    {
        zRight = 0;
    }
    double zLeft =   offsetZ_global_data
                    +signLeft*(-1*( sqrt(pow(curvatureLeft_global_data,2)-
                            radiusSquared)
                        +signLeft *(-curvatureLeft_global_data +( (1-t)*z_left_outer_global_data + t * z_left_edge_global_data))));

    if (z_left_outer_global_data == z_left_edge_global_data)
    {
        zLeft = 0;
    }

   double z = zRight * (t1) + zLeft * (1-t1) ;
    if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
    {
568
569
570
571
//        if (  fabs(z) > 1e-8)
//        {
//            cout << "stop  "<<endl;
//        }
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
    }
        return D3vector (   0 ,0 ,z);

}


D3vector transform_inner_faces_NE_quad( double t1, double t2, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    bool invertT1T2 = false;
    if (invertT1T2)
    {

        double temp = t1;
        t1 = t2;
        t2 = temp;
    }

    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;
    double signLeft = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;

    double x = r_global_data* (t1-1);
    double y = r_global_data* (t1);
    double radiusSquared = x*x+y*y;

    double zRight = offsetZ_global_data
                +sign*(( sqrt(pow(curvatureRight_global_data,2)- radiusSquared) //pow(r_global_data,2) * (t*t + (1-t)*(1-t)))
                         +sign*(- curvatureRight_global_data + (thickness_global_data-z_right_inner_global_data)) ));
    double zLeft = offsetZ_global_data
                +signLeft*(-1*( sqrt(pow(curvatureLeft_global_data,2)- radiusSquared)
                            - signLeft* (curvatureLeft_global_data - z_left_inner_global_data)) );

    //works for one side only:
    double z = zRight * (t2) + zLeft * (1-t2);

    if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
    {
617
618
619
620
//        if (  fabs(z) > 1e-8)
//        {
//            cout << "stop  "<<endl;
//        }
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
    }
        return D3vector (   0 ,0 ,z);

}

D3vector transform_right_lens_diag_NE_quad ( double t1, double t2, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;

    double x = R_global_data * ( sin ( t1*0.5*M_PI )-t1);

    x = x*t2;
    double y = R_global_data *  (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    y = y*t2;

    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;

    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));



    double z = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                           radiusSquared)
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));

    if (std::isnan(x) || std::isnan(y) || std::isnan(z))
    {   z = 0;}
    return D3vector ( x,y,z);

}


D3vector transform_right_lens_diag_NW_quad_cut ( double t1, double t2, double* pointer_global_data) {

    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];

    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];

    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;

    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];


    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
   // t2 = (1-t2);
    double x = -R_global_data*( sin ( t1*0.5*M_PI )-t1);
    x = x*t2;
    double y = R_global_data*(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    y = y*t2;


    //added due to bended inner part :
    double xAdd = -r_global_data * ( sin ( t1*0.5*M_PI )-t1);
    double yAdd = r_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    x += (1-t2) * xAdd;
    y += (1-t2) * yAdd;

    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;

    actualX = -actualX;
    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;

    double z = offsetZ_global_data+
                sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                               radiusSquared)
                          + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));

    if (z_right_inner_global_data == z_right_outer_global_data)
    {
        z = 0;
    }
725

726
    if (std::isnan(z))
727
    {
728
        z = 0;
729
    }
730
731
732


    return D3vector ( x,y,z);
733
734
735

}

736
D3vector transform_left_lens_diag_NW_quad_cut ( double t1, double t2, double* pointer_global_data) {
737
738
739
740
741
742
743
744
745
746
    double R_global_data = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
747
748
749
750
751
752
753
754
755
756
757
758


    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];

    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;

    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];

759
760
761
762
763
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
   // t2 = (1-t2);
764
    double x = -R_global_data*( sin ( t1*0.5*M_PI )-t1);
765
    x = x*t2;
766
    double y = R_global_data*(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
767
    y = y*t2;
768
769
770
771
772
773
774

    //added due to bended inner part :
    double xAdd =-r_global_data * ( sin ( t1*0.5*M_PI )-t1);
    double yAdd = r_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    x += (1-t2) * xAdd;
    y += (1-t2) * yAdd;

775
776
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
777

778
779
    actualX = -actualX;
    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));
780
781

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
782

783
    double z =offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-radiusSquared) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
784
785
786
787
788
789
790

    if (z_left_inner_global_data == z_left_outer_global_data)
    {
        z = 0;
    }

    if (std::isnan(z))
791
     {z = 0;}
792

793
     return D3vector ( x,y,z);
794
795
}

796
D3vector transform_right_lens_diag_SW_quad_cut ( double t1, double t2, double* pointer_global_data) {
797
798
799
800
801
802
803
804
805
806
    double R_global_data = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
807
808
809
810
811
812
813
814
815
816
817

    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];

    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;

    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];

818
819
820
821
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
822
    double x = -R_global_data *( sin ( t1*0.5*M_PI )-t1);
823
    x = x*t2;
824
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
825
    y = y*t2;
826
827
828
829
830
831
832

    //added due to bended inner part :
    double xAdd =-r_global_data * ( sin ( t1*0.5*M_PI )-t1);
    double yAdd =-r_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    x += (1-t2) * xAdd;
    y += (1-t2) * yAdd;

833
834
835
836
837
838
839
840
841
842
843
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    actualY = -actualY;
    actualX = -actualX;
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;

    double z = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                           ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY)))
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));

844
845
846
847
    if (z_right_inner_global_data == z_right_outer_global_data)
    {
        z = 0;
    }
848
849
850
    if (std::isnan(z))
    {        z = 0;    }
    return D3vector ( x,y,z);
851
852
853

}

854
D3vector transform_left_lens_diag_SW_quad_cut ( double t1, double t2, double* pointer_global_data) {
855
856
857
858
859
860
861
862
863
864
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
865
866
867
868
869
870
871
872
873
874
875

    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];

    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;

    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];

876
877
878
    double temp = t1;
    t1 = t2;
    t2 = temp;
879
880
    double t = t2;
    double x = -R_global_data *( sin ( t1*0.5*M_PI )-t1);
881
    x = x*t2;
882
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
883
    y = y*t2;
884
885
886
887
888
889
890

    //added due to bended inner part :
    double xAdd =-r_global_data * ( sin ( t1*0.5*M_PI )-t1);
    double yAdd =-r_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    x += (1-t2) * xAdd;
    y += (1-t2) * yAdd;

891
892
893
894
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    actualY = -actualY;
    actualX = -actualX;
895
896

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
897
898
899
900

    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));

    double z =offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-radiusSquared) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
901
902
903
904
905
906
907

    if (z_left_inner_global_data == z_left_outer_global_data)
    {
        z = 0;
    }

    if (std::isnan(z))
908
909
910
     {z = 0;}

     return D3vector ( x,y,z);
911
912
}

913
D3vector transform_left_lens_diag_SE_quad_cut ( double t1, double t2, double* pointer_global_data) {
914
915
916
917
918
919
920
921
922
923
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
924
925
926
927
928
929
930
931
932
933
934

    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];

    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;

    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];

935
936
937
    double temp = t1;
    t1 = t2;
    t2 = temp;
938
939
    double t = t2;
    double x =R_global_data * ( sin ( t1*0.5*M_PI )-t1);
940
    x = x*t2;
941
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
942
    y = y*t2;
943
944
945
946
947
    //added due to bended inner part :
    double xAdd = r_global_data * ( sin ( t1*0.5*M_PI )-t1);
    double yAdd =-r_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    x += (1-t2) * xAdd;
    y += (1-t2) * yAdd;
948
949
950
951

    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    actualY = -actualY;
952
953

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
954
    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));
955
956
    //std::cout << "radius outer " << sqrt(radiusSquared ) << std::endl;

957
    double z =offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-radiusSquared) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
958
959
960
961
962
963
964

    if (z_left_inner_global_data == z_left_outer_global_data)
    {
        z = 0;
    }

    if (std::isnan(z))
965
966
     {z = 0;}

967

968
     return D3vector ( x,y,z);
969
970
}

971
D3vector transform_right_lens_diag_SE_quad_cut ( double t1, double t2, double* pointer_global_data) {
972
    double R_global_data              = pointer_global_data[0];
973
974
975
976
977
978
979
980
981
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
982
983
984
985
986
987
988
989
990
991
992

    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];

    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;

    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];

993
994
995
996
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
997
    double x =R_global_data * ( sin ( t1*0.5*M_PI )-t1);
998
    x = x*t2;
999
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
1000
1001
    y = y*t2;

1002
1003
1004
1005
1006
1007
    //added due to bended inner part :
    double xAdd = r_global_data * ( sin ( t1*0.5*M_PI )-t1);
    double yAdd =-r_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    x += (1-t2) * xAdd;
    y += (1-t2) * yAdd;

1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    actualY = -actualY;
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;

    double z = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
                           ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY)))
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));

1018
1019
1020
1021
    if (z_right_inner_global_data == z_right_outer_global_data)
    {
        z = 0;
    }
1022

1023
    if (std::isnan(z))
1024
    {
1025
1026
    z = 0;}
    return D3vector ( x,y,z);
1027
1028
1029

}

1030
D3vector transform_left_lens_diag_NE_quad_cut ( double t1, double t2, double* pointer_global_data) {
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051

    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];

    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;

    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];

1052
    double temp = t1;
1053

1054
1055
    t1 = t2;
    t2 = temp;
1056
1057
1058
1059
    double t = t2;

    double x = R_global_data * ( sin ( t1*0.5*M_PI )-t1);

1060
    x = x*t2;
1061
    double y = R_global_data *  (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
1062
    y = y*t2;
1063

1064
1065
1066
1067
1068
1069
    //added due to bended inner part :
    double xAdd = r_global_data * ( sin ( t1*0.5*M_PI )-t1);
    double yAdd = r_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    x += (1-t2) * xAdd;
    y += (1-t2) * yAdd;

1070
1071
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
1072
1073

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
1074
1075
1076
1077

    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));


1078
    double z  =offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-radiusSquared) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
1079

1080
    if (z_left_inner_global_data == z_left_outer_global_data)
1081
    {
1082
        z = 0;
1083
    }
1084

1085
1086
    if (std::isnan(z))
    {z = 0;}
1087

1088
    return D3vector ( x,y,z);
1089
}
1090

1091
D3vector transform_right_lens_diag_NE_quad_cut ( double t1, double t2, double* pointer_global_data) {
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data      = pointer_global_data[4];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];

1103
1104
1105
    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];
1106

1107
1108
    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;
1109

1110
1111
    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];
1112

1113
1114
1115
1116
1117
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;

1118
    double x = R_global_data * ( sin ( t1*0.5*M_PI )-t1);
1119
1120

    x = x*t2;
1121
    double y = R_global_data *  (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
1122
1123
    y = y*t2;

1124
1125
1126
1127
1128
1129
    //added due to bended inner part :
    double xAdd = r_global_data * ( sin ( t1*0.5*M_PI )-t1);
    double yAdd = r_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
    x += (1-t2) * xAdd;
    y += (1-t2) * yAdd;

1130
1131
1132
1133
    double actualX = 0             +  r_global_data * t1 + 0                             * t2 + (R_global_data-r_global_data) * t1 * t2;
    double actualY = r_global_data -  r_global_data * t1 + (R_global_data-r_global_data) * t2 - (R_global_data-r_global_data) * t1 * t2;
    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;

1134
    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));
1135
1136
1137
1138


    double z = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
1139
                           radiusSquared)
1140
1141
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));

1142
1143
1144
1145
1146
    if (z_right_inner_global_data == z_right_outer_global_data)
    {
        z = 0;
    }

1147
1148
1149
    if (std::isnan(x) || std::isnan(y) || std::isnan(z))
    {   z = 0;}
    return D3vector ( x,y,z);
1150
1151
1152
1153
1154

}



1155
1156


1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
D3vector transform_left_lens_diag ( double t, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureLeft_global_data  = pointer_global_data[2];
    double offsetZ_global_data        = pointer_global_data[5];
    double z_left_inner_global_data   = pointer_global_data[6];
    double z_left_outer_global_data   = pointer_global_data[7];

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;

1167
1168
    double z = offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-pow(r_global_data * (1-t) + R_global_data * t,2)) +sign *(-curvatureLeft_global_data +( (1-t)*z_left_inner_global_data + t * z_left_outer_global_data))));
    return D3vector ( 0.0 ,0.0 , z );
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
}

D3vector transform_left_lens_rectangle ( double t, double* pointer_global_data) {
  double r_global_data              = pointer_global_data[1];
  double curvatureLeft_global_data  = pointer_global_data[2];
  double offsetZ_global_data        =  pointer_global_data[5];
  double z_left_inner_global_data   = pointer_global_data[6];

  //std::cout << "t : " << t << " : " << offsetZ_global_data-1*( sqrt(pow(curvatureLeft_global_data,2)-pow(r_global_data,2) * (t*t + (1-t)*(1-t))) - curvatureLeft_global_data + z_left_inner_global_data)  <<std::endl;
  double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
    //std::cout << "transform_left_lens_rectangle : t = " << t << " : " <<offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-pow(r_global_data,2) * (t*t + (1-t)*(1-t))) - sign* (curvatureLeft_global_data - z_left_inner_global_data)) ) <<std::endl;
1180
1181
  double z = offsetZ_global_data+sign*(-1*( sqrt(pow(curvatureLeft_global_data,2)-pow(r_global_data,2) * (t*t + (1-t)*(1-t))) - sign* (curvatureLeft_global_data - z_left_inner_global_data)) );
  return D3vector ( 0.0 ,0.0 ,z);
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
                              //offsetZ_global_data-1*( sqrt(pow(curvatureLeft_global_data,2)-pow(r_global_data,2) * (t*t + (1-t)*(1-t))) - curvatureLeft_global_data + z_left_inner_global_data) )
}

D3vector transform_right_lens_diag ( double t, double* pointer_global_data) {
    double R_global_data              = pointer_global_data[0];
    double r_global_data              = pointer_global_data[1];
    double curvatureRight_global_data = pointer_global_data[3];
    double thickness_global_data          = pointer_global_data[4];
    double offsetZ_global_data        =  pointer_global_data[5];
    double z_right_inner_global_data  = pointer_global_data[8];
    double z_right_outer_global_data  = pointer_global_data[9];

    double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;
    //std::cout << "transform_right_lens_diag : t = " << t << " : " <<offsetZ_global_data+ sign*( ( sqrt(pow(curvatureRight_global_data,2)-pow(r_global_data * (1-t) + R_global_data * t,2)) + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data))))) <<std::endl;

1197
1198
1199
    double z = offsetZ_global_data+ sign*(  ( sqrt(pow(curvatureRight_global_data,2)-pow(r_global_data * (1-t) + R_global_data * t,2)) + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));

    return D3vector ( 0.0 ,0.0 , z);
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
}

D3vector transform_right_lens_rectangle ( double t, double* pointer_global_data) {
  double r_global_data              = pointer_global_data[1];
  double curvatureRight_global_data = pointer_global_data[3];
  double thickness_global_data      = pointer_global_data[4];
  double offsetZ_global_data        =  pointer_global_data[5];
  double z_right_inner_global_data  = pointer_global_data[8];

  double sign = (curvatureRight_global_data > 0) ? 1 : ((curvatureRight_global_data < 0) ? -1 : 0)  ;
  //std::cout << "transform_right_lens_rectangle : t = " << t << " : " <<offsetZ_global_data+sign*(( sqrt(pow(curvatureRight_global_data,2)-pow(r_global_data,2) * (t*t + (1-t)*(1-t))) +sign*(- curvatureRight_global_data + (thickness_global_data-z_right_inner_global_data)) )) <<std::endl;

  return D3vector ( 0.0 ,0.0 ,offsetZ_global_data+sign*(( sqrt(pow(curvatureRight_global_data,2)-pow(r_global_data,2) * (t*t + (1-t)*(1-t))) +sign*(- curvatureRight_global_data + (thickness_global_data-z_right_inner_global_data)) )));
}


D3vector transform_lens_NE ( double t, double* pointer_global_data) {
  double R_global_data = pointer_global_data[0];
  return R_global_data*D3vector ( (cos ( t*0.5*M_PI )- ( 1-t )) ,( sin ( t*0.5*M_PI )-t) , 0.0 );
}

D3vector transform_lens_NW ( double t, double* pointer_global_data ) {
  double R_global_data = pointer_global_data[0];
  return R_global_data*D3vector (( -sin ( t*0.5*M_PI ) +t),( cos ( t*0.5*M_PI )- ( 1-t )), 0.0 );
}

D3vector transform_lens_SW ( double t, double* pointer_global_data ) {
  double R_global_data = pointer_global_data[0];
  return R_global_data*D3vector ( -cos ( t*0.5*M_PI ) + ( 1-t ), -sin ( t*0.5*M_PI ) +t, 0.0 );
}

D3vector transform_lens_SE ( double t, double* pointer_global_data ) {
  double R_global_data = pointer_global_data[0];
  return R_global_data*D3vector (( cos ( t*0.5*M_PI )- ( 1-t )),( -sin ( t*0.5*M_PI ) +t), 0.0 );
}

D3vector transform_lens_NE_inner ( double t, double* pointer_global_data) {
  double R_global_data = pointer_global_data[1];
  return R_global_data*D3vector ( cos ( t*0.5*M_PI )- ( 1-t ), sin ( t*0.5*M_PI )-t, 0.0 );
}

D3vector transform_lens_NW_inner ( double t, double* pointer_global_data ) {
  double R_global_data = pointer_global_data[1];
  return R_global_data*D3vector ( -sin ( t*0.5*M_PI ) +t, cos ( t*0.5*M_PI )- ( 1-t ), 0.0 );
}

D3vector transform_lens_SW_inner ( double t, double* pointer_global_data ) {
  double R_global_data = pointer_global_data[1];
  return R_global_data*D3vector ( -cos ( t*0.5*M_PI ) + ( 1-t ), -sin ( t*0.5*M_PI ) +t, 0.0 );
}

D3vector transform_lens_SE_inner ( double t, double* pointer_global_data ) {
  double R_global_data = pointer_global_data[1];
  return R_global_data*D3vector ( cos ( t*0.5*M_PI )- ( 1-t ), -sin ( t*0.5*M_PI ) +t, 0.0 );
}

// Fuer DEformation der 4 inneren Kanten t=0,...,1
D3vector transform_lens_NE_square ( double t, double* pointer_global_data) {
  double r = pointer_global_data[1];
  double rho = pointer_global_data[2];
  //return D3vector(0.0,0.0,0.0); //Keine Aenderung
  return D3vector (rho*(cos(M_PI/6.0*(1.0+t))-0.5)-r*(1.0-t), rho*(sin(M_PI/6.0*(1.0+t))-0.5)-r*t,0.0);
}

D3vector transform_lens_NW_square ( double t, double* pointer_global_data ) {
  double r = pointer_global_data[1];
  double rho = pointer_global_data[2];
  //return D3vector(0.0,0.0,0.0); //Keine Aenderung
  return D3vector (rho*(-sin(M_PI/6.0*(1.0+t))+0.5)+r*t, rho*(cos(M_PI/6.0*(1.0+t))-0.5)-r*(1.0-t),0.0);
}

D3vector transform_lens_SW_square ( double t, double* pointer_global_data ) {
  double r = pointer_global_data[1];
  double rho = pointer_global_data[2];
  //return D3vector(0.0,0.0,0.0); //Keine Aenderung
  return D3vector (-rho*(cos(M_PI/6.0*(1.0+t))-0.5)+r*(1.0-t), rho*(-sin(M_PI/6.0*(1.0+t))+0.5)+r*t,0.0);
}

D3vector transform_lens_SE_square ( double t, double* pointer_global_data ) {
  double r = pointer_global_data[1];
  double rho = pointer_global_data[2];
  //return D3vector(0.0,0.0,0.0); //Keine Aenderung
  return D3vector (rho*(cos(M_PI/6.0*(1.0+t))-0.5)-r*(1.0-t), rho*(-sin(M_PI/6.0*(1.0+t))+0.5)+r*t,0.0);
}


1286
Lens_Geometry::Lens_Geometry (double Radius, double thickness, double curvatureLeft, double curvatureRight, double offsetX, double offsetY, double offsetZ, bool inner_grid_arched, double radius)
1287
{
1288
1289
1290
1291
1292
    if (radius == 0)
    {
        radius = Radius / 2.0;
    }
    assert(Radius > radius);
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
    size_pointer_global_data = 10;
    if (fabs(curvatureLeft) >1e10)
    {
        curvatureLeft = 1e10;
    }
    if (fabs(curvatureRight) >1e10)
    {
        curvatureRight = 1e10;
    }

    double inversFocal = (1.5 - 1.0) * ( (1.0 / curvatureLeft) - ( 1.0 / -curvatureRight ) + ( 1.5 - 1.0) * thickness / ( 1.5 * -curvatureRight * curvatureLeft ));

1305
   // cout << "Focal length of Lens is " << 1.0 / inversFocal << " (assume n = 1.5 ) ." << endl;
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
    pointer_global_data = new double[size_pointer_global_data];
    pointer_global_data[0] = Radius;
    pointer_global_data[1] = radius;
    pointer_global_data[2] = curvatureLeft;
    pointer_global_data[3] = curvatureRight;
    pointer_global_data[4] = thickness;
    pointer_global_data[5] = offsetZ;

    assert ((thickness > 0.0) &&  "Thickness must be positive.");
    assert ((Radius > 0.0) &&  "Radius must be positive.");
    assert ((radius > 0.0) &&  "radius must be positive.");



    constructionParameters.resize(8);
    constructionParameters[0] = Radius;
    constructionParameters[1] = radius;
    constructionParameters[2] = thickness;
    constructionParameters[3] = curvatureLeft;
    constructionParameters[4] = curvatureRight;
    constructionParameters[5] = offsetX;
    constructionParameters[6] = offsetY;
    constructionParameters[7] = offsetZ;
    constructionBoolArched = inner_grid_arched;
    // maybe adjust, if lens is negative (most thick part not in the centre but at the edges!)
    relativeCoordVector.push_back(0.0);
    relativeCoordVector.push_back(thickness);
    typFuerSlice = lensUgTyp;


    int num_blocks_z_dir = 1;
    assert(num_blocks_z_dir>0);
    int num_blocks_total = 5 * num_blocks_z_dir;
    int num_points_per_face = 8;
    int numPoints = num_points_per_face*(num_blocks_z_dir+1) ;

    double z_left_inner  = -sqrt( pow(curvatureLeft ,2) - radius * radius ) + curvatureLeft  + offsetZ;
    double z_left_outer  = -sqrt( pow(curvatureLeft ,2) - Radius * Radius ) + curvatureLeft  + offsetZ;
    double z_right_inner = +sqrt( pow(curvatureRight,2) - radius * radius ) - curvatureRight + offsetZ + thickness;
    double z_right_outer = +sqrt( pow(curvatureRight,2) - Radius * Radius ) - curvatureRight + offsetZ + thickness;

    if (curvatureLeft< 0.0)
    {
        z_left_inner  = +sqrt( pow(curvatureLeft ,2) - radius * radius ) + curvatureLeft  + offsetZ;
        z_left_outer  = +sqrt( pow(curvatureLeft ,2) - Radius * Radius ) + curvatureLeft  + offsetZ;
    }
    if (curvatureRight< 0.0)
    {
        z_right_inner = -sqrt( pow(curvatureRight,2) - radius * radius ) - curvatureRight + offsetZ + thickness;
        z_right_outer = -sqrt( pow(curvatureRight,2) - Radius * Radius ) - curvatureRight + offsetZ + thickness;
    }

    if (curvatureLeft == 0.0)
    {
        z_left_inner  = 0.0  + offsetZ;
        z_left_outer  = 0.0  + offsetZ;
    }
    if (curvatureRight == 0.0)
    {
        z_right_inner = 0.0 + offsetZ + thickness;
        z_right_outer = 0.0 + offsetZ + thickness;
    }


1370
1371


1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
//    cout << z_right_outer - z_left_outer << endl;
//    cout << thickness << endl;
//    double diff = z_right_outer - z_left_outer - thickness ;
//    cout <<fabs(z_right_outer - z_left_outer) - thickness << endl;
//    cout << ((fabs(z_right_outer - z_left_outer) - thickness) < 0.0) << endl;
//    double epsilon = 1e-5;
//    double diff2 = fabs(z_right_outer - z_left_outer) - thickness-epsilon;
    if (curvatureRight < 0 && curvatureLeft < 0)
    {
        assert (((fabs(z_right_outer - z_left_outer) - thickness) < 0.0) &&  "Lens has negative thickness at edge! Make lens more thick or increase radius of curvature.");

    }
    if (curvatureRight > 0 && curvatureLeft > 0)
    {
        assert ((((z_right_outer - z_left_outer) ) > 0.0) &&  "Lens has negative thickness at edge! Make lens more thick or increase radius of curvature.");

    }


    pointer_global_data[6] = z_left_inner;
    pointer_global_data[7] = z_left_outer;
    pointer_global_data[8] = z_right_inner;
    pointer_global_data[9] = z_right_outer;


    Set_number_points ( numPoints );
    Set_number_hexahedra ( num_blocks_total );


    Set_coordinate_point( 0, D3vector ( offsetX+radius,offsetY,z_left_inner ));
    Set_coordinate_point( 1, D3vector ( offsetX+Radius,offsetY,z_left_outer ));

    Set_coordinate_point( 2, D3vector ( offsetX,offsetY+radius,z_left_inner ));
    Set_coordinate_point( 3, D3vector ( offsetX,offsetY+Radius,z_left_outer ));

    Set_coordinate_point( 4, D3vector ( offsetX-radius,offsetY,z_left_inner ));
    Set_coordinate_point( 5, D3vector ( offsetX-Radius,offsetY,z_left_outer ));

    Set_coordinate_point( 6, D3vector ( offsetX,offsetY-radius,z_left_inner ));
    Set_coordinate_point( 7, D3vector ( offsetX,offsetY-Radius,z_left_outer ));

    Set_coordinate_point( 8, D3vector ( offsetX+radius,offsetY,z_right_inner ));
    Set_coordinate_point( 9, D3vector ( offsetX+Radius,offsetY,z_right_outer ));

    Set_coordinate_point( 10, D3vector ( offsetX,offsetY+radius,z_right_inner ));
    Set_coordinate_point( 11, D3vector ( offsetX,offsetY+Radius,z_right_outer ));

    Set_coordinate_point( 12, D3vector ( offsetX-radius,offsetY,z_right_inner ));
    Set_coordinate_point( 13, D3vector ( offsetX-Radius,offsetY,z_right_outer ));

    Set_coordinate_point( 14, D3vector ( offsetX,offsetY-radius,z_right_inner ));
    Set_coordinate_point( 15, D3vector ( offsetX,offsetY-Radius,z_right_outer ));

    int num_blocks = 1;
    for ( int i = 0; i < num_blocks; ++i ) {
      Set_hexahedron ( i, i*num_points_per_face + 0, i*num_points_per_face + 2,
                          i*num_points_per_face + 6, i*num_points_per_face + 4,
                          ( i+1 ) * num_points_per_face + 0, ( i+1 ) * num_points_per_face +2,
                          ( i+1 ) * num_points_per_face + 6, ( i+1 ) * num_points_per_face +4 );
    }
    for ( int j = 0; j < num_points_per_face; j=j+2) {
      for ( int i = 0; i < num_blocks; ++i) {
        int myIndex = (j/2+1)*num_blocks +i;
        Set_hexahedron ( myIndex,
                         i*num_points_per_face     +  j+0,
                         i*num_points_per_face     +  j+1,
                         i*num_points_per_face     +((j+2) % num_points_per_face),
                         i*num_points_per_face     +((j+3) % num_points_per_face),
                         (i+1)*num_points_per_face +  j+0,
                         (i+1)*num_points_per_face +  j+1,
                         (i+1)*num_points_per_face +((j+2) % num_points_per_face),
                         (i+1)*num_points_per_face +((j+3) % num_points_per_face)
                       );
     }
    }
  construction_hexahedron_points_done();
  int shift;
  for ( int i = 0; i <= num_blocks_z_dir; ++i ) {
    shift = i * num_points_per_face;
    Set_transformation_edge ( 1+shift, 3+shift, transform_lens_NE );
    Set_transformation_edge ( 3+shift, 5+shift, transform_lens_NW );
    Set_transformation_edge ( 5+shift, 7+shift, transform_lens_SW );
    Set_transformation_edge ( 1+shift, 7+shift, transform_lens_SE );

    if (inner_grid_arched == true) {
      Set_transformation_edge ( 0+shift, 2+shift, transform_lens_NE_square );
      Set_transformation_edge ( 2+shift, 4+shift, transform_lens_NW_square );
      Set_transformation_edge ( 4+shift, 6+shift, transform_lens_SW_square );
      Set_transformation_edge ( 0+shift, 6+shift, transform_lens_SE_square );
    }
  }


  Set_transformation_edge(0,2,transform_left_lens_rectangle);
  Set_transformation_edge(2,4,transform_left_lens_rectangle);
  Set_transformation_edge(4,6,transform_left_lens_rectangle);
  Set_transformation_edge(0,6,transform_left_lens_rectangle);

  Set_transformation_edge(0,1,transform_left_lens_diag);
  Set_transformation_edge(2,3,transform_left_lens_diag);
  Set_transformation_edge(4,5,transform_left_lens_diag);
  Set_transformation_edge(6,7,transform_left_lens_diag);
  Set_transformation_edge(0+num_points_per_face,2+num_points_per_face,transform_right_lens_rectangle);
  Set_transformation_edge(2+num_points_per_face,4+num_points_per_face,transform_right_lens_rectangle);
  Set_transformation_edge(4+num_points_per_face,6+num_points_per_face,transform_right_lens_rectangle);
  Set_transformation_edge(0+num_points_per_face,6+num_points_per_face,transform_right_lens_rectangle);
  Set_transformation_edge(0+num_points_per_face,1+num_points_per_face,transform_right_lens_diag);
  Set_transformation_edge(2+num_points_per_face,3+num_points_per_face,transform_right_lens_diag);
  Set_transformation_edge(4+num_points_per_face,5+num_points_per_face,transform_right_lens_diag);
  Set_transformation_edge(6+num_points_per_face,7+num_points_per_face,transform_right_lens_diag);

  construction_done();
}

1486
Lens_Geometry_Quad::Lens_Geometry_Quad(double Radius, double thickness, double curvatureLeft, double curvatureRight, double offsetX, double offsetY, double offsetZ, bool inner_grid_arched, double radius, double cut_edge_from_left, double cut_edge_from_right)
1487
{
1488
1489
1490



1491
1492
1493
1494
    if (radius == 0)
    {
        radius = Radius / 2.0;
    }
1495
    assert(Radius > radius);
1496
    size_pointer_global_data = 12;
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
    if (fabs(curvatureLeft) >1e10)
    {
        curvatureLeft = 1e10;
    }
    if (fabs(curvatureRight) >1e10)
    {
        curvatureRight = 1e10;
    }

    double inversFocal = (1.5 - 1.0) * ( (1.0 / curvatureLeft) - ( 1.0 / -curvatureRight ) + ( 1.5 - 1.0) * thickness / ( 1.5 * -curvatureRight * curvatureLeft ));

1508
    focalLength_ = 1.0 / inversFocal;
Phillip Lino Rall's avatar