SWE
/import/home/rettenbs/src/SWE/src/blocks/SWE_Block.hh
Go to the documentation of this file.
00001 
00029 #ifndef __SWE_BLOCK_HH
00030 #define __SWE_BLOCK_HH
00031 
00032 #include "tools/help.hh"
00033 #include "scenarios/SWE_Scenario.hh"
00034 
00035 #include <iostream>
00036 #include <fstream>
00037 
00038 using namespace std;
00039 
00040 // number of blocks for multiple-block-version of the code
00041 const int BLOCKS=4;
00042 
00043 // forward declaration
00044 class SWE_Block1D;
00045 
00116 class SWE_Block {
00117 
00118   public:
00119   // object methods
00121     void initScenario(float _offsetX, float _offsetY,
00122                 SWE_Scenario &i_scenario, const bool i_multipleBlocks = false );
00123     // set unknowns
00125     void setWaterHeight(float (*_h)(float, float));
00127     void setDischarge(float (*_u)(float, float), float (*_v)(float, float));
00129     void setBathymetry(float _b);
00131     void setBathymetry(float (*_b)(float, float));
00132     
00133     // read access to arrays of unknowns
00135     const Float2D& getWaterHeight();
00137     const Float2D& getDischarge_hu();
00139     const Float2D& getDischarge_hv();
00141     const Float2D& getBathymetry();
00142 
00143     // defining boundary conditions
00145     void setBoundaryType(BoundaryEdge edge, BoundaryType boundtype, 
00146                          const SWE_Block1D* inflow = NULL);
00147 //     void connectBoundaries(BoundaryEdge edge, SWE_Block &neighbour, BoundaryEdge neighEdge);
00148 
00150     virtual SWE_Block1D* registerCopyLayer(BoundaryEdge edge);
00152     virtual SWE_Block1D* grabGhostLayer(BoundaryEdge edge);
00153     
00155     void setGhostLayer();
00156 
00158 
00161     float getMaxTimestep() { return maxTimestep; };
00162   
00163     // compute the largest allowed time step for the current grid block
00164     void computeMaxTimestep( const float i_dryTol = 0.1, const float i_cflNumber = 0.4 );
00165 
00167     virtual void simulateTimestep(float dt) = 0;
00168 
00171 
00180     virtual float simulate(float tStart, float tEnd) = 0;
00181     
00183 
00188     virtual void computeNumericalFluxes() = 0;
00189     
00191 
00199     virtual void updateUnknowns(float dt) = 0;
00200 
00201     // access methods to grid sizes
00203     int getNx() { return nx; }
00205     int getNy() { return ny; }
00206 
00207   // Konstanten:
00209     static const float g;
00210         
00211   protected:
00212     // Constructor und Destructor
00213     SWE_Block(int l_nx, int l_ny,
00214                 float l_dx, float l_dy);
00215     virtual ~SWE_Block();
00216 
00217     // Sets the bathymetry on outflow and wall boundaries
00218     void setBoundaryBathymetry();
00219 
00220     // synchronization Methods
00221     virtual void synchAfterWrite();
00222     virtual void synchWaterHeightAfterWrite();
00223     virtual void synchDischargeAfterWrite();
00224     virtual void synchBathymetryAfterWrite();
00225     virtual void synchGhostLayerAfterWrite();
00226 
00227     virtual void synchBeforeRead();
00228     virtual void synchWaterHeightBeforeRead();
00229     virtual void synchDischargeBeforeRead();
00230     virtual void synchBathymetryBeforeRead();
00231     virtual void synchCopyLayerBeforeRead();
00232     
00234     virtual void setBoundaryConditions();
00235 
00236     // grid size: number of cells (incl. ghost layer in x and y direction:
00237     int nx;     
00238     int ny;     
00239     // mesh size dx and dy:
00240     float dx;   
00241     float dy;   
00242 
00243     // define arrays for unknowns: 
00244     // h (water level) and u,v (velocity in x and y direction)
00245     // hd, ud, and vd are respective CUDA arrays on GPU
00246     Float2D h;  
00247     Float2D hu; 
00248     Float2D hv; 
00249     Float2D b;  
00250     
00252     BoundaryType boundary[4];
00254     const SWE_Block1D* neighbour[4];
00255 
00257 
00261     float maxTimestep;
00262 
00263     // offset of current block
00264     float offsetX;      
00265     float offsetY;      
00266 };
00267 
00275 struct SWE_Block1D {
00276     SWE_Block1D(const Float1D& _h, const Float1D& _hu, const Float1D& _hv)
00277     : h(_h), hu(_hu), hv(_hv) {};
00278     SWE_Block1D(float* _h, float* _hu, float* _hv, int _size, int _stride=1)
00279     : h(_h,_size,_stride), hu(_hu,_size,_stride), hv(_hv,_size,_stride) {};
00280    
00281     Float1D h;
00282     Float1D hu;
00283     Float1D hv;
00284 };
00285 
00286 
00287 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends