blockgrid.cc 47.1 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

Phillip Lino Rall's avatar
Phillip Lino Rall committed
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
    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
476
477
478
D3vector Blockgrid::Give_coord_hexahedron ( int id_hex,
    int i, int j, int k ) const
{
Phillip Lino Rall's avatar
Phillip Lino Rall committed
479

Christoph Pflaum's avatar
Christoph Pflaum committed
480
    if(bg_coord != NULL) if(bg_coord->blockgrid_edge_coordinates_calculated)
481
482
483
484
485
        {
            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
486
            return bg_coord->blockgrid_hexa_coordinates.at(id_hex).at(i + Nx* (j  + k * (Ny))  );
487
        }
488

Phillip Lino Rall's avatar
Phillip Lino Rall committed
489

Phillip Lino Rall's avatar
Phillip Lino Rall committed
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
  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
505
506
507
508
509
510
511
512
513
514



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

515

516

517
518


Phillip Lino Rall's avatar
Phillip Lino Rall committed
519
520
521
522
523
524
525
526
527
528
  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;

529
  D3vector QPsi[6];
Phillip Lino Rall's avatar
Phillip Lino Rall committed
530
531


532
    if(ug->Give_transform_From_Quadrangle())
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
    {
        //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;


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

        // Version: 1 x Flaechen + 2 x Kanten + 3 x Ecken
        // /////////////////////////////////////////////////////////
563
        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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578

        //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
        // /////////////////////////////////////////////////////////
579
        Pres = Pres +
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
620
621
               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
          {

              PSW = Give_coord_quadrangle(idS,quadSaddI+i*p_quad_Sdir3D[0] ,quadSaddK);
              if(coordianteFromCorners)
              PSW = Psi[SDed];

              PSE = Give_coord_quadrangle(idN,quadNaddI+i * p_quad_Ndir3D[0],quadNaddK);
             if(coordianteFromCorners)
              PSE = Psi[NDed];


              PNW = Give_coord_quadrangle(idS,quadSaddI+i*p_quad_Sdir3D[0] ,nEdgeZ-quadSaddK);
              if(coordianteFromCorners)
              PNW = Psi[STed];


              PNE = Give_coord_quadrangle(idN,quadNaddI+i * p_quad_Ndir3D[0],nEdgeZ-quadNaddK);
              if(coordianteFromCorners)
              PNE = Psi[NTed];



            p_EW = xi;
            p_NS = phi;
622

Phillip Lino Rall's avatar
Phillip Lino Rall committed
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
          }
          if ( md==1 ) // NS
          {


              PSW = Give_coord_quadrangle(idD,quadDaddI,quadDaddJ+j*p_quad_Ddir3D[1]);
              if(coordianteFromCorners)
              PSW = Psi[WDed];


            PSE = Give_coord_quadrangle(idD,nEdgeX-quadDaddI,quadDaddJ+j*p_quad_Ddir3D[1]);
            if(coordianteFromCorners)
            PSE = Psi[EDed];


            PNW = Give_coord_quadrangle(idT,quadTaddI,quadTaddJ+j*p_quad_Tdir3D[1]);
            if(coordianteFromCorners)
            PNW = Psi[WTed];

            PNE = Give_coord_quadrangle(idT,nEdgeX-quadTaddI,quadTaddJ+j*p_quad_Tdir3D[1]);
            if(coordianteFromCorners)
            PNE = Psi[ETed];




            p_EW = eta;
            p_NS = phi;
651

Phillip Lino Rall's avatar
Phillip Lino Rall committed
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
          }
          if ( md==2 ) // TD
          {


            PSW = Give_coord_quadrangle(idW,quadWaddJ,quadWaddK+k*p_quad_Wdir3D[2]);
           if(coordianteFromCorners)
            PSW = Psi[SWed];

            PSE = Give_coord_quadrangle(idE,quadEaddJ,quadEaddK+k*p_quad_Edir3D[2]);
            if(coordianteFromCorners)
            PSE = Psi[SEed];


            PNW = Give_coord_quadrangle(idW,nEdgeY-quadWaddJ,quadWaddK+k*p_quad_Wdir3D[2]);
            if(coordianteFromCorners)
            PNW = Psi[NWed];

            PNE = Give_coord_quadrangle(idE,nEdgeY-quadEaddJ,quadEaddK+k*p_quad_Edir3D[2]);
           if(coordianteFromCorners)
            PNE = Psi[NEed];

            p_EW = eta;
            p_NS = xi;


          }

680
          Pres = Pres + ( PSW +
Phillip Lino Rall's avatar
Phillip Lino Rall committed
681
682
683
684
685
                 ( PSE - PSW ) * p_EW +
                 ( PNW - PSW ) * p_NS +
                 ( PNE - PSE - PNW + PSW ) * p_EW * p_NS) * (-1.0);
        }

686

Phillip Lino Rall's avatar
Phillip Lino Rall committed
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
    }
    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
