31
template <typename TmplSphere, typename TmplBox>
32
std::string getDetailsString(const TmplSphere &sphere, const TmplBox &box)
34
std::stringstream msg;
37
<< box.getMinPt() << ", " << box.getMaxPt() << ")"
38
<< ", sphere = (" << sphere.getCentre() << ", " << sphere.getRadius() << ")";
42
template <typename TmplSphere, typename TmplBox>
43
void checkIntersectionVolume(double vol, const TmplSphere &sphere, const TmplBox &box)
47
std::stringstream msg;
49
<< "nan encountered during volume calculation: "
50
<< getDetailsString(sphere, box);
52
throw std::runtime_error(msg.str());
54
else if ((vol < 0.0) && (fabs(vol) > 1.0e-6))
56
std::stringstream msg;
58
<< "Negative intersection volume " << vol
59
<< ". " << getDetailsString(sphere, box);
60
throw std::runtime_error(msg.str());
62
else if (vol > (box.getVolume() + (box.getVolume()*1.0e-6)))
64
std::stringstream msg;
67
<< " larger than box volume " << box.getVolume()
68
<< ". " << getDetailsString(sphere, box);
69
throw std::runtime_error(msg.str());
71
else if (vol > (sphere.getVolume() + (sphere.getVolume()*1.0e-6)))
73
std::stringstream msg;
76
<< " larger than sphere volume " << sphere.getVolume()
77
<< ". " << getDetailsString(sphere, box);
78
throw std::runtime_error(msg.str());
31
82
class ThreeDIntersectionCalker : public SphereBoxVolCalculator
34
typedef SphereBoxVolCalculator::Sphere Sphere;
35
85
ThreeDIntersectionCalker(const BoundingBox &box)
36
86
: SphereBoxVolCalculator(Box(box.getMinPt(), box.getMaxPt()))
40
std::string getDetailsString(const Sphere &sphere) const
42
std::stringstream msg;
45
<< getBox().getMinPt() << ", " << getBox().getMaxPt() << ")"
46
<< ", sphere = (" << sphere.getCentre() << ", " << sphere.getRadius() << ")";
50
90
double getVolume(const Sphere &sphere)
52
92
const double vol = SphereBoxVolCalculator::getVolume(sphere);
55
std::stringstream msg;
57
<< "nan encountered during volume calculation: " << getDetailsString(sphere);
58
throw std::runtime_error(msg.str());
60
else if (vol > (getBox().getVolume() + (getBox().getVolume()*1.0e-6)))
62
std::stringstream msg;
65
<< " larger than box volume " << getBox().getVolume()
66
<< ". " << getDetailsString(sphere);
67
throw std::runtime_error(msg.str());
69
else if (vol > (sphere.getVolume() + (sphere.getVolume()*1.0e-6)))
71
std::stringstream msg;
74
<< " larger than sphere volume " << sphere.getVolume()
75
<< ". " << getDetailsString(sphere);
76
throw std::runtime_error(msg.str());
93
checkIntersectionVolume(vol, sphere, getBox());
82
98
class TwoDIntersectionCalker : public CircleBoxVolCalculator
85
typedef CircleBoxVolCalculator::Sphere Sphere;
86
101
TwoDIntersectionCalker(const BoundingBox &box)
87
102
: CircleBoxVolCalculator(Box(box.getMinPt(), box.getMaxPt()))
106
double getVolume(const Sphere &sphere)
108
const double vol = CircleBoxVolCalculator::getVolume(sphere);
109
checkIntersectionVolume(vol, sphere, getBox());
92
114
class PointDataType
120
142
typedef vtk::Vec3Type PointType;
121
143
typedef vtk::UnstructuredPiece<PointType, PointDataType> Piece;
122
144
typedef EigenvalueCalculator::ComplexRealImagComparer RealImagComparer;
145
typedef EigenvalueCalculator::ComplexAbsRealImagComparer AbsRealImagComparer;
123
146
typedef EigenvalueCalculator::ComplexNormComparer NormComparer;
125
InteractionToStressConverter::InteractionToStressConverter(double stdDeviation)
126
: m_stressCalculator(),
148
InteractionToStressConverter::InteractionToStressConverter(const BoundingBox &bBox, double gridSpacing)
149
: m_gridSpacing(gridSpacing),
151
m_stressCalculator(),
127
152
m_stressTensorCollection(m_stressCalculator),
128
m_stdDeviation(stdDeviation)
153
m_regTensorGrid(bBox, gridSpacing),
154
m_regDevStressGrid(bBox, gridSpacing),
155
m_irrStressTensorGrid(bBox, gridSpacing)
132
159
double InteractionToStressConverter::getRealDevStress(const Tensor &stressTensor) const
134
161
StressTensor::ComplexVector eigenvals = stressTensor.getEigenvalues();
135
std::sort(eigenvals.begin(), eigenvals.end(), RealImagComparer());
137
162
double devStress = 0.0;
166
std::sort(eigenvals.begin(), eigenvals.end(), RealImagComparer());
140
167
devStress = (eigenvals[2].real() - eigenvals[0].real());
144
if (abs(eigenvals[1].real()) > abs(eigenvals[0].real()))
146
devStress = (eigenvals[2].real() - eigenvals[1].real());
150
devStress = (eigenvals[2].real() - eigenvals[0].real());
172
// In 2d, make sure we only ever subtract \sigma_1 and \sigma_2,
173
// so we sort by absolute value. This ensures that the zero-eigenvalue
174
// (corresponding to the z-dimension) will be sorted into the
175
// eigenvals[0] element.
177
std::sort(eigenvals.begin(), eigenvals.end(), AbsRealImagComparer());
178
devStress = fabs(eigenvals[2].real() - eigenvals[1].real());
154
181
return devStress;
269
296
typedef vtk::Vec3Type StrctPointType;
270
297
typedef vtk::StructuredPiece<StrctPointType, StrctPointDataType> StrctPiece;
273
DoubleGrid InteractionToStressConverter::getDevRegularGrid
275
const BoundingBox &bBox,
280
DoubleGrid irregularGrid = DoubleGrid(bBox, gridSpacing);
299
StressTensorPtrGrid &InteractionToStressConverter::getTensorIrregularGrid()
301
if (m_irrStressTensorGrid.size() <= 0)
303
calcTensorIrregularGrid();
305
return m_irrStressTensorGrid;
308
double InteractionToStressConverter::getMaxRadius()
310
StressTensorPtrGrid::ValueIterator it = getTensorIrregularGrid().getValueIterator();
311
double maxRadius = -1.0;
315
StressTensorPtrGrid::const_reference stressTensor = it.next();
316
if (stressTensor->getRad() > maxRadius)
318
maxRadius = stressTensor->getRad();
324
void InteractionToStressConverter::calcTensorIrregularGrid()
326
m_irrStressTensorGrid = StressTensorPtrGrid(m_bBox, m_gridSpacing);
281
327
StressTensorCollection::StressTensorIterator it = m_stressTensorCollection.getIterator();
283
329
while (it.hasNext()) {
284
330
StressTensorCollection::StressTensorIterator::reference stressTensor = it.next();
285
const double val = getRealDevStress(stressTensor);
286
irregularGrid.insert(stressTensor.getPos(), val);
289
DoubleGrid regularGrid = DoubleGrid(bBox, gridSpacing);
291
GaussianGridder gridder = GaussianGridder(stdDeviation);
292
gridder.transform(irregularGrid, regularGrid);
331
m_irrStressTensorGrid.insert(stressTensor.getPos(), &stressTensor);
335
TensorGrid &InteractionToStressConverter::getTensorRegularGrid()
337
if (m_regTensorGrid.size() <= 0)
339
calcTensorRegularGrid();
341
return m_regTensorGrid;
298
344
template <typename TmplCellIterator, typename TmplIntsectVolCalker>
299
345
Matrix3 getBoxTensor(
320
366
return tensor*(1.0/intersectCalker.getBox().getVolume());
323
TensorGrid InteractionToStressConverter::getTensorRegularGrid
325
const BoundingBox &bBox,
369
void InteractionToStressConverter::calcTensorRegularGrid()
329
StressTensorPtrGrid irregularGrid = StressTensorPtrGrid(bBox, gridSpacing);
330
StressTensorCollection::StressTensorIterator it = m_stressTensorCollection.getIterator();
332
double maxRadius = -1.0;
333
while (it.hasNext()) {
334
StressTensorCollection::StressTensorIterator::reference stressTensor = it.next();
335
irregularGrid.insert(stressTensor.getPos(), &stressTensor);
336
if (stressTensor.getRad() > maxRadius)
338
maxRadius = stressTensor.getRad();
342
TensorGrid regularGrid = TensorGrid(bBox, gridSpacing);
344
maxRadius += gridSpacing;
346
TensorGrid::CellIterator regCellIt = regularGrid.getCellIterator();
371
StressTensorPtrGrid &irregularGrid = getTensorIrregularGrid();
373
m_regTensorGrid = TensorGrid(m_bBox, m_gridSpacing);
375
const double maxRadius = (getMaxRadius() + m_gridSpacing);
377
TensorGrid::CellIterator regCellIt = m_regTensorGrid.getCellIterator();
347
378
while (regCellIt.hasNext())
349
380
TensorGrid::Cell ®Cell = regCellIt.next();
383
DoubleGrid InteractionToStressConverter::getDevRegularGrid
385
const BoundingBox &bBox,
389
const TensorGrid regularTensorGrid = getTensorRegularGrid(bBox, gridSpacing);
390
DoubleGrid regularGrid = DoubleGrid(bBox, gridSpacing);
412
DoubleGrid &InteractionToStressConverter::getDevRegularGrid()
414
if (m_regDevStressGrid.size() <= 0)
416
calcDevRegularGrid();
418
return m_regDevStressGrid;
421
void InteractionToStressConverter::calcDevRegularGrid()
423
const TensorGrid ®ularTensorGrid = getTensorRegularGrid();
424
m_regDevStressGrid = DoubleGrid(m_bBox, m_gridSpacing);
392
426
TensorGrid::CellConstIterator cellIt = regularTensorGrid.getCellIterator();
393
427
while (cellIt.hasNext())
396
430
while (pairIt.hasNext())
398
432
const Tensor &tensor = pairIt.next().getValue();
433
m_regDevStressGrid.insert(
401
435
getRealDevStress(tensor)
409
void InteractionToStressConverter::writeVtkStructuredXml
411
std::ostream &oStream,
412
const BoundingBox &bBox,
441
void InteractionToStressConverter::writeVtkStructuredXml(std::ostream &oStream)
416
TensorGrid regularGrid = getTensorRegularGrid(bBox, gridSpacing);
443
TensorGrid ®ularGrid = getTensorRegularGrid();
417
444
StrctPiece piece(StrctPointType("points"), StrctPointDataType());
418
445
piece.setExtent(regularGrid.getMinVecIndex(), regularGrid.getMaxVecIndex());
419
446
TensorGrid::CellIterator cellIt = regularGrid.getCellIterator();