| 1 |
///////////////////////////////////////////////////////////// |
| 2 |
// // |
| 3 |
// Copyright (c) 2007-2017 by The University of Queensland // |
| 4 |
// Centre for Geoscience Computing // |
| 5 |
// http://earth.uq.edu.au/centre-geoscience-computing // |
| 6 |
// // |
| 7 |
// Primary Business: Brisbane, Queensland, Australia // |
| 8 |
// Licensed under the Open Software License version 3.0 // |
| 9 |
// http://www.apache.org/licenses/LICENSE-2.0 // |
| 10 |
// // |
| 11 |
///////////////////////////////////////////////////////////// |
| 12 |
|
| 13 |
/*! |
| 14 |
\file main.cc |
| 15 |
$Revision:$ |
| 16 |
$Date:$ |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "geometry/Sphere.h" |
| 20 |
#include "geometry/Line2D.h" |
| 21 |
#include "geometry/LineSegment2D.h" |
| 22 |
#include "util/vector3.h" |
| 23 |
#include "MNTable2D.h" |
| 24 |
#include "MNTable3D.h" |
| 25 |
#include "CircMNTable3D.h" |
| 26 |
#include "FullCircMNTable3D.h" |
| 27 |
#include "CircMNTable2D.h" |
| 28 |
#include "CircMNTableXY2D.h" |
| 29 |
#include "InsertGenerator2D.h" |
| 30 |
#include "HexAggregateInsertGenerator2D.h" |
| 31 |
#include "HGrainGenerator.h" |
| 32 |
#include "InsertGenerator3D.h" |
| 33 |
#include "BoxWithLines2D.h" |
| 34 |
#include "BoxWithLines2DSubVol.h" |
| 35 |
#include "BoxWithPlanes3D.h" |
| 36 |
#include "CylinderVol.h" |
| 37 |
#include "DogBone.h" |
| 38 |
#include "SphereVol.h" |
| 39 |
#include "TriBox.h" |
| 40 |
|
| 41 |
// --- IO includes --- |
| 42 |
#include <iostream> |
| 43 |
|
| 44 |
using std::cout; |
| 45 |
using std::cout; |
| 46 |
using std::endl; |
| 47 |
|
| 48 |
// -- System includes -- |
| 49 |
#include <cstdlib> |
| 50 |
#include <sys/time.h> |
| 51 |
#include <cmath> |
| 52 |
|
| 53 |
using std::atoi; |
| 54 |
using std::atof; |
| 55 |
using std::sqrt; |
| 56 |
|
| 57 |
int main(int argc, char** argv) |
| 58 |
{ |
| 59 |
int ret=0; |
| 60 |
double size=atof(argv[1]); |
| 61 |
int ntry=atoi(argv[2]); |
| 62 |
double rmin=atof(argv[3]); |
| 63 |
int outputstyle=atoi(argv[4]); |
| 64 |
int dim=atoi(argv[5]); |
| 65 |
double vol; |
| 66 |
|
| 67 |
// seed RNG |
| 68 |
struct timeval tv; |
| 69 |
gettimeofday(&tv,NULL); |
| 70 |
int random_seed=tv.tv_usec; |
| 71 |
srand(random_seed); |
| 72 |
|
| 73 |
if(dim==2){ |
| 74 |
double ratio=atof(argv[6]); |
| 75 |
double xsize=ratio*size; |
| 76 |
double ysize=size; |
| 77 |
MNTable2D T(Vector3(0.0,0.0,0.0),Vector3(xsize,ysize,0.0),2.5,1); |
| 78 |
Vector3 min=Vector3(0.0,0.0,0.0); |
| 79 |
Vector3 max=Vector3(xsize,ysize,0.0); |
| 80 |
|
| 81 |
MNTable2D::SetOutputStyle(outputstyle); |
| 82 |
|
| 83 |
InsertGenerator2D *G=new InsertGenerator2D(rmin,1.0,ntry,10000,1e-7); |
| 84 |
BoxWithLines2D Box(Vector3(0.0,0.0,0.0),Vector3(xsize,ysize,0.0)); |
| 85 |
Line2D top_line(Vector3(xsize,0.0,0.0),min); |
| 86 |
Line2D bottom_line(max,Vector3(0.0,ysize,0.0)); |
| 87 |
Line2D left_line(Vector3(xsize,0.0,0.0),max); |
| 88 |
Line2D right_line(min,Vector3(0.0,ysize,0.0)); |
| 89 |
|
| 90 |
Box.addLine(top_line); |
| 91 |
Box.addLine(bottom_line); |
| 92 |
Box.addLine(left_line); |
| 93 |
Box.addLine(right_line); |
| 94 |
|
| 95 |
G->generatePacking(&Box,&T,0,0); |
| 96 |
T.generateBonds(0,1e-5,0); |
| 97 |
|
| 98 |
T.tagParticlesAlongLineWithMask(left_line,0.5,4,4,0); |
| 99 |
T.tagParticlesAlongLineWithMask(right_line,0.5,8,8,0); |
| 100 |
|
| 101 |
vol=xsize*ysize; |
| 102 |
double poros=(vol-T.getSumVolume(0))/vol; |
| 103 |
cout << "Porosity: " << poros << endl; |
| 104 |
|
| 105 |
cout << T << endl; |
| 106 |
|
| 107 |
delete G; |
| 108 |
} else if(dim==3){ // 3D block 1x2x1 |
| 109 |
double rmax=atof(argv[6]); |
| 110 |
Vector3 min=Vector3(0.0,0.0,0.0); |
| 111 |
Vector3 max=Vector3(size,2.0*size,size); |
| 112 |
MNTable3D T(min,max,2.5*rmax,1); |
| 113 |
MNTable3D::SetOutputStyle(outputstyle); |
| 114 |
InsertGenerator3D G(rmin,rmax,ntry,1000,1e-6); |
| 115 |
BoxWithPlanes3D Box(min,max); |
| 116 |
Box.addPlane(Plane(min,Vector3(1.0,0.0,0.0))); |
| 117 |
Box.addPlane(Plane(min,Vector3(0.0,1.0,0.0))); |
| 118 |
Box.addPlane(Plane(min,Vector3(0.0,0.0,1.0))); |
| 119 |
Box.addPlane(Plane(max,Vector3(-1.0,0.0,0.0))); |
| 120 |
Box.addPlane(Plane(max,Vector3(0.0,-1.0,0.0))); |
| 121 |
Box.addPlane(Plane(max,Vector3(0.0,0.0,-1.0))); |
| 122 |
G.generatePacking(&Box,&T,0); |
| 123 |
T.generateBonds(0,1e-5,0); |
| 124 |
|
| 125 |
double vol=2.0*size*size*size; |
| 126 |
double poros=(vol-T.getSumVolume(0))/vol; |
| 127 |
cout << "Porosity: " << poros << endl; |
| 128 |
|
| 129 |
cout << T << endl; |
| 130 |
} else if(dim==4){ // Cylinder, 3:1 |
| 131 |
Vector3 orig=Vector3(0.0,0.0,0.0); |
| 132 |
Vector3 axis=Vector3(0.0,1.0,0.0); |
| 133 |
Vector3 min=Vector3(-1.0*size,0.0,-1.0*size); |
| 134 |
Vector3 max=Vector3(size,3.0*size,size); |
| 135 |
MNTable3D T(min,max,2.2,1); |
| 136 |
MNTable3D::SetOutputStyle(outputstyle); |
| 137 |
InsertGenerator3D G(rmin,1.0,ntry,1000,1e-6); |
| 138 |
|
| 139 |
CylinderVol Cyl(orig,axis,3.0*size,size); |
| 140 |
G.generatePacking(&Cyl,&T,0); |
| 141 |
cout << T << endl; |
| 142 |
} else if(dim==5){ // Torus, 3:1 |
| 143 |
double l2=atof(argv[6]); |
| 144 |
double r2=atof(argv[7]); |
| 145 |
Vector3 orig=Vector3(0.0,0.0,0.0); |
| 146 |
Vector3 axis=Vector3(0.0,1.0,0.0); |
| 147 |
Vector3 min=Vector3(-1.0*size,0.0,-1.0*size); |
| 148 |
Vector3 max=Vector3(size,3.0*size,size); |
| 149 |
MNTable3D T(min,max,2.2,1); |
| 150 |
MNTable3D::SetOutputStyle(outputstyle); |
| 151 |
InsertGenerator3D G(rmin,1.0,ntry,1000,1e-6); |
| 152 |
|
| 153 |
DogBone DB(orig,axis,3.0*size,size,l2,r2); |
| 154 |
G.generatePacking(&DB,&T,0); |
| 155 |
cout << T << endl; |
| 156 |
} else if(dim==6){ // sphere |
| 157 |
Vector3 orig=Vector3(0.0,0.0,0.0); |
| 158 |
Vector3 min=Vector3(-1.0*size,-1.0*size,-1.0*size); |
| 159 |
Vector3 max=Vector3(size,size,size); |
| 160 |
MNTable3D T(min,max,2.2,1); |
| 161 |
MNTable3D::SetOutputStyle(outputstyle); |
| 162 |
InsertGenerator3D G(rmin,1.0,ntry,1000,1e-6); |
| 163 |
SphereVol Sph(orig,size); |
| 164 |
|
| 165 |
G.generatePacking(&Sph,&T,0); |
| 166 |
cout << T << endl; |
| 167 |
} else if(dim==7){ |
| 168 |
Vector3 min=Vector3(0.0,0.0,0.0); |
| 169 |
Vector3 max=Vector3(size,size,size); |
| 170 |
MNTable3D T(min,max,2.5,1); |
| 171 |
MNTable3D::SetOutputStyle(outputstyle); |
| 172 |
InsertGenerator3D G(rmin,1.0,ntry,1000,1e-6); |
| 173 |
TriBox Box(min,max); |
| 174 |
Box.addPlane(Plane(min,Vector3(0.0,1.0,0.0))); // bottom |
| 175 |
Box.addPlane(Plane(min,Vector3(0.0,0.0,1.0))); // front |
| 176 |
Box.addPlane(Plane(max,Vector3(0.0,0.0,-1.0))); // back |
| 177 |
double dx=(max-min).X(); |
| 178 |
double dy=(max-min).Y(); |
| 179 |
Box.addPlane(Plane(min,(Vector3(dy,-0.5*dx,0.0)).unit())); // top left |
| 180 |
Box.addPlane(Plane(max-Vector3(dx/2.0,0.0,0.0),(Vector3(-1.0*dy,-0.5*dx,0.0)).unit())); // top right |
| 181 |
|
| 182 |
G.generatePacking(&Box,&T,0); |
| 183 |
T.generateBonds(0,1e-5,0); |
| 184 |
|
| 185 |
cout << T << endl; |
| 186 |
} else if(dim==8){ |
| 187 |
Vector3 min=Vector3(0.0,0.0,0.0); |
| 188 |
Vector3 max=Vector3(size,size,size); |
| 189 |
MNTable3D T(min,max,2.5,1); |
| 190 |
MNTable3D::SetOutputStyle(outputstyle); |
| 191 |
InsertGenerator3D G(rmin,1.0,ntry,1000,1e-6); |
| 192 |
TriBox Box(min,max,true); |
| 193 |
Box.addPlane(Plane(max,Vector3(0.0,-1.0,0.0))); // top |
| 194 |
Box.addPlane(Plane(min,Vector3(0.0,0.0,1.0))); // front |
| 195 |
Box.addPlane(Plane(max,Vector3(0.0,0.0,-1.0))); // back |
| 196 |
double dx=(max-min).X(); |
| 197 |
double dy=(min-max).Y(); |
| 198 |
Box.addPlane(Plane(min+Vector3(dx/2.0,0.0,0.0),(Vector3(dy,-0.5*dx,0.0)).unit())); // top left |
| 199 |
Box.addPlane(Plane(max,(Vector3(-1.0*dy,-0.5*dx,0.0)).unit())); // top right |
| 200 |
|
| 201 |
G.generatePacking(&Box,&T,0); |
| 202 |
T.generateBonds(0,1e-5,0); |
| 203 |
|
| 204 |
cout << T << endl; |
| 205 |
} else if(dim==9){ |
| 206 |
CircMNTable2D T(Vector3(0.0,0.0,0.0),Vector3(size,size,0.0),2.5,1); |
| 207 |
Vector3 min=Vector3(0.0,0.0,0.0); |
| 208 |
Vector3 max=Vector3(size,size,0.0); |
| 209 |
|
| 210 |
CircMNTable2D::SetOutputStyle(outputstyle); |
| 211 |
|
| 212 |
HexAggregateInsertGenerator2D *G=new HexAggregateInsertGenerator2D(rmin,1.0,ntry,1000,1e-6); |
| 213 |
BoxWithLines2DSubVol Box(Vector3(-0.5,0.0,0.0),Vector3(size+0.5,size,0.0),10.0,10.0); |
| 214 |
Line2D top_line(Vector3(size,0.0,0.0),min); |
| 215 |
Line2D bottom_line(max,Vector3(0.0,size,0.0)); |
| 216 |
|
| 217 |
Box.addLine(top_line); |
| 218 |
Box.addLine(bottom_line); |
| 219 |
|
| 220 |
G->generatePacking(&Box,&T,0,0); |
| 221 |
T.tagParticlesAlongLineWithMask(top_line,0.5,4,4,0); |
| 222 |
T.tagParticlesAlongLineWithMask(bottom_line,0.5,8,8,0); |
| 223 |
|
| 224 |
vol=size*size; |
| 225 |
double poros=(vol-T.getSumVolume(0))/vol; |
| 226 |
cout << "Porosity: " << poros << endl; |
| 227 |
|
| 228 |
cout << T << endl; |
| 229 |
|
| 230 |
delete G; |
| 231 |
} else if(dim==20){ // hex grain regular |
| 232 |
double xsize=size; |
| 233 |
double ysize=size; |
| 234 |
|
| 235 |
MNTable2D T(Vector3(0.0,0.0,0.0),Vector3(xsize,ysize,0.0),2.5,1); |
| 236 |
Vector3 min=Vector3(0.0,0.0,0.0); |
| 237 |
Vector3 max=Vector3(xsize,ysize,0.0); |
| 238 |
|
| 239 |
CircMNTable2D::SetOutputStyle(outputstyle); |
| 240 |
|
| 241 |
HGrainGenerator2D *G=new HGrainGenerator2D(rmin); |
| 242 |
BoxWithLines2D Box(Vector3(0.0,0.0,0.0),Vector3(xsize,ysize,0.0)); |
| 243 |
Line2D top_line(Vector3(xsize,0.0,0.0),min); |
| 244 |
Line2D bottom_line(max,Vector3(0.0,ysize,0.0)); |
| 245 |
Line2D left_line(Vector3(xsize,0.0,0.0),max); |
| 246 |
Line2D right_line(min,Vector3(0.0,ysize,0.0)); |
| 247 |
|
| 248 |
Box.addLine(top_line); |
| 249 |
Box.addLine(bottom_line); |
| 250 |
Box.addLine(left_line); |
| 251 |
Box.addLine(right_line); |
| 252 |
|
| 253 |
G->generatePacking(&Box,&T,0,0); |
| 254 |
T.generateBonds(0,1e-5,0); |
| 255 |
|
| 256 |
T.tagParticlesAlongLineWithMask(top_line,5.0,4,4,0); |
| 257 |
T.tagParticlesAlongLineWithMask(bottom_line,5.0,8,8,0); |
| 258 |
T.tagParticlesAlongLineWithMask(left_line,8.0,16,16,0); |
| 259 |
T.tagParticlesAlongLineWithMask(right_line,8.0,32,32,0); |
| 260 |
|
| 261 |
double ldx=0.5*ysize; |
| 262 |
double ldy=(sqrt(3.0)/2.0)*ldx; |
| 263 |
double lx0=atof(argv[6]); |
| 264 |
double ly0=atof(argv[7]); |
| 265 |
|
| 266 |
LineSegment2D breakLine(Vector3(lx0,ly0,0.0),Vector3(lx0-ldx,ly0+ldy,0.0)); |
| 267 |
|
| 268 |
T.breakBondsAlongLineSegment(breakLine,1.0,0,0); |
| 269 |
|
| 270 |
vol=xsize*ysize; |
| 271 |
double poros=(vol-T.getSumVolume(0))/vol; |
| 272 |
cout << "Porosity: " << poros << endl; |
| 273 |
|
| 274 |
cout << T << endl; |
| 275 |
|
| 276 |
delete G; |
| 277 |
} |
| 278 |
|
| 279 |
return ret; |
| 280 |
} |