cellvar.h 29.1 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
/**********************************************************************************
 * 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
33

Phillip Lino Rall's avatar
Phillip Lino Rall committed
34
//////////////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
35
36
37
38
39
// 1. interpolation: variable -> cell variable
// 2. cell variable
// 2.1. definition
// 2.2. product_cell, L_infty_cell
// 3. Implementierungen
Phillip Lino Rall's avatar
Phillip Lino Rall committed
40
41
//////////////////////////////////////////////////////////////

Phillip Lino Rall's avatar
Phillip Lino Rall committed
42
43
44
//////////////////////////////////////////////////////////////
// 1. interpolation: variable -> cell variable
//////////////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
45
46
47
48
49
50
51
52
53
54

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
55
56
57
                    
  bool totalCalcNotPossible()    const { return true; }	
                    
Phillip Lino Rall's avatar
Phillip Lino Rall committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  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
82
    a_.template Update<TYP_EL>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
83
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
84
85
                  
  double Give_fromTotal(int i) const  { assert(false); return 0.0; }	
Phillip Lino Rall's avatar
Phillip Lino Rall committed
86
87
};

88
89
90
91
92
/** \addtogroup InterpolationOperators **/
/* @{ */  
/**
 * interpolates from point data to cell data
 **/
Phillip Lino Rall's avatar
Phillip Lino Rall committed
93
template <class A>
94
95
96
97
98
99
100
inline Expr_interpolant_point_to_cell<A> Cell_interpolation(const Expr<A>& ao) {
	const A& a ( ao );  
	Unstructured_grid* ug = a.Give_blockgrid()->Give_unstructured_grid();
  	for(int id = 0;id < ug->Give_number_hexahedra();++id ) {
		a.template Update<hexahedronEl> ( id );
	}
  return Expr_interpolant_point_to_cell<A>(ao);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
101
102
}

103
/* @} */
Phillip Lino Rall's avatar
Phillip Lino Rall committed
104
105


106
107
108
109
110
111
112
113
114

/*
template <class DTyp>
inline Expr_interpolant_point_to_cell<Variable<DTyp> > Cell_interpolation(Variable<DTyp>& v) {
  v.UpdateHexahedra();
  return Expr_interpolant_point_to_cell<Variable<DTyp> >(v);
}
*/

Phillip Lino Rall's avatar
Phillip Lino Rall committed
115
//////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
116
// 2. cell variable
Phillip Lino Rall's avatar
Phillip Lino Rall committed
117
//////////////////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
118
// 2.1. definition
Phillip Lino Rall's avatar
Phillip Lino Rall committed
119
120
//////////////////////////////////////////////////////////////

Christoph Pflaum's avatar
Christoph Pflaum committed
121
122
123
template <class DTyp, class Vari>
class VariableVector;

124
125
126

/** \addtogroup ExpressionTemplates **/
/* @{ */ 
Phillip Lino Rall's avatar
Phillip Lino Rall committed
127
128
129
template <class DTyp>
class Cell_variable : public Expr<Cell_variable< DTyp > > {

Christoph Pflaum's avatar
Christoph Pflaum committed
130
131
132
  friend  VariableVector<DTyp, Cell_variable<DTyp> >;

public:
Phillip Lino Rall's avatar
Phillip Lino Rall committed
133
134
135
136
137

  typedef DTyp Result;


  Cell_variable(Blockgrid& blockgrid_);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
138
139
  Blockgrid* getBlockgrid() { return blockgrid; }   // WORK NOW  das sollte mal weg!!
		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
140
141
  ~Cell_variable();

Christoph Pflaum's avatar
Christoph Pflaum committed
142
143
 // template <elementTyp TYP_EL>
 // void Update(int id) const {}
Phillip Lino Rall's avatar
Phillip Lino Rall committed
144

Phillip Lino Rall's avatar
Phillip Lino Rall committed
145
146
147
  Blockgrid* Give_blockgrid()  const { return blockgrid; };
  Unstructured_grid* Give_Ug() const { return ug; };
    
Phillip Lino Rall's avatar
Phillip Lino Rall committed
148
149
150
151
152
153
154
155
156
  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
157
158
159
160
161
162
163
164
165
166
  inline DTyp Give_fromTotal(int i)                       const  { return dataTotal[i]; }

  /**
   * Man wird dies im Wesentlichen fuer die locale Steifigeitsmatrix von Helm anwenden
   * Dann wird das Volumen pro Zelle berechnet
   * @param localStiffnessMatrix das sollte locale Steifigeitsmatrix sein
   **/
  template <class LocalMat>
  void IntegrateOnCell(LocalMat& localStiffnessMatrix);
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
167
168
169
170
171
172
173
174
175
176
  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);

Phillip Lino Rall's avatar
Phillip Lino Rall committed
177
178
179
  
  static DTyp product(Cell_variable& a, Cell_variable& b) { return product_cell(a,b,a.Give_blockgrid()->Give_unstructured_grid()->Give_all_points()); }
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
180
181
182
183
184
185
  // 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
186
187
188
189
190
191
192
193
  
  
  bool totalCalcNotPossible() const { return false; }
  int  getTotalNumberData()   const { return totalNumberData; }
  
  bool containsNaN();  
  
private:
Christoph Pflaum's avatar
Christoph Pflaum committed
194
  inline DTyp* give_startTotal() const  { return dataTotal; }  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
195
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
196
197
198
199
  Blockgrid*        blockgrid;
  Unstructured_grid*       ug;

  // own data
Phillip Lino Rall's avatar
Phillip Lino Rall committed
200
201
202
203
  int totalNumberData;
  DTyp* dataTotal;
  
  int numberHex;  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
204
205
206
207
208
209
210
  DTyp** data_cell;        // num_hexahedra

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

211

Phillip Lino Rall's avatar
Phillip Lino Rall committed
212
213
214
215
216
//////////////////////////////////////////
// 2.2. product_cell, L_infty_cell
//////////////////////////////////////////////////////////////


Phillip Lino Rall's avatar
Phillip Lino Rall committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
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
231
232
233
234
235
template <class A>
double Maximum_cell(const Expr<A>& a);

template <class A>
double Minimum_cell(const Expr<A>& a);
236
/* @} */
Phillip Lino Rall's avatar
Phillip Lino Rall committed
237

Phillip Lino Rall's avatar
Phillip Lino Rall committed
238
//////////////////////////////////////////
Phillip Lino Rall's avatar
Phillip Lino Rall committed
239
// 3. Implementierungen
Phillip Lino Rall's avatar
Phillip Lino Rall committed
240
241
//////////////////////////////////////////////////////////////

Phillip Lino Rall's avatar
Phillip Lino Rall committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
template <class DTyp>
template <class LocalMat>
void Cell_variable<DTyp>::IntegrateOnCell(LocalMat& localStiffnessMatrix) {
     int Nx, Ny, Nz, N_total;
     
     assert(blockgrid == localStiffnessMatrix.Give_blockgrid());
     
     double** loc_m_hexahedra = localStiffnessMatrix.Give_loc_m_hexahedra();
     // hexahedra
     for(int id=0;id<numberHex;++id) {
         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] = 0.0;
		
            #pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
            for(int i=0;i<N_total;++i) {
	        for(int s=0;s<64;++s) {
                    data_cell[id][i] = data_cell[id][i] + loc_m_hexahedra[id][i*64+s];
		}
	    }
	 }
     }
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
272
273
274
275
276
277
278
279
280
281
282
283

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

Phillip Lino Rall's avatar
Phillip Lino Rall committed
284
285
286
  numberHex = ug->Give_number_hexahedra();
  
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
287
  // hexahedra
Phillip Lino Rall's avatar
Phillip Lino Rall committed
288
  data_cell = new DTyp*[numberHex];
Phillip Lino Rall's avatar
Phillip Lino Rall committed
289

Phillip Lino Rall's avatar
Phillip Lino Rall committed
290
291
292
293
294
295
  totalNumberData = 0;
  for(int id=0;id<numberHex;++id) {
      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);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
296

Phillip Lino Rall's avatar
Phillip Lino Rall committed
297
298
299
300
301
302
303
304
305
306
307
308
         N_total = Nx * Ny * Nz;
         totalNumberData = totalNumberData + N_total;
      }
  }
  dataTotal = new DTyp[totalNumberData];
    
  int indexNow = 0;  
  for(int id=0;id<numberHex;++id) {
      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);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
309

Phillip Lino Rall's avatar
Phillip Lino Rall committed
310
         data_cell[id] = &(dataTotal[indexNow]);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
311

Phillip Lino Rall's avatar
Phillip Lino Rall committed
312
313
314
         N_total = Nx * Ny * Nz;
         indexNow = indexNow + N_total;
      //data_cell[id] = new DTyp[N_total];
Phillip Lino Rall's avatar
Phillip Lino Rall committed
315

