CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
raster_grid.cpp
Go to the documentation of this file.
1
12
13/*===============================================================================================================================
14
15This file is part of CoastalME, the Coastal Modelling Environment.
16
17CoastalME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
18
19This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23===============================================================================================================================*/
24#include <new>
25using std::bad_alloc;
26
27#include "cme.h"
28#include "raster_grid.h"
29
30CGeomRasterGrid* CGeomCell::m_pGrid = NULL; // Initialise m_pGrid, the static member of CGeomCell
31
34: m_dD50Fine(0),
35 m_dD50Sand(0),
36 m_dD50Coarse(0),
37 m_pSim(pSimIn),
38 m_Cell(NULL)
39{
40}
41
44{
45 int nXMax = m_pSim->nGetGridXMax();
46
47 // Free the m_Cell memory
48 for (int nX = 0; nX < nXMax; nX++)
49 delete [] m_Cell[nX];
50
51 delete [] m_Cell;
52}
53
59
60// CGeomCell* CGeomRasterGrid::pGetCell(int const nX, int const nY)
61// {
62// return &m_Cell[nX][nY];
63// }
64
67{
68 // Create the 2D CGeomCell array (this is faster than using 2D STL vectors)
69 int nXMax = m_pSim->nGetGridXMax();
70 int nYMax = m_pSim->nGetGridYMax();
71
72 // TODO 038 Do better error handling if insufficient memory
73 try
74 {
75 m_Cell = new CGeomCell * [nXMax];
76 for (int nX = 0; nX < nXMax; nX++)
77 m_Cell[nX] = new CGeomCell[nYMax];
78 }
79 catch(bad_alloc&)
80 {
81 // Uh-oh, not enough memory
82 return RTN_ERR_MEMALLOC;
83 }
84
85 // Initialize the CGeomCell shared pointer to the CGeomRasterGrid object
86 CGeomCell::m_pGrid = this;
87
88 return RTN_OK;
89}
90
Geometry class for the cell objects which comprise the raster grid.
Definition cell.h:33
static CGeomRasterGrid * m_pGrid
Definition cell.h:215
Geometry cass used to represent the raster grid of cell objects.
Definition raster_grid.h:35
double m_dD50Fine
The d50 of fine-sized sediment.
Definition raster_grid.h:44
double m_dD50Sand
The d50 of sand-sized sediment.
Definition raster_grid.h:47
CGeomCell ** m_Cell
The 2D array of m_Cell objects. A c-style 2D array seems to be faster than using 2D STL vectors.
Definition raster_grid.h:56
~CGeomRasterGrid(void)
Destructor.
int nCreateGrid(void)
Creates the 2D CGeomCell array.
double m_dD50Coarse
The d50 of coarse-sized sediment.
Definition raster_grid.h:50
CSimulation * m_pSim
A pointer to the CSimulation object.
Definition raster_grid.h:53
friend class CSimulation
The CSimulation class is a friend of the CGeomRasterGrid class.
Definition raster_grid.h:37
CGeomRasterGrid(CSimulation *)
Constructor.
CSimulation * pGetSim(void)
Returns a pointer to the simulation object.
This file contains global definitions for CoastalME.
int const RTN_ERR_MEMALLOC
Definition cme.h:593
int const RTN_OK
Definition cme.h:577
Contains CGeomRasterGrid definitions.