variable.h 55.8 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
34
35
36
37
38
39
40
41
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
/**********************************************************************************
 * 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.
 **********************************************************************************/
 
// ------------------------------------------------------------
//
// variable.h
//
// ------------------------------------------------------------

#include <limits>
//#include <math.h>


#ifndef VARIABLE_H
#define VARIABLE_H
#ifdef _OPENMP
#include <omp.h>
#else
#include "../myopenmp.h"
#endif


#include "../ugopenmp.h"

#include <complex>
using std::complex;
//////////////////////////////////////////////////////////////
// 1. Restriction to subgrid
// 2. Variable for points
// 3. Other funktions like max, infty ...
// 4. Implementation of inline functions, operator=, ...
// 5. Nconst , ... funtions for copy of data
//////////////////////////////////////////////////////////////

// Gitter:
// * boundary point
// + interior point

/*
Ny    *  *  *  *  *  *
Ny-1  *  +  +  +  +  *
3     *  +  +  +  +  *
2     *  +  +  +  +  *
1     *  +  +  +  +  *
0     *  *  *  *  *  *
      0  1  2  3 Nx-1 Nx
*/
// k=0...Nz            for(k=0;k<=Nz;++k)
//   j=0...Ny            for(j=0;j<=Ny;++j)
//     i=0...Nx            for(i=0;i<=Nx;++i)
//       index = i + (Nx+1)*(j+k*(Ny+1))


///////////////////////////
// 0. Predefinitions
///////////////////////////

class IteratorZDirection;

template <typename TYPE>  class ExpressionRestriction;

template <typename TYPE>  class ExpressionProlongation;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
79
//template <typename TYPE>  class Expr_interpolant_cell_to_point;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93

template <class A, class DTyp>  class Expr_Equation_of_Array;

class QString;

class IteratorZDirection;

template <class DTyp> class Variable2D;
template <class A> struct Expr2D;


template <class Typ> class vtkSmartPointer;
class vtkUnstructuredGrid;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
94
95
template <class A, class B>
_TypeOf2_ ( A, B ) product_on ( Expr<A>& ao, Expr<B>& bo, Marker& marker );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

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

template <class A>
class Expr_Restriction {
		const A& a_;
		const Marker& marker;
		
	public:
		Expr_Restriction ( const Expr<A>& a, const Marker& mark ) : a_ ( a ), marker ( mark ) {}
		
		Blockgrid* Give_blockgrid() const { return a_.Give_blockgrid(); };
		
		stencil_typ Give_stencil_typ() const { return a_.Give_stencil_typ(); }
		
		typedef typename A::Result Result;
		
		template <elementTyp TYP_EL>
		inline Result Give_data ( params_in ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
117
			return a_.template Give_data<TYP_EL> ( params_out );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
118
119
120
		}
		
		inline Result Give_cell_hexahedra ( params_in_cell ) const  {
Christoph Pflaum's avatar
Christoph Pflaum committed
121
                       return a_.Give_cell_hexahedra ( params_out_cell );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
122
123
124
125
		}
		
		template <elementTyp TYP_EL>
		void Update ( int id ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
126
			a_.template Update<TYP_EL> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
		}
		
		template <elementTyp TYP_EL>
		marker_typ Give_marker ( int i ) const{ return marker.Give_marker<TYP_EL> ( i ); }
};

template <class A>
inline Expr_Restriction<A> operator| ( const Expr<A>& a, const Marker& sg ) {
	return Expr_Restriction<A> ( a, sg );
}

template <typename DTyp>
class DTyp_Restriction {
		DTyp x_;
		const Marker& marker;
		
	public:
		DTyp_Restriction ( DTyp x, const Marker& mark ) : x_ ( x ), marker ( mark ) {}
		
		~DTyp_Restriction() {}
		
		template <elementTyp TYP_EL>
		marker_typ Give_marker ( int i ) const{ return marker.Give_marker<TYP_EL> ( i ); }
		
		inline DTyp Give_x() const { return x_; }
};

inline DTyp_Restriction<double> operator| ( double x, Marker& sg ) {
	return DTyp_Restriction<double> ( x, sg );
}

inline DTyp_Restriction<std::complex<double> > operator| ( std::complex<double> x, Marker& sg ) {
	return DTyp_Restriction<std::complex<double> > ( x, sg );
}


///////////////////////////
// 1.b Restriction to subgrid and iteration description
///////////////////////////

class Iteration_description {

	public:
		Iteration_description ( Marker& m ) : marker ( &m ) { red_black = false; }
		
		Marker* marker;
		bool red_black;
};


template <class A>
class Expr_Restriction_Iterdes {
		const A& a_;
		
	public:
		Expr_Restriction_Iterdes ( const Expr<A>& a, const Iteration_description& ides ) : a_ ( a ), iterdes ( ides ) {}
		
		const Iteration_description& iterdes;
		
		Blockgrid* Give_blockgrid() const { return a_.Give_blockgrid(); };
		
		stencil_typ Give_stencil_typ() const { return a_.Give_stencil_typ(); }
		
		typedef typename A::Result Result;
		
		template <elementTyp TYP_EL>
		inline Result Give_data ( params_in ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
194
			return a_.template Give_data<TYP_EL> ( params_out );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
195
196
197
198
		}
		
		template <elementTyp TYP_EL>
		void Update ( int id ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
199
			a_.template Update<TYP_EL> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
		}
		
		template <elementTyp TYP_EL>
		marker_typ Give_marker ( int i ) const{ return iterdes.marker->Give_marker<TYP_EL> ( i ); }
};

template <class A>
inline Expr_Restriction_Iterdes<A> operator| ( const Expr<A>& a, const Iteration_description& iterdes ) {
	return Expr_Restriction_Iterdes<A> ( a, iterdes );
}


///////////////////////////
// 2. Variable for points
///////////////////////////

class Assign_System;

Christoph Pflaum's avatar
Christoph Pflaum committed
218
219
template <class DTyp, class Vari>
class VariableVector;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
220
221
222
223
224

template <class DTyp>
class Variable : public Expr<Variable< DTyp > >, public Object_based_on_ug {
		template <class A, class ADTyp>
		
Christoph Pflaum's avatar
Christoph Pflaum committed
225
		friend class Expr_Equation_of_Array;		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
226
227
		class Assign_System;
		
Christoph Pflaum's avatar
Christoph Pflaum committed
228
229
                friend  VariableVector<DTyp, Variable<DTyp> >;		
		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
230
231
232
233
234
235
236
237
238
239
240
241
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
	public:
		int checkThreshold(double threshold, int kz );
		
		typedef DTyp Result;
		
		//  template <class DTyp_>
		//  friend DTyp_ product(Variable<DTyp_>& a, Variable<DTyp_>& b, Marker& marker);
		
		Variable(Blockgrid& blockgrid_ );
		/**
		 * Ganz spezieller Konstruktor der nur für Ausgabe von Daten in Raytracing ist
		 * Blockgrid darf nur einen Block enthalten
		 * das ist dann:  specialVariableForOneBlock
		 **/
		Variable(Blockgrid& blockgrid_, double *data);
		
		/**
		 * Ganz spezieller Konstruktor fuer vtKReader
		 * äusseren Pointer (dataHex) darf man nach Aufruf löschen
		 * Daten zu innerem Pointer (*dataHex) werden verwendet und darf man nach Aufrud nicht löschen
		 **/
		Variable(Blockgrid& blockgrid_, double **dataHex);		
		
		
		~Variable();
		void Delete_data();

		int getGridId() { return idGrid; }
		Blockgrid* Give_blockgrid() const { return blockgrid; };
		Unstructured_grid * Give_Ug() const { return ug;};
		
		void interpolateSlizeZ(const Variable2D<DTyp>* U, IteratorZDirection* iterZ);
		
		template <class A>
		void interpolateSlizeZ(const Expr2D<A>& a_, IteratorZDirection* iterZ);

		bool containsNaN();
		
		void Print_AVS ( std::ofstream *Datei );
		void Print_Dx ( std::ofstream *Datei );
		
		// QT-VTK  
		void QPrint_VTK(QString DateiName, double stretch_z = 1., QString title = QString("myfile"),  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, bool cutSmallData = true);
		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, int z_cut, QString title = "myData" );
		
		// VTK output  
		vtkUnstructuredGrid* GetVtkOutput(double stretch_z = 1., QString title = QString("myfile"),  Unstructured_grid_Marker * marker = NULL );
		
		// z_cut = Nz, falls z_cut zu gross gewaehlt
		void Print_VTK ( std::ostream& Datei, int z_cut, std::string title = "myData" );
		void Print_VTK ( std::ostream& Datei, double ( *convert ) ( DTyp x ), double stretch_z = 1., std::string title = "myData", Unstructured_grid_Marker * marker = NULL );
		
		/// Prints absolute value in case of complex variable
		void Print_VTK ( std::ostream& Datei, double stretch_z = 1., std::string title = "myData",  Unstructured_grid_Marker * marker = NULL );
		
		
		///Binary VTK
		void Print_VTK_BIN ( std::ostream& Datei, double stretch_z = 1., std::string title = "myData",  Unstructured_grid_Marker * marker = NULL );
		
		void Print_AVS ( Variable<double>& ux, Variable<double>& uy, Variable<double>& uz, std::ofstream *Datei );
		void Print_Dx ( Variable<double>& ux, Variable<double>& uy, Variable<double>& uz, std::ofstream *Datei );
		
		// copy of data from hex_a to hex_b
		void Copy_invert_z ( int hex_b, Variable<DTyp>& a, int hex_a );
		
		template <elementTyp TYP_EL>
		inline DTyp Give_data ( params_in ) const;
299
300
301

        template <elementTyp TYP_EL>
        inline void Set_data ( params_in, DTyp value );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
302
303
304
305
306
307
308
		
		
		// fuer debug-zwecke mit positionsrueckgabe
		template <elementTyp TYP_EL>
		inline DTyp Give_data ( params_in, D3vector &posVector ) const ;
		
		void UpdateHexahedra(); ///> Updated alle Randdaten in allen Hexahedra
309
        void UpdateHexahedraBack();
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
		/// todo update nur falls notwendig
		template <elementTyp TYP_EL>
		void Update ( int id ) const;
		
		void Update_back(int id) const; ///> fuer interpolation slice 2D -> 3D
				
		
		inline DTyp Give_data_quadrangle_middle ( int id, int i, int j, int Nx ) const;
		inline DTyp Give_data_quadrangle_interior ( int id, int i, int j, int Nx ) const;
		inline DTyp Give_data_quadrangle_exterior ( int id, int i, int j, int Nx ) const;
		
		inline DTyp Give_data_edge ( int id, int i ) const;
		inline DTyp Give_data_neighbor_edge ( int id, int num, int i ) const;
		
		inline DTyp Give_data_point ( int id ) const;
		inline DTyp Give_data_neighbor_point ( int id, int num ) const;
		
		inline DTyp** Give_pointer_data_points() const { return data_points; };		
		inline DTyp** Give_pointer_data_edges() const { return data_edges; };
		inline DTyp** Give_pointer_data_hexahedra() const { return data_hexahedra; };		
		inline DTyp** Give_pointer_data_quadrangle() const { return data_quadrangles; };
		
		void operator= ( const DTyp_Restriction<DTyp>& a );
		
		template <class A>
		void operator= ( const Expr_Restriction<A>& a );

		// wie oben nur Iteration Rückwärts
		template <class A>
		void operator== ( const Expr_Restriction<A>& a );		
		
		template <class A>
		void Plane_z_relaxation ( int iter_plane, const Expr_Restriction<A>& a );
		
		template <class A>
		void Plane_minus_z_relaxation ( int iter_plane, const Expr_Restriction<A>& a );
		
		template <class A>
		void operator= ( const Expr_Restriction_Iterdes<A>& a );
		
		template <class A>
		void operator= ( const Expr<A>& a );
		
		void operator= ( const Variable<DTyp>& v );
		void operator= ( DTyp x );
		
		void operator= ( const ExpressionRestriction<DTyp>& Expr_res );
		void operator= ( const ExpressionProlongation<DTyp>& Expr_prol );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
358
//                void operator= ( const Expr_interpolant_cell_to_point<DTyp>& Expr_cell );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
359
		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
360
361
		
		static DTyp product(Variable& a, Variable& b) { return product_on(a,b,a.Give_blockgrid()->Give_unstructured_grid()->Give_all_points()); }
362

Phillip Lino Rall's avatar
Phillip Lino Rall committed
363
364
365
366
367
368
369
		
		stencil_typ Give_stencil_typ() const { return no_stencil; }
		control_typ Give_control_typ() const { return thread_save; }
		
		// copies data from a in hex_a to data in hex_b
		void Copy_invert_z ( int hex_b, Variable<DTyp> a, int hex_a );
		
Christoph Pflaum's avatar
Christoph Pflaum committed
370
                int  getTotalNumberData()   const { return totalNumberData; }		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
371
	private:
Christoph Pflaum's avatar
Christoph Pflaum committed
372
373
	        inline DTyp* give_startTotal() const  { assert(dataTotal!=NULL);  return dataTotal; }  	
	        
Phillip Lino Rall's avatar
Phillip Lino Rall committed
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
		Blockgrid*        blockgrid;
		Unstructured_grid*       ug;
		
		// own data
		DTyp** data_hexahedra;        // num_hexahedra
		DTyp** data_quadrangles;      // num_quadrangles
		DTyp** data_edges;            // num_edges
		DTyp** data_points;           // num_points, first own data
		// rest unstructured
		
		// neighbor unstructured data
		DTyp**  data_interior_quadrangles;       // num_quadrangles
		DTyp**  data_exterior_quadrangles;       // num_quadrangles
		
		DTyp*** data_neighbor_edges;             // num_edges
		
		DTyp**  data_neighbor_points;            // num_points
		
		//  DTyp**  data_triangles;                // num_triangles
		//  DTyp**  data_interior_triangles;       // num_triangles
		//  DTyp**  data_exterior_triangles;       // num_triangles
		
Christoph Pflaum's avatar
Christoph Pflaum committed
396
397

		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
		// for parallel
		int my_rank;
		MPI_Comm comm;
		
		// zum Löschen von Daten Kopie der UG_Blocks Daten
		int  ug_number_hexahedra;
		int  ug_number_quadrangles;
		int  ug_number_edges;
		int* ug_edge_number_neighbors;  // array of size ug_number_edges
		int  ug_number_points;
		int  idGrid;
		
		bool isIndeterminateTT(const double pV) { return (pV != pV);  } 
                bool isInfiniteTT(const double pV) { return (fabs(pV) == std::numeric_limits<double>::infinity());  }
                
Christoph Pflaum's avatar
Christoph Pflaum committed
413
414
415
416
		// own data
                int totalNumberData;
                DTyp* dataTotal;
                bool specialVariableForOneBlock; //> dann ist dataTotal nicht verwendbar
Phillip Lino Rall's avatar
Phillip Lino Rall committed
417
418
419
420
421
422
423
424
425
};
	
template <class DTyp>
void Variable<DTyp>::UpdateHexahedra() {
     for(int id_hex=0;id_hex<ug->Give_number_hexahedra();++id_hex) {
         Update<hexahedronEl>(id_hex);
     }
}

