cellvar.h 19.6 KB
Newer Older
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**********************************************************************************
 * Copyright 2010 Christoph Pflaum 
 * 		Department Informatik Lehrstuhl 10 - Systemsimulation
 *		Friedrich-Alexander Universität Erlangen-Nürnberg
 * 
 * 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.
 **********************************************************************************/
 
// ------------------------------------------------------------
//
// cellvar.h
//
// ------------------------------------------------------------

#ifndef CE_VA_H
#define CE_VA_H

#ifdef _OPENMP
#include <omp.h>
#endif
#include "../grid/compose_grid.h"

//////////////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
34
35
36
37
38
39
// 1. Marker: Restriction to subgrid
// 2. interpolation: variable -> cell variable
// 3. cell variable
// 3.1. definition
// 3.2. assign operators
// 3.3. product_cell, L_infty_cell
Phillip Lino Rall's avatar
Phillip Lino Rall committed
40
41
//////////////////////////////////////////////////////////////

Phillip Lino Rall's avatar
Phillip Lino Rall committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

///////////////////////////
// 1. Restriction to subgrid
///////////////////////////



// 2. interpolation: variable -> cell variable
//////////////////////////////////////////////////////

/*
template <class DTyp>
class Expr_interpolant_point_to_cell : public Expr<Expr_interpolant_point_to_cell< DTyp > > {
 public:
  Expr_interpolant_point_to_cell(Variable<DTyp>& var) { 
    v = &var; 
    data_hexahedra = var.Give_pointer_data_hexahedra();
  }

  typedef double Result;

  template <elementTyp TYP_EL>
  void Update(int id_hex) const;

  inline DTyp Give_cell_hexahedra(params_in_cell)         const;
  inline DTyp Give_matrix_hexahedra(params_in_loc_matrix) const;

 private:
  Variable<DTyp>* v;
  DTyp** data_hexahedra;        // num_hexahedra
};


template <class DTyp>
Expr_interpolant_point_to_cell<DTyp> Cell_interpolation(Variable<DTyp>& var) {
  return Expr_interpolant_point_to_cell<DTyp>(var);
}

template <class DTyp>
DTyp Expr_interpolant_point_to_cell<DTyp>::Give_cell_hexahedra(params_in_cell) const {
  return 0.125 * (data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i,  j,  k)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i+1,j,  k)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i,  j+1,k)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i+1,j+1,k)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i,  j,  k+1)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i+1,j,  k+1)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i,  j+1,k+1)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i+1,j+1,k+1)]);
		  
}

template <class DTyp>
DTyp Expr_interpolant_point_to_cell<DTyp>::Give_matrix_hexahedra(params_in_loc_matrix) const {
  return 0.125 * (data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i,  j,  k)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i+1,j,  k)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i,  j+1,k)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i+1,j+1,k)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i,  j,  k+1)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i+1,j,  k+1)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i,  j+1,k+1)] +
		  data_hexahedra[id_hex][Ind_loc_variable_hexahedra(i+1,j+1,k+1)]);
		  
}

*/
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
108
109
110
111
112
113
114
115
116
117

template <class A>
class Expr_interpolant_point_to_cell : public Expr<Expr_interpolant_point_to_cell< A > >  {
 private:
  const A& a_;

 public:
  Expr_interpolant_point_to_cell(const Expr<A>& a) : a_(a) {}
    
  typedef typename A::Result Result;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
118
    
Phillip Lino Rall's avatar
Phillip Lino Rall committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  Result Give_cell_hexahedra(params_in_cell) const {
    return 0.125 * (a_.template Give_data<hexahedronEl>(id_hex,i  ,j  ,k  ,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i+1,j  ,k  ,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i  ,j+1,k  ,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i+1,j+1,k  ,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i  ,j  ,k+1,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i+1,j  ,k+1,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i  ,j+1,k+1,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i+1,j+1,k+1,Nx,Ny));
  }
  
  Result Give_matrix_hexahedra(params_in_loc_matrix) const {
    return 0.125 * (a_.template Give_data<hexahedronEl>(id_hex,i  ,j  ,k  ,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i+1,j  ,k  ,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i  ,j+1,k  ,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i+1,j+1,k  ,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i  ,j  ,k+1,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i+1,j  ,k+1,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i  ,j+1,k+1,Nx,Ny) +
		    a_.template Give_data<hexahedronEl>(id_hex,i+1,j+1,k+1,Nx,Ny));
  }

  template <elementTyp TYP_EL>
  void Update(int id) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
143
    a_.Update<TYP_EL>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
144
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
145
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
146
147
148
149
150
151
152
153
154
155
};

template <class A>
inline Expr_interpolant_point_to_cell<A> Cell_interpolation(const Expr<A>& a) {
  return Expr_interpolant_point_to_cell<A>(a);
}



//////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
156
// 3. cell variable
Phillip Lino Rall's avatar
Phillip Lino Rall committed
157
//////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
158
// 3.1. definition
Phillip Lino Rall's avatar
Phillip Lino Rall committed
159
160
161
162
163
164
165
166
167
168
169
//////////////////////////////////////////////////////////////

template <class DTyp>
class Cell_variable : public Expr<Cell_variable< DTyp > > {

 public:

  typedef DTyp Result;


  Cell_variable(Blockgrid& blockgrid_);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
170
171
  Blockgrid* getBlockgrid() { return blockgrid; }
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
172
173
174
175
176
  ~Cell_variable();

  template <elementTyp TYP_EL>
  void Update(int id) const {}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
177
178
  const Blockgrid* Give_blockgrid() const { return blockgrid; };
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
179
180
181
182
183
184
185
186
187
  void Print_VTK(std::ostream& Datei, double (*convert)(DTyp x), double stretch_z = 1., std::string title = "myData", Unstructured_grid_Marker * marker = NULL);
  void Print_VTK(std::ostream& Datei, double stretch_z = 1., std::string title = "myData",  Unstructured_grid_Marker * marker = NULL);

  void QPrint_VTK(QString DateiName, double (*convert)(DTyp x), double stretch_z = 1., QString title = "myData", Unstructured_grid_Marker * marker = NULL);
  void QPrint_VTK(QString DateiName, complex<double> (*convert)(DTyp x), double stretch_z = 1., QString title = "myData", Unstructured_grid_Marker * marker = NULL);
  void QPrint_VTK(QString DateiName, double stretch_z = 1., QString title = "myData",  Unstructured_grid_Marker * marker = NULL);

  inline DTyp Give_cell_hexahedra(params_in_cell)         const  { return data_cell[id_hex][ind_cell]; }
  inline DTyp Give_matrix_hexahedra(params_in_loc_matrix) const  { return data_cell[id_hex][ind_cell]; }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
188

Phillip Lino Rall's avatar
Phillip Lino Rall committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  template <class A>
  void operator=(const Expr<A>& a);
  void operator=(DTyp x);
  void operator=(const Cell_variable<DTyp>& varRight);

  void operator=(const DTyp_Restriction<DTyp>& a);

  template <class A>
  void operator=(const Expr_Restriction<A>& a);

  // copy data from hex_a to hex_b (=)
  void Copy_invert_z(int hex_b,  Cell_variable<DTyp>& a, int hex_a);
  void Copy_invert_z(int hex_b_start, Cell_variable<DTyp>& a, int hex_a_start, int numBlocks);
  // copy and add data from hex_a to hex_b (+=)
  void Add_invert_z(int hex_b,  Cell_variable<DTyp>& a, int hex_a);
  void Add_invert_z(int hex_b_start, Cell_variable<DTyp>& a, int hex_a_start, int numBlocks);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
205
206
 private:

Phillip Lino Rall's avatar
Phillip Lino Rall committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
  Blockgrid*        blockgrid;
  Unstructured_grid*       ug;

  // own data
  DTyp** data_cell;        // num_hexahedra

  // for parallel
  int my_rank;
  MPI_Comm comm;
};

template <class A, class B>
_TypeOf2_(A,B) product_cell(Expr<A>& a, Expr<B>& b, Marker& marker);

template <class A, class B>
_TypeOf2_(A,B) product_cell(Expr<A>& a, Expr<B>& b);


template <class A>
double L_infty_cell(const Expr<A>& a, Marker& marker);

template <class A>
double L_infty_cell(const Expr<A>& a);


//////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
233
// 3.3. product_cell, L_infty_cell
Phillip Lino Rall's avatar
Phillip Lino Rall committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//////////////////////////////////////////////////////////////


