2
! A small program for constructing local matrices
3
! Useful for doing linear analyses on mixed elements etc.
10
!use global_parameters, only : current_debug_level, PYTHON_FUNC_LEN
14
integer :: degree, quad_degree=6
15
type(quadrature_type), target :: quad,f_quad
16
type(element_type), target :: X_shape, u_shape, h_shape
17
real, allocatable, dimension(:,:) :: X_ele
18
character(len=100) :: tmpbuf
19
! Arguments for handling the command line
20
character(len=256) :: filename
21
integer :: status, ele
22
character(len=100) :: fmt,buffer,buf
23
integer :: u_degree=1, h_degree=2, dim=1, simplex_type=1
26
!1. Equilateral, unit. 2. Right-angled, unit.
28
namelist/LocalMats_data/u_degree,h_degree,dim,simplex_type, quad_degree
29
logical :: file_exists
30
integer :: unit, io1, stat
32
!current_debug_level = 2
34
print *, 'program LocalMats'
36
call get_command_argument(1, value=filename, status=status)
39
print *, 'no file specified?'
42
write(0,*) "Warning: truncating filename"
44
filename=trim(filename)
46
print *, 'Reading parameters'
49
open(unit=unit, file=trim(trim(filename)//".dat"), status='old', &
53
print *, 'Looked for ', trim(trim(filename)//".dat")
54
print *, 'Could not read from .dat file'
58
read(unit, LocalMats_data)
61
print *, 'Making local matrices for an element with'
62
print *, 'Dimension == ', dim
63
print *, 'U degree = ', u_degree
64
print *, 'H degree = ', h_degree
65
print *, 'simplex type = ',simplex_type
66
print *, 'Quad degree =', quad_degree
68
print *, 'Getting quadrature'
70
quad=make_quadrature(loc=dim+1, dimension=dim, degree=quad_degree)
72
print *, 'Getting shape functions'
74
! Shape functions for positions (linear)
75
X_shape=make_element_shape(loc=dim+1, dimension=dim, &
78
! Shape functions for velocity and height
79
u_shape=make_element_shape(loc=dim+1, &
80
dimension=dim, degree=u_degree, quad=quad)
81
h_shape=make_element_shape(loc=dim+1, &
82
dimension=dim, degree=h_degree, quad=quad)
84
allocate(X_ele(u_shape%dim,x_shape%loc))
86
call get_X_ele(X_ele,simplex_type)
88
print *, 'Coordinates'
91
call assemble_local_matrices(u_shape,h_shape,X_shape,X_ele)
95
subroutine assemble_local_matrices( &
96
u_shape,h_shape,X_shape,X_ele)
97
type(element_type), intent(in) :: u_shape,h_shape,X_shape
98
real, dimension(u_shape%dim,x_shape%loc), intent(in) :: X_ele
101
! Coordinate transform * quadrature weights.
102
real, dimension(u_shape%ngi) :: detwei
103
! Derivatives of shape function:
104
real, dimension(h_shape%loc, h_shape%ngi, h_shape%dim) :: h_dshape
106
real, dimension(u_shape%dim,h_shape%loc,u_shape%loc) :: grad_mat
107
real, dimension(u_shape%loc,u_shape%loc) :: u_mass_mat
108
real, dimension(h_shape%loc,h_shape%loc) :: lap_mat,h_mass_mat
109
integer :: idim, iloc
111
! Transform derivatives and weights into physical space.
112
call transform_to_physical(X_ele, X_shape, m=h_shape, &
113
dm_t=h_dshape, detwei=detwei)
115
grad_mat = -dshape_shape(h_dshape,u_shape,detwei)
116
lap_mat = dshape_dot_dshape(h_dshape,h_dshape,detwei)
117
u_mass_mat = shape_shape(u_shape,u_shape,detwei)
118
h_mass_mat = shape_shape(h_shape,h_shape,detwei)
120
print *, 'U Mass Matrix'
122
do iloc = 1, u_shape%loc
123
print *, u_mass_mat(iloc,:)
126
print *, 'H mass matrix'
127
do iloc = 1, h_shape%loc
128
print *, h_mass_mat(iloc,:)
131
print *, 'Div matrix'
132
do idim = 1, u_shape%dim
133
do iloc = 1, h_shape%loc
134
print *, grad_mat(idim,iloc,:)
139
print *, 'Laplacian matrix'
140
do iloc = 1, h_shape%loc
141
print *, lap_mat(iloc,:)
144
end subroutine assemble_local_matrices
146
subroutine get_X_ele(X_ele,simplex_type)
147
real, dimension(:,:), intent(inout) :: X_ele
148
integer, intent(in) :: simplex_type
151
select case(size(X_ele,1))
153
X_ele(1,:) = (/ 0.0, 1.0 /)
155
select case(simplex_type)
157
X_ele(1,:) = (/ 0.0, 1.0, 0.5 /)
158
X_ele(2,:) = (/ 0.0, 0.0, 0.8660254037844386 /)
160
X_ele(1,:) = (/ 0.0, 1.0, 1.0 /)
161
X_ele(2,:) = (/ 0.0, 0.0, 1.0 /)
163
print *, 'no support for simplex type, try coding it?'
167
print *, 'no support for dimension, try coding it?'
171
end subroutine get_X_ele
172
end program LOCALMATS