blockgrid.cc 52.9 KB
Newer Older
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1
/**********************************************************************************
Phillip Lino Rall's avatar
Phillip Lino Rall committed
2
 * Copyright 2010 Christoph Pflaum
Phillip Lino Rall's avatar
Phillip Lino Rall committed
3
4
 * 		Department Informatik Lehrstuhl 10 - Systemsimulation
 *		Friedrich-Alexander Universität Erlangen-Nürnberg
Phillip Lino Rall's avatar
Phillip Lino Rall committed
5
 *
Phillip Lino Rall's avatar
Phillip Lino Rall committed
6
7
8
9
10
11
12
13
14
15
16
17
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **********************************************************************************/
Phillip Lino Rall's avatar
Phillip Lino Rall committed
18

Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
#include <sstream>
#include <stdexcept>

#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"
#include "blockgrid.h"


#define HWSD hex->Give_coord(WSDdir3D)
#define HESD hex->Give_coord(ESDdir3D)
#define HWND hex->Give_coord(WNDdir3D)
#define HEND hex->Give_coord(ENDdir3D)
#define HWST hex->Give_coord(WSTdir3D)
#define HEST hex->Give_coord(ESTdir3D)
#define HWNT hex->Give_coord(WNTdir3D)
#define HENT hex->Give_coord(ENTdir3D)

int Blockgrid::id_count_grid = 0;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
44

45

Phillip Lino Rall's avatar
Phillip Lino Rall committed
46

Phillip Lino Rall's avatar
Phillip Lino Rall committed
47
48
Blockgrid::Blockgrid() {
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
49
50
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
51
52
53
  variable_set = false;
}

54
55


Phillip Lino Rall's avatar
Phillip Lino Rall committed
56
57
58
Blockgrid::Blockgrid ( Unstructured_grid *ug_ ) {
  id_of_grid = id_count_grid; ++id_count_grid;
  phase_shift = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
59
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
60
61
62
63
64
65
66
  ug = ug_;
  number_points = new int[ug->degree_of_freedom() ];
  for ( int i=0;i<ug->degree_of_freedom();++i )
  {
    number_points[i] = 10;
  }
  variable_set = false;
67
 }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
68
69

Blockgrid::Blockgrid ( Unstructured_grid *ug_, int N ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
70
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
71
  phase_shift = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
72
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
73
74
75
76
77
78
79
80
81
82
  ug = ug_;
  number_points = new int[ug->degree_of_freedom() ];
  for ( int i=0;i<ug->degree_of_freedom();++i )
  {
    number_points[i] = N;
  }
  variable_set = false;
}

Blockgrid::Blockgrid ( Unstructured_grid *ug_, int Nx, int Ny, int Nz ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
83
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
84
85
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  ug = ug_;
  if ( ug->degree_of_freedom() <3 )
    cout << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_, int Nx, int Ny, int Nz) "
    << endl;
  number_points = new int[ug->degree_of_freedom() ];

  number_points[0] = Nx;
  number_points[1] = Ny;
  for ( int i = 2; i < ug->degree_of_freedom();++i )
  {
    number_points[i] = Nz;
  }

  variable_set = false;
}


Blockgrid::Blockgrid ( Unstructured_grid *ug_, int Nx, int Ny, int Nz, int Nr ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
104
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
105
106
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  ug = ug_;
  if ( ug->degree_of_freedom() !=4 ) {
    cout << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_,int Nx,int Ny,int Nz,int Nr) "
    << endl;
    cout << " number of degree of freedom is: " << ug->degree_of_freedom() << endl;
  }
  number_points = new int[4];

  number_points[0] = Nx;
  number_points[1] = Ny;
  number_points[2] = Nz;
  number_points[3] = Nr;

  variable_set = false;
}

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Blockgrid::Blockgrid(Unstructured_grid *ug_, int Nx, int Ny, int Nz, int Nr, int Nr2){
   id_of_grid = id_count_grid; ++id_count_grid;
     phase_shift = NULL;
   bg_coord = NULL;
   ug = ug_;
   if ( ug->degree_of_freedom() !=5 ) {
     cout << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_,int Nx,int Ny,int Nz,int Nr) "
     << endl;
     cout << " number of degree of freedom is: " << ug->degree_of_freedom() << endl;
   }
   number_points = new int[5];

   number_points[0] = Nx;
   number_points[1] = Ny;
   number_points[2] = Nz;
   number_points[3] = Nr;
   number_points[4] = Nr2;

   variable_set = false;
 }

Phillip Lino Rall's avatar
Phillip Lino Rall committed
144
Blockgrid::Blockgrid ( Unstructured_grid *ug_, int Nx, int Ny, std::vector<int>& Nz ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
145
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
146
147
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
148
149
150
151
152
153
154
155
156
  ug = ug_;
  if ( ug->degree_of_freedom() !=Nz.size() +2 )
  {
    std::stringstream ss;
    ss << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_,int Nx,int Ny,vector<int>& Nz) " << endl << "Nz.size+2 = "<< Nz.size() +2 << endl << "degree_of_freedom = " << ug->degree_of_freedom()
    << endl;
    throw ( std::runtime_error ( ss.str() ) );
  }
  number_points = new int[Nz.size() +2];
Phillip Lino Rall's avatar
Phillip Lino Rall committed
157

Phillip Lino Rall's avatar
Phillip Lino Rall committed
158
159
160
161
162
163
164
165
166
167
168
169
  number_points[0] = Nx;
  number_points[1] = Ny;

//   std::cout << "Nx = " << Nx << endl;
//   std::cout << "Nx = " << Ny << endl;
  int tmp_num;
  for ( unsigned int i = 0; i < Nz.size();++i )
  {
    tmp_num = Nz.at ( i );
    if ( tmp_num <= 0 )
    {
      std::stringstream ss;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
170
171
      ss << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_,int Nx,int Ny,vector<int>& Nz) "
        << endl << "Nz.at("<< i << ") = "
Phillip Lino Rall's avatar
Phillip Lino Rall committed
172
173
174
175
176
177
178
179
180
181
182
        << tmp_num <<" <= 0" << endl;
      throw ( std::runtime_error ( ss.str() ) );
    }

//     cout << "Nz.at("<< i << ") = " << tmp_num << endl;
    number_points[i+2] = tmp_num;
  }

  variable_set = false;
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
183
184
185
186
187



Blockgrid::Blockgrid ( Unstructured_grid *ug_,std::vector<int> Nvec) {
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
188
189
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  ug = ug_;
  if ( ug->degree_of_freedom() !=Nvec.size() )
  {
    std::stringstream ss;
    ss << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_,std::vector<int> Nvec) " << endl << "Nvec.size() = "<< Nvec.size() << endl << "degree_of_freedom = " << ug->degree_of_freedom()
    << endl;
    throw ( std::runtime_error ( ss.str() ) );
  }
  number_points = new int[Nvec.size()];

  for(unsigned int i = 0; i < Nvec.size();++i)  {
    number_points[i] = Nvec.at(i);
  }

  variable_set = false;
}





Phillip Lino Rall's avatar
Phillip Lino Rall committed
211
212
Blockgrid::Blockgrid ( Unstructured_grid *ug_, int Nx, int Ny, std::vector<int>& Nz, int Nr ) {
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
213

Phillip Lino Rall's avatar
Phillip Lino Rall committed
214
215
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
216
217
218
219
220
221
222
223
224
  ug = ug_;
  if ( ug->degree_of_freedom() !=Nz.size() +3 )
  {
    std::stringstream ss;
    ss << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_,int Nx,int Ny,vector<int>& Nz,, int Nr) " << endl << "Nz.size+3 = "<< Nz.size() +3 << endl << "degree_of_freedom = " << ug->degree_of_freedom()
    << endl;
    throw ( std::runtime_error ( ss.str() ) );
  }
  number_points = new int[Nz.size() +3];
Phillip Lino Rall's avatar
Phillip Lino Rall committed
225

Phillip Lino Rall's avatar
Phillip Lino Rall committed
226
227
228
  number_points[0] = Nx;
  number_points[1] = Ny;
  number_points[Nz.size()+2] = Nr;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
229

Phillip Lino Rall's avatar
Phillip Lino Rall committed
230
231
232
233
234
235
236
237
238
//   std::cout << "Nx = " << Nx << endl;
//   std::cout << "Nx = " << Ny << endl;
  int tmp_num;
  for ( unsigned int i = 0; i < Nz.size();++i )
  {
    tmp_num = Nz.at ( i );
    if ( tmp_num <= 0 )
    {
      std::stringstream ss;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
239
240
      ss << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_,int Nx,int Ny,vector<int>& Nz,int Nr) "
        << endl << "Nz.at("<< i << ") = "
Phillip Lino Rall's avatar
Phillip Lino Rall committed
241
242
243
244
245
246
247
248
249
250
251
252
253
254
        << tmp_num <<" <= 0" << endl;
      throw ( std::runtime_error ( ss.str() ) );
    }
//     cout << "Nz.at("<< i << ") = " << tmp_num << endl;
    number_points[i+2] = tmp_num;
  }

  variable_set = false;
}



Blockgrid::Blockgrid(Unstructured_grid *ug_, std::vector<int>& Nx, std::vector<int>& Ny, std::vector<int>& Nz) {
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
255

Phillip Lino Rall's avatar
Phillip Lino Rall committed
256
257
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
  ug = ug_;

  int size = Nx.size()+Ny.size()+Nz.size();

  if ( ug->degree_of_freedom() != size )
  {
    std::stringstream ss;
    ss << " error in Blockgrid::Blockgrid(Unstructured_grid *ug_,std::vector<int>& Nx,std::vector<int>& Ny,vector<int>& Nz,, int Nr) " << endl << "Nx.size+Ny.size+Nz.size = "<< Nx.size()+Ny.size()+Nz.size() << endl << "degree_of_freedom = " << ug->degree_of_freedom()
    << endl;
    throw ( std::runtime_error ( ss.str() ) );
  }

  number_points = new int[size];
  number_points[0] = Nx[0];
  number_points[1] = Ny[0];
  number_points[2] = Nz[0];
  for(int i = 1; i < Nx.size(); ++i)
  {
    number_points[i+2] = Nx[i];
  }
  for(int i = 1; i < Ny.size(); ++i)
  {
    number_points[Nx.size()+i+1] = Ny[i];
  }
  for(int i = 1; i < Nz.size(); ++i)
  {
    number_points[Nx.size()+Ny.size()+i] = Nz[i];
  }
}

Blockgrid::~Blockgrid()
{
  if ( number_points!=NULL )
    delete [] number_points;
  number_points = NULL;
Christoph Pflaum's avatar
Christoph Pflaum committed
293
  
294
295
  if (bg_coord != NULL)
    delete bg_coord;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
}

int Blockgrid::Give_Nx_hexahedron ( int id ) const
{
  return number_points[ug->Give_edge ( ( ug->Give_hexahedron ( id )->
                                         Give_id_edge ( SDed ) ) )->Give_color_of_edge() ];
}

int Blockgrid::Give_Ny_hexahedron ( int id ) const
{
  return number_points[ug->Give_edge ( ( ug->Give_hexahedron ( id )->
                                         Give_id_edge ( WDed ) ) )->Give_color_of_edge() ];
}

int Blockgrid::Give_Nz_hexahedron ( int id ) const
{
  return number_points[ug->Give_edge ( ( ug->Give_hexahedron ( id )->
                                         Give_id_edge ( SWed ) ) )->Give_color_of_edge() ];
}
int Blockgrid::Give_N_total_hexahedron ( int id ) const
{
  return
    ( Give_Nx_hexahedron ( id ) +1 ) *
    ( Give_Ny_hexahedron ( id ) +1 ) *
    ( Give_Nz_hexahedron ( id ) +1 );
}

int Blockgrid::Give_Nx_quadrangle ( int id ) const
{
  return number_points[ug->Give_edge ( ( ug->Give_quadrangle ( id )->
                                         Give_id_edge ( Sdir2D ) ) )->Give_color_of_edge() ];
}

int Blockgrid::Give_Ny_quadrangle ( int id ) const
{
  return number_points[ug->Give_edge ( ( ug->Give_quadrangle ( id )->
                                         Give_id_edge ( Wdir2D ) ) )->Give_color_of_edge() ];
}

int Blockgrid::Give_N_total_quadrangle ( int id ) const
{
  return ( Give_Nx_quadrangle ( id ) +1 ) * ( Give_Ny_quadrangle ( id ) +1 );
}

int Blockgrid::Give_Nx_edge ( int id ) const
{
  return number_points[ug->Give_edge ( id )->Give_color_of_edge() ];
}

int Blockgrid::Give_N_color ( int color ) const
{
  if ( developer_version )
    if ( color>=ug->degree_of_freedom() || color<0 )
      cout << " error in  Blockgrid::Give_N_color " << endl;

  return number_points[color];
}

inline double change ( bool ori, double q )
{
  if ( ori ) return q;
  return 1.0-q;
}

