1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
/*@@
@file AHFinder_initguess.F
@date July 1999
@author Miguel Alcubierre
@desc
Find initial guess for minimization algorithm
@enddesc
@@*/
#include "cctk.h"
#include "cctk_Parameters.h"
#include "cctk_Arguments.h"
subroutine AHFinder_initguess(CCTK_ARGUMENTS,rmx)
use AHFinder_dat
implicit none
DECLARE_CCTK_ARGUMENTS
DECLARE_CCTK_PARAMETERS
integer i,j
integer nn0,nn2,min_i,min_j
CCTK_REAL zero,one,cc0,cc2,rmx,aux,min_aa
CCTK_REAL, allocatable, dimension(:,:) :: aa,a0,a2
! Description of variables
!
! i,j Counters.
!
! aa Area array for initial guess.
! a0 c0(0) array for initial guess.
! a2 c0(2) array for initial guess.
!
! rmx Radius of largest sphere that fits in the grid.
!
! nn0 Number of subdivisions of c0(0) for initial guess.
! nn2 Number of subdivisions of c0(2) for initial guess.
! **********************
! *** INITIALIZE ***
! **********************
! define numbers
zero = 0.0D0
one = 1.0D0
aux = rmx
! Initialize arrays.
c0 = zero
cc = zero
cs = zero
cc0 = zero
cc2 = zero
! Get {nn0,nn2}.
nn0 = ahf_nn0
nn2 = ahf_nn0
if (cartoon) nn2 = 0
! Allocate storage.
allocate(aa(0:nn0,0:nn2))
allocate(a0(0:nn0,0:nn2))
allocate(a2(0:nn0,0:nn2))
aa = zero; a0 = zero; a2 = zero
! ****************************
! *** FIND INITIAL GUESS ***
! ****************************
! IMPORTANT: In order to choose a good initial guess,
! I map a section of the space {c0(0),c0(2)} looking
! for a local minimum. This is VERY expensive, so the
! parameter space is not very well convered.
if (veryver.and.(myproc.eq.0)) then
write(*,*)
write(*,*) 'Choosing initial guess ...'
end if
! lmax >= 2 and good guess.
if ((lmax.ge.2).and.(.not.sloppy)) then
do j=0,nn2
c0(2) = (0.5D0*dble(j)/dble(nn2) - 0.25D0)*aux
call AHFinder_fun(CCTK_ARGUMENTS)
call AHFinder_exp(CCTK_ARGUMENTS)
do i=0,nn0
c0(0) = 4.0D0*dx + (aux-4.0D0*dx)*dble(i)/dble(nn0)
a0(i,j) = c0(0)
a2(i,j) = c0(2)
call AHFinder_int(CCTK_ARGUMENTS)
if (minarea) then
aa(i,j) = intarea
else
aa(i,j) = intexp2
end if
if (guessverbose) then
write(*,*)
write(*,"(A12,2ES14.6)") ' a0 and a2: ',a0(i,0),a2(i,0)
write(*,"(A6,ES14.6)") ' H : ',intexp
write(*,"(A6,ES14.6)") ' H^2: ',intexp2
end if
end do
end do
if ((.not.inner).or.(minarea)) then
min_i = 1
min_j = 1
min_aa = 1.0d15
do i=1,nn0-1
do j=1,nn2-1
if ((aa(i,j).gt.zero).and.
. (aa(i,j).lt.aa(i+1,j)).and.
. (aa(i,j).lt.aa(i-1,j)).and.
. (aa(i,j).lt.aa(i,j+1)).and.
. (aa(i,j).lt.aa(i,j-1))) then
cc0 = a0(i,j)
cc2 = a2(i,j)
end if
if (aa(i,j) .le. min_aa) then
min_i = i
min_j = j
min_aa = aa(i,j)
end if
end do
end do
else
min_i = nn0-1
min_j = 1
min_aa = 1.0d15
do i=nn0-1,1,-1
do j=1,nn2-1
if ((aa(i,j).gt.zero).and.
. (aa(i,j).lt.aa(i+1,j)).and.
. (aa(i,j).lt.aa(i-1,j)).and.
. (aa(i,j).lt.aa(i,j+1)).and.
. (aa(i,j).lt.aa(i,j-1))) then
cc0 = a0(i,j)
cc2 = a2(i,j)
end if
if (aa(i,j).le.min_aa) then
min_i = i
min_j = j
min_aa = aa(i,j)
end if
end do
end do
end if
if (guess_absmin) then
cc0 = a0(min_i,min_j)
cc2 = a2(min_i,min_j)
endif
! Set up initial guess.
c0(0) = cc0
c0(2) = cc2
! lmax < 2 or sloppy guess.
else
call AHFinder_fun(CCTK_ARGUMENTS)
call AHFinder_exp(CCTK_ARGUMENTS)
do i=0,nn0
c0(0) = 4.0D0*dx + (aux-4.0D0*dx)*dble(i)/dble(nn0)
a0(i,0) = c0(0)
call AHFinder_int(CCTK_ARGUMENTS)
if (minarea) then
aa(i,0) = intarea
else
aa(i,0) = intexp2
end if
if (guessverbose) then
write(*,*)
write(*,"(A6,ES14.6)") ' a0 : ',a0(i,0)
write(*,"(A6,ES14.6)") ' H : ',intexp
write(*,"(A6,ES14.6)") ' H^2: ',intexp2
end if
end do
if ((.not.inner).or.(minarea)) then
do i=1,nn0-1
if ((aa(i,0).gt.zero).and.
. (aa(i,0).lt.0.9D0*aa(i+1,0)).and.
. (aa(i,0).lt.0.9D0*aa(i-1,0))) then
cc0 = a0(i,0)
end if
end do
else
do i=nn0-1,1,-1
if ((aa(i,0).gt.zero).and.
. (aa(i,0).lt.0.9D0*aa(i+1,0)).and.
. (aa(i,0).lt.0.9D0*aa(i-1,0))) then
cc0 = a0(i,0)
end if
end do
end if
! Set up initial guess.
c0(0) = cc0
end if
! If no local minimum was found, start with
! a large sphere anyway.
if (c0(0).eq.zero) then
c0 = zero
c0(0) = rmx
end if
! ***************
! *** END ***
! ***************
! Print message.
if (veryver.and.(myproc.eq.0)) then
write(*,*)
write(*,*) 'Initial guess found'
if (lmax.lt.2) then
write(*,"(A8,ES14.6)") ' c0(0): ',c0(0)
else
write(*,"(A14,2ES14.6)") ' c0(0),c0(2): ',c0(0),c0(2)
end if
end if
! Deallocate storage.
deallocate(aa,a0,a2)
end subroutine AHFinder_initguess
|