00001 #ifndef gridripper_amr1d_FieldComponents_h
00002 #define gridripper_amr1d_FieldComponents_h
00003
00004 #include <gridripper/math.h>
00005 #include <gridripper/amr1d/FieldWrapper.h>
00006
00007 namespace gridripper { namespace amr1d {
00008
00009 using namespace std;
00010
00019 template<class K>
00020 class FieldComponents;
00021
00022
00024 template <>
00025 class FieldComponents<GReal_t>;
00026
00027
00029 template <>
00030 class FieldComponents<GComplex_t>;
00031
00032
00034 template <>
00035 class FieldComponents<GReal_t>: public FieldWrapper
00036 {
00037 private:
00038 int numComponents;
00039
00040 public:
00042 FieldComponents<GReal_t>(GReal_t* d, int n):
00043 FieldWrapper(d, n), numComponents(n) {
00044 }
00045
00047 FieldComponents<GReal_t>(int n):
00048 FieldWrapper(n), numComponents(n) {
00049 }
00050
00052 FieldComponents<GReal_t>(const FieldComponents<GReal_t>& other):
00053 FieldWrapper(other), numComponents(other.getNumComponents()) {
00054 }
00055
00057 FieldComponents<GReal_t>():
00058 FieldWrapper(0), numComponents(0) {
00059 }
00060
00061 int getNumComponents() const {
00062 return numComponents;
00063 }
00064
00065 GReal_t operator [](int i) const {
00066 return data()[i];
00067 }
00068
00069 GReal_t& operator [](int i) {
00070 return data()[i];
00071 }
00072
00077 bool resize(int n)
00078 {
00079 if (ownsData) numComponents=n;
00080 return FieldWrapper::resize(n);
00081 }
00082
00083 virtual FieldWrapper* cloneFieldWrapper() const {
00084 return new FieldComponents<GReal_t>(*this);
00085 }
00086
00087 FieldComponents<GReal_t>& operator=(const FieldComponents<GReal_t>& other)
00088 {
00089 FieldWrapper::operator=(other);
00090 if (ownsData) numComponents=other.numComponents;
00091 return *this;
00092 }
00093
00094 };
00095
00096
00098 template <>
00099 class FieldComponents<GComplex_t>: public FieldWrapper
00100 {
00101 private:
00102 int numComponents;
00103
00104 public:
00106 FieldComponents<GComplex_t>(GReal_t* d, int n):
00107 FieldWrapper(d, n*2), numComponents(n) {
00108 }
00109
00111 FieldComponents<GComplex_t>(int n):
00112 FieldWrapper(n*2), numComponents(n) {
00113 }
00114
00116 FieldComponents<GComplex_t>(const FieldComponents<GComplex_t>& other):
00117 FieldWrapper(other), numComponents(other.getNumComponents()) {
00118 }
00119
00121 FieldComponents<GComplex_t>():
00122 FieldWrapper(0*2), numComponents(0) {
00123 }
00124
00125 int getNumComponents() const {
00126 return numComponents;
00127 }
00128
00129 const GComplex_t& operator [](int i) const {
00130 return *(GComplex_t*)(&(data()[i*2]));
00131 }
00132
00133 GComplex_t& operator [](int i) {
00134 return *(GComplex_t*)(&(data()[i*2]));
00135 }
00136
00141 bool resize(int n)
00142 {
00143 if (ownsData) numComponents=n;
00144 return FieldWrapper::resize(2*n);
00145 }
00146
00147 virtual FieldWrapper* cloneFieldWrapper() const {
00148 return new FieldComponents<GComplex_t>(*this);
00149 }
00150
00151 FieldComponents<GComplex_t>& operator=(const FieldComponents<GComplex_t>& other)
00152 {
00153 FieldWrapper::operator=(other);
00154 if (ownsData) numComponents=other.numComponents;
00155 return *this;
00156 }
00157
00158 };
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 } }
00266
00267 #endif