# ----------------------------------------------------------------------
# Example 1: Set up the simplest possible mesh by hand so as to see
# the essential elements of a finite element basis
# Specify the three vertices, in counter-clockwise order, for a single
# right triangle
# ----------------------------------------------------------------------
pts <- matrix(c(0, 0, 1, 0, 0, 1),3,2,byrow=TRUE)
# These points also specify the boundary edges by a 3 by 2 matrix
# with each row containing the index of the starting point and of the
# corresponding ending point
edg <- matrix(c(1, 2, 2, 3, 3, 1), 3, 2, byrow=TRUE)
# The triangles are defined by a 1 by 3 matrix specifying the indices
# of the vertices in counter-clockwise order
tri <- matrix(c(1, 2, 3), 1, 3)
# FEM basis objects can be either linear (order 1) or quadratice (order 2)
# both are illustrated here:
# Set up a FEM basis object of order 1 (piecewise linear) basis functions
order <- 1
FEMbasis1 <- create.FEM.basis(pts, edg, tri, order)
# display the number of basis functions
print(paste("Number of basis functions =",FEMbasis1$nbasis))
# plot the basis, the boundary being plotted in red
plotFEM.mesh(pts,tri)
# Set up an FEM basis object of order 2 (piecewise quadratic) basis functions
order <- 2
FEMbasis2 <- create.FEM.basis(pts, edg, tri, order)
# display the number of basis functions
print(paste("Number of basis functions =",FEMbasis2$nbasis))
# plot the basis, the boundary being plotted in red
plotFEM.mesh(pts,tri)
# ----------------------------------------------------------------------
# Example 2: Set up an FEM object with a hexagonal boundary, and a single
# interior point
# ----------------------------------------------------------------------
angle <- seq(0,2*pi,len=7)
x <- cos(angle); y <- sin(angle)
pts <- rbind(cbind(x[1:6], y[1:6]), c(0, 0))
edg <- cbind((1:6),c((2:6), 1))
tri <- matrix(c(7*rep(1,6), 1:6, 2:6, 1),6,3)
hexFEMbasis <- create.FEM.basis(pts, edg, tri)
# display the number of basis functions
print(paste("Number of basis functions =",hexFEMbasis$nbasis))
# plot the basis, the boundary being plotted in red
plotFEM.mesh(pts,tri)
Run the code above in your browser using DataLab