702
703
704
705
706
707
708
709
710
711
712

  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
713

Phillip Lino Rall's avatar
Phillip Lino Rall committed
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
      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
737
738
739

    // Version: 0 x Flaechen + 1 x Kanten + 3 x Ecken
    // /////////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
    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 );
758
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
759

760

Phillip Lino Rall's avatar
Phillip Lino Rall committed
761
762
763
764
765
766
767
768
769
770
  if ( hex->transform_hex== NULL )
    return Pres;
  else
    return Pres + hex->transform_hex ( id_hex,eta,xi,phi );
}

D3vector Blockgrid::Give_coord_quadrangle ( int id, int i, int j ) const
{
  double eta, xi;
  D3vector PSW, PSE, PNW, PNE, PW, PE, PN, PS;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
771
  D3vector PTransFace, PWithoutTrans;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
772
773
774
  Quadrangle_el* quad;
  Edge_el* edge;

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

Phillip Lino Rall's avatar
Phillip Lino Rall committed
777
778
779
780
781
782
783
784
785
786

  eta = ( double ) i/ ( double ) Give_Nx_quadrangle ( id );
  xi = ( double ) j/ ( double ) Give_Ny_quadrangle ( id );

  // @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
787
788


Phillip Lino Rall's avatar
Phillip Lino Rall committed
789
790
791
792
793
794
795
796
797
798
799
800
801
802
  /*
  // 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
803
804
805
806
807
808
809
810
811
812
  //Phillip version with deformed faces

  if (quad->transform != NULL)
  {
      PTransFace = quad->transform ( eta, xi, quad->shiftPointer(ug->Get_pointer_global_data()));
      PTransFace =     PSW + (PSE-PSW) * eta + (PNW-PSW)*xi + (PNE-PSE-PNW+PSW)*xi*eta + PTransFace;
      return PTransFace;
  }

  //Christoph version with deformed edges
Phillip Lino Rall's avatar
Phillip Lino Rall committed
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
  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
840

Christoph Pflaum's avatar
Christoph Pflaum committed
841
        if(bg_coord != NULL) if(bg_coord->blockgrid_edge_coordinates_calculated)
842
        {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
843
844

            return bg_coord->blockgrid_edge_coordinates.at(id).at(i) ;
845
        }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
846

847

848

Phillip Lino Rall's avatar
Phillip Lino Rall committed
849
    Quadrangle_el* quad;
850
    Hexahedron_el* hex;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
851
    D3vector Psi;
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901

    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;

            }
        }
    }
    ug->Set_edge_to_quad_id(id,quadId);
    ug->Set_edge_to_quad_dir(id,(int)dirForQuad);
    }
    else
    {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
902

903
904
905
906
907
908
909
910
911
912
913
        quadId = ug->Give_edge_to_quad_id(id);
        dirForQuad = (dir3D)ug->Give_edge_to_quad_dir(id);
        quad = ug->Give_quadrangle(quadId);
    }

    int Nx = Give_Nx_quadrangle(dirForQuad);
    int Ny = Give_Ny_quadrangle(dirForQuad);


    if (id == quad->Give_id_edge(Wdir2D)) //Wdir2D
    {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
914

915
        Psi = Give_coord_quadrangle(quadId,0,i);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
916

917
918
919
920
921
    }
    if (id == quad->Give_id_edge(Edir2D)) //Edir2D
    {

        Psi = Give_coord_quadrangle(quadId,Nx,i);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
922

923
924
925
    }
    if (id == quad->Give_id_edge(Sdir2D)) //Sdir2D
    {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
926

927
        Psi = Give_coord_quadrangle(quadId,i,0);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
928

929
930
931
932
933
    }
    if (id == quad->Give_id_edge(Ndir2D)) //Ndir2D
    {


Phillip Lino Rall's avatar
Phillip Lino Rall committed
934
        Psi = Give_coord_quadrangle(quadId,i,Ny);
935

Phillip Lino Rall's avatar
Phillip Lino Rall committed
936
    }
937
938
939
940



    return Psi;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
941
942


943
}
Phillip Lino Rall's avatar
Phillip Lino Rall committed
944
     //Christoph version, if quadrangles are NOT defined.
Phillip Lino Rall's avatar
Phillip Lino Rall committed
945
  double eta;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
946
  D3vector PL, PR;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
947
948
949
950
951
952
  Edge_el* edge;

  edge = ug->Give_edge ( id );

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

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

Phillip Lino Rall's avatar
Phillip Lino Rall committed
955
956
957
958
959
960
961
962
963
964
  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();
  */

965
 // cout << "psi old " ; (Psi + PL + ( PR-PL ) * eta).Print();cout << endl;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
966
967
968
969
970
971
972
973
974
975
976
977
978
  return Psi + PL + ( PR-PL ) * eta;
}

