Navigation

Staggered grids

Staggered_grid grid( N_, N_, N_ , {0., 0., 0.}, {1., 1., 1.}, periodic, periodic, periodic );

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<_X_> X( grid );
Coordinate<_Y_> Y( grid );
Coordinate<_Z_> Z( grid );

Function<double, double> Sin( std::sin );
Function<double, double> Sinh( std::sinh );

u_ex = Sin( X * M_PI ) * Sinh( Y * M_PI ); // exact solution
u = u_ex;

for ( size_t i = 0; i < iterations; ++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;

std::cout << "Error: " << Math::L_infty( err ) << std::endl;
;}