ug.h 13.6 KB
Newer Older
Phillip Lino Rall's avatar
Phillip Lino Rall committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**********************************************************************************
 * 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.
 **********************************************************************************/


#ifndef UG_H
#define UG_H
// next two includes for exception handling
#include <stdexcept>
#include <string>
#include <list>
#include <vector>
27
#include <algorithm>
28
#include <math_lib.h>
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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


////////////////////////////////////////////////////////////////
//
//  1. class Not_constant_direction_marker
//           this class is for special stencils
//           this class is currently not really in use
//  2. class Zordering: this class orders all geometric objects in z-direction
//
//  3. class Unstructured_grid and other classes
//           main class describing an unstructured grid
//
//  4. UG mit z-direction um slize und so auf 2D Gitter machen zu können
//
//  5. some inline functions
//
////////////////////////////////////////////////////////////////


class Marker;
class Unstructured_grid;



////////////////////////////////////////////////////////////////
//
//  1. class Not_constant_direction_marker
//           this class is for special stencils
//           this class is currently not really in use
//
////////////////////////////////////////////////////////////////

void Calculate_corresponding_corners(dir3D_sons corner, dir3D_sons& SED_corner,
                                     dir3D_sons& NWD_corner, dir3D_sons& SWT_corner);


class Not_constant_direction_marker {
 public:
  Not_constant_direction_marker(Unstructured_grid* grid);
68
  ~Not_constant_direction_marker();
Phillip Lino Rall's avatar
Phillip Lino Rall committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  int stenIndex(int i, int j, int k, int Nx, int Ny, int id) const {
    return ((i-1)*not_const_x[id]  +  ((Nx-2)*not_const_x[id] + 1)*
	    ((j-1)*not_const_y[id]  +  ((Ny-2)*not_const_y[id] + 1)*
	     ((k-1)*not_const_z[id])))
      *27;  // new version with constant directions
  }
  
  bool Not_const_x(int id) const { return not_const_x[id]; };
  bool Not_const_y(int id) const { return not_const_y[id]; };
  bool Not_const_z(int id) const { return not_const_z[id]; };

  int  Give_number_hexahedra() { return num_hexahedra; }

  void Mark_x_as_not_constant_at(int i, bool bb);
  void Mark_y_as_not_constant_at(int i, bool bb);
  void Mark_z_as_not_constant_at(int i, bool bb);

 private:
  int num_hexahedra;
  
  bool* not_const_x;
  bool* not_const_y;
  bool* not_const_z;
};

//////////////////////////////////////////////////////////////////
//
//  2. class Zordering: this class orders all geometric objects in z-direction
//
//////////////////////////////////////////////////////////////////

class Zordering {
 public:
  Zordering(Unstructured_grid* ug);
  ~Zordering();

  int         Give_number_indizes() { return number_indizes; }
  int         Give_index(int i) { return indices[i]; }
  elementTyp Give_type(int  i) { return type_index[i]; }

  void Print(Unstructured_grid* ug);
  

 private:
  int* indices;
  elementTyp* type_index;
  int number_indizes;
};

//////////////////////////////////////////////////////////////////
//
//  3. class Unstructured_grid and other classes
//           main class describing an unstructured grid
//////////////////////////////////////////////////////////////////

Phillip Lino Rall's avatar
Phillip Lino Rall committed
124
enum TypeOfUG { noWithZTyp = 0, hexahedronUgTyp = 1, cylinderUgTyp = 2, cylinderListUgTyp = 3, hexahedronAdaptiveUgTyp = 4, hexahedronListUgTyp = 5,hexahedronListTestUgTyp = 6, lensUgTyp = 7  };
Phillip Lino Rall's avatar
Phillip Lino Rall committed
125
126
127
128
129
130
131
132
133
134
135
136

// This is base class of every object which needs data from ug Unstructured_grid
class Object_based_on_ug {
public:
  Object_based_on_ug(Unstructured_grid* ug);
  virtual void Delete_data() = 0;
protected:
  void Unregister(Unstructured_grid* ug);
};



