Overture  Version 25
AdvancingFront.h
Go to the documentation of this file.
1 #ifndef __KKC_AdvancingFront__
2 #define __KKC_AdvancingFront__
3 
4 #define USE_SARRAY
5 //#define USE_GADT2
6 
7 #include "OvertureDefine.h"
8 #include "OvertureTypes.h"
9 
10 #ifndef OV_USE_OLD_STL_HEADERS
11 #include <vector>
12 #include <map>
13 #include <list>
15 #else
16 #include <vector.h>
17 #include <map.h>
18 #include <list.h>
19 #endif
20 
21 #include "PriorityQueue.h"
22 
23 #include "Overture.h"
24 #include "PlotStuff.h"
25 #include "Mapping.h"
26 #include "MappingInformation.h"
27 #include "Face.h"
28 
29 #ifdef USE_GADT2
30 #include "GeometricADT2.h"
31 #else
32 #include "GeometricADT.h"
33 #endif
34 
35 #include "OvertureDefine.h"
36 #include "AbstractException.h"
37 #include "Mapping.h"
38 #include "UnstructuredMapping.h"
39 #include "CompositeGridFunction.h"
41 #include "ArraySimple.h"
42 
43 //typedef PriorityQueueTemplate<Face *> PriorityQueue;
45 
47 {
48 
49  // friend class PlotStuff;
50 
51 public:
52 
53 
55  AdvancingFront(intArray &initialFaces, realArray &xyz_in, MappingInformation *backgroundMappings_=NULL);
56 
57  virtual ~AdvancingFront();
58 
59  void initialize(intArray &initialFaces, realArray &xyz_in, MappingInformation *backgroundMappings_= NULL, intArray &initialFaceSurfaceMapping_ = Overture::nullIntegerDistributedArray());
60 
61  bool isFrontEmpty() const;
62 
63  //int insertFace(const IntegerArray &vertexIDs, int z1, int z2);
64  int insertFace( const ArraySimple<int> &vertexIDs, int z1, int z2 );
65  int advanceFront(int nSteps = 1);
66 
68 
70 
71  // PriorityQueue::iterator getFrontIteratorForFace(const IntegerArray &faceVertices);
72  // bool existsInFront(const IntegerArray &);
74  bool existsInFront(const ArraySimple<int> &);
75  bool existsInFront(const int p1, const int p2);
76 
77  void plot(PlotStuff & ps, PlotStuffParameters & psp);
78 
79  bool expandFront();
80 
81  // getFaces and getFront are used in the plotAdvancingFront method
82  const vector<Face *> & getFaces() const { return faces; }
83  const PriorityQueue & getFront() const { return front; }
84 
85  const realArray & getVertices() { return xyz; }
86  const vector< vector<int> > & getElements() const { return elements; }
87 
88  intArray generateElementList( bool removeUnusedNodes = true ); // generates the list of points in each element, used to build an unstructuredMapping
89  intArray generateElementFaceList(); // generate the list of Adv. Front faces in each element
90 
91  // get various dimensional information
92  int getRangeDimension() const { return rangeDimension; }
93  int getDomainDimension() const { return domainDimension; }
94  int getNumberOfVertices() const { return nptsTotal; }
95  int getNumberOfFaces() const { return nFacesTotal; }
96  int getNumberOfElements() const { return nElements; }
97 
99 
101  bool vertexIsOnFront(int v);
102 
103  // get and set the spacing control grid
105  void setControlFunction(const CompositeGrid & controlGrid_, const realCompositeGridFunction & controlFunction_)
106  {
107  controlGrid.reference(controlGrid_);
109  controlFunction.reference(controlFunction_);
110  }
111 
112  // destroy the information in this class, reset to some basic state
113  void destroyFront();
114 
115  int computeTransformationAtPoint(realArray &midPt, ArraySimple<real> &T); // computes a mesh control transformation based on the data in the controlFunction
116 
117 protected:
118 
120 
121  int nFacesFront; // number of faces in the front
122  int nFacesTotal; // total number of faces generated
123  int nFacesEst; // estimated number of faces to be generated
124  int nptsTotal; // number of points in the mesh so far (size of used portion of xyz)
125  int nptsEst; // estimated number of points to be created
126  int nElements; // total number of elements generated
127  int nElementsEst; // current estimate on the total number of elements to be generated
128 
133 
135 
137 
138  vector<Face *> faces; // a vector of all the faces, indexed by face id
139  vector<int> foo;
140  vector< vector<int> > elements; // a list containing the elements identified by thier faces
141  realArray elementQuality; // the quality of each valid element in elements
142  PriorityQueue front; // a priority queue for the front
143  realArray xyz; // the positions of the points
144  realArray faceNormals; // precomputed face normals
145 
147 
148  enum TimingsEnum {
179  };
180 
182 
183  struct cmpFace { bool operator() (const int i1, const int i2) const { return (i1<i2); } }; // used in the map below
184  map<int, vector< PriorityQueue::iterator >, cmpFace> pointFaceMapping; // maps a point id to the faces that have that point as point "1" (basically a simple hash table)
185 
186 #ifdef USE_GADT2
187  GeometricADT<Face *,4> faceSearcher; // Geometric search ADT used to detect intersections
188  GeometricADT<int,4> vertexSearcher; // Geometric search ADT used to find vertices in bounding boxes
189 #else
190  GeometricADT<Face *> faceSearcher; // Geometric search ADT used to detect intersections
191  GeometricADT<int> vertexSearcher; // Geometric search ADT used to find vertices in bounding boxes
192 #endif
193 
194  CompositeGrid controlGrid; // meshes used to define control functions
195  realCompositeGridFunction controlFunction; // function used to define stretching/distribution functions
196  //Mapping *backgroundMapping; // background parametric mapping
197  MappingInformation backgroundMappings; // mappings used to project points while makeing surface meshes
198 
200 
201  //void gatherExistingCandidates(const Face & face, real distance, ArraySimple<real> & pIdealTrans,
202  // ArraySimple<real> & T, ArraySimple<real> & Tinv, vector<int> &existing_candidates);
203  void gatherExistingCandidates(const Face & face, real distance, ArraySimple<real> & pIdealTrans,
204  ArraySimple<real> &pIdealPhys, ArraySimple<real> & T, ArraySimple<real> & Tinv, vector<int> &existing_candidates, vector<int> &existing_candidates_neighb, vector<int> &local_nodes);
205 
206  void computeVertexCandidates(const ArraySimple<real> &currentFaceVerticesTrans,
207  const ArraySimple<real> &pIdealTrans, vector<int> &existing_candidates,
208  const ArraySimple<real> &T, ArraySimple<real> &new_candidates, real rad);
209 
210 
211  bool makeTriTetFromExistingVertices(const Face &currentFace, int newElementID,
212  const vector<int> &existing_candidates, const vector<int> &local_nodes,
213  vector<PriorityQueue::iterator > &oldFrontFaces);
214 
215  //bool makeTriTetFromNewVertex(const Face & currentFace, int newElementID,
216  // realArray &new_candidates);
217  bool makeTriTetFromNewVertex(const Face & currentFace, int newElementID,
218  ArraySimple<real> &new_candidates, vector<int> &local_nodes);
219 
220  bool makeTriOnSurface(const Face &currentFace, int newElementID,
221  const vector<int> &existing_candidates,
222  ArraySimple<real> &new_candidates, vector<PriorityQueue::iterator > &oldFrontFaces);
223 
224 #if 0
225  bool makePrismPyramidHex(const Face & currentFace, int newElementID, const ArraySimple<real> &pIdealPhys,
226  const ArraySimple<real> &T, vector<int> &existing_candidates,
227  vector<PriorityQueue::iterator > &oldFrontFaces);
228 #endif
229 
230  // bool isFaceConsistent(const IntegerArray &, const Face & filterFace); //const; // essentially checks for intersections
231  //bool isFaceConsistent(const realArray & , const Face & filterFace); //const; // again.
232  bool isFaceConsistent(const ArraySimple<int> &, const Face & filterFace); //const; // essentially checks for intersections
233  bool isFaceConsistent(const ArraySimple<real> & , const Face & filterFace); //const; // again.
234  bool isFaceConsistent2D(const ArraySimple<real> &p1, const ArraySimple<real> &p2, const int filterFace) const;
235 
236  bool isFaceConsistent2D(int v1, int v2, int filterFace) const;
237 
238  // bool isFaceConsistent2D_3R(const ArraySimple<int> &, const Face & filterFace); //const; // essentially checks for intersections
239  // bool isFaceConsistent2D_3R(const ArraySimple<real> & , const Face & filterFace); //const; // again.
240 
241  bool isFaceConsistent3D(const ArraySimple<int> &, const Face & filterFace); //const; // essentially checks for intersections
242  bool isFaceConsistent3D(const ArraySimple<real> & , const Face & filterFace); //const; // again.
243 
244  bool isOnFacePlane( const Face & face, ArraySimple<real> &vertex );
245  bool checkVertexDirection( const Face & face, const ArraySimple<real> &vertex ) const;
246 
248  void computeFaceNormal(const ArraySimple<real> &vertices, ArraySimple<real> & normal, int subsurf = -1);
249 
250  void addFaceToFront(Face &);
251 
252  // bool auxiliaryCheck(Face &face, ArraySimple<real> &faceNormal);
253  bool auxiliaryCheck(ArraySimple<real> &candNormal, ArraySimple<real> &faceNormal);
254  int resizeFaces(int newSize); // resizes face relevant arrays
255  //int addPoint(const realArray &newPt); // adds a new point to the list of points, resizes if needed
256  int addPoint(const ArraySimple<real> &newPt); // adds a new point to the list of points, resizes if needed
257 
258  void addFaceToElement(int face, int elem); // adds a face to an element
259  void removeFaceFromFront(PriorityQueue::iterator&); // deletes a face from the front as well as associated data structures
260  int transformCoordinatesToParametricSpace(realArray &xyz_in, realArray &xyz_param); // for parameterized surfacees
261 
263  void computeFaceNormalTransformation(const realArray &vertices, ArraySimple<real> &T, double stretch=1.0); // computes a mesh control transformation based on the current Face`s size and position
264  real computeElementQuality(int element);
265  void improveQuality();
266 
267  bool newElementVertexCheck(const Face &currentFace, vector<int> &local_nodes,
268  ArraySimpleFixed<real,3,1,1,1> &pc, int filterNode = -1);
269 
270  void removeUnusedNodes();
271 
272 private:
273 
274 };
275 
276 // AdvancingFront exceptions ( it would be nice to use namespaces...)
278 {
279 public:
280  virtual void debug_print() const { cerr<<"\nAdvancingFront Error"; }
281 };
282 
284 {
285 public:
286  void debug_print() const
287  {
288  //AdvancingFront::AdvancingFrontError::debug_print();
289  cerr<<": BookKeepingError : Errors found with mesh bookeeping ";
290  }
291 };
292 
294 {
295 public:
296  void debug_print() const
297  {
298  //AdvancingFront::AdvancingFrontError::debug_print();
299  cerr<<": DimensionError : Internal error with dimensions used in internal vectors";
300  }
301 };
302 
304 {
305 public:
306  void debug_print() const
307  {
308  //AdvancingFront::AdvancingFrontError::debug_print();
309  cerr<<": AdvanceFailedError : The front is not empty but could not be advanced, probably a bug in the algorithm";
310  }
311 };
312 
314 {
315 public:
316  void debug_print() const
317  {
318  //AdvancingFront::AdvancingFrontError::debug_print();
319  cerr<<": FrontInsertionFailedError : A problem occurred inserting a new face into the front, probably a bug in the algorithm";
320  }
321 };
322 
323 
324 #endif