xref: /phasta/svLS/LS.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_LS_CREATE(ls, LS_type, relTol, absTol, maxItr,
42*1e99f302SBen Matthews     2   dimKry, relTolIn, absTolIn, maxItrIn)
43*1e99f302SBen Matthews
44*1e99f302SBen Matthews      INCLUDE "svLS_STD.h"
45*1e99f302SBen Matthews
46*1e99f302SBen Matthews      TYPE(svLS_lsType), INTENT(INOUT) :: ls
47*1e99f302SBen Matthews      INTEGER, INTENT(IN) :: LS_type
48*1e99f302SBen Matthews      REAL*8, INTENT(IN), OPTIONAL :: relTol, absTol, relTolIn(2),
49*1e99f302SBen Matthews     2   absTolIn(2)
50*1e99f302SBen Matthews      INTEGER, INTENT(IN), OPTIONAL :: maxItr, dimKry, maxItrIn(2)
51*1e99f302SBen Matthews
52*1e99f302SBen Matthews      IF (ls%foC) THEN
53*1e99f302SBen Matthews         PRINT *, "LS is not free"
54*1e99f302SBen Matthews         PRINT *, "You may use svLS_LS_FREE to free this structure"
55*1e99f302SBen Matthews      END IF
56*1e99f302SBen Matthews
57*1e99f302SBen Matthews      ls%foC     = .TRUE.
58*1e99f302SBen Matthews      ls%LS_type = LS_type
59*1e99f302SBen Matthews
60*1e99f302SBen Matthews      SELECT CASE (LS_type)
61*1e99f302SBen Matthews         CASE (LS_TYPE_NS)
62*1e99f302SBen Matthews            ls%RI%relTol = 4D-1
63*1e99f302SBen Matthews            ls%GM%relTol = 1D-2
64*1e99f302SBen Matthews            ls%CG%relTol = 1D-1
65*1e99f302SBen Matthews            ls%RI%mItr = 10
66*1e99f302SBen Matthews            ls%GM%mItr = 3
67*1e99f302SBen Matthews            ls%CG%mItr = 500
68*1e99f302SBen Matthews            ls%GM%sD   = 50
69*1e99f302SBen Matthews         CASE (LS_TYPE_GMRES)
70*1e99f302SBen Matthews            ls%RI%relTol = 1D-2
71*1e99f302SBen Matthews            ls%RI%mItr   = 2
72*1e99f302SBen Matthews            ls%RI%sD     = 150
73*1e99f302SBen Matthews         CASE (LS_TYPE_CG)
74*1e99f302SBen Matthews            ls%RI%reltol = 1D-4
75*1e99f302SBen Matthews            ls%RI%mItr   = 1000
76*1e99f302SBen Matthews         CASE DEFAULT
77*1e99f302SBen Matthews            PRINT *, 'Solver type LS_TYPE is not defined'
78*1e99f302SBen Matthews            STOP
79*1e99f302SBen Matthews      END SELECT
80*1e99f302SBen Matthews      ls%RI%absTol = 1D-10
81*1e99f302SBen Matthews      ls%GM%absTol = 1D-10
82*1e99f302SBen Matthews      ls%CG%absTol = 1D-10
83*1e99f302SBen Matthews
84*1e99f302SBen Matthews      IF (PRESENT(relTol)) ls%RI%relTol = relTol
85*1e99f302SBen Matthews      IF (PRESENT(absTol)) ls%RI%absTol = absTol
86*1e99f302SBen Matthews      IF (PRESENT(maxItr)) ls%RI%mItr   = maxItr
87*1e99f302SBen Matthews
88*1e99f302SBen Matthews      IF (PRESENT(dimKry)) THEN
89*1e99f302SBen Matthews         ls%RI%sD = dimKry
90*1e99f302SBen Matthews         ls%GM%sD = dimKry
91*1e99f302SBen Matthews      END IF
92*1e99f302SBen Matthews      IF (PRESENT(relTolIn)) THEN
93*1e99f302SBen Matthews         ls%GM%relTol = relTolIn(1)
94*1e99f302SBen Matthews         ls%CG%relTol = relTolIn(2)
95*1e99f302SBen Matthews      END IF
96*1e99f302SBen Matthews      IF (PRESENT(absTolIn)) THEN
97*1e99f302SBen Matthews         ls%GM%absTol = absTolIn(1)
98*1e99f302SBen Matthews         ls%CG%absTol = absTolIn(2)
99*1e99f302SBen Matthews      END IF
100*1e99f302SBen Matthews      IF (PRESENT(maxItrIn)) THEN
101*1e99f302SBen Matthews         ls%GM%mItr = maxItrIn(1)
102*1e99f302SBen Matthews         ls%CG%mItr = maxItrIn(2)
103*1e99f302SBen Matthews      END IF
104*1e99f302SBen Matthews
105*1e99f302SBen Matthews      RETURN
106*1e99f302SBen Matthews      END SUBROUTINE svLS_LS_CREATE
107*1e99f302SBen Matthews
108*1e99f302SBen Matthews!====================================================================
109*1e99f302SBen Matthews
110*1e99f302SBen Matthews      SUBROUTINE svLS_LS_FREE (ls)
111*1e99f302SBen Matthews
112*1e99f302SBen Matthews      INCLUDE "svLS_STD.h"
113*1e99f302SBen Matthews
114*1e99f302SBen Matthews      TYPE(svLS_lsType), INTENT(INOUT) :: ls
115*1e99f302SBen Matthews
116*1e99f302SBen Matthews      IF (.NOT.ls%foC) THEN
117*1e99f302SBen Matthews         PRINT *, 'Cannot free LS'
118*1e99f302SBen Matthews         PRINT *, 'It is not created yet'
119*1e99f302SBen Matthews         STOP
120*1e99f302SBen Matthews      END IF
121*1e99f302SBen Matthews      ls%foC  = .FALSE.
122*1e99f302SBen Matthews
123*1e99f302SBen Matthews      RETURN
124*1e99f302SBen Matthews      END SUBROUTINE svLS_LS_FREE
125*1e99f302SBen Matthews
126