因为没有给定参数,所以参数t和u全都用字符串代替,而且之后的解矩阵运算也没办法进行。
如果给定参数而不是用字符串表示,那么整个程序的效率会更高,而且之后可以继续写具体的矩阵运算过程。
#include <iostream>
#include <bitset>
#include <string>
#include <fstream>
using namespace std;
const int atoms = 4;
const int configurations = (atoms * (atoms - 1)) * (atoms * (atoms - 1)) / 4;
bitset<2 * atoms> waves[configurations];
int main()
{
//定义输出文件
//组态数据
ofstream configwaves("configurations.out", ofstream::out | ofstream::trunc);
//矩阵元数据
ofstream matrix("Hamiltonian.out", ofstream::out | ofstream::trunc);
//组态计算
configwaves << "atoms = " << atoms << endl;
configwaves << "configurations = " << configurations << endl;
configwaves << "-----------------------------------------" << endl;
//定义必要的变量
int index = 0;
bitset<2 * atoms> iwave;
//生成Sz=0的所有组态
//注意bitset输出之后是从后向前读的
for(int alpha_i = 0; alpha_i != 2 * (atoms - 1); alpha_i += 2) {
iwave.set(alpha_i);
for(int alpha_j = alpha_i + 2; alpha_j != 2 * atoms; alpha_j += 2) {
iwave.set(alpha_j);
for(int beta_i = 0; beta_i != 2 * (atoms - 1); beta_i += 2) {
iwave.set(beta_i + 1);
for(int beta_j = beta_i + 2; beta_j != 2 * atoms; beta_j += 2) {
iwave.set(beta_j + 1);
waves[index] = iwave;
//为了可读性,输出便于阅读的组态
configwaves << "index = " << index << endl;
if(alpha_i <= beta_i) {