426
427
428
429
430
431
432
template <class DTyp>
void Variable<DTyp>::UpdateHexahedraBack() {
     for(int id_hex=0;id_hex<ug->Give_number_hexahedra();++id_hex) {
         Update_back(id_hex);
     }
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
template <class DTyp>
int Variable<DTyp>::checkThreshold ( double threshold, int kz ) {
			int id_hex = 1;

			int Ny = blockgrid->Give_Ny_hexahedron ( id_hex );
			int Nx = blockgrid->Give_Nx_hexahedron ( id_hex );
			D3vector v;
			DTyp temp;

			Update<hexahedronEl> ( id_hex );
			
			int thresholdReached = 0;

			int k = kz;
			
			for ( int j = 0;j <= Ny;++j ) {
				for ( int i = 0;i <= Nx;++i ) {
					temp = ( data_hexahedra[id_hex][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] );
					
					if ( ABS ( temp ) > threshold ) {
						thresholdReached++;
						std::cout << "Variable: real(value) = " << real ( temp ) <<std::endl;
						v = blockgrid->Give_coord_hexahedron ( id_hex, i, j, k );
						std::cout << " at coordinate (" << v.x
						<< "," << v.y
						<< "," << v.z
						<< ")." <<std::endl;
						std::cout << "with indizes (" << i
						<< "," << j
						<< "," << k
						<< ")." <<std::endl;;
					}
				}
			}
			return thresholdReached;
}


		
template <>
template <>
inline double Variable<double>::Give_data<pointEl> ( params_in ) const {
	return data_points[id][0];
}

template <>
template <>
inline std::complex<double> Variable<std::complex<double> >::Give_data<pointEl> ( params_in ) const {
	return data_points[id][0];
}

template <>
template <>
inline double Variable<double>::Give_data<edgeEl> ( params_in ) const {
	return data_edges[id][i];
}

template <>
template <>
inline std::complex<double> Variable<std::complex<double> >::Give_data<edgeEl> ( params_in ) const {
	return data_edges[id][i];
}

template <>
template <>
inline double Variable<double>::Give_data<quadrangleEl> ( params_in ) const {
	return data_quadrangles[id][i+ ( Nx+1 ) *j];
}

template <>
template <>
inline std::complex<double> Variable<std::complex<double> >::Give_data<quadrangleEl> ( params_in ) const {
	return data_quadrangles[id][i+ ( Nx+1 ) *j];
}

template <>
template <>
inline double Variable<double>::Give_data<hexahedronEl> ( params_in ) const {
	return data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ];
}

514
515
516
template <>
template <>
inline void Variable<double>::Set_data<hexahedronEl> ( params_in, double value )  {
517
     data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] = value;
518
519
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
// fuer debug zwecke koordinatenrueckgabe
template <>
template <>
inline std::complex<double> Variable<std::complex<double> >::Give_data<hexahedronEl> ( params_in, D3vector &posVector ) const {
	posVector = blockgrid->Give_coord_hexahedron ( id, i, j, k );
	return data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ];
	;
}

// fuer debug zwecke koordinatenrueckgabe
template <>
template <>
inline double Variable<double >::Give_data<hexahedronEl> ( params_in, D3vector &posVector ) const {
	posVector = blockgrid->Give_coord_hexahedron ( id, i, j, k );
	return data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ];
	;
}


template <>
template <>
inline std::complex<double> Variable<std::complex<double> >::Give_data<hexahedronEl> ( params_in ) const {
	return data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ];
}


///////////////////////////
// 3. Other functions, max, ...
///////////////////////////



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

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



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

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


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

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


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

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



//////////////////////////////////////////
// and it's implementation

template <class A, class B>
_TypeOf2_ ( A, B ) product ( Expr<A>& a, Expr<B>& b ) {
	const A& ao ( a );
	
Phillip Lino Rall's avatar
Phillip Lino Rall committed
589
	return product_on ( a, b, ao.Give_blockgrid()->Give_unstructured_grid()->Give_all_points() );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
}

template <class A>
double  L_infty ( const Expr<A>& a ) {
	const A& ao ( a );
	
	return L_infty ( a, ao.Give_blockgrid()->Give_unstructured_grid()->Give_all_points() );
}


template <class A>
double  Minimum ( const Expr<A>& a ) {
	const A& ao ( a );
	
	return Minimum ( a, ao.Give_blockgrid()->Give_unstructured_grid()->Give_all_points() );
}


template <class A>
double  Maximum ( const Expr<A>& a ) {
	const A& ao ( a );
	
	return Maximum ( a, ao.Give_blockgrid()->Give_unstructured_grid()->Give_all_points() );
}

template <class A, class B>
Phillip Lino Rall's avatar
Phillip Lino Rall committed
616
_TypeOf2_ ( A, B ) product ( Expr<A>& ao, Expr<B>& bo, Marker& marker ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
617
618
619
620
621
622
  return product_on(ao,bo,marker);
}


template <class A, class B>
_TypeOf2_ ( A, B ) product_on ( Expr<A>& ao, Expr<B>& bo, Marker& marker ) {
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
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
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
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
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
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
        int i, j, k, id;
        int Nx, Ny, Nz;

        typedef _TypeOf2_ ( A, B ) DTyp;
        const A& a ( ao );
        const B& b ( bo );

        DTyp sum;
        DTyp sum_total;

        sum = ( DTyp ) 0;

        if ( developer_version )
                if ( a.Give_blockgrid() != b.Give_blockgrid() ) std::cout << " error2 in product!" << 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 ( 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 );

/// @todo: problem mit kombination aus reduction (+:sum) und MyConj
//#pragma omp parallel for private(k,j,i) reduction(+ : sum) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)

                        for ( k = 1;k < Nz;++k )
                                for ( j = 1;j < Ny;++j )
                                        for ( i = 1;i < Nx;++i )
                                                sum += a.template Give_data<hexahedronEl> ( params_out )
                                                       * MyConj<DTyp>::Give ( b.template Give_data<hexahedronEl> ( params_out ) );
                }
        }

        for ( id = 0;id < ug->Give_number_quadrangles();++id ) {
                if ( ug->Give_quadrangle ( id )->my_object ( my_rank )   &&
                        marker.template Give_marker<quadrangleEl> ( id ) == yes_mark ) {
                        Nx = a.Give_blockgrid()->Give_Nx_quadrangle ( id );
                        Ny = a.Give_blockgrid()->Give_Ny_quadrangle ( id );

                        for ( j = 1;j < Ny;++j )
                                for ( i = 1;i < Nx;++i )
                                        sum += a.template Give_data<quadrangleEl> ( params_out )
                                               * MyConj<DTyp>::Give ( b.template Give_data<quadrangleEl> ( params_out ) );
                }
        }

        for ( id = 0;id < ug->Give_number_edges();++id ) {
                if ( ug->Give_edge ( id )->my_object ( my_rank )    &&
                        marker.template Give_marker<edgeEl> ( id ) == yes_mark ) {
                        Nx = a.Give_blockgrid()->Give_Nx_edge ( id );

                        for ( i = 1;i < Nx;++i )
                                sum += a.template Give_data<edgeEl> ( params_out )
                                       * MyConj<DTyp>::Give ( b.template Give_data<edgeEl> ( params_out ) );
                }
        }

        for ( id = 0;id < ug->Give_number_points();++id ) {
                if ( ug->Give_point ( id )->my_object ( my_rank )    &&
                        marker.template Give_marker<pointEl> ( id ) == yes_mark ) {
                        sum += a.template Give_data<pointEl> ( params_out )
                               * MyConj<DTyp>::Give ( b.template Give_data<pointEl> ( params_out ) );
                }
        }



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

        return sum_total;
}

