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
15 This file is part of CoastalME, the Coastal Modelling Environment.
16
17 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.
18
19 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.
20
21 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.
22
23===============================================================================================================================*/
24#include <cstdio>
25
26#include <new>
27using std::bad_alloc;
28
29#include "cme.h"
30#include "cell.h"
31#include "simulation.h"
32#include "raster_grid.h"
33
34CGeomRasterGrid* CGeomCell::m_pGrid = NULL; // Initialise m_pGrid, the static member of CGeomCell
35
38 : m_dD50Fine(0),
39 m_dD50Sand(0),
40 m_dD50Coarse(0),
41 m_pSim(pSimIn),
42 m_Cell(NULL)
43{
44}
45
48{
49 int const nXMax = m_pSim->nGetGridXMax();
50
51 // Free the m_Cell memory
52 for (int nX = 0; nX < nXMax; nX++)
53 delete[] m_Cell[nX];
54
55 delete[] m_Cell;
56}
57
63
64// CGeomCell* CGeomRasterGrid::pGetCell(int const nX, int const nY)
65// {
66// return &m_Cell[nX][nY];
67// }
68
71{
72 // Create the 2D CGeomCell array (this is faster than using 2D STL vectors)
73 int const nXMax = m_pSim->nGetGridXMax();
74 int const nYMax = m_pSim->nGetGridYMax();
75
76 // TODO 038 Do better error handling if insufficient memory
77 try
78 {
79 m_Cell = new CGeomCell*[nXMax];
80
81 for (int nX = 0; nX < nXMax; nX++)
82 m_Cell[nX] = new CGeomCell[nYMax];
83 }
84
85 catch (bad_alloc&)
86 {
87 // Uh-oh, not enough memory
88 return RTN_ERR_MEMALLOC;
89 }
90
91 // Initialize the CGeomCell shared pointer to the CGeomRasterGrid object
92 CGeomCell::m_pGrid = this;
93
94 return RTN_OK;
95}
Contains CGeomCell definitions.
Geometry class for the cell objects which comprise the raster grid.
Definition cell.h:46
static CGeomRasterGrid * m_pGrid
Definition cell.h:262
Geometry cass used to represent the raster grid of cell objects.
Definition raster_grid.h:34
double m_dD50Fine
The d50 of fine-sized sediment.
Definition raster_grid.h:43
double m_dD50Sand
The d50 of sand-sized sediment.
Definition raster_grid.h:46
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:55
~CGeomRasterGrid(void)
Destructor.
int nCreateGrid(void)
Creates the 2D CGeomCell array.
double m_dD50Coarse
The d50 of coarse-sized sediment.
Definition raster_grid.h:49
CSimulation * m_pSim
A pointer to the CSimulation object.
Definition raster_grid.h:52
friend class CSimulation
The CSimulation class is a friend of the CGeomRasterGrid class.
Definition raster_grid.h:36
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:711
int const RTN_OK
Definition cme.h:695
Contains CGeomRasterGrid definitions.
Contains CSimulation definitions.