next up previous
Next: 6 計算精度のチェック Up: 計算天文学 II 第11回 データ構造とアルゴリズム(2) Previous: 4 時間積分

5 プログラム全体の構造

さて、これまで断片的にいろいろな関数を説明してきたが、プログラム全体と してはどんな構造にすればいいだろうか?やらないといけないことは以下のよ うなものである。

  1. ソフトニング、時間刻みなどのパラメータを読み込む。
  2. 初期条件を作るなり、ファイルから読み込むなりする。
  3. 重力を計算する。
  4. 以下のループをシミュレーション時刻の終わりまで繰り返す。
  5. 予測子を計算。
  6. 重力を計算。
  7. 修正子を計算。
  8. 出力が必要であればなんか書く。

pt minus 1 pt

int main()
{
    particle * pp;
    int n;
    cerr << "Enter n:";
    cin >> n ;
    pp = new particle[n];
    double rsize = 1.0;
    create_uniform_sphere(pp, n, 0 , rsize);
    bhnode * bn = NULL;

    int nnodes = n*2+100;
    bn = new bhnode[nnodes];
    double eps2;
    double theta;
    double dt;
    double tend;
    int iout;
    cerr << "Enter eps2, theta, dt, tend, iout:";
    cin >> eps2 >>theta >>dt >>tend >> iout;
    cerr << "eps2=" << eps2 << " theta=" <<theta <<" dt=" << dt 
         << " tend=" << tend << " iout=" << iout <<endl;
    calculate_gravity(bn,nnodes,pp,n,eps2, theta);
    cerr << "Initial data"<<endl;
    print_energies(pp,n,0);
    int istep = 0;
    for(double t=0;t<tend; t+=dt){
        integrate(bn, nnodes, pp, n, eps2, theta, dt);
        istep++;
        if (istep % iout == 0){
            cerr << "Time=" << t+dt <<endl;
            print_cm(pp, n);
            print_energies(pp,n,1);
        }
    }
    return 0;
}



Jun Makino
平成19年1月14日