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
|
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "../testing/core.h"
#include "atom.h"
#include "domain.h"
#include "fmt/format.h"
#include "info.h"
#include "input.h"
#include "lammps.h"
#include "lattice.h"
#include "region.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <mpi.h>
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS {
using ::testing::ExitedWithCode;
using ::testing::MatchesRegex;
using ::testing::StrEq;
class LatticeRegionTest : public LAMMPSTest {
protected:
void SetUp() override
{
testbinary = "LatticeRegionTest";
LAMMPSTest::SetUp();
command("units metal");
}
};
TEST_F(LatticeRegionTest, lattice_none)
{
BEGIN_HIDE_OUTPUT();
command("lattice none 2.0");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::NONE);
ASSERT_EQ(lattice->xlattice, 2.0);
ASSERT_EQ(lattice->ylattice, 2.0);
ASSERT_EQ(lattice->zlattice, 2.0);
ASSERT_EQ(lattice->nbasis, 0);
ASSERT_EQ(lattice->basis, nullptr);
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice"););
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice xxx"););
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice none 1.0 origin"););
TEST_FAILURE(".*ERROR: Expected floating point.*", command("lattice none xxx"););
BEGIN_HIDE_OUTPUT();
command("units lj");
command("lattice none 1.0");
END_HIDE_OUTPUT();
lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->xlattice, 1.0);
ASSERT_EQ(lattice->ylattice, 1.0);
ASSERT_EQ(lattice->zlattice, 1.0);
}
TEST_F(LatticeRegionTest, lattice_sc)
{
BEGIN_CAPTURE_OUTPUT();
command("lattice sc 1.0 spacing 1.5 2.0 3.0");
auto output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 1.50* 2.0* 3.0*.*"));
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->xlattice, 1.5);
ASSERT_EQ(lattice->ylattice, 2.0);
ASSERT_EQ(lattice->zlattice, 3.0);
BEGIN_CAPTURE_OUTPUT();
command("lattice sc 2.0");
output = END_CAPTURE_OUTPUT();
ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 2.0* 2.0* 2.0*.*"));
lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::SC);
ASSERT_EQ(lattice->xlattice, 2.0);
ASSERT_EQ(lattice->ylattice, 2.0);
ASSERT_EQ(lattice->zlattice, 2.0);
ASSERT_EQ(lattice->nbasis, 1);
ASSERT_NE(lattice->basis, nullptr);
ASSERT_EQ(lattice->a1[0], 1.0);
ASSERT_EQ(lattice->a1[1], 0.0);
ASSERT_EQ(lattice->a1[2], 0.0);
ASSERT_EQ(lattice->a2[0], 0.0);
ASSERT_EQ(lattice->a2[1], 1.0);
ASSERT_EQ(lattice->a2[2], 0.0);
ASSERT_EQ(lattice->a3[0], 0.0);
ASSERT_EQ(lattice->a3[1], 0.0);
ASSERT_EQ(lattice->a3[2], 1.0);
ASSERT_EQ(lattice->basis[0][0], 0.0);
ASSERT_EQ(lattice->basis[0][1], 0.0);
ASSERT_EQ(lattice->basis[0][2], 0.0);
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
command("lattice sc 1.0 origin 1.0 1.0 1.0"););
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice sc 1.0 origin 1.0"););
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
command("lattice sc 1.0 origin 0.0 0.0 0.0 xxx"););
TEST_FAILURE(".*ERROR: Expected floating point.*",
command("lattice sc 1.0 origin xxx 1.0 1.0"););
TEST_FAILURE(".*ERROR: Lattice orient vectors are not orthogonal.*",
command("lattice sc 1.0 orient x 2 2 0"););
TEST_FAILURE(".*ERROR: Lattice orient vectors are not right-handed.*",
command("lattice sc 1.0 orient y 0 -1 0"););
TEST_FAILURE(".*ERROR: Lattice spacings are invalid.*",
command("lattice sc 1.0 spacing 0.0 1.0 1.0"););
TEST_FAILURE(".*ERROR: Lattice spacings are invalid.*",
command("lattice sc 1.0 spacing 1.0 -0.1 1.0"););
BEGIN_HIDE_OUTPUT();
command("units lj");
command("lattice sc 2.0");
END_HIDE_OUTPUT();
lattice = lmp->domain->lattice;
ASSERT_DOUBLE_EQ(lattice->xlattice, pow(0.5, 1.0 / 3.0));
ASSERT_DOUBLE_EQ(lattice->ylattice, pow(0.5, 1.0 / 3.0));
ASSERT_DOUBLE_EQ(lattice->zlattice, pow(0.5, 1.0 / 3.0));
BEGIN_HIDE_OUTPUT();
command("dimension 2");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice sc 1.0"););
}
TEST_F(LatticeRegionTest, lattice_bcc)
{
BEGIN_HIDE_OUTPUT();
command("lattice bcc 4.2 orient x 1 1 0 orient y -1 1 0");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::BCC);
ASSERT_DOUBLE_EQ(lattice->xlattice, sqrt(2.0) * 4.2);
ASSERT_DOUBLE_EQ(lattice->ylattice, sqrt(2.0) * 4.2);
ASSERT_DOUBLE_EQ(lattice->zlattice, 4.2);
ASSERT_EQ(lattice->nbasis, 2);
ASSERT_EQ(lattice->basis[0][0], 0.0);
ASSERT_EQ(lattice->basis[0][1], 0.0);
ASSERT_EQ(lattice->basis[0][2], 0.0);
ASSERT_EQ(lattice->basis[1][0], 0.5);
ASSERT_EQ(lattice->basis[1][1], 0.5);
ASSERT_EQ(lattice->basis[1][2], 0.5);
BEGIN_HIDE_OUTPUT();
command("dimension 2");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice bcc 1.0"););
}
TEST_F(LatticeRegionTest, lattice_fcc)
{
BEGIN_HIDE_OUTPUT();
command("lattice fcc 3.5 origin 0.5 0.5 0.5");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::FCC);
ASSERT_DOUBLE_EQ(lattice->xlattice, 3.5);
ASSERT_DOUBLE_EQ(lattice->ylattice, 3.5);
ASSERT_DOUBLE_EQ(lattice->zlattice, 3.5);
ASSERT_EQ(lattice->nbasis, 4);
ASSERT_EQ(lattice->basis[0][0], 0.0);
ASSERT_EQ(lattice->basis[0][1], 0.0);
ASSERT_EQ(lattice->basis[0][2], 0.0);
ASSERT_EQ(lattice->basis[1][0], 0.5);
ASSERT_EQ(lattice->basis[1][1], 0.5);
ASSERT_EQ(lattice->basis[1][2], 0.0);
ASSERT_EQ(lattice->basis[2][0], 0.5);
ASSERT_EQ(lattice->basis[2][1], 0.0);
ASSERT_EQ(lattice->basis[2][2], 0.5);
ASSERT_EQ(lattice->basis[3][0], 0.0);
ASSERT_EQ(lattice->basis[3][1], 0.5);
ASSERT_EQ(lattice->basis[3][2], 0.5);
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
command("lattice fcc 1.0 basis 0.0 0.0 0.0"););
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
command("lattice fcc 1.0 a1 0.0 1.0 0.0"););
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice fcc 1.0 orient w 1 0 0"););
BEGIN_HIDE_OUTPUT();
command("dimension 2");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice fcc 1.0"););
}
TEST_F(LatticeRegionTest, lattice_hcp)
{
BEGIN_HIDE_OUTPUT();
command("lattice hcp 3.0 orient z 0 0 1");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::HCP);
ASSERT_DOUBLE_EQ(lattice->xlattice, 3.0);
ASSERT_DOUBLE_EQ(lattice->ylattice, 3.0 * sqrt(3.0));
ASSERT_DOUBLE_EQ(lattice->zlattice, 2.0 * sqrt(6.0));
ASSERT_EQ(lattice->nbasis, 4);
ASSERT_EQ(lattice->basis[0][0], 0.0);
ASSERT_EQ(lattice->basis[0][1], 0.0);
ASSERT_EQ(lattice->basis[0][2], 0.0);
ASSERT_EQ(lattice->basis[1][0], 0.5);
ASSERT_EQ(lattice->basis[1][1], 0.5);
ASSERT_EQ(lattice->basis[1][2], 0.0);
ASSERT_EQ(lattice->basis[2][0], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[2][1], 5.0 / 6.0);
ASSERT_EQ(lattice->basis[2][2], 0.5);
ASSERT_EQ(lattice->basis[3][0], 0.0);
ASSERT_DOUBLE_EQ(lattice->basis[3][1], 1.0 / 3.0);
ASSERT_EQ(lattice->basis[3][2], 0.5);
ASSERT_EQ(lattice->a1[0], 1.0);
ASSERT_EQ(lattice->a1[1], 0.0);
ASSERT_EQ(lattice->a1[2], 0.0);
ASSERT_EQ(lattice->a2[0], 0.0);
ASSERT_DOUBLE_EQ(lattice->a2[1], sqrt(3.0));
ASSERT_EQ(lattice->a2[2], 0.0);
ASSERT_EQ(lattice->a3[0], 0.0);
ASSERT_EQ(lattice->a3[1], 0.0);
ASSERT_DOUBLE_EQ(lattice->a3[2], sqrt(8.0 / 3.0));
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
command("lattice hcp 1.0 a2 0.0 1.0 0.0"););
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
command("lattice hcp 1.0 a3 0.0 1.0 0.0"););
BEGIN_HIDE_OUTPUT();
command("dimension 2");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice hcp 1.0"););
}
TEST_F(LatticeRegionTest, lattice_diamond)
{
BEGIN_HIDE_OUTPUT();
command("lattice diamond 4.1 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::DIAMOND);
ASSERT_DOUBLE_EQ(lattice->xlattice, 6.6952719636073539);
ASSERT_DOUBLE_EQ(lattice->ylattice, 5.7982756057296889);
ASSERT_DOUBLE_EQ(lattice->zlattice, 7.1014083110323973);
ASSERT_EQ(lattice->nbasis, 8);
ASSERT_EQ(lattice->basis[0][0], 0.0);
ASSERT_EQ(lattice->basis[0][1], 0.0);
ASSERT_EQ(lattice->basis[0][2], 0.0);
ASSERT_EQ(lattice->basis[1][0], 0.0);
ASSERT_EQ(lattice->basis[1][1], 0.5);
ASSERT_EQ(lattice->basis[1][2], 0.5);
ASSERT_EQ(lattice->basis[2][0], 0.5);
ASSERT_EQ(lattice->basis[2][1], 0.0);
ASSERT_EQ(lattice->basis[2][2], 0.5);
ASSERT_EQ(lattice->basis[3][0], 0.5);
ASSERT_EQ(lattice->basis[3][1], 0.5);
ASSERT_EQ(lattice->basis[3][2], 0.0);
ASSERT_EQ(lattice->basis[4][0], 0.25);
ASSERT_EQ(lattice->basis[4][1], 0.25);
ASSERT_EQ(lattice->basis[4][2], 0.25);
ASSERT_EQ(lattice->basis[5][0], 0.25);
ASSERT_EQ(lattice->basis[5][1], 0.75);
ASSERT_EQ(lattice->basis[5][2], 0.75);
ASSERT_EQ(lattice->basis[6][0], 0.75);
ASSERT_EQ(lattice->basis[6][1], 0.25);
ASSERT_EQ(lattice->basis[6][2], 0.75);
ASSERT_EQ(lattice->basis[7][0], 0.75);
ASSERT_EQ(lattice->basis[7][1], 0.75);
ASSERT_EQ(lattice->basis[7][2], 0.25);
ASSERT_EQ(lattice->a1[0], 1.0);
ASSERT_EQ(lattice->a1[1], 0.0);
ASSERT_EQ(lattice->a1[2], 0.0);
ASSERT_EQ(lattice->a2[0], 0.0);
ASSERT_EQ(lattice->a2[1], 1.0);
ASSERT_EQ(lattice->a2[2], 0.0);
ASSERT_EQ(lattice->a3[0], 0.0);
ASSERT_EQ(lattice->a3[1], 0.0);
ASSERT_EQ(lattice->a3[2], 1.0);
BEGIN_HIDE_OUTPUT();
command("dimension 2");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice diamond 1.0"););
}
TEST_F(LatticeRegionTest, lattice_sq)
{
BEGIN_HIDE_OUTPUT();
command("dimension 2");
command("lattice sq 3.0");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::SQ);
ASSERT_DOUBLE_EQ(lattice->xlattice, 3.0);
ASSERT_DOUBLE_EQ(lattice->ylattice, 3.0);
ASSERT_DOUBLE_EQ(lattice->zlattice, 3.0);
ASSERT_EQ(lattice->nbasis, 1);
ASSERT_EQ(lattice->basis[0][0], 0.0);
ASSERT_EQ(lattice->basis[0][1], 0.0);
ASSERT_EQ(lattice->basis[0][2], 0.0);
TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*",
command("lattice sq 1.0 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1"););
BEGIN_HIDE_OUTPUT();
command("dimension 3");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice sq 1.0"););
}
TEST_F(LatticeRegionTest, lattice_sq2)
{
BEGIN_HIDE_OUTPUT();
command("dimension 2");
command("lattice sq2 2.0");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::SQ2);
ASSERT_DOUBLE_EQ(lattice->xlattice, 2.0);
ASSERT_DOUBLE_EQ(lattice->ylattice, 2.0);
ASSERT_DOUBLE_EQ(lattice->zlattice, 2.0);
ASSERT_EQ(lattice->nbasis, 2);
ASSERT_EQ(lattice->basis[0][0], 0.0);
ASSERT_EQ(lattice->basis[0][1], 0.0);
ASSERT_EQ(lattice->basis[0][2], 0.0);
ASSERT_EQ(lattice->basis[1][0], 0.5);
ASSERT_EQ(lattice->basis[1][1], 0.5);
ASSERT_EQ(lattice->basis[1][2], 0.0);
BEGIN_HIDE_OUTPUT();
command("dimension 3");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice sq2 1.0"););
}
TEST_F(LatticeRegionTest, lattice_hex)
{
BEGIN_HIDE_OUTPUT();
command("dimension 2");
command("lattice hex 2.0");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::HEX);
ASSERT_DOUBLE_EQ(lattice->xlattice, 2.0);
ASSERT_DOUBLE_EQ(lattice->ylattice, 3.4641016151377544);
ASSERT_DOUBLE_EQ(lattice->zlattice, 2.0);
ASSERT_EQ(lattice->nbasis, 2);
ASSERT_EQ(lattice->basis[0][0], 0.0);
ASSERT_EQ(lattice->basis[0][1], 0.0);
ASSERT_EQ(lattice->basis[0][2], 0.0);
ASSERT_EQ(lattice->basis[1][0], 0.5);
ASSERT_EQ(lattice->basis[1][1], 0.5);
ASSERT_EQ(lattice->basis[1][2], 0.0);
ASSERT_EQ(lattice->a1[0], 1.0);
ASSERT_EQ(lattice->a1[1], 0.0);
ASSERT_EQ(lattice->a1[2], 0.0);
ASSERT_EQ(lattice->a2[0], 0.0);
ASSERT_DOUBLE_EQ(lattice->a2[1], sqrt(3.0));
ASSERT_EQ(lattice->a2[2], 0.0);
ASSERT_EQ(lattice->a3[0], 0.0);
ASSERT_EQ(lattice->a3[1], 0.0);
ASSERT_EQ(lattice->a3[2], 1.0);
BEGIN_HIDE_OUTPUT();
command("dimension 3");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice hex 1.0"););
}
TEST_F(LatticeRegionTest, lattice_custom)
{
BEGIN_HIDE_OUTPUT();
command("variable a equal 4.34");
command("variable b equal $a*sqrt(3.0)");
command("variable c equal $a*sqrt(8.0/3.0)");
command("variable t equal 1.0/3.0");
command("variable f equal 5.0/6.0");
command("lattice custom 1.0 "
"a1 $a 0.0 0.0 "
"a2 0.0 $b 0.0 "
"a3 0.0 0.0 $c "
"basis 0.0 0.0 0.0 "
"basis 0.5 0.5 0.0 "
"basis $t 0.0 0.5 "
"basis $f 0.5 0.5 "
"basis 0.0 0.0 0.625 "
"basis 0.5 0.5 0.625 "
"basis $t 0.0 0.125 "
"basis $f 0.5 0.125 ");
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::CUSTOM);
ASSERT_DOUBLE_EQ(lattice->xlattice, 4.34);
ASSERT_DOUBLE_EQ(lattice->ylattice, 4.34 * sqrt(3.0));
ASSERT_DOUBLE_EQ(lattice->zlattice, 4.34 * sqrt(8.0 / 3.0));
ASSERT_EQ(lattice->nbasis, 8);
ASSERT_DOUBLE_EQ(lattice->basis[0][0], 0.0);
ASSERT_DOUBLE_EQ(lattice->basis[0][1], 0.0);
ASSERT_DOUBLE_EQ(lattice->basis[0][2], 0.0);
ASSERT_DOUBLE_EQ(lattice->basis[1][0], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[1][1], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[1][2], 0.0);
ASSERT_NEAR(lattice->basis[2][0], 1.0 / 3.0, 1.0e-14);
ASSERT_DOUBLE_EQ(lattice->basis[2][1], 0.0);
ASSERT_DOUBLE_EQ(lattice->basis[2][2], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[3][0], 5.0 / 6.0);
ASSERT_DOUBLE_EQ(lattice->basis[3][1], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[3][2], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[4][0], 0.0);
ASSERT_DOUBLE_EQ(lattice->basis[4][1], 0.0);
ASSERT_DOUBLE_EQ(lattice->basis[4][2], 0.625);
ASSERT_DOUBLE_EQ(lattice->basis[5][0], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[5][1], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[5][2], 0.625);
ASSERT_NEAR(lattice->basis[6][0], 1.0 / 3.0, 1.0e-14);
ASSERT_DOUBLE_EQ(lattice->basis[6][1], 0.0);
ASSERT_DOUBLE_EQ(lattice->basis[6][2], 0.125);
ASSERT_DOUBLE_EQ(lattice->basis[7][0], 5.0 / 6.0);
ASSERT_DOUBLE_EQ(lattice->basis[7][1], 0.5);
ASSERT_DOUBLE_EQ(lattice->basis[7][2], 0.125);
ASSERT_DOUBLE_EQ(lattice->a1[0], 4.34);
ASSERT_DOUBLE_EQ(lattice->a1[1], 0.0);
ASSERT_DOUBLE_EQ(lattice->a1[2], 0.0);
ASSERT_DOUBLE_EQ(lattice->a2[0], 0.0);
ASSERT_DOUBLE_EQ(lattice->a2[1], 4.34 * sqrt(3.0));
ASSERT_DOUBLE_EQ(lattice->a2[2], 0.0);
ASSERT_DOUBLE_EQ(lattice->a3[0], 0.0);
ASSERT_DOUBLE_EQ(lattice->a3[1], 0.0);
ASSERT_DOUBLE_EQ(lattice->a3[2], 4.34 * sqrt(8.0 / 3.0));
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
command("lattice custom 1.0 basis -0.1 0 0"););
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
command("lattice custom 1.0 basis 0.0 1.0 0"););
BEGIN_HIDE_OUTPUT();
command("dimension 2");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: No basis atoms in lattice.*", command("lattice custom 1.0"););
TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*",
command("lattice custom 1.0 origin 0.5 0.5 0.5 basis 0.0 0.0 0.0"););
TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*",
command("lattice custom 1.0 a1 1.0 1.0 1.0 basis 0.0 0.0 0.0"););
TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*",
command("lattice custom 1.0 a2 1.0 1.0 1.0 basis 0.0 0.0 0.0"););
TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*",
command("lattice custom 1.0 a3 1.0 1.0 1.0 basis 0.0 0.0 0.0"););
}
TEST_F(LatticeRegionTest, region_fail)
{
BEGIN_HIDE_OUTPUT();
command("lattice none 2.0");
command("region box block 0 1 0 1 0 1");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Create_atoms command before simulation box is defined.*",
command("create_atoms 1 box"););
BEGIN_HIDE_OUTPUT();
command("create_box 1 box");
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Cannot create atoms with undefined lattice.*",
command("create_atoms 1 box"););
}
TEST_F(LatticeRegionTest, region_block_lattice)
{
BEGIN_HIDE_OUTPUT();
command("lattice sc 1.5");
command("region box block 0 2 0 2 0 2 units lattice");
command("create_box 1 box");
command("create_atoms 1 box");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
auto x = lmp->atom->x;
ASSERT_EQ(lmp->atom->natoms, 8);
ASSERT_DOUBLE_EQ(x[0][0], 0.0);
ASSERT_DOUBLE_EQ(x[0][1], 0.0);
ASSERT_DOUBLE_EQ(x[0][2], 0.0);
ASSERT_DOUBLE_EQ(x[1][0], 1.5);
ASSERT_DOUBLE_EQ(x[1][1], 0.0);
ASSERT_DOUBLE_EQ(x[1][2], 0.0);
ASSERT_DOUBLE_EQ(x[2][0], 0.0);
ASSERT_DOUBLE_EQ(x[2][1], 1.5);
ASSERT_DOUBLE_EQ(x[2][2], 0.0);
ASSERT_DOUBLE_EQ(x[3][0], 1.5);
ASSERT_DOUBLE_EQ(x[3][1], 1.5);
ASSERT_DOUBLE_EQ(x[3][2], 0.0);
}
TEST_F(LatticeRegionTest, region_block_box)
{
BEGIN_HIDE_OUTPUT();
command("lattice sc 1.5 origin 0.75 0.75 0.75");
command("region box block 0 2 0 2 0 2 units box");
command("create_box 1 box");
command("create_atoms 1 box");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
auto x = lmp->atom->x;
ASSERT_EQ(lmp->atom->natoms, 1);
ASSERT_DOUBLE_EQ(x[0][0], 1.125);
ASSERT_DOUBLE_EQ(x[0][1], 1.125);
ASSERT_DOUBLE_EQ(x[0][2], 1.125);
}
TEST_F(LatticeRegionTest, region_cone)
{
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region box cone x 1.0 1.0 0.5 2.1 0.0 2.0");
command("create_box 1 box");
command("create_atoms 1 region box");
command("write_dump all atom init.lammpstrj");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 42);
}
TEST_F(LatticeRegionTest, region_cylinder)
{
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region box cylinder z 1.0 1.0 2.1 0.0 2.0 ");
command("create_box 1 box");
command("create_atoms 1 region box");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 114);
}
TEST_F(LatticeRegionTest, region_prism)
{
BEGIN_HIDE_OUTPUT();
command("lattice bcc 2.5 origin 0.75 0.75 0.75");
command("region box prism 0 2 0 2 0 2 0.5 0.0 0.0");
command("create_box 1 box");
command("create_atoms 1 box");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 1);
ASSERT_EQ(lmp->atom->natoms, 16);
}
TEST_F(LatticeRegionTest, region_sphere)
{
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region box sphere 1.0 1.0 1.0 1.1");
command("create_box 1 box");
command("create_atoms 1 region box");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 14);
}
TEST_F(LatticeRegionTest, region_union)
{
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region part1 sphere 2.0 1.0 1.0 1.1");
command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0");
command("region box union 2 part1 part2");
command("create_box 1 box");
command("create_atoms 1 region box");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 67);
}
TEST_F(LatticeRegionTest, region_intersect)
{
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region part1 sphere 2.0 1.0 1.0 1.8");
command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0");
command("region box intersect 2 part1 part2");
command("create_box 1 box");
command("create_atoms 1 region box");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 21);
}
TEST_F(LatticeRegionTest, region_plane)
{
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region box block 0.0 2.0 0.0 2.0 0.0 2.0");
command("region part1 plane 0.5 1.0 0.0 0.75 0.0 0.0");
command("region part2 plane 1.5 1.0 0.0 0.75 0.0 0.0 side out");
command("region atoms intersect 2 part1 part2");
command("create_box 1 box");
command("create_atoms 1 region atoms");
command("write_dump all atom init.lammpstrj");
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 16);
}
} // namespace LAMMPS_NS
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. "
"Death tests will be skipped\n";
// handle arguments passed via environment variable
if (const char *var = getenv("TEST_ARGS")) {
std::vector<std::string> env = split_words(var);
for (auto arg : env) {
if (arg == "-v") {
verbose = true;
}
}
}
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
int rv = RUN_ALL_TESTS();
MPI_Finalize();
return rv;
}
|