Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
volume.cpp
Go to the documentation of this file.
1 /* *******************************************************************
2  * Illinois Open Source License *
3  * *
4  * University of Illinois/NCSA *
5  * Open Source License *
6  * *
7  * Copyright@2008, University of Illinois. All rights reserved. *
8  * *
9  * Developed by: *
10  * *
11  * Center for Simulation of Advanced Rockets *
12  * *
13  * University of Illinois *
14  * *
15  * www.csar.uiuc.edu *
16  * *
17  * Permission is hereby granted, free of charge, to any person *
18  * obtaining a copy of this software and associated documentation *
19  * files (the "Software"), to deal with the Software without *
20  * restriction, including without limitation the rights to use, *
21  * copy, modify, merge, publish, distribute, sublicense, and/or *
22  * sell copies of the Software, and to permit persons to whom the *
23  * Software is furnished to do so, subject to the following *
24  * conditions: *
25  * *
26  * *
27  * @ Redistributions of source code must retain the above copyright *
28  * notice, this list of conditions and the following disclaimers. *
29  * *
30  * @ Redistributions in binary form must reproduce the above *
31  * copyright notice, this list of conditions and the following *
32  * disclaimers in the documentation and/or other materials *
33  * provided with the distribution. *
34  * *
35  * @ Neither the names of the Center for Simulation of Advanced *
36  * Rockets, the University of Illinois, nor the names of its *
37  * contributors may be used to endorse or promote products derived *
38  * from this Software without specific prior written permission. *
39  * *
40  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
41  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
42  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
43  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
44  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
45  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
46  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
47  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
48  *********************************************************************
49  * Please acknowledge The University of Illinois Center for *
50  * Simulation of Advanced Rockets in works and publications *
51  * resulting from this software or its derivatives. *
52  *********************************************************************/
53 /*
54 Check the quality of the input mesh, using the
55 same criteria used by Rocflo.
56 
57 Inside Rocflo, mesh volumes are computed using the routines:
58  RocfluidMP/libfloflu/controlVolume.F90 : VolumeHexa
59  Called by RFLO_calcControlVolumes.F90 and stored in "vol".
60  RocfluidMP/libfloflu/faceVector.F90 : FaceVectorQuad
61  Called by RFLO_calcFaceVectors.F90 and stored in "s[ijk]".
62 
63 These volumes are used by RocfluidMP/rocflo/RFLO_checkMetrics.F90,
64 which checks:
65  Face area-normal-sum-max against 0.1*(shortest edge squared).
66  Cell volume checked against 0.1*(shortest edge cubed).
67 
68 Orion Sky Lawlor, olawlor@acm.org, 2004/7/6
69 */
70 #include <stdio.h>
71 #include "adj.h"
72 #include "ckstatistics.h"
73 
74 void checkQuality(const block &b)
75 {
76  int nBadVol=0, nBadFace=0;
77  double minVolRatio=1.0;
78  blockLoc aBadVol, aBadFace;
79  CkSample edgeStats, volumeStats, volRatioStats, faceRatioStats;
80  /* loop over all cells in the block */
81  blockLoc cellCoor;
82  blockSpan cells(blockLoc(0,0,0),b.getDim()-blockLoc(1,1,1));
83 
84  enum {nCorners=8,nEdges=12,nFaces=6};
85  vector3d c[nCorners];
86  int i,j,k,f,e;
87 
88  /* Check the quality of each cell */
89  BLOCKSPAN_FOR(cellCoor,cells) {
90 
91  // Copy out the locations of the cell corners
92  for (k=0;k<2;k++) for (j=0;j<2;j++) for (i=0;i<2;i++)
93  c[i+2*j+4*k]=b.getLoc(cellCoor+blockLoc(i,j,k));
94 
95  /* Find the minimum edge length for this cell.
96  FIXME: Rocflo's criterion depends on the minimum edge
97  length for *any* cell in the (partitioned) block. This means
98  our per-cell criterion is actually more stringent than Rocflo's.
99  */
100  double minEdge=1.0e30;
101 
102  // Compute the length of the shortest edge
103  const static int edges[nEdges][2]={
104  {0,1}, {1,3}, {3,2}, {2,0},
105  {4,5}, {5,7}, {7,6}, {6,4},
106  {0,4}, {1,5}, {3,7}, {2,6}
107  };
108  for (e=0;e<nEdges;e++) {
109  double l=c[edges[e][0]].dist(c[edges[e][1]]);
110  if (l<minEdge) minEdge=l;
111  edgeStats.add(l);
112  }
113 
114  // Compute the outward-pointing normals of the faces
115  const static int faces[nFaces][4]={
116  {0,4,6,2}, {1,3,7,5}, /* imin, imax */
117  {0,1,5,4}, {2,6,7,3}, /* jmin, jmax */
118  {0,2,3,1}, {4,5,7,6} /* kmin, kmax */
119  };
120  vector3d normals[nFaces]; // area-scaled normal vector
121  vector3d center[nFaces]; // position of centroid
122  for (f=0;f<nFaces;f++)
123  { // Area and normal come from face diagonals:
124  vector3d diagA=c[faces[f][2]]-c[faces[f][0]];
125  vector3d diagB=c[faces[f][3]]-c[faces[f][1]];
126  normals[f]=0.5*diagA.cross(diagB);
127  center[f]=0.25*(c[faces[f][0]]+c[faces[f][1]]+
128  c[faces[f][2]]+c[faces[f][3]]);
129  }
130 
131  // Check face vector sum (closedness, smaller is better)
132  vector3d faceVecSum=
133  normals[0]+normals[1]+
134  normals[2]+normals[3]+
135  normals[4]+normals[5];
136  double faceRatio=faceVecSum.max()/(minEdge*minEdge);
137  if (faceRatio>0.1) { /* non-closed face */
138  nBadFace++;
139  aBadFace=cellCoor;
140  }
141 
142  // Compute volume of cell relative to smallest edge (fullness, bigger is better)
143  double volume=0.0;
144  for (f=0;f<nFaces;f++)
145  volume+=(1.0/3.0)*normals[f].dot(center[f]);
146 
147  double volRatio=volume/(minEdge*minEdge*minEdge);
148  if (volRatio<0.1) { /* bad skinny cell */
149  nBadVol++;
150  if (volRatio<minVolRatio) {
151  minVolRatio=volRatio;
152  aBadVol=cellCoor;
153  }
154  }
155 
156  // Update statistics
157  faceRatioStats.add(faceRatio);
158  volumeStats.add(volume);
159  volRatioStats.add(volRatio);
160  }
161 
162  printf("Original block %d mesh quality:\n",1+b.getOriginalNumber());
163  printf(" cell volumes: "); volumeStats.printMinAveMax(stdout);
164  printf(" edge lengths: "); edgeStats.printMinAveMax(stdout);
165  printf(" volume ratio (fullness): "); volRatioStats.printMinAveMax(stdout);
166  printf(" face ratio (skewness): "); faceRatioStats.printMinAveMax(stdout);
167 
168  if (nBadVol>0) {
169  printf("WARNING: detected %d bad-volume cells in original block %d: \n"
170  " the worst of which is cell (%d,%d,%d), with ratio %.3f\n",
171  nBadVol, b.getOriginalNumber(),
172  1+aBadVol[0],1+aBadVol[1],1+aBadVol[2], minVolRatio);
173  }
174 }
175 
176 
CkSampleT represents a statistical &quot;sample&quot; of some data values.
Definition: ckstatistics.h:79
int getOriginalNumber(void) const
Definition: adj.h:220
vector3d cross(const vector3d &b) const
Definition: vector3d.h:146
real dist(const vector3d &b) const
Definition: vector3d.h:136
j indices k indices k
Definition: Indexing.h:6
void printMinAveMax(FILE *dest)
Print a terse textual description of this sample to this FILE.
Definition: ckstatistics.h:153
Definition: adj.h:203
#define BLOCKSPAN_FOR(i, span)
Definition: gridutil.h:230
int volume(const block *b)
Definition: split.cpp:181
void checkQuality(const block &b)
Definition: volume.cpp:74
const blockDim & getDim(void) const
Definition: adj.h:222
blockLoc i
Definition: read.cpp:79
void add(real r)
Add this value to the sample set.
Definition: ckstatistics.h:95
const vector3d & getLoc(const blockLoc &l) const
Definition: adj.h:223
j indices j
Definition: Indexing.h:6
real max(void)
Definition: vector3d.h:151