FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_estimate_condition.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! Copyright (c) 2019 FrontISTR Commons
3 ! This software is released under the MIT License, see LICENSE.txt
4 !-------------------------------------------------------------------------------
5 
7 
8  private
11 
12 contains
13 
14  subroutine hecmw_estimate_condition_cg(ITER, D, E)
16  implicit none
17  integer(kind=kint), intent(in) :: iter
18  real(kind=kreal), intent(in) :: d(:), e(:)
19 
20 #ifdef HECMW_WITH_LAPACK
21  character(len=1) :: jobz, range
22  ! character(len=1) :: COMPZ
23  real(kind=kreal) :: vl, vu, abstol, z(1,1)
24  integer(kind=kint) :: n, il, iu, m, ldz=1, isuppz(1)
25  integer(kind=kint) :: lwork, liwork, info
26  real(kind=kreal), allocatable :: w(:), work(:)
27  integer(kind=kint), allocatable :: iwork(:)
28  real(kind=kreal), allocatable :: d1(:), e1(:)
29  integer(kind=kint) :: i
30 
31  if (iter <= 1) return
32 
33  ! copy D, E
34  allocate(d1(iter),e1(iter))
35  do i=1,iter-1
36  d1(i) = d(i)
37  e1(i) = e(i)
38  enddo
39  d1(iter) = d(iter)
40 
41 
42  !!
43  !! dstegr version (faster than dsteqr)
44  !!
45 
46  ! prepare arguments for calling dstegr
47  jobz='N'
48  range='A'
49  n=iter
50  allocate(w(iter))
51  ! estimate optimal LWORK and LIWORK
52  lwork=-1
53  liwork=-1
54  allocate(work(1),iwork(1))
55  call dstegr(jobz,range,n,d1,e1,vl,vu,il,iu,abstol, &
56  m,w,z,ldz,isuppz,work,lwork,iwork,liwork,info)
57  if (info /= 0) then
58  write(*,*) 'ERROR: dstegr returned with INFO=',info
59  return
60  endif
61  ! calculate eigenvalues
62  lwork=work(1)
63  liwork=iwork(1)
64  deallocate(work,iwork)
65  allocate(work(lwork),iwork(liwork))
66  call dstegr(jobz,range,n,d1,e1,vl,vu,il,iu,abstol, &
67  m,w,z,ldz,isuppz,work,lwork,iwork,liwork,info)
68  if (info /= 0) then
69  write(*,*) 'ERROR: dstegr returned with INFO=',info
70  return
71  endif
72  write(*,'("emin=",1pe13.6,", emax=",1pe13.6,", emax/emin=",1pe13.6)') &
73  w(1),w(n),w(n)/w(1)
74  deallocate(work,iwork)
75  deallocate(w)
76 
77 
78  ! !!
79  ! !! dsteqr version
80  ! !!
81 
82  ! ! prepare arguments for calling dsteqr
83  ! COMPZ='N'
84  ! N=ITER
85  ! allocate(WORK(1))
86  ! ! calculate eigenvalues
87  ! call dsteqr(COMPZ,N,D1,E1,Z,LDZ,WORK,INFO)
88  ! if (INFO /= 0) then
89  ! write(*,*) 'ERROR: dsteqr returned with INFO=',INFO
90  ! return
91  ! endif
92  ! write(*,'("emin=",1pe13.6,", emax=",1pe13.6,", emax/emin=",1pe13.6)') &
93  ! D1(1),D1(N),D1(N)/D1(1)
94  ! deallocate(WORK)
95 
96 
97  deallocate(d1,e1)
98 #endif
99  end subroutine hecmw_estimate_condition_cg
100 
101 
102  subroutine hecmw_estimate_condition_gmres(I, H)
104  implicit none
105  integer(kind=kint), intent(in) :: i
106  real(kind=kreal), intent(in) :: h(:,:)
107 
108 #ifdef HECMW_WITH_LAPACK
109  ! character(len=1) :: JOBU, JOBVT
110  character(len=1) :: jobz
111  integer(kind=kint) :: n, ldh, ldz=1, lwork, info
112  real(kind=kreal), allocatable :: wr(:), work(:), h1(:,:)
113  integer(kind=kint), allocatable :: iwork(:)
114  real(kind=kreal) :: z(1,1)
115  integer(kind=kint) :: j, k
116 
117  if (i == 0) return
118 
119  ! copy H
120  n=i
121  allocate(h1(n+1,n))
122  do j = 1, n
123  do k = 1, j+1
124  h1(k,j) = h(k,j)
125  enddo
126  do k = j+2, n
127  h1(k,j) = 0.d0
128  enddo
129  enddo
130  ldh=n+1
131  allocate(wr(n))
132 
133 
134  ! !!
135  ! !! dgesvd version
136  ! !!
137 
138  ! ! arguments for calling dgesvd
139  ! JOBU='N'
140  ! JOBVT='N'
141  ! ! estimate optimal LWORK
142  ! allocate(WORK(1))
143  ! LWORK=-1
144  ! call dgesvd(JOBU,JOBVT,N,N,H1,LDH,WR,Z,LDZ,Z,LDZ,WORK,LWORK,INFO)
145  ! if (INFO /= 0) then
146  ! write(*,*) 'ERROR: dgesvd returned with INFO=',INFO
147  ! return
148  ! endif
149  ! ! calculate singular values
150  ! LWORK=WORK(1)
151  ! deallocate(WORK)
152  ! allocate(WORK(LWORK))
153  ! call dgesvd(JOBU,JOBVT,N,N,H1,LDH,WR,Z,LDZ,Z,LDZ,WORK,LWORK,INFO)
154  ! if (INFO /= 0) then
155  ! write(*,*) 'ERROR: dgesvd returned with INFO=',INFO
156  ! return
157  ! endif
158  ! deallocate(WORK)
159 
160 
161  !!
162  !! dgesdd version (faster but need more workspace than dgesvd)
163  !!
164 
165  ! arguments for calling dgesdd
166  jobz='N'
167  allocate(iwork(8*n))
168  ! estimate optimal LWORK
169  allocate(work(1))
170  lwork=-1
171  call dgesdd(jobz,n,n,h1,ldh,wr,z,ldz,z,ldz,work,lwork,iwork,info)
172  if (info /= 0) then
173  write(*,*) 'ERROR: dgesdd returned with INFO=',info
174  return
175  endif
176  ! calculate singular values
177  lwork=work(1)
178  deallocate(work)
179  allocate(work(lwork))
180  call dgesdd(jobz,n,n,h1,ldh,wr,z,ldz,z,ldz,work,lwork,iwork,info)
181  if (info /= 0) then
182  write(*,*) 'ERROR: dgesdd returned with INFO=',info
183  return
184  endif
185  deallocate(work)
186  deallocate(iwork)
187 
188 
189  write(*,'("emin=",1pe13.6,", emax=",1pe13.6,", emax/emin=",1pe13.6)') &
190  wr(n), wr(1), wr(1)/wr(n)
191 
192  deallocate(wr)
193  deallocate(h1)
194 #endif
195  end subroutine hecmw_estimate_condition_gmres
196 
197 end module hecmw_estimate_condition
hecmw_estimate_condition::hecmw_estimate_condition_cg
subroutine, public hecmw_estimate_condition_cg(ITER, D, E)
Definition: hecmw_estimate_condition.F90:15
hecmw_util
I/O and Utility.
Definition: hecmw_util_f.F90:7
hecmw_estimate_condition
Definition: hecmw_estimate_condition.F90:6
hecmw_util::kreal
integer(kind=4), parameter kreal
Definition: hecmw_util_f.F90:16
hecmw_estimate_condition::hecmw_estimate_condition_gmres
subroutine, public hecmw_estimate_condition_gmres(I, H)
Definition: hecmw_estimate_condition.F90:103