#ifndef _INCLUDED_L3_DIFF_H #define _INCLUDED_L3_DIFF_H // *Finite differences methods* Copyright (C) Krzysztof Bosak, 1999-12-02...1999-12-03 // All rights reserved. // kbosak@box43.pl // http://www.kbosak.prv.pl #include "l3_array.h" template class Lattice { int _steps; int _stepspow2; real _lostvalue; basearray _indexy; basearray _lattice; public: Lattice(int steps, bool clear) : _steps(steps), _stepspow2(steps*steps), _indexy(steps), _lattice(steps*steps) { for(int i=0, iy=0; i=-2 && x<_steps+2); assert(y>=-2 && y<_steps+2); if(x<0 || x>=_steps) { return _lostvalue=0; } if(y<0 || y>=_steps) { return _lostvalue=0; } return _lattice[x+_indexy[y]]; } inline real operator()(int x, int y) const {// SOR needs wide array boundaries... assert(x>=-2 && x<_steps+2); assert(y>=-2 && y<_steps+2); if(x<0 || x>=_steps) { return 0; } if(y<0 || y>=_steps) { return 0; } return _lattice[x+_indexy[y]]; } inline real& Value(int x, int y) { // Get value by reference assert(x>=0 && x<_steps); assert(y>=0 && y<_steps); return _lattice[x+_indexy[y]]; } inline real Value(int x, int y) const { // Get value assert(x>=0 && x<_steps); assert(y>=0 && y<_steps); return _lattice[x+_indexy[y]]; } inline real& operator[](int i) { return _lattice[i]; } inline real operator[](int i) const { return _lattice[i]; } inline void Clear() { for(int j=0; j<_stepspow2; j++) { _lattice[j]=0; } } inline void Swap(Lattice& lat2) { assert(_steps==lat2._steps); _lattice.swap(lat2._lattice); } inline void GetData(Lattice& lat) { _lattice=lat._lattice; } void Deriv1x(Lattice& lat, real h) const { const real c1=1/(12*h); const real c2=8/(12*h); const int sm1=_steps-1; const int sm2=_steps-2; int y, iy; // Interior for(y=0, iy=0; y<_steps; y++, iy+=_steps) { for(int x=2; x