Phillip Lino Rall's avatar
Phillip Lino Rall committed
316
317
      }
      else data_cell[id] = NULL;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
318
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
319
320
321
322
323
  
#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
  for(int i=0;i<totalNumberData;++i)
      dataTotal[i] = (DTyp)0;  

Phillip Lino Rall's avatar
Phillip Lino Rall committed
324
325
326
327
}

template <class DTyp>
Cell_variable<DTyp>::~Cell_variable() {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
328
329
330
331
332
333
334
335
  if(dataTotal != NULL) {
     delete [] dataTotal;
     dataTotal = NULL;
  }
  if(data_cell != NULL) {
     /*
      for(int i=0; i<numberHex; ++i)
          if(data_cell[i] != NULL) 
Phillip Lino Rall's avatar
Phillip Lino Rall committed
336
              delete [] data_cell[i];
Phillip Lino Rall's avatar
Phillip Lino Rall committed
337
	  */
Phillip Lino Rall's avatar
Phillip Lino Rall committed
338
339
340
341
342
      delete [] data_cell;
  }
  data_cell = NULL;
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
343
344
345
346
347
348
349
350
351
352

template <class DTyp>
bool Cell_variable<DTyp>::containsNaN() {
    for(int i=0;i<totalNumberData;++i) {
        if(isNaN(dataTotal[i])) return true;
    }
    return false;
}


Phillip Lino Rall's avatar
Phillip Lino Rall committed
353
354
template <class DTyp>
void Cell_variable<DTyp>::operator=(DTyp x) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
355
356
357
358
359
360
#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
    for(int i=0;i<totalNumberData;++i) {
        dataTotal[i] = x;
    }
  
  /*
Phillip Lino Rall's avatar
Phillip Lino Rall committed
361
362
363
  int Nx, Ny, Nz, N_total;

  // hexahedra
Phillip Lino Rall's avatar
Phillip Lino Rall committed
364
  for(int id=0;id<numberHex;++id) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
365
366
367
368
369
370
371
372
373
374
375
376
377

    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;
    }
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
378
  */
Phillip Lino Rall's avatar
Phillip Lino Rall committed
379
380
381
382
383
384
385
386
}

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
387
  for(int id=0;id<numberHex;++id) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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

    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;
Christoph Pflaum's avatar
Christoph Pflaum committed
418
//         varRight.template Update<hexahedronEl>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441

         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
442
  for(int id=0;id<numberHex;++id) {
Christoph Pflaum's avatar
Christoph Pflaum committed
443
//    varRight.template Update<hexahedronEl>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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

    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
470
   const A& ao ( a );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
471

Phillip Lino Rall's avatar
Phillip Lino Rall committed
472
473
474
475
476
477
478
479
480
481
   if(ao.totalCalcNotPossible()==false) {
#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)     
      for(int i=0;i<totalNumberData;++i) {
          dataTotal[i] = ao.Give_fromTotal(i);
      }
   }
   else {  
      // hexahedra
      int Nx, Ny, Nz;  
      for(int id=0;id<numberHex;++id) {
Christoph Pflaum's avatar
Christoph Pflaum committed
482
          //ao.template Update<hexahedronEl>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
483

Phillip Lino Rall's avatar
Phillip Lino Rall committed
484
485
486
487
          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);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
488

Phillip Lino Rall's avatar
Phillip Lino Rall committed
489
490
491
492
493
494
495
496
#pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
             for(int k=0;k<Nz;++k) {
                 for(int j=0;j<Ny;++j)
                     for(int 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
497
498
	  }
      }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
499
   }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
500
501
502
503
504
505
506
507
508
509
}

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
510
  for(int id=0;id<numberHex;++id) {
Christoph Pflaum's avatar
Christoph Pflaum committed
511
    //a.template Update<hexahedronEl>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537

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

Phillip Lino Rall's avatar
Phillip Lino Rall committed
538
539
540
541
542
543
544
545
546
template<class DTyp>
struct ProductCalculator {
   template <class A, class B>
   static DTyp product_cell(Expr<A>& ao, Expr<B>& bo, Marker& marker);
   
   template <class A, class B>   
   static DTyp product_cell(Expr<A>& ao, Expr<B>& bo);   
};

Phillip Lino Rall's avatar
Phillip Lino Rall committed
547
548
549
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
550
551
  typedef _TypeOf2_(A, B) DTyp;
  return ProductCalculator<DTyp>::product_cell(a,b);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
552
553
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
554
555
template <class A, class B>
  _TypeOf2_(A,B) product_cell(Expr<A>& a, Expr<B>& b, Marker& marker) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
556
  const A& ao ( a );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
557
558
559
560
  typedef _TypeOf2_(A, B) DTyp;
  return ProductCalculator<DTyp>::product_cell(a,b,marker);
}  
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
561

