Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
volume.cpp File Reference
#include <stdio.h>
#include "adj.h"
#include "ckstatistics.h"
Include dependency graph for volume.cpp:

Go to the source code of this file.

Functions

void checkQuality (const block &b)
 

Function Documentation

void checkQuality ( const block b)

Definition at line 74 of file volume.cpp.

References CkSampleT< real, ret >::add(), BLOCKSPAN_FOR, vector3d::cross(), vector3d::dist(), block::getDim(), block::getLoc(), block::getOriginalNumber(), i, j, k, vector3d::max(), CkSampleT< real, ret >::printMinAveMax(), and volume().

Referenced by main().

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 }
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
#define BLOCKSPAN_FOR(i, span)
Definition: gridutil.h:230
int volume(const block *b)
Definition: split.cpp:181
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

Here is the call graph for this function:

Here is the caller graph for this function: