From 114e7481fe91c89735e77e7c0d25235dda07d104 Mon Sep 17 00:00:00 2001 From: chn Date: Mon, 25 Sep 2023 15:47:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=94=BB=E5=9B=BE?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.lock | 85 +++++++++++++++++++++++++++--------------------------- flake.nix | 2 +- main.cpp | 16 +++++----- plot.cpp | 68 ++++++++++++++++++++++++++++++++++--------- 4 files changed, 107 insertions(+), 64 deletions(-) diff --git a/flake.lock b/flake.lock index e85bb15..c871281 100644 --- a/flake.lock +++ b/flake.lock @@ -32,11 +32,11 @@ "utils": "utils" }, "locked": { - "lastModified": 1694158470, - "narHash": "sha256-yWx9eBDHt6WR3gr65+J85KreHdMypty/P6yM35tIYYM=", + "lastModified": 1695052866, + "narHash": "sha256-agn7F9Oww4oU6nPiw+YiYI9Xb4vOOE73w8PAoBRP4AA=", "owner": "serokell", "repo": "deploy-rs", - "rev": "d0cfc042eba92eb206611c9e8784d41a2c053bab", + "rev": "e3f41832680801d0ee9e2ed33eb63af398b090e9", "type": "github" }, "original": { @@ -456,11 +456,11 @@ "systems": "systems_6" }, "locked": { - "lastModified": 1692799911, - "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -558,11 +558,11 @@ ] }, "locked": { - "lastModified": 1693208669, - "narHash": "sha256-hHFaaUsZ860wvppPeiu7nJn/nXZjJfnqAQEu9SPFE9I=", + "lastModified": 1694465129, + "narHash": "sha256-8BQiuobMrCfCbGM7w6Snx+OBYdtTIm0+cGVaKwQ5BFg=", "owner": "nix-community", "repo": "home-manager", - "rev": "5bac4a1c06cd77cf8fc35a658ccb035a6c50cd2c", + "rev": "9787dffff5d315c9593d3f9fb0f9bf2097e1b57b", "type": "github" }, "original": { @@ -574,11 +574,11 @@ }, "impermanence": { "locked": { - "lastModified": 1690797372, - "narHash": "sha256-GImz19e33SeVcIvBB7NnhbJSbTpFFmNtWLh7Z85Y188=", + "lastModified": 1694622745, + "narHash": "sha256-z397+eDhKx9c2qNafL1xv75lC0Q4nOaFlhaU1TINqb8=", "owner": "nix-community", "repo": "impermanence", - "rev": "e3a7acd113903269a1b5c8b527e84ce7ee859851", + "rev": "e9643d08d0d193a2e074a19d4d90c67a874d932e", "type": "github" }, "original": { @@ -723,11 +723,11 @@ ] }, "locked": { - "lastModified": 1693711723, - "narHash": "sha256-5QmlVzskLciJ0QzYmZ6ULvKA7bP6pgV9wwrLBB0V3j0=", + "lastModified": 1694921880, + "narHash": "sha256-yU36cs5UdzhTwsM9bUWUz43N//ELzQ1ro69C07pU/8E=", "owner": "Mic92", "repo": "nix-index-database", - "rev": "aca56a79afb82208af2b39d8459dd29c10989135", + "rev": "9d2bcc47110b3b6217dfebd6761ba20bc78aedf2", "type": "github" }, "original": { @@ -746,16 +746,17 @@ ] }, "locked": { - "lastModified": 1694222210, - "narHash": "sha256-PzfwrGQMEpJk4lMK2a47bFbJpJFlAG/ihvZsL9U1Lik=", + "lastModified": 1693358717, + "narHash": "sha256-OYGe2Yay1QoodZZmvPYBFGAoTrRfyKLzFs2vON4gRek=", "owner": "nix-community", "repo": "nix-vscode-extensions", - "rev": "5a63908466573a4a1c0466e38f33c42c73ec5136", + "rev": "50c4bce16b93e7ca8565d51fafabc05e9f0515da", "type": "github" }, "original": { "owner": "nix-community", "repo": "nix-vscode-extensions", + "rev": "50c4bce16b93e7ca8565d51fafabc05e9f0515da", "type": "github" } }, @@ -768,11 +769,11 @@ ] }, "locked": { - "lastModified": 1693052712, - "narHash": "sha256-7wrP6s4OEuR7BUasy76n7j+c09rp7wyOq7YVYviXw9s=", + "lastModified": 1694400214, + "narHash": "sha256-QHESodq9FQpjWshfxmdYePnEAPaNPsYEd3iBe/JYjqk=", "owner": "nix-community", "repo": "nixd", - "rev": "f88accc8a8231efdae900ff6a14cb6301a73cff9", + "rev": "69b533e8d643c5dcbda7962d4dff808d72165783", "type": "github" }, "original": { @@ -806,11 +807,11 @@ "touchix": "touchix" }, "locked": { - "lastModified": 1694353998, - "narHash": "sha256-gJvDeofJG+Z3CJvtBxQsaEkjlx7DsY+cKrftqGKjYDc=", + "lastModified": 1695465859, + "narHash": "sha256-nauD552M00PmcpDkKqoYC0ql8QFaFyfKpIYm2qyRKEQ=", "owner": "CHN-beta", "repo": "nixos", - "rev": "228a5388193ceb2df28daabdd06e88a114622018", + "rev": "ad7be5bc2b22a47baf34eebb913b93c11482fb37", "type": "github" }, "original": { @@ -851,11 +852,11 @@ ] }, "locked": { - "lastModified": 1694192131, - "narHash": "sha256-nt5ypVXKh65lQFqKqWgytEzI841yUhpl6E291Briu+g=", + "lastModified": 1694664321, + "narHash": "sha256-NLuFP5JW2LRJTUg0zpeYXS14KjtrgTpFdhH0T7YqEpc=", "owner": "nixpak", "repo": "nixpak", - "rev": "16bd2860238c53bb7a31f745693d7d3c33a1490c", + "rev": "9dd948303ea4c7d531e0775146b1b7fd969994c9", "type": "github" }, "original": { @@ -950,11 +951,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1694233973, - "narHash": "sha256-LPFbAgsJhj5l64bwmeA2POGrdtEm6+WyGwyNVbGRl9A=", + "lastModified": 1695275987, + "narHash": "sha256-DjfwcdkKY7Hom5Nk8fR2fJInRf93uyeAvX+GoA1rqKo=", "owner": "CHN-beta", "repo": "nixpkgs", - "rev": "6b10eef17e5f6fbbb07b38015ce3dc0d5e463282", + "rev": "1523dd436e6f9baf1ab789131b4394b3502de789", "type": "github" }, "original": { @@ -998,11 +999,11 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1694317825, - "narHash": "sha256-ud2qoXA90zSWBUeJqh/5tM055TlSe3HvsEma7Wm0V/Y=", + "lastModified": 1695281058, + "narHash": "sha256-YQs/xiqOW081DCqkeVc+Eonapo0fBCUGwy/5SD1rKTI=", "owner": "CHN-beta", "repo": "nixpkgs", - "rev": "8870ebda280940fcedca9bc35d56ed3bed9d2070", + "rev": "53bdd8bdc15e678f30e450f5be8ef3cee572b11a", "type": "github" }, "original": { @@ -1014,11 +1015,11 @@ }, "nur": { "locked": { - "lastModified": 1694237951, - "narHash": "sha256-6gql7EJIWwn3mUvG/RHf1iGUA3Ptfmalz9WdgX3noSY=", + "lastModified": 1695048039, + "narHash": "sha256-zbJJylG0nrr6bP4+UXK10m2h9Kae5OUeYntU6rli02o=", "owner": "nix-community", "repo": "NUR", - "rev": "19674a713837dcfbef704a16815a4bbc462cd57a", + "rev": "e57ad2a4d59c577780da709180c36304a1d8106c", "type": "github" }, "original": { @@ -1038,11 +1039,11 @@ "nvfetcher": "nvfetcher" }, "locked": { - "lastModified": 1694239804, - "narHash": "sha256-C5ERSMRp8kQEqyKS2yggXSqaKZUgnNyQD+zjy6iqXm0=", + "lastModified": 1695017238, + "narHash": "sha256-JoGZyYAnWZnq8NPu+ptmydA9s/96kb518fY5Q56FcHE=", "owner": "xddxdd", "repo": "nur-packages", - "rev": "ce48d1df62cab988a5e8eefdf97bec8bdc46392f", + "rev": "6e5f2de9db2dede7f1bf350b97adff4901209352", "type": "github" }, "original": { @@ -1157,11 +1158,11 @@ ] }, "locked": { - "lastModified": 1693898833, - "narHash": "sha256-OIrMAGNYNeLs6IvBynxcXub7aSW3GEUvWNsb7zx6zuU=", + "lastModified": 1694495315, + "narHash": "sha256-sZEYXs9T1NVHZSSbMqBEtEm2PGa7dEDcx0ttQkArORc=", "owner": "Mic92", "repo": "sops-nix", - "rev": "faf21ac162173c2deb54e5fdeed002a9bd6e8623", + "rev": "ea208e55f8742fdcc0986b256bdfa8986f5e4415", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 8a0aaf7..5b1070c 100644 --- a/flake.nix +++ b/flake.nix @@ -8,7 +8,7 @@ buildInputs = with pkgs; [ yaml-cpp eigen fmt (localPackages.concurrencpp.override { stdenv = genericPackages.gcc13Stdenv; }) highfive - hdf5.dev tbb + hdf5.dev tbb (localPackages.matplotplusplus.override { stdenv = genericPackages.gcc13Stdenv; }) ]; hardeningDisable = [ "all" ]; }; diff --git a/main.cpp b/main.cpp index d5bb1ba..0c001b2 100644 --- a/main.cpp +++ b/main.cpp @@ -13,7 +13,6 @@ # include # include # include -// # include using namespace std::literals; @@ -49,8 +48,10 @@ struct Input // 超胞中原子的坐标,每行表示一个原子的坐标,单位为埃 Eigen::MatrixX3d AtomPosition; - // 如果打开调试,就不会合并相近的模式,不过滤权重过小的模式,也不会限制浮点的精度 - std::optional Debug; + // 是否调整输出结果, 使得结果中的模式适合人类阅读. 默认为 true. + // 这包括合并相近的模式, 去除权重过小的模式, 限制输出的小数位数. + // 如果想用结果来进一步画图, 则建议关闭. + std::optional Filter; // 关于各个 Q 点的数据 struct QPointDataType_ @@ -249,6 +250,7 @@ int main(int argc, const char** argv) min_score_qpoint = this_qpoint; } } + current_qpoint = min_score_qpoint; } return current_qpoint; }(); @@ -271,7 +273,7 @@ int main(int argc, const char** argv) // 得到 sub_qpoint_by_reciprocal_primative_cell = PrimativeCell * sub_qpoint _.QPoint = input.PrimativeCell * sub_qpoint; _.Source = input.QPointData[i_of_qpoint].QPoint; - if (!input.Debug.value_or(false)) + if (input.Filter.value_or(true)) { // 从小到大枚举所有的模式,并将相近的模式(相差小于 0.1 THz)合并 std::map frequency_to_weight; @@ -320,7 +322,7 @@ int main(int argc, const char** argv) std::ofstream(argc > 3 ? argv[3] : argv[2]) << [&] { std::stringstream print; - auto format = input.Debug.value_or(false) ? 10 : 3; + auto format = input.Filter.value_or(true) ? 3 : 10; print << "QPointData:\n"; for (auto& qpoint: output.QPointData) { @@ -364,8 +366,8 @@ Input::Input(std::string yaml_file, std::optional hdf5_file) for (unsigned i = 0; i < 3; i++) PrimativeCellBasisNumber(i) = node["PrimativeCellBasisNumber"][i].as(); - if (auto value = node["Debug"]) - Debug = value.as(); + if (auto value = node["Filter"]) + Filter = value.as(); auto points = node["points"].as>(); auto atom_position_to_super_cell = Eigen::MatrixX3d(points.size(), 3); diff --git a/plot.cpp b/plot.cpp index edb1a6b..c667ed9 100644 --- a/plot.cpp +++ b/plot.cpp @@ -3,7 +3,9 @@ # include # include # include +# include # include +# include using namespace std::literals; @@ -24,15 +26,44 @@ struct Output std::vector QPointData; }; -std::vector> Qpoints = { - {} + {0, 0, 0}, + {0.025, 0, 0}, + {0.05, 0, 0}, + {0.075, 0, 0}, + {0.1, 0, 0}, + {0.125, 0, 0}, + {0.15, 0, 0}, + {0.175, 0, 0}, + {0.2, 0, 0}, + {0.225, 0, 0}, + {0.25, 0, 0}, + {0.275, 0, 0}, + {0.3, 0, 0}, + {0.325, 0, 0}, + {0.35, 0, 0}, + {0.375, 0, 0}, + {0.4, 0, 0}, + {0.425, 0, 0}, + {0.45, 0, 0}, + {0.475, 0, 0}, + {0.5, 0, 0} }; - -int main() +int main(int argc, char** argv) { - YAML::Node root = YAML::LoadFile("out.yaml"); + YAML::Node root = YAML::LoadFile(argv[1]); Output output; output.QPointData.resize(root["QPointData"].size()); for (int i = 0; i < root["QPointData"].size(); i++) @@ -48,15 +79,24 @@ int main() } } - std::ofstream os("out.dat"); - for (int i = 0; i < output.QPointData.size(); i++) - for (int j = 0; j < output.QPointData[i].ModeData.size(); j++) - { - if (output.QPointData[i].QPoint[1] < 1e-3 && output.QPointData[i].QPoint[2] < 1e-3) + // 外层表示 q 点坐标, 内层表示频率 + // 频率取 -5 到 30 THz, 每 0.1 THz 一个点 + std::vector> data(21); + for (int i = 0; i < 21; i++) + { + data[i].resize(351); + for (auto& qpoint : output.QPointData) + if (std::abs(qpoint.QPoint[0] - Qpoints[i][0]) < 1e-3 && + std::abs(qpoint.QPoint[1] - Qpoints[i][1]) < 1e-3 && + std::abs(qpoint.QPoint[2] - Qpoints[i][2]) < 1e-3) { - os << output.QPointData[i].QPoint[0] << "\t" - << output.QPointData[i].ModeData[j].Frequency << "\t" - << output.QPointData[i].ModeData[j].Weight << "\n"; + for (auto& mode : qpoint.ModeData) + data[i][static_cast((mode.Frequency + 5) * 10)] += mode.Weight; + break; } - } + } + + matplot::image(data, true); + matplot::colorbar().limits({0, 0.5}); + matplot::show(); }