Two- and three-dimensional P1 finite element assembly