| 1 | !> Module that handles data from 'triangle' program output |
|---|
| 2 | module triangle_mod |
|---|
| 3 | use Mesh_class |
|---|
| 4 | use read_triangle_data_mod |
|---|
| 5 | |
|---|
| 6 | contains |
|---|
| 7 | subroutine triangle_to_mesh(td, M) |
|---|
| 8 | implicit none |
|---|
| 9 | type(triangle_data), intent(in) :: td |
|---|
| 10 | type(Mesh), intent(out) :: M |
|---|
| 11 | |
|---|
| 12 | integer :: i,j,k |
|---|
| 13 | integer, allocatable :: all2freeMap(:) ! index map from all nodes to free nodes |
|---|
| 14 | |
|---|
| 15 | M = Mesh_New() |
|---|
| 16 | M%nell = td%ntri |
|---|
| 17 | M%nnode = td%nvert |
|---|
| 18 | M%ngf = count(td%vert_bmark==0)! number of free nodes (i.e. non-fixed nodes) <=nnode |
|---|
| 19 | M%mfrelt = 3 ! max number of free nodes per element (i.e. VERTICES_PER_ELEMENT) |
|---|
| 20 | M%nsd = 2 ! number of spatial dimensions |
|---|
| 21 | |
|---|
| 22 | ! create index map from free nodes to all nodes |
|---|
| 23 | allocate(M%freemap(M%ngf)) |
|---|
| 24 | k = 0 |
|---|
| 25 | do i = 1, M%nnode |
|---|
| 26 | if (td%vert_bmark(i)==0) then |
|---|
| 27 | k = k+1 |
|---|
| 28 | M%freemap(k) = i |
|---|
| 29 | end if |
|---|
| 30 | end do |
|---|
| 31 | |
|---|
| 32 | ! create reverse map |
|---|
| 33 | allocate(all2freeMap(M%nnode)) |
|---|
| 34 | all2freeMap = 0 |
|---|
| 35 | all2freeMap(M%freemap) = (/ (i,i=1,M%ngf) /) |
|---|
| 36 | |
|---|
| 37 | ! copy element info |
|---|
| 38 | allocate(M%nfrelt(M%nell)) ! number of free nodes for each element |
|---|
| 39 | allocate(M%mhead(M%mfrelt,M%nell)) ! free node indices for each element |
|---|
| 40 | |
|---|
| 41 | ! copy triangle vertices (DOUG has 0 as missing) |
|---|
| 42 | M%mhead = 0 |
|---|
| 43 | do i = 1, M%nell |
|---|
| 44 | ! calculate number of free (non-boundary) nodes |
|---|
| 45 | M%nfrelt(i) = count(td%vert_bmark(td%tri_vert(:,i))==0) |
|---|
| 46 | k = 0 |
|---|
| 47 | do j = 1, 3 ! VERTICES_PER_ELEMENT |
|---|
| 48 | ! exclude boundary nodes (treat as fixed) |
|---|
| 49 | if (td%vert_bmark(td%tri_vert(j,i)) == 0) then |
|---|
| 50 | k = k+1 |
|---|
| 51 | M%mhead(k,i) = all2freeMap(td%tri_vert(j,i)) |
|---|
| 52 | end if |
|---|
| 53 | end do |
|---|
| 54 | end do |
|---|
| 55 | |
|---|
| 56 | ! copy coordinates |
|---|
| 57 | allocate(M%coords(M%nsd,M%nnode)) |
|---|
| 58 | do i = 1, M%nnode |
|---|
| 59 | M%coords(1,i) = td%vert_coord(i)%x |
|---|
| 60 | M%coords(2,i) = td%vert_coord(i)%y |
|---|
| 61 | end do |
|---|
| 62 | |
|---|
| 63 | end subroutine triangle_to_mesh |
|---|
| 64 | end module triangle_mod |
|---|