template <class A, class B>
_TypeOf2_ ( A, B ) product ( const Expr<A>& ao, const Expr<B>& bo, Marker& marker ) {
	int i, j, k, id;
	int Nx, Ny, Nz;
	
	typedef _TypeOf2_ ( A, B ) DTyp;
	const A& a ( ao );
	const B& b ( bo );
	
	DTyp sum;
	DTyp sum_total;
	
	sum = ( DTyp ) 0;
	
	if ( developer_version )
		if ( a.Give_blockgrid() != b.Give_blockgrid() ) std::cout << " error2 in product!" <<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 ( 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 );
			
/// @todo: problem mit kombination aus reduction (+:sum) und MyConj
//#pragma omp parallel for private(k,j,i) reduction(+ : sum) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)

			for ( k = 1;k < Nz;++k )
				for ( j = 1;j < Ny;++j )
					for ( i = 1;i < Nx;++i )
						sum += a.template Give_data<hexahedronEl> ( params_out )
						       * MyConj<DTyp>::Give ( b.template Give_data<hexahedronEl> ( params_out ) );
		}
	}
	
	for ( id = 0;id < ug->Give_number_quadrangles();++id ) {
		if ( ug->Give_quadrangle ( id )->my_object ( my_rank )   &&
		        marker.template Give_marker<quadrangleEl> ( id ) == yes_mark ) {
			Nx = a.Give_blockgrid()->Give_Nx_quadrangle ( id );
			Ny = a.Give_blockgrid()->Give_Ny_quadrangle ( id );
			
			for ( j = 1;j < Ny;++j )
				for ( i = 1;i < Nx;++i )
					sum += a.template Give_data<quadrangleEl> ( params_out )
					       * MyConj<DTyp>::Give ( b.template Give_data<quadrangleEl> ( params_out ) );
		}
	}
	
	for ( id = 0;id < ug->Give_number_edges();++id ) {
		if ( ug->Give_edge ( id )->my_object ( my_rank )    &&
		        marker.template Give_marker<edgeEl> ( id ) == yes_mark ) {
			Nx = a.Give_blockgrid()->Give_Nx_edge ( id );
			
			for ( i = 1;i < Nx;++i )
				sum += a.template Give_data<edgeEl> ( params_out )
				       * MyConj<DTyp>::Give ( b.template Give_data<edgeEl> ( params_out ) );
		}
	}
	
	for ( id = 0;id < ug->Give_number_points();++id ) {
		if ( ug->Give_point ( id )->my_object ( my_rank )    &&
		        marker.template Give_marker<pointEl> ( id ) == yes_mark ) {
			sum += a.template Give_data<pointEl> ( params_out )
			       * MyConj<DTyp>::Give ( b.template Give_data<pointEl> ( params_out ) );
		}
	}
	
	
	
	sum_total = Make_MPI_All_Sum<DTyp>::Do ( sum, comm );
	
	return sum_total;
}


template <class A>
double L_infty ( const Expr<A>& ao, Marker& marker ) {
	int i, j, k, id;
	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();
	
	for ( 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 ( k = 1;k < Nz;++k )
				for ( j = 1;j < Ny;++j )
					for ( i = 1;i < Nx;++i )
						if ( infty < ABS ( a.template Give_data<hexahedronEl> ( params_out ) ) )
							infty = ABS ( a.template Give_data<hexahedronEl> ( params_out ) );
		}
	}
	
	for ( id = 0; id < ug->Give_number_quadrangles(); ++id ) {
		if ( ug->Give_quadrangle ( id )->my_object ( my_rank ) &&
		        marker.template Give_marker<quadrangleEl> ( id ) == yes_mark ) {
			Nx = a.Give_blockgrid()->Give_Nx_quadrangle ( id );
			Ny = a.Give_blockgrid()->Give_Ny_quadrangle ( id );
			
			for ( j = 1;j < Ny;++j )
				for ( i = 1;i < Nx;++i )
					if ( infty < ABS ( a.template Give_data<quadrangleEl> ( params_out ) ) )
						infty = ABS ( a.template Give_data<quadrangleEl> ( params_out ) );
						
		}
	}
	
	for ( id = 0; id < ug->Give_number_edges(); ++id ) {
		if ( ug->Give_edge ( id )->my_object ( my_rank ) &&
		        marker.template Give_marker<edgeEl> ( id ) == yes_mark ) {
			Nx = a.Give_blockgrid()->Give_Nx_edge ( id );
			
			for ( i = 1;i < Nx;++i )
				if ( infty < ABS ( a.template Give_data<edgeEl> ( params_out ) ) )
					infty = ABS ( a.template Give_data<edgeEl> ( params_out ) );
		}
	}
	
	for ( id = 0; id < ug->Give_number_points(); ++id ) {
		if ( ug->Give_point ( id )->my_object ( my_rank ) &&
		        marker.template Give_marker<pointEl> ( id ) == yes_mark ) {
			if ( infty < ABS ( a.template Give_data<pointEl> ( params_out ) ) )
				infty = ABS ( a.template Give_data<pointEl> ( params_out ) );
		}
	}
	
	MPI_Allreduce ( &infty, &infty_total, 1, MPI_DOUBLE, MPI_MAX, comm );
	
	return infty_total;
}

template <class A>
double Minimum ( const Expr<A>& ao, Marker& marker ) {
	int i, j, k, id;
	int Nx, Ny, Nz;
	
	double minimum = 1e60;
	double minimum_total;
	
	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();
	
	int set       = false;
	int set_total = false;

	for ( 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 ( k = 1;k < Nz;++k )
				for ( j = 1;j < Ny;++j )
					for ( i = 1;i < Nx;++i ) {
						if ( minimum > myREAL ( a.template Give_data<hexahedronEl> ( params_out ) ) ||
						        set == false ) {
							minimum = myREAL ( a.template Give_data<hexahedronEl> ( params_out ) );
							set = true;
						}
					}
		}
	}


	for ( id = 0; id < ug->Give_number_quadrangles(); ++id ) {
		if ( ug->Give_quadrangle ( id )->my_object ( my_rank ) &&
		        marker.template Give_marker<quadrangleEl> ( id ) == yes_mark ) {
			Nx = a.Give_blockgrid()->Give_Nx_quadrangle ( id );
			Ny = a.Give_blockgrid()->Give_Ny_quadrangle ( id );
			
			for ( j = 1;j < Ny;++j )
				for ( i = 1;i < Nx;++i ) {
					if ( minimum > myREAL ( a.template Give_data<quadrangleEl> ( params_out ) ) ||
					        set == false ) {
						minimum = myREAL ( a.template Give_data<quadrangleEl> ( params_out ) );
						set = true;
					}
				}
		}
	}
	
	for ( id = 0; id < ug->Give_number_edges(); ++id ) {
		if ( ug->Give_edge ( id )->my_object ( my_rank ) &&
		        marker.template Give_marker<edgeEl> ( id ) == yes_mark ) {
			Nx = a.Give_blockgrid()->Give_Nx_edge ( id );
			
			for ( i = 1;i < Nx;++i ) {
				if ( minimum > myREAL ( a.template Give_data<edgeEl> ( params_out ) ) ||
				        set == false ) {
					minimum = myREAL ( a.template Give_data<edgeEl> ( params_out ) );
					set = true;
				}
			}
		}
	}
	
	for ( id = 0; id < ug->Give_number_points(); ++id ) {
		if ( ug->Give_point ( id )->my_object ( my_rank ) &&
		        marker.template Give_marker<pointEl> ( id ) == yes_mark ) {
			if ( minimum > myREAL ( a.template Give_data<pointEl> ( params_out ) ) ||
			        set == false ) {
				minimum = myREAL ( a.template Give_data<pointEl> ( params_out ) );
				set = true;
			}
		}
	}
	
	MPI_Allreduce ( &minimum, &minimum_total, 1, MPI_DOUBLE, MPI_MIN, comm );
	
	int p;
	
	MPI_Comm_size ( comm, &p );
	
	MPI_Allreduce ( &set, &set_total, 1, MPI_INT, MPI_SUM, comm );
	
	if ( set_total != p && minimum_total > 1e59 ) std::cout << "error in Minimum" << std::endl;
	
	return minimum_total;
}

template <class A>
double Maximum ( const Expr<A>& ao, Marker& marker ) {
	int i, j, k, id;
	int Nx, Ny, Nz;
	
	double maximum = -1e60;
	double maximum_total;
	
	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();
	
	int set = false;
	int set_total = false;
	
	for ( 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 ( k = 1;k < Nz;++k )
				for ( j = 1;j < Ny;++j )
					for ( i = 1;i < Nx;++i )
						if ( maximum < a.template Give_data<hexahedronEl> ( params_out ) ||
						        set == false ) {
							maximum = myREAL ( a.template Give_data<hexahedronEl> ( params_out ) );
							set = true;
						}
		}
	}
	
	for ( id = 0; id < ug->Give_number_quadrangles(); ++id ) {
		if ( ug->Give_quadrangle ( id )->my_object ( my_rank )  &&
		        marker.template Give_marker<quadrangleEl> ( id ) == yes_mark ) {
			Nx = a.Give_blockgrid()->Give_Nx_quadrangle ( id );
			Ny = a.Give_blockgrid()->Give_Ny_quadrangle ( id );
			
			for ( j = 1;j < Ny;++j )
				for ( i = 1;i < Nx;++i )
					if ( maximum < a.template Give_data<quadrangleEl> ( params_out ) ||
					        set == false ) {
						maximum = myREAL ( a.template Give_data<quadrangleEl> ( params_out ) );
						set = true;
					}
		}
	}
	
	for ( id = 0; id < ug->Give_number_edges(); ++id ) {
		if ( ug->Give_edge ( id )->my_object ( my_rank )  &&
		        marker.template Give_marker<edgeEl> ( id ) == yes_mark ) {
			Nx = a.Give_blockgrid()->Give_Nx_edge ( id );
			
			for ( i = 1;i < Nx;++i )
				if ( maximum < a.template Give_data<edgeEl> ( params_out ) ||
				        set == false ) {
					maximum = myREAL ( a.template Give_data<edgeEl> ( params_out ) );
					set = true;
				}
		}
	}
	
	for ( id = 0; id < ug->Give_number_points(); ++id ) {
		if ( ug->Give_point ( id )->my_object ( my_rank )  &&
		        marker.template Give_marker<pointEl> ( id ) == yes_mark ) {
			if ( maximum < a.template Give_data<pointEl> ( params_out ) ||
			        set == false ) {
				maximum = myREAL ( a.template Give_data<pointEl> ( params_out ) );
				set = true;
			}
		}
	}
	
	MPI_Allreduce ( &maximum, &maximum_total, 1, MPI_DOUBLE, MPI_MAX, comm );
	
	int p;
	MPI_Comm_size ( comm, &p );
	
	MPI_Allreduce ( &set, &set_total, 1, MPI_INT, MPI_SUM, comm );
	
	if ( set_total != p && maximum_total < -1e59 ) std::cout << "error in Maximum! " <<std::endl;
	
	//max_total = " << maximum_total << ".\t set_total = " << set_total << ".\t p = " << p  <<std::endl;
	
	
	return maximum_total;
}

//////////////////////////////////////////
// 4. Implementation of inline functions
//////////////////////////////////////////

template <class DTyp>
inline DTyp Variable<DTyp>::Give_data_quadrangle_middle ( int id, int i, int j, int Nx ) const {
	return data_quadrangles[id][i+ ( Nx+1 ) *j];
}

template <class DTyp>
inline DTyp Variable<DTyp>::Give_data_quadrangle_interior ( int id, int i, int j, int Nx ) const {
	return data_interior_quadrangles[id][i+ ( Nx+1 ) *j];
}

template <class DTyp>
inline DTyp Variable<DTyp>::Give_data_quadrangle_exterior ( int id, int i, int j, int Nx ) const {
	return data_exterior_quadrangles[id][i+ ( Nx+1 ) *j];
}

template <class DTyp>
inline DTyp Variable<DTyp>::Give_data_edge ( int id, int i ) const {
	return data_edges[id][i];
}

template <class DTyp>
inline DTyp Variable<DTyp>::Give_data_neighbor_edge ( int id, int num, int i ) const {
	return data_neighbor_edges[id][num][i];
}

template <class DTyp>
inline DTyp Variable<DTyp>::Give_data_point ( int id ) const {
	return data_points[id][0];
}

template <class DTyp>
inline DTyp Variable<DTyp>::Give_data_neighbor_point ( int id, int num ) const {
	return data_neighbor_points[id][num];
}

template <class DTyp>
template <class A>
void Variable<DTyp>::operator= ( const Expr_Restriction<A>& a ) {
	int Nx, Ny, Nz, i, j, k;
	
	stencil_typ sten_typ = a.Give_stencil_typ();
	
	// hexahedra
	
	for ( int id = 0;id < ug->Give_number_hexahedra();++id ) {
		if ( sten_typ == yes_stencil ) {
			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 );
			
#pragma omp parallel for private(j,i) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
			for ( k = 1;k < Nz;++k ) {
				for ( j = 1;j < Ny;++j )
					for ( i = 1;i < Nx;++i )
						data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1101
						    a.template Give_data<hexahedronEl> ( id, i, j, k, Nx, Ny );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1102
1103
1104
1105
1106
1107
1108
			}
		}
	}
	
	// quadrangles
	for ( int id = 0;id < ug->Give_number_quadrangles();++id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1109
			a.template Update<quadrangleEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
		}
		
		if ( ug->Give_quadrangle ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<quadrangleEl> ( id ) == yes_mark ) {
			Nx = blockgrid->Give_Nx_quadrangle ( id );
			Ny = blockgrid->Give_Ny_quadrangle ( id );
			
			for ( j = 1;j < Ny;++j )
				for ( i = 1;i < Nx;++i ) {
					data_quadrangles[id][i+ ( Nx+1 ) *j] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1120
					    a.template Give_data<quadrangleEl> ( id, i, j, 0, Nx, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1121
1122
1123
1124
1125
1126
1127
				}
		}
	}
	
	// edges
	for ( int id = 0;id < ug->Give_number_edges();++id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1128
			a.template Update<edgeEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1129
1130
1131
1132
1133
1134
1135
1136
		}
		
		if ( ug->Give_edge ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<edgeEl> ( id ) == yes_mark ) {
			Nx = blockgrid->Give_Nx_edge ( id );
			
			for ( i = 1;i < Nx;++i )
				data_edges[id][i] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1137
				    a.template Give_data<edgeEl> ( id, i, 0, 0, 0, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1138
1139
1140
1141
1142
1143
		}
	}
	
	// points
	for ( int id = 0;id < ug->Give_number_points();++id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1144
			a.template Update<pointEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1145
1146
1147
1148
1149
		}
		
		if ( ug->Give_point ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<pointEl> ( id ) == yes_mark ) {
			data_points[id][0] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1150
			    a.template Give_data<pointEl> ( id, 0, 0, 0, 0, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
		}
	}
}

