BasisFunction.cc 3.88 KB
 Peter Gottschling committed Feb 15, 2008 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 ``````#include #include "FixVec.h" #include "DOFVector.h" #include "BasisFunction.h" #include "Lagrange.h" namespace AMDiS { /****************************************************************************/ /* Lagrangian basisfunctions of order 0-4; these */ /* functions are evaluated in barycentric coordinates; the derivatives */ /* are those corresponding to these barycentric coordinates. */ /****************************************************************************/ BasisFunction::~BasisFunction() { DELETE nDOF; } BasisFunction::BasisFunction(const ::std::string& name_, int dim_, int degree_) : name(name_), degree(degree_), dim(dim_) { FUNCNAME("BasisFunction::BasisFunction()"); nDOF = NEW DimVec(dim, DEFAULT_VALUE, -1); }; /****************************************************************************/ /* some routines for evaluation of a finite element function, its gradient */ /* and second derivatives; all those with _fast use the preevaluated */ /* basis functions at that point. */ /****************************************************************************/ double BasisFunction::evalUh(const DimVec& lambda, const double *uh_loc) const { double val = 0.0; for (int i = 0; i < nBasFcts; i++) val += uh_loc[i] * (*(*phi)[i])(lambda); return(val); } `````` Thomas Witkowski committed Mar 05, 2008 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 `````` const WorldVector& BasisFunction::evalUh(const DimVec& lambda, const WorldVector *uh_loc, WorldVector* values) const { static WorldVector Values(DEFAULT_VALUE, 0.); WorldVector *val = (NULL != values) ? values : &Values; int dow = Global::getGeo(WORLD); for (int n = 0; n < dow; n++) (*val)[n] = 0; for (int i = 0; i < nBasFcts; i++) { double phil = (*(*phi)[i])(lambda); for (int n = 0; n < dow; n++) (*val)[n] += uh_loc[i][n] * phil; } return((*val)); } `````` Peter Gottschling committed Feb 15, 2008 70 71 `````` const WorldVector& BasisFunction::evalGrdUh(const DimVec& lambda, const DimVec >& grd_lambda, `````` Thomas Witkowski committed Jun 20, 2008 72 73 `````` const double *uh_loc, WorldVector* grd_uh) const `````` Peter Gottschling committed Feb 15, 2008 74 `````` { `````` Thomas Witkowski committed Jun 20, 2008 75 `````` static WorldVector grd; `````` Peter Gottschling committed Feb 15, 2008 76 `````` `````` Thomas Witkowski committed Jun 20, 2008 77 78 `````` DimVec grd_b(dim, DEFAULT_VALUE, 0.0); WorldVector *val; `````` Peter Gottschling committed Feb 15, 2008 79 80 81 82 83 84 85 86 `````` DimVec grd1(dim, DEFAULT_VALUE, 0.); val = grd_uh ? grd_uh : &grd; for (int j = 0; j < dim + 1; j++) grd1[j] = 0.0; for (int i = 0; i < nBasFcts; i++) { `````` Thomas Witkowski committed Jun 20, 2008 87 88 `````` (*(*grdPhi)[i])(lambda, grd_b); `````` Peter Gottschling committed Feb 15, 2008 89 90 91 92 93 94 95 96 97 98 99 100 `````` for (int j = 0; j < dim + 1; j++) grd1[j] += uh_loc[i] * grd_b[j]; } int dow = Global::getGeo(WORLD); for (int i = 0; i < dow; i++) { (*val)[i] = 0; for (int j = 0; j < dim + 1; j++) (*val)[i] += grd_lambda[j][i] * grd1[j]; } `````` Thomas Witkowski committed Jun 20, 2008 101 `````` return ((*val)); `````` Peter Gottschling committed Feb 15, 2008 102 103 104 105 106 107 108 `````` } const WorldMatrix& BasisFunction::evalD2Uh(const DimVec& lambda, const DimVec >& grd_lambda, const double *uh_loc, WorldMatrix* D2_uh) const { static WorldMatrix D2(DEFAULT_VALUE, 0.); `````` Thomas Witkowski committed Jun 20, 2008 109 `````` DimMat D2_b(dim, DEFAULT_VALUE, 0.0); `````` Peter Gottschling committed Feb 15, 2008 110 `````` DimMat D2_tmp(dim, DEFAULT_VALUE, 0.0); `````` Thomas Witkowski committed Jun 20, 2008 111 `````` WorldMatrix *val = D2_uh ? D2_uh : &D2; `````` Peter Gottschling committed Feb 15, 2008 112 113 `````` for (int i = 0; i < nBasFcts; i++) { `````` Thomas Witkowski committed Jun 20, 2008 114 `````` (*(*d2Phi)[i])(lambda, D2_b); `````` Peter Gottschling committed Feb 15, 2008 115 116 117 118 119 120 121 122 123 124 `````` for (int k = 0; k < dim + 1; k++) for (int l = 0; l < dim + 1; l++) D2_tmp[k][l] += uh_loc[i] * D2_b[k][l]; } int dow = Global::getGeo(WORLD); for (int i = 0; i < dow; i++) for (int j = 0; j < dow; j++) { (*val)[i][j] = 0.0; `````` Thomas Witkowski committed Jun 20, 2008 125 126 `````` for (int k = 0; k < dim + 1; k++) for (int l = 0; l < dim + 1; l++) `````` Peter Gottschling committed Feb 15, 2008 127 128 129 `````` (*val)[i][j] += grd_lambda[k][i] * grd_lambda[l][j] * D2_tmp[k][l]; } `````` Thomas Witkowski committed Jun 20, 2008 130 `````` return ((*val)); `````` Peter Gottschling committed Feb 15, 2008 131 132 133 134 135 136 137 138 139 `````` } int BasisFunction::getNumberOfDOFs(int i) const { return (*nDOF)[i]; } }``````