inline double find_p ( Edges_cell ed, double eta, double xi,double phi )
{
  if ( ed<=NTed ) return eta;
  if ( ed<=ETed ) return xi;
  if ( developer_version )
    if ( ed>NEed ) cout << " error in find_p!" << endl;
  return phi;
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
369
370
371
372
373
374
inline std::vector<int> find_p_quad ( dir3D quad, Hexahedron_el *hex )
{
    // enum Edges_cell { SDed, NDed, STed, NTed,
    //                   WDed, EDed, WTed, ETed,
    //                   SWed, SEed, NWed, NEed };
    std::vector<int> ijk = {1 , 1 , 1};
375
376
377
378
379
//    for (int iter = 0 ; iter < 12; iter++)
//    {
//        std::cout << hex->orientation[iter] << "\n" ;
//    }
//    std::cout << std::endl;
380

Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
    if (quad == Wdir3D)
    {
        hex->orientation[4];
        hex->orientation[6];
        hex->orientation[8];
        hex->orientation[10];
        ijk[0] = 0;
        if (!hex->orientation[4] && !hex->orientation[6])
        {
            ijk[1] = -1;
        }
        if (!hex->orientation[8] && !hex->orientation[10])
        {
            ijk[2] = -1;
        }
    }
    else if (quad == Edir3D)
    {
        hex->orientation[5];
        hex->orientation[7];
        hex->orientation[9];
        hex->orientation[11];
        ijk[0] = 0;
        if (!hex->orientation[5] && !hex->orientation[7])
        {
            ijk[1] = -1;
        }
        if (!hex->orientation[9] && !hex->orientation[11])
        {
            ijk[2] = -1;
        }
    }
    else if (quad == Sdir3D)
    {
        hex->orientation[0];
        hex->orientation[2];
        hex->orientation[8];
        hex->orientation[9];
        ijk[1] = 0;
        if (!hex->orientation[0] && !hex->orientation[2])
        {
            ijk[0] = -1;
        }
        if (!hex->orientation[8] && !hex->orientation[9])
        {
            ijk[2] = -1;
        }
    }
    else if (quad == Ndir3D)
    {
        hex->orientation[1];
        hex->orientation[3];
        hex->orientation[10];
        hex->orientation[11];
        ijk[1] = 0;
        if (!hex->orientation[1] && !hex->orientation[3])
        {
            ijk[0] = -1;
        }
        if (!hex->orientation[10] && !hex->orientation[11])
        {
            ijk[2] = -1;
        }
    }
    else if (quad == Ddir3D)
    {
        hex->orientation[0];
        hex->orientation[1];
        hex->orientation[4];
        hex->orientation[5];
        ijk[2] = 0;
        if (!hex->orientation[0] && !hex->orientation[1])
        {
            ijk[0] = -1;
        }
        if (!hex->orientation[4] && !hex->orientation[5])
        {
            ijk[1] = -1;
        }
    }
    else if (quad == Tdir3D)
    {
        hex->orientation[2];
        hex->orientation[3];
        hex->orientation[6];
        hex->orientation[7];
        ijk[2] = 0;
        if (!hex->orientation[2] && !hex->orientation[3])
        {
            ijk[0] = -1;
        }
        if (!hex->orientation[6] && !hex->orientation[7])
        {
            ijk[1] = -1;
        }
    }
    return ijk;

}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
481
482
483
D3vector Blockgrid::Give_coord_hexahedron ( int id_hex,
    int i, int j, int k ) const
{
Phillip Lino Rall's avatar
Phillip Lino Rall committed
484

Christoph Pflaum's avatar
Christoph Pflaum committed
485
    if(bg_coord != NULL) if(bg_coord->blockgrid_edge_coordinates_calculated)
486
487
488
489
490
        {
            int Nx = Give_Nx_hexahedron ( id_hex ) +1;
            int Ny = Give_Ny_hexahedron ( id_hex ) +1;
            //cout << "id_hex " << id_hex << " i " << i << " j " << j << " k " << k << endl;
            //cout << "index " << i + Nx* (j  + k * (Ny))<< endl;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
491
            return bg_coord->blockgrid_hexa_coordinates.at(id_hex).at(i + Nx* (j  + k * (Ny))  );
492
        }
493

Phillip Lino Rall's avatar
Phillip Lino Rall committed
494

Phillip Lino Rall's avatar
Phillip Lino Rall committed
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
  double eta,xi,phi;
  D3vector Psi[12];
  Hexahedron_el *hex;
  D3vector PL, PR;
  D3vector PSW, PSE, PNW, PNE;
  D3vector Pres, PT, PD;
  double   p_EW, p_NS;
  double   p;

  eta = ( double ) i/ ( double ) Give_Nx_hexahedron ( id_hex );
  xi  = ( double ) j/ ( double ) Give_Ny_hexahedron ( id_hex );
  phi = ( double ) k/ ( double ) Give_Nz_hexahedron ( id_hex );

  hex = ug->Give_hexahedron ( id_hex );

Phillip Lino Rall's avatar
Phillip Lino Rall committed
510
511
512
513
514
515
516
517
518
519



  std::vector<int> p_quad_Wdir3D = find_p_quad(Wdir3D,hex);
  std::vector<int> p_quad_Edir3D = find_p_quad(Edir3D,hex);
  std::vector<int> p_quad_Sdir3D = find_p_quad(Sdir3D,hex);
  std::vector<int> p_quad_Ndir3D = find_p_quad(Ndir3D,hex);
  std::vector<int> p_quad_Ddir3D = find_p_quad(Ddir3D,hex);
  std::vector<int> p_quad_Tdir3D = find_p_quad(Tdir3D,hex);

520

521

522
523


Phillip Lino Rall's avatar
Phillip Lino Rall committed
524
525
526
527
528
529
530
531
532
533
  int idW = hex->Give_id_quadrangle(Wdir3D);
  int idE = hex->Give_id_quadrangle(Edir3D);
  int idS = hex->Give_id_quadrangle(Sdir3D);
  int idN = hex->Give_id_quadrangle(Ndir3D);
  int idD = hex->Give_id_quadrangle(Ddir3D);
  int idT = hex->Give_id_quadrangle(Tdir3D);


  D3vector QS, QN, QE, QW, QT, QD;

534
  D3vector QPsi[6];
Phillip Lino Rall's avatar
Phillip Lino Rall committed
535
536


537
    if(ug->Give_transform_From_Quadrangle())
Phillip Lino Rall's avatar
Phillip Lino Rall committed
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
    {
        //geht bisher nur fuer 1 hexaeder, allgemien so richtig?
        // idW = 0 ; idE = 1 ; idS = 2 ; idN = 3 ; idD = 4 ; idT = 5;
        int nEdgeX = Give_Nx_hexahedron ( id_hex );
        int nEdgeY = Give_Ny_hexahedron ( id_hex );
        int nEdgeZ = Give_Nz_hexahedron ( id_hex );
        int quadSaddI = (p_quad_Sdir3D[0] == 1) ? 0 : nEdgeX;
        int quadSaddK = (p_quad_Sdir3D[2] == 1) ? 0 : nEdgeZ;
        int quadNaddI = (p_quad_Ndir3D[0] == 1) ? 0 : nEdgeX;
        int quadNaddK = (p_quad_Ndir3D[2] == 1) ? 0 : nEdgeZ;
        int quadDaddI = (p_quad_Ddir3D[0] == 1) ? 0 : nEdgeX;
        int quadDaddJ = (p_quad_Ddir3D[1] == 1) ? 0 : nEdgeY;
        int quadTaddI = (p_quad_Tdir3D[0] == 1) ? 0 : nEdgeX;
        int quadTaddJ = (p_quad_Tdir3D[1] == 1) ? 0 : nEdgeY;
        int quadEaddJ = (p_quad_Edir3D[1] == 1) ? 0 : nEdgeY;
        int quadEaddK = (p_quad_Edir3D[2] == 1) ? 0 : nEdgeZ;
        int quadWaddJ = (p_quad_Wdir3D[1] == 1) ? 0 : nEdgeY;
        int quadWaddK = (p_quad_Wdir3D[2] == 1) ? 0 : nEdgeZ;


558
559
560
561
562
563
564
565
566
//        std::cout <<"Nx "  << Give_Nx_quadrangle ( idW ) << " Ny " << Give_Ny_quadrangle ( idW ) << "\n";
//        std::cout <<"Nx "  << Give_Nx_quadrangle ( idE ) << " Ny " << Give_Ny_quadrangle ( idE ) << "\n";
//        std::cout <<"Nx "  << Give_Nx_quadrangle ( idS ) << " Ny " << Give_Ny_quadrangle ( idS ) << "\n";
//        std::cout <<"Nx "  << Give_Nx_quadrangle ( idN ) << " Ny " << Give_Ny_quadrangle ( idN ) << "\n";
//        std::cout <<"Nx "  << Give_Nx_quadrangle ( idD ) << " Ny " << Give_Ny_quadrangle ( idD ) << "\n";
//        std::cout <<"Nx "  << Give_Nx_quadrangle ( idT ) << " Ny " << Give_Ny_quadrangle ( idT ) << std::endl;

//        std::cout << std::endl;
//        std::cout << " transface coordiantes: "<< std::endl;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
567
568
        //with modification

569
570
571
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
        bool invertTD = false;
        bool invertNS = false;
        bool invertEW = false;
        if (!(nEdgeY == Give_Nx_quadrangle ( idW ) && nEdgeZ == Give_Ny_quadrangle ( idW )))
        {
                invertEW = true;
        }

        if (!(nEdgeX == Give_Nx_quadrangle ( idS ) && nEdgeZ == Give_Ny_quadrangle ( idS ) ))
        {
            invertNS = true;
        }

        if (!(nEdgeX == Give_Nx_quadrangle ( idD ) && nEdgeY == Give_Ny_quadrangle ( idD )))
        {
            invertTD = true;
        }

        QPsi[0] = Give_coord_quadrangle( idW , quadWaddJ + j*p_quad_Wdir3D[1] , quadWaddK + k*p_quad_Wdir3D[2],invertEW);
        QPsi[1] = Give_coord_quadrangle( idE , quadEaddJ + j*p_quad_Edir3D[1] , quadEaddK + k*p_quad_Edir3D[2],invertEW);
        QPsi[2] = Give_coord_quadrangle( idS , quadSaddI + i*p_quad_Sdir3D[0] , quadSaddK + k*p_quad_Sdir3D[2],invertNS);
        QPsi[3] = Give_coord_quadrangle( idN , quadNaddI + i*p_quad_Ndir3D[0] , quadNaddK + k*p_quad_Ndir3D[2],invertNS);
        QPsi[4] = Give_coord_quadrangle( idD , quadDaddI + i*p_quad_Ddir3D[0] , quadDaddJ + j*p_quad_Ddir3D[1],invertTD);
        QPsi[5] = Give_coord_quadrangle( idT , quadTaddI + i*p_quad_Tdir3D[0] , quadTaddJ + j*p_quad_Tdir3D[1],invertTD);
        //delete again!!!
       // QPsi[5] = Give_coord_quadrangle( idT , quadTaddJ + j*p_quad_Tdir3D[1] , quadTaddI + i*p_quad_Tdir3D[0]);

        //std::cout << std::endl;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
597
598
        // Version: 1 x Flaechen + 2 x Kanten + 3 x Ecken
        // /////////////////////////////////////////////////////////
599
        Pres = (QPsi[0] + eta * (QPsi[1]-QPsi[0]) + QPsi[2] + xi * (QPsi[3]-QPsi[2]) + QPsi[4] + phi * (QPsi[5]-QPsi[4]));
Phillip Lino Rall's avatar
Phillip Lino Rall committed
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

        //cout << "PresQuad V1 " ; PresQuad.Print();cout<<endl;

        PD = HWSD +
             ( HESD - HWSD ) * eta +
             ( HWND - HWSD ) * xi +
             ( HEND - HESD - HWND + HWSD ) * eta * xi;

        PT = HWST +
             ( HEST - HWST ) * eta +
             ( HWNT - HWST ) * xi +
             ( HENT - HEST - HWNT + HWST ) * eta * xi;

        // Version: 0 x Flaechen + 0 x Kanten + 1 x Ecken
        // /////////////////////////////////////////////////////////
615
        Pres = Pres +
Phillip Lino Rall's avatar
Phillip Lino Rall committed
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
               1.0 * ( PD + ( PT-PD ) * phi );



        // Version: 0 x Flaechen + 1 x Kanten + 3 x Ecken
        // /////////////////////////////////////////////////////////

        bool coordianteFromCorners = false;

        for ( int md = 0; md < 3; ++md )
        {






          if ( md==0 ) // EW
          {

636
              PSW = Give_coord_quadrangle(idS,quadSaddI+i*p_quad_Sdir3D[0] ,quadSaddK, invertNS);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
637
638
639
              if(coordianteFromCorners)
              PSW = Psi[SDed];

640
              PSE = Give_coord_quadrangle(idN,quadNaddI+i * p_quad_Ndir3D[0],quadNaddK, invertNS);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
641
642
643
644
             if(coordianteFromCorners)
              PSE = Psi[NDed];


645
              PNW = Give_coord_quadrangle(idS,quadSaddI+i*p_quad_Sdir3D[0] ,nEdgeZ-quadSaddK, invertNS);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
646
647
648
649
              if(coordianteFromCorners)
              PNW = Psi[STed];


650
              PNE = Give_coord_quadrangle(idN,quadNaddI+i * p_quad_Ndir3D[0],nEdgeZ-quadNaddK, invertNS);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
651
652
653
654
655
656
657
              if(coordianteFromCorners)
              PNE = Psi[NTed];



            p_EW = xi;
            p_NS = phi;
658

Phillip Lino Rall's avatar
Phillip Lino Rall committed
659
660
661
662
663
          }
          if ( md==1 ) // NS
          {


664
              PSW = Give_coord_quadrangle(idD,quadDaddI,quadDaddJ+j*p_quad_Ddir3D[1], invertTD);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
665
666
667
668
              if(coordianteFromCorners)
              PSW = Psi[WDed];


669
            PSE = Give_coord_quadrangle(idD,nEdgeX-quadDaddI,quadDaddJ+j*p_quad_Ddir3D[1], invertTD);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
670
671
672
673
            if(coordianteFromCorners)
            PSE = Psi[EDed];


674
            PNW = Give_coord_quadrangle(idT,quadTaddI,quadTaddJ+j*p_quad_Tdir3D[1], invertTD);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
675
676
677
            if(coordianteFromCorners)
            PNW = Psi[WTed];

678
            PNE = Give_coord_quadrangle(idT,nEdgeX-quadTaddI,quadTaddJ+j*p_quad_Tdir3D[1], invertTD);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
679
680
681
682
683
684
685
686
            if(coordianteFromCorners)
            PNE = Psi[ETed];




            p_EW = eta;
            p_NS = phi;
687

Phillip Lino Rall's avatar
Phillip Lino Rall committed
688
689
690
691
692
          }
          if ( md==2 ) // TD
          {


693
            PSW = Give_coord_quadrangle(idW,quadWaddJ,quadWaddK+k*p_quad_Wdir3D[2], invertEW);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
694
695
696
           if(coordianteFromCorners)
            PSW = Psi[SWed];

697
            PSE = Give_coord_quadrangle(idE,quadEaddJ,quadEaddK+k*p_quad_Edir3D[2], invertEW);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
698
699
700
701
            if(coordianteFromCorners)
            PSE = Psi[SEed];


702
            PNW = Give_coord_quadrangle(idW,nEdgeY-quadWaddJ,quadWaddK+k*p_quad_Wdir3D[2], invertEW);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
703
704
705
            if(coordianteFromCorners)
            PNW = Psi[NWed];

706
            PNE = Give_coord_quadrangle(idE,nEdgeY-quadEaddJ,quadEaddK+k*p_quad_Edir3D[2], invertEW);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
707
708
709
710
711
712
713
714
715
           if(coordianteFromCorners)
            PNE = Psi[NEed];

            p_EW = eta;
            p_NS = xi;


          }

716
          Pres = Pres + ( PSW +
Phillip Lino Rall's avatar
Phillip Lino Rall committed
717
718
719
720
721
                 ( PSE - PSW ) * p_EW +
                 ( PNW - PSW ) * p_NS +
                 ( PNE - PSE - PNW + PSW ) * p_EW * p_NS) * (-1.0);
        }

722

Phillip Lino Rall's avatar
Phillip Lino Rall committed
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
    }
    else
    {
        for ( int ed = 0; ed < 12; ++ed )
        {
          p = find_p ( ( Edges_cell ) ed,eta,xi,phi );
          Psi[ed] = hex->transform[ed] ( change ( hex->orientation[ed],p ) ,
                         hex->shiftPointer(ug->Get_pointer_global_data()));
          PL = hex->Give_coord ( Transform ( ( Edges_cell ) ed,Ldir1D ) );
          PR = hex->Give_coord ( Transform ( ( Edges_cell ) ed,Rdir1D ) );
          Psi[ed] = Psi[ed] + PL + ( PR-PL ) * p;
        }



Phillip Lino Rall's avatar
Phillip Lino Rall committed
738
739
740
741
742
743
744
745
746
747
748

  Pres = D3vector ( 0.0,0.0,0.0 );
  for ( int md = 0; md < 3; ++md )
  {
    if ( md==0 ) // EW
    {
      PSW = Psi[SDed];
      PSE = Psi[NDed];
      PNW = Psi[STed];
      PNE = Psi[NTed];

Phillip Lino Rall's avatar
Phillip Lino Rall committed
749

Phillip Lino Rall's avatar
Phillip Lino Rall committed
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
      p_EW = xi;
      p_NS = phi;
    }
    if ( md==1 ) // NS
    {
      PSW = Psi[WDed];
      PSE = Psi[EDed];
      PNW = Psi[WTed];
      PNE = Psi[ETed];

      p_EW = eta;
      p_NS = phi;
    }
    if ( md==2 ) // TD
    {
      PSW = Psi[SWed];
      PSE = Psi[SEed];
      PNW = Psi[NWed];
      PNE = Psi[NEed];

      p_EW = eta;
      p_NS = xi;
    }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
773
774
775

    // Version: 0 x Flaechen + 1 x Kanten + 3 x Ecken
    // /////////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
    Pres = Pres + PSW +
           ( PSE - PSW ) * p_EW +
           ( PNW - PSW ) * p_NS +
           ( PNE - PSE - PNW + PSW ) * p_EW * p_NS;
  }

  PD = HWSD +
       ( HESD - HWSD ) * eta +
       ( HWND - HWSD ) * xi +
       ( HEND - HESD - HWND + HWSD ) * eta * xi;

  PT = HWST +
       ( HEST - HWST ) * eta +
       ( HWNT - HWST ) * xi +
       ( HENT - HEST - HWNT + HWST ) * eta * xi;

  Pres = Pres -
         2.0 * ( PD + ( PT-PD ) * phi );
794
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
795

796

Phillip Lino Rall's avatar
Phillip Lino Rall committed
797
798
799
800
801
802
  if ( hex->transform_hex== NULL )
    return Pres;
  else
    return Pres + hex->transform_hex ( id_hex,eta,xi,phi );
}

803
D3vector Blockgrid::Give_coord_quadrangle (int id, int i, int j, bool invert) const
Phillip Lino Rall's avatar
Phillip Lino Rall committed
804
{
805
806
807
808
809
810
811
812
813
    if(bg_coord != NULL) if(bg_coord->blockgrid_quad_coordinates_calculated)
        {
            int Nx = Give_Nx_quadrangle(  id ) +1;
            //cout << "id_hex " << id_hex << " i " << i << " j " << j << " k " << k << endl;
            //cout << "index " << i + Nx* (j  + k * (Ny))<< endl;
            return bg_coord->blockgrid_quad_coordinates.at(id).at(i + Nx* (j  )  );
        }


814
815


Phillip Lino Rall's avatar
Phillip Lino Rall committed
816
817
  double eta, xi;
  D3vector PSW, PSE, PNW, PNE, PW, PE, PN, PS;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
818
  D3vector PTransFace, PWithoutTrans;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
819
820
821
  Quadrangle_el* quad;
  Edge_el* edge;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
822
823
  quad = this->ug->Give_quadrangle ( id );

824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
  double Nx = (double) Give_Nx_quadrangle ( id );
  double Ny = ( double ) Give_Ny_quadrangle ( id );

//  std::cout << "nx ny " << Nx << " " << Ny << std::endl;
//  if (id == 23 && Nx != Ny)
//  {
//      std::cout << "break";
//  }

//  std::cout << "nx ny " << Nx << " " << Ny << std::endl;
  if (invert)
  {
      double temp = Nx; Nx = Ny; Ny = temp;
  }
  //std::cout << "nx ny " << Nx << " " << Ny << std::endl;
  eta = ( double ) i/ Nx;
  xi = ( double ) j/ Ny;

  if (eta > 1 || xi > 1)
  {
      std::cout << "debug : flag is " << invert << ", but should be " << !invert << std::endl;
      std::cout << std::endl;
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
847
848
849
850
851
852
853
854


  // @todo : so sollte es sein
  PSW  = quad->Give_coord ( SWdir2D );
  PSE  = quad->Give_coord ( SEdir2D );
  PNW  = quad->Give_coord ( NWdir2D );
  PNE  = quad->Give_coord ( NEdir2D );

Phillip Lino Rall's avatar
Phillip Lino Rall committed
855
856


Phillip Lino Rall's avatar
Phillip Lino Rall committed
857
858
859
860
861
862
863
864
865
866
867
868
869
870
  /*
  // aber ist noch so
  PSW  = ug->Give_point(quad->Give_id_corner(SWdir2D))->Give_coordinate();
  PSE  = ug->Give_point(quad->Give_id_corner(SEdir2D))->Give_coordinate();
  PNW  = ug->Give_point(quad->Give_id_corner(NWdir2D))->Give_coordinate();
  PNE  = ug->Give_point(quad->Give_id_corner(NEdir2D))->Give_coordinate();
  */

  if ( developer_version )
    if ( quad->Give_id_corner ( SWdir2D ) >=quad->Give_id_corner ( SEdir2D ) ||
         quad->Give_id_corner ( SEdir2D ) >=quad->Give_id_corner ( NWdir2D )  ||
         quad->Give_id_corner ( SWdir2D ) >=quad->Give_id_corner ( NEdir2D ) )
      cout << " error in Blockgrid::Give_coord_quadrangle! " << endl;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
871
872
873
874
875
  //Phillip version with deformed faces

  if (quad->transform != NULL)
  {
      PTransFace = quad->transform ( eta, xi, quad->shiftPointer(ug->Get_pointer_global_data()));
876
877
878
      //std::cout << "PTransFace ";PTransFace.Print();
      D3vector TEMP = PSW + (PSE-PSW) * eta + (PNW-PSW)*xi + (PNE-PSE-PNW+PSW)*xi*eta ;
      PTransFace =  TEMP + PTransFace;//   + PTransFace;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
879
880
881
882
      return PTransFace;
  }

  //Christoph version with deformed edges
Phillip Lino Rall's avatar
Phillip Lino Rall committed
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
  edge = ug->Give_edge ( quad->Give_id_edge ( Wdir2D ) );
  PW = edge->transform ( xi, edge->shiftPointer(ug->Get_pointer_global_data()));
  PW = PW + PSW + ( PNW-PSW ) * xi;

  edge = ug->Give_edge ( quad->Give_id_edge ( Sdir2D ) );
  PS = edge->transform ( eta, edge->shiftPointer(ug->Get_pointer_global_data()));
  PS = PS + PSW + ( PSE-PSW ) * eta;

  edge = ug->Give_edge ( quad->Give_id_edge ( Edir2D ) ); // @todo: warum braucht man hier kein orientation
  PE = edge->transform ( xi, edge->shiftPointer(ug->Get_pointer_global_data()));
  PE = PE + PSE + ( PNE-PSE ) * xi;

  edge = ug->Give_edge ( quad->Give_id_edge ( Ndir2D ) ); // @todo: warum braucht man hier kein orientation
  PN = edge->transform ( eta , edge->shiftPointer(ug->Get_pointer_global_data()));
  PN = PN + PNW + ( PNE-PNW ) * eta;

  return
    PW + eta* ( PE-PW ) +
    PS + xi* ( PN-PS )
    - ( PSW +
        ( PSE - PSW ) * eta +
        ( PNW - PSW ) * xi +
        ( PNE - PSE - PNW + PSW ) * eta * xi );
}

D3vector Blockgrid::Give_coord_edge ( int id, int i ) const
{
Phillip Lino Rall's avatar
Phillip Lino Rall committed
910

Christoph Pflaum's avatar
Christoph Pflaum committed
911
        if(bg_coord != NULL) if(bg_coord->blockgrid_edge_coordinates_calculated)
912
        {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
913
            return bg_coord->blockgrid_edge_coordinates.at(id).at(i) ;
914
        }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
915

916

917

Phillip Lino Rall's avatar
Phillip Lino Rall committed
918
    Quadrangle_el* quad;
919
    Hexahedron_el* hex;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
920
    D3vector Psi;
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965

    if (ug->Give_transform_From_Quadrangle())
    {
    int idHex;
    dir3D dirForQuad;
    int quadId;

    if (ug->Give_edge_to_quad_id(id) == -1)
    {
       // cout << "slow way, once each, id " << id << endl;

    //findet hexahedron entsprechend zur kanten ID
    for (int iterHex = 0 ; iterHex < ug->Give_number_hexahedra() ; iterHex++)
    {
        idHex = iterHex;
        hex = ug->Give_hexahedron(iterHex);
        for (int iter = 0 ; iter < 12 ; iter++)
        {
            int idCorner = hex->Give_id_edge(Edges_cell(iter));
            if (idCorner == id)
            {
               iterHex = ug->Give_number_hexahedra() ;
               iter = 12;
            }
        }
    }


    //findet quad ID sowie ausrichtung entsprechend zur kanten ID
    for ( int iter = 0 ; iter < 6 ; iter++)
    {
        quad = ug->Give_quadrangle(hex->Give_id_quadrangle((dir3D)iter));
        dirForQuad = (dir3D)iter ;
        for (int iterEdge = 0 ; iterEdge < 4 ; iterEdge++)
        {
            quadId = quad->Give_id_edge((dir2D)iterEdge);
            if (id == quadId)
            {
                quadId = hex->Give_id_quadrangle((dir3D)iter);
                iterEdge = 4;
                iter = 6;

            }
        }
    }
966
    ug->Set_edge_to_hex_id(id, idHex);
967
968
969
970
971
    ug->Set_edge_to_quad_id(id,quadId);
    ug->Set_edge_to_quad_dir(id,(int)dirForQuad);
    }
    else
    {
972
        idHex = ug->Give_edge_to_hex_id(id);
973
974
975
976
977
        quadId = ug->Give_edge_to_quad_id(id);
        dirForQuad = (dir3D)ug->Give_edge_to_quad_dir(id);
        quad = ug->Give_quadrangle(quadId);
    }

978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
    int Nx = Give_Nx_quadrangle(quadId);
    int Ny = Give_Ny_quadrangle(quadId);
    int nEdgeX = Give_Nx_hexahedron ( idHex );
    int nEdgeY = Give_Ny_hexahedron ( idHex );
    int nEdgeZ = Give_Nz_hexahedron ( idHex );
    bool invert = false;

//    std::cout << "dirForQuad " << dirForQuad << std::endl;
//    std::cout << "Nx " << Nx << " Ny " << Ny << std::endl;
//            if (!(Nx == Give_Nx_quadrangle ( dirForQuad ) && Ny == Give_Ny_quadrangle ( dirForQuad ) ))
//            {
//                invert = true;
//            }
//    if (dirForQuad == Edir3D || dirForQuad == Wdir3D)
//    {
//        if (!(nEdgeY == Give_Nx_quadrangle ( dirForQuad ) && nEdgeZ == Give_Ny_quadrangle ( dirForQuad ) ))
//        {
//            invert = true;
//        }
//    }
//    else if (dirForQuad == Ndir3D || dirForQuad == Sdir3D)
//    {
//        if (!(nEdgeX == Give_Nx_quadrangle ( dirForQuad ) && nEdgeZ == Give_Ny_quadrangle ( dirForQuad ) ))
//        {
//            invert = true;
//        }
//    }
//    else if (dirForQuad == Tdir3D || dirForQuad == Ddir3D)
//    {
//        if (!(nEdgeX == Give_Nx_quadrangle ( dirForQuad ) && nEdgeY == Give_Ny_quadrangle ( dirForQuad )))
//        {
//            invert = true;
//        }
//    }
//    else
//    {
//        std::cout << "should not happen, dirForQuad only has 6 possibilities\n";
//    }

    if (Nx == nEdgeX && Ny == nEdgeY || Nx == nEdgeX && Ny == nEdgeZ || Nx == nEdgeY && Ny == nEdgeZ )
    {
        invert = false;
    }
    else
    {
        invert = true;
    }
    
    invert = false;
1027
1028
1029

    if (id == quad->Give_id_edge(Wdir2D)) //Wdir2D
    {
1030
        Psi = Give_coord_quadrangle(quadId,0,i,invert);
1031
1032
1033
    }
    if (id == quad->Give_id_edge(Edir2D)) //Edir2D
    {
1034
        Psi = Give_coord_quadrangle(quadId,Nx,i,invert);
1035
1036
1037
    }
    if (id == quad->Give_id_edge(Sdir2D)) //Sdir2D
    {
1038
        Psi = Give_coord_quadrangle(quadId,i,0,invert);
1039
1040
1041
    }
    if (id == quad->Give_id_edge(Ndir2D)) //Ndir2D
    {
1042
        Psi = Give_coord_quadrangle(quadId,i,Ny,invert);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1043
    }
1044
1045

    return Psi;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1046
1047


1048
}
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1049
     //Christoph version, if quadrangles are NOT defined.
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1050
  double eta;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1051
  D3vector PL, PR;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1052
1053
1054
1055
1056
1057
  Edge_el* edge;

  edge = ug->Give_edge ( id );

  eta = ( double ) i/ ( double ) Give_Nx_edge ( id );

1058
  //cout << "psi new "; Psi.Print();cout << endl;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1059

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
  Psi = edge->transform ( eta , edge->shiftPointer(ug->Get_pointer_global_data()));

  PL  = edge->Give_coord ( Ldir1D );
  PR  = edge->Give_coord ( Rdir1D );

  /*
  PL  = ug->Give_point(edge->Give_id_corner_W())->Give_coordinate();
  PR  = ug->Give_point(edge->Give_id_corner_E())->Give_coordinate();
  */

1070
 // cout << "psi old " ; (Psi + PL + ( PR-PL ) * eta).Print();cout << endl;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1071
1072
1073
1074
1075
  return Psi + PL + ( PR-PL ) * eta;
}

D3vector Blockgrid::Give_coord_point ( int id_point ) const
{
1076
1077
1078
1079
    if(bg_coord != NULL) if(bg_coord->blockgrid_point_coordinates_calculated)
        {
            return bg_coord->blockgrid_point_coordinates.at(id_point);
        }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1080
1081
1082
1083
1084
1085
1086
1087
  return ug->Give_point ( id_point )->Give_coordinate();
}



int Blockgrid::Total_number_of_points() const
{
  using namespace std;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1088

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
  int num_points, num_points_hex, num_points_quad, num_points_edges;

  int Nx, Ny, Nz;

  num_points = num_points_hex = num_points_quad = num_points_edges = 0;

  // hexahedra
  for ( int id=0;id<ug->Give_number_hexahedra();++id )
  {
    Nx = Give_Nx_hexahedron ( id );
    Ny = Give_Ny_hexahedron ( id );
    Nz = Give_Nz_hexahedron ( id );

    num_points_hex += ( Nx-1 ) * ( Ny-1 ) * ( Nz-1 );
  }

  // quadrangles
  for ( int id=0;id<ug->Give_number_quadrangles();++id )
  {
    Nx = Give_Nx_quadrangle ( id );
    Ny = Give_Ny_quadrangle ( id );

    num_points_quad += ( Nx-1 ) * ( Ny-1 );
  }

  // edges
  for ( int id=0;id<ug->Give_number_edges();++id )
  {
    Nx = Give_Nx_edge ( id );

    num_points_edges += ( Nx-1 );
  }

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1122

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1123
1124
1125
1126
  // points
  num_points = ug->Give_number_points();
  // alltogether
  num_points = num_points + num_points_hex + num_points_quad + num_points_edges;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1127

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1128
1129
1130
1131
1132
1133
/*  cout << "total number of points of blockgrid: " << num_points << endl;
  getchar();*/
  return num_points;
}


Phillip Lino Rall's avatar
Phillip Lino Rall committed
1134
1135
1136
1137
1138
1139


void Blockgrid_coordinates::init_blockgrid_coordinates()
{
    blockgrid_edge_coordinates_calculated = false;
    blockgrid_hexa_coordinates_calculated = false;
1140
1141
    blockgrid_quad_coordinates_calculated = false;
    blockgrid_point_coordinates_calculated = false;
1142
1143

    blockgrid_hexa_boundaries_calculated = false;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
    blockgrid_hexa_coordinates.resize(bg->Give_unstructured_grid()->Give_number_hexahedra());
    for (int id_hex = 0 ; id_hex < bg->Give_unstructured_grid()->Give_number_hexahedra() ; id_hex++)
    {
        int Nx = bg->Give_Nx_hexahedron(id_hex)+1;
        int Ny = bg->Give_Ny_hexahedron(id_hex)+1;
        int Nz = bg->Give_Nz_hexahedron(id_hex)+1;
        blockgrid_hexa_coordinates.at(id_hex).resize(Nx*Ny*Nz);
    }
    for (int id_hex = 0 ; id_hex < bg->Give_unstructured_grid()->Give_number_hexahedra() ; id_hex++)
    {
        int Nx = bg->Give_Nx_hexahedron(id_hex)+1;
        int Ny = bg->Give_Ny_hexahedron(id_hex)+1;
        int Nz = bg->Give_Nz_hexahedron(id_hex)+1;

            for(int i=0;i<Nx;++i) for(int j=0;j<Ny;++j) for(int k=0;k<Nz;++k)
            {

                blockgrid_hexa_coordinates.at(id_hex).at(    i    +Nx*(j    +Ny* k)) = bg->Give_coord_hexahedron(id_hex,i,j,k);
            }
    }

1165
1166

    //test:: ??? Nx = 3????
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
    blockgrid_edge_coordinates.resize(bg->Give_unstructured_grid()->Give_number_edges());
    for (int id_edge = 0 ; id_edge < bg->Give_unstructured_grid()->Give_number_edges() ; id_edge++)
    {
        int Nx = bg->Give_Nx_edge(id_edge)+1;
        blockgrid_edge_coordinates.at(id_edge).resize(Nx);
    }
    for (int id_edge = 0 ; id_edge < bg->Give_unstructured_grid()->Give_number_edges() ; id_edge++)
    {
        int Nx = bg->Give_Nx_edge(id_edge)+1;

            for(int i=0;i<Nx;++i)
            {
                blockgrid_edge_coordinates.at(id_edge).at(i) = bg->Give_coord_edge(id_edge,i);
            }
    }

1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
    blockgrid_quad_coordinates.resize(bg->Give_unstructured_grid()->Give_number_quadrangles());
    for (int id_quad = 0 ; id_quad < bg->Give_unstructured_grid()->Give_number_quadrangles() ; id_quad++)
    {
        int Nx = bg->Give_Nx_quadrangle(id_quad)+1;
        int Ny = bg->Give_Ny_quadrangle(id_quad)+1;
        blockgrid_quad_coordinates.at(id_quad).resize(Nx*Ny);
    }
    for (int id_quad = 0 ; id_quad < bg->Give_unstructured_grid()->Give_number_quadrangles() ; id_quad++)
    {
        int Nx = bg->Give_Nx_quadrangle(id_quad)+1;
        int Ny = bg->Give_Ny_quadrangle(id_quad)+1;

        for(int i=0;i<Nx;++i) for(int j=0;j<Ny;++j)
        {
                blockgrid_quad_coordinates.at(id_quad).at(i + Nx * j) = bg->Give_coord_quadrangle(id_quad,i,j);
        }
    }

    blockgrid_point_coordinates.resize(bg->Give_unstructured_grid()->Give_number_points());
    for (int id_point = 0 ; id_point < bg->Give_unstructured_grid()->Give_number_points() ; id_point++)
    {
        int N = bg->Give_unstructured_grid()->Give_number_points();

        for(int i=0;i<N;++i)
        {
                blockgrid_point_coordinates.at(i) = bg->Give_coord_point(i);
        }
    }


Phillip Lino Rall's avatar
Phillip Lino Rall committed
1213
1214
    blockgrid_edge_coordinates_calculated = true;
    blockgrid_hexa_coordinates_calculated = true;
1215
1216
    blockgrid_quad_coordinates_calculated = true;
    blockgrid_point_coordinates_calculated = true;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1217
1218
1219
1220
1221
}

void Blockgrid_coordinates::init_blockgrid_coordinates_boundary()
{

1222
    blockgrid_hexa_boundary.clear();
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1223
1224
1225
1226
1227
1228
1229
1230
1231
    int counter(0);
     blockgrid_hexa_boundary.resize(bg->Give_unstructured_grid()->Give_number_hexahedra());
    //outer loop
    for (int id_hex = 0 ; id_hex < bg->Give_unstructured_grid()->Give_number_hexahedra() ; id_hex++)
    {
        int Nx = bg->Give_Nx_hexahedron(id_hex)+1;
        int Ny = bg->Give_Ny_hexahedron(id_hex)+1;
        int Nz = bg->Give_Nz_hexahedron(id_hex)+1;
        blockgrid_hexa_boundary.at(id_hex).resize(Nx*Ny*Nz);
1232
1233
        //for(int i=0;i<Nx;++i) for(int j=0;j<Ny;++j) for(int k=0;k<Nz;++k)
             for(int k=0;k<Nz;++k) for(int j=0;j<Ny;++j) for(int i=0;i<Nx;++i)
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1234
1235
1236
                {

                    //if ((i > 0 || i < Nx-1) ^ (j > 0 || j < Ny-1) ^ (k > 0 || k < Nz-1))
1237
                    //remove true here?
1238
                    if (false || (i == 0 || i == Nx-1) || (j== 0 || j == Ny-1) || (k == 0 || k == Nz-1))
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
                    {
                        //inner loop
                        for (int id_hexInner = 0 ; id_hexInner < bg->Give_unstructured_grid()->Give_number_hexahedra() ; id_hexInner++)
                        {
                            if (id_hex == id_hexInner)
                            {
                                //id_hexInner++;
                            }
                            else
                            {
                            //cout << "id_hexInner " << id_hexInner<< endl;
                            int NxInner = bg->Give_Nx_hexahedron(id_hexInner)+1;
                            int NyInner = bg->Give_Ny_hexahedron(id_hexInner)+1;
                            int NzInner = bg->Give_Nz_hexahedron(id_hexInner)+1;
1253
1254
                            //for(int iInner=0;iInner<NxInner;++iInner) for(int jInner=0;jInner<NyInner;++jInner) for(int kInner=0;kInner<NzInner;++kInner)
                             for(int kInner=0;kInner<NzInner;++kInner) for(int jInner=0;jInner<NyInner;++jInner) for(int iInner=0;iInner<NxInner;++iInner)
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1255
1256
1257
                                {
                                    // not sure which if loop is correct:
                                    //if ((iInner > 0 || iInner < NxInner-1) ^ (jInner > 0 || jInner < NyInner-1) ^ (kInner > 0 || kInner < NzInner-1))
1258
                                    if (false || (iInner == 0 || iInner == NxInner-1) || (jInner == 0 || jInner == NyInner-1) || (kInner == 0 || kInner == NzInner-1))
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1259
                                    {
1260
                                        if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInner,jInner,kInner)) < 1e-10 )
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1261
1262
1263
1264
1265
1266
1267
1268
                                        {

                                            int convertedLocalIndex = i    +(Nx)*(j    +(Ny)* k);
                                            counter++;
                                            blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                                            blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInner);
                                            blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInner);
                                            blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInner);
1269
1270


Phillip Lino Rall's avatar
Phillip Lino Rall committed
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
                                        }

                                    }
                                }

                            }


                            }


                        }

                    }
                 }
    blockgrid_hexa_boundaries_calculated = true;
    }

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
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
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
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
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
void Blockgrid_coordinates::init_blockgrid_coordinates_boundary_fast()
{
    blockgrid_hexa_boundary.clear();
    counter = 0;
     blockgrid_hexa_boundary.resize(bg->Give_unstructured_grid()->Give_number_hexahedra());
    //outer loop
    for (int id_hex = 0 ; id_hex < bg->Give_unstructured_grid()->Give_number_hexahedra() ; id_hex++)
    {
        int Nx = bg->Give_Nx_hexahedron(id_hex);
        int Ny = bg->Give_Ny_hexahedron(id_hex);
        int Nz = bg->Give_Nz_hexahedron(id_hex);
        blockgrid_hexa_boundary.at(id_hex).resize((Nx+1)*(Ny+1)*(Nz+1));
             for(int k=0;k<=Nz;k+=Nz/2) for(int j=0;j<=Ny;j+=Ny/2) for(int i=0;i<=Nx;i+=Nx/2)
                {
                 bool A = (i == 0 || i == Nx);
                 bool B = (j == 0 || j == Ny);
                 bool C = (k == 0 || k == Nz);
                    if ((A&!B&!C)|(!A&B&!C)|(!A&!B&C))
                    {
                        //inner loop
                        for (int id_hexInner = 0 ; id_hexInner < bg->Give_unstructured_grid()->Give_number_hexahedra() ; id_hexInner++)
                        {
                            if (id_hex != id_hexInner)
                            {
                            //cout << "id_hexInner " << id_hexInner<< endl;
                            int NxInner = bg->Give_Nx_hexahedron(id_hexInner);
                            int NyInner = bg->Give_Ny_hexahedron(id_hexInner);
                            int NzInner = bg->Give_Nz_hexahedron(id_hexInner);
                              for(int kInner=0;kInner<=NzInner;kInner+=NzInner/2) for(int jInner=0;jInner<=NyInner;jInner+=NyInner/2) for(int iInner=0;iInner<=NxInner;iInner+=NxInner/2)
                                {
                                  bool AI = (iInner == 0 || iInner == NxInner);
                                 bool BI = (jInner == 0 || jInner == NyInner);
                                 bool CI = (kInner == 0 || kInner == NzInner);
                                    if ((AI&!BI&!CI)|(!AI&BI&!CI)|(!AI&!BI&CI))
                                    {
                                        if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInner,jInner,kInner)) < 1e-10 )
                                        {
                                            //add whole plane :
                                            addBoundaryPlane(id_hex,i,j,k,id_hexInner,iInner,jInner,kInner, Nx,  Ny, Nz, NxInner, NyInner, NzInner);
//                                            int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
//                                            counter++;
//                                            blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
//                                            blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInner);
//                                            blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInner);
//                                            blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInner);


                                        }

                                    }
                                }

                            }


                            }


                        }

                    }
                 }
    blockgrid_hexa_boundaries_calculated = true;
    }