Christoph Pflaum's avatar
Christoph Pflaum committed
137
138
/** \addtogroup GridGeneration **/
/* @{ */   
Phillip Lino Rall's avatar
Phillip Lino Rall committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
class Unstructured_grid : public Partitioning {
  public:
    Unstructured_grid();
    ~Unstructured_grid();
    TypeOfUG getUgTyp() { return typFuerSlice; }
    
    std::vector<double> getConstructionParameters() { return constructionParameters; } 
    std::vector<double> getConstructionParametersLx() { return construction_lx; }
    std::vector<double> getConstructionParametersLy() { return construction_ly; }
    std::vector<double> getConstructionParametersLz() { return construction_lz; }
    bool getConstructionBoolArched() { return constructionBoolArched; }
    bool getConstructionBoolPeriodic() { return constructionBoolPeriodic;}
    std::vector<double> getRelativeCoord() { return relativeCoordVector; }
    
    
    
    void Add_object(Object_based_on_ug *obj);
    void Remove_object(Object_based_on_ug *obj); 

    virtual bool isComposeGrid() { return false; }

    // for parallel
    void Make_Partitioning(MPI_Comm com);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
162
163
164
165
    /**
     * Step 2: Function called in construction of UG-Block
     * @param num_points_ Anzhal der Points
     **/
Phillip Lino Rall's avatar
Phillip Lino Rall committed
166
167
168

    void Set_number_points(int num_points_);
    int  Give_number_points() { return num_points; }
Phillip Lino Rall's avatar
Phillip Lino Rall committed
169
170
171
172
173
174
175


    /**
     * Step 3: Function called in construction of UG-Block
     * @param id index of point
     * @param coord geometric coordinate of this point
     */
Phillip Lino Rall's avatar
Phillip Lino Rall committed
176
177
    void Set_coordinate_point(int id, D3vector coord);

Phillip Lino Rall's avatar
Phillip Lino Rall committed
178
179
180
181
182
183
    /**
     * Step 1: Function called in construction of UG-Block
     * @param num_hexahedra_ Anzhal der Hexahedra
     **/


Phillip Lino Rall's avatar
Phillip Lino Rall committed
184
185
186
187
188
189
    void Set_number_hexahedra(int num_hexahedra_);
    int  Give_number_hexahedra() { return num_hexahedra; }

    int  Give_number_edges() { return num_edges; }
    int  Give_number_quadrangles() { return num_quadrangles; }

190
    bool Give_transform_From_Quadrangle() {return transformFromQuadrangle;}
Phillip Lino Rall's avatar
Phillip Lino Rall committed
191
192
//    bool Adjacent(int num_hex, int num_edge);

193
194
    void Set_edge_to_quad_id(int index, int value){ if(index < Give_number_edges()){edge_to_quad_id.at(index) = value; } };
    int Give_edge_to_quad_id(int index){ if(index < Give_number_edges()){return edge_to_quad_id.at(index); } };
195

196
197
    void Set_edge_to_quad_dir(int index, int value){ if(index < Give_number_edges()){edge_to_quad_dir.at(index) = value; } };
    int Give_edge_to_quad_dir(int index){ if(index < Give_number_edges()){return edge_to_quad_dir.at(index); } };
198

Phillip Lino Rall's avatar
Phillip Lino Rall committed
199
200
201
202
203
    Hexahedron_el* Give_hexahedron(int i) { return &(hexahedra[i]); }
    Quadrangle_el* Give_quadrangle(int i) { return &(quadrangles[i]); }
    Edge_el* Give_edge(int i) { return &(edges[i]); }
    Point_el* Give_point(int i) { return &(points[i]); }
    inline Geometric_Object* Give_geometric_object(elementTyp el_typ, int i);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
204
205
206
207
208
    /**
     * Step 4: Function called in construction of UG-Block
     * @param id index of hexahedron
     * @param i_WSD ... i_ENT index of corresponding point of corner of hexahedron
     **/
Phillip Lino Rall's avatar
Phillip Lino Rall committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224

