1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
|
/////////////////////////////////////////////////////////////
// //
// Copyright (c) 2003-2011 by The University of Queensland //
// Earth Systems Science Computational Centre (ESSCC) //
// http://www.uq.edu.au/esscc //
// //
// Primary Business: Brisbane, Queensland, Australia //
// Licensed under the Open Software License version 3.0 //
// http://www.opensource.org/licenses/osl-3.0.php //
// //
/////////////////////////////////////////////////////////////
#ifndef ESYS_LSMGOUGECONFIG_H
#define ESYS_LSMGOUGECONFIG_H
#include "Foundation/BoundingBox.h"
#include "Geometry/CircularNeighbourTable.h"
#include "Geometry/Plane.h"
#include "Geometry/CubicBoxPacker.h"
#include "Geometry/RandomBoxPacker.h"
#include "Geometry/PackerGenerators.h"
#include "Geometry/DistConnections.h"
#include <boost/shared_ptr.hpp>
#include <vector>
#include <float.h>
namespace esys
{
namespace lsm
{
typedef std::vector<Plane> PlaneVector;
enum Orientation
{
XY,
XZ,
YZ
};
class ParticleRndPackPrms
{
public:
inline ParticleRndPackPrms();
inline ParticleRndPackPrms(double size, double minRadius, double maxRadius);
inline ~ParticleRndPackPrms();
inline double getSize() const;
inline double getMinParticleRadius() const;
inline double getMaxParticleRadius() const;
private:
double m_size;
double m_minParticleRadius;
double m_maxParticleRadius;
};
template <typename TmplParticleGrainGen>
class GrainRndPackPrms : public ParticleRndPackPrms
{
public:
typedef TmplParticleGrainGen ParticleGrainGen;
typedef ParticleRndPackPrms Inherited;
GrainRndPackPrms();
GrainRndPackPrms(
double size,
ParticleGrainGen &particleGrainGen,
int connectionTag=0
);
double getMinGrainRadius();
double getMaxGrainRadius();
ParticleGrainGen &getParticleGrainGen() const;
int getConnectionTag() const;
private:
ParticleGrainGen *m_pParticleGrainGen;
int m_connectionTag;
};
typedef std::vector<bool> BoolVector;
typedef std::vector<BoundingBox> BoundingBoxVector;
class PackingInfo
{
public:
inline PackingInfo(
const BoundingBox &bBox,
const BoolVector &periodicDimensions,
Orientation orientation,
double minRadius,
double maxRadius
);
inline bool is3d() const;
inline void initialiseFitPlaneVector();
inline const BoundingBox &getBBox() const;
inline const PlaneVector &getFitPlaneVector() const;
inline double getMinParticleRadius() const;
inline double getMaxParticleRadius() const;
inline const BoolVector &getPeriodicDimensions() const;
private:
BoundingBox m_bBox;
BoolVector m_periodicDimensions;
Orientation m_orientation;
double m_minRadius;
double m_maxRadius;
PlaneVector m_fitPlaneVector;
};
template <typename TmplParticleGrainGen>
class GougePackingInfo : public PackingInfo
{
public:
typedef TmplParticleGrainGen ParticleGrainGen;
typedef PackingInfo Inherited;
GougePackingInfo(
const BoundingBox &bBox,
const BoolVector &periodicDimensions,
Orientation orientation,
ParticleGrainGen &particleGrainGen
);
double getMinGrainRadius() const;
double getMaxGrainRadius() const;
ParticleGrainGen &getParticleGrainGen() const;
private:
ParticleGrainGen *m_pParticleGrainGen;
};
typedef std::vector<PackingInfo> PackingInfoVector;
template <typename TmplParticleGrainGen>
class GougeConfigPrms
{
public:
typedef TmplParticleGrainGen ParticleGrainGen;
typedef GrainRndPackPrms<ParticleGrainGen> GrainRPackPrms;
typedef typename GrainRPackPrms::Inherited ParticleRndPackPrms;
typedef GougePackingInfo<ParticleGrainGen> GougePackInfo;
typedef std::vector<GougePackInfo> GougePackingInfoVector;
GougeConfigPrms();
/**
*
*/
GougeConfigPrms(
const BoundingBox &bBox,
double padRadius,
Orientation orientation,
const ParticleRndPackPrms &faultRegionPrms,
const GrainRPackPrms &gougeRegionPrms,
const BoolVector &peridicDimensions=BoolVector(3, false),
int maxInsertionFailures=100,
double tolerance = DBL_EPSILON*128,
double connectionTolerance = DBL_EPSILON*128*10,
int blockConnectionTag = 0
);
~GougeConfigPrms();
double getTolerance() const;
double getConnectionTolerance() const;
const BoundingBox &getBBox() const;
int getMaxInsertionFailures() const;
double getRegularBlockRadius() const;
double getFaultMinRadius() const;
double getFaultMaxRadius() const;
double getGougeMinRadius() const;
double getGougeMaxRadius() const;
int getGougeConnectionTag() const;
int getBlockConnectionTag() const;
const BoolVector &getPeriodicDimensions() const;
BoundingBoxVector getRegularBBoxVector() const;
GougePackingInfoVector getGougePackingInfoVector() const;
PackingInfoVector getFaultPackingInfoVector() const;
BoundingBox cutFromCentre(double d1, double d2) const;
Orientation getOrientation() const;
int getOrientationIndex() const;
double getOrientationSize() const;
double getMaxRadius() const;
double getMinRadius() const;
bool is2d() const;
private:
BoundingBox m_bBox;
double m_padRadius;
Orientation m_orientation;
ParticleRndPackPrms m_faultPrms;
GrainRPackPrms m_gougePrms;
BoolVector m_periodicDimensions;
int m_maxInsertionFailures;
double m_tolerance;
double m_connectionTolerance;
int m_blockConnectionTag;
};
/**
*
*/
template <
typename TmplGrainRandomBoxPacker,
typename TmplParticleRandomBoxPacker,
typename TmplConnection
>
class GougeConfig
{
public:
typedef TmplConnection Connection;
typedef TmplGrainRandomBoxPacker GrainRandomPacker;
typedef boost::shared_ptr<GrainRandomPacker> GrainRandomPackerPtr;
typedef typename GrainRandomPacker::ParticleGrainGen ParticleGrainGen;
typedef GougeConfigPrms<ParticleGrainGen> GougeConfPrms;
typedef typename GougeConfPrms::GougePackingInfoVector GougePackingInfoVector;
typedef typename GrainRandomPacker::Particle Particle;
typedef typename GrainRandomPacker::ParticleIterator ParticleIterator;
typedef typename GrainRandomPacker::ParticleConstIterator ParticleConstIterator;
typedef typename GrainRandomPacker::ParticleCollection ParticleCollection;
typedef typename GrainRandomPacker::Grain Grain;
typedef typename GrainRandomPacker::GrainIterator GrainIterator;
typedef typename GrainRandomPacker::GrainConstIterator GrainConstIterator;
typedef typename GrainRandomPacker::GrainCollection GrainCollection;
typedef typename GrainRandomPacker::PackerBase APacker;
typedef typename GrainRandomPacker::BoxPackerBase ABoxPacker;
typedef ConstRadiusGen<Particle> RegRadiusGen;
typedef CubicBoxPacker<RegRadiusGen,ABoxPacker> RegBoxPacker;
typedef typename RegBoxPacker::ParticleGeneratorPtr RegRadiusGenPtr;
typedef TmplParticleRandomBoxPacker RndBoxPacker;
typedef typename RndBoxPacker::ParticleGenerator RndRadiusGen;
typedef typename RndBoxPacker::ParticleGeneratorPtr RndRadiusGenPtr;
typedef typename GrainRandomPacker::NTable NTable;
typedef typename GrainRandomPacker::NTablePtr NTablePtr;
typedef boost::shared_ptr<APacker> GeneratorPtr;
typedef std::vector<GeneratorPtr> GeneratorPtrVector;
typedef std::vector<GrainRandomPackerPtr> GrainRndPackerPtrVector;
typedef typename GrainRandomPacker::ParticlePool ParticlePool;
typedef typename GrainRandomPacker::ParticlePoolPtr ParticlePoolPtr;
typedef typename GrainRandomPacker::GrainPool GrainPool;
typedef typename GrainRandomPacker::GrainPoolPtr GrainPoolPtr;
class ConnectionCmp
{
public:
bool operator()(const Connection &i1, const Connection &i2) const
{
return
(
(i1.getP1Id() < i2.getP1Id())
||
(
(i1.getP1Id() == i2.getP1Id())
&&
(
(i1.getP2Id() < i2.getP2Id())
||
(
(i1.getP2Id() == i2.getP2Id())
&&
(i1.getTag() < i2.getTag())
)
)
)
);
}
bool operator()(const Connection *i1, const Connection *i2) const
{
return (*this)(*i1, *i2);
}
};
typedef std::set<Connection,ConnectionCmp> ConnectionSet;
typedef DistConnections<Particle,Connection> ConnectionFinder;
GougeConfig(const GougeConfPrms &prms);
virtual ~GougeConfig();
virtual void generate();
int getNumParticles() const;
int getNumGrains() const;
int getNumConnections() const;
const GrainRndPackerPtrVector &getGougeGeneratorVector() const;
GrainRndPackerPtrVector &getGougeGeneratorVector();
const GeneratorPtrVector &getFaultGeneratorVector() const;
bool isGougeParticle(const Particle &particle) const;
bool areInDifferentFaultBlocks(
const Particle &p1,
const Particle &p2
) const;
virtual void write(std::ostream &oStream) const;
void writeToFile(const std::string &fileName) const;
void tagGougeParticles(int tag);
void tagRndBlockParticles(int tag);
void tagDrivingPlateParticles(
int minDrivingTag,
int maxDrivingTag,
double distanceFromBBoxEdge
);
virtual void createConnectionSet();
const ConnectionSet &getConnectionSet() const;
GrainCollection getGrainCollection();
ParticleCollection getParticleCollection();
template <typename TmplVisitor>
void visitParticles(TmplVisitor &visitor)
{
for (
typename GeneratorPtrVector::iterator it = m_genPtrVector.begin();
it != m_genPtrVector.end();
it++
)
{
ParticleIterator particleIt = (*it)->getParticleIterator();
while (particleIt.hasNext()) {
particleIt.next().visit(visitor);
}
}
}
template <typename TmplVisitor>
void visitParticles(const TmplVisitor &visitor) const
{
for (
typename GeneratorPtrVector::const_iterator it = m_genPtrVector.begin();
it != m_genPtrVector.end();
it++
)
{
ParticleIterator particleIt = (*it)->getParticleIterator();
while (particleIt.hasNext()) {
particleIt.next().visit(visitor);
}
}
}
template <typename TmplVisitor>
void visitConnections(TmplVisitor &visitor) const
{
const ConnectionSet &connectionSet = getConnectionSet();
for (
typename ConnectionSet::const_iterator it = connectionSet.begin();
it != connectionSet.end();
it++
)
{
it->visit(visitor);
}
}
const GougeConfPrms &getPrms() const
{
return m_prms;
}
class IdCompare
{
public:
bool operator()(const Particle *p1, const Particle *p2) const
{
return (p1->getID() < p2->getID());
}
};
class ConnectionValidator
{
public:
inline ConnectionValidator(const GougeConfig &gougeBlock, double tolerance)
: m_pGougeConfig(&gougeBlock),
m_tolerance(tolerance)
{
}
inline bool isValid(const Particle &p1, const Particle &p2) const
{
return
(
(p1.getID() < p2.getID())
&&
((p1.getPos() - p2.getPos()).norm() < (m_tolerance + (p1.getRad() + p2.getRad())))
&&
((!m_pGougeConfig->isGougeParticle(p1)) && (!m_pGougeConfig->isGougeParticle(p2)))
&&
((!m_pGougeConfig->areInDifferentFaultBlocks(p1, p2)))
);
}
private:
const GougeConfig *m_pGougeConfig;
double m_tolerance;
};
class GeoParticleWriter
{
public:
GeoParticleWriter(std::ostream &oStream, int precision)
: m_pOStream(&oStream),
m_precision(precision)
{
}
void visitParticle(const Particle &particle) const
{
(*m_pOStream)
<< std::setprecision(m_precision)
<< particle.getPos() << " "
<< particle.getRad() << " "
<< particle.getID() << " "
<< particle.getTag() << "\n";
}
private:
std::ostream *m_pOStream;
int m_precision;
};
class GeoConnectionWriter
{
public:
GeoConnectionWriter(std::ostream &oStream)
: m_pOStream(&oStream)
{
}
void visitBasicInteraction(const BasicInteraction &connection)
{
(*m_pOStream)
<< connection.first() << " "
<< connection.second() << " "
<< 0 << "\n";
}
private:
std::ostream *m_pOStream;
int m_precision;
};
protected:
NTablePtr m_nTablePtr;
GougeConfPrms m_prms;
ConnectionSet m_connectionSet;
GrainRndPackerPtrVector m_gougeGenPtrVector;
GeneratorPtrVector m_genPtrVector;
ParticlePoolPtr m_particlePoolPtr;
GrainPoolPtr m_grainPoolPtr;
void createRegularBlockGenerators();
void createFaultBlockGenerators();
virtual void createGougeConfigGenerators();
private:
GeneratorPtrVector m_regularGenPtrVector;
GeneratorPtrVector m_faultGenPtrVector;
};
};
};
#include "Geometry/GougeConfig.hpp"
#endif
|