20 check(
argc == 2,
"Expected example filename");
22 check(defaults.type ==
"EllipsoidalInclusion" && defaults.style ==
"Individual" && !defaults.parser &&
23 defaults.center.isZero() && defaults.crystalAxes_SI.isZero() && defaults.crystalEigenDistortion.isZero() &&
24 defaults.velocityReductionFactor == 1.0 && defaults.phaseID == 0 && !defaults.allowOverlap &&
25 !defaults.allowOutside,
26 "Incorrect specification defaults");
27 const Spec parsed(
argv[1]);
28 Eigen::Matrix3d expectedAxes;
29 expectedAxes << 0, -2
e-8, 0, 3
e-8, 0, 0, 0, 0, 1
e-8;
30 Eigen::Matrix3d expectedStrain;
31 expectedStrain << 1
e-3, 2
e-4, 0, 2
e-4, -2
e-3, 0, 0, 0, 3
e-3;
32 check(parsed.center.isApprox(Eigen::Vector3d(200, 0, 0)) && parsed.crystalAxes_SI.isApprox(expectedAxes) &&
33 parsed.crystalEigenDistortion(1) == 2
e-4 && parsed.crystalEigenDistortion(8) == 3
e-3 &&
34 parsed.velocityReductionFactor == 1.0 && parsed.phaseID == 0 && !parsed.allowOverlap &&
36 "Example parsing failed");
37 const Eigen::Matrix3d strain = Eigen::Map<const Eigen::Matrix3d>(parsed.crystalEigenDistortion.data()).transpose();
38 check(strain.isApprox(expectedStrain),
"Eigen-distortion ordering failed");
39 const double b_SI = 2.5e-10;
41 parsed.velocityReductionFactor, parsed.phaseID,
nullptr);
42 check(inclusion.contains(parsed.center) && inclusion.stress(parsed.center).allFinite(),
43 "Specification cannot construct an inclusion");
45 const auto file = std::filesystem::temp_directory_path() /
46 (
"model-ellipsoid-spec-" +
47 std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()) +
".txt");
49 std::ofstream
out(file);
50 out <<
"center=1 2 3;\ncrystalAxes_SI=1 2;\n";
52 bool rejected =
false;
55 const Spec invalid(file.string());
57 catch(
const std::runtime_error &)
61 check(rejected,
"Wrong axes dimensions accepted");
63 std::ofstream
out(file);
64 out <<
"center=1 2 3;\ncrystalAxes_SI=1e-8 0 0 0 2e-8 0 0 0 3e-8;\n"
65 <<
"crystalEigenDistortion=0 0 0 0 0 0 0 0 0;\n"
66 <<
"velocityReductionFactor=.75;\nphaseID=4;\nallowOverlap=1;\nallowOutside=1;\n";
68 const Spec custom(file.string());
69 check(custom.center.isApprox(Eigen::Vector3d(1, 2, 3)) && custom.velocityReductionFactor == .75 &&
70 custom.phaseID == 4 && custom.allowOverlap && custom.allowOutside,
71 "Custom metadata parsing failed");
72 std::filesystem::remove(file);
74 <<
"PASS specification defaults, file parsing, field order, unit conversion, and malformed dimensions\n";
77 catch(
const std::exception &error)
79 std::cerr << error.what() <<
'\n';