blockgrid2D.h 6.02 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
/**********************************************************************************
 * 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 BLOCKGRID2D_H
#define BLOCKGRID2D_H
#include <vector>
/*
Ny    *  *  *  *  *  *
Ny-1  *  +  +  +  +  *
3     *  +  +  +  +  *
2     *  +  +  +  +  *
1     *  +  +  +  +  *
0     *  *  *  *  *  *
      0  1  2  3 Nx-1 Nx
*/

template <class DTyp>
class Variable2D;

class  Blockgrid2D {
 public:
  Blockgrid2D(Unstructured2DGrid *ug);
  Blockgrid2D(Unstructured2DGrid *ug, int N);
  Blockgrid2D(Unstructured2DGrid *ug, int Nx,  int Ny);
    /** Constructor for disc
  *** @param Nx: Number of grid points in x-direction
  *** @param Ny: Number of grid points in y-direction
  *** @param Nr: Number of grid points in radial direction
  **/
  Blockgrid2D(Unstructured2DGrid *ug, int Nx,  int Ny, int Nr);

  Blockgrid2D(Unstructured2DGrid *ug, const std::vector<int>& N);

  Blockgrid2D(Unstructured2DGrid *ug, const std::vector<int>& Nx,  const std::vector<int>&Ny);

  Blockgrid2D(const Blockgrid2D& copy, const std::vector<int>& number_points);

  Blockgrid2D(const Blockgrid2D& copy);

  ~Blockgrid2D();

  bool hasSameStructure(const Blockgrid2D& otherBg) { return true; } 
  
  /**
   * @param strechDomainX streched die Geometrie um Faktor strechDomainX in x-Richtung
   * @param strechDomainY streched die Geometrie um Faktor strechDomainY in y-Richtung
   */
  void SetDomainStrech(double strechDomainX_,double strechDomainY_) { strechDomainX = strechDomainX_; strechDomainY = strechDomainY_; }
64
65
66
  double getStrechX() const { return strechDomainX; }
  double getStrechY() const { return strechDomainY; }
  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  inline bool inStrechedDomain(const D2vector& point_coord);
  double MinimumStrechedX() { return ug->MinimumX()*strechDomainX; };
  double MinimumStrechedY() { return ug->MinimumY()*strechDomainY; };
  double MaximumStrechedX() { return ug->MaximumX()*strechDomainX; };
  double MaximumStrechedY() { return ug->MaximumY()*strechDomainY; };
    
  void Set_grid_points(int d, int Nd);
  Unstructured2DGrid* Give_unstructured_grid() const { return ug; };

  D2vector Give_coord_rectangle(int id, int i, int j) const;
  D2vector Give_coord_edge(int id, int i) const;
  D2vector Give_coord_point(int id) const;

  int Give_Nx_rectangle(int id) const;
  int Give_Ny_rectangle(int id) const;

  int Give_N_total_rectangle(int id) const;

  const std::vector<int>& Give_N() const;

  int Give_Nx_edge(int id) const;

  int Give_N_color(int color) const; 

  int Total_number_of_points();



  Blockgrid2D CopyRefinement(std::vector<int>& N) const;

  void Refine(std::vector<int>& N);

  /**
   * Verschiebung der Indizes in einer Richtung
   * Diese Funktion verwNEdiret man oft nacheinder in x und y Richtung
   * und addiert Nconst auf. 
   * Indizes bezüglich Zellen
   * */
  inline static int Give_Nconst_cell ( dir2D dir, int Nxrec, int Nyrec);
  
   /**
   * Index der Zelle an der Ecke son
   * Indizes bezüglich Zellen
   * */
  inline static int Give_Nconst_cell (dir2D_sons son, int Nxrec, int Nyrec);
  
 
  /**
   * Indizes des inneren Punktes im Quadrangle an der Ecke son
   * Indizes bezüglich Punkte
   * */
  inline static int Give_Nconst(dir2D_sons son, int Nxrec, int Nyrec);

  int getId() { return id_of_grid; }
 protected:
  std::vector<int> number_points;    // number_points[i] 
                         // Anzahl der Punkte in Richtung i
                         // i=0, ..., degree_of_freedom()-1
  bool variable_set;     // set true falls eine Variable konstruiert

 private: 
  Unstructured2DGrid *ug;
  
  int id_of_grid;
  static int id_count_grid;
  
  double strechDomainX;
  double strechDomainY;  
};


// inline Funtionen
//-------------------------------------
bool Blockgrid2D::inStrechedDomain(const D2vector& point_coord) { 
     D2vector point_streched(point_coord.x/strechDomainX,point_coord.y/strechDomainY);
     return ug->inDomain(point_streched); 
}

inline int Blockgrid2D::Give_Nconst_cell ( dir2D dir, int Nxrec, int Nyrec) {
  /* old
	if ( dir == Wdir2D ) return   Nxrec;
	if ( dir == Sdir2D ) return ( Nxrec + 1 ) *Nyrec;
	return 0;
	*/
  	if ( dir == Wdir2D ) return  Nxrec-1;
	if ( dir == Ndir2D ) return  Nxrec * (Nyrec-1);
	return 0;
	//Index Zelle: (j*Nx+i)
	//  i=0,...,Nx-1,  j=0,...,Ny-1
}
   
// Index der Zelle an der Ecke son
inline int Blockgrid2D::Give_Nconst_cell (dir2D_sons son, int Nxrec, int Nyrec) {
   if(son == SWdir2D) return 0;
   if(son == SEdir2D) return Nxrec-1;
   if(son == NWdir2D) return Nxrec*(Nyrec-1);
   // son == NEdir2D
   return                Nxrec*(Nyrec-1)+Nxrec-1;
   //Index Zelle: (j*Nx+i)
   //  i=0,...,Nx-1,  j=0,...,Ny-1
}

// dir2D_sons { SWdir2D, SEdir2D, NWdir2D, NEdir2D };
inline int Blockgrid2D::Give_Nconst(dir2D_sons son, int Nxrec, int Nyrec) {
   if(son == SWdir2D) return Nxrec + 2;
   if(son == SEdir2D) return 2*Nxrec;
   if(son == NWdir2D) return (Nxrec+1) * Nyrec - Nxrec;
   // son == NEdir2D
   return                (Nxrec+1) * Nyrec - 2;

   //Bsp Nx=3, Ny=4
   //
   // ++++
   // +--+
   // +--+
   // +--+     
   // ++++     

   // WS:   3 + 2 = 5
   // 4  5
   // 0  1  2  3 

   // ES:   2*3   = 6
   // 4  5  6
   // 0  1  2  3 

   // WN:   4*4 - 3   = 13
   // 12 13
   // 8  9  10 11
   // 4  5  6  7
   // 0  1  2  3 
   
   // EN:   4*4 - 2 = 14
   // 12 13 14
   // 8  9  10 11
   // 4  5  6  7
   // 0  1  2  3   
}

#endif // BLOCKGRID_H