#ifndef _1D_LAGRANGIAN_CC #define _1D_LAGRANGIAN_CC // the degree of the Lagrangian elements. #define DEGREE 4 //mapping from a reference element to a given FE double map_to_FE(double x, int ele) { return ((ele+x)*h); } //mapping from a a given FE to a reference element double map_from_FE(double x, int ele) { return ((x-ele*h)/h); } // the number of local degrees of freedom int dofs_per_element() { return DEGREE+1; } // the mapping of local to global degrees of freedom void fill_element_dofs(int* array, int ele) { for (int i=0; i<=DEGREE; i++) array[i] = DEGREE*ele+i; } //the i-th shape function on the reference element double reference_shape_funct(int index, double x) { double step = 1.0/DEGREE; double result = 1; for (int i=0; i<=DEGREE; i++) if (i!=index) result *= (x-i*step)/(index*step-i*step); return result; } //the x-derivative of the i-th shape function on the reference element double reference_shape_funct_x(int index, double x) { double step = 1.0/DEGREE; double result = 0; for (int i=0; i<=DEGREE; i++) { double prod = 1; if (i==index) continue; for (int j=0; j<=DEGREE; j++) if ((j!=index) && (j!=i)) prod *= (x-j*step)/(index*step-j*step); result += prod / (index*step-i*step); } return result; } // the jacobian of the transformation // (i.e. the change of variables in the integral over an element // to the reference elemen (unit interval)) double jacobian(double q_point, int ele) { return h; } /********* NOTE **********/ // The following two functions are not needed in general, // since we are only working on the reference element. // I've included them here for clarity. double shape_funct(double x, int ele, int index) { return reference_shape_funct(index, map_from_FE(x,ele)); } double shape_funct_x(double x, int ele, int index) { // (1.0/h) = (map_from_FE)' <------------ TODO return reference_shape_funct_x(index, map_from_FE(x,ele))*(1.0/h); } #endif