template <class DTyp>
template <class A>
void Variable<DTyp>::operator== ( const Expr_Restriction<A>& a ) {
	int Nx, Ny, Nz, i, j, k;
	
	stencil_typ sten_typ = a.Give_stencil_typ();

	// points
	for ( int id = ug->Give_number_points()-1;id >=0;--id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1165
			a.template Update<pointEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1166
1167
1168
1169
1170
		}
		
		if ( ug->Give_point ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<pointEl> ( id ) == yes_mark ) {
			data_points[id][0] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1171
			    a.template Give_data<pointEl> ( id, 0, 0, 0, 0, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1172
1173
1174
1175
1176
1177
		}
	}

	// edges
	for ( int id = ug->Give_number_edges()-1;id >=0;--id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1178
			a.template Update<edgeEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1179
1180
1181
1182
1183
1184
1185
1186
		}
		
		if ( ug->Give_edge ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<edgeEl> ( id ) == yes_mark ) {
			Nx = blockgrid->Give_Nx_edge ( id );
			
			for(i=Nx-1;i>=1;--i )
				data_edges[id][i] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1187
				    a.template Give_data<edgeEl> ( id, i, 0, 0, 0, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1188
1189
1190
1191
1192
1193
1194
		}
	}
	

	// quadrangles
	for ( int id = ug->Give_number_quadrangles()-1;id>=0;--id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1195
			a.template Update<quadrangleEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
		}
		
		if ( ug->Give_quadrangle ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<quadrangleEl> ( id ) == yes_mark ) {
			Nx = blockgrid->Give_Nx_quadrangle ( id );
			Ny = blockgrid->Give_Ny_quadrangle ( id );
			
			for(j=Ny-1;j>=1;--j )
				for(i=Nx-1;i>=1;--i ) {
					data_quadrangles[id][i+ ( Nx+1 ) *j] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1206
					    a.template Give_data<quadrangleEl> ( id, i, j, 0, Nx, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
				}
		}
	}
	
	
	// hexahedra	
	for ( int id = ug->Give_number_hexahedra()-1;id>=0;--id ) {
		if ( sten_typ == yes_stencil ) {
			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 );
			
#pragma omp parallel for private(j,i) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
			for(k = Nz-1;k>=1;--k ) {
				for(j = Ny-1;j>=1;--j )
					for(i = Nx-1;i>=1;--i )
						data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1229
						    a.template Give_data<hexahedronEl> ( id, i, j, k, Nx, Ny );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
			}
		}
	}
	
	
}