D3vector Blockgrid::Give_coord_point ( int id_point ) const
{
  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
979

Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
  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
1013

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1014
1015
1016
1017
  // 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
1018

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1019
1020
1021
1022
1023
1024
/*  cout << "total number of points of blockgrid: " << num_points << endl;
  getchar();*/
  return num_points;
}


Phillip Lino Rall's avatar
Phillip Lino Rall committed
1025
1026
1027
1028
1029
1030


void Blockgrid_coordinates::init_blockgrid_coordinates()
{
    blockgrid_edge_coordinates_calculated = false;
    blockgrid_hexa_coordinates_calculated = false;
1031
1032

    blockgrid_hexa_boundaries_calculated = false;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
    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);
            }
    }

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

    blockgrid_edge_coordinates_calculated = true;
    blockgrid_hexa_coordinates_calculated = true;
}

void Blockgrid_coordinates::init_blockgrid_coordinates_boundary()
{

1077
    blockgrid_hexa_boundary.clear();
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1078
1079
1080
1081
1082
1083
1084
1085
1086
    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);
1087
1088
        //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
1089
1090
1091
                {

                    //if ((i > 0 || i < Nx-1) ^ (j > 0 || j < Ny-1) ^ (k > 0 || k < Nz-1))
1092
                    //remove true here?
1093
                    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
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
                    {
                        //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;
1108
1109
                            //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
1110
1111
1112
                                {
                                    // not sure which if loop is correct:
                                    //if ((iInner > 0 || iInner < NxInner-1) ^ (jInner > 0 || jInner < NyInner-1) ^ (kInner > 0 || kInner < NzInner-1))
1113
                                    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
1114
                                    {
1115
                                        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
1116
1117
1118
1119
1120
1121
1122
1123
                                        {

                                            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);
1124
1125


Phillip Lino Rall's avatar
Phillip Lino Rall committed
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
                                        }

                                    }
                                }

                            }


                            }


                        }

                    }
                 }
    blockgrid_hexa_boundaries_calculated = true;
    }

1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
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
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
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
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
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
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418

void Blockgrid_coordinates::delete_blockgrid_coordinates()
{

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

}
1419