The code below shows a simple code for solving Poisson's equation by Gauss-Seidel. The pure code can be found here. .
#include "source/staggex.h"
double sinus (double x){
return sin(x);
}
double sinush (double x){
return sinh(x);
}
int main(int argc, char** argv)
{
cout.precision(10);
cout.setf(std::ios::fixed,std::ios::floatfield);
std::ifstream PARAMETER;
int n, iteration;
ofstream DATEI;
PARAMETER.open("para.dat",std::ios::in);
PARAMETER >> n >> iteration;
PARAMETER.close();
cout << "\n Solving bla \n";
cout << "\n n: " << n;
Staggered_grid grid(n,n,n,
D3vector(0.0,0.0,0.0),
D3vector(1.0,1.0,1.0));
Variable<double,not_staggered,not_staggered,not_staggered> u(grid);
Variable<double,not_staggered,not_staggered,not_staggered> u_ex(grid);
Variable<double,not_staggered,not_staggered,not_staggered> err(grid);
Coordinate<WE_dir> X(grid);
Coordinate<SN_dir> Y(grid);
Coordinate<DT_dir> Z(grid);
//GAUSS Seidel
Function1 Sin(sinus);
Function1 Sinh(sinush);
// u_ex = X*Y;
u_ex = Sin( X * M_PI ) * Sinh( Y * M_PI); // exact solution
u = u_ex;
for(int i=0; i < iteration;++i) {
u = (E(E(u)) + W(W(u)) + N(N(u)) + S(S(u)) + T(T(u)) + D(D(u))) / 6.0;
err = u - u_ex;
cout << " error: " << L_infty(err) << endl;
}
DATEI.open("u.dx",std::ios :: out);
u.Print_Dx(&DATEI);
DATEI.close();
cout << " end! " << endl;
}
Last modified: Wed Jun 6 10:14:54 PDT 2001