    void Set_hexahedron(int id,
			int i_WSD, int i_ESD, int i_WND, int i_END,
			int i_WST, int i_EST, int i_WNT, int i_ENT);

    // for hexahedra with perodic boundary conditions:
    void Set_hexahedron(int id,
			int i_WSD, int i_ESD, int i_WND, int i_END,
			int i_WST, int i_EST, int i_WNT, int i_ENT,
			D3vector coord_WSD, D3vector coord_ESD,
			D3vector coord_WND, D3vector coord_END,
			D3vector coord_WST, D3vector coord_EST,
			D3vector coord_WNT, D3vector coord_ENT);



Phillip Lino Rall's avatar
Phillip Lino Rall committed
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
    /**
     * Step 5: Function called in construction of UG-Block
     * calculates edges and faces
     **/
    void construction_hexahedron_points_done();

     /**
      * Step 5: Function called in construction of UG-Block
      * ``transform'' must be zero vector at 0,1
      * transform: [0,1] ->  D3vector
      * transform(t,pointer_global_data)
      * @param idL index of left point
      * @param idR index of right point
      * @param transform transformation function
      **/
    void Set_transformation_edge(int idL,
                 int idR, D3vector (*transform)(double, double*),
Phillip Lino Rall's avatar
Phillip Lino Rall committed
242
                                 int shift_of_pointer = 0);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
243

Phillip Lino Rall's avatar
Phillip Lino Rall committed
244
                                    // ``transform'' must be zero vector at 0,1
Phillip Lino Rall's avatar
Phillip Lino Rall committed
245
246
247
248
                                    // transform: [0,1] ->  D3vector
									// 
    void Set_transformation_edge_from_face(int idL, int idR, D3vector (*transform)(double,double, double*),
                                           int shift_of_pointer = 0);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
249

Phillip Lino Rall's avatar
Phillip Lino Rall committed
250
251
252
    void Set_transformation_edge_of_hexahedron(int id_hex, Edges_cell ed, D3vector (*transform)(double, double*));
                                    // ``transform'' must be zero vector at 0,1
                                    // transform: [0,1] ->  D3vector
Phillip Lino Rall's avatar
Phillip Lino Rall committed
253
254
255
256

    void Set_transformation_hex(int id_hex, D3vector (*transform)(int, double,double,double));
                                    // transform of hex id_hex: [0,1]^3 ->  D3vector
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
257
258
259
260
261
262
263
264
265
266
267
268
    /**
     * Step 6: Function called in construction of UG-Block
     *
     * not implemented
     *
     * ``transform'' must be zero vector at edges of face
     * transform: [0,1]x[0,1] ->  D3vector
     * transform(tEW,tNS,pointer_global_data)
     * @param idSW ... idNE  index of corner points of face
     * @param transform transformation function
     **/

Phillip Lino Rall's avatar
Phillip Lino Rall committed
269
    void Set_transformation_face(int idSW, int idSE, int idNW, int idNE, D3vector (*Transform)(double, double, double*), int shift_of_pointer = 0);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
270
271
                                 // ``transform'' must be zero at (0,0), ...

Phillip Lino Rall's avatar
Phillip Lino Rall committed
272
273
274
275
    /**
      * Step 7: Function called in construction of UG-Block
     **/

Phillip Lino Rall's avatar
Phillip Lino Rall committed
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    void construction_done();

    int  degree_of_freedom()  { return number_degree_of_freedom; };
    inline int Give_color_of_edge(int id_edge);

    void Print_AVS(ofstream *Datei);
    void Print_Dx(ofstream *Datei);

    void Print();

    Marker& Give_all_points() { return *all_points; };
    Not_constant_direction_marker* Give_not_constant_directions() { return my_not_constant_directions; }

    Zordering* Give_Zordering() { return zordering; }

