-
Notifications
You must be signed in to change notification settings - Fork 1
/
collsub.f
399 lines (328 loc) · 10.8 KB
/
collsub.f
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
c$$$ Subroutines to identify sample points and to perform transformations
c$$$ This file contains all collocation related routines.
c$$$
c$$$
c$$$ Input Variables:
c$$$ ipar : Array of distribution type of input variables
c$$$ (e.g., 1 => uniform, 2 => normal, etc.)
c$$$ par : 2-D array of distribution parameters for each input
c$$$ (e.g., par(1,2) => 2nd distribution parameter of the
c$$$ first input, which has distribution iparno(1)
c$$$ ndim : Number of input random variables
c$$$ norder : Order of the polynomial chaos expansion
c$$$ IPRN : Print option (IPRN=1 => print the collocation points)
c$$$ ITRNS : Transform the collocation points into the actual sample
c$$$ values (ITRNS=1 => transform). If not, just leave them
c$$$ as sample values of the standard random variables.
c$$$ MAXVAR : Maximum number of inputs (required for physical dimension
c$$$ of coll array)
c$$$ MAXPTS : Maximum number of collocation points (required for
c$$$ physical dimension of coll array)
c$$$ MAXPAR : Maximum number of parameters a distribution can have
c$$$ (e.g., normal distribution has 2 params, etc.)
c$$$ Output Variables:
c$$$ coll : array of the collocation points coll(point_number,variable)
c$$$ ictr : total number of collocation points
subroutine colgen (coll,par,ipar,ndim,norder,IPRN,ITRNS,ictr)
INCLUDE "collsub.h"
dimension coll(MAXPTS,MAXVAR), iparno(MAXDST), par(MAXVAR,MAXPAR)
dimension ipar(MAXVAR), param(MAXPAR), ocoll(MAXPTS,MAXVAR)
data iparno /2,2,2,2,1,1,0,0,0,0,
. 0,0,0,0,0,0,0,0,0,0/
do i=1,MAXPTS
do j=1,MAXVAR
coll(i,j) = 0.0
enddo
enddo
jctr = 2
if (norder.ne.1) goto 20
C 1st order terms
call trm1(coll,ndim,1.0,jctr)
C 2nd order terms
20 if (norder.ne.2) goto 30
x = 1.732
call trm1(coll,ndim,x,jctr)
call trm22(coll,ndim,x,-x,jctr)
call trm22(coll,ndim,-x,x,jctr)
call trm22(coll,ndim,x,x,jctr)
call trm22(coll,ndim,-x,-x,jctr)
30 if (norder.ne.3) goto 40
C 3rd order terms
x = 2.334
y = 0.742
call trm1(coll,ndim,x,jctr)
call trm1(coll,ndim,y,jctr)
call trm22(coll,ndim,y,y,jctr)
call trm22(coll,ndim,-y,-y,jctr)
call trm22(coll,ndim,-y,y,jctr)
call trm22(coll,ndim,y,-y,jctr)
call trm22(coll,ndim,x,y,jctr)
call trm22(coll,ndim,y,x,jctr)
call trm22(coll,ndim,x,-y,jctr)
call trm22(coll,ndim,-y,x,jctr)
call trm33(coll,ndim,y,-y,y,jctr)
call trm33(coll,ndim,-y,y,y,jctr)
call trm33(coll,ndim,y,y,-y,jctr)
call trm33(coll,ndim,y,-x,y,jctr)
call trm33(coll,ndim,-y,x,-y,jctr)
call trm33(coll,ndim,-x,y,y,jctr)
call trm33(coll,ndim,x,-y,-y,jctr)
call trm33(coll,ndim,y,y,-x,jctr)
call trm33(coll,ndim,-y,-y,x,jctr)
40 if (norder.ne.4) goto 50
C 4th order terms
y = 1.356
x = 2.860
call trm1(coll,ndim,x,jctr)
call trm1(coll,ndim,y,jctr)
call trm22(coll,ndim,y,y,jctr)
call trm22(coll,ndim,-y,-y,jctr)
call trm22(coll,ndim,y,-y,jctr)
call trm22(coll,ndim,-y,y,jctr)
call trm22(coll,ndim,x,y,jctr)
call trm22(coll,ndim,y,x,jctr)
call trm22(coll,ndim,x,-y,jctr)
call trm22(coll,ndim,-y,x,jctr)
call trm33(coll,ndim,y,-y,y,jctr)
call trm33(coll,ndim,-y,y,y,jctr)
call trm33(coll,ndim,y,y,-y,jctr)
call trm33(coll,ndim,y,y,y,jctr)
call trm33(coll,ndim,-y,-y,-y,jctr)
call trm33(coll,ndim,y,y,-y,jctr)
call trm33(coll,ndim,y,-x,y,jctr)
call trm33(coll,ndim,-y,x,-y,jctr)
call trm33(coll,ndim,-x,y,y,jctr)
call trm33(coll,ndim,x,-y,-y,jctr)
call trm33(coll,ndim,y,y,-x,jctr)
call trm33(coll,ndim,-y,-y,x,jctr)
call trm44(coll,ndim,y,-y,y,-y,jctr)
call trm44(coll,ndim,-y,y,-y,y,jctr)
call trm44(coll,ndim,-x,y,-y,x,jctr)
50 if (norder.ne.5) goto 999
C 5th order terms
call trm1(coll,ndim,3.324,jctr)
call trm1(coll,ndim,0.617,jctr)
call trm1(coll,ndim,1.890,jctr)
! write (filenum,*) 'ERROR... Not Yet Implemented'
stop'NOT yet implemented '
999 ictr = jctr - 1
do i=1,ndim
do j=1,ictr
ocoll(j,i) = coll(j,i)
enddo
enddo
if (ITRNS.EQ.1) then
do i=1,ndim
do j=1,iparno(ipar(i))
param(j) = par(i,j)
enddo
do j=1,ictr
coll(j,i) = xitran(coll(j,i), ipar(i), param)
enddo
enddo
endif
if (IPRN.EQ.1) then
do j=1,ictr
write (*,21) j, (coll(j,i),i=1,ndim)
enddo
endif
21 format (i7,2X,50(G11.4,X))
return
end
C Transformation from a Gaussian to another distribution type
C The following transformations are available in this version
C 1 - Uniform (a,b) UNIFORM
C 2 - Normal (mu, sigma) NORMAL
C 3 - Lognormal (mu, sigma) LOGNORMAL
C 4 - Gamma (a,b) GAMMA
C 5 - Exponential (lambda) EXPONENTIAL
C 6 - Weibull (a) WEIBULL
C 7 - Extreme Value EXTREME
C Reading the distribution information from a file
C Read Variable number and Type of distribution (numerical or name)
C
function xitran(xi, itrans, param)
INCLUDE "collsub.h"
dimension param(MAXPAR)
sqrt2 = 1.41421356
if ( (itrans.lt.1).OR.(itrans.gt.MXDNOW) ) then
! write (filenum,*) 'Error: Unknown distribution type'
stop'Unknownd distribution'
endif
if (itrans.eq.1) xnew = param(1) + (param(2)-param(1))*
. (0.5 + 0.5*erf(xi/sqrt2))
if (itrans.eq.2) xnew = param(1) + param(2)*xi
if (itrans.eq.3) xnew = exp(param(1) + param(2)*xi)
if (itrans.eq.4) xnew = param(1)*param(2)*
. (xi*sqrt2/(3.0*sqrt(param(1))) + 1 - 2.0/(9.*param(1)))**3.0
if (itrans.eq.5) xnew = -1.0/param(1) *
. alog(0.5 + 0.5*erf(xi/sqrt2))
if (itrans.eq.6) xnew = (-1.0*log(0.5 + 0.5*erf(xi/sqrt2)))
. **(1.0/param(1))
if (itrans.eq.7) xnew = -log(-1.0*log(0.5 + 0.5*erf(xi/sqrt2)))
xitran=xnew
return
end
subroutine trm1(coll,ndim,xval,jctr)
INCLUDE "collsub.h"
dimension coll(MAXPTS,MAXVAR)
do j=1,ndim
coll(jctr,j) = xval
coll(jctr+ndim,j) = -xval
jctr = jctr + 1
enddo
jctr = jctr + ndim
return
end
subroutine trm22(coll,ndim,xval,yval,jctr)
INCLUDE "collsub.h"
dimension coll(MAXPTS,MAXVAR)
C ixtr = (ndim*(ndim-1))/2
do j=1,ndim-1
do k=j+1,ndim
coll(jctr,j) = xval
coll(jctr,k) = yval
C coll(jctr+ixtr,j) = yval
C coll(jctr+ixtr,k) = xval
jctr = jctr + 1
enddo
enddo
C jctr = jctr + ixtr
return
end
subroutine trm33(coll,ndim,xval,yval,zval,jctr)
INCLUDE "collsub.h"
dimension coll(MAXPTS,MAXVAR)
C ixtr = (ndim*(ndim-1)*(ndim-2))/6
do j=1,ndim-2
do k=j+1,ndim-1
do l=k+1,ndim
coll(jctr,j) = xval
coll(jctr,k) = yval
coll(jctr,l) = zval
jctr = jctr + 1
enddo
enddo
enddo
return
end
subroutine trm44(coll,ndim,x,y,z,w,jctr)
INCLUDE "collsub.h"
dimension coll(MAXPTS,MAXVAR)
C ixtr = (ndim*(ndim-1)*(ndim-2)*(ndim-3))/2
do j=1,ndim-3
do k=j+1,ndim-2
do l=k+1,ndim-1
do m=l+1,ndim
coll(jctr,j) = x
coll(jctr,k) = y
coll(jctr,l) = z
coll(jctr,m) = w
jctr = jctr + 1
enddo
enddo
enddo
enddo
return
end
subroutine trm55(coll,ndim,x,y,z,w,u,jctr)
INCLUDE "collsub.h"
dimension coll(MAXPTS,MAXVAR)
C ixtr = (ndim*(ndim-1)*(ndim-2)*(ndim-3))/2
do j=1,ndim-4
do k=j+1,ndim-3
do l=k+1,ndim-2
do m=l+1,ndim-1
do n=m+1,ndim
coll(jctr,j) = x
coll(jctr,k) = y
coll(jctr,l) = z
coll(jctr,m) = w
coll(jctr,n) = u
jctr = jctr + 1
enddo
enddo
enddo
enddo
enddo
return
end
subroutine multidx(maxdim,DIM,DIMPC,mregout,nterms)
implicit none
integer :: i,ii,j,k,isum,DIM,DIMPC,nterms,ent,maxdim
integer :: mreg(maxdim,DIM),mregout(maxdim,DIM)
call combination(DIM+DIMPC,DIM,nterms)
mreg(:,:) = 0
if (DIMPC.ne.0) then
do 100 i=1,nterms
isum = 0
do j=1,DIM
isum = isum + mreg(i,j)
end do
if(isum.ne.DIMPC)then
mreg(i+1,:) = mreg(i,:)
mreg(i+1,1) = mreg(i+1,1) + 1
go to 100
else
do j=1,DIM
if(mreg(i,j).ne.0)then
if(j.eq.DIM) go to 200
mreg(i+1,:) = mreg(i,:)
mreg(i+1,j) = 0
mreg(i+1,j+1) = mreg(i+1,j+1) + 1
go to 100
end if
end do
stop 'No target j in Make_Mreg'
end if
100 continue
! write(filenum,'(3i6)')DIMPC,nterms,DIM
stop 'Error in Make_Mreg'
200 continue
if(i.ne.nterms)then
! write(filenum,*) i,nterms,DIMPC
stop 'i.ne.nterms in Make_Mreg'
end if
end if
! Resort
mregout(:,:) = 0
ent=2
do ii=1,DIMPC
do i=2,nterms
isum = 0
do j=1,DIM
isum = isum + mreg(i,j)
end do
if (isum.eq.ii) then
mregout(ent,:)=mreg(i,:)
mreg(i,:)=0
ent=ent+1
end if
end do
end do
end subroutine multidx
subroutine combination(n,m,l)
implicit none
! l = nCm = (n!)/(m!)/((n-m)!)
integer, intent(in) :: n,m
integer, intent(out) :: l
integer :: i,i1,i2,i3,nbig,npet
if(n.le.0.or.m.le.0) stop'n<1 or m<1 in combination'
if(n.lt.m) stop'n<m in combination'
if(m.ne.n-m)then
nbig = max(m,n-m)
npet = min(m,n-m)
else
nbig = m
npet = n-m
end if
i1 = 1
i2 = 1
do i=nbig+1,n
i1 = i1 * i
end do
do i=1,npet
i2 = i2 * i
end do
l = int( dble(i1)/dble(i2) )
end subroutine combination