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 extrapol_pel3(ielfa,xrlfa,icyclic,ifatie,gradpfa,
20     &  gradpel,c,ipnei,xxi,nfacea,nfaceb,ncfd)
21!
22!     interpolate/extrapolate the pressure gradient from the
23!     center of the elements to the center of the faces
24!
25      implicit none
26!
27      integer ielfa(4,*),icyclic,ifatie(*),ipnei(*),nfacea,nfaceb,
28     &  iel1,iel2,i,l,indexf,ncfd
29!
30      real*8 xrlfa(3,*),gradpfa(3,*),gradpel(3,*),c(3,3),xxi(3,*),
31     &  gradnor,xl1,xl2
32!
33!
34!
35      do i=nfacea,nfaceb
36         iel1=ielfa(1,i)
37         xl1=xrlfa(1,i)
38         iel2=ielfa(2,i)
39         if(iel2.gt.0) then
40!
41!           face in between two elements
42!
43            xl2=xrlfa(2,i)
44            if((icyclic.eq.0).or.(ifatie(i).eq.0)) then
45               do l=1,ncfd
46                  gradpfa(l,i)=xl1*gradpel(l,iel1)+
47     &                 xl2*gradpel(l,iel2)
48               enddo
49            elseif(ifatie(i).gt.0) then
50               do l=1,ncfd
51                  gradpfa(l,i)=xl1*gradpel(l,iel1)+xl2*
52     &                  (gradpel(1,iel2)*c(l,1)+
53     &                   gradpel(2,iel2)*c(l,2)+
54     &                   gradpel(3,iel2)*c(l,3))
55               enddo
56            else
57               do l=1,ncfd
58                  gradpfa(l,i)=xl1*gradpel(l,iel1)+xl2*
59     &                  (gradpel(1,iel2)*c(1,l)+
60     &                   gradpel(2,iel2)*c(2,l)+
61     &                   gradpel(3,iel2)*c(3,l))
62               enddo
63            endif
64         elseif(ielfa(3,i).ne.0) then
65!
66!           boundary face; more than one layer; extrapolation
67!
68            do l=1,ncfd
69               gradpfa(l,i)=xl1*gradpel(l,iel1)+
70     &              xrlfa(3,i)*gradpel(l,abs(ielfa(3,i)))
71            enddo
72         else
73!
74!           boundary face; one layer
75!
76            indexf=ipnei(iel1)+ielfa(4,i)
77            gradnor=gradpel(1,iel1)*xxi(1,indexf)+
78     &              gradpel(2,iel1)*xxi(2,indexf)+
79     &              gradpel(3,iel1)*xxi(3,indexf)
80            do l=1,ncfd
81                  gradpfa(l,i)=gradpel(l,iel1)
82     &                        -gradnor*xxi(l,indexf)
83            enddo
84         endif
85      enddo
86!
87      return
88      end
89