void Blockgrid_coordinates::addBoundaryPlane(int id_hex, int i, int j, int k, int id_hexInner, int iInner, int jInner, int kInner, int Nx, int Ny, int Nz, int NxInner, int NyInner, int NzInner)
{
    int PlaneHits{0};
    int tempTries{0};
    if (i == 0 || i == Nx)
    {
        //vary j,k
        for (j = 0 ; j <= Ny;j++)for (k = 0 ; k <= Nz;k++)
        {

            if (iInner == 0 || iInner == NxInner)
            {
                //vary j,k
                for (int jInnerT = 0 ; jInnerT <= NyInner;jInnerT++)for (int kInnerT = 0 ; kInnerT <= NzInner;kInnerT++)
                {
                    tempTries++;
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInner,jInnerT,kInnerT)) < 1e-10 )
                    {
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInnerT);
                    }
                }
            }
            else if (jInner == 0 || jInner == NyInner)
            {
                //vary i,k
                for (int iInnerT = 0 ; iInnerT <= NxInner;iInnerT++)for (int kInnerT = 0 ; kInnerT <= NzInner;kInnerT++)
                {
                    tempTries++;
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInnerT,jInner,kInnerT)) < 1e-10 )
                    {
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInnerT);
                    }
                }
            }
            else
            {
                //vary i,j
                for (int iInnerT = 0 ; iInnerT <= NxInner;iInnerT++)for (int jInnerT = 0 ; jInnerT <= NyInner;jInnerT++)
                {
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInnerT,jInnerT,kInner)) < 1e-10 )
                    {
                        tempTries++;
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInner);
                    }
                }
            }
        }
    }
    else if (j == 0 || j == Ny)
    {
        //vary i,k
        for (i = 0 ; i <= Nx;i++)for (k = 0 ; k <= Nz;k++)
        {

            if (iInner == 0 || iInner == NxInner)
            {
                //vary j,k
                for (int jInnerT = 0 ; jInnerT <= NyInner;jInnerT++)for (int kInnerT = 0 ; kInnerT <= NzInner;kInnerT++)
                {
                    tempTries++;
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInner,jInnerT,kInnerT)) < 1e-10 )
                    {
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInnerT);
                    }
                }
            }
            else if (jInner == 0 || jInner == NyInner)
            {
                //vary i,k
                for (int iInnerT = 0 ; iInnerT <= NxInner;iInnerT++)for (int kInnerT = 0 ; kInnerT <= NzInner;kInnerT++)
                {
                    tempTries++;
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInnerT,jInner,kInnerT)) < 1e-10 )
                    {
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInnerT);
                    }
                }
            }
            else
            {
                //vary i,j
                for (int iInnerT = 0 ; iInnerT <= NxInner;iInnerT++)for (int jInnerT = 0 ; jInnerT <= NyInner;jInnerT++)
                {
                    tempTries++;
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInnerT,jInnerT,kInner)) < 1e-10 )
                    {
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInner);
                    }
                }
            }
        }
    }
    else
    {
        //vary i,j
        for (i = 0 ; i <= Nx;i++)for (j = 0 ; j <= Ny;j++)
        {

            if (iInner == 0 || iInner == NxInner)
            {
                //vary j,k
                for (int jInnerT = 0 ; jInnerT <= NyInner;jInnerT++)for (int kInnerT = 0 ; kInnerT <= NzInner;kInnerT++)
                {
                    tempTries++;
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInner,jInnerT,kInnerT)) < 1e-10 )
                    {
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInnerT);
                    }
                }
            }
            else if (jInner == 0 || jInner == NyInner)
            {
                //vary i,k
                for (int iInnerT = 0 ; iInnerT <= NxInner;iInnerT++)for (int kInnerT = 0 ; kInnerT <= NzInner;kInnerT++)
                {
                    tempTries++;
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInnerT,jInner,kInnerT)) < 1e-10 )
                    {
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInnerT);
                    }
                }
            }
            else
            {
                //vary i,j
                for (int iInnerT = 0 ; iInnerT <= NxInner;iInnerT++)for (int jInnerT = 0 ; jInnerT <= NyInner;jInnerT++)
                {
                    tempTries++;
                    if(D3VectorNormSquared(bg->Give_coord_hexahedron(id_hex,i,j,k) - bg->Give_coord_hexahedron(id_hexInner,iInnerT,jInnerT,kInner)) < 1e-10 )
                    {
                        int convertedLocalIndex = i    +(Nx+1)*(j    +(Ny+1)* k);
                        counter++;
                        PlaneHits++;
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(id_hexInner);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(iInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(jInnerT);
                        blockgrid_hexa_boundary.at(id_hex).at(convertedLocalIndex).push_back(kInner);
                    }
                }
            }
        }
    }


//    std::cout << "tempTries " << tempTries << std::endl;
//    std::cout << "PlaneHits " << PlaneHits << std::endl;
//    std::cout << "PlaneHits " << PlaneHits << std::endl;



}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563

void Blockgrid_coordinates::delete_blockgrid_coordinates()
{

    blockgrid_edge_coordinates_calculated = false;
    blockgrid_hexa_coordinates_calculated = false;
    blockgrid_hexa_coordinates.clear();
    blockgrid_hexa_boundary.clear();

}
1564