Phillip Lino Rall's avatar
Phillip Lino Rall committed
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
//////////////////////////////////////////////////////////////////////////////


template<>
template <class A, class B>
double ProductCalculator<double>::product_cell(Expr<A>& ao, Expr<B>& bo) {
  int Nx, Ny, Nz;
  const A& a ( ao );
  const B& b ( bo );

  typedef double DTyp;
  
  double sum;
  double sum_total;

  sum = 0.0;

  if(developer_version) 
     if(a.Give_blockgrid() != b.Give_blockgrid()) std::cout << " error2 in product_cell!" << std::endl;

  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
585

Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
  
   if(a.totalCalcNotPossible() || b.totalCalcNotPossible()) {  
      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);

             double localSum = 0.0;
             #pragma omp parallel for reduction(+ : localSum) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)     
             for(int k=0;k<Nz;++k) {
                 for(int j=0;j<Ny;++j)
                     for(int i=0;i<Nx;++i)
	                 localSum  +=   a.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny)
	                              * b.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny);
	     }
     
             sum = sum + localSum;
	  }
      }
  }
  else {          // WORK NOW muss man nich richtig machen mit getTotalNumberData
      #pragma omp parallel for reduction(+ : sum) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)     
      for(int i=0;i<a.getTotalNumberData();++i) {
	  sum  = sum + a.Give_fromTotal(i) * b.Give_fromTotal(i); 
      }
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
613

Phillip Lino Rall's avatar
Phillip Lino Rall committed
614
  sum_total = Make_MPI_All_Sum<DTyp>::Do(sum,comm);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
615

Phillip Lino Rall's avatar
Phillip Lino Rall committed
616
617
618
619
  return sum_total;
}

template<>
Phillip Lino Rall's avatar
Phillip Lino Rall committed
620
template <class A, class B>
Phillip Lino Rall's avatar
Phillip Lino Rall committed
621
double ProductCalculator<double>::product_cell(Expr<A>& ao, Expr<B>& bo, Marker& marker) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
622
  int Nx, Ny, Nz;
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
651
652
653
654
655
656
657
658
659
660
661
  const A& a ( ao );
  const B& b ( bo );

  typedef double DTyp;
  
  double sum;
  double sum_total;

  sum = 0.0;

  if(developer_version) 
     if(a.Give_blockgrid() != b.Give_blockgrid()) std::cout << " error2 in product_cell!" << std::endl;

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

             double localSum = 0.0;
             #pragma omp parallel for reduction(+ : localSum) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)     
             for(int k=0;k<Nz;++k) {
                 for(int j=0;j<Ny;++j)
                     for(int i=0;i<Nx;++i)
	                 localSum  +=   a.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny)
	                              * b.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny);
	     }
     
             sum = sum + localSum;
	  }
      }

  sum_total = Make_MPI_All_Sum<DTyp>::Do(sum,comm);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
662

Phillip Lino Rall's avatar
Phillip Lino Rall committed
663
664
665
666
667
668
669
  return sum_total;
}

template <class DTyp>
template <class A, class B>
DTyp ProductCalculator<DTyp>::product_cell(Expr<A>& ao, Expr<B>& bo, Marker& marker) {
  int Nx, Ny, Nz;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
670
671
672
673
674
675
676
677
  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
678
  if(developer_version) 
Phillip Lino Rall's avatar
Phillip Lino Rall committed
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
     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);

      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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
     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);

	    
	    double localInfy = 0.0;
#pragma omp parallel for reduction(max : localInfy) num_threads(UGBlocks::numThreadsToTake) 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(localInfy < ABS(a.Give_cell_hexahedra(id,
						 Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny)))
	                   localInfy = ABS(a.Give_cell_hexahedra(id,
						Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny));
	    }
	    
	    if(infty < localInfy) infty = localInfy;
	 }
     }
  
  MPI_Allreduce(&infty,&infty_total,1,MPI_DOUBLE,MPI_MAX,comm);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
751

Phillip Lino Rall's avatar
Phillip Lino Rall committed
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
  return infty_total;
}


