ParMooN
 All Classes Functions Variables Friends Pages
Benchmark.h
1 // Navier-Stokes coupled with conformation stress tensor problem, Benchmark problem
2 
3 
4 void ExampleFile()
5 {
6  OutPut("Example: Benchmark_FlowPastCylinder" << endl) ;
7 }
8 
9 #define __BENCH__
10 
11 #include <Joint.h>
12 #include <BoundEdge.h>
13 #include <BoundComp.h>
14 #include <FE2D.h>
15 #include <FEDesc2D.h>
16 // ========================================================================
17 // exact solution
18 // ========================================================================
19 void ExactU1(double x, double y, double *values)
20 {
21  values[0] = 0;
22  values[1] = 0;
23  values[2] = 0;
24  values[3] = 0;
25 }
26 
27 void ExactU2(double x, double y, double *values)
28 {
29  values[0] = 0;
30  values[1] = 0;
31  values[2] = 0;
32  values[3] = 0;
33 }
34 
35 void ExactP(double x, double y, double *values)
36 {
37  values[0] = 0;
38  values[1] = 0;
39  values[2] = 0;
40  values[3] = 0;
41 }
42 
43 // ========================================================================
44 // boundary conditions
45 // ========================================================================
46 void BoundCondition(int i, double t, BoundCond &cond)
47 {
48  cond = DIRICHLET;
49 }
50 
51 void U1BoundValue(int BdComp, double Param, double &value)
52 {
53  switch(BdComp)
54  {
55  case 0: value = 0;
56  break;
57  case 1: value=1.2*Param*(1.0-Param);
58  break;
59  case 2: value = 0;
60  break;
61  case 3: value=1.2*Param*(1.0-Param) ;
62  break;
63  case 4: value=0;
64  break;
65  default: cout << "wrong boundary part number: " << BdComp << endl;
66  }
67 }
68 
69 void U2BoundValue(int BdComp, double Param, double &value)
70 {
71  value = 0;
72  if(BdComp>4) cout << "wrong boundary part number: " << BdComp << endl;
73 }
74 
75 // ========================================================================
76 // coefficients for Stokes form: A, B1, B2, f1, f2
77 // ========================================================================
78 void LinCoeffs(int n_points, double *x, double *y,
79  double **parameters, double **coeffs)
80 {
81  double eps = 1/TDatabase::ParamDB->RE_NR, beta = TDatabase::ParamDB->P3, nu = 1/TDatabase::ParamDB->WEI_NR;
82  int i;
83  double *coeff, *param, tau1x, tau1y, tau2x, tau2y, tau3x, tau3y, nondim;
84  nondim = (beta-1.0)*eps*nu;
85 
86  eps = eps*beta; // beta/Re due to only solvent contribution
87 
88  for(i=0;i<n_points;i++)
89  {
90  coeff = coeffs[i];
91 
92  param = parameters[i];
93 
94  tau1x = param[9];
95  tau2x = param[10];
96 // tau3x = param[11];
97 // tau1y = param[12];
98  tau2y = param[13];
99  tau3y = param[14];
100 
101  coeff[0] = eps;
102  coeff[1] = nondim;
103  coeff[2] = nondim;
104 // coeff[1] = 0;
105 // coeff[2] = 0;
106  }
107 }
108 
109 // ========================================================================
110 // exact solution
111 // ========================================================================
112 void ExactS1(double x, double y, double *values)
113 {
114  values[0] = 0;
115  values[1] = 0;
116  values[2] = 0;
117  values[3] = 0;
118 }
119 
120 void ExactS2(double x, double y, double *values)
121 {
122  values[0] = 0;
123  values[1] = 0;
124  values[2] = 0;
125  values[3] = 0;
126 }
127 
128 void ExactS3(double x, double y, double *values)
129 {
130  values[0] = 0;
131  values[1] = 0;
132  values[2] = 0;
133  values[3] = 0;
134 }
135 
136 // ========================================================================
137 // boundary conditions
138 // ========================================================================
139 void BoundCondition_CST(int i, double t, BoundCond &cond)
140 {
141  cond = DIRICHLET;
142 
143 }
144 
145 void S1BoundValue(int BdComp, double Param, double &value)
146 {
147  double Wei = TDatabase::ParamDB->WEI_NR;
148  switch(BdComp)
149  {
150  case 0: value=1.0;
151  break;
152  case 1: value= (pow(Wei*1.2*(1.0-(2.0*Param))/0.41,2) * 2.0 )+1.0;
153  break;
154  case 2: value=1.0;
155  break;
156  case 3: value=(pow(Wei*1.2*(1.0-(2.0*(1.0-Param)))/0.41,2)* 2.0 )+1.0;
157  break;
158  case 4: value=1.0;
159  break;
160  default: cout << "wrong boundary part number" << endl;
161  break;
162  }
163 }
164 
165 void S2BoundValue(int BdComp, double Param, double &value)
166 {
167  double Wei = TDatabase::ParamDB->WEI_NR;
168  switch(BdComp)
169  {
170  case 0: value=0;
171  break;
172  case 1: value=Wei*1.2*(1.0-(2.0*Param))/0.41;
173  break;
174  case 2: value=0;
175  break;
176  case 3: value=Wei*1.2*(1.0-(2.0*(1.0-Param)))/0.41;
177  break;
178  case 4: value=0;
179  break;
180  default: cout << "wrong boundary part number" << endl;
181  break;
182  }
183  return;
184 }
185 
186 
187 
188 void S3BoundValue(int BdComp, double Param, double &value)
189 {
190  value=1.0;
191  if(BdComp>4) cout << "wrong boundary part number: " << BdComp << endl;
192 }
193 
194 void LinCoeffs_CST(int n_points, double *X, double *Y,
195  double **parameters, double **coeffs)
196 {
197  double nu=1./TDatabase::ParamDB->WEI_NR;
198 
199  int i;
200  double *coeff;
201 
202  for(i=0;i<n_points;i++)
203  {
204  coeff = coeffs[i];
205 
206  coeff[0] = nu;
207  coeff[1] = nu; //f1
208  coeff[2] = 0.0; //f2
209  coeff[3] = nu; //f3
210 
211 
212  }
213 }
214 
216 void GetCdCl(TFEFunction2D *u1fct, TFEFunction2D *u2fct,
217  TFEFunction2D *pfct, TFEFunction2D *u1old,
218  TFEFunction2D *u2old,
219  double &cd, double &cl)
220 {
221  int i,j,k,l, N_;
222  int N_Points,N_Edges,comp,ed_nr;
223  double *weights, *xi, *eta;
224  double X[MaxN_QuadPoints_2D];
225  double Y[MaxN_QuadPoints_2D];
226  double AbsDetjk[MaxN_QuadPoints_2D];
227  int N_LocalUsedElements;
228  FE2D LocalUsedElements[2], CurrentElement;
229  int *DOF;
230  double **OrigFEValues, *Orig;
231  bool SecondDer[2] = { FALSE, FALSE };
232  double *u1, *u2, *p;
233  TFESpace2D *USpace, *PSpace;
234  int *UGlobalNumbers, *UBeginIndex;
235  int *PGlobalNumbers, *PBeginIndex;
236  int *N_BaseFunct, N_Cells;
237  BaseFunct2D BaseFunct, *BaseFuncts;
238  TCollection *Coll;
239  TBaseCell *cell;
240  double value, value1, value2, value3;
241  double FEFunctValues[MaxN_BaseFunctions2D];
242  double FEFunctValues1[MaxN_BaseFunctions2D];
243  double FEFunctValues2[MaxN_BaseFunctions2D];
244  double FEFunctValues3[MaxN_BaseFunctions2D];
245  int N_DerivativesU = 3;
246  double *Derivatives[MaxN_BaseFunctions2D];
247  MultiIndex2D NeededDerivatives[3] = { D00, D10, D01 };
248  TFEFunction2D *vfct;
249  double *v, nu = 1/TDatabase::ParamDB->RE_NR;
250  double *Der, *aux;
251  TJoint *joint;
252  TBoundEdge *boundedge;
253  TBoundComp *BoundComp;
254  TFE2D *eleCell;
255  FE2D FEEle;
256  TFEDesc2D *FEDesc;
257  int N_DOF_Circ, *DOF_Circ;
258  char VString[] = "v";
259 
260  u1 = u1fct->GetValues();
261  u2 = u2fct->GetValues();
262  p = pfct->GetValues();
263 
264  USpace = u1fct->GetFESpace2D();
265  PSpace = pfct->GetFESpace2D();
266 
267  UGlobalNumbers = USpace->GetGlobalNumbers();
268  UBeginIndex = USpace->GetBeginIndex();
269 
270  PGlobalNumbers = PSpace->GetGlobalNumbers();
271  PBeginIndex = PSpace->GetBeginIndex();
272 
275 
276  aux = new double [MaxN_QuadPoints_2D*10];
277  for(j=0;j<MaxN_QuadPoints_2D;j++)
278  Derivatives[j] = aux + j*10;
279 
280  N_ = u1fct->GetLength();
281  v = new double[N_];
282  memset(v,0,N_*SizeOfDouble);
283  vfct = new TFEFunction2D(USpace, VString, VString, v, N_);
284 
285 // ########################################################################
286 // loop over all cells
287 // ########################################################################
288  Coll = USpace->GetCollection(); // all spaces use same Coll
289  N_Cells = Coll->GetN_Cells();
290 
291  for(i=0;i<N_Cells;i++)
292  {
293  cell = Coll->GetCell(i);
294  N_Edges=cell->GetN_Edges();
295  for(j=0;j<N_Edges;j++) // loop over all edges of cell
296  {
297  joint=cell->GetJoint(j);
298  if ((joint->GetType() == BoundaryEdge)||
299  (joint->GetType() == IsoBoundEdge)) // boundary edge
300  {
301 
302  boundedge=(TBoundEdge *)joint;
303  BoundComp=boundedge->GetBoundComp(); // get boundary component
304  comp=BoundComp->GetID(); // boundary id
305  if (comp==4)
306  {
307  FEEle = USpace->GetFE2D(i,cell); // finite element of cell
308  eleCell = TFEDatabase2D::GetFE2D(FEEle);
309  FEDesc = eleCell->GetFEDesc2D(); // fe descriptor
310  N_DOF_Circ = FEDesc->GetN_JointDOF(); // # local dofs on joints
311  DOF_Circ = FEDesc->GetJointDOF(j); // local dofs on joint j
312  DOF = UGlobalNumbers + UBeginIndex[i]; // pointer to global dofs
313  for (k=0;k<N_DOF_Circ;k++) // set fe on circle to 1
314  v[DOF[DOF_Circ[k]]] = 1;
315  }
316  }
317  }
318  }
319 
320  cd = 0;
321  cl = 0;
322 
323 // ########################################################################
324 // loop over all cells
325 // ########################################################################
326  Coll = USpace->GetCollection(); // all spaces use same Coll
327  N_Cells = Coll->GetN_Cells();
328  for(i=0;i<N_Cells;i++)
329  {
330  cell = Coll->GetCell(i);
331 
332  // ####################################################################
333  // find local used elements on this cell
334  // ####################################################################
335  N_LocalUsedElements = 2;
336  LocalUsedElements[0] = USpace->GetFE2D(i, cell);
337  LocalUsedElements[1] = PSpace->GetFE2D(i, cell);
338 
339  // ####################################################################
340  // calculate values on original element
341  // ####################################################################
342  TFEDatabase2D::GetOrig(N_LocalUsedElements, LocalUsedElements, Coll, cell, SecondDer, N_Points, xi, eta, weights, X, Y, AbsDetjk);
343 
344  // calculate all needed values of p
345  CurrentElement = LocalUsedElements[1];
346  BaseFunct = BaseFuncts[CurrentElement];
347  N_ = N_BaseFunct[CurrentElement];
348 
349  DOF = PGlobalNumbers + PBeginIndex[i];
350  for(l=0;l<N_;l++)
351  FEFunctValues[l] = p[DOF[l]];
352 
353  OrigFEValues = TFEDatabase2D::GetOrigElementValues(BaseFunct, D00);
354 
355  for(j=0;j<N_Points;j++)
356  {
357  Orig = OrigFEValues[j];
358  value = 0;
359  for(l=0;l<N_;l++)
360  value += FEFunctValues[l] * Orig[l];
361 
362  Derivatives[j][0] = value;
363  }
364 
365  // calculate all needed values of u1, u2
366  CurrentElement = LocalUsedElements[0];
367  BaseFunct = BaseFuncts[CurrentElement];
368  N_ = N_BaseFunct[CurrentElement];
369 
370  DOF = UGlobalNumbers + UBeginIndex[i];
371  for(l=0;l<N_;l++)
372  {
373  FEFunctValues1[l] = u1[DOF[l]];
374  FEFunctValues2[l] = u2[DOF[l]];
375  FEFunctValues3[l] = v[DOF[l]];
376  }
377 
378  for(k=0;k<N_DerivativesU;k++)
379  {
380  OrigFEValues = TFEDatabase2D::GetOrigElementValues(BaseFunct,
381  NeededDerivatives[k]);
382  for(j=0;j<N_Points;j++)
383  {
384  Orig = OrigFEValues[j];
385  value1 = 0;
386  value2 = 0;
387  value3 = 0;
388  for(l=0;l<N_;l++)
389  {
390  value1 += FEFunctValues1[l] * Orig[l];
391  value2 += FEFunctValues2[l] * Orig[l];
392  value3 += FEFunctValues3[l] * Orig[l];
393  } // endfor l
394  Derivatives[j][k+1] = value1;
395  Derivatives[j][k+4] = value2;
396  Derivatives[j][k+7] = value3;
397  } // endfor j
398  } // endfor k
399 
400  // calculation
401  for(j=0;j<N_Points;j++)
402  {
403  Der = Derivatives[j];
404 
405  // nu * (u1_x*v_x, u1_y*v_y), v= (v,0)
406  value1 = nu*(Der[2]*Der[8]+Der[3]*Der[9]);
407  // (u1 * u1_x + u2* u1_y) * (1,0)
408  value1 += (Der[1]*Der[2]+Der[4]*Der[3])*Der[7];
409  // pressure times divergence of test function (1,0)
410  value1 -= Der[0]*Der[8];
411 
412  value2 = nu*(Der[5]*Der[8]+Der[6]*Der[9]);
413  value2 += (Der[1]*Der[5]+Der[4]*Der[6])*Der[7];
414  value2 -= Der[0]*Der[9];
415 
416  cd += AbsDetjk[j]*weights[j] * value1;
417  cl += AbsDetjk[j]*weights[j] * value2;
418  }
419 
420  } // endfor i
421 
422  cd *= -500;
423  cl *= -500;
424 
425  delete Derivatives[0];
426  delete vfct;
427  delete v;
428 }
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