1!
2!     CalculiX - A 3-dimensional finite element program
3!              Copyright (C) 1998-2021 Guido Dhondt
4!
5!     This program is free software; you can redistribute it and/or
6!     modify it under the terms of the GNU General Public License as
7!     published by the Free Software Foundation(version 2);
8!
9!
10!     This program is distributed in the hope that it will be useful,
11!     but WITHOUT ANY WARRANTY; without even the implied warranty of
12!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13!     GNU General Public License for more details.
14!
15!     You should have received a copy of the GNU General Public License
16!     along with this program; if not, write to the Free Software
17!     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18!
19      subroutine catedges_refine(netet_,iedg,kontet,ipoed,ifreeed,
20     &  iedtet,ipoeled,ieled,ifreele)
21!
22!     catalogueing the edges of the tetrahedral elements of the mesh
23!
24      implicit none
25!
26      integer i,j,netet_,iedg(3,*),kontet(4,*),nodee(2),ie(2,6),n,
27     &  node,index,ipoed(*),ifreeed,iedtet(6,*),
28     &  ieled(2,*),iedge,ifreele,ipoeled(*)
29!
30!     nodes belonging to the six edges
31!
32      data ie /1,2,2,3,1,3,1,4,2,4,3,4/
33!
34!     initialization of ipoed and iedg
35!
36      do i=1,6*netet_
37         iedg(3,i)=i+1
38      enddo
39      iedg(3,6*netet_)=0
40!
41!     setting up the edge databank
42!
43      do j=1,netet_
44         if(kontet(1,j).eq.0) cycle
45!
46!        loop over all edges per tet
47!
48         do i=1,6
49            nodee(1)=kontet(ie(1,i),j)
50            nodee(2)=kontet(ie(2,i),j)
51            n=2
52c            kflag=1
53            call insertsorti(nodee,n)
54c            call isortii(nodee,idum,n,kflag)
55!
56!           check whether edge is already catalogued
57!
58            node=nodee(1)
59            index=ipoed(node)
60!
61            do
62               if(index.eq.0) exit
63               if(iedg(2,index).eq.nodee(2)) exit
64               index=iedg(3,index)
65            enddo
66!
67            if(index.eq.0) then
68               index=ifreeed
69               ifreeed=iedg(3,ifreeed)
70               if(ifreeed.eq.0) then
71                  write(*,*) '*ERROR in catedges: increase'
72                  write(*,*) '       the dimension of iedg'
73                  call exit(201)
74               endif
75               iedg(1,index)=nodee(1)
76               iedg(2,index)=nodee(2)
77               iedg(3,index)=ipoed(node)
78               ipoed(node)=index
79            endif
80            iedtet(i,j)=index
81         enddo
82      enddo
83!
84!     initialization of ieled
85!
86      do i=1,6*netet_
87         ieled(2,i)=i+1
88      enddo
89      ieled(2,6*netet_)=0
90!
91!     generating the element per edge relationship
92!
93      do j=1,netet_
94         if(kontet(1,j).eq.0) cycle
95         do i=1,6
96            iedge=iedtet(i,j)
97            index=ifreele
98            ieled(1,index)=j
99            ifreele=ieled(2,index)
100            if(ifreele.eq.0) then
101               write(*,*) '*ERROR in catedges: increase the'
102               write(*,*) '       dimension of ieln'
103               call exit(201)
104            endif
105            ieled(2,index)=ipoeled(iedge)
106            ipoeled(iedge)=index
107         enddo
108      enddo
109!
110      return
111      end
112
113