blockgrid.cc 33.5 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 ) {
104
   cout << "Nx " << Nx <<  "Ny " << Ny <<  "Nz " << Nz <<  "Nr " << Nr << endl;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
105
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
106
107
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  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;
}

124
Blockgrid::Blockgrid(Unstructured_grid *ug_, int Nx, int Ny, int Nz, int Nr, int Nr2){
125
    cout << "Nx " << Nx <<  "Ny " << Ny <<  "Nz " << Nz <<  "Nr " << Nr << "Nr2 " << Nr2 << endl;
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
   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
146
Blockgrid::Blockgrid ( Unstructured_grid *ug_, int Nx, int Ny, std::vector<int>& Nz ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
147
  id_of_grid = id_count_grid; ++id_count_grid;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
148
149
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
150
151
152
153
154
155
156
157
158
  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
159

Phillip Lino Rall's avatar
Phillip Lino Rall committed
160
161
162
163
164
165
166
167
168
169
170
171
  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
172
173
      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
174
175
176
177
178
179
180
181
182
183
184
        << 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
185
186
187
188
189



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
190
191
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
  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
213
214
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
215

Phillip Lino Rall's avatar
Phillip Lino Rall committed
216
217
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
218
219
220
221
222
223
224
225
226
  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
227

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

Phillip Lino Rall's avatar
Phillip Lino Rall committed
232
233
234
235
236
237
238
239
240
//   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
241
242
      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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
        << 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
257

Phillip Lino Rall's avatar
Phillip Lino Rall committed
258
259
    phase_shift = NULL;
  bg_coord = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
  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;
295
296
  if (bg_coord != NULL)
    delete bg_coord;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
}

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
370
371
372
373
374
375
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};
376

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

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

Phillip Lino Rall's avatar
Phillip Lino Rall committed
490

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



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

516

517

518
519


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

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


533
    if(ug->Give_transform_From_Quadrangle())
Phillip Lino Rall's avatar
Phillip Lino Rall committed
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
    {
        //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
        // /////////////////////////////////////////////////////////
564
        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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579

        //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
        // /////////////////////////////////////////////////////////
580
        Pres = Pres +
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
622
               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;
623

Phillip Lino Rall's avatar
Phillip Lino Rall committed
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
          }
          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;
652

Phillip Lino Rall's avatar
Phillip Lino Rall committed
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
          }
          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;


          }

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

687

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

  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
714

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

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

761

Phillip Lino Rall's avatar
Phillip Lino Rall committed
762
763
764
765
766
767
768
769
770
771
  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
772
  D3vector PTransFace, PWithoutTrans;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
773
774
775
  Quadrangle_el* quad;
  Edge_el* edge;

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

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

  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
788
789


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

        if (bg_coord != NULL && bg_coord->blockgrid_edge_coordinates_calculated)
843
        {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
844
845

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

848

849

Phillip Lino Rall's avatar
Phillip Lino Rall committed
850
    Quadrangle_el* quad;
851
    Hexahedron_el* hex;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
852
    D3vector Psi;
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
902

    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
903

904
905
906
907
908
909
910
911
912
913
914
        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
915

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

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

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

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

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

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


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

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



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


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

  edge = ug->Give_edge ( id );

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

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

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

966
 // cout << "psi old " ; (Psi + PL + ( PR-PL ) * eta).Print();cout << endl;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
967
968
969
970
971
972
973
974
975
976
977
978
979
  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
980

Phillip Lino Rall's avatar
Phillip Lino Rall committed
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
  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 );
For faster browsing, not all history is shown. View entire blame