template <class DTyp>
template <class A>
void Variable<DTyp>::operator= ( const Expr_Restriction_Iterdes<A>& a ) {
	int Nx, Ny, Nz;
	
	stencil_typ sten_typ;
	
	sten_typ = a.Give_stencil_typ();
	
	// hexahedra
	
	for ( int id = 0;id < ug->Give_number_hexahedra();++id ) {
		if ( sten_typ == yes_stencil ) {
			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 );
			
			if(a.iterdes.red_black) {
			   for(int kk = 0;kk < 2;++kk ) for(int jj = 0;jj < 2;++jj ) for (int ii = 0;ii < 2;++ii) {

				    #pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
				    for(int k = 1 + kk;k < Nz;k = k + 2 ) {
					for(int j = 1 + jj;j < Ny;j = j + 2 ) {
					    for(int i = 1 + ii;i < Nx;i = i + 2 ) {
						data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1268
							    a.template Give_data<hexahedronEl> ( id, i, j, k, Nx, Ny );					      
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
					    }
					}
				    }
			   }		  
			  
			  /*
				for ( kk = 0;kk < 2;++kk ) {

				    #pragma omp parallel for private(jj,j,i) num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
				    for ( k = 1 + kk;k < Nz;k = k + 2 ) {
						for ( jj = 0;jj < 2;++jj )
							for ( j = 1 + jj;j < Ny;j = j + 2 ) {
								data_hexahedra[id][1+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1282
								    a.template Give_data<hexahedronEl> ( id, 1, j, k, Nx, Ny );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1283
1284
1285
1286
								    
								for ( i = 2;i < Nx;i = i + 2 ) {
									//for(i=2;i<Nx;i=i+1) {  // so kann man etwas line_blocking machen
									data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1287
									    a.template Give_data<hexahedronEl> ( id, i, j, k, Nx, Ny );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1288
									data_hexahedra[id][i-1+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1289
									    a.template Give_data<hexahedronEl> ( id, i - 1, j, k, Nx, Ny );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1290
1291
1292
1293
								}
								
								if ( Nx >= 2 )
									data_hexahedra[id][Nx-1+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1294
									    a.template Give_data<hexahedronEl> ( id, Nx - 1, j, k, Nx, Ny );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
							}
					}
				}
				*/
			}
			else {

			  #pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(UGBlocks::useOpenMP)
				for(int k = 1;k < Nz;++k ) {
					for(int j = 1;j < Ny;++j ) {
						for(int i = 1;i < Nx;i = i + 1 ) {
							data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1307
							    a.template Give_data<hexahedronEl> ( id, i, j, k, Nx, Ny );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
						}
					}
				}
			}
		}
	}
	
	
	// quadrangles
	for ( int id = 0;id < ug->Give_number_quadrangles();++id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1319
			a.template Update<quadrangleEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
		}
		
		if ( ug->Give_quadrangle ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<quadrangleEl> ( id ) == yes_mark ) {
		        
			Nx = blockgrid->Give_Nx_quadrangle ( id );
			Ny = blockgrid->Give_Ny_quadrangle ( id );
			
			if ( a.iterdes.red_black ) {
				for(int jj = 0;jj < 2;++jj ) {
					for(int j = 1 + jj;j < Ny;j = j + 2 ) { // das ist eigentlich kein red-black!!!!!
						data_quadrangles[id][1+ ( Nx+1 ) *j] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1332
						    a.template Give_data<quadrangleEl> ( id, 1, j, 0, Nx, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1333
1334
1335
						    
						for(int i = 2;i < Nx;i = i + 2 ) {
							data_quadrangles[id][i+ ( Nx+1 ) *j] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1336
							    a.template Give_data<quadrangleEl> ( id, i, j, 0, Nx, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1337
							data_quadrangles[id][i-1+ ( Nx+1 ) *j] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1338
							    a.template Give_data<quadrangleEl> ( id, i - 1, j, 0, Nx, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1339
1340
1341
1342
						}
						
						if ( Nx >= 2 )
							data_quadrangles[id][Nx-1+ ( Nx+1 ) *j] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1343
							    a.template Give_data<quadrangleEl> ( id, Nx - 1, j, 0, Nx, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1344
1345
1346
1347
1348
1349
					}
				}
			} else {
				for(int j = 1;j < Ny;++j )
					for(int i = 1;i < Nx;++i ) {
						data_quadrangles[id][i+ ( Nx+1 ) *j] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1350
						    a.template Give_data<quadrangleEl> ( id, i, j, 0, Nx, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1351
1352
1353
1354
1355
1356
1357
1358
1359
					}
			}
		}
	}
	
	
	// edges
	for(int id = 0;id < ug->Give_number_edges();++id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1360
			a.template Update<edgeEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
		}
		
		if(ug->Give_edge ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<edgeEl> ( id ) == yes_mark ) {
			Nx = blockgrid->Give_Nx_edge ( id );
			
			if(a.iterdes.red_black ) {
				for(int ii = 0;ii < 2;++ii ) {
					for(int i = 1 + ii;i < Nx;i = i + 2 )
						data_edges[id][i] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1371
						    a.template Give_data<edgeEl> ( id, i, 0, 0, 0, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1372
1373
1374
1375
				}
			} else {
				for(int i = 1;i < Nx;++i )
					data_edges[id][i] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1376
					    a.template Give_data<edgeEl> ( id, i, 0, 0, 0, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1377
1378
1379
1380
1381
1382
1383
			}
		}
	}
	
	// points
	for(int id = 0;id < ug->Give_number_points();++id ) {
		if ( sten_typ == yes_stencil ) {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1384
			a.template Update<pointEl> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1385
1386
1387
1388
1389
		}
		
		if(ug->Give_point ( id )->my_object ( my_rank ) &&
		        a.template Give_marker<pointEl> ( id ) == yes_mark ) {
			data_points[id][0] =
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1390
			    a.template Give_data<pointEl> ( id, 0, 0, 0, 0, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
		}
	}
}



template <class DTyp>
template <class A>
void Variable<DTyp>::operator= ( const Expr<A>& a ) {
	int Nx, Ny, Nz;
	
	const A& ao ( a );
	
	stencil_typ sten_typ = ao.Give_stencil_typ();
	control_typ cont_typ = ao.Give_control_typ();
	
	
	bool useOpenMP_here = UGBlocks::useOpenMP && (cont_typ == thread_save);
	
	
	// hexahedra
	
	for(int id = 0;id < ug->Give_number_hexahedra();++id ) {
		if ( sten_typ == yes_stencil ) {
			ao.template Update<hexahedronEl> ( 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 );

//test
//if(cont_typ != thread_save) 
//  std::cout << " not thread_save " << std::endl;		
			
                        #pragma omp parallel for num_threads(UGBlocks::numThreadsToTake) if(useOpenMP_here)
			for(int k = 1;k < Nz;++k ) {
				for(int j = 1;j < Ny;++j )
				    for(int i = 1;i < Nx;++i )
					data_hexahedra[id][i+ ( Nx+1 ) * ( j+ ( Ny+1 ) *k ) ] =
							    ao.template Give_data<hexahedronEl> ( id, i, j, k, Nx, Ny );
			}
		}
	}
	
	// quadrangles
	for ( int id = 0;id < ug->Give_number_quadrangles();++id ) {
		if ( sten_typ == yes_stencil )
			ao.template Update<quadrangleEl> ( id );
			
		if ( ug->Give_quadrangle ( id )->my_object ( my_rank ) ) {
		
			Nx = blockgrid->Give_Nx_quadrangle ( id );
			Ny = blockgrid->Give_Ny_quadrangle ( id );

                        // #pragma omp parallel for private(i) num_threads(UGBlocks::numThreadsToTake) if(useOpenMP_here)			
			for(int j = 1;j < Ny;++j )
				for (int i = 1;i < Nx;++i ) {
					data_quadrangles[id][i+ ( Nx+1 ) *j] =
1452
                        ao.template Give_data<quadrangleEl> ( id, i, j, 0, Nx, 0 );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
				}
		}
		Update<quadrangleEl> ( id );
	}
	
	// edges
	for ( int id = 0;id < ug->Give_number_edges();++id ) {
		if ( sten_typ == yes_stencil )
			ao.template Update<edgeEl> ( id );
			
		if ( ug->Give_edge ( id )->my_object ( my_rank ) ) {
			Nx = blockgrid->Give_Nx_edge ( id );
			
			for(int i = 1;i < Nx;++i )
				data_edges[id][i] =
				    ao.template Give_data<edgeEl> ( id, i, 0, 0, 0, 0 );
		}
		Update<edgeEl> ( id );
	}
	
	// points
	for(int id = 0;id < ug->Give_number_points();++id ) {
		if ( sten_typ == yes_stencil )
			ao.template Update<pointEl> ( id );
			
		if(ug->Give_point ( id )->my_object ( my_rank ) ) {
			data_points[id][0] =
			    ao.template Give_data<pointEl> ( id, 0, 0, 0, 0, 0 );
		}
		Update<pointEl> ( id );
	}
//
//
//        for ( int id = 0;id < ug->Give_number_hexahedra();++id )
//          Update<hexahedronEl> ( id );
//        for ( int id = 0;id < ug->Give_number_quadrangles();++id )
//          Update<quadrangleEl> ( id );
//        for ( int id = 0;id < ug->Give_number_edges();++id )
//          Update<edgeEl> ( id );
//        for ( int id = 0;id < ug->Give_number_points();++id )
//          Update<pointEl> ( id );
}





Phillip Lino Rall's avatar
Phillip Lino Rall committed
1500
1501
1502



Phillip Lino Rall's avatar
Phillip Lino Rall committed
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
/////////////////////////////////////////////////////////////////////////
// 5. Nconst , ... funtions for copy of data
//////////////////////////////////////////////////////////////




inline int Give_Nconst ( dir3D dir, int Nxhex, int Nyhex, int Nzhex ) {
	if ( dir == Wdir3D ) return Nxhex;
	
	if ( dir == Sdir3D ) return ( Nxhex + 1 ) *Nyhex;
	
	if ( dir == Ddir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) *Nzhex;
	
	return 0;
}

inline int Give_Ni ( dir3D dir, int Nxhex, int Nyhex, int Nzhex ) {
	if ( dir == Edir3D ) return   1;
	
	if ( dir == Wdir3D ) return  -1;
	
	if ( dir == Ndir3D ) return   Nxhex + 1;
	
	if ( dir == Sdir3D ) return - ( Nxhex + 1 );
	
	if ( dir == Tdir3D ) return  ( Nxhex + 1 ) * ( Nyhex + 1 );
	
	if ( developer_version )
		if ( dir != Ddir3D ) std::cout << "error in Give_Ni !" <<std::endl;
		
	return - ( Nxhex + 1 ) * ( Nyhex + 1 );
}


// dir3D_sons { WSDdir3D, ESDdir3D, WNDdir3D, ENDdir3D, WSTdir3D, ESTdir3D, WNTdir3D, ENTdir3D };
inline int Give_Nconst ( dir3D_sons Left, dir3D_sons Right, int Nxhex, int Nyhex, int Nzhex ) {
	if ( Left == WSDdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) + Nxhex + 2;
	
	if ( Left == ESDdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) + 2*Nxhex;
	
	if ( Left == WNDdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) + ( Nxhex + 1 ) * ( Nyhex - 1 ) + 1;
	
	if ( Left == ENDdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) + ( Nxhex + 1 ) *Nyhex - 2;
	
	if ( Left == WSTdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) * ( Nzhex - 1 ) + Nxhex + 2;
	
	if ( Left == ESTdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) * ( Nzhex - 1 ) + 2*Nxhex;;
	
	if ( Left == WNTdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) * ( Nzhex - 1 ) + ( Nxhex + 1 ) * ( Nyhex - 1 ) + 1;
	
	if ( developer_version )
		if ( Left != ENTdir3D ) std::cout << "error1 in Give_Nconst !" <<std::endl;
		
	return ( Nxhex + 1 ) * ( Nyhex + 1 ) * ( Nzhex - 1 ) + ( Nxhex + 1 ) *Nyhex - 2;
}

inline int Give_Nj ( dir3D_sons Left, dir3D_sons Right, int Nxhex, int Nyhex, int Nzhex ) {
	if ( Left == WSDdir3D ) {
		if ( Right ==  ESDdir3D ) return 1;
		
		if ( Right ==  WNDdir3D ) return ( Nxhex + 1 );
		
		if ( developer_version )
			if ( Right !=  WSTdir3D ) std::cout << "error1 in Give_Nj !" <<std::endl;
			
		return ( Nxhex + 1 ) * ( Nyhex + 1 );
	}
	
	if ( Left == ESDdir3D ) {
		if ( Right ==  WSDdir3D ) return -1;
		
		if ( Right ==  ENDdir3D ) return ( Nxhex + 1 );
		
		if ( developer_version )
			if ( Right !=  ESTdir3D ) std::cout << "error2 in Give_Nj !" <<std::endl;
			
		return ( Nxhex + 1 ) * ( Nyhex + 1 );
	}
	
	if ( Left == WNDdir3D ) {
		if ( Right ==  ENDdir3D ) return 1;
		
		if ( Right ==  WSDdir3D ) return - ( Nxhex + 1 );
		
		if ( developer_version )
			if ( Right !=  WNTdir3D ) std::cout << "error3 in Give_Nj !" <<std::endl;
			
		return ( Nxhex + 1 ) * ( Nyhex + 1 );
	}
	
	if ( Left == ENDdir3D ) {
		if ( Right ==  WNDdir3D ) return -1;
		
		if ( Right ==  ESDdir3D ) return - ( Nxhex + 1 );
		
		if ( developer_version )
			if ( Right !=  ENTdir3D ) std::cout << "error4 in Give_Nj !" <<std::endl;
			
		return ( Nxhex + 1 ) * ( Nyhex + 1 );
	}
	
	if ( Left == WSTdir3D ) {
		if ( Right ==  ESTdir3D ) return 1;
		
		if ( Right ==  WNTdir3D ) return ( Nxhex + 1 );
		
		if ( developer_version )
			if ( Right !=  WSDdir3D ) std::cout << "error5 in Give_Nj !" <<std::endl;
			
		return - ( Nxhex + 1 ) * ( Nyhex + 1 );
	}
	
	if ( Left == ESTdir3D ) {
		if ( Right ==  WSTdir3D ) return -1;
		
		if ( Right ==  ENTdir3D ) return ( Nxhex + 1 );
		
		if ( developer_version )
			if ( Right !=  ESDdir3D ) std::cout << "error6 in Give_Nj !" <<std::endl;
			
		return - ( Nxhex + 1 ) * ( Nyhex + 1 );
	}
	
	if ( Left == WNTdir3D ) {
		if ( Right ==  ENTdir3D ) return 1;
		
		if ( Right ==  WSTdir3D ) return - ( Nxhex + 1 );
		
		if ( developer_version )
			if ( Right !=  WNDdir3D ) std::cout << "error7 in Give_Nj !" <<std::endl;
			
		return - ( Nxhex + 1 ) * ( Nyhex + 1 );
	}
	
	if ( developer_version )
		if ( Left != ENTdir3D ) std::cout << "error8 in Give_Nj !" <<std::endl;
		
	if ( Right ==  WNTdir3D ) return -1;
	
	if ( Right ==  ESTdir3D ) return - ( Nxhex + 1 );
	
	if ( developer_version )
		if ( Right !=  ENDdir3D ) std::cout << "error9 in Give_Nj !" <<std::endl;
		
	return - ( Nxhex + 1 ) * ( Nyhex + 1 );
}

// dir2D_sons { SWdir2D, SEdir2D, NWdir2D, NEdir2D };
inline int Give_Nconst ( dir2D_sons Left, dir2D_sons Right, int Nxquad, int Nyquad ) {
	if ( Left == SWdir2D )
		return Nxquad + 2;
		
	if ( Left == SEdir2D )
		return 2*Nxquad;
		
	if ( Left == NWdir2D )
		return ( Nxquad + 1 ) * ( Nyquad - 1 ) + 1;
		
	if ( developer_version )
		if ( Left != NEdir2D ) std::cout << "error2 in Give_Nconst !" <<std::endl;
		
	return ( Nxquad + 1 ) *Nyquad - 2;
}

inline int Give_Nj ( dir2D_sons Left, dir2D_sons Right, int Nxquad, int Nyquad ) {
	if ( Left == SWdir2D ) {
		if ( Right ==  SEdir2D ) return 1;
		
		if ( developer_version )
			if ( Right !=  NWdir2D ) std::cout << "error10 in Give_Nj !" <<std::endl;
			
		return ( Nxquad + 1 );
	}
	
	if ( Left == SEdir2D ) {
		if ( Right ==  SWdir2D ) return -1;
		
		if ( developer_version )
			if ( Right !=  NEdir2D ) std::cout << "error11 in Give_Nj !" <<std::endl;
			
		return ( Nxquad + 1 );
	}
	
	if ( Left == NWdir2D ) {
		if ( Right ==  NEdir2D ) return 1;
		
		if ( developer_version )
			if ( Right !=  SWdir2D ) std::cout << "error12 in Give_Nj !" <<std::endl;
			
		return - ( Nxquad + 1 );
	}
	
	if ( developer_version )
		if ( Left != NEdir2D ) std::cout << "error13 in Give_Nj !" <<std::endl;
		
	if ( Right ==  NWdir2D ) return -1;
	
	if ( developer_version )
		if ( Right !=  SEdir2D ) std::cout << "error14 in Give_Nj !" <<std::endl;
		
	return - ( Nxquad + 1 );
}

// dir3D_sons { WSDdir3D, ESDdir3D, WNDdir3D, ENDdir3D, WSTdir3D, ESTdir3D, WNTdir3D, ENTdir3D };
inline int Give_Nconst ( dir3D_sons son, int Nxhex, int Nyhex, int Nzhex ) {
	if ( son == WSDdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) + Nxhex + 2;
	
	if ( son == ESDdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) + 2*Nxhex;
	
	if ( son == WNDdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) + ( Nxhex + 1 ) * ( Nyhex - 1 ) + 1;
	
	if ( son == ENDdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) + ( Nxhex + 1 ) *Nyhex - 2;
	
	if ( son == WSTdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) * ( Nzhex - 1 ) + Nxhex + 2;
	
	if ( son == ESTdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) * ( Nzhex - 1 ) + 2*Nxhex;;
	
	if ( son == WNTdir3D ) return ( Nxhex + 1 ) * ( Nyhex + 1 ) * ( Nzhex - 1 ) + ( Nxhex + 1 ) * ( Nyhex - 1 ) + 1;
	
	if ( developer_version )
		if ( son != ENTdir3D ) std::cout << "error3 in Give_Nconst !" <<std::endl;
		
	return ( Nxhex + 1 ) * ( Nyhex + 1 ) * ( Nzhex - 1 ) + ( Nxhex + 1 ) *Nyhex - 2;
}

// dir2D_sons { SWdir2D, SEdir2D, NWdir2D, NEdir2D };
inline int Give_Nconst ( dir2D_sons son, int Nxquad, int Nyquad ) {
	if ( son == SWdir2D )
		return Nxquad + 2;
		
	if ( son == SEdir2D )
		return 2*Nxquad;
		
	if ( son == NWdir2D )
		return ( Nxquad + 1 ) * ( Nyquad - 1 ) + 1;
		
	if ( developer_version )
		if ( son != NEdir2D ) std::cout << "error4 in Give_Nconst !" <<std::endl;
		
	return ( Nxquad + 1 ) *Nyquad - 2;
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
1746
/*
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
template <class DTyp>
class Cell_variable;

template <class DTyp>
class Expr_interpolant_cell_to_point : public Expr<Expr_interpolant_cell_to_point< DTyp> >  {
 private:
  const Cell_variable< DTyp > & a_;

 public:
  Expr_interpolant_cell_to_point(const Cell_variable<DTyp>& a) : a_(a) {}

  template <elementTyp TYP_EL>
  inline DTyp Give_data ( params_in) const {
    switch(TYP_EL) {
      case hexahedronEl:
        Give_data_hexahedronEl(params_out);
      case edgeEl:
        Give_data_edgeEl(params_out);
      case pointEl:
        Give_data_pointEl(params_out);
    }
  }
  inline DTyp Give_data_hexahedronEl ( params_in) const;
  inline DTyp Give_data_edgeEl ( params_in) const;
  inline DTyp Give_data_pointEl ( params_in) const;

  template <elementTyp TYP_EL>
  void Update(int id) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1775
    a_.template Update<TYP_EL>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
  }

};

template <class DTyp>
inline DTyp Expr_interpolant_cell_to_point<DTyp>::Give_data_hexahedronEl ( params_in) const {
  return 0.125 * (a_.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i  ,j  ,k  ,Nx,Ny) +
                  a_.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i+1,j  ,k  ,Nx,Ny) +
                  a_.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i  ,j+1,k  ,Nx,Ny) +
                  a_.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i+1,j+1,k  ,Nx,Ny) +
                  a_.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i  ,j  ,k+1,Nx,Ny) +
                  a_.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i+1,j  ,k+1,Nx,Ny) +
                  a_.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i  ,j+1,k+1,Nx,Ny) +
                  a_.Give_cell_hexahedra(id,Ind_loc_matrix_hexahedra(i,j,k),i+1,j+1,k+1,Nx,Ny));
}

template <class DTyp>
inline DTyp Expr_interpolant_cell_to_point<DTyp>::Give_data_edgeEl ( params_in) const {
  return 0;
//  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 <class DTyp>
inline DTyp Expr_interpolant_cell_to_point<DTyp>::Give_data_pointEl ( params_in) const {
  return 0;
//  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 <class DTyp>
inline Expr_interpolant_cell_to_point<DTyp> Point_interpolation(const Cell_variable< DTyp >& a) {
  return Expr_interpolant_cell_to_point<DTyp>(a);
}
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1822
*/
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1823
#endif // VARIABLE_H