ParMooN
 All Classes Functions Variables Friends Pages
Benchmark.h
1 // Navier-Stokes problem, Benchmark problem
2 //
3 // u(x,y) = unknown
4 // p(x,y) = unknown
5 
6 void ExampleFile()
7 {
8  OutPut("Example: Benchmark.h" << endl) ;
9 }
10 
11 #define __BENCH__
12 
13 #include <Joint.h>
14 #include <BoundEdge.h>
15 #include <BoundComp.h>
16 #include <FE2D.h>
17 #include <FEDesc2D.h>
18 // ========================================================================
19 // exact solution
20 // ========================================================================
21 void ExactU1(double x, double y, double *values)
22 {
23  values[0] = 0;
24  values[1] = 0;
25  values[2] = 0;
26  values[3] = 0;
27 }
28 
29 void ExactU2(double x, double y, double *values)
30 {
31  values[0] = 0;
32  values[1] = 0;
33  values[2] = 0;
34  values[3] = 0;
35 }
36 
37 void ExactP(double x, double y, double *values)
38 {
39  values[0] = 0;
40  values[1] = 0;
41  values[2] = 0;
42  values[3] = 0;
43 }
44 
45 // ========================================================================
46 // boundary conditions
47 // ========================================================================
48 void BoundCondition(int i, double t, BoundCond &cond)
49 {
50  switch(i)
51  {
52  case 0:
53  cond = SLIP_FRICTION_PENETRATION_RESISTANCE;
54  TDatabase::ParamDB->INTERNAL_SLIP_WITH_FRICTION=1;
55 // cond = DIRICHLET;
56  break;
57  case 2:
58 // cond = SLIP_FRICTION_PENETRATION_RESISTANCE;
59 // TDatabase::ParamDB->INTERNAL_SLIP_WITH_FRICTION=1;
60  cond = DIRICHLET;
61  break;
62 
63  case 1:
64  cond = NEUMANN;
65 // cond = DIRICHLET;
66  TDatabase::ParamDB->INTERNAL_PROJECT_PRESSURE = 0;
67  break;
68 
69  case 3:
70  case 4:
71  cond = DIRICHLET;
72  break;
73  default: cout << "wrong boundary part number: " << i << endl;
74  }
75 }
76 
77 void U1BoundValue(int BdComp, double Param, double &value)
78 {
79  switch(BdComp)
80  {
81  case 0: value = 0;
82  break;
83  case 1: value=0;
84  break;
85  case 2: value = 0;
86  break;
87  case 3:
88 // value=1.2*Param*(1-Param) ;
89  value= Param;
90 // cout<<Param<<" "<<value<<endl;
91  break;
92  case 4: value=0;
93  break;
94  default: cout << "wrong boundary part number: " << BdComp << endl;
95  }
96 }
97 
98 void U2BoundValue(int BdComp, double Param, double &value)
99 {
100  value = 0;
101  if(BdComp>4) cout << "wrong boundary part number: " << BdComp << endl;
102 }
103 
104 // ========================================================================
105 // coefficients for Stokes form: A, B1, B2, f1, f2
106 // ========================================================================
107 void LinCoeffs(int n_points, double *x, double *y,
108  double **parameters, double **coeffs)
109 {
110  double eps = 1/TDatabase::ParamDB->RE_NR;
111  int i;
112  double *coeff;
113 
114  for(i=0;i<n_points;i++)
115  {
116  coeff = coeffs[i];
117 
118  coeff[0] = eps;
119  coeff[1] = 0; // f1
120  coeff[2] = 0; // f2
121  }
122 }
123 
124 
126 void GetCdCl(TFEFunction2D *u1fct, TFEFunction2D *u2fct,
127  TFEFunction2D *pfct, TFEFunction2D *u1old,
128  TFEFunction2D *u2old,
129  double &cd, double &cl)
130 {
131  int i,j,k,l, N_;
132  int N_Points,N_Edges,comp,ed_nr;
133  double *weights, *xi, *eta;
134  double X[MaxN_QuadPoints_2D];
135  double Y[MaxN_QuadPoints_2D];
136  double AbsDetjk[MaxN_QuadPoints_2D];
137  int N_LocalUsedElements;
138  FE2D LocalUsedElements[2], CurrentElement;
139  int *DOF;
140  double **OrigFEValues, *Orig;
141  bool SecondDer[2] = { FALSE, FALSE };
142  double *u1, *u2, *p;
143  TFESpace2D *USpace, *PSpace;
144  int *UGlobalNumbers, *UBeginIndex;
145  int *PGlobalNumbers, *PBeginIndex;
146  int *N_BaseFunct, N_Cells;
147  BaseFunct2D BaseFunct, *BaseFuncts;
148  TCollection *Coll;
149  TBaseCell *cell;
150  double value, value1, value2, value3;
151  double FEFunctValues[MaxN_BaseFunctions2D];
152  double FEFunctValues1[MaxN_BaseFunctions2D];
153  double FEFunctValues2[MaxN_BaseFunctions2D];
154  double FEFunctValues3[MaxN_BaseFunctions2D];
155  int N_DerivativesU = 3;
156  double *Derivatives[MaxN_BaseFunctions2D];
157  MultiIndex2D NeededDerivatives[3] = { D00, D10, D01 };
158  TFEFunction2D *vfct;
159  double *v, nu = 1/TDatabase::ParamDB->RE_NR;
160  double *Der, *aux;
161  TJoint *joint;
162  TBoundEdge *boundedge;
163  TBoundComp *BoundComp;
164  TFE2D *eleCell;
165  FE2D FEEle;
166  TFEDesc2D *FEDesc;
167  int N_DOF_Circ, *DOF_Circ;
168  char VString[] = "v";
169 
170  u1 = u1fct->GetValues();
171  u2 = u2fct->GetValues();
172  p = pfct->GetValues();
173 
174  USpace = u1fct->GetFESpace2D();
175  PSpace = pfct->GetFESpace2D();
176 
177  UGlobalNumbers = USpace->GetGlobalNumbers();
178  UBeginIndex = USpace->GetBeginIndex();
179 
180  PGlobalNumbers = PSpace->GetGlobalNumbers();
181  PBeginIndex = PSpace->GetBeginIndex();
182 
185 
186  aux = new double [MaxN_QuadPoints_2D*10];
187  for(j=0;j<MaxN_QuadPoints_2D;j++)
188  Derivatives[j] = aux + j*10;
189 
190  N_ = u1fct->GetLength();
191  v = new double[N_];
192  memset(v,0,N_*SizeOfDouble);
193  vfct = new TFEFunction2D(USpace, VString, VString, v, N_);
194 
195 // ########################################################################
196 // loop over all cells
197 // ########################################################################
198  Coll = USpace->GetCollection(); // all spaces use same Coll
199  N_Cells = Coll->GetN_Cells();
200 
201  for(i=0;i<N_Cells;i++)
202  {
203  cell = Coll->GetCell(i);
204  N_Edges=cell->GetN_Edges();
205  for(j=0;j<N_Edges;j++) // loop over all edges of cell
206  {
207  joint=cell->GetJoint(j);
208  if ((joint->GetType() == BoundaryEdge)||
209  (joint->GetType() == IsoBoundEdge)) // boundary edge
210  {
211 
212  boundedge=(TBoundEdge *)joint;
213  BoundComp=boundedge->GetBoundComp(); // get boundary component
214  comp=BoundComp->GetID(); // boundary id
215  if (comp==4)
216  {
217  FEEle = USpace->GetFE2D(i,cell); // finite element of cell
218  eleCell = TFEDatabase2D::GetFE2D(FEEle);
219  FEDesc = eleCell->GetFEDesc2D(); // fe descriptor
220  N_DOF_Circ = FEDesc->GetN_JointDOF(); // # local dofs on joints
221  DOF_Circ = FEDesc->GetJointDOF(j); // local dofs on joint j
222  DOF = UGlobalNumbers + UBeginIndex[i]; // pointer to global dofs
223  for (k=0;k<N_DOF_Circ;k++) // set fe on circle to 1
224  v[DOF[DOF_Circ[k]]] = 1;
225  }
226  }
227  }
228  }
229 
230  cd = 0;
231  cl = 0;
232 
233 // ########################################################################
234 // loop over all cells
235 // ########################################################################
236  Coll = USpace->GetCollection(); // all spaces use same Coll
237  N_Cells = Coll->GetN_Cells();
238  for(i=0;i<N_Cells;i++)
239  {
240  cell = Coll->GetCell(i);
241 
242  // ####################################################################
243  // find local used elements on this cell
244  // ####################################################################
245  N_LocalUsedElements = 2;
246  LocalUsedElements[0] = USpace->GetFE2D(i, cell);
247  LocalUsedElements[1] = PSpace->GetFE2D(i, cell);
248 
249  // ####################################################################
250  // calculate values on original element
251  // ####################################################################
252  TFEDatabase2D::GetOrig(N_LocalUsedElements, LocalUsedElements, Coll, cell, SecondDer, N_Points, xi, eta, weights, X, Y, AbsDetjk);
253 
254  // calculate all needed values of p
255  CurrentElement = LocalUsedElements[1];
256  BaseFunct = BaseFuncts[CurrentElement];
257  N_ = N_BaseFunct[CurrentElement];
258 
259  DOF = PGlobalNumbers + PBeginIndex[i];
260  for(l=0;l<N_;l++)
261  FEFunctValues[l] = p[DOF[l]];
262 
263  OrigFEValues = TFEDatabase2D::GetOrigElementValues(BaseFunct, D00);
264 
265  for(j=0;j<N_Points;j++)
266  {
267  Orig = OrigFEValues[j];
268  value = 0;
269  for(l=0;l<N_;l++)
270  value += FEFunctValues[l] * Orig[l];
271 
272  Derivatives[j][0] = value;
273  }
274 
275  // calculate all needed values of u1, u2
276  CurrentElement = LocalUsedElements[0];
277  BaseFunct = BaseFuncts[CurrentElement];
278  N_ = N_BaseFunct[CurrentElement];
279 
280  DOF = UGlobalNumbers + UBeginIndex[i];
281  for(l=0;l<N_;l++)
282  {
283  FEFunctValues1[l] = u1[DOF[l]];
284  FEFunctValues2[l] = u2[DOF[l]];
285  FEFunctValues3[l] = v[DOF[l]];
286  }
287 
288  for(k=0;k<N_DerivativesU;k++)
289  {
290  OrigFEValues = TFEDatabase2D::GetOrigElementValues(BaseFunct,
291  NeededDerivatives[k]);
292  for(j=0;j<N_Points;j++)
293  {
294  Orig = OrigFEValues[j];
295  value1 = 0;
296  value2 = 0;
297  value3 = 0;
298  for(l=0;l<N_;l++)
299  {
300  value1 += FEFunctValues1[l] * Orig[l];
301  value2 += FEFunctValues2[l] * Orig[l];
302  value3 += FEFunctValues3[l] * Orig[l];
303  } // endfor l
304  Derivatives[j][k+1] = value1;
305  Derivatives[j][k+4] = value2;
306  Derivatives[j][k+7] = value3;
307  } // endfor j
308  } // endfor k
309 
310  // calculation
311  for(j=0;j<N_Points;j++)
312  {
313  Der = Derivatives[j];
314 
315  // nu * (u1_x*v_x, u1_y*v_y), v= (v,0)
316  value1 = nu*(Der[2]*Der[8]+Der[3]*Der[9]);
317  // (u1 * u1_x + u2* u1_y) * (1,0)
318  value1 += (Der[1]*Der[2]+Der[4]*Der[3])*Der[7];
319  // pressure times divergence of test function (1,0)
320  value1 -= Der[0]*Der[8];
321 
322  value2 = nu*(Der[5]*Der[8]+Der[6]*Der[9]);
323  value2 += (Der[1]*Der[5]+Der[4]*Der[6])*Der[7];
324  value2 -= Der[0]*Der[9];
325 
326  cd += AbsDetjk[j]*weights[j] * value1;
327  cl += AbsDetjk[j]*weights[j] * value2;
328  }
329 
330  } // endfor i
331 
332  cd *= -500;
333  cl *= -500;
334 
335  delete Derivatives[0];
336  delete vfct;
337  delete v;
338 }
double * GetValues()
Definition: FEFunction2D.h:67
static TFE2D * GetFE2D(FE2D FE)
Definition: FEDatabase2D.h:353
int GetLength()
Definition: FEFunction2D.h:63
TCollection * GetCollection() const
Definition: FESpace.h:131
JointType GetType()
Definition: Joint.h:75
TBaseCell * GetCell(int i) const
return Cell with index i in Cells-array
Definition: Collection.h:50
TBoundComp2D * GetBoundComp() const
Definition: BoundEdge.h:77
Definition: FE2D.h:20
Definition: FESpace2D.h:28
double RE_NR
Definition: Database.h:313
static double ** GetOrigElementValues(BaseFunct1D BaseFunct, MultiIndex1D MultiIndex)
Definition: FEDatabase2D.h:300
store cells in an array, used by cell iterators
Definition: Collection.h:18
int GetN_Cells() const
return number of cells
Definition: Collection.h:46
TJoint * GetJoint(int J_i)
return the pointer to face with number i
Definition: BaseCell.h:175
Definition: Joint.h:48
TFESpace2D * GetFESpace2D()
Definition: FEFunction2D.h:59
FE2D GetFE2D(int i, TBaseCell *cell)
Definition: FESpace2D.C:1184
TFEDesc2D * GetFEDesc2D() const
Definition: FE2D.h:97
int ** GetJointDOF() const
Definition: FEDesc2D.h:86
static BaseFunct2D * GetBaseFunct2D_IDFromFE2D()
Definition: FEDatabase2D.h:417
static int * GetN_BaseFunctFromFE2D()
Definition: FEDatabase2D.h:421
int GetID() const
Definition: BoundComp.h:49
information for finite element data structure
Definition: BaseCell.h:25
int * GetGlobalNumbers() const
Definition: FESpace.h:135
int GetN_Edges()
return the number of edges of the cell
Definition: BaseCell.h:182
Definition: BoundEdge.h:19
Definition: BoundComp.h:27
static RefTrans2D GetOrig(int N_LocalUsedElements, FE2D *LocalUsedElements, TCollection *Coll, TBaseCell *cell, bool *Needs2ndDer, int &N_Points, double *&xi, double *&eta, double *&weights, double *X, double *Y, double *absdetjk)
Definition: FEDatabase2D.C:1765
Definition: FEDesc2D.h:15
int * GetBeginIndex() const
Definition: FESpace.h:142
int GetN_JointDOF() const
Definition: FEDesc2D.h:61
static TParamDB * ParamDB
Definition: Database.h:1134
Definition: FEFunction2D.h:24