ParMooN
 All Classes Functions Variables Friends Pages
Hemker_Wide.h
1 // Navier-Stokes Benchmark problem with wide channel
2 
3 
4 void ExampleFile()
5 {
6  OutPut("Example: Hemker_DEVSS" << endl) ;
7 }
8 
9 #define __BENCH__
10 
11 
12 #include <Joint.h>
13 #include <BoundEdge.h>
14 #include <BoundComp.h>
15 #include <FE2D.h>
16 #include <FEDesc2D.h>
17 
18 #include <MainUtilities.h>
19 
20 
21 #include <MacroCell.h>
22 #include <BoundEdge.h>
23 #include <IsoBoundEdge.h>
24 #include <gridgen.h>
25 #include <IsoInterfaceJoint.h>
26 #include <BdLine.h>
27 #include <BdCircle.h>
28 #include <GridCell.h>
29 
30 #include <QuadAffin.h>
31 #include <QuadBilinear.h>
32 #include <QuadIsoparametric.h>
33 #include <TriaAffin.h>
34 #include <TriaIsoparametric.h>
35 
36 extern "C"
37 {
38  void triangulate(char*, struct triangulateio*,
39  struct triangulateio*, struct triangulateio*);
40 }
41 
42 // ========================================================================
43 // exact solution
44 // ========================================================================
45 void ExactU1(double x, double y, double *values)
46 {
47  values[0] = 0;
48  values[1] = 0;
49  values[2] = 0;
50  values[3] = 0;
51 }
52 
53 void ExactU2(double x, double y, double *values)
54 {
55  values[0] = 0;
56  values[1] = 0;
57  values[2] = 0;
58  values[3] = 0;
59 }
60 
61 void ExactP(double x, double y, double *values)
62 {
63  values[0] = 0;
64  values[1] = 0;
65  values[2] = 0;
66  values[3] = 0;
67 }
68 
69 // ========================================================================
70 // boundary conditions
71 // ========================================================================
72 void BoundCondition(int i, double t, BoundCond &cond)
73 {
74  switch(i)
75  {
76  case 0:
77  case 2:
78  case 3:
79  case 4:
80  cond = DIRICHLET;
81  break;
82  case 1:
83  cond = NEUMANN;
84  break;
85  }
86 }
87 
88 void U1BoundValue(int BdComp, double Param, double &value)
89 {
90  switch(BdComp)
91  {
92  case 0: value = 0;
93  break;
94  case 1: value=0;
95  break;
96  case 2: value = 0;
97  break;
98  case 3: value=1.5*(1.0 - (0.25*pow(2-4*Param,2))) ;
99  break;
100  case 4: value=0;
101  break;
102  default: cout << "wrong boundary part number: " << BdComp << endl;
103  }
104 }
105 
106 void U2BoundValue(int BdComp, double Param, double &value)
107 {
108  value = 0;
109  if(BdComp>4) cout << "wrong boundary part number: " << BdComp << endl;
110 }
111 
112 // ========================================================================
113 // coefficients for Stokes form: A, B1, B2, f1, f2
114 // ========================================================================
115 void LinCoeffs(int n_points, double *x, double *y,
116  double **parameters, double **coeffs)
117 {
118  double eps = 1/TDatabase::ParamDB->RE_NR, beta = TDatabase::ParamDB->P3;
119  int i;
120  double *coeff, nondim;
121 
122  if (TDatabase::ParamDB->TENSOR_TYPE == 1)
123  nondim = beta*eps;
124  else if (TDatabase::ParamDB->TENSOR_TYPE == 2)
125  nondim = eps;
126 
127  for(i=0;i<n_points;i++)
128  {
129  coeff = coeffs[i];
130 
131  coeff[0] = eps;
132  coeff[1] = 0; // f1
133  coeff[2] = 0; // f2
134  }
135 }
136 
137 
139 void GetCdCl(TFEFunction2D *u1fct, TFEFunction2D *u2fct,
140  TFEFunction2D *pfct, TFEFunction2D *u1old,
141  TFEFunction2D *u2old,
142  double &cd, double &cl)
143 {
144  int i,j,k,l, N_;
145  int N_Points,N_Edges,comp,ed_nr;
146  double *weights, *xi, *eta;
147  double X[MaxN_QuadPoints_2D];
148  double Y[MaxN_QuadPoints_2D];
149  double AbsDetjk[MaxN_QuadPoints_2D];
150  int N_LocalUsedElements;
151  FE2D LocalUsedElements[2], CurrentElement;
152  int *DOF;
153  double **OrigFEValues, *Orig;
154  bool SecondDer[2] = { FALSE, FALSE };
155  double *u1, *u2, *p;
156  TFESpace2D *USpace, *PSpace;
157  int *UGlobalNumbers, *UBeginIndex;
158  int *PGlobalNumbers, *PBeginIndex;
159  int *N_BaseFunct, N_Cells;
160  BaseFunct2D BaseFunct, *BaseFuncts;
161  TCollection *Coll;
162  TBaseCell *cell;
163  double value, value1, value2, value3;
164  double FEFunctValues[MaxN_BaseFunctions2D];
165  double FEFunctValues1[MaxN_BaseFunctions2D];
166  double FEFunctValues2[MaxN_BaseFunctions2D];
167  double FEFunctValues3[MaxN_BaseFunctions2D];
168  int N_DerivativesU = 3;
169  double *Derivatives[MaxN_BaseFunctions2D];
170  MultiIndex2D NeededDerivatives[3] = { D00, D10, D01 };
171  TFEFunction2D *vfct;
172  double *v, nu = 1/TDatabase::ParamDB->RE_NR;
173  double *Der, *aux;
174  TJoint *joint;
175  TBoundEdge *boundedge;
176  TBoundComp *BoundComp;
177  TFE2D *eleCell;
178  FE2D FEEle;
179  TFEDesc2D *FEDesc;
180  int N_DOF_Circ, *DOF_Circ;
181  char VString[] = "v";
182 
183  u1 = u1fct->GetValues();
184  u2 = u2fct->GetValues();
185  p = pfct->GetValues();
186 
187  USpace = u1fct->GetFESpace2D();
188  PSpace = pfct->GetFESpace2D();
189 
190  UGlobalNumbers = USpace->GetGlobalNumbers();
191  UBeginIndex = USpace->GetBeginIndex();
192 
193  PGlobalNumbers = PSpace->GetGlobalNumbers();
194  PBeginIndex = PSpace->GetBeginIndex();
195 
198 
199  aux = new double [MaxN_QuadPoints_2D*10];
200  for(j=0;j<MaxN_QuadPoints_2D;j++)
201  Derivatives[j] = aux + j*10;
202 
203  N_ = u1fct->GetLength();
204  v = new double[N_];
205  memset(v,0,N_*SizeOfDouble);
206  vfct = new TFEFunction2D(USpace, VString, VString, v, N_);
207 
208 // ########################################################################
209 // loop over all cells
210 // ########################################################################
211  Coll = USpace->GetCollection(); // all spaces use same Coll
212  N_Cells = Coll->GetN_Cells();
213 
214  for(i=0;i<N_Cells;i++)
215  {
216  cell = Coll->GetCell(i);
217  N_Edges=cell->GetN_Edges();
218  for(j=0;j<N_Edges;j++) // loop over all edges of cell
219  {
220  joint=cell->GetJoint(j);
221  if ((joint->GetType() == BoundaryEdge)||
222  (joint->GetType() == IsoBoundEdge)) // boundary edge
223  {
224 
225  boundedge=(TBoundEdge *)joint;
226  BoundComp=boundedge->GetBoundComp(); // get boundary component
227  comp=BoundComp->GetID(); // boundary id
228  if (comp==4)
229  {
230  FEEle = USpace->GetFE2D(i,cell); // finite element of cell
231  eleCell = TFEDatabase2D::GetFE2D(FEEle);
232  FEDesc = eleCell->GetFEDesc2D(); // fe descriptor
233  N_DOF_Circ = FEDesc->GetN_JointDOF(); // # local dofs on joints
234  DOF_Circ = FEDesc->GetJointDOF(j); // local dofs on joint j
235  DOF = UGlobalNumbers + UBeginIndex[i]; // pointer to global dofs
236  for (k=0;k<N_DOF_Circ;k++) // set fe on circle to 1
237  v[DOF[DOF_Circ[k]]] = 1;
238  }
239  }
240  }
241  }
242 
243  cd = 0;
244  cl = 0;
245 
246 // ########################################################################
247 // loop over all cells
248 // ########################################################################
249  Coll = USpace->GetCollection(); // all spaces use same Coll
250  N_Cells = Coll->GetN_Cells();
251  for(i=0;i<N_Cells;i++)
252  {
253  cell = Coll->GetCell(i);
254 
255  // ####################################################################
256  // find local used elements on this cell
257  // ####################################################################
258  N_LocalUsedElements = 2;
259  LocalUsedElements[0] = USpace->GetFE2D(i, cell);
260  LocalUsedElements[1] = PSpace->GetFE2D(i, cell);
261 
262  // ####################################################################
263  // calculate values on original element
264  // ####################################################################
265  TFEDatabase2D::GetOrig(N_LocalUsedElements, LocalUsedElements, Coll, cell, SecondDer, N_Points, xi, eta, weights, X, Y, AbsDetjk);
266 
267  // calculate all needed values of p
268  CurrentElement = LocalUsedElements[1];
269  BaseFunct = BaseFuncts[CurrentElement];
270  N_ = N_BaseFunct[CurrentElement];
271 
272  DOF = PGlobalNumbers + PBeginIndex[i];
273  for(l=0;l<N_;l++)
274  FEFunctValues[l] = p[DOF[l]];
275 
276  OrigFEValues = TFEDatabase2D::GetOrigElementValues(BaseFunct, D00);
277 
278  for(j=0;j<N_Points;j++)
279  {
280  Orig = OrigFEValues[j];
281  value = 0;
282  for(l=0;l<N_;l++)
283  value += FEFunctValues[l] * Orig[l];
284 
285  Derivatives[j][0] = value;
286  }
287 
288  // calculate all needed values of u1, u2
289  CurrentElement = LocalUsedElements[0];
290  BaseFunct = BaseFuncts[CurrentElement];
291  N_ = N_BaseFunct[CurrentElement];
292 
293  DOF = UGlobalNumbers + UBeginIndex[i];
294  for(l=0;l<N_;l++)
295  {
296  FEFunctValues1[l] = u1[DOF[l]];
297  FEFunctValues2[l] = u2[DOF[l]];
298  FEFunctValues3[l] = v[DOF[l]];
299  }
300 
301  for(k=0;k<N_DerivativesU;k++)
302  {
303  OrigFEValues = TFEDatabase2D::GetOrigElementValues(BaseFunct,
304  NeededDerivatives[k]);
305  for(j=0;j<N_Points;j++)
306  {
307  Orig = OrigFEValues[j];
308  value1 = 0;
309  value2 = 0;
310  value3 = 0;
311  for(l=0;l<N_;l++)
312  {
313  value1 += FEFunctValues1[l] * Orig[l];
314  value2 += FEFunctValues2[l] * Orig[l];
315  value3 += FEFunctValues3[l] * Orig[l];
316  } // endfor l
317  Derivatives[j][k+1] = value1;
318  Derivatives[j][k+4] = value2;
319  Derivatives[j][k+7] = value3;
320  } // endfor j
321  } // endfor k
322 
323  // calculation
324  for(j=0;j<N_Points;j++)
325  {
326  Der = Derivatives[j];
327 
328  // nu * (u1_x*v_x, u1_y*v_y), v= (v,0)
329  value1 = nu*(Der[2]*Der[8]+Der[3]*Der[9]);
330  // (u1 * u1_x + u2* u1_y) * (1,0)
331  // value1 += (Der[1]*Der[2]+Der[4]*Der[3])*Der[7];
332  // pressure times divergence of test function (1,0)
333  value1 -= Der[0]*Der[8];
334 
335  value2 = (Der[5]*Der[8]+Der[6]*Der[9]);
336  // value2 += (Der[1]*Der[5]+Der[4]*Der[6])*Der[7];
337  value2 -= Der[0]*Der[9];
338 
339  cd += AbsDetjk[j]*weights[j] * value1;
340  cl += AbsDetjk[j]*weights[j] * value2;
341  }
342 
343  } // endfor i
344 
345  cd *= -1;
346  cl *= -1;
347 
348  delete Derivatives[0];
349  delete vfct;
350  delete v;
351 }
352 
353 
354 // **************************************************************************
355 // Triangular Mesh Generation
356 // **************************************************************************
357 
358 void TriaReMeshGen(TDomain *&Domain)
359 {
360  int j, ID, k, N_G, *PartMarker, *PointNeighb, maxEpV=0;
361  int a, b, len1, len2, Neighb_tmp, BDpart;
362  int i, temp, N_Cells, N_RootCells, CurrVertex, N_Joints, N_Vertices;
363  int N_Interface_Vert, N_Verti, N_Hori, N_SlipBound_Vert, N_BDVertices;
364  int CurrComp, In_Index, *Triangles, Neib[2], CurrNeib;
365 
366  double deviation, hi, x0, y0, x, y, phi1, phi2;
367  double T_a, T_b, C_x, C_y, s, theta;
368  double dt, area = TDatabase::ParamDB->Area;
369  double *Coordinates, *Hole_List;
370 
371  double Xi[4] = {-20., 20., 20.,-20.};
372  double Yi[4] = {-2.,-2., 2., 2.};
373 
374  TBaseCell **CellTree, *cell;
375  TBoundPart *BoundPart;
376  TJoint *Joint;
377  TCollection *coll;
378  TVertex **VertexDel, **NewVertices;
379  TBdLine *UpdateBound[12];
380  TBdCircle *UpdateIntface;
381 
382 
383  boolean AllowEdgeRef = (boolean) TDatabase::ParamDB->MESHGEN_ALLOW_EDGE_REF;
384 
385  struct triangulateio In, Out;
386  std::ostringstream opts;
387  opts << " ";
388 
389  Out.pointlist = NULL;
390  Out.pointattributelist = NULL;
391  Out.pointmarkerlist = NULL;
392  Out.trianglelist = NULL;
393  Out.triangleattributelist = NULL;
394  Out.trianglearealist = NULL;
395  Out.neighborlist = NULL;
396  Out.segmentlist = NULL;
397  Out.segmentmarkerlist = NULL;
398  Out.holelist = NULL;
399  Out.regionlist = NULL;
400  Out.edgelist = NULL;
401  Out.edgemarkerlist = NULL;
402  Out.normlist = NULL;
403 
404  opts.seekp(std::ios::beg);
405 
406 
407  BoundPart = Domain->GetBdPart(0);
408  UpdateBound[0] = (TBdLine*)BoundPart->GetBdComp(0);
409  UpdateBound[1] = (TBdLine*)BoundPart->GetBdComp(1);
410  UpdateBound[2] = (TBdLine*)BoundPart->GetBdComp(2);
411  UpdateBound[3] = (TBdLine*)BoundPart->GetBdComp(3);
412  BoundPart = Domain->GetBdPart(1);
413  UpdateIntface = (TBdCircle*)BoundPart->GetBdComp(0);
414 
415 
416 //OutPut("MESHGEN_REF_QUALIT " << TDatabase::ParamDB->MESHGEN_REF_QUALITY << endl);
417 
418  opts<<'p'; // Constrained Delaunay Triangulation:
419  // initial values - only points defined on the boundary of the domain;
420  // triangulation near boundary may variate from Delaunay criterion
421  opts<<"q"<< TDatabase::ParamDB->MESHGEN_REF_QUALITY;
422  // Quality mesh generation with no angles smaller than 20 degrees;
423  opts<<"a"<< area; // Imposes a maximum triangle area.
424  opts<<'e'; // Outputs a list of edges of the triangulation
425  opts<<'z'; // Numbers if items starting from 0
426  //opts<<"VVVV"; // Gives detailed information about what Triangle is doing
427  opts<<'Q'; // Supress all explanation of what Triangle is doing, unless an error occurs
428 // opts<<'Y'; // Supress adding vertices on boundary edges
429  opts<<ends;
430 
431  N_Interface_Vert = int (TDatabase::ParamDB->P6); //Freesurf except end point
432  N_Hori = 300; // number of horrizontal BD vertices
433  N_Verti = 50; // number of vertical BD vertices
434  N_SlipBound_Vert = 2*N_Hori + 2*N_Verti;
435 
436  N_BDVertices = N_Interface_Vert+N_SlipBound_Vert;
437  In.numberofpoints = N_BDVertices;
438  In.pointlist = new double[2*In.numberofpoints];
439  In.pointmarkerlist = new int[In.numberofpoints];
440  In.numberofpointattributes = 0;
441 
442  In.numberofsegments = In.numberofpoints;
443  In.segmentlist = new int[2*In.numberofsegments];
444  In.segmentmarkerlist = new int[In.numberofsegments];
445  In.numberofregions = 0;
446  In.regionlist = NULL;
447 
448  In.numberofholes = 1;
449  In.holelist = NULL;
450 
451  Hole_List = new double[2* In.numberofholes];
452  Hole_List[0] = 0.;
453  Hole_List[1] = 0.;
454  In.holelist = Hole_List;
455 
456  In_Index = 0;
457  CurrComp = 1;
458 
459  hi = (Xi[1] - Xi[0])/(double)N_Hori;
460  x0 = Xi[0];
461  y0 = Yi[0];
462  x = Xi[0];
463 
464  // points and segments on the horizontal boundary (marker=1)
465  for(i=0;i<N_Hori;i++) // without last point
466  {
467  x = x0 + (double)i*hi;
468  In.pointlist[2*In_Index] = x;
469  In.pointlist[2*In_Index+1] = y0;
470 // cout<<" x : "<< In.pointlist[2*In_Index] << " y : "<< In.pointlist[2*In_Index+1] <<endl;
471  In.pointmarkerlist[In_Index] = CurrComp;
472  In.segmentlist[2*In_Index] = In_Index;
473  In.segmentlist[2*In_Index+1] = In_Index+1;
474  In.segmentmarkerlist[In_Index] = CurrComp;
475  In_Index++;
476  }
477 
478  CurrComp++;
479 
480  hi = (Yi[2] - Yi[1])/(double)N_Verti;
481  x0 = Xi[1];
482  y0 = Yi[1];
483  y = Yi[1];
484  // points and segments on the horizontal boundary (marker=1)
485  for(i=0;i<N_Verti;i++) // without last point
486  {
487  y = y0 + (double)i*hi;
488  In.pointlist[2*In_Index] = x0;
489  In.pointlist[2*In_Index+1] = y;
490 // cout<<" x : "<< In.pointlist[2*In_Index] << " y : "<< In.pointlist[2*In_Index+1] <<endl;
491  In.pointmarkerlist[In_Index] = CurrComp;
492  In.segmentlist[2*In_Index] = In_Index;
493  In.segmentlist[2*In_Index+1] = In_Index+1;
494  In.segmentmarkerlist[In_Index] = CurrComp;
495  In_Index++;
496 
497  }
498 
499  CurrComp++;
500 // cout<<endl;
501 
502  hi = (Xi[3] - Xi[2])/(double)N_Hori;
503  x0 = Xi[2];
504  y0 = Yi[2];
505  x = Xi[2];
506  // points and segments on the horizontal boundary (marker=1)
507  for(i=0;i<N_Hori;i++) // without last point
508  {
509  x = x0 + (double)i*hi;
510  In.pointlist[2*In_Index] = x;
511  In.pointlist[2*In_Index+1] = y0;
512 // cout<<" x : "<< In.pointlist[2*In_Index] << " y : "<< In.pointlist[2*In_Index+1] <<endl;
513  In.pointmarkerlist[In_Index] = CurrComp;
514  In.segmentlist[2*In_Index] = In_Index;
515  In.segmentlist[2*In_Index+1] = In_Index+1;
516  In.segmentmarkerlist[In_Index] = CurrComp;
517  In_Index++;
518 
519  }
520 
521  CurrComp++;
522 // cout<<endl;
523 
524  hi = (Yi[0] - Yi[3])/(double)N_Verti;
525  x0 = Xi[3];
526  y0 = Yi[3];
527  y = Yi[3];
528  // points and segments on the horizontal boundary (marker=1)
529  for(i=0;i<N_Verti;i++) // without last point
530  {
531  y = y0 + (double)i*hi;
532  In.pointlist[2*In_Index] = x0;
533  In.pointlist[2*In_Index+1] = y;
534 // cout<<" x : "<< In.pointlist[2*In_Index] << " y : "<< In.pointlist[2*In_Index+1] <<endl;
535  In.pointmarkerlist[In_Index] = CurrComp;
536  In.segmentlist[2*In_Index] = In_Index;
537  In.segmentlist[2*In_Index+1] = In_Index+1;
538  In.segmentmarkerlist[In_Index] = CurrComp;
539  In_Index++;
540 
541  }
542  CurrComp++;
543 
544  In.segmentlist[2*(In_Index-1)+1] = 0;
545  temp=In_Index;
546 
547 
548  T_a = TDatabase::ParamDB->P1; // x axis value in ellipse
549  T_b = TDatabase::ParamDB->P2; // y axis value in ellipse !!! set in modifyGausscoord funct also
550 // deviation = fabs( T_a - T_b);
551 
552 
553  C_x = 0.0; // center of the inner phase
554  C_y = 0.0, // center of the inner phase
555  phi1 = 0.000000E+0000; // end degree value of interface
556  phi2 = 2.*Pi;
557 
558 // C_x = 0.0; // center of the inner phase
559 // C_y = 0.0, // center of the inner phase
560  s = (phi2- phi1)/(double)N_Interface_Vert;
561 
562  // points and segments on the interface (marker=2)
563 // theta = 0.;
564 // t0 = theta;
565 
566  for(i=0;i<N_Interface_Vert;i++)
567  {
568  theta = phi1 + (double)i*s;
569 // cout<<" theta : "<< theta <<endl;
570 
571 // if(fabs(I_FaceX[i]) < 1e-10 ) I_FaceX[i] = 0.0;
572  In.pointlist[2*In_Index] = T_a*cos(theta);;
573  In.pointlist[2*In_Index+1] = T_b*sin(theta);
574 
575 // if(i==0)
576 // {
577 // FreeBD_X = I_FaceX[i]; FreeBD_Y = I_FaceY[i];
578 // cout << " sorting " << FreeBD_X << ' ' << FreeBD_Y<<endl;
579 // }
580 
581 // if(i==1)
582 // {
583 // h_interface = sqrt((I_FaceX[i-1]-I_FaceX[i])*(I_FaceX[i-1]-I_FaceX[i]) +
584 // (I_FaceY[i-1]-I_FaceY[i])*(I_FaceY[i-1]-I_FaceY[i]) );
585 // OutPut("h_interface " <<h_interface << endl);
586 // }
587 // cout<<(180./Pi)*theta<< " x : "<< In.pointlist[2*In_Index] << " y : "<< In.pointlist[2*In_Index+1] <<endl;
588 
589  In.pointmarkerlist[In_Index] = CurrComp;
590  In.segmentlist[2*In_Index] = In_Index;
591  In.segmentlist[2*In_Index+1] = In_Index+1;
592  In.segmentmarkerlist[In_Index] = CurrComp;
593  In_Index++;
594  }
595 
596  In.segmentlist[2*(In_Index-1)+1] = temp;
597 
598 // exit(0);
599 
600  if(Out.pointlist!=NULL) {
601  free(Out.pointlist); Out.pointlist = NULL;}
602  if(Out.pointattributelist!=NULL) {
603  free(Out.pointattributelist); Out.pointattributelist = NULL;}
604  if(Out.pointmarkerlist!=NULL) {
605  free(Out.pointmarkerlist); Out.pointmarkerlist = NULL;}
606  if(Out.trianglelist!=NULL) {
607  free(Out.trianglelist); Out.trianglelist = NULL;}
608  if(Out.triangleattributelist!=NULL) {
609  free(Out.triangleattributelist); Out.triangleattributelist = NULL;}
610  if(Out.trianglearealist!=NULL) {
611  free(Out.trianglearealist); Out.trianglearealist = NULL;}
612  if(Out.neighborlist!=NULL) {
613  free(Out.neighborlist); Out.neighborlist = NULL;}
614  if(Out.segmentlist!=NULL) {
615  free(Out.segmentlist); Out.segmentlist = NULL;}
616  if(Out.segmentmarkerlist!=NULL) {
617  free(Out.segmentmarkerlist); Out.segmentmarkerlist = NULL;}
618  if(Out.holelist!=NULL) {
619  free(Out.holelist); Out.holelist = NULL;}
620  if(Out.regionlist!=NULL) {
621  free(Out.regionlist); Out.regionlist = NULL;}
622  if(Out.edgelist!=NULL) {
623  free(Out.edgelist); Out.edgelist = NULL;}
624  if(Out.edgemarkerlist!=NULL) {
625  free(Out.edgemarkerlist); Out.edgemarkerlist = NULL;}
626  if(Out.normlist!=NULL) {
627  free(Out.normlist); Out.normlist = NULL;}
628 
629  // call triangle
630  triangulate((char*)opts.str().c_str(), &In, &Out, (struct triangulateio *)NULL);
631 
632 
633  Domain->GetTreeInfo(CellTree, N_RootCells);
634  coll = Domain->GetCollection(It_Finest, 0);
635  N_Cells = coll->GetN_Cells();
636 
637  // remove all existing vertices and joints
638  VertexDel = new TVertex*[3*N_RootCells];
639 
640  CurrVertex = 0;
641 
642  for(i=0;i<N_Cells;i++)
643  {
644  cell = coll->GetCell(i);
645  N_Joints = cell->GetN_Joints();
646  N_Vertices = cell->GetN_Vertices();
647  for(j=0;j<N_Joints;j++)
648  {
649  if(CurrVertex==0)
650  {
651  VertexDel[CurrVertex] = cell->GetVertex(j);
652  CurrVertex++;
653  }
654  else
655  {
656  ID = 0;
657  for(k=0;k<CurrVertex;k++)
658  if(VertexDel[k]==cell->GetVertex(j))
659  {
660  ID = 1; break;
661  }
662  if(ID!=1)
663  {
664  VertexDel[CurrVertex] = cell->GetVertex(j);
665  CurrVertex++;
666  }
667  } // else if(CurrVertex==0)
668 
669  ID = 0;
670  for(k=0;k<CurrVertex;k++)
671  if(VertexDel[k]==cell->GetVertex((j+1)%N_Vertices))
672  {
673  ID = 1; break;
674  }
675  if(ID!=1)
676  {
677  VertexDel[CurrVertex] = cell->GetVertex((j+1)%N_Vertices);
678  CurrVertex++;
679  }
680  } // for j
681  } // for i
682  for(i=0;i<CurrVertex;i++)
683  delete VertexDel[i];
684 
685  delete []VertexDel;
686  OutPut(CurrVertex<<" vertices were deleted"<<endl);
687 
688  // remove all existing cells and joints
689  for(i=0;i<N_RootCells;i++)
690  delete (TGridCell*)CellTree[i];
691  OutPut(N_RootCells<<" cells were deleted"<<endl);
692  delete CellTree;
693  delete coll;
694 
695 
696 
697  // Solid Bound startx, starty, x length and y length
698  UpdateBound[0]->SetParams(Xi[0], Yi[0], Xi[1]-Xi[0],Yi[1]-Yi[0]);
699  UpdateBound[1]->SetParams(Xi[1], Yi[1], Xi[2]-Xi[1],Yi[2]-Yi[1]);
700  UpdateBound[2]->SetParams(Xi[2], Yi[2], Xi[3]-Xi[2],Yi[3]-Yi[2]);
701  UpdateBound[3]->SetParams(Xi[3], Yi[3], Xi[0]-Xi[3],Yi[0]-Yi[3]);
702 
703 
704 // Free boundary xmid, ymid, radius_a, radius_b, start angle, end angle
705  UpdateIntface->SetParams(C_x, C_y, T_a, T_b, phi1, phi2);
706 
707 
708  N_RootCells = Out.numberoftriangles;
709 
710  // allocate auxillary fields
711  Coordinates = Out.pointlist;
712  Triangles = Out.trianglelist;
713  PartMarker = new int[Out.numberofpoints];
714 
715  // generate new vertices
716  N_G = Out.numberofpoints;
717  NewVertices = new TVertex*[N_G];
718 
719  for (i=0;i<N_G;i++)
720  NewVertices[i] = new TVertex(Coordinates[2*i], Coordinates[2*i+1]);
721 
722 // // set bounding box
723 // left = bottom = 1e8;
724 // right = top = -1e8;
725 //
726 // for(i=0;i<In.numberofpoints;i++)
727 // {
728 // if(left>In.pointlist[2*i]) left = In.pointlist[2*i];
729 // if(right<In.pointlist[2*i]) right = In.pointlist[2*i];
730 // if(top<In.pointlist[2*i+1]) top = In.pointlist[2*i+1];
731 // if(bottom>In.pointlist[2*i+1]) bottom = In.pointlist[2*i+1];
732 // }
733 
734 /* // Solid Bound startx, starty, x length and y length
735  UpdateSlipBound[0]->SetParams(Xi[0], Yi[0], Xi[1]-Xi[0],Yi[1]-Yi[0]);
736  UpdateSlipBound[1]->SetParams(Xi[1], Yi[1], Xi[2]-Xi[1],Yi[2]-Yi[1]);
737  UpdateSlipBound[2]->SetParams(Xi[2], Yi[2], Xi[3]-Xi[2],Yi[3]-Yi[2]);
738  UpdateSlipBound[3]->SetParams(Xi[3], Yi[3], Xi[0]-Xi[3],Yi[0]-Yi[3]);
739 
740 // Free boundary xmid, ymid, radius_a, radius_b, start angle, end angle
741  UpdateIntface->SetParams(C_x, C_y, T_a, T_b, phi1, phi2);*/
742 
743  // generate cells
744  CellTree = new TBaseCell*[N_RootCells];
745 
746  for (i=0;i<N_RootCells;i++)
747  {
748  CellTree[i] = new TMacroCell(TDatabase::RefDescDB[Triangle], 0);
749 
750  CellTree[i]->SetVertex(0, NewVertices[Out.trianglelist[3*i ]]);
751  CellTree[i]->SetVertex(1, NewVertices[Out.trianglelist[3*i + 1]]);
752  CellTree[i]->SetVertex(2, NewVertices[Out.trianglelist[3*i + 2]]);
753 
754  ((TMacroCell *) CellTree[i])->SetSubGridID(0);
755  }
756 
757  Domain->SetTreeInfo(CellTree, N_RootCells);
758 
759  // initialize iterators
760  TDatabase::IteratorDB[It_EQ]->SetParam(Domain);
761  TDatabase::IteratorDB[It_LE]->SetParam(Domain);
762  TDatabase::IteratorDB[It_Finest]->SetParam(Domain);
763  TDatabase::IteratorDB[It_Between]->SetParam(Domain);
764  TDatabase::IteratorDB[It_OCAF]->SetParam(Domain);
765 
766  // search neighbours
767  N_G = Out.numberofpoints;
768  PointNeighb = new int[N_G];
769 
770  memset(PointNeighb, 0, N_G *SizeOfInt);
771 
772  for (i=0;i<3*N_RootCells;i++)
773  PointNeighb[Triangles[i]]++;
774 
775  maxEpV=0;
776 
777  for (i=0;i<N_G;i++)
778  if (PointNeighb[i] > maxEpV) maxEpV = PointNeighb[i];
779  delete [] PointNeighb;
780 
781  PointNeighb = new int[++maxEpV * N_G];
782 
783  memset(PointNeighb, 0, maxEpV * N_G *SizeOfInt);
784 
785  // first colomn contains the number of following elements
786  // for every point at first column we set the number of neighbour points
787  // at further columns we set the index of corresponding cells
788  for(i=0;i<3*N_RootCells;i++)
789  {
790  j = Triangles[i]*maxEpV;
791  PointNeighb[j]++;
792  PointNeighb[j + PointNeighb[j]] = i / 3;
793  }
794 
795  // generate new edges
796  N_G = Out.numberofedges;
797  for (i=0;i<N_G;i++)
798  {
799  a = Out.edgelist[2*i];
800  b = Out.edgelist[2*i+1];
801  Neib[0] = -1;
802  Neib[1] = -1;
803  CurrNeib = 0;
804 
805  len1 = PointNeighb[a*maxEpV];
806  len2 = PointNeighb[b*maxEpV];
807 
808  // find indexes of cells containing the current edge
809  for (j=1;j<=len1;j++)
810  {
811  Neighb_tmp = PointNeighb[a*maxEpV + j];
812  for (k=1;k<=len2;k++)
813  if (Neighb_tmp == PointNeighb[b*maxEpV + k])
814  {
815  Neib[CurrNeib++] = Neighb_tmp;
816  break;
817  }
818  if (CurrNeib == 2) break;
819  }
820 
821 // cout<<BDpart << " BDpart CurrComp "<< CurrComp <<endl;
822 
823 
824 
825  if (Out.edgemarkerlist[i]) // 0 for inner edges and Boundcomp+1 for Boundedge respect
826  {
827  CurrComp = Out.edgemarkerlist[i] - 1;
828  if (CurrComp >= 100000) CurrComp -= 100000;
829 
830  BDpart=Domain->GetBdPartID(CurrComp);
831  CurrComp= Domain->GetLocalBdCompID(CurrComp);
832 
833 // cout<<BDpart << " BDpart CurrComp "<< CurrComp <<endl;
834 
835  if(Domain->GetBdPart(BDpart)->GetBdComp(CurrComp)->GetTofXY(
836  NewVertices[a]->GetX(), NewVertices[a]->GetY(), T_a) ||
837  Domain->GetBdPart(BDpart)->GetBdComp(CurrComp)->GetTofXY(
838  NewVertices[b]->GetX(), NewVertices[b]->GetY(), T_b))
839  {
840  cerr<<"Error: could not set parameter values"<<endl;
841  OutPut(NewVertices[a]<<endl);
842  OutPut(NewVertices[b]<<endl);
843  // exit(0);
844  }
845 
846 // ===============================================================================
847  // due to the hole the orientation of the circle is colck-wise from out side
848 // the parameter of the starting edge (in 0, 2pi) is for e.g (0, 0.9) (colck-wise)
849 // while refining to get the mid point we should get the mid point parameter as 0.95
850 // but we will get only (0+0.9)/2 =0.45 (wrong mid point). So we change.
851 // Note only if the orientation is colck-wise !!!!!!!
852 // ===============================================================================
853 
854  if(BDpart==1 && CurrComp==0 && fabs(T_a)==0 ) T_a=1;
855 
856 
857 // cout<<BDpart << " BDpart CurrComp "<< CurrComp <<endl;
858 
859 
860  if (CurrNeib == 2) // 2 cells contain the current edge
861  {
862  if(Domain->GetBdPart(BDpart)->GetBdComp(CurrComp)->IsFreeBoundary())
863  {
864  Joint = new TIsoInterfaceJoint(Domain->GetBdPart(BDpart)->GetBdComp(CurrComp),
865  T_a, T_b, CellTree[Neib[0]], CellTree[Neib[1]]);
866  }
867  else
868  {
869  Joint = new TInterfaceJoint(Domain->GetBdPart(BDpart)->GetBdComp(CurrComp),
870  T_a, T_b, CellTree[Neib[0]], CellTree[Neib[1]]);
871  }
872  }
873  else
874  {
875  if(Domain->GetBdPart(BDpart)->GetBdComp(CurrComp)->IsFreeBoundary())
876  {
877  Joint = new TIsoBoundEdge(Domain->GetBdPart(BDpart)->GetBdComp(CurrComp), T_a, T_b);
878 // cout<<" FreeBoundary"<<endl;
879  }
880  else
881  {
882  Joint = new TBoundEdge(Domain->GetBdPart(BDpart)->GetBdComp(CurrComp), T_a, T_b);
883  }
884  }
885  }
886  else // inner edge
887  {
888  if (CurrNeib != 2)
889  cerr << "Error!!!!!!!! not enough neighbours!" << endl;
890 
891  Joint = new TJointEqN(CellTree[Neib[0]], CellTree[Neib[1]]);
892  }
893 
894  // find the local index for the point 'a' on the cell
895  for (j=0;j<3;j++)
896  if (Triangles[3*Neib[0]+j] == a) break;
897 
898  // find the local index for the point 'b' on the cell
899  for (k=0;k<3;k++)
900  if (Triangles[3*Neib[0]+k] == b) break;
901 
902  k = k*10 + j;
903 
904  switch (k)
905  {
906  case 1:
907  case 10:
908  j = 0;
909  break;
910  case 12:
911  case 21:
912  j = 1;
913  break;
914  case 2:
915  case 20:
916  j = 2;
917  break;
918  }
919 
920  CellTree[Neib[0]]->SetJoint(j, Joint);
921 
922  if (Neib[1] != -1)
923  {
924  // find the local index for the point 'a' on the cell
925  for (j=0;j<3;j++)
926  if (Triangles[3*Neib[1]+j] == a) break;
927 
928  // find the local index for the point 'b' on the cell
929  for (k=0;k<3;k++)
930  if (Triangles[3*Neib[1]+k] == b) break;
931 
932  k = k*10 + j;
933 
934  switch (k) // j will contain the local index for the current
935  {
936  case 1:
937  case 10:
938  j = 0;
939  break;
940  case 12:
941  case 21:
942  j = 1;
943  break;
944  case 2:
945  case 20:
946  j = 2;
947  break;
948  }
949 
950  CellTree[Neib[1]]->SetJoint(j, Joint);
951  }
952 
953  if (Joint->GetType() == InterfaceJoint ||
954  Joint->GetType() == IsoInterfaceJoint)
955  ((TInterfaceJoint *) Joint)->CheckOrientation();
956  }
957 
958 
959  delete [] NewVertices;
960  delete [] PointNeighb;
961  delete [] In.pointlist;
962  delete [] In.pointmarkerlist;
963  delete [] In.segmentlist;
964  delete [] In.segmentmarkerlist;
965 
966  if(Out.pointlist!=NULL) {
967  free(Out.pointlist); Out.pointlist = NULL;}
968  if(Out.pointattributelist!=NULL) {
969  free(Out.pointattributelist); Out.pointattributelist = NULL;}
970  if(Out.pointmarkerlist!=NULL) {
971  free(Out.pointmarkerlist); Out.pointmarkerlist = NULL;}
972  if(Out.trianglelist!=NULL) {
973  free(Out.trianglelist); Out.trianglelist = NULL;}
974  if(Out.triangleattributelist!=NULL) {
975  free(Out.triangleattributelist); Out.triangleattributelist = NULL;}
976  if(Out.trianglearealist!=NULL) {
977  free(Out.trianglearealist); Out.trianglearealist = NULL;}
978  if(Out.neighborlist!=NULL) {
979  free(Out.neighborlist); Out.neighborlist = NULL;}
980  if(Out.segmentlist!=NULL) {
981  free(Out.segmentlist); Out.segmentlist = NULL;}
982  if(Out.segmentmarkerlist!=NULL) {
983  free(Out.segmentmarkerlist); Out.segmentmarkerlist = NULL;}
984  if(Out.holelist!=NULL) {
985  free(Out.holelist); Out.holelist = NULL;}
986  if(Out.regionlist!=NULL) {
987  free(Out.regionlist); Out.regionlist = NULL;}
988  if(Out.edgelist!=NULL) {
989  free(Out.edgelist); Out.edgelist = NULL;}
990  if(Out.edgemarkerlist!=NULL) {
991  free(Out.edgemarkerlist); Out.edgemarkerlist = NULL;}
992  if(Out.normlist!=NULL) {
993  free(Out.normlist); Out.normlist = NULL;}
994 
995 //======================================================================
996 // Triangular for grid generation --end
997 //======================================================================
998 
999 
1000 // cout<< "tetgen" <<endl;
1001 // exit(0);
1002 
1003 
1004 } // TriaReMeshGen
double * GetValues()
Definition: FEFunction2D.h:67
virtual int GetTofXY(double X, double Y, double &T)=0
static TFE2D * GetFE2D(FE2D FE)
Definition: FEDatabase2D.h:353
int GetLength()
Definition: FEFunction2D.h:63
void GetTreeInfo(TBaseCell **&celltree, int &N_rootcells)
get tree of cells
Definition: Domain.h:176
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
int GetBdPartID(int BdCompID)
get boundary part of BdCompID
Definition: Domain.C:88
void SetParams(double xmid, double ymid, double radius_a, double radius_b, double phi1, double phi2)
Definition: BdCircle.C:21
Definition: IsoBoundEdge.h:18
Definition: FE2D.h:20
Definition: gridgen.h:21
TBoundComp2D * GetBdComp(int i)
Definition: BoundPart.h:49
int SetJoint(int J_i, TJoint *J)
set the pointer to face J_i to J
Definition: BaseCell.h:168
contains the boundary description, the virtual cell tree and macro grid
Definition: Domain.h:36
void SetParams(double xstart, double ystart, double delx, double dely)
Definition: BdLine.C:21
Definition: FESpace2D.h:28
double RE_NR
Definition: Database.h:313
int SetParam(TDomain *domain)
Definition: Iterator.C:17
static double ** GetOrigElementValues(BaseFunct1D BaseFunct, MultiIndex1D MultiIndex)
Definition: FEDatabase2D.h:300
static TIterator ** IteratorDB
Definition: Database.h:1131
store cells in an array, used by cell iterators
Definition: Collection.h:18
int GetN_Joints()
return the number of joints
Definition: BaseCell.h:185
virtual TVertex * GetVertex(int Vert_i)=0
return the pointer to vertex with number i
represent a unit of the macro grid
Definition: MacroCell.h:15
Definition: JointEqN.h:20
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
TBoundPart * GetBdPart(int i)
get i-th boundary part
Definition: Domain.h:172
FE2D GetFE2D(int i, TBaseCell *cell)
Definition: FESpace2D.C:1184
TFEDesc2D * GetFEDesc2D() const
Definition: FE2D.h:97
int GetN_Vertices()
return the number of vertices of the cell
Definition: BaseCell.h:179
int ** GetJointDOF() const
Definition: FEDesc2D.h:86
static BaseFunct2D * GetBaseFunct2D_IDFromFE2D()
Definition: FEDatabase2D.h:417
Definition: BoundPart.h:21
void SetTreeInfo(TBaseCell **celltree, int N_rootcells)
set tree of cells
Definition: Domain.h:183
static int * GetN_BaseFunctFromFE2D()
Definition: FEDatabase2D.h:421
bool IsFreeBoundary() const
Definition: BoundComp.h:57
TCollection * GetCollection(Iterators it, int level)
produce a collection with all cells returned by iterator it
Definition: Domain.C:1982
int GetID() const
Definition: BoundComp.h:49
Definition: BdCircle.h:18
information for finite element data structure
Definition: BaseCell.h:25
int * GetGlobalNumbers() const
Definition: FESpace.h:135
Definition: Vertex.h:19
int GetN_Edges()
return the number of edges of the cell
Definition: BaseCell.h:182
static TRefDesc ** RefDescDB
Definition: Database.h:1125
Definition: BoundEdge.h:19
Definition: IsoInterfaceJoint.h:18
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
virtual int SetVertex(int Vert_i, TVertex *Vert)=0
set the pointer of vertex Vert_i to Vert
Definition: FEDesc2D.h:15
Definition: BdLine.h:18
represent geometric information of the cell
Definition: GridCell.h:15
int * GetBeginIndex() const
Definition: FESpace.h:142
int GetN_JointDOF() const
Definition: FEDesc2D.h:61
Definition: InterfaceJoint.h:18
static TParamDB * ParamDB
Definition: Database.h:1134
int GetLocalBdCompID(int BdCompID)
get local number of boundary component
Definition: Domain.C:98
Definition: FEFunction2D.h:24