ewNode.h 4.05 KB
Newer Older
1
2
3
4
#ifndef EW_NODE_H
#define EW_NODE_H

#include <stdlib.h>
5
6
#include <string.h>
#include "easywave.h"
7
8
9
10
11
12
13
14
15
16
17
18
19
20

#define CHKRET( x ) if( (x) == NULL ) return 1;

typedef float Float[MAX_VARS_PER_NODE];

class CNode {

public:
	virtual ~CNode() {};
	virtual float& operator()( const int idx1, const int idx2 ) = 0;
	virtual int mallocMem() = 0;
	virtual int copyToGPU() = 0;
	virtual int copyFromGPU() = 0;
	virtual int copyIntermediate() = 0;
21
	virtual int copyPOIs() = 0;
22
23
	virtual int freeMem() = 0;
	virtual int run() = 0;
24
25

	virtual void initMemory( int index, int val ) = 0;
26
27
28
29
30
31
32
33
34
35
36
37
38
};

class CStructNode : public CNode {

public:
	Float *node;

public:
	inline float& operator()( const int idx1, const int idx2 ) {

		return node[idx1][idx2];
	}

39
40
41
42
43
44
45
46
47
48
49
	void initMemory( int index, int val ) {

		int m;
		for( int i=1; i<=NLon; i++ ) {
		  for( int j=1; j<=NLat; j++ ) {
				m = idx(j,i);
				this->operator ()(m, index) = val;
		  }
		}
	}

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	int mallocMem() {

		CHKRET( this->node = (Float*) malloc( sizeof(Float) * NLon * NLat) );

		/* FIXME: remove global variables */
		CHKRET( R6 = (float*) malloc( sizeof(float) * (NLat+1) ) );
		CHKRET( C1 = (float*) malloc( sizeof(float) * (NLon+1) ) );
		CHKRET( C3 = (float*) malloc( sizeof(float) * (NLon+1) ) );
		CHKRET( C2 = (float*) malloc( sizeof(float) * (NLat+1) ) );
		CHKRET( C4 = (float*) malloc( sizeof(float) * (NLat+1) ) );

		return 0;
	}

	int freeMem() {

		free( this->node );
		free( R6 );
		free( C1 );
		free( C2 );
		free( C3 );
		free( C4 );

		return 0;
	}

	int run() {

		if( Par.coriolis )
		  return ewStepCor();

		return ewStep();
	}

	int copyToGPU() { return 0; }
	int copyFromGPU() {	return 0; }
	int copyIntermediate() { return 0; }
87
	int copyPOIs() { return 0; }
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
};

#pragma pack(push, 1)
class CArrayNode : public CNode {

protected:
	float *d;
	float *h;
	float *hMax;
	float *fM;
	float *fN;
	float *cR1;
	float *cR2;
	float *cR3;
	float *cR4;
	float *cR5;
	float *tArr;
	float *topo;

public:
	virtual float& operator()( const int idx1, const int idx2 ) {

		return ((float**)&d)[idx2][idx1];
	}

114
115
116
117
118
119
120
121
	void *getBuf( int idx ) { return ((float**)&d)[idx]; }

	virtual void initMemory( int index, int val ) {

		memset( getBuf(index), 0, NLat * NLon * sizeof(float) );

	}

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
	virtual int mallocMem() {

		CHKRET( this->d = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->h = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->hMax = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->fM = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->fN = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->cR1 = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->cR2 = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->cR3 = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->cR4 = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->cR5 = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->tArr = (float*) malloc( sizeof(float) * NLon * NLat ) );
		CHKRET( this->topo = (float*) malloc( sizeof(float) * NLon * NLat ) );

		/* FIXME: remove global variables */
		CHKRET( R6 = (float*) malloc( sizeof(float) * (NLat+1) ) );
		CHKRET( C1 = (float*) malloc( sizeof(float) * (NLon+1) ) );
		CHKRET( C3 = (float*) malloc( sizeof(float) * (NLon+1) ) );
		CHKRET( C2 = (float*) malloc( sizeof(float) * (NLat+1) ) );
		CHKRET( C4 = (float*) malloc( sizeof(float) * (NLat+1) ) );

		return 0;
	}

	virtual int freeMem() {

		free( this->d );
		free( this->h );
		free( this->hMax );
		free( this->fM );
		free( this->fN );
		free( this->cR1 );
		free( this->cR2 );
		free( this->cR3 );
		free( this->cR4 );
		free( this->cR5 );
		free( this->tArr );
		free( this->topo );

		free( R6 );
		free( C1 );
		free( C2 );
		free( C3 );
		free( C4 );

		return 0;
	}

	virtual int run() {

		if( Par.coriolis )
		  return ewStepCor();

		return ewStep();
	}

	virtual int copyToGPU() { return 0; }
	virtual int copyFromGPU() {	return 0; }
	virtual int copyIntermediate() { return 0; }
182
	virtual int copyPOIs() { return 0; }
183
184
185
186
187

};
#pragma pack(pop)

#endif /* EW_NODE_H */