Research Article

Finite Element Assembly Using an Embedded Domain Specific Language

Listing 13

Element type for first order line elements of the Lagrange family.
(/// 1D Line shape function
()  struct line1d
()  {
()   static const int nb_nodes = 2; // Number of nodes
()   static const int dimension = 1;
()  
()   // Type of the mapped coordinates
()   typedef Eigen::Matrix<double, 1, dimension> coord_t;
()   // Type of the shape function vector
() typedef Eigen::Matrix<double, 1, nb_nodes> shape_func_t;
() // Type of the coordinates matrix
() typedef Eigen::Matrix<double, nb_nodes, dimension> coord_mat_t;
()  
() // Compute the shape function vector at mapped coordinate c
() static shape_func_t shape_function(const coord_t& c)
() {
()  const double xi = c[];
()  shape_func_t result;
()  result[] = 0.5*(1.xi);
()  result[] = 0.5*(1.+xi);
()  return result;
() }
()  
() // Compute the jacobian determinant
() static double jacobian_determinant(const coord_t& mapped_coord, const coord_mat_t&
     node_coords)
() {
()  return 0.5*(node_coords[] node_coords[]);
() }
()  
() static const int nb_gauss_points = 2;
() // Type of the matrix with the Gauss points
() typedef Eigen::Matrix<double, nb_gauss_points, 1> gauss_points_t;
() // The Gauss points for the current shape function (definition omitted)
() static const gauss_points_t gauss_points();
() // Type for the weights
() typedef Eigen::Matrix<double, nb_gauss_points, 1> gauss_weights_t;
() // The Gauss weights (definition omitted)
() static const gauss_weights_t gauss_weights();
() };