    double* Get_pointer_global_data() { return pointer_global_data; }
292
    std::vector<D3vector> getBoundaryPoints(){return boundaryPoints;}
Phillip Lino Rall's avatar
Phillip Lino Rall committed
293
294
295
296
    int sizeGlobalPointerData() { return size_pointer_global_data; } 
  protected:
	 // pointer for global objects used in coordinate transformations
     double* pointer_global_data;
297
     std::vector<D3vector> boundaryPoints;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
298
299
300
301
302
303
304
305
     int size_pointer_global_data;
     
     TypeOfUG typFuerSlice;

     std::vector<double> constructionParameters;     
     std::vector<double> relativeCoordVector;
     std::vector<double> construction_lx, construction_ly, construction_lz;
     bool constructionBoolArched;
306
     bool constructionBoolPeriodic{false};
307
     bool transformFromQuadrangle;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
308
309
310
311
312
313
314
     
     
  private:
    bool construction_hexahedron_points_done_yn;
    bool construction_done_yn;

    bool periodic;   // is num_poi == num_poi_plus_periodic
Phillip Lino Rall's avatar
Phillip Lino Rall committed
315
    //* Necessary for getting edge transfrom from quad transform. Stores edge id and the direction, such that the correct edge from the quad is used.
316
317
    std::vector<int> edge_to_quad_id;
    std::vector<int> edge_to_quad_dir;
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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

    Topf<2, sorted_pair> topf_edges;         //  spaeter löschen?
    Topf<4, sorted_quad> topf_quadrangles;   //  spaeter löschen?

    int num_points;
    int num_edges;
    int num_quadrangles;
    int num_hexahedra;

    Point_el*      points;      //[num_poi_plus_periodic];
    Edge_el*       edges;       //[num_edges];
public:  
// FIXME: Nur zum testen public
    Quadrangle_el* quadrangles; //[num_quadrangles];
private:
    Hexahedron_el* hexahedra;   //[num_poi_hexahedra];

    int number_degree_of_freedom;

    void Set_recursive_color(int id_edge, int color);

    Marker* all_points;

    Not_constant_direction_marker* my_not_constant_directions;
    
    // function called in construction_hexahedron_points_done()
  void Set_coordinates_quadrangles();
  void Set_coordinates_edges();

  Zordering* zordering;


  
  
  typedef std::list<Object_based_on_ug*> Object_list;
  Object_list  all_objects_based_on_ug;

};
Christoph Pflaum's avatar
Christoph Pflaum committed
356
357
/* @} */

Phillip Lino Rall's avatar
Phillip Lino Rall committed
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
//////////////////////////////////////////////////////////////////
// 4. UG mit z-direction um slize und so auf 2D Gitter machen zu können
//////////////////////////////////////////////////////////////////

class UG_WithZdirection : public Unstructured_grid {
   public: 
     int getNummerBlockZ(double z) { for(int i=1;i<Lz.size();++i) if(z<=Lz.at(i)) return i-1; return Lz.size()-2;  }
     int getNummernBloecke() { return Lz.size()-1; }
     double zLeft( int nummerBlockZ) { return Lz.at(nummerBlockZ); }
     double zRight(int nummerBlockZ) { return Lz.at(nummerBlockZ+1); }
   protected:
     UG_WithZdirection(TypeOfUG type,int sizeLz) : Unstructured_grid() { 
       typFuerSlice = type;  assert(typFuerSlice!=noWithZTyp); 
       Lz.resize(sizeLz);
     }
     std::vector<double> Lz; ///> coordinates in z-direction
};

//////////////////////////////////////////////////////////////////
// 5. some inline functions
//////////////////////////////////////////////////////////////////

inline Geometric_Object* Unstructured_grid::Give_geometric_object(elementTyp el_typ, int i){
   if(el_typ == hexahedronEl)
      return &(hexahedra[i]);
   if(el_typ == quadrangleEl)
      return &(quadrangles[i]);
   if(el_typ == edgeEl)
      return &(edges[i]);
   if(developer_version)
       if(el_typ != pointEl) std::cout << "error in Give_geometric_object !" << std::endl;
   return &(points[i]);
}

inline int Unstructured_grid::Give_color_of_edge(int id_edge) {
  return edges[id_edge].Give_color_of_edge();
}



#endif // UG_H