26 check(defaultConfig.
getTxtFilename(7) ==
"config/evl_7.txt",
"Default configuration folder is wrong");
27 const auto directory =
28 std::filesystem::temp_directory_path() /
29 (
"model-ddconfig-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
30 std::filesystem::create_directory(directory);
31 Config config(directory.string()), restored(directory.string());
33 axes << 0, -2, 0, 3, 0, 0, 0, 0, 1;
34 Eigen::Matrix3d strain;
35 strain << .01, .003, -.004, .003, -.002, .005, -.004, .005, .007;
36 const Eigen::Vector3d center(1, -2, 3);
37 config.sphericalInclusions().emplace_back(10, center, 2.0, strain, .5, 1);
38 config.ellipsoidalInclusions().emplace_back(20, center, axes, strain, .625, 2);
39 config.ellipsoidalInclusions().emplace_back(21, -center, 2 * axes, -strain, .75, 3);
40 for(
size_t id = 30;
id < 33; ++id)
42 config.polyhedronInclusions().emplace_back(
id, strain, .875, 4);
44 config.polyhedronInclusionNodes().emplace_back(100, center);
45 config.polyhedronInclusionEdges().emplace_back(30, 0, 100, 100);
46 const std::array<size_t, 11> counts{{0, 0, 0, 0, 1, 2, 3, 1, 1, 0, 0}};
47 const auto serialized =
text(config);
48 std::istringstream header(serialized);
50 for(
auto count : counts)
52 std::getline(header, line);
53 check(std::stoull(line) == count,
"Text count order is wrong");
55 for(
auto id : {10, 20, 21, 30, 31, 32, 100, 30})
57 std::getline(header, line);
58 check(std::stoull(line) ==
static_cast<size_t>(
id),
"Text block order is wrong");
60 std::istringstream input(serialized);
62 check(
text(restored) == serialized,
"Text round trip failed");
63 const Config &constConfig = restored;
67 std::ifstream binary(config.getBinFilename(0), std::ios::binary);
68 for(
auto count : counts)
71 binary.read(
reinterpret_cast<char *
>(&actual),
sizeof(actual));
72 check(binary.good() && actual == count,
"Binary count order is wrong");
75 binary.read(
reinterpret_cast<char *
>(&
sphere),
sizeof(
sphere));
76 check(
sphere.inclusionID == 10,
"Binary spherical block is misplaced");
77 for(
size_t id : {20, 21})
80 binary.read(
reinterpret_cast<char *
>(&ellipsoid),
sizeof(ellipsoid));
84 binary.read(
reinterpret_cast<char *
>(&polyhedron),
sizeof(polyhedron));
88 check(
text(restored) == serialized,
"Binary round trip failed");
91 check(
text(restored) == serialized,
"Binary-to-text conversion failed");
94 config.displacementMatrix().setConstant(2, 6, 1.25);
95 config.cdMatrix().setConstant(1, config.cdMatrix().cols(), 2.5);
96 std::istringstream withMatrices(
text(config));
98 check(
text(restored) ==
text(config),
"Trailing matrices were shifted");
101 check(config.ellipsoidalInclusions().empty(),
"clear() retained ellipsoids");
102 const auto empty =
text(config);
103 std::istringstream emptyInput(empty);
105 check(
text(restored) == empty,
"Empty text read retained old data");
108 check(
text(restored) == empty,
"Empty binary round trip failed");
109 std::filesystem::remove_all(directory);
110 std::cout <<
"PASS DefectiveCrystal configuration defaults, inclusion ordering, text/binary round trips, conversion, matrices, and clear\n";
113 catch(
const std::exception &error)
115 std::cerr << error.what() <<
'\n';