From 78cc7ed3d37a22da14a1a147ee9fef87599ba3d4 Mon Sep 17 00:00:00 2001 From: chn Date: Mon, 11 Sep 2023 19:54:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.lock | 1333 +++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 9 +- main.cpp | 272 +++++------ 3 files changed, 1470 insertions(+), 144 deletions(-) diff --git a/flake.lock b/flake.lock index 1f48883..e85bb15 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,944 @@ { "nodes": { + "aagl": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693886279, + "narHash": "sha256-oVCA5yz6zcsFzGCCwRpVDuDml7Z0sWQqW1fEWWcC0xM=", + "owner": "ezKEa", + "repo": "aagl-gtk-on-nix", + "rev": "8fc45fabbedef44a481c3bcabd9512732c0ade91", + "type": "github" + }, + "original": { + "owner": "ezKEa", + "repo": "aagl-gtk-on-nix", + "type": "github" + } + }, + "deploy-rs": { + "inputs": { + "flake-compat": "flake-compat_2", + "nixpkgs": [ + "nixos", + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1694158470, + "narHash": "sha256-yWx9eBDHt6WR3gr65+J85KreHdMypty/P6yM35tIYYM=", + "owner": "serokell", + "repo": "deploy-rs", + "rev": "d0cfc042eba92eb206611c9e8784d41a2c053bab", + "type": "github" + }, + "original": { + "owner": "serokell", + "repo": "deploy-rs", + "type": "github" + } + }, + "dguibert-nur-packages": { + "inputs": { + "dwl-src": "dwl-src", + "dwm-src": "dwm-src", + "emacs-overlay": "emacs-overlay", + "emacs-src": "emacs-src", + "flake-parts": "flake-parts", + "flake-utils": "flake-utils_2", + "mako-src": "mako-src", + "nix": "nix", + "nixpkgs": [ + "nixos", + "nixpkgs" + ], + "st-src": "st-src" + }, + "locked": { + "lastModified": 1693549169, + "narHash": "sha256-1mgWe0BH63pEOI2MaclIxGyQbyh0e/k+PbjCasuNfS4=", + "owner": "CHN-beta", + "repo": "dguibert-nur-packages", + "rev": "3d4419864595ee05e82a391206d9f8499e321265", + "type": "github" + }, + "original": { + "owner": "CHN-beta", + "repo": "dguibert-nur-packages", + "type": "github" + } + }, + "dwl-src": { + "flake": false, + "locked": { + "lastModified": 1680697480, + "narHash": "sha256-vaxCJB4ykNVwZNKau42Xu+D39A5mXgjfyKgOE2Frsa4=", + "owner": "dguibert", + "repo": "dwl", + "rev": "844b04d23db2de161a058bec477ef7ff772ce298", + "type": "github" + }, + "original": { + "owner": "dguibert", + "ref": "pu", + "repo": "dwl", + "type": "github" + } + }, + "dwm-src": { + "flake": false, + "locked": { + "lastModified": 1649608053, + "narHash": "sha256-+v2wof46XG/n85zVY82GIuKgzr0K9s1apPfaDSyuqos=", + "owner": "dguibert", + "repo": "dwm", + "rev": "306e1790145849abd30ef6c81051755a6813ff30", + "type": "github" + }, + "original": { + "owner": "dguibert", + "ref": "pu", + "repo": "dwm", + "type": "github" + } + }, + "emacs-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixos", + "dguibert-nur-packages", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1691144360, + "narHash": "sha256-DPaalQfXWXbyiuSqbk0dWKusniMWQSzAu0e36xU6rbA=", + "owner": "nix-community", + "repo": "emacs-overlay", + "rev": "4ba15d6f4310459e6da08dcd4d3df7f4d102bdf0", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "emacs-overlay", + "type": "github" + } + }, + "emacs-src": { + "flake": false, + "locked": { + "lastModified": 1685570069, + "narHash": "sha256-lp6HgksMTfUboBm/BBLHFwiZ1aQnzHEAOhRL8I9RHOg=", + "owner": "emacs-mirror", + "repo": "emacs", + "rev": "17c7915ab947ebeec6ea5ad3eb4cad1f24d5d4fc", + "type": "github" + }, + "original": { + "owner": "emacs-mirror", + "ref": "emacs-29", + "repo": "emacs", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_3": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_4": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_5": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_6": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1682984683, + "narHash": "sha256-fSMthG+tp60AHhNmaHc4StT3ltfHkQsJtN8GhfLWmtI=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "86684881e184f41aa322e653880e497b66429f3e", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib_2" + }, + "locked": { + "lastModified": 1685662779, + "narHash": "sha256-cKDDciXGpMEjP1n6HlzKinN0H+oLmNpgeCTzYnsA2po=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "71fb97f0d875fd4de4994dfb849f2c75e17eb6c3", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_3": { + "inputs": { + "nixpkgs-lib": [ + "nixos", + "nixpak", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693611461, + "narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_4": { + "inputs": { + "nixpkgs-lib": [ + "nixos", + "nixpak", + "hercules-ci-effects", + "hercules-ci-agent", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688466019, + "narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils-plus": { + "inputs": { + "flake-utils": [ + "nixos", + "nur-xddxdd", + "flake-utils" + ] + }, + "locked": { + "lastModified": 1657226504, + "narHash": "sha256-GIYNjuq4mJlFgqKsZ+YrgzWm0IpA4axA3MCrdKYj7gs=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a", + "type": "github" + }, + "original": { + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "inputs": { + "systems": "systems_4" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_5": { + "inputs": { + "systems": "systems_5" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_6": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_7": { + "inputs": { + "systems": "systems_6" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_8": { + "inputs": { + "systems": "systems_7" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "haskell-flake": { + "locked": { + "lastModified": 1684780604, + "narHash": "sha256-2uMZsewmRn7rRtAnnQNw1lj0uZBMh4m6Cs/7dV5YF08=", + "owner": "srid", + "repo": "haskell-flake", + "rev": "74210fa80a49f1b6f67223debdbf1494596ff9f2", + "type": "github" + }, + "original": { + "owner": "srid", + "ref": "0.3.0", + "repo": "haskell-flake", + "type": "github" + } + }, + "hercules-ci-agent": { + "inputs": { + "flake-parts": "flake-parts_4", + "haskell-flake": "haskell-flake", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1688568579, + "narHash": "sha256-ON0M56wtY/TIIGPkXDlJboAmuYwc73Hi8X9iJGtxOhM=", + "owner": "hercules-ci", + "repo": "hercules-ci-agent", + "rev": "367dd8cd649b57009a6502e878005a1e54ad78c5", + "type": "github" + }, + "original": { + "id": "hercules-ci-agent", + "type": "indirect" + } + }, + "hercules-ci-effects": { + "inputs": { + "flake-parts": [ + "nixos", + "nixpak", + "flake-parts" + ], + "hercules-ci-agent": "hercules-ci-agent", + "nixpkgs": [ + "nixos", + "nixpak", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1689397210, + "narHash": "sha256-fVxZnqxMbsDkB4GzGAs/B41K0wt/e+B/fLxmTFF/S20=", + "owner": "hercules-ci", + "repo": "hercules-ci-effects", + "rev": "0a63bfa3f00a3775ea3a6722b247880f1ffe91ce", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "hercules-ci-effects", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693208669, + "narHash": "sha256-hHFaaUsZ860wvppPeiu7nJn/nXZjJfnqAQEu9SPFE9I=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "5bac4a1c06cd77cf8fc35a658ccb035a6c50cd2c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-23.05", + "repo": "home-manager", + "type": "github" + } + }, + "impermanence": { + "locked": { + "lastModified": 1690797372, + "narHash": "sha256-GImz19e33SeVcIvBB7NnhbJSbTpFFmNtWLh7Z85Y188=", + "owner": "nix-community", + "repo": "impermanence", + "rev": "e3a7acd113903269a1b5c8b527e84ce7ee859851", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "impermanence", + "type": "github" + } + }, + "lmix": { + "inputs": { + "nixpkgs": [ + "nixos", + "nixpkgs" + ], + "nurl": "nurl", + "utils": "utils_2" + }, + "locked": { + "lastModified": 1693749173, + "narHash": "sha256-+ACUbkspARXLzgxxgiAbINOPYa2+oiR4JhNimpVP9wU=", + "owner": "CHN-beta", + "repo": "lmix", + "rev": "73b61e4318432e50c4b742edbeae82f6ad2fe69a", + "type": "github" + }, + "original": { + "owner": "CHN-beta", + "repo": "lmix", + "type": "github" + } + }, + "lowdown-src": { + "flake": false, + "locked": { + "lastModified": 1653759997, + "narHash": "sha256-mvWCdd79cNh8VK9wfHsMMF2XFYaHd9DhdlwSa33uW+M=", + "owner": "kristapsdz", + "repo": "lowdown", + "rev": "edca6ce6d5336efb147321a43c47a698de41bb7c", + "type": "github" + }, + "original": { + "owner": "kristapsdz", + "repo": "lowdown", + "type": "github" + } + }, + "mako-src": { + "flake": false, + "locked": { + "lastModified": 1684537028, + "narHash": "sha256-y0gp33fCX/qYdexGceDu3ZEUM/hCU2if9BFCSHqZ11g=", + "owner": "emersion", + "repo": "mako", + "rev": "0e111547b17dd8d2733c48fc4082cdb419d7688d", + "type": "github" + }, + "original": { + "owner": "emersion", + "ref": "master", + "repo": "mako", + "type": "github" + } + }, + "napalm": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693989153, + "narHash": "sha256-gx39Y3opGB25+44OjM+h1bdJyzgLD963va8ULGYlbhM=", + "owner": "nix-community", + "repo": "napalm", + "rev": "a8215ccf1c80070f51a92771f3bc637dd9b9f7ee", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "napalm", + "type": "github" + } + }, + "nix": { + "inputs": { + "flake-compat": "flake-compat_3", + "lowdown-src": "lowdown-src", + "nixpkgs": [ + "nixos", + "dguibert-nur-packages", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1692264617, + "narHash": "sha256-ZOf28XhU8Fvir3biY58zmIaShiUP/s4GwB4ruuQkMlc=", + "owner": "dguibert", + "repo": "nix", + "rev": "fa563827bdc7f1c939173b1036fb121e43f947c7", + "type": "github" + }, + "original": { + "owner": "dguibert", + "ref": "pu", + "repo": "nix", + "type": "github" + } + }, + "nix-alien": { + "inputs": { + "flake-compat": "flake-compat_4", + "flake-utils": "flake-utils_4", + "nix-index-database": [ + "nixos", + "nix-index-database" + ], + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1693880502, + "narHash": "sha256-krCRVLNdlCI7l7F1Bb2ovkgac8hoz015LyYvm/+aYZw=", + "owner": "thiagokokada", + "repo": "nix-alien", + "rev": "0fbd284930bcf1a5d1e3d07f2973e6f1738505cc", + "type": "github" + }, + "original": { + "owner": "thiagokokada", + "repo": "nix-alien", + "type": "github" + } + }, + "nix-index-database": { + "inputs": { + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693711723, + "narHash": "sha256-5QmlVzskLciJ0QzYmZ6ULvKA7bP6pgV9wwrLBB0V3j0=", + "owner": "Mic92", + "repo": "nix-index-database", + "rev": "aca56a79afb82208af2b39d8459dd29c10989135", + "type": "github" + }, + "original": { + "owner": "Mic92", + "repo": "nix-index-database", + "type": "github" + } + }, + "nix-vscode-extensions": { + "inputs": { + "flake-compat": "flake-compat_5", + "flake-utils": "flake-utils_5", + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1694222210, + "narHash": "sha256-PzfwrGQMEpJk4lMK2a47bFbJpJFlAG/ihvZsL9U1Lik=", + "owner": "nix-community", + "repo": "nix-vscode-extensions", + "rev": "5a63908466573a4a1c0466e38f33c42c73ec5136", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-vscode-extensions", + "type": "github" + } + }, + "nixd": { + "inputs": { + "flake-parts": "flake-parts_2", + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693052712, + "narHash": "sha256-7wrP6s4OEuR7BUasy76n7j+c09rp7wyOq7YVYviXw9s=", + "owner": "nix-community", + "repo": "nixd", + "rev": "f88accc8a8231efdae900ff6a14cb6301a73cff9", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixd", + "type": "github" + } + }, + "nixos": { + "inputs": { + "aagl": "aagl", + "deploy-rs": "deploy-rs", + "dguibert-nur-packages": "dguibert-nur-packages", + "home-manager": "home-manager", + "impermanence": "impermanence", + "lmix": "lmix", + "napalm": "napalm", + "nix-alien": "nix-alien", + "nix-index-database": "nix-index-database", + "nix-vscode-extensions": "nix-vscode-extensions", + "nixd": "nixd", + "nixos-cn": "nixos-cn", + "nixpak": "nixpak", + "nixpkgs": "nixpkgs_4", + "nixpkgs-unstable": "nixpkgs-unstable", + "nur": "nur", + "nur-xddxdd": "nur-xddxdd", + "pnpm2nix-nzbr": "pnpm2nix-nzbr", + "qchem": "qchem", + "sops-nix": "sops-nix", + "touchix": "touchix" + }, + "locked": { + "lastModified": 1694353998, + "narHash": "sha256-gJvDeofJG+Z3CJvtBxQsaEkjlx7DsY+cKrftqGKjYDc=", + "owner": "CHN-beta", + "repo": "nixos", + "rev": "228a5388193ceb2df28daabdd06e88a114622018", + "type": "github" + }, + "original": { + "owner": "CHN-beta", + "repo": "nixos", + "type": "github" + } + }, + "nixos-cn": { + "inputs": { + "flake-utils": "flake-utils_6", + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1682818384, + "narHash": "sha256-l8jh9BQj6nfjPDYGyrZkZwX1GaOqBX+pBHU+7fFZU3w=", + "owner": "nixos-cn", + "repo": "flakes", + "rev": "2d475ec68cca251ef6c6c69a9224db5c264c5e5b", + "type": "github" + }, + "original": { + "owner": "nixos-cn", + "repo": "flakes", + "type": "github" + } + }, + "nixpak": { + "inputs": { + "flake-parts": "flake-parts_3", + "hercules-ci-effects": "hercules-ci-effects", + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1694192131, + "narHash": "sha256-nt5ypVXKh65lQFqKqWgytEzI841yUhpl6E291Briu+g=", + "owner": "nixpak", + "repo": "nixpak", + "rev": "16bd2860238c53bb7a31f745693d7d3c33a1490c", + "type": "github" + }, + "original": { + "owner": "nixpak", + "repo": "nixpak", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1693953029, - "narHash": "sha256-1+28KQl4YC4IBzKo/epvEyK5KH4MlgoYueJ8YwLGbOc=", + "lastModified": 1689850295, + "narHash": "sha256-fUYf6WdQlhd2H+3aR8jST5dhFH1d0eE22aes8fNIfyk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5df4d78d54f7a34e9ea1f84a22b4fd9baebc68d0", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1682879489, + "narHash": "sha256-sASwo8gBt7JDnOOstnps90K1wxmVfyhsTPPNTGBPjjg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4077a0e4ac3356222bc1f0a070af7939c3098535", + "rev": "da45bf6ec7bbcc5d1e14d3795c025199f28e0de0", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib_2": { + "locked": { + "dir": "lib", + "lastModified": 1685564631, + "narHash": "sha256-8ywr3AkblY4++3lIVxmrWZFzac7+f32ZEhH/A8pNscI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4f53efe34b3a8877ac923b9350c874e3dcd5dc0a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1690927903, + "narHash": "sha256-D5gCaCROnjEKDOel//8TO/pOP87pAEtT0uT8X+0Bj/U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bd836ac5e5a7358dea73cb74a013ca32864ccb86", "type": "github" }, "original": { @@ -16,9 +948,402 @@ "type": "github" } }, - "root": { + "nixpkgs-unstable": { + "locked": { + "lastModified": 1694233973, + "narHash": "sha256-LPFbAgsJhj5l64bwmeA2POGrdtEm6+WyGwyNVbGRl9A=", + "owner": "CHN-beta", + "repo": "nixpkgs", + "rev": "6b10eef17e5f6fbbb07b38015ce3dc0d5e463282", + "type": "github" + }, + "original": { + "owner": "CHN-beta", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1692007866, + "narHash": "sha256-X8w0vPZjZxMm68VCwh/BHDoKRGp+BgzQ6w7Nkif6IVM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "de2b8ddf94d6cc6161b7659649594c79bd66c13b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1688322751, + "narHash": "sha256-eW62dC5f33oKZL7VWlomttbUnOTHrAbte9yNUNW8rbk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0fbe93c5a7cac99f90b60bdf5f149383daaa615f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1694317825, + "narHash": "sha256-ud2qoXA90zSWBUeJqh/5tM055TlSe3HvsEma7Wm0V/Y=", + "owner": "CHN-beta", + "repo": "nixpkgs", + "rev": "8870ebda280940fcedca9bc35d56ed3bed9d2070", + "type": "github" + }, + "original": { + "owner": "CHN-beta", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nur": { + "locked": { + "lastModified": 1694237951, + "narHash": "sha256-6gql7EJIWwn3mUvG/RHf1iGUA3Ptfmalz9WdgX3noSY=", + "owner": "nix-community", + "repo": "NUR", + "rev": "19674a713837dcfbef704a16815a4bbc462cd57a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "NUR", + "type": "github" + } + }, + "nur-xddxdd": { + "inputs": { + "flake-utils": "flake-utils_7", + "flake-utils-plus": "flake-utils-plus", + "nixpkgs": [ + "nixos", + "nixpkgs" + ], + "nvfetcher": "nvfetcher" + }, + "locked": { + "lastModified": 1694239804, + "narHash": "sha256-C5ERSMRp8kQEqyKS2yggXSqaKZUgnNyQD+zjy6iqXm0=", + "owner": "xddxdd", + "repo": "nur-packages", + "rev": "ce48d1df62cab988a5e8eefdf97bec8bdc46392f", + "type": "github" + }, + "original": { + "owner": "xddxdd", + "repo": "nur-packages", + "type": "github" + } + }, + "nurl": { "inputs": { "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1692200072, + "narHash": "sha256-s1GdyzB9ACSqQGxJ8Syc0hFn5w8YXhOzDVdNJxQHNpg=", + "owner": "nix-community", + "repo": "nurl", + "rev": "647bc872cbb7927af0ce0a18735749ed1399f85d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nurl", + "type": "github" + } + }, + "nvfetcher": { + "inputs": { + "flake-compat": "flake-compat_6", + "flake-utils": [ + "nixos", + "nur-xddxdd", + "flake-utils" + ], + "nixpkgs": [ + "nixos", + "nur-xddxdd", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693539235, + "narHash": "sha256-ACmCq1+RnVq+EB7yeN6fThUR3cCJZb6lKEfv937WG84=", + "owner": "berberman", + "repo": "nvfetcher", + "rev": "2bcf73dea96497ac9c36ed320b457caa705f9485", + "type": "github" + }, + "original": { + "owner": "berberman", + "repo": "nvfetcher", + "type": "github" + } + }, + "pnpm2nix-nzbr": { + "inputs": { + "flake-utils": "flake-utils_8", + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1692918416, + "narHash": "sha256-SPbFwuIJ5HIhoZxI6snQ3QGyrusqB8eqX/3aOtx+afA=", + "owner": "CHN-beta", + "repo": "pnpm2nix-nzbr", + "rev": "7472a7749fc9f1ef7b75b618d6645f84ead2764d", + "type": "github" + }, + "original": { + "owner": "CHN-beta", + "repo": "pnpm2nix-nzbr", + "type": "github" + } + }, + "qchem": { + "inputs": { + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693829707, + "narHash": "sha256-nBFIF+a1aqDIzmi+1Hue3zVXI4V4tK5R4aW2lyNXIXs=", + "owner": "Nix-QChem", + "repo": "NixOS-QChem", + "rev": "ac7ffea07370d0df2c2b934ea582f0cc8acd0ae1", + "type": "github" + }, + "original": { + "owner": "Nix-QChem", + "repo": "NixOS-QChem", + "type": "github" + } + }, + "root": { + "inputs": { + "nixos": "nixos" + } + }, + "sops-nix": { + "inputs": { + "nixpkgs": [ + "nixos", + "nixpkgs" + ], + "nixpkgs-stable": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693898833, + "narHash": "sha256-OIrMAGNYNeLs6IvBynxcXub7aSW3GEUvWNsb7zx6zuU=", + "owner": "Mic92", + "repo": "sops-nix", + "rev": "faf21ac162173c2deb54e5fdeed002a9bd6e8623", + "type": "github" + }, + "original": { + "owner": "Mic92", + "repo": "sops-nix", + "type": "github" + } + }, + "st-src": { + "flake": false, + "locked": { + "lastModified": 1619005886, + "narHash": "sha256-PGD1oVKzaFARUJnn+IhgcDwqx8xuvnouLhUjaGwsMto=", + "owner": "dguibert", + "repo": "st", + "rev": "d7faa1e059e1cdb7ba0d2383c1f0fc81d6d00e15", + "type": "github" + }, + "original": { + "owner": "dguibert", + "ref": "pu", + "repo": "st", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_5": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_6": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_7": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "touchix": { + "inputs": { + "nixpkgs": [ + "nixos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1685202181, + "narHash": "sha256-yRj9Vh3T1pL+cNxhiQCFyH67Ys1h7pcrOfSZM10Xb+g=", + "owner": "CHN-beta", + "repo": "touchix", + "rev": "9cedc2f3dc007875525af480976d91b2990847de", + "type": "github" + }, + "original": { + "owner": "CHN-beta", + "repo": "touchix", + "type": "github" + } + }, + "utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "utils_2": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 8741adb..30d1aed 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,12 @@ { - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + inputs.nixos.url = "github:CHN-beta/nixos"; - outputs = inputs: let pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux; in + outputs = inputs: let pkgs = inputs.nixos.nixosConfigurations.pc.pkgs; in { - devShell.x86_64-linux = pkgs.mkShell.override { stdenv = pkgs.gcc13Stdenv; } + devShell.x86_64-linux = pkgs.mkShell.override { stdenv = pkgs.genericPackages.gcc13Stdenv; } { - buildInputs = with pkgs; [ yaml-cpp eigen fmt ]; + buildInputs = with pkgs; + [ yaml-cpp eigen fmt (localPackages.concurrencpp.override { stdenv = genericPackages.gcc13Stdenv; }) ]; nativeBuildInputs = with pkgs; [ gdb ]; }; }; diff --git a/main.cpp b/main.cpp index 7fd3676..8132a5d 100644 --- a/main.cpp +++ b/main.cpp @@ -3,8 +3,12 @@ # include # include # include +# include +# include +# include # include # include +# include using namespace std::literals; @@ -18,10 +22,10 @@ struct Input // 单胞的三个格矢,每行表示一个格矢的坐标,单位为埃 Eigen::Matrix3d PrimativeCell; // 超胞在各个方向上是单胞的多少倍,这是一个对角矩阵 - Eigen::Matrix3i SuperCellMultiplier; + Eigen::Matrix SuperCellMultiplier; // 在单胞内取几个平面波的基矢 // 在 debug 阶段, 先仅取一个 - Eigen::Vector3i PrimativeCellBasisNumber; + Eigen::Vector PrimativeCellBasisNumber; // 超胞中原子的坐标,每行表示一个原子的坐标,单位为埃 Eigen::MatrixX3d AtomPosition; @@ -39,7 +43,7 @@ struct Input // 模式中各个原子的运动状态 // 这个数据是这样得到的: phonopy 输出的动态矩阵的 eigenvector 乘以 $\exp(-2 \pi i \vec q \cdot \vec r)$ // 这个数据可以认为是原子位移中, 关于超胞有周期性的那一部分, 再乘以原子质量的开方. - // 这个数据在读入后会立即被归一化处理. + // 这个数据在读入后不会被立即归一化. Eigen::MatrixX3cd AtomMovement; }; std::vector ModeData; @@ -55,8 +59,6 @@ struct Input // 各个模式的频率: phonon[*].band[*].frequency 单位为 THz 直接从 phonopy 的输出中复制 // 各个模式的原子运动状态: phonon[*].band[*].eigenvector 直接从 phonopy 的输出中复制 // 文件中可以有多余的项目, 多余的项目不管. - Input(std::string filename) : Input(YAML::LoadFile(filename)) {} - Input(YAML::Node node); }; struct Output @@ -74,21 +76,36 @@ struct Output double Frequency; // 模式的权重 double Weight; + // 来源于哪个 Q 点, 单位为超胞的倒格矢 + Eigen::Vector3d Source; }; std::vector ModeData; }; std::vector QPointData; - - // 将数据写入文件 - void write(std::string filename) const; }; +template<> struct YAML::convert { static bool decode(const Node& node, Input& input); }; +template<> struct YAML::convert { static Node encode(const Output& output); }; + +concurrencpp::generator, unsigned>> + triplet_sequence(Eigen::Vector range) +{ + for (unsigned x = 0; x < range[0]; x++) + for (unsigned y = 0; y < range[1]; y++) + for (unsigned z = 0; z < range[2]; z++) + co_yield + { + Eigen::Vector{{x}, {y}, {z}}, + x * range[1] * range[2] + y * range[2] + z + }; +} + int main(int argc, const char** argv) { if (argc != 3) throw std::runtime_error("Usage: " + std::string(argv[0]) + " input.yaml output.yaml"); - Input input(argv[1]); + auto input = YAML::LoadFile(argv[1]).as(); // 反折叠的原理: 将超胞中的原子运动状态, 投影到一组平面波构成的基矢中. // 每一个平面波的波矢由两部分相加得到: 一部分是单胞倒格子的整数倍, 所取的个数有一定任意性, 论文中建议取大约单胞中原子个数那么多个; @@ -98,176 +115,159 @@ int main(int argc, const char** argv) // 将超胞中原子的运动状态投影到这些基矢上, 计算出投影的系数, 就可以将超胞的原子运动状态分解到单胞中的多个 q 点上. // 构建基 - // 外层下标对应超胞倒格子的整数倍那部分(第二部分), 也就是对应不同反折叠后的 q 点 + // 外层下标对应超胞倒格子的整数倍那部分(第二部分), 也就是对应不同反折叠后的 q 点(sub qpoint) // 内层下标对应单胞倒格子的整数倍那部分(第一部分), 也就是对应同一个反折叠后的 q 点上的不同平面波 std::vector> basis; - basis.resize(input.SuperCellMultiplier.determinant()); - for (int i = 0; i < input.SuperCellMultiplier(0, 0); i++) - for (int j = 0; j < input.SuperCellMultiplier(1, 1); j++) - for (int k = 0; k < input.SuperCellMultiplier(2, 2); k++) - { - // 反折叠后的某个 q 点 对应的所有的基矢 - auto& basis_at_unfolded_qpoint - = basis[i * input.SuperCellMultiplier(1, 1) * input.SuperCellMultiplier(2, 2) - + j * input.SuperCellMultiplier(2, 2) + k]; - basis_at_unfolded_qpoint.resize(input.PrimativeCellBasisNumber.prod()); - for (int x = 0; x < input.PrimativeCellBasisNumber(0); x++) - for (int y = 0; y < input.PrimativeCellBasisNumber(1); y++) - for (int z = 0; z < input.PrimativeCellBasisNumber(2); z++) - { - // 计算 q 点的坐标, 单位为相对于超胞的倒格矢 - auto qpoint_relative_to_super_cell = - Eigen::Vector3i({{i}, {j}, {k}}) - + input.SuperCellMultiplier * Eigen::Vector3i({{x}, {y}, {z}}); - // 将 q 点坐标转换为埃^-1 - auto qpoint = (qpoint_relative_to_super_cell.transpose().cast() - * (input.SuperCellMultiplier.cast().inverse().transpose())).transpose(); - // 计算基矢 - auto& single_basis = basis_at_unfolded_qpoint - [x * input.PrimativeCellBasisNumber(1) * input.PrimativeCellBasisNumber(2) - + y * input.PrimativeCellBasisNumber(2) + z]; - single_basis = (-2 * std::numbers::pi_v * 1i * (input.AtomPosition * qpoint)).array().exp(); - } - } + basis.resize(input.SuperCellMultiplier.diagonal().prod()); + for (auto [xyz_of_sub_qpoint, i_of_sub_qpoint] + : triplet_sequence(input.SuperCellMultiplier.diagonal())) + { + basis[i_of_sub_qpoint].resize(input.PrimativeCellBasisNumber.prod()); + for (auto [xyz_of_basis, i_of_basis] : triplet_sequence(input.PrimativeCellBasisNumber)) + { + // 计算 q 点的坐标, 单位为单胞的倒格矢 + auto qpoint_relative_to_primative_cell = xyz_of_basis.cast() + + input.SuperCellMultiplier.cast().inverse() * xyz_of_sub_qpoint.cast(); + // 将 q 点坐标转换为埃^-1 + auto qpoint = (qpoint_relative_to_primative_cell.transpose() * (input.PrimativeCell.transpose().inverse())) + .transpose(); + // 计算基矢 + basis[i_of_sub_qpoint][i_of_basis] + = (-2 * std::numbers::pi_v * 1i * (input.AtomPosition * qpoint)).array().exp(); + } + } // 计算投影的结果 // 最外层下标对应反折叠前的 q 点, 第二层下标对应不同模式, 第三层下标对应这个模式在反折叠后的 q 点 std::vector>> projection_coefficient; projection_coefficient.resize(input.QPointData.size()); - for (int i_of_folded_qpoint = 0; i_of_folded_qpoint < input.QPointData.size(); i_of_folded_qpoint++) + for (unsigned i_of_folded_qpoint = 0; i_of_folded_qpoint < input.QPointData.size(); i_of_folded_qpoint++) { - projection_coefficient[i_of_folded_qpoint].resize(input.QPointData[i_of_folded_qpoint].ModeData.size()); - for (int i_of_mode = 0; i_of_mode < projection_coefficient[i_of_folded_qpoint].size(); i_of_mode++) + auto num_of_mode = input.QPointData[i_of_folded_qpoint].ModeData.size(); + projection_coefficient[i_of_folded_qpoint].resize(num_of_mode); + for (unsigned i_of_mode = 0; i_of_mode < num_of_mode; i_of_mode++) { - auto& coefficient_at_mode = projection_coefficient[i_of_folded_qpoint][i_of_mode]; - coefficient_at_mode.resize(input.SuperCellMultiplier.determinant()); - for - (int i_of_unfolded_qpoint = 0; i_of_unfolded_qpoint < coefficient_at_mode.size(); i_of_unfolded_qpoint++) + auto num_of_sub_qpoint = input.SuperCellMultiplier.diagonal().prod(); + projection_coefficient[i_of_folded_qpoint][i_of_mode].resize(num_of_sub_qpoint); + for (unsigned i_of_sub_qpoint = 0; i_of_sub_qpoint < num_of_sub_qpoint; i_of_sub_qpoint++) // 对于 basis 中, 对应于单胞倒格子的部分, 以及对应于不同方向的部分, 分别求内积, 然后求绝对值, 然后求和 - for - ( - int i_of_basis_in_primary_cell = 0; - i_of_basis_in_primary_cell < basis[i_of_unfolded_qpoint].size(); - i_of_basis_in_primary_cell++ - ) - coefficient_at_mode[i_of_unfolded_qpoint] += + // 最后, 还应该除以原子数 + for (unsigned i_of_basis = 0; i_of_basis < input.PrimativeCellBasisNumber.prod(); i_of_basis++) + projection_coefficient[i_of_folded_qpoint][i_of_mode][i_of_sub_qpoint] += ( - basis[i_of_unfolded_qpoint][i_of_basis_in_primary_cell].transpose() - * input.QPointData[i_of_folded_qpoint].ModeData[i_of_mode].AtomMovement - ).array().abs2().sum(); - - // 归一化 - auto sum = std::accumulate(coefficient_at_mode.begin(), coefficient_at_mode.end(), 0.); - for (auto& coefficient : coefficient_at_mode) - coefficient /= sum; + basis[i_of_sub_qpoint][i_of_basis].transpose() + * input.QPointData[i_of_folded_qpoint].ModeData[i_of_mode].AtomMovement + ).array().abs().sum() / input.AtomPosition.rows(); } } // 填充输出对象 Output output; - for (int i_of_folded_qpoint = 0; i_of_folded_qpoint < input.QPointData.size(); i_of_folded_qpoint++) - // for each unfolded q point corresponding to this folded q point - for (int x = 0; x < input.SuperCellMultiplier(0, 0); x++) - for (int y = 0; y < input.SuperCellMultiplier(1, 1); y++) - for (int z = 0; z < input.SuperCellMultiplier(2, 2); z++) - { - auto& unfolded_qpoint = output.QPointData.emplace_back(); - unfolded_qpoint.QPoint = input.SuperCellMultiplier.cast().inverse() * - (input.QPointData[i_of_folded_qpoint].QPoint - + Eigen::Vector3i({{x}, {y}, {z}}).cast()); - for (int i_of_mode = 0; i_of_mode < input.QPointData[i_of_folded_qpoint].ModeData.size(); i_of_mode++) - if (projection_coefficient[i_of_folded_qpoint][i_of_mode] - [x * input.SuperCellMultiplier(1, 1) * input.SuperCellMultiplier(2, 2) - + y * input.SuperCellMultiplier(2, 2) + z] > 1e-3) - { - auto& mode = unfolded_qpoint.ModeData.emplace_back(); - mode.Frequency = input.QPointData[i_of_folded_qpoint].ModeData[i_of_mode].Frequency; - mode.Weight = projection_coefficient[i_of_folded_qpoint][i_of_mode] - [x * input.SuperCellMultiplier(1, 1) * input.SuperCellMultiplier(2, 2) - + y * input.SuperCellMultiplier(2, 2) + z]; - } - } + for (unsigned i_of_folded_qpoint = 0; i_of_folded_qpoint < input.QPointData.size(); i_of_folded_qpoint++) + for (auto [xyz_of_sub_qpoint, i_of_sub_qpoint] + : triplet_sequence(input.SuperCellMultiplier.diagonal())) + { + auto& sub_qpoint = output.QPointData.emplace_back(); + sub_qpoint.QPoint = input.SuperCellMultiplier.cast().inverse() * + (input.QPointData[i_of_folded_qpoint].QPoint + xyz_of_sub_qpoint.cast()); + for (unsigned i_of_mode = 0; i_of_mode < input.QPointData[i_of_folded_qpoint].ModeData.size(); i_of_mode++) + { + auto& mode = sub_qpoint.ModeData.emplace_back(); + mode.Frequency = input.QPointData[i_of_folded_qpoint].ModeData[i_of_mode].Frequency; + mode.Weight = projection_coefficient[i_of_folded_qpoint][i_of_mode][i_of_sub_qpoint]; + mode.Source = input.QPointData[i_of_folded_qpoint].QPoint; + } + } - output.write(argv[2]); + std::ofstream(argv[2]) << YAML::Node(output); } -Input::Input(YAML::Node root) +bool YAML::convert::decode(const Node& node, Input& input) { - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - PrimativeCell(i, j) = root["lattice"][i][j].as(); + for (unsigned i = 0; i < 3; i++) + for (unsigned j = 0; j < 3; j++) + input.PrimativeCell(i, j) = node["lattice"][i][j].as(); - SuperCellMultiplier.setZero(); - for (int i = 0; i < 3; i++) - SuperCellMultiplier(i, i) = root["SuperCellMultiplier"][i].as(); + input.SuperCellMultiplier.setZero(); + for (unsigned i = 0; i < 3; i++) + input.SuperCellMultiplier(i, i) = node["SuperCellMultiplier"][i].as(); - for (int i = 0; i < 3; i++) - PrimativeCellBasisNumber(i) = root["PrimativeCellBasisNumber"][i].as(); + for (unsigned i = 0; i < 3; i++) + input.PrimativeCellBasisNumber(i) = node["PrimativeCellBasisNumber"][i].as(); - auto points = root["points"].as>(); + auto points = node["points"].as>(); auto atom_position_to_super_cell = Eigen::MatrixX3d(points.size(), 3); - for (int i = 0; i < points.size(); i++) - for (int j = 0; j < 3; j++) + for (unsigned i = 0; i < points.size(); i++) + for (unsigned j = 0; j < 3; j++) atom_position_to_super_cell(i, j) = points[i]["coordinates"][j].as(); - AtomPosition = atom_position_to_super_cell * (SuperCellMultiplier.cast() * PrimativeCell); + input.AtomPosition = atom_position_to_super_cell * (input.SuperCellMultiplier.cast() * input.PrimativeCell); - auto phonon = root["phonon"].as>(); - QPointData.resize(phonon.size()); - for (int i = 0; i < phonon.size(); i++) + auto phonon = node["phonon"].as>(); + input.QPointData.resize(phonon.size()); + for (unsigned i = 0; i < phonon.size(); i++) { - QPointData[i].QPoint.resize(3); - for (int j = 0; j < 3; j++) - QPointData[i].QPoint(j) = phonon[i]["q-position"][j].as(); + input.QPointData[i].QPoint.resize(3); + for (unsigned j = 0; j < 3; j++) + input.QPointData[i].QPoint(j) = phonon[i]["q-position"][j].as(); auto band = phonon[i]["band"].as>(); - QPointData[i].ModeData.resize(band.size()); - for (int j = 0; j < band.size(); j++) + input.QPointData[i].ModeData.resize(band.size()); + for (unsigned j = 0; j < band.size(); j++) { - QPointData[i].ModeData[j].Frequency = band[j]["frequency"].as(); - auto eigenvectors = Eigen::MatrixX3cd(AtomPosition.rows(), 3); + input.QPointData[i].ModeData[j].Frequency = band[j]["frequency"].as(); + auto eigenvectors = Eigen::MatrixX3cd(input.AtomPosition.rows(), 3); auto eigenvector_vectors = band[j]["eigenvector"] .as>>>(); - for (int k = 0; k < AtomPosition.rows(); k++) - for (int l = 0; l < 3; l++) + for (unsigned k = 0; k < input.AtomPosition.rows(); k++) + for (unsigned l = 0; l < 3; l++) eigenvectors(k, l) = eigenvector_vectors[k][l][0] + 1i * eigenvector_vectors[k][l][1]; // 需要对读入的原子运动状态作相位转换, 使得它们与我们的约定一致(对超胞周期性重复) - // QPointData[i].ModeData[j].AtomMovement - // = eigenvectors.array().colwise() * (-2 * std::numbers::pi_v * 1i - // * (AtomPosition * QPointData[i].QPoint)).array().exp(); - QPointData[i].ModeData[j].AtomMovement.resize(AtomPosition.rows(), 3); - for (int k = 0; k < AtomPosition.rows(); k++) - QPointData[i].ModeData[j].AtomMovement.row(k) = eigenvectors.row(k) - * std::exp(-2 * std::numbers::pi_v * 1i - * (atom_position_to_super_cell.row(k).dot(QPointData[i].QPoint))); - - // print AtomMovement - // std::cout << "AtomMovement" << std::endl; - // std::cout << QPointData[i].ModeData[j].AtomMovement << std::endl; - + input.QPointData[i].ModeData[j].AtomMovement + = eigenvectors.array().colwise() * (-2 * std::numbers::pi_v * 1i + * (atom_position_to_super_cell * input.QPointData[i].QPoint)).array().exp(); + // input.QPointData[i].ModeData[j].AtomMovement.resize(input.AtomPosition.rows(), 3); + // for (unsigned k = 0; k < input.AtomPosition.rows(); k++) + // input.QPointData[i].ModeData[j].AtomMovement.row(k) = eigenvectors.row(k) + // * std::exp(-2 * std::numbers::pi_v * 1i + // * (atom_position_to_super_cell.row(k).dot(input.QPointData[i].QPoint))); // 这里还要需要做归一化处理 - // phonopy 的文档似乎没有保证一定做了归一化处理, 再来做一遍吧. - auto sum = QPointData[i].ModeData[j].AtomMovement.cwiseAbs2().sum(); - QPointData[i].ModeData[j].AtomMovement /= std::sqrt(sum); + // 这里的归一化其实并不是必须的, 因为在计算投影系数的时候, 还会进行一次归一化. + // 因为计算量并不大, 因此这里还是做一次归一化, 达到形式上的正确. + auto average = + ({ + auto& _ = input.QPointData[i].ModeData[j].AtomMovement; + _.cwiseAbs2().rowwise().sum().cwiseSqrt().sum() / _.rows(); + }); + input.QPointData[i].ModeData[j].AtomMovement /= average; } } + + return true; } -void Output::write(std::string filename) const +auto YAML::convert::encode(const Output& output) -> Node { - YAML::Node root; - root["QPointData"] = YAML::Node(YAML::NodeType::Sequence); - for (int i = 0; i < QPointData.size(); i++) + Node node; + node["QPointData"] = Node(NodeType::Sequence); + for (unsigned i = 0; i < output.QPointData.size(); i++) { - root["QPointData"][i]["QPoint"] = YAML::Node(YAML::NodeType::Sequence); - for (int j = 0; j < 3; j++) - root["QPointData"][i]["QPoint"][j] = QPointData[i].QPoint(j); - root["QPointData"][i]["ModeData"] = YAML::Node(YAML::NodeType::Sequence); - for (int j = 0; j < QPointData[i].ModeData.size(); j++) + node["QPointData"][i]["QPoint"] = + ({ + auto& _ = output.QPointData[i].QPoint; + std::vector(_.data(), _.data() + _.size()); + }); + node["QPointData"][i]["ModeData"] = Node(NodeType::Sequence); + for (unsigned j = 0; j < output.QPointData[i].ModeData.size(); j++) { - root["QPointData"][i]["ModeData"][j]["Frequency"] = QPointData[i].ModeData[j].Frequency; - root["QPointData"][i]["ModeData"][j]["Weight"] = QPointData[i].ModeData[j].Weight; + node["QPointData"][i]["ModeData"][j]["Frequency"] = output.QPointData[i].ModeData[j].Frequency; + node["QPointData"][i]["ModeData"][j]["Weight"] = output.QPointData[i].ModeData[j].Weight; + node["QPointData"][i]["ModeData"][j]["Source"] = + ({ + auto& _ = output.QPointData[i].ModeData[j].Source; + std::vector(_.data(), _.data() + _.size()); + }); } } - std::ofstream(filename) << root; + return node; }