refinedsimplexlocalbasis.hh
Go to the documentation of this file.00001
00002
00003 #ifndef DUNE_REFINED_SIMPLEX_LOCALBASIS_HH
00004 #define DUNE_REFINED_SIMPLEX_LOCALBASIS_HH
00005
00010 #include <dune/common/fvector.hh>
00011 #include <dune/common/exceptions.hh>
00012 #include <dune/localfunctions/common/localbasis.hh>
00013
00014 namespace Dune
00015 {
00016 template<class D, int dim>
00017 class RefinedSimplexLocalBasis
00018 {
00019 protected:
00020 RefinedSimplexLocalBasis()
00021 {
00022 DUNE_THROW(Dune::NotImplemented,"RefinedSimplexLocalBasis not implemented for dim > 3.");
00023 }
00024 };
00025
00048 template<class D>
00049 class RefinedSimplexLocalBasis<D,1>
00050 {
00051 protected:
00052
00054 RefinedSimplexLocalBasis() {}
00055
00062 static void getSubElement(const FieldVector<D,1>& global,
00063 int& subElement,
00064 FieldVector<D,1>& local)
00065 {
00066 if (global[0] <= 0.5) {
00067 subElement = 0;
00068 local[0] = 2.0 * global[0];
00069 return;
00070 }
00071
00072 subElement = 1;
00073 local[0] = 2.0 * global[0] - 1.0;
00074
00075 }
00076
00077 };
00078
00079
00101 template<class D>
00102 class RefinedSimplexLocalBasis<D,2>
00103 {
00104 protected:
00105
00107 RefinedSimplexLocalBasis() {}
00108
00123 static int getSubElement(const FieldVector<D,2>& global)
00124 {
00125 if (global[0] + global[1] <= 0.5)
00126 return 0;
00127 else if (global[0] >= 0.5)
00128 return 1;
00129 else if (global[1] >= 0.5)
00130 return 2;
00131 return 3;
00132 }
00133
00140 static void getSubElement(const FieldVector<D,2>& global,
00141 int& subElement,
00142 FieldVector<D,2>& local)
00143 {
00144 if (global[0] + global[1] <= 0.5) {
00145 subElement = 0;
00146 local[0] = 2*global[0];
00147 local[1] = 2*global[1];
00148 return;
00149 } else if (global[0] >= 0.5) {
00150 subElement = 1;
00151 local[0] = 2*global[0]-1;
00152 local[1] = 2*global[1];
00153 return;
00154 } else if (global[1] >= 0.5) {
00155 subElement = 2;
00156 local[0] = 2*global[0];
00157 local[1] = 2*global[1]-1;
00158 return;
00159 }
00160
00161 subElement = 3;
00162 local[0] = -2 * global[0] + 1;
00163 local[1] = -2 * global[1] + 1;
00164
00165 }
00166
00167
00168 };
00169
00197 template<class D>
00198 class RefinedSimplexLocalBasis<D,3>
00199 {
00200 protected:
00201
00203 RefinedSimplexLocalBasis() {}
00204
00211 static void getSubElement(const FieldVector<D,3>& global,
00212 int& subElement,
00213 FieldVector<D,3>& local)
00214 {
00215 if (global[0] + global[1] + global[2] <= 0.5) {
00216 subElement = 0;
00217 local = global;
00218 local *= 2.0;
00219 return;
00220 } else if (global[0] >= 0.5) {
00221 subElement = 1;
00222 local = global;
00223 local[0] -= 0.5;
00224 local *= 2.0;
00225 return;
00226 } else if (global[1] >= 0.5) {
00227 subElement = 2;
00228 local = global;
00229 local[1] -= 0.5;
00230 local *= 2.0;
00231 return;
00232 } else if (global[2] >= 0.5) {
00233 subElement = 3;
00234 local = global;
00235 local[2] -= 0.5;
00236 local *= 2.0;
00237 return;
00238 } else if ((global[0] + global[1] <= 0.5) and (global[1] + global[2] <= 0.5)) {
00239 subElement = 4;
00240 local[0] = 2.0 * global[1];
00241 local[1] = 2.0 * (0.5 - global[0] - global[1]);
00242 local[2] = 2.0 * (-0.5 + global[0] + global[1] + global[2]);
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 return;
00254 } else if ((global[0] + global[1] >= 0.5) and (global[1] + global[2] <= 0.5)) {
00255 subElement = 5;
00256 local[0] = 2.0 * (0.5 - global[0]);
00257 local[1] = 2.0 * (0.5 - global[1] - global[2]);
00258 local[2] = 2.0 * global[2];
00259
00260
00261
00262
00263
00264
00265
00266
00267 return;
00268 } else if ((global[0] + global[1] <= 0.5) and (global[1] + global[2] >= 0.5)) {
00269 subElement = 6;
00270 local[0] = 2.0 * (0.5 - global[0] - global[1]);
00271 local[1] = 2.0 * global[0];
00272 local[2] = 2.0 * (-0.5 + global[1] + global[2]);
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 return;
00283 } else if ((global[0] + global[1] >= 0.5) and (global[1] + global[2] >= 0.5)) {
00284 subElement = 7;
00285 local[0] = 2.0 * (-0.5 + global[1] + global[2]);
00286 local[1] = 2.0 * (0.5 - global[1]);
00287 local[2] = 2.0 * (-0.5 + global[0] + global[1]);
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 return;
00299 }
00300
00301 DUNE_THROW(InvalidStateException, "no subelement defined");
00302
00303 }
00304
00305 };
00306
00307
00308 }
00309
00310 #endif