DFNgen  2.0
DFN Model Generator
insertUserRects.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 #include "testing.h"
11 
12 
13 /***********************************************************************/
14 /******************** Insert User Rectangles *************************/
22 void insertUserRects(std::vector<Poly>& acceptedPoly, std::vector<IntPoints> &intpts, struct Stats &pstats, std::vector<Point> &triplePoints) {
23 
24  std::cout << "\n" << nUserRect << " User Rectangles Defined\n";
25 
26  for (int i = 0; i < nUserRect; i++) {
27 
28  Poly newPoly;
29  newPoly.familyNum = -2; // Using -2 for all user specified rectangles
30 
31  newPoly.vertices = new double[12]; // 4*{x,y,z}
32 
33  // Set number of nodes. Needed for rotations.
34  newPoly.numberOfNodes = 4;
35 
36  int index = i*3; // Index to start of vertices/nodes
37 
38  // initializeRectVertices() sets newpoly.xradius, newpoly.yradius, newpoly.aperture
39  initializeRectVertices(newPoly, urRadii[i], uraspect[i]);
40 
41  // Convert angle to rad if necessary
42  float angle = urBeta[i];
43  if (urAngleOption == 1 ){
44  angle = urBeta[i] * M_PI/180;
45  }
46  else {
47  angle = urBeta[i];
48  }
49 
50  // Initialize normal to {0,0,1}. need initialized for 3D rotation
51  newPoly.normal[0] = 0; //x
52  newPoly.normal[1] = 0; //y
53  newPoly.normal[2] = 1; //z
54 
55  // Apply 2d rotation matrix, twist around origin
56  // Assumes polygon on x-y plane
57  // Angle must be in rad
58  applyRotation2D(newPoly, angle);
59 
60  // Rotate into 3D from poly.normal to "urnormal", new normal
61  normalize(&urnormal[index]);
62 
63  // Rotate vertices to urnormal[index] (new normal)
64  applyRotation3D(newPoly, &urnormal[index]);
65 
66  // Save newPoly's new normal vector
67  newPoly.normal[0] = urnormal[index];
68  newPoly.normal[1] = urnormal[index+1];
69  newPoly.normal[2] = urnormal[index+2];
70 
71  // Translate newPoly to urtranslation
72  translate(newPoly, &urtranslation[index]);
73 
74  if (domainTruncation(newPoly, domainSize) == 1) {
75  //poly completely outside domain
76  delete[] newPoly.vertices;
77  pstats.rejectionReasons.outside++;
78  pstats.rejectedPolyCount++;
79  std::cout << "\nUser Rectangle " << i+1 << " was rejected for being outside the defined domain.\n";
80  continue; // Go to next poly (go to next iteration of for loop)
81  }
82 
83  createBoundingBox(newPoly);
84 
85  // Line of intersection and FRAM
86  int rejectCode = intersectionChecking(newPoly, acceptedPoly, intpts, pstats, triplePoints);
87  if(rejectCode == 0) {
88  // If intersection is ok
89  if (newPoly.truncated == 1) {
90  pstats.truncated++;
91  }
92 
93  // Incriment counter of accepted polys
94  pstats.acceptedPolyCount++;
95 
96  // Calculate poly's area
97  newPoly.area = getArea(newPoly);
98 
99  // Add new rejectsPerAttempt counter
100  pstats.rejectsPerAttempt.push_back(0);
101 
102  std::cout << "\nUser Defined Rectangular Fracture " << (i+1) << " Accepted\n";
103  acceptedPoly.push_back(newPoly); // Save newPoly to accepted polys list
104  }
105  else {
106  delete[] newPoly.vertices; // Delete manually, created with new[]
107  pstats.rejectedPolyCount++;
108  pstats.rejectsPerAttempt[pstats.acceptedPolyCount]++;
109  std::cout << "\nRejected user defined rectangular fracture " << i+1 << "\n";
110  printRejectReason(rejectCode, newPoly);
111 
112  #ifdef TESTING
113  exit(1);
114  #endif
115 
116  }
117 
118  }//end loop
119 
120  delete[] urRadii;
121  delete[] uraspect;
122  delete[] urBeta;
123  delete[] urtranslation;
124  delete[] urnormal;
125 
126 }
127 
128 
129 
130 
131 
int nUserRect
Definition: readInput.cpp:360
void translate(Poly &newPoly, double *translation)
float * urRadii
Definition: readInput.cpp:363
void normalize(T *vec)
bool truncated
Definition: structures.h:95
int numberOfNodes
Definition: structures.h:14
double * urnormal
Definition: readInput.cpp:380
bool urAngleOption
Definition: readInput.cpp:368
double getArea(struct Poly &poly)
unsigned int truncated
Definition: structures.h:311
void initializeRectVertices(struct Poly &newPoly, float radius, float aspectRatio)
struct RejectionReasons rejectionReasons
Definition: structures.h:339
unsigned long long int outside
Definition: structures.h:262
void insertUserRects(std::vector< Poly > &acceptedPoly, std::vector< IntPoints > &intpts, struct Stats &pstats, std::vector< Point > &triplePoints)
std::vector< unsigned int > rejectsPerAttempt
Definition: structures.h:371
void applyRotation3D(Poly &newPoly, double *normalB)
double * vertices
Definition: structures.h:70
float * uraspect
Definition: readInput.cpp:374
void createBoundingBox(struct Poly &newPoly)
bool domainTruncation(Poly &newPoly, double *domainSize)
Definition: domain.cpp:19
float * urBeta
Definition: readInput.cpp:371
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
double * urtranslation
Definition: readInput.cpp:377
void applyRotation2D(Poly &newPoly, float angle)
unsigned int acceptedPolyCount
Definition: structures.h:300
unsigned long long int rejectedPolyCount
Definition: structures.h:304