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 "simulation.h"
29#include "raster_grid.h"
30
31CGeomRasterGrid* CGeomCell::m_pGrid = NULL; // Initialise m_pGrid, the static member of CGeomCell
32
35: m_dD50Fine(0),
36 m_dD50Sand(0),
37 m_dD50Coarse(0),
38 m_pSim(pSimIn),
39 m_Cell(NULL)
40{
41}
42
45{
46 int nXMax = m_pSim->nGetGridXMax();
47
48 // Free the m_Cell memory
49 for (int nX = 0; nX < nXMax; nX++)
50 delete [] m_Cell[nX];
51
52 delete [] m_Cell;
53}
54
60
61// CGeomCell* CGeomRasterGrid::pGetCell(int const nX, int const nY)
62// {
63// return &m_Cell[nX][nY];
64// }
65
68{
69 // Create the 2D CGeomCell array (this is faster than using 2D STL vectors)
70 int nXMax = m_pSim->nGetGridXMax();
71 int nYMax = m_pSim->nGetGridYMax();
72
73 // TODO 038 Do better error handling if insufficient memory
74 try
75 {
76 m_Cell = new CGeomCell * [nXMax];
77 for (int nX = 0; nX < nXMax; nX++)
78 m_Cell[nX] = new CGeomCell[nYMax];
79 }
80 catch(bad_alloc&)
81 {
82 // Uh-oh, not enough memory
83 return RTN_ERR_MEMALLOC;
84 }
85
86 // Initialize the CGeomCell shared pointer to the CGeomRasterGrid object
87 CGeomCell::m_pGrid = this;
88
89 return RTN_OK;
90}
91
Geometry class for the cell objects which comprise the raster grid.
Definition cell.h:38
static CGeomRasterGrid * m_pGrid
Definition cell.h:220
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:596
int const RTN_OK
Definition cme.h:580
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.