245{
246 if (res <= 0) { return false; }
247
250 if (motherLog == nullptr) { return false; }
251
254
255 if (verbose)
256 {
257 G4cout <<
"Checking overlaps for volume "
260 }
261
262
263
266 {
268 std::ostringstream message;
269 message <<
"Sample point is not on the surface !" <<
G4endl
270 << " The issue is detected for volume "
273 << " generated point " << ptmp
277 return false;
278 }
279
280
281
282
283
284 std::vector<G4ThreeVector> points(res);
285 G4double xmin = kInfinity, ymin = kInfinity, zmin = kInfinity;
286 G4double xmax = -kInfinity, ymax = -kInfinity, zmax = -kInfinity;
288 for (
G4int i = 0; i < res; ++i)
289 {
291 xmin = std::min(xmin, points[i].x());
292 ymin = std::min(ymin, points[i].y());
293 zmin = std::min(zmin, points[i].z());
294 xmax = std::max(xmax, points[i].x());
295 ymax = std::max(ymax, points[i].y());
296 zmax = std::max(zmax, points[i].z());
297 }
298 G4ThreeVector scenter(0.5*(xmax+xmin), 0.5*(ymax+ymin), 0.5*(zmax+zmin));
300
301
302
303 G4int overlapCount = 0;
307 for (
G4int i = 0; i < res; ++i)
308 {
312 if (distin < tol) continue;
313 ++overlapCount;
314 if (distin <= overlapSize) continue;
315 overlapSize = distin;
316 overlapPoint = mp;
317 }
318
319
320
321 if (overlapCount > 0)
322 {
323 ++trials;
324 retval = true;
325 std::ostringstream message;
326 message <<
"Overlap with mother volume !" <<
G4endl
327 << " Overlap is detected for volume "
330 <<
" with its mother volume " << motherLog->
GetName()
332 << " protrusion at mother local point " << overlapPoint
333 <<
" by " <<
G4BestUnit(overlapSize,
"Length")
334 << " (max of " << overlapCount << " cases)";
335 if (trials >= maxErr)
336 {
338 << "NOTE: Reached maximum fixed number -" << maxErr
339 << "- of overlaps reports for this volume !";
340 }
343 if (trials >= maxErr) { return true; }
344 }
345
346
347
350
352 {
354 if (daughter == this) continue;
355 G4bool check_encapsulation =
true;
356
359 if (previous != daughterSolid)
360 {
362 previous = daughterSolid;
363 }
364 overlapCount = 0;
365 overlapSize = -kInfinity;
366 if (!Td.IsRotated()) {
370 if (pmin.x() >= xmax) continue;
371 if (pmin.y() >= ymax) continue;
372 if (pmin.z() >= zmax) continue;
373 if (pmax.x() <= xmin) continue;
374 if (pmax.y() <= ymin) continue;
375 if (pmax.z() <= zmin) continue;
376 for (
G4int i = 0; i < res; ++i)
377 {
379 if (p.
x() <= pmin.x())
continue;
380 if (p.
x() >= pmax.x())
continue;
381 if (p.
y() <= pmin.y())
continue;
382 if (p.
y() >= pmax.y())
continue;
383 if (p.
z() <= pmin.z())
continue;
384 if (p.
z() >= pmax.z())
continue;
387 {
388 check_encapsulation = false;
390 if (distout < tol) continue;
391 ++overlapCount;
392 if (distout <= overlapSize) continue;
393 overlapSize = distout;
394 overlapPoint = md;
395 }
396 }
397 }
398 else
399 {
401 G4ThreeVector dcenter = Td.TransformPoint(0.5*(pmin + pmax));
402 G4double dradius = 0.5*((pmax - pmin).mag());
403 if ((scenter - dcenter).mag2() >= (sradius + dradius)*(sradius + dradius)) continue;
404 if (dcenter.
x() - dradius >= xmax)
continue;
405 if (dcenter.
y() - dradius >= ymax)
continue;
406 if (dcenter.
z() - dradius >= zmax)
continue;
407 if (dcenter.
x() + dradius <= xmin)
continue;
408 if (dcenter.
y() + dradius <= ymin)
continue;
409 if (dcenter.
z() + dradius <= zmin)
continue;
410
420 };
421 G4double dxmin = kInfinity, dymin = kInfinity, dzmin = kInfinity;
422 G4double dxmax = -kInfinity, dymax = -kInfinity, dzmax = -kInfinity;
423 for (
G4int i = 0; i < 8; ++i)
424 {
426 dxmin = std::min(dxmin, p.
x());
427 dymin = std::min(dymin, p.
y());
428 dzmin = std::min(dzmin, p.
z());
429 dxmax = std::max(dxmax, p.
x());
430 dymax = std::max(dymax, p.
y());
431 dzmax = std::max(dzmax, p.
z());
432 }
433 if (dxmin >= xmax) continue;
434 if (dymin >= ymax) continue;
435 if (dzmin >= zmax) continue;
436 if (dxmax <= xmin) continue;
437 if (dymax <= ymin) continue;
438 if (dzmax <= zmin) continue;
439 for (
G4int i = 0; i < res; ++i)
440 {
442 if (p.
x() >= dxmax)
continue;
443 if (p.
x() <= dxmin)
continue;
444 if (p.
y() >= dymax)
continue;
445 if (p.
y() <= dymin)
continue;
446 if (p.
z() >= dzmax)
continue;
447 if (p.
z() <= dzmin)
continue;
450 {
451 check_encapsulation = false;
453 if (distout < tol) continue;
454 ++overlapCount;
455 if (distout <= overlapSize) continue;
456 overlapSize = distout;
457 overlapPoint = md;
458 }
459 }
460 }
461
462
463
464 if (overlapCount > 0)
465 {
466 ++trials;
467 retval = true;
468 std::ostringstream message;
469 message <<
"Overlap with volume already placed !" <<
G4endl
470 << " Overlap is detected for volume "
475 << " overlap at local point " << overlapPoint
476 <<
" by " <<
G4BestUnit(overlapSize,
"Length")
477 << " (max of " << overlapCount << " cases)";
478 if (trials >= maxErr)
479 {
481 << "NOTE: Reached maximum fixed number -" << maxErr
482 << "- of overlaps reports for this volume !";
483 }
486 if (trials >= maxErr) { return true; }
487 }
488 else if (check_encapsulation)
489 {
490
491
492
493
494
499 pInside : pSurface;
500
501
502
503
506
508 {
509 ++trials;
510 retval = true;
511 std::ostringstream message;
512 message <<
"Overlap with volume already placed !" <<
G4endl
513 << " Overlap is detected for volume "
516 << " apparently fully encapsulating volume "
519 << " at the same level!";
520 if (trials >= maxErr)
521 {
523 << "NOTE: Reached maximum fixed number -" << maxErr
524 << "- of overlaps reports for this volume !";
525 }
528 if (trials >= maxErr) { return true; }
529 }
530 }
531 }
532
533 if (verbose && trials == 0) {
G4cout <<
"OK! " <<
G4endl; }
534 return retval;
535}
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
G4VSolid * GetSolid() const
std::size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
const G4String & GetName() const
G4LogicalVolume * GetMotherLogical() const
const G4ThreeVector GetTranslation() const
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
virtual G4ThreeVector GetPointOnSurface() const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual G4GeometryType GetEntityType() const =0