/* An example of a program solving -(ku')' + cu = f in the 1D interval [0,l] using linear finite elements. */ #include #include #include "math.h" //Include our own previously written code... // in general we will be using iterative solvers, // but for this particular example (since we're // assembling the full global matrix) we'll use // the Gaussian Elimination direct solver that // we have written for Math609. #include "gaussian.cc" int n = 20; double l = 1; double h = l/n; // Include a file with functions describing the Lagrangian // finite elements. #include "1d_lagrangian.cc" // Include a file with various quadratures (currently only // the Simpson's rule and a 5 point Gaussian for the unit // interval are implemented). #include "quadrature.cc" /************************* The Coefficients ************************/ double S = 100; double q = 200; double D = 8.8*pow(10,7); double k(double x) { return 1; } double c(double x) { return 4; } double f(double x) { return -120*x*x+40*x*x*x*x; } // an expected solution (used to check our approximation) double sol(double x) { return 10*x*x*x*x; } /************************* The Main Code ************************/ int main() { int global_dofs = n+1+n*(DEGREE-1); double** A = new double*[global_dofs]; double* b = new double[global_dofs]; Create_Quadratures(); Quadrature *quad = &FIVE_POINT_GAUSS; //create the empty matrix and rhs for (int i=0; isize; l++) { // get the values of the point and the weight double q_point = map_to_FE(quad->points[l], ele); double q_weight = quad->weights[l]; for (int i=0; i