void Update_Structure_Factor ()
{
double Ssin [121][121][121];
double Scos [121][121][121];
double kdotr;
int ik;
double Sk_ [66];
int howmany [66];
for ( int i=0; i<x_.size(); ++i )
{
for ( int k1=0; k1<=120; ++k1 )
{
for ( int k2=0; k2<=120; ++k2 )
{
for ( int k3=0; k3<=120; ++k3 )
{
kdotr = (double)dQ*( (k1-60)*x_[i][0] + (k2-60)*x_[i][1] + (k3-60)*x_[i][1] );
Ssin[k1][k2][k3] += (double)sin(kdotr);
Scos[k1][k2][k3] += (double)cos(kdotr);
}
}
}
}
for ( int k1=0; k1<=120; ++k1 )
{
for ( int k2=0; k2<=120; ++k2 )
{
for ( int k3=0; k3<=120; ++k3 )
{
double k = (double)dQ*sqrt( pow((k1-60),2) + pow((k2-60),2) + pow((k3-60),2) );
ik = round(k/0.1);
Sk_[ik] += Ssin[k1][k2][k3]*Ssin[k1][k2][k3] + Scos[k1][k2][k3]*Scos[k1][k2][k3];
++howmany[ik];
}
}
}
for ( int i=0; i<66; ++i )
Sk[i] += (double)Sk_[i]/howmany[i];
}
第 34 行导致了问题,即Sk_[ik] += Ssin[k1][k2][k3]*Ssin[k1][k2][k3] + Scos[k1][k2][k3]*Scos[k1][k2][k3];
“有趣”的事情是,如果我替换Ssin[k1][k2][k3]*Ssin[k1][k2][k3] + Scos[k1][k2][k3]*Scos[k1][k2][k3]
为 2,它会起作用。
请帮忙!
PS:x_
并且Sk
是该方法Update_Structure_Factor
所属的类的成员。