xref: /phasta/svLS/SOLVE.f (revision 712d3df0b59ebebaaeaea358162c8d2c043c6e08)
1*1e99f302SBen Matthews!     This software is Copyright (c) 2012-2015 The Regents of the
2*1e99f302SBen Matthews!     University of California. All Rights Reserved.
3*1e99f302SBen Matthews!
4*1e99f302SBen Matthews!     Permission to copy and modify this software and its documentation
5*1e99f302SBen Matthews!     for educational, research and non-profit purposes, without fee,
6*1e99f302SBen Matthews!     and without a written agreement is hereby granted, provided that
7*1e99f302SBen Matthews!     the above copyright notice, this paragraph and the following three
8*1e99f302SBen Matthews!     paragraphs appear in all copies.
9*1e99f302SBen Matthews!
10*1e99f302SBen Matthews!     Permission to make commercial use of this software may be obtained
11*1e99f302SBen Matthews!     by contacting:
12*1e99f302SBen Matthews!
13*1e99f302SBen Matthews!     Technology Transfer Office
14*1e99f302SBen Matthews!     9500 Gilman Drive, Mail Code 0910
15*1e99f302SBen Matthews!     University of California
16*1e99f302SBen Matthews!     La Jolla, CA 92093-0910
17*1e99f302SBen Matthews!     (858) 534-5815
18*1e99f302SBen Matthews!     invent@ucsd.edu
19*1e99f302SBen Matthews!
20*1e99f302SBen Matthews!     This software program and documentation are copyrighted by The
21*1e99f302SBen Matthews!     Regents of the University of California. The software program and
22*1e99f302SBen Matthews!     documentation are supplied "as is", without any accompanying
23*1e99f302SBen Matthews!     services from The Regents. The Regents does not warrant that the
24*1e99f302SBen Matthews!     operation of the program will be uninterrupted or error-free. The
25*1e99f302SBen Matthews!     end-user understands that the program was developed for research
26*1e99f302SBen Matthews!     purposes and is advised not to rely exclusively on the program for
27*1e99f302SBen Matthews!     any reason.
28*1e99f302SBen Matthews!
29*1e99f302SBen Matthews!     IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
30*1e99f302SBen Matthews!     PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
31*1e99f302SBen Matthews!     DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
32*1e99f302SBen Matthews!     SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
33*1e99f302SBen Matthews!     CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*1e99f302SBen Matthews!     THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
35*1e99f302SBen Matthews!     WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36*1e99f302SBen Matthews!     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
37*1e99f302SBen Matthews!     SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
38*1e99f302SBen Matthews!     UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
39*1e99f302SBen Matthews!     MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
40*1e99f302SBen Matthews
41*1e99f302SBen Matthews      SUBROUTINE svLS_SOLVE (lhs, ls, dof, Ri, Val, incL, res)
42*1e99f302SBen Matthews
43*1e99f302SBen Matthews      INCLUDE "svLS_STD.h"
44*1e99f302SBen Matthews
45*1e99f302SBen Matthews      TYPE(svLS_lhsType), INTENT(INOUT) :: lhs
46*1e99f302SBen Matthews      TYPE(svLS_lsType), INTENT(INOUT) :: ls
47*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: dof
48*1e99f302SBen Matthews      REAL*8, INTENT(INOUT) :: Ri(dof,lhs%nNo)
49*1e99f302SBen Matthews      REAL*8, INTENT(INOUT) :: Val(dof*dof,lhs%nnz)
50*1e99f302SBen Matthews      INTEGER, INTENT(IN), OPTIONAL :: incL(lhs%nFaces)
51*1e99f302SBen Matthews      REAL*8, INTENT(IN), OPTIONAL :: res(lhs%nFaces)
52*1e99f302SBen Matthews
53*1e99f302SBen Matthews      LOGICAL flag
54*1e99f302SBen Matthews      INTEGER faIn, a, nNo, nnz, nFaces
55*1e99f302SBen Matthews      REAL*8, ALLOCATABLE :: R(:,:), W(:,:)
56*1e99f302SBen Matthews
57*1e99f302SBen Matthews      nNo    = lhs%nNo
58*1e99f302SBen Matthews      nnz    = lhs%nnz
59*1e99f302SBen Matthews      nFaces = lhs%nFaces
60*1e99f302SBen Matthews
61*1e99f302SBen Matthews      IF (lhs%nFaces .NE. 0) THEN
62*1e99f302SBen Matthews         lhs%face%incFlag = .TRUE.
63*1e99f302SBen Matthews         IF (PRESENT(incL)) THEN
64*1e99f302SBen Matthews            DO faIn=1, lhs%nFaces
65*1e99f302SBen Matthews               IF (incL(faIn) .EQ. 0) lhs%face(faIn)%incFlag = .FALSE.
66*1e99f302SBen Matthews            END DO
67*1e99f302SBen Matthews         END IF
68*1e99f302SBen Matthews
69*1e99f302SBen Matthews         flag = ANY(lhs%face%bGrp.EQ.BC_TYPE_Neu)
70*1e99f302SBen Matthews         IF (.NOT.PRESENT(res) .AND. flag) THEN
71*1e99f302SBen Matthews            PRINT *, "res is required when there is a Neu surface"
72*1e99f302SBen Matthews         END IF
73*1e99f302SBen Matthews         DO faIn=1, lhs%nFaces
74*1e99f302SBen Matthews            lhs%face(faIn)%coupledFlag = .FALSE.
75*1e99f302SBen Matthews            IF (.NOT.lhs%face(faIn)%incFlag) CYCLE
76*1e99f302SBen Matthews            flag = lhs%face(faIn)%bGrp .EQ. BC_TYPE_Neu
77*1e99f302SBen Matthews            IF (flag .AND. res(faIn).NE.0D0) THEN
78*1e99f302SBen Matthews               lhs%face(faIn)%res = res(faIn)
79*1e99f302SBen Matthews               lhs%face(faIn)%coupledFlag = .TRUE.
80*1e99f302SBen Matthews            END IF
81*1e99f302SBen Matthews         END DO
82*1e99f302SBen Matthews      END IF
83*1e99f302SBen Matthews
84*1e99f302SBen Matthews      ALLOCATE(R(dof,nNo), W(dof,nNo))
85*1e99f302SBen Matthews      DO a=1, nNo
86*1e99f302SBen Matthews         R(:,lhs%map(a)) = Ri(:,a)
87*1e99f302SBen Matthews      END DO
88*1e99f302SBen Matthews
89*1e99f302SBen Matthews      CALL COMMUV(dof, nNo, lhs%commu, lhs%cS, R)
90*1e99f302SBen Matthews      CALL PRECOND(nFaces, dof, nNo, nnz, lhs%commu, lhs%cS,
91*1e99f302SBen Matthews     2   lhs%face, lhs%rowPtr, lhs%colPtr, lhs%diagPtr, Val, R, W)
92*1e99f302SBen Matthews
93*1e99f302SBen Matthews      SELECT CASE (ls%LS_type)
94*1e99f302SBen Matthews         CASE (LS_TYPE_NS)
95*1e99f302SBen Matthews            CALL NSSOLVER(nFaces, lhs%gnNo, dof, nNo, nnz, lhs%mynNo,
96*1e99f302SBen Matthews     2         lhs%commu, lhs%cS, lhs%face, ls, lhs%rowPtr, lhs%colPtr,
97*1e99f302SBen Matthews     3         Val, R)
98*1e99f302SBen Matthews         CASE (LS_TYPE_GMRES)
99*1e99f302SBen Matthews            CALL GMRESV(nFaces, dof, nNo, nnz, lhs%mynNo, lhs%commu,
100*1e99f302SBen Matthews     2         lhs%cS, lhs%face, ls%RI, lhs%rowPtr, lhs%colPtr, Val, R)
101*1e99f302SBen Matthews         CASE (LS_TYPE_CG)
102*1e99f302SBen Matthews            IF (dof .EQ. 1) THEN
103*1e99f302SBen Matthews               CALL CGRADS(nNo, nnz, lhs%mynNo, lhs%commu, lhs%cS,
104*1e99f302SBen Matthews     2            ls%RI, lhs%rowPtr, lhs%colPtr, Val, R)
105*1e99f302SBen Matthews            ELSE
106*1e99f302SBen Matthews               CALL CGRADV(dof, nNo, nnz, lhs%mynNo, lhs%commu, lhs%cS,
107*1e99f302SBen Matthews     2            ls%RI, lhs%rowPtr, lhs%colPtr, Val, R)
108*1e99f302SBen Matthews            END IF
109*1e99f302SBen Matthews         CASE DEFAULT
110*1e99f302SBen Matthews            PRINT *, 'LS_type not defined'
111*1e99f302SBen Matthews            STOP
112*1e99f302SBen Matthews      END SELECT
113*1e99f302SBen Matthews      R = R*W
114*1e99f302SBen Matthews
115*1e99f302SBen Matthews      DO a=1, nNo
116*1e99f302SBen Matthews         Ri(:,a) = R(:,lhs%map(a))
117*1e99f302SBen Matthews      END DO
118*1e99f302SBen Matthews
119*1e99f302SBen Matthews      DEALLOCATE(R, W)
120*1e99f302SBen Matthews
121*1e99f302SBen Matthews      RETURN
122*1e99f302SBen Matthews      END SUBROUTINE svLS_SOLVE
123*1e99f302SBen Matthews
124