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
10
11/* ===============================================================================================================================
12 This file is part of CoastalME, the Coastal Modelling Environment.
13
14 CoastalME 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.
15
16 This 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.
17
18 You 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.
19===============================================================================================================================*/
20#include <cstdio>
21
22#include <new>
23using std::bad_alloc;
24
25#include "cme.h"
26#include "cell.h"
27#include "simulation.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 const 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 const nXMax = m_pSim->nGetGridXMax();
70 int const 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
77 for (int nX = 0; nX < nXMax; nX++)
78 m_Cell[nX] = new CGeomCell[nYMax];
79 }
80
81 catch (bad_alloc&)
82 {
83 // Uh-oh, not enough memory
84 return RTN_ERR_MEMALLOC;
85 }
86
87 // Initialize the CGeomCell shared pointer to the CGeomRasterGrid object
88 CGeomCell::m_pGrid = this;
89
90 return RTN_OK;
91}
Contains CGeomCell definitions.
Geometry class for the cell objects which comprise the raster grid.
Definition cell.h:36
static CGeomRasterGrid * m_pGrid
Definition cell.h:245
Geometry cass used to represent the raster grid of cell objects.
Definition raster_grid.h:29
double m_dD50Fine
The d50 of fine-sized sediment.
Definition raster_grid.h:38
double m_dD50Sand
The d50 of sand-sized sediment.
Definition raster_grid.h:41
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:50
~CGeomRasterGrid(void)
Destructor.
int nCreateGrid(void)
Creates the 2D CGeomCell array.
double m_dD50Coarse
The d50 of coarse-sized sediment.
Definition raster_grid.h:44
CSimulation * m_pSim
A pointer to the CSimulation object.
Definition raster_grid.h:47
friend class CSimulation
The CSimulation class is a friend of the CGeomRasterGrid class.
Definition raster_grid.h:31
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:601
int const RTN_OK
Definition cme.h:585
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.