template <class DTyp>
Cell_variable<DTyp>::Cell_variable(Blockgrid& blockgrid_) {
  int Nx, Ny, Nz, N_total;

  blockgrid = &blockgrid_;
  ug = blockgrid->Give_unstructured_grid();

  // for parallel
  my_rank = ug->Give_my_rank();
  comm    = ug->Give_MPI_comm();

  // hexahedra
Phillip Lino Rall's avatar
Phillip Lino Rall committed
249
250
  data_cell = new DTyp*[ug->Give_number_hexahedra()];
  for(int id=0;id<ug->Give_number_hexahedra();++id) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
251

Phillip Lino Rall's avatar
Phillip Lino Rall committed
252
    if(ug->Give_hexahedron(id)->my_object(my_rank)) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
253

Phillip Lino Rall's avatar
Phillip Lino Rall committed
254
255
256
      Nx = blockgrid->Give_Nx_hexahedron(id);
      Ny = blockgrid->Give_Ny_hexahedron(id);
      Nz = blockgrid->Give_Nz_hexahedron(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
257

Phillip Lino Rall's avatar
Phillip Lino Rall committed
258
      N_total = Nx * Ny * Nz;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
259

Phillip Lino Rall's avatar
Phillip Lino Rall committed
260
      data_cell[id] = new DTyp[N_total];
Phillip Lino Rall's avatar
Phillip Lino Rall committed
261
262

#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
Phillip Lino Rall's avatar
Phillip Lino Rall committed
263
264
265
266
267
      for(int i=0;i<N_total;++i)
        data_cell[id][i] = (DTyp)0;
    }
    else data_cell[id] = NULL;
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
268
269
270
271
}

template <class DTyp>
Cell_variable<DTyp>::~Cell_variable() {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
272
273
274
  if(data_cell != NULL){
      for(int i=0; i<ug->Give_number_hexahedra(); ++i)
          if(data_cell[i] != NULL)
Phillip Lino Rall's avatar
Phillip Lino Rall committed
275
276
277
278
279
280
281
282
283
284
285
              delete [] data_cell[i];
      delete [] data_cell;
  }
  data_cell = NULL;
}

template <class DTyp>
void Cell_variable<DTyp>::operator=(DTyp x) {
  int Nx, Ny, Nz, N_total;

  // hexahedra
Phillip Lino Rall's avatar
Phillip Lino Rall committed
286
  for(int id=0;id<ug->Give_number_hexahedra();++id) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

    if(ug->Give_hexahedron(id)->my_object(my_rank)) {

      Nx = blockgrid->Give_Nx_hexahedron(id);
      Ny = blockgrid->Give_Ny_hexahedron(id);
      Nz = blockgrid->Give_Nz_hexahedron(id);
      N_total = Nx * Ny * Nz;

#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
      for(int i=0;i<N_total;++i)
        data_cell[id][i] = x;
    }
  }
}

template <class DTyp>
void Cell_variable<DTyp>::operator=(const DTyp_Restriction<DTyp>& a) {
  int Nx, Ny, Nz, N_total;
  DTyp   x      = a.Give_x();

  // hexahedra
Phillip Lino Rall's avatar
Phillip Lino Rall committed
308
  for(int id=0;id<ug->Give_number_hexahedra();++id) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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

    if(ug->Give_hexahedron(id)->my_object(my_rank) &&
       a.template Give_marker<hexahedronEl>(id)==yes_mark) {

      Nx = blockgrid->Give_Nx_hexahedron(id);
      Ny = blockgrid->Give_Ny_hexahedron(id);
      Nz = blockgrid->Give_Nz_hexahedron(id);
      N_total = Nx * Ny * Nz;

#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
      for(int i=0;i<N_total;++i)
        data_cell[id][i] = x;
    }
  }
}

