DFNgen  2.0
DFN Model Generator
insertUserEllByCoord.cpp
Go to the documentation of this file.
1 #include <cmath>
2 #include <iostream>
3 #include "insertShape.h"
4 #include "vectorFunctions.h"
5 #include "mathFunctions.h"
7 #include "structures.h"
8 #include "input.h"
9 #include "domain.h"
10 
11 /****************************************************************/
12 /*********** Insert User Ellipses By Coord ********************/
21 void insertUserEllByCoord(std::vector<Poly>& acceptedPoly, std::vector<IntPoints> &intpts, struct Stats &pstats, std::vector<Point> &triplePoints) {
22 
23  std::cout << "\n" << nEllByCoord << " User Ellipses By Coordinates Defined\n\n";
24 
25  for (unsigned int i = 0; i < nEllByCoord; i++) {
26 
27  Poly newPoly;
28  newPoly.familyNum = -1; // Using -1 for all user specified ellipses
29 
30  newPoly.vertices = new double[3 * nEllNodes]; // 3 * number of nodes
31 
32  // Set number of nodes - needed for rotations
33  newPoly.numberOfNodes = nEllNodes;
34 
35  int polyVertIdx = i*3*nEllNodes; // Each polygon has nEllNodes * 3 vertices
36 
37  // Initialize vertices
38  for (unsigned int j = 0; j < nEllNodes; j++) {
39  int vIdx = j*3;
40  newPoly.vertices[vIdx] = userEllCoordVertices[polyVertIdx+vIdx];
41  newPoly.vertices[vIdx+1] = userEllCoordVertices[polyVertIdx+1+vIdx];
42  newPoly.vertices[vIdx+2] = userEllCoordVertices[polyVertIdx+2+vIdx];
43  }
44 
45  // Get a normal vector
46  // Vector from fist node to node accross middle of polygon
47  int midPtIdx = 3 * (int) (nEllNodes/2);
48  double v1[3] = {newPoly.vertices[midPtIdx]-newPoly.vertices[0],
49  newPoly.vertices[midPtIdx+1]-newPoly.vertices[1],
50  newPoly.vertices[midPtIdx+2]-newPoly.vertices[2]};
51  // Vector from first node to 2nd node
52  double v2[3] = {newPoly.vertices[3]-newPoly.vertices[0],
53  newPoly.vertices[4]-newPoly.vertices[1],
54  newPoly.vertices[5]-newPoly.vertices[2]};
55  double *xProd1 = crossProduct(v2, v1);
56 
57  // Set normal vector
58  newPoly.normal[0] = xProd1[0]; //x
59  newPoly.normal[1] = xProd1[1]; //y
60  newPoly.normal[2] = xProd1[2]; //z
61 
62  normalize(newPoly.normal);
63 
64  delete[] xProd1;
65 
66  // Estimate radius
67  newPoly.xradius = .5 * magnitude(v2[0],v2[1],v2[2]); // across middle if even number of nodes
68 
69  int tempIdx1 = 3 * (int) (midPtIdx / 2) ; // Get idx for node 1/4 around polygon
70  int tempIdx2 = 3 * (tempIdx1 + midPtIdx); // Get idx for node 3/4 around polygon
71 
72  // across middle close to perpendicular to xradius magnitude calculation
73  newPoly.yradius = .5 * euclideanDistance(&newPoly.vertices[tempIdx1], &newPoly.vertices[tempIdx2]);
74  newPoly.aspectRatio = newPoly.yradius/newPoly.xradius;
75 
76  // Estimate translation (middle of poly)
77  // Use midpoint between 1st and and half way around polygon
78  // Note: For polygons defined by coordinates, the coordinates
79  // themselves provide the translation. We need to estimate the center
80  // of the polygon and init. the translation array
81  newPoly.translation[0] = .5*(newPoly.vertices[0]+newPoly.vertices[midPtIdx]);
82  newPoly.translation[1] = .5*(newPoly.vertices[1]+newPoly.vertices[midPtIdx+1]);
83  newPoly.translation[2] = .5*(newPoly.vertices[2]+newPoly.vertices[midPtIdx+2]);
84 
85  if (domainTruncation(newPoly, domainSize) == 1) {
86  // Poly completely outside domain
87  delete[] newPoly.vertices;
88  pstats.rejectionReasons.outside++;
89  pstats.rejectedPolyCount++;
90  std::cout << "\nUser Ellipse (defined by coordinates) " << i+1 << " was rejected for being outside the defined domain.\n";
91  continue; // Go to next poly (go to next iteration of for loop)
92  }
93 
94  createBoundingBox(newPoly);
95 
96  // Line of intersection and FRAM
97  int rejectCode = intersectionChecking(newPoly, acceptedPoly, intpts, pstats, triplePoints);
98  if(rejectCode == 0) {
99  // If intersection is ok (FRAM passed all tests)
100 
101  if (newPoly.truncated == 1) {
102  pstats.truncated++;
103  }
104 
105  // Incriment counter of accepted polys
106  pstats.acceptedPolyCount++;
107 
108  // Calculate poly's area
109  newPoly.area = getArea(newPoly);
110 
111  // Add new rejectsPerAttempt counter
112  pstats.rejectsPerAttempt.push_back(0);
113 
114  std::cout << "\nUser Defined Elliptical Fracture (Defined By Coordinates) " << (i+1) << " Accepted\n";
115  acceptedPoly.push_back(newPoly); // Save newPoly to accepted polys list
116  }
117  else {
118  delete[] newPoly.vertices; // Need to delete manually, created with new[]
119  pstats.rejectsPerAttempt[pstats.acceptedPolyCount]++;
120  pstats.rejectedPolyCount++;
121  std::cout << "\nRejected Eser Defined Elliptical Fracture (Defined By Coordinates) " << i+1 << "\n";
122  printRejectReason(rejectCode, newPoly);
123  }
124  } // End loop
125 
126  delete[] userEllCoordVertices;
127 }
128 
double euclideanDistance(double *A, double *B)
T magnitude(T x, T y, T z)
void normalize(T *vec)
bool truncated
Definition: structures.h:95
double * userEllCoordVertices
Definition: readInput.cpp:397
int numberOfNodes
Definition: structures.h:14
double getArea(struct Poly &poly)
unsigned int truncated
Definition: structures.h:311
struct RejectionReasons rejectionReasons
Definition: structures.h:339
float aspectRatio
Definition: structures.h:49
unsigned long long int outside
Definition: structures.h:262
std::vector< unsigned int > rejectsPerAttempt
Definition: structures.h:371
double * vertices
Definition: structures.h:70
void insertUserEllByCoord(std::vector< Poly > &acceptedPoly, std::vector< IntPoints > &intpts, struct Stats &pstats, std::vector< Point > &triplePoints)
double yradius
Definition: structures.h:46
void createBoundingBox(struct Poly &newPoly)
unsigned int nEllNodes
Definition: readInput.cpp:389
bool domainTruncation(Poly &newPoly, double *domainSize)
Definition: domain.cpp:19
double xradius
Definition: structures.h:40
unsigned int nEllByCoord
Definition: readInput.cpp:386
double normal[3]
Definition: structures.h:55
float area
Definition: structures.h:33
int intersectionChecking(struct Poly &newPoly, std::vector< Poly > &acceptedPoly, std::vector< IntPoints > &intPtsList, struct Stats &pstats, std::vector< Point > &triplePoints)
void printRejectReason(int rejectCode, struct Poly newPoly)
double domainSize[3]
Definition: readInput.cpp:18
int familyNum
Definition: structures.h:22
T * crossProduct(const T *v1, const T *v2)
unsigned int acceptedPolyCount
Definition: structures.h:300
double translation[3]
Definition: structures.h:52
unsigned long long int rejectedPolyCount
Definition: structures.h:304