examples_ug_optics.cc 91.2 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
    }
        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) {
453
    return D3vector{0,0,0};
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
500
    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))
    {
501
502
503
504
//        if (  fabs(z) > 1e-8)
//        {
//            cout << "stop  "<<endl;
//        }
505
506
507
508
509
510
    }
        return D3vector (   0 ,0 ,z);

}

D3vector transform_diag_inner_faces_NE_quad_cut( double t1, double t2, double* pointer_global_data) {
511
    return D3vector{0,0,0};
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
    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;
    }

567

568
569
570
   double z = zRight * (t1) + zLeft * (1-t1) ;
    if (( t1 == 0 && t2 == 0)||( t1 == 1 && t2 == 0)||( t1 == 0 && t2 == 1)||( t1 == 1 && t2 == 1))
    {
571
572
573
574
//        if (  fabs(z) > 1e-8)
//        {
//            cout << "stop  "<<endl;
//        }
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
617
618
619
    }
        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))
    {
620
621
622
623
//        if (  fabs(z) > 1e-8)
//        {
//            cout << "stop  "<<endl;
//        }
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
    }
        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)))));

664
    //std::cout << "z inner " << z << std::endl;
665
666
    if (std::isnan(x) || std::isnan(y) || std::isnan(z))
    {   z = 0;}
667
668
669
//    std::cout << "transform_right_lens_diag_NE_quad ";
//    D3vector ( x,y,z).Print();
//    std::cout << std::endl;
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
725
726
727
728
729
730
731
    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;
    }
732

733
    if (std::isnan(z))
734
    {
735
        z = 0;
736
    }
737
738
739


    return D3vector ( x,y,z);
740
741
742

}

743
D3vector transform_left_lens_diag_NW_quad_cut ( double t1, double t2, double* pointer_global_data) {
744
745
746
747
748
749
750
751
752
753
    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];
754
755
756
757
758
759
760
761
762
763
764
765


    //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];

766
767
768
769
770
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
   // t2 = (1-t2);
771
    double x = -R_global_data*( sin ( t1*0.5*M_PI )-t1);
772
    x = x*t2;
773
    double y = R_global_data*(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
774
    y = y*t2;
775
776
777
778
779
780
781

    //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;

782
783
    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;
784

785
786
    actualX = -actualX;
    double radiusSquared = ((x+actualX)*(x+actualX)+(y+actualY)*(y+actualY));
787
788

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

790
    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))));
791
792
793
794
795
796
797

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

    if (std::isnan(z))
798
     {z = 0;}
799

800
     return D3vector ( x,y,z);
801
802
}

803
D3vector transform_right_lens_diag_SW_quad_cut ( double t1, double t2, double* pointer_global_data) {
804
805
806
807
808
809
810
811
812
813
    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];
814
815
816
817
818
819
820
821
822
823
824

    //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];

825
826
827
828
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
829
    double x = -R_global_data *( sin ( t1*0.5*M_PI )-t1);
830
    x = x*t2;
831
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
832
    y = y*t2;
833
834
835
836
837
838
839

    //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;

840
841
842
843
844
845
846
847
848
849
850
    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)))));

851
852
853
854
    if (z_right_inner_global_data == z_right_outer_global_data)
    {
        z = 0;
    }
855
856
857
    if (std::isnan(z))
    {        z = 0;    }
    return D3vector ( x,y,z);
858
859
860

}

861
D3vector transform_left_lens_diag_SW_quad_cut ( double t1, double t2, double* pointer_global_data) {
862
863
864
865
866
867
868
869
870
871
    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];
872
873
874
875
876
877
878
879
880
881
882

    //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];

883
884
885
    double temp = t1;
    t1 = t2;
    t2 = temp;
886
887
    double t = t2;
    double x = -R_global_data *( sin ( t1*0.5*M_PI )-t1);
888
    x = x*t2;
889
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
890
    y = y*t2;
891
892
893
894
895
896
897

    //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;

898
899
900
901
    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;
902
903

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
904
905
906
907

    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))));
908
909
910
911
912
913
914

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

    if (std::isnan(z))
915
916
917
     {z = 0;}

     return D3vector ( x,y,z);
918
919
}

920
D3vector transform_left_lens_diag_SE_quad_cut ( double t1, double t2, double* pointer_global_data) {
921
922
923
924
925
926
927
928
929
930
    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];
931
932
933
934
935
936
937
938
939
940
941

    //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];

942
943
944
    double temp = t1;
    t1 = t2;
    t2 = temp;
945
946
    double t = t2;
    double x =R_global_data * ( sin ( t1*0.5*M_PI )-t1);
947
    x = x*t2;
948
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
949
    y = y*t2;
950
951
952
953
954
    //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;
955
956
957
958

    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;
959
960

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

964
    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))));
965
966
967
968
969
970
971

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

    if (std::isnan(z))
972
973
     {z = 0;}

974

975
     return D3vector ( x,y,z);
976
977
}

978
D3vector transform_right_lens_diag_SE_quad_cut ( double t1, double t2, double* pointer_global_data) {
979
    double R_global_data              = pointer_global_data[0];
980
981
982
983
984
985
986
987
988
    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];
989
990
991
992
993
994
995
996
997
998
999

    //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];

1000
1001
1002
1003
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;
1004
    double x =R_global_data * ( sin ( t1*0.5*M_PI )-t1);
1005
    x = x*t2;
1006
    double y = -R_global_data *(cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
1007
1008
    y = y*t2;

1009
1010
1011
1012
1013
1014
    //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;

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
    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)))));

1025
1026
1027
1028
    if (z_right_inner_global_data == z_right_outer_global_data)
    {
        z = 0;
    }
1029

1030
    if (std::isnan(z))
1031
    {
1032
1033
    z = 0;}
    return D3vector ( x,y,z);
1034
1035
1036

}

1037
D3vector transform_left_lens_diag_NE_quad_cut ( double t1, double t2, double* pointer_global_data) {
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
    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];
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058

    //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];

1059
    double temp = t1;
1060

1061
1062
    t1 = t2;
    t2 = temp;
1063
1064
1065
1066
    double t = t2;

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

1067
    x = x*t2;
1068
    double y = R_global_data *  (cos ( t1*0.5*M_PI )- ( 1-t1 )) ;
1069
    y = y*t2;
1070
1071
    double xT = x;
    double yT = y;
1072
1073
1074
1075
1076
1077
    //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;

1078

1079
1080
    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;
1081
1082

    double sign = (curvatureLeft_global_data > 0) ? 1 : ((curvatureLeft_global_data < 0) ? -1 : 0)  ;
1083
1084
1085
1086

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


1087
    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))));
1088

1089
    if (z_left_inner_global_data == z_left_outer_global_data)
1090
    {
1091
        //std::cout << "set to zero again!\n";
1092
        z = 0;
1093
    }
1094

1095
1096
    if (std::isnan(z))
    {z = 0;}
1097

1098
    //return D3vector ( xT,yT,z);
1099
    return D3vector ( x,y,z);
1100
}
1101

1102
D3vector transform_right_lens_diag_NE_quad_cut ( double t1, double t2, double* pointer_global_data) {
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
    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];

1114
1115
1116
    //shirts the transformation to the cut domain
    r_global_data                     = R_global_data;
    R_global_data                     = pointer_global_data[12];
1117

1118
1119
    z_left_inner_global_data          = z_left_outer_global_data;
    z_right_inner_global_data         = z_right_outer_global_data;
1120

1121
1122
    z_left_outer_global_data          = pointer_global_data[11];
    z_right_outer_global_data         = pointer_global_data[10];
1123

1124
1125
1126
1127
1128
    double temp = t1;
    t1 = t2;
    t2 = temp;
    double t = t2;

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

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

1135
1136
    double xT = x;
    double yT = y;
1137
1138
1139
1140
1141
1142
    //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;

1143
1144
1145
1146
    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)  ;

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

1149
1150
1151
//    std::cout << "(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data))) " << (-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data))) << "\n";
//    std::cout << "t1,2 :: " << t1 << " " << t2 << "\n";
//std::cout << "radius " << sqrt(radiusSquared) << std::endl;
1152
1153
    double z = offsetZ_global_data+
            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
1154
                           radiusSquared)
1155
                      + sign*(-curvatureRight_global_data +( (1-t)*(thickness_global_data-z_right_inner_global_data) + t * (thickness_global_data-z_right_outer_global_data)))));
1156
1157
1158
1159
1160
  //  z =radiusSquared;
    //z *= 10;
    //z = 1;
    //std::cout << "z outer" << z << std::endl;
   // double ADAD = 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))));
1161

1162
1163
1164
1165
1166
    if (z_right_inner_global_data == z_right_outer_global_data)
    {
        z = 0;
    }

1167
1168
    if (std::isnan(x) || std::isnan(y) || std::isnan(z))
    {   z = 0;}
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178

//    std::cout << "transform_right_lens_diag_NE_quad_cut ";
//    D3vector ( x,y,z).Print();
//    std::cout << std::endl;
//    double actualZ =  offsetZ_global_data+
//            sign*(  ( sqrt(pow(curvatureRight_global_data,2)-
//                           radiusSquared)
//                      + sign*(-curvatureRight_global_data))) ;
//    return D3vector (actualX, actualY,actualZ );
    //return D3vector ( xT,yT,z);
1179
    return D3vector ( x,y,z);
1180
1181
    //return D3vector ( (1-t2) * xAdd,(1-t2) * yAdd,z);
    return D3vector ( 0,0,z);
1182
1183
1184
1185
1186

}



1187
1188


1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
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)  ;

1199
1200
    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 );
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
}

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;
1212
1213
  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);
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
                              //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;

1229
1230
1231
    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);
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
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
}

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);
}


1318
Lens_Geometry::Lens_Geometry (double Radius, double thickness, double curvatureLeft, double curvatureRight, double offsetX, double offsetY, double offsetZ, bool inner_grid_arched, double radius)
1319
{
1320
1321
1322
1323
1324
    if (radius == 0)
    {
        radius = Radius / 2.0;
    }
    assert(Radius > radius);
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
    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 ));

1337
   // cout << "Focal length of Lens is " << 1.0 / inversFocal << " (assume n = 1.5 ) ." << endl;
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
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
    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;
    }


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
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
//    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,off