template <class DTyp>
void Cell_variable<DTyp>::operator=(const Cell_variable<DTyp>& varRight) {
  int Nx, Ny, Nz;

  if(blockgrid->getId() != varRight.blockgrid->getId()) {
     assert(ug->isComposeGrid());
     ComposeUg* compUg = static_cast<ComposeUg*>(ug);

     int thisIdGrid = varRight.blockgrid->getId();
     int startHex = compUg->getStartHex(thisIdGrid);
     int endHex   = compUg->getEndHex(thisIdGrid);
  
     for(int id=startHex;id<endHex;++id) {
         int idRight = id - startHex;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
339
         varRight.Update<hexahedronEl>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362

         if(ug->Give_hexahedron(id)->my_object(my_rank)) {
            Nx = blockgrid->Give_Nx_hexahedron(id);
            Ny = blockgrid->Give_Ny_hexahedron(id);
            Nz = blockgrid->Give_Nz_hexahedron(id);

            int i,j,k;

// pragma laut gcc4.2 hier nicht erlaubt
#pragma omp parallel for private(i,j)  num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
            for(k=0;k<Nz;++k) {
                for(j=0;j<Ny;++j)
                    for(i=0;i<Nx;++i){
                        data_cell[id][Ind_loc_matrix_hexahedra(i,j,k)] =
                           varRight.Give_cell_hexahedra(idRight,Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny);
		    }
	    }
	 }
     }
     return;
  }
  
  // hexahedra
Phillip Lino Rall's avatar
Phillip Lino Rall committed
363
364
  for(int id=0;id<ug->Give_number_hexahedra();++id) {
    varRight.Update<hexahedronEl>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390

    if(ug->Give_hexahedron(id)->my_object(my_rank)) {

      Nx = blockgrid->Give_Nx_hexahedron(id);
      Ny = blockgrid->Give_Ny_hexahedron(id);
      Nz = blockgrid->Give_Nz_hexahedron(id);

      int i,j,k;

// pragma laut gcc4.2 hier nicht erlaubt
#pragma omp parallel for private(i,j) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
      for(k=0;k<Nz;++k) {
        for(j=0;j<Ny;++j)
          for(i=0;i<Nx;++i){
            data_cell[id][Ind_loc_matrix_hexahedra(i,j,k)] =
              varRight.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny);
	  }
      }
    }
  }
}


template <class DTyp>
template <class A>
void Cell_variable<DTyp>::operator=(const Expr<A>& a) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
391
  int Nx, Ny, Nz;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
392

Phillip Lino Rall's avatar
Phillip Lino Rall committed
393
  const A& ao ( a );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
394

Phillip Lino Rall's avatar
Phillip Lino Rall committed
395
396
397
  // hexahedra
  for(int id=0;id<ug->Give_number_hexahedra();++id) {
    ao.Update<hexahedronEl>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
398

Phillip Lino Rall's avatar
Phillip Lino Rall committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
    if(ug->Give_hexahedron(id)->my_object(my_rank)) {

      Nx = blockgrid->Give_Nx_hexahedron(id);
      Ny = blockgrid->Give_Ny_hexahedron(id);
      Nz = blockgrid->Give_Nz_hexahedron(id);

      int i,j,k;

// pragma laut gcc4.2 hier nicht erlaubt
#pragma omp parallel for private(i,j) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
      for(k=0;k<Nz;++k) {
        for(j=0;j<Ny;++j)
          for(i=0;i<Nx;++i){
            data_cell[id][Ind_loc_matrix_hexahedra(i,j,k)] =
              ao.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
414
415
	  }
      }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
416
417
    }
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
418
419
420
421
422
423
424
425
426
427
}

template <class DTyp>
template <class A>
void Cell_variable<DTyp>::operator=(const Expr_Restriction<A>& a)  {
  int Nx, Ny, Nz;

  //  const A& ao ( a );

  // hexahedra
Phillip Lino Rall's avatar
Phillip Lino Rall committed
428
  for(int id=0;id<ug->Give_number_hexahedra();++id) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
    a.template Update<hexahedronEl>(id);

    if(ug->Give_hexahedron(id)->my_object(my_rank) &&
       a.template Give_marker<hexahedronEl>(id)==yes_mark) {
      
      Nx = blockgrid->Give_Nx_hexahedron(id);
      Ny = blockgrid->Give_Ny_hexahedron(id);
      Nz = blockgrid->Give_Nz_hexahedron(id);

      int i,j,k;
// pragma laut gcc4.2 hier nicht erlaubt
#pragma omp parallel for private(i,j) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
      for(k=0;k<Nz;++k) {
        for(j=0;j<Ny;++j)
          for(i=0;i<Nx;++i){
            data_cell[id][Ind_loc_matrix_hexahedra(i,j,k)] =
              a.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny);
	  }
      }
    }
  }
}

