DFNgen  2.0
DFN Model Generator
insertUserEll.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 "input.h"
8 #include "generatingPoints.h"
9 #include "domain.h"
10 #include "testing.h"
11 
12 /***********************************************************************/
13 /********************* Insert User Ellipse ***************************/
21 void insertUserEll(std::vector<Poly>& acceptedPoly, std::vector<IntPoints> &intpts,struct Stats &pstats, std::vector<Point> &triplePoints) {
22 
23  std::cout << "\n" << nUserEll << " User Ellipses Defined\n\n";
24 
25  for (int i = 0; i < nUserEll; i++) {
26 
27  int index = i*3; // Index to start of vertices/nodes
28 
29  Poly newPoly; // New poly/fracture to be tested
30  newPoly.familyNum = -1; // Using -1 for all user specified ellipses
31 
32  newPoly.vertices = new double[uenumPoints[i]*3];
33 
34  // Set number of nodes - needed for rotations
35  newPoly.numberOfNodes = uenumPoints[i];
36 
37  // Initialize translation data
38  newPoly.translation[0] = uetranslation[index];
39  newPoly.translation[1] = uetranslation[index+1];
40  newPoly.translation[2] = uetranslation[index+2];
41 
42  // Generate theta array used to place vertices
43  float *thetaAry;
44  generateTheta(thetaAry, ueaspect[i], uenumPoints[i]);
45 
46  // Initialize vertices on x-y plane
47  initializeEllVertices(newPoly, ueRadii[i], ueaspect[i], thetaAry, uenumPoints[i]);
48 
49  delete[] thetaAry;
50 
51  // Convert angle to rad if necessary
52  float angle = ueBeta[i];
53  if (ueAngleOption == 1 ){
54  angle = ueBeta[i] * M_PI/180;
55  }
56  else {
57  angle = ueBeta[i];
58  }
59 
60  // Initialize normal to {0,0,1}. need initialized for 3D rotation
61  newPoly.normal[0] = 0; //x
62  newPoly.normal[1] = 0; //y
63  newPoly.normal[2] = 1; //z
64 
65  // Apply 2d rotation matrix, twist around origin
66  // Assumes polygon on x-y plane
67  // Angle must be in rad
68  applyRotation2D(newPoly, angle);
69 
70  // Normalize user denined normal vector
71  normalize(&uenormal[index]);
72 
73  // Rotate vertices to uenormal[index] (new normal)
74  applyRotation3D(newPoly, &uenormal[index]);
75 
76  // Save newPoly's new normal vector
77  newPoly.normal[0] = uenormal[index];
78  newPoly.normal[1] = uenormal[index+1];
79  newPoly.normal[2] = uenormal[index+2];
80 
81  // Translate newPoly to uetranslation
82  translate(newPoly, &uetranslation[index]);
83 
84  if (domainTruncation(newPoly, domainSize) == 1) {
85  // Poly completely outside domain
86  delete[] newPoly.vertices;
87  pstats.rejectionReasons.outside++;
88  pstats.rejectedPolyCount++;
89  std::cout<<"\nUser Ellipse "<< i+1 <<" was rejected for being outside the defined domain.\n";
90  continue; // Go to next poly (go to next iteration of for loop)
91  }
92 
93  createBoundingBox(newPoly);
94 
95  // Line of intersection and FRAM
96  int rejectCode = intersectionChecking(newPoly, acceptedPoly, intpts, pstats, triplePoints);
97 
98  if(rejectCode == 0) {//if intersection is ok
99 
100  if (newPoly.truncated == 1) {
101  pstats.truncated++;
102  }
103 
104  // Incriment counter of accepted polys
105  pstats.acceptedPolyCount++;
106 
107  // Calculate poly's area
108  newPoly.area = getArea(newPoly);
109 
110  // Add new rejectsPerAttempt counter
111  pstats.rejectsPerAttempt.push_back(0);
112 
113  std::cout<<"User Defined Elliptical Fracture "<<(i+1)<<" Accepted\n";
114  acceptedPoly.push_back(newPoly); // Save newPoly to accepted polys list
115  }
116  else {
117  delete[] newPoly.vertices; // Need to delete manually, created with new[]
118  pstats.rejectsPerAttempt[pstats.acceptedPolyCount]++;
119  pstats.rejectedPolyCount++;
120  std::cout<<"\nRejected User Defined Elliptical Fracture "<< i+1<<"\n";
121  printRejectReason(rejectCode, newPoly);
122 
123  #ifdef TESTING
124  exit(1);
125  #endif
126  }
127  std::cout<<"\n\n";
128  } // End loops
129 
130  delete[] ueRadii;
131  delete[] ueaspect;
132  delete[] ueBeta;
133  delete[] uetranslation;
134  delete[] uenormal;
135  delete[] uenumPoints;
136 
137 }
138 
139 
140 
141 
void translate(Poly &newPoly, double *translation)
double * uenormal
Definition: readInput.cpp:329
void normalize(T *vec)
bool truncated
Definition: structures.h:95
int numberOfNodes
Definition: structures.h:14
int nUserEll
Definition: readInput.cpp:309
bool ueAngleOption
Definition: readInput.cpp:314
float * ueaspect
Definition: readInput.cpp:323
double getArea(struct Poly &poly)
unsigned int truncated
Definition: structures.h:311
struct RejectionReasons rejectionReasons
Definition: structures.h:339
unsigned long long int outside
Definition: structures.h:262
std::vector< unsigned int > rejectsPerAttempt
Definition: structures.h:371
void applyRotation3D(Poly &newPoly, double *normalB)
double * vertices
Definition: structures.h:70
void createBoundingBox(struct Poly &newPoly)
unsigned int * uenumPoints
Definition: readInput.cpp:332
bool domainTruncation(Poly &newPoly, double *domainSize)
Definition: domain.cpp:19
float * ueRadii
Definition: readInput.cpp:317
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)
void generateTheta(float *&thetaArray, float aspectRatio, int nPoints)
double domainSize[3]
Definition: readInput.cpp:18
void initializeEllVertices(struct Poly &newPoly, float radius, float aspectRatio, float *thetaList, int numPoints)
int familyNum
Definition: structures.h:22
float * ueBeta
Definition: readInput.cpp:320
void applyRotation2D(Poly &newPoly, float angle)
unsigned int acceptedPolyCount
Definition: structures.h:300
double * uetranslation
Definition: readInput.cpp:326
double translation[3]
Definition: structures.h:52
void insertUserEll(std::vector< Poly > &acceptedPoly, std::vector< IntPoints > &intpts, struct Stats &pstats, std::vector< Point > &triplePoints)
unsigned long long int rejectedPolyCount
Definition: structures.h:304