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 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
|
#include "Base/Const/Units.h"
#include "Base/Type/Span.h"
#include "Sample/HardParticle/HardParticles.h"
#include "Sample/Scattering/Rotations.h"
#include "Tests/GTestWrapper/google_test.h"
#include <numbers>
using std::numbers::pi;
using namespace std::complex_literals;
void test_eps_q(const IFormfactor* p, C3 qdir, double eps)
{
C3 q = eps * qdir;
complex_t ff = p->formfactor(q);
// std::cout<<"q="<<q<<" -> "<<std::setprecision(16)<<" ff0="<<V<<", ff ="<<ff<<"\n";
double V = p->volume();
double R = p->radialExtension();
EXPECT_LE(real(ff), V * (1 + 4e-16));
EXPECT_GT(real(ff), V * (1 - std::max(3e-16, 2 * eps * R * eps * R)));
EXPECT_LT(std::abs(imag(ff)), 2 * eps * V * R);
}
void test_small_q(const IFormfactor* p, complex_t x, complex_t y, complex_t z)
{
C3 q(x, y, z);
test_eps_q(p, q, 1e-14);
test_eps_q(p, q, 1e-11);
test_eps_q(p, q, 1e-8);
test_eps_q(p, q, 1e-5);
}
void test_ff(const IFormfactor* p)
{
complex_t ff0 = p->formfactor(C3(0., 0., 0.));
EXPECT_EQ(imag(ff0), 0.);
double V = real(ff0);
EXPECT_NEAR(p->volume(), V, 3e-16 * V);
double R = p->radialExtension();
if (R * R * R < V / 20 || R * R * R > 20 * V) {
std::cerr << "WARNING: very elongated particle, or wrong radius; some tests disabled\n";
std::cerr << std::setprecision(16) << " V =" << V << "\n R^3=" << R * R * R << "\n";
} else {
test_small_q(p, 1, 0, 0);
test_small_q(p, -1, 0, 0);
test_small_q(p, 0, 1, 0);
test_small_q(p, 0, -1, 0);
test_small_q(p, 0, 0, 1);
test_small_q(p, 0, 0, -1);
test_small_q(p, 1, 1, 0);
test_small_q(p, 0, 1, 1);
test_small_q(p, 1, 0, 1);
test_small_q(p, 1, -1, 0);
test_small_q(p, 0, 1, -1);
test_small_q(p, -1, 0, 1);
test_small_q(p, 1, 1, 1);
test_small_q(p, .7, .8, .9);
}
IFormfactor* clone = p->clone();
EXPECT_EQ(clone->volume(), V);
C3 q(.1, .2, complex_t(.3, .004));
EXPECT_EQ(clone->formfactor(q), p->formfactor(q));
delete clone;
}
const C3 q0 = {0.23, 0.11, -0.33};
const C3 q1 = {-0.52, -0.68, -0.69};
const C3 q2 = {0.16, -0.48, -0.46};
const C3 q3 = {-0.27, 0.87, 0.41};
const C3 q4 = {0.31, 0.36, -0.43};
const C3 q5 = {-0.60, 0.79, -0.37};
const C3 q6 = {-0.20, -0.89, 0.27};
const C3 q7 = {-0.18, 0.47, -0.06};
const C3 q8 = {-0.56, -0.94, 0.12};
const C3 q9 = {-0.51, -0.16, -0.42};
void test_ff_print(const IFormfactor* p, const C3 a, const C3 b, const C3 c,
std::complex<double> exp_a, std::complex<double> exp_b,
std::complex<double> exp_c)
{
std::complex<double> ff_a = p->formfactor(a);
std::complex<double> ff_b = p->formfactor(b);
std::complex<double> ff_c = p->formfactor(c);
std::cout << std::fixed;
std::cout << "Formfactor Calculation for " << p->className() << "\n";
std::cout << std::setprecision(2) << "F(" << a << ") = " << std::setprecision(15) << ff_a
<< "\n";
std::cout << std::setprecision(2) << "F(" << b << ") = " << std::setprecision(15) << ff_b
<< "\n";
std::cout << std::setprecision(2) << "F(" << c << ") = " << std::setprecision(15) << ff_c
<< "\n\n";
double abs_a = abs(exp_a);
EXPECT_NEAR(fabs(ff_a.real() - exp_a.real()), 0, abs_a * 1E-13);
EXPECT_NEAR(fabs(ff_a.imag() - exp_a.imag()), 0, abs_a * 1E-13);
double abs_b = abs(exp_b);
EXPECT_NEAR(fabs(ff_b.real() - exp_b.real()), 0, abs_b * 1E-13);
EXPECT_NEAR(fabs(ff_b.imag() - exp_b.imag()), 0, abs_b * 1E-13);
double abs_c = abs(exp_c);
EXPECT_NEAR(fabs(ff_c.real() - exp_c.real()), 0, abs_c * 1E-13);
EXPECT_NEAR(fabs(ff_c.imag() - exp_c.imag()), 0, abs_c * 1E-13);
}
TEST(FormfactorBasic, Name)
{
Box ff(1., 2., 3.);
EXPECT_EQ(ff.className(), "Box");
EXPECT_EQ(ff.className(), "Box");
}
TEST(FormfactorBasic, Pyramid2)
{
EXPECT_THROW(Pyramid2(12, 14, -5, .8), std::runtime_error);
EXPECT_THROW(Pyramid2(0, 1, 1, pi / 4), std::runtime_error);
EXPECT_THROW(Pyramid2(1, 1, 1, 3 * pi / 4), std::runtime_error);
double length = 12.;
double width = 14.;
double height = 5.;
double alpha = 0.8;
double tga = std::tan(alpha);
double volume = height
* (length * width - (length + width) * height / tga
+ 4.0 / 3.0 * height * height / (tga * tga));
Pyramid2 particle(length, width, height, alpha);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q5, q3, q8, {-3.326507178430593, -4.221250124559902},
{-28.875234172319271, -14.799465747269439},
{-8.434962366982653, -1.380171136944693});
}
TEST(FormfactorBasic, Bar)
{
EXPECT_THROW(BarGauss(-100, -20, 4), std::runtime_error);
EXPECT_THROW(BarGauss(100, 20, -4), std::runtime_error);
// TODO EXPECT_THROW(BarGauss(0, 20, 4), std::runtime_error);
// TODO EXPECT_THROW(BarGauss(100, 0, 4), std::runtime_error);
// TODO EXPECT_THROW(BarGauss(100, 20, 0), std::runtime_error);
// test_ff_print(&particle,q0,q4,q1,0,0,0);
double width = 20.;
double height = 4.;
double length = 100.0;
double volume = height * width * length;
BarGauss particle(length, width, height);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
}
TEST(FormfactorBasic, Box)
{
EXPECT_THROW(Box(-6, 5, -7), std::runtime_error);
EXPECT_THROW(Box(6, 0, 7), std::runtime_error);
double length = 6.;
double height = 5.;
double width = 7.;
double volume = length * height * width;
Box particle(length, width, height);
EXPECT_NEAR(sqrt(pow(length / 2, 2) + pow(height / 2, 2) + pow(width / 2, 2)),
particle.radialExtension(), 1e-14);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
EXPECT_NEAR(0., particle.spanZ(new RotationZ(17 * Units::deg)).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(new RotationZ(39 * Units::deg)).hig(), height * 1e-15);
EXPECT_NEAR(-width / 2, particle.spanZ(new RotationX(90 * Units::deg)).low(), 1e-12);
EXPECT_NEAR(-length / 2, particle.spanZ(new RotationY(90 * Units::deg)).low(), 1e-12);
test_ff(&particle);
test_ff_print(&particle, q9, q7, q2, {53.471450007876584, -93.217597445730974},
{119.400684160766147, -18.045648436947012},
{38.756783058601833, -86.601913488017942});
}
TEST(FormfactorBasic, CantellatedCube)
{
EXPECT_THROW(CantellatedCube(0, 0), std::runtime_error);
EXPECT_THROW(CantellatedCube(10, -1), std::runtime_error);
EXPECT_THROW(CantellatedCube(10, 6), std::runtime_error);
double L = 10.;
double t = 2.; // side length of removed trirectangular tetrahedron at each vertex
double volume = L * L * L - 6 * L * t * t + 16 * t * t * t / 3;
CantellatedCube particle(L, t);
EXPECT_DOUBLE_EQ(particle.volume(), volume);
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), L * 1e-15);
EXPECT_NEAR(L, particle.spanZ(&rot).hig(), L * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q0, q5, q6, {-33.391098526973408, -420.703291952477457},
{10.070159899276099, 35.125317795931998},
{-20.124862756519551, -89.660726461058985});
}
TEST(FormfactorBasic, Cone)
{
EXPECT_THROW(Cone(-6, -5, 0.8), std::runtime_error);
// TODO EXPECT_THROW(Cone(6, 5, 0), std::runtime_error);
EXPECT_THROW(Cone(6, 5, 2 * pi / 3), std::runtime_error);
double radius = 6.;
double height = 5.;
double alpha = 0.8;
double tga = std::tan(alpha);
double HdivRtga = height / tga / radius;
double volume = pi / 3. * tga * radius * radius * radius
* (1. - (1. - HdivRtga) * (1. - HdivRtga) * (1. - HdivRtga));
Cone particle(radius, height, alpha);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q0, q8, q4, {154.836630212175464, -89.616777161335065},
{-7.158085433517508, 2.913985277509306},
{71.266836187605691, -75.316792284104494});
}
TEST(FormfactorBasic, Pyramid6)
{
EXPECT_THROW(Pyramid6(-6, -5, 0.8), std::runtime_error);
// TODO EXPECT_THROW(Pyramid6(6, 5, 0), std::runtime_error);
EXPECT_THROW(Pyramid6(6, 5, 2 * pi / 3), std::runtime_error);
double base_edge = 6.;
double height = 5.;
double alpha = 0.8;
double tga = std::tan(alpha);
double HdivRtga = 2. * height / tga / base_edge / std::sqrt(3.);
double volume = 3. / 4. * tga * base_edge * base_edge * base_edge
* (1. - (1. - HdivRtga) * (1. - HdivRtga) * (1. - HdivRtga));
Pyramid6 particle(base_edge, height, alpha);
EXPECT_DOUBLE_EQ(volume, particle.volume());
test_ff(&particle);
test_ff_print(&particle, q9, q3, q5, {56.580851533712433, -49.055032503649102},
{-0.620299369844318, 17.442172408792921},
{-5.221867418516533, -12.118764972593246});
}
TEST(FormfactorBasic, CosineRippleBox)
{
EXPECT_THROW(CosineRippleBox(-20, 4, -100), std::runtime_error);
// TODO EXPECT_THROW(CosineRippleBox(0, 4, 100), std::runtime_error);
// TODO EXPECT_THROW(CosineRippleBox(20, 0, 100), std::runtime_error);
// TODO EXPECT_THROW(CosineRippleBox(20, 4, 0), std::runtime_error);
double width = 20.;
double height = 4.;
double length = 100.0;
double volume = 0.5 * height * width * length;
CosineRippleBox particle(length, width, height);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q2, q7, q3, {2.983050737973751, -90.325884432736274},
{30.902915765072844, -6.396035046006810},
{-6.822717212205538, -1.551498996606969});
}
TEST(FormfactorBasic, Bipyramid4)
{
double length = 10.;
double height = 4;
double height_ratio = .7;
double alpha = 0.8;
double tga = std::tan(alpha);
double H2divLtga = height * 2. / length / tga;
double ratioH2divLtga = height_ratio * height * 2. / length / tga;
double volume = 1. / 6. * tga * length * length * length
* (2. - (1. - H2divLtga) * (1. - H2divLtga) * (1. - H2divLtga)
- (1. - ratioH2divLtga) * (1. - ratioH2divLtga) * (1. - ratioH2divLtga));
Bipyramid4 particle(length, height, height_ratio, alpha);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
const double H = height * (1 + height_ratio);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), H * 1e-15);
EXPECT_NEAR(H, particle.spanZ(&rot).hig(), H * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q0, q3, q7, {71.667831484482932, -230.808201823553276},
{9.207591216136489, -11.771946031248554},
{153.865204621358430, -35.153360066115340});
}
TEST(FormfactorBasic, Cylinder)
{
EXPECT_THROW(Cylinder(-3, -5), std::runtime_error);
// TODO EXPECT_THROW(Cylinder(0, 5), std::runtime_error);
double radius = 3.;
double height = 5.;
double volume = pi * radius * radius * height;
Cylinder particle(radius, height);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
RotationX rectX(90 * Units::deg);
EXPECT_NEAR(-radius, particle.spanZ(&rectX).low(), 1e-13);
EXPECT_NEAR(+radius, particle.spanZ(&rectX).hig(), 1e-13);
RotationY rectY(90 * Units::deg);
EXPECT_NEAR(-radius, particle.spanZ(&rectY).low(), 1e-13);
EXPECT_NEAR(+radius, particle.spanZ(&rectY).hig(), 1e-13);
RotationY invY(180 * Units::deg);
EXPECT_NEAR(-height, particle.spanZ(&invY).low(), 1e-13);
EXPECT_NEAR(0, particle.spanZ(&invY).hig(), 1e-13);
for (double gamma : {1.123, -2.34, 7.5, -9.})
// 7.5deg is worst case for 24-vertex circle
EXPECT_NEAR(-radius,
particle.spanZ(new RotationEuler(0, 90 * Units::deg, gamma * Units::deg)).low(),
3e-2); // TODO decrease epsilon after replacement of vertex-based approximation
test_ff(&particle);
test_ff_print(&particle, q8, q5, q1, {18.469449230629245, 5.713270157358191},
{17.176432808867649, -22.792734170623486},
{-4.645065790555677, -29.883784273353299});
}
TEST(FormfactorBasic, HorizontalCylinder)
{
EXPECT_THROW(HorizontalCylinder(-3, -5), std::runtime_error);
double R = 3.; // radius
double L = 5.; // length
double b = -0; // slice_bottom
double t = 2.3; // slice_top
double full_volume = pi * R * R * L;
double trunc_volume =
L
* (t * sqrt(R * R - t * t) - b * sqrt(R * R - b * b) + R * R * (asin(t / R) - asin(b / R)));
RotationZ rot(.42);
// full
HorizontalCylinder particle_full(R, L);
EXPECT_DOUBLE_EQ(full_volume, particle_full.volume());
EXPECT_NEAR(0., particle_full.spanZ(&rot).low(), 2 * R * 1e-15);
EXPECT_NEAR(2 * R, particle_full.spanZ(&rot).hig(), 2 * R * 1e-15);
// truncated
HorizontalCylinder particle_top(R, L, 0., R);
EXPECT_NEAR(full_volume / 2, particle_top.volume(), 1e-7);
HorizontalCylinder particle_bottom(R, L, -R, 0.);
EXPECT_NEAR(full_volume / 2, particle_bottom.volume(), 1e-7);
HorizontalCylinder particle_trunc(R, L, b, t);
EXPECT_NEAR(trunc_volume, particle_trunc.volume(), 1e-7);
EXPECT_NEAR(0., particle_trunc.spanZ(&rot).low(), 1e-7);
EXPECT_NEAR(t - b, particle_trunc.spanZ(&rot).hig(), 1e-7);
RotationX rot1((pi / 2));
EXPECT_NEAR(-R, particle_trunc.spanZ(&rot1).low(), 1e-7);
EXPECT_NEAR(R, particle_trunc.spanZ(&rot1).hig(), 1e-7);
RotationX rot2((pi / 4));
EXPECT_NEAR(-R / sqrt(2.), particle_trunc.spanZ(&rot2).low(), 1e-7);
EXPECT_NEAR(R, particle_trunc.spanZ(&rot2).hig(), 1e-7);
test_ff(&particle_trunc);
test_ff_print(&particle_trunc, q5, q3, q8, {14.015342836573883, -6.888112822293706},
{14.242986207014122, 8.418849429673980}, {9.515192299073808, 1.605174270540351});
}
TEST(FormfactorBasic, Dodecahedron)
{
EXPECT_THROW(Dodecahedron(-1), std::runtime_error);
EXPECT_THROW(Dodecahedron(0), std::runtime_error);
double edge = 3.;
double volume = (15 + 7 * sqrt(5)) / 4 * pow(edge, 3);
Dodecahedron particle(edge);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), 1e-4);
EXPECT_NEAR(2 * 1.11352 * edge, particle.spanZ(&rot).hig(), 1e-4);
// height=2*inradius from web ressource
test_ff(&particle);
test_ff_print(&particle, q1, q9, q2, {-10.878977464020377, -12.054560796788392},
{17.159983916914797, -101.323984000413375},
{3.473237908867695, -101.684458467045090});
}
TEST(FormfactorBasic, EllipsoidalCylinder)
{
double radiusx = 3.;
double radiusy = 5.;
double height = 4;
double volume = pi * radiusx * radiusy * height;
EllipsoidalCylinder particle(radiusx, radiusy, height);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q3, q5, q7, {-10.885311020650205, -11.665937196046933},
{-10.799240867203938, 9.860673803151998},
{80.174590178312371, -9.667398944888935});
}
TEST(FormfactorBasic, Sphere)
{
EXPECT_THROW(Sphere(-1), std::runtime_error);
// TODO EXPECT_THROW(Sphere(0), std::runtime_error);
double radius = 5.;
double volume = 4. / 3. * pi * radius * radius * radius;
Sphere particle(radius);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), 2 * radius * 1e-15);
EXPECT_NEAR(2 * radius, particle.spanZ(&rot).hig(), 2 * radius * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q7, q2, q9, {244.485507285703591, -75.628229907665755},
{-78.931070547231570, -88.340730913140689},
{-61.244894114710341, -104.719370472590086});
}
TEST(FormfactorBasic, Spheroid)
{
EXPECT_THROW(Spheroid(-3, -5), std::runtime_error);
// TODO EXPECT_THROW(Spheroid(0, 5), std::runtime_error);
// TODO EXPECT_THROW(Spheroid(3, 0), std::runtime_error);
double radius = 3.;
double height = 5.;
double volume = 2. / 3. * pi * radius * radius * height;
Spheroid particle(radius, height / 2);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q1, q4, q6, {-4.602530455511736, -29.610135452483558},
{32.081363863555183, -59.315827480130920},
{29.477269660229449, 23.594341882593568});
}
TEST(FormfactorBasic, HemiEllipsoid)
{
EXPECT_THROW(HemiEllipsoid(-6, -7, 5), std::runtime_error);
double radiusx = 6.;
double radiusy = 7.;
double height = 5.;
double volume = (2 * pi) * radiusx * radiusy * height / 3.;
HemiEllipsoid particle(radiusx, radiusy, height);
EXPECT_DOUBLE_EQ(volume, particle.volume());
test_ff(&particle);
}
TEST(FormfactorBasic, Icosahedron)
{
EXPECT_THROW(Icosahedron(-1), std::runtime_error);
EXPECT_THROW(Icosahedron(0), std::runtime_error);
double edge = 7.;
double volume = 5 * (3 + sqrt(5)) / 12 * pow(edge, 3);
Icosahedron particle(edge);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), 1e-4);
EXPECT_NEAR(2 * 0.755761 * edge, particle.spanZ(&rot).hig(), 1e-4);
// height=2*inradius from web ressource
test_ff(&particle);
test_ff_print(&particle, q1, q8, q9, {59.253013256524476, -33.045312405031297},
{-65.498197697297627, -48.242910954959228},
{-56.385591749217589, -73.996078291078817});
}
TEST(FormfactorBasic, PlatonicOctahedron)
{
EXPECT_THROW(PlatonicOctahedron(-1), std::runtime_error);
EXPECT_THROW(PlatonicOctahedron(0), std::runtime_error);
double edge = 7.;
double volume = sqrt(2.) / 3 * pow(edge, 3);
PlatonicOctahedron particle(edge);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), 1e-4);
EXPECT_NEAR(edge * sqrt(2.), particle.spanZ(&rot).hig(), 1e-4);
test_ff(&particle);
test_ff_print(&particle, q3, q2, q7, {-14.326152086303487, 29.017548785469330},
{-55.305324166329513, -64.855380598892353},
{111.736751011333311, -34.195429173985289});
}
TEST(FormfactorBasic, PlatonicTetrahedron)
{
EXPECT_THROW(PlatonicTetrahedron(-1), std::runtime_error);
EXPECT_THROW(PlatonicTetrahedron(0), std::runtime_error);
double edge = 7.;
double volume = sqrt(2.) / 12 * pow(edge, 3);
PlatonicTetrahedron particle(edge);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), 1e-4);
EXPECT_NEAR(edge * sqrt(2. / 3.), particle.spanZ(&rot).hig(), 1e-4);
test_ff(&particle);
test_ff_print(&particle, q1, q0, q4, {7.338200374299324, -18.083987657244137},
{32.356617373497095, -16.489570069327176},
{25.457763901100478, -17.975973097181353});
}
TEST(FormfactorBasic, Prism3)
{
EXPECT_THROW(Prism3(-4, -6), std::runtime_error);
// TODO EXPECT_THROW(Prism3(0, 6), std::runtime_error);
// TODO EXPECT_THROW(Prism3(4, 0), std::runtime_error);
double height = 4.;
double base_edge = 6.;
double volume = sqrt(3.) / 4. * height * base_edge * base_edge;
Prism3 particle(base_edge, height);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q0, q5, q3, {43.549331118825300, -33.846003647829569},
{14.780314930820900, -21.332048794901649},
{22.325921825843015, 18.106569746121767});
}
TEST(FormfactorBasic, Prism6)
{
EXPECT_THROW(Prism6(-4, -3), std::runtime_error);
// TODO EXPECT_THROW(Prism6(0, 3), std::runtime_error);
// TODO EXPECT_THROW(Prism6(4, 0), std::runtime_error);
double height = 4.;
double base_edge = 3.;
double volume = 3. * sqrt(3.) / 2. * height * base_edge * base_edge;
Prism6 particle(base_edge, height);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q0, q6, q4, {64.541920636979285, -50.091301690725452},
{30.516218708711495, 18.292325480907053},
{43.176189009775861, -50.151555255241675});
}
TEST(FormfactorBasic, Pyramid4)
{
EXPECT_THROW(Pyramid4(-10, -4, .8), std::runtime_error);
EXPECT_THROW(Pyramid4(0, 4, .8), std::runtime_error);
// TODO EXPECT_THROW(Pyramid4(10, 0, .8), std::runtime_error);
EXPECT_THROW(Pyramid4(10, 4, 0), std::runtime_error);
double base_edge = 10.;
double height = 4.;
double alpha = 0.8;
double tga = std::tan(alpha);
double H2divLtga = height * 2. / base_edge / tga;
double volume = 1. / 6. * tga * base_edge * base_edge * base_edge
* (1. - (1. - H2divLtga) * (1. - H2divLtga) * (1. - H2divLtga));
Pyramid4 particle(base_edge, height, alpha);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q6, q8, q0, {-3.441841162284046, 8.991520427160811},
{4.963277061028782, 3.351425235955785},
{123.934890528173085, -57.248659449949685});
}
TEST(FormfactorBasic, SawtoothRippleBox)
{
EXPECT_THROW(SawtoothRippleBox(-20, 4, -100, .3), std::runtime_error);
// TODO EXPECT_THROW(SawtoothRippleBox(0, 4, 100, .3), std::runtime_error);
// TODO EXPECT_THROW(SawtoothRippleBox(20, 0, 100, .3), std::runtime_error);
// TODO EXPECT_THROW(SawtoothRippleBox(20, 4, 0, .3), std::runtime_error);
// TODO EXPECT_THROW(SawtoothRippleBox(20, 4, 0, -.3), std::runtime_error);
double width = 20.;
double height = 4.;
double length = 100.0;
double d = 0.3; // asymmetry
double volume = 0.5 * height * width * length;
SawtoothRippleBox particle(length, width, height, d);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
// test_ff( &particle ); WAITING: restore once radius returns the umkreis radius
test_ff_print(&particle, q9, q2, q6, {34.804843364383807, -22.650035449823580},
{-15.198443862633562, -71.676907701099211},
{-7.303609141120358, -5.907207608040455});
}
TEST(FormfactorBasic, TruncatedCube)
{
EXPECT_THROW(TruncatedCube(0, 0), std::runtime_error);
EXPECT_THROW(TruncatedCube(10, -1), std::runtime_error);
EXPECT_THROW(TruncatedCube(10, 6), std::runtime_error);
double length = 15.;
double t = 6.; // side length of removed trirectangular tetrahedron at each vertex
double volume = length * length * length - 4. / 3. * t * t * t;
TruncatedCube particle(length, t);
EXPECT_DOUBLE_EQ(particle.volume(), volume);
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), length * 1e-15);
EXPECT_NEAR(length, particle.spanZ(&rot).hig(), length * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q0, q1, q7, {-354.587043898980710, -278.961804308277806},
{3.203168895902472, 6.422974142279478},
{-130.107009837376836, 62.848850174170870});
}
TEST(FormfactorBasic, SphericalSegment)
{
EXPECT_THROW(SphericalSegment(-5, -3, 1.7), std::runtime_error);
// TODO EXPECT_THROW(SphericalSegment(5, 3, 0), std::runtime_error);
EXPECT_THROW(SphericalSegment(0, 3, 1.7), std::runtime_error);
EXPECT_THROW(SphericalSegment(5, 8.4, 1.7), std::runtime_error);
double radius = 5.;
double height = 3.;
double HdivR = height / radius;
double volume = pi / 3. * radius * radius * radius
* (3. * HdivR - 1. - (HdivR - 1.) * (HdivR - 1.) * (HdivR - 1.));
SphericalSegment particle(radius, 0, 2 * radius - height);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q8, q5, q3, {-2.581178686741104, 1.096481712394733},
{1.598578167217787, -5.876368926542401}, {7.334079342958564, 9.540086846266590});
}
TEST(FormfactorBasic, SpheroidalSegment)
{
EXPECT_THROW(SpheroidalSegment(-5, -3, 1.7, 0), std::runtime_error);
// TODO EXPECT_THROW(SpheroidalSegment(5, 3, 0, 0), std::runtime_error);
EXPECT_THROW(SpheroidalSegment(0, 3, 1.7, 0), std::runtime_error);
// TODO EXPECT_THROW(SpheroidalSegment(5, 0, 1.7, 0), std::runtime_error);
double radius = 3.;
double height = 5.;
double flattening = 1.5;
double volume =
pi * radius * height * height / flattening * (1. - height / (3. * flattening * radius));
double radius_xy = radius;
double radius_z = radius_xy * flattening;
double rm_bottom = 2 * radius_z - height;
SpheroidalSegment particle(radius_xy, radius_z, 0, rm_bottom);
EXPECT_DOUBLE_EQ(volume, particle.volume());
RotationZ rot(.42);
EXPECT_NEAR(0., particle.spanZ(&rot).low(), height * 1e-15);
EXPECT_NEAR(height, particle.spanZ(&rot).hig(), height * 1e-15);
test_ff(&particle);
test_ff_print(&particle, q0, q9, q5, {69.033474560055168, -50.648848240714358},
{43.816907833926741, -48.128263322981383},
{18.861884199850003, -22.594798796005833});
}
TEST(FormfactorBasic, Pyramid3)
{
EXPECT_THROW(Pyramid3(-16, -4, .8), std::runtime_error);
EXPECT_THROW(Pyramid3(0, 4, .8), std::runtime_error);
// TODO EXPECT_THROW(Pyramid3(16, 0, .8), std::runtime_error);
EXPECT_THROW(Pyramid3(16, 4, 0), std::runtime_error);
double base_edge = 16.;
double height = 4.;
double alpha = 0.8;
double tga = std::tan(alpha);
double sqrt3H2divLtga = std::sqrt(3.) * 2. * height / base_edge / tga;
double volume = tga / 24. * base_edge * base_edge * base_edge
* (1. - (1. - sqrt3H2divLtga) * (1. - sqrt3H2divLtga) * (1. - sqrt3H2divLtga));
Pyramid3 particle(base_edge, height, alpha);
EXPECT_DOUBLE_EQ(volume, particle.volume());
test_ff(&particle);
test_ff_print(&particle, q6, q8, q3, {12.744695481874178, -7.093565343710422},
{-5.320188956629416, -14.254410426450482},
{9.442516587003057, -7.290344882322833});
}
|