//////////////////////////////////////////
// 3.3. product_cell, L_infty_cell
//////////////////////////////////////////////////////////////

template <class A, class B>
  _TypeOf2_(A,B) product_cell(Expr<A>& a, Expr<B>& b) {
  const A& ao ( a );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
459
460

  return product_cell(a,b,ao.Give_blockgrid()->Give_unstructured_grid()->Give_all_points());
Phillip Lino Rall's avatar
Phillip Lino Rall committed
461
462
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
463
464
template <class A>
double  L_infty_cell(Expr<A>& a) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
465
466
  const A& ao ( a );

Phillip Lino Rall's avatar
Phillip Lino Rall committed
467
  return L_infty_cell(a,ao.Give_blockgrid()->Give_unstructured_grid()->Give_all_points());
Phillip Lino Rall's avatar
Phillip Lino Rall committed
468
469
470
471
472
}



template <class A, class B>
Phillip Lino Rall's avatar
Phillip Lino Rall committed
473
_TypeOf2_(A,B) product_cell(Expr<A>& ao, Expr<B>& bo, Marker& marker) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
474
  int Nx, Ny, Nz;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
475
476

  typedef _TypeOf2_(A,B) DTyp;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
477
478
479
480
481
482
483
484
  const A& a ( ao );
  const B& b ( bo );

  DTyp sum;
  DTyp sum_total;

  sum = (DTyp)0;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
485
  if(developer_version)
Phillip Lino Rall's avatar
Phillip Lino Rall committed
486
487
488
489
490
491
492
493
494
495
496
497
498
499
     if(a.Give_blockgrid() != b.Give_blockgrid()) cout << " error2 in product_cell!" << endl;

  Unstructured_grid* ug = a.Give_blockgrid()->Give_unstructured_grid();
  int my_rank   = ug->Give_my_rank();
  MPI_Comm comm = ug->Give_MPI_comm();

  // hexahedra
  for(int id=0;id<ug->Give_number_hexahedra();++id) {
     if(ug->Give_hexahedron(id)->my_object(my_rank)   &&
        marker.template Give_marker<hexahedronEl>(id)==yes_mark) {
      Nx = a.Give_blockgrid()->Give_Nx_hexahedron(id);
      Ny = a.Give_blockgrid()->Give_Ny_hexahedron(id);
      Nz = a.Give_blockgrid()->Give_Nz_hexahedron(id);

Phillip Lino Rall's avatar
Phillip Lino Rall committed
500
501
      /// todo hier sollte noch ein reduction rein
      //#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) private(i,j)  if(UGBlocks::useOpenMP)
Phillip Lino Rall's avatar
Phillip Lino Rall committed
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
      for(int k=0;k<Nz;++k) {
        for(int j=0;j<Ny;++j)
          for(int i=0;i<Nx;++i)
	    sum+= a.Give_cell_hexahedra(id,
					Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny)
	      * MyConj<DTyp>::Give(b.Give_cell_hexahedra(id,
							 Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny));
      }
     }
  }

  sum_total = Make_MPI_All_Sum<DTyp>::Do(sum,comm);

  return sum_total;
}




template <class A>
double L_infty_cell(const Expr<A>& ao, Marker& marker) {
  int Nx, Ny, Nz;

  double infty;
  double infty_total;

  const A& a ( ao );

  infty = 0.0;

  Unstructured_grid* ug = a.Give_blockgrid()->Give_unstructured_grid();
  int my_rank   = ug->Give_my_rank();
  MPI_Comm comm = ug->Give_MPI_comm();

Phillip Lino Rall's avatar
Phillip Lino Rall committed
536
537
538
539
540
541
  for(int id=0; id<ug->Give_number_hexahedra(); ++id) {
    if(ug->Give_hexahedron(id)->my_object(my_rank) &&
        marker.template Give_marker<hexahedronEl>(id)==yes_mark) {
      Nx = a.Give_blockgrid()->Give_Nx_hexahedron(id);
      Ny = a.Give_blockgrid()->Give_Ny_hexahedron(id);
      Nz = a.Give_blockgrid()->Give_Nz_hexahedron(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
542

Phillip Lino Rall's avatar
Phillip Lino Rall committed
543
544
545
546
547
548
      /// todo hier sollte noch ein reduction rein 
      //#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) private(i,j)  if(UGBlocks::useOpenMP)
      for(int k=0;k<Nz;++k) {
        for(int j=0;j<Ny;++j)
          for(int i=0;i<Nx;++i)
	    if(infty < ABS(a.Give_cell_hexahedra(id,
Phillip Lino Rall's avatar
Phillip Lino Rall committed
549
						 Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny)))
Phillip Lino Rall's avatar
Phillip Lino Rall committed
550
	      infty = ABS(a.Give_cell_hexahedra(id,
Phillip Lino Rall's avatar
Phillip Lino Rall committed
551
552
						Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny));
      }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
553
    }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
554
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
555

Phillip Lino Rall's avatar
Phillip Lino Rall committed
556
557
558
559
560
561
562
563
564
565
566
567
  MPI_Allreduce(&infty,&infty_total,1,MPI_DOUBLE,MPI_MAX,comm);

  return infty_total;
}

template <class A>
double Maximum_cell(const Expr<A>& ao)  {
  int Nx, Ny, Nz;

  double maximum;
  double maximum_total;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
568
  maximum = -1.0e50;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
569
570
571
572
573
574
575
576
577
  
  const A& a ( ao );


  Unstructured_grid* ug = a.Give_blockgrid()->Give_unstructured_grid();
  int my_rank   = ug->Give_my_rank();
  MPI_Comm comm = ug->Give_MPI_comm();

  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
  
  for(int id=0; id<ug->Give_number_hexahedra(); ++id) {
    if(ug->Give_hexahedron(id)->my_object(my_rank)) {
      Nx = a.Give_blockgrid()->Give_Nx_hexahedron(id);
      Ny = a.Give_blockgrid()->Give_Ny_hexahedron(id);
      Nz = a.Give_blockgrid()->Give_Nz_hexahedron(id);

      /// todo hier sollte noch ein reduction rein 
      //#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) private(i,j)  if(UGBlocks::useOpenMP)
      for(int k=0;k<Nz;++k) {
        for(int j=0;j<Ny;++j)
          for(int i=0;i<Nx;++i) {
	    if(maximum < ABS(a.Give_cell_hexahedra(id,
						 Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny)))
	      maximum = ABS(a.Give_cell_hexahedra(id,
						Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny));
Phillip Lino Rall's avatar
Phillip Lino Rall committed
594
      }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
595
596
    }
   }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
597
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
598

Phillip Lino Rall's avatar
Phillip Lino Rall committed
599
600
601
602
603
604
605
606
607
608
609
610
611
  MPI_Allreduce(&maximum,&maximum_total,1,MPI_DOUBLE,MPI_MAX,comm);

  return maximum_total;
}


template <class A>
double Minimum_cell(const Expr<A>& ao) {
  int Nx, Ny, Nz;

  double minimum;
  double minimum_total;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
612
  minimum = 1.0e50;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
  
  const A& a ( ao );


  Unstructured_grid* ug = a.Give_blockgrid()->Give_unstructured_grid();
  int my_rank   = ug->Give_my_rank();
  MPI_Comm comm = ug->Give_MPI_comm();

  
  
  for(int id=0; id<ug->Give_number_hexahedra(); ++id) {
    if(ug->Give_hexahedron(id)->my_object(my_rank)) {
      Nx = a.Give_blockgrid()->Give_Nx_hexahedron(id);
      Ny = a.Give_blockgrid()->Give_Ny_hexahedron(id);
      Nz = a.Give_blockgrid()->Give_Nz_hexahedron(id);

      /// todo hier sollte noch ein reduction rein 
      //#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) private(i,j)  if(UGBlocks::useOpenMP)
      for(int k=0;k<Nz;++k) {
        for(int j=0;j<Ny;++j)
          for(int i=0;i<Nx;++i) {
	    if(minimum > ABS(a.Give_cell_hexahedra(id,
						 Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny)))
	      minimum = ABS(a.Give_cell_hexahedra(id,
						Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny));
      }
    }
   }
  }

  MPI_Allreduce(&minimum,&minimum_total,1,MPI_DOUBLE,MPI_MAX,comm);

  return minimum_total;
}
Phillip Lino Rall's avatar
Phillip Lino Rall committed
647

Phillip Lino Rall's avatar
Phillip Lino Rall committed
648
649
650
651



#endif // CE_VA_H