template <class A>
double L_infty_cell(const Expr<A>& ao) {
  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();

  if(a.totalCalcNotPossible()) {  
     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);

	    
	    double localInfy = 0.0;
//#pragma omp parallel for reduction(max : localInfy) num_threads(UGBlocks::numThreadsToTake) 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(localInfy < ABS(a.Give_cell_hexahedra(id,
Phillip Lino Rall's avatar
Phillip Lino Rall committed
785
						 Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny)))
Phillip Lino Rall's avatar
Phillip Lino Rall committed
786
	                   localInfy = ABS(a.Give_cell_hexahedra(id,
Phillip Lino Rall's avatar
Phillip Lino Rall committed
787
						Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny));
Phillip Lino Rall's avatar
Phillip Lino Rall committed
788
789
790
791
792
793
794
795
796
797
	    }
	    
	    if(infty < localInfy) infty = localInfy;
	 }
     }
  }
  else {
//#pragma omp parallel for reduction(max : infty) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)     
      for(int i=0;i<a.getTotalNumberData();++i) {
	  if(infty < ABS(a.Give_fromTotal(i))) infty = ABS(a.Give_fromTotal(i)); 
Phillip Lino Rall's avatar
Phillip Lino Rall committed
798
799
      }
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
800
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
801
802
803
804
805
  MPI_Allreduce(&infty,&infty_total,1,MPI_DOUBLE,MPI_MAX,comm);

  return infty_total;
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
806

Phillip Lino Rall's avatar
Phillip Lino Rall committed
807
808
809
810
811
812
813
template <class A>
double Maximum_cell(const Expr<A>& ao)  {
  int Nx, Ny, Nz;

  double maximum;
  double maximum_total;

814
  maximum = -std::numeric_limits<double>::max(); // früher: -1.0e50;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
815
816
817
818
819
820
821
822
823
  
  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
824
825
826
827
828
829
830
  if(a.totalCalcNotPossible()) {  
     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);

831
	    double localMax = -std::numeric_limits<double>::max();
Phillip Lino Rall's avatar
Phillip Lino Rall committed
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
//#pragma omp parallel for reduction(max:localMax) num_threads(UGBlocks::numThreadsToTake) 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 < a.Give_cell_hexahedra(id,
			   			 Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny))
	                   maximum = a.Give_cell_hexahedra(id,
						Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny);
		    }
	    } 
	    if(maximum < localMax) maximum = localMax;
	 }
     }
  }
  else {
//    #pragma omp parallel for reduction(max:maximum) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)     
      for(int i=0;i<a.getTotalNumberData();++i) {
	  if(maximum < a.Give_fromTotal(i)) maximum = a.Give_fromTotal(i); 
Phillip Lino Rall's avatar
Phillip Lino Rall committed
850
851
      }
  }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
852
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
853
854
855
856
857
  MPI_Allreduce(&maximum,&maximum_total,1,MPI_DOUBLE,MPI_MAX,comm);

  return maximum_total;
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
903
904
905
906
907
template <class A>
double Minimum_cell(const Expr<A>& ao)  {
  int Nx, Ny, Nz;

  double minimum;
  double minimum_total;

  minimum = std::numeric_limits<double>::max();
  
  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();

  
  if(a.totalCalcNotPossible()) {  
     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);

	    double localMin = std::numeric_limits<double>::max();
//#pragma omp parallel for reduction(min:localMin) num_threads(UGBlocks::numThreadsToTake) 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 > a.Give_cell_hexahedra(id,
			   			 Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny))
	                   minimum = a.Give_cell_hexahedra(id,
						Ind_loc_matrix_hexahedra(i,j,k),i,j,k,Nx,Ny);
		    }
	    } 
	    if(minimum > localMin) minimum = localMin;
	 }
     }
  }
  else {
//    #pragma omp parallel for reduction(min:minimum) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)     
      for(int i=0;i<a.getTotalNumberData();++i) {
	  if(minimum > a.Give_fromTotal(i)) minimum = a.Give_fromTotal(i); 
      }
  }
  
  MPI_Allreduce(&minimum,&minimum_total,1,MPI_DOUBLE,MPI_MIN,comm);

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

Phillip Lino Rall's avatar
Phillip Lino Rall committed
909
/*
Phillip Lino Rall's avatar
Phillip Lino Rall committed
910
911
912
913
914
915
916
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
917
  minimum = std::numeric_limits<double>::max();
Phillip Lino Rall's avatar
Phillip Lino Rall committed
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
  
  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
952
*/
Phillip Lino Rall's avatar
Phillip Lino Rall committed
953
954
955
956



#endif // CE_VA_H