Télécharger rlenco.eso

Retour à la liste

Numérotation des lignes :

rlenco
  1. C RLENCO SOURCE OF166741 24/12/13 21:17:23 12097
  2. SUBROUTINE RLENCO(MELSOM,MELCEN,MELLI1,MELLI2,INORM,MLEPOI,MLECOE)
  3. C************************************************************************
  4. C
  5. C PROJET : CASTEM 2000
  6. C
  7. C NOM : RLENCO
  8. C
  9. C DESCRIPTION : Appelle par GRADI2
  10. C
  11. C LANGAGE : FORTRAN 77 + ESOPE 2000 (avec extensions CISI)
  12. C
  13. C AUTEUR : A. BECCANTINI
  14. C
  15. C************************************************************************
  16. C
  17. C This subroutine computes the coefficients which allow to perform
  18. C a linear exact reconstruction of each 'sommet' (vertex) value
  19. C Indeed, given the i-th sommet (V=MELSOM.NUM(1,i)), given the list
  20. C of its neighbors MLEPOI.LECT(i), we have to compute the matrix of
  21. C coefficients a(i,j) such that
  22. C
  23. C VAL(MELSOM.NUM(1,i)) = \sum_{neig1} a(i,neig1) * VAL(neig1) +
  24. C \sum_{neig2} a(i,neig2) * VALNOR(neig2)
  25. C
  26. C where neig1 is a 'CENTRE' point or a 'Dirichlet boundary condition'
  27. C point, neig2 is a 'Von Neumann boundary condition' point, VAL(j)
  28. C is the value of the function in the j-th neighbor, VALNOR(j) is
  29. C the value of grad(VAL).n is the j-th neighbor.
  30. C
  31. C
  32. C To compute these coefficients, we impose that VAL is linear with
  33. C respect to the coordinates of V and its neighbor. Then, since
  34. C there are less unknowns than equations, we use a least square
  35. C method. If the neighbor is a 'CENTRE' point or a 'Dirichlet
  36. C boundary condition' point, we impose that
  37. C
  38. C A + B (x_{neig} - x_V) + C (y_{neig} - y_V) + D (z_{neig} - z_V)
  39. C = VAL(neig)
  40. C
  41. C If the neighbor is a 'von Neumann boundary condition' point,
  42. C we impose that
  43. C
  44. C |r_{neig} - r_V| (B nx_{neig} + C ny_{neig} + D nz_{neig}) =
  45. C VALNOR(neig) * |r_{neig} - r_V|
  46. C
  47. c r = (x,y,z)
  48. c n = (nx, ny, nz) is the normal to the surface
  49. C
  50. C To determine A, B, C, D we have to solve
  51. C
  52. C MATA . tran(A, B, C, D) = tran(VAL(1), VAL(2), ... , VALNOR(j) /
  53. C (r_{j} - r_V)
  54. C
  55. C with MATA(1,*) = (1,x_1-x_V,y_1-y_V,z_1-z_V)
  56. C MATA(2,*) = (1,x_2-x_V,y_2-y_V,z_2-z_V)
  57. C ...
  58. C MATA(j,*) = (0,nx_{j}, ny_{j}, nz_{j})
  59. C ...
  60. C
  61. C To determine a(i,neig) we have to solve a linear system (for each
  62. C neig). If the neighbor is a 'CENTRE' point or a 'Dirichlet boundary
  63. C condition' point we solve
  64. C
  65. C MATA . tran(a(i,neig), b(i,neig), c(i,neig), d(i,neig)) = e_{neig}
  66. C
  67. C with e_{neig} = tran (0,0,...,0,1,0,...) (1 in the neig position)
  68. C
  69. C If the neighbor is a 'von Neumann boundary condition' points,
  70. C we solve
  71. C
  72. C MATA . tran(a(i,neig), b(i,neig), c(i,neig), d(i,neig)) =
  73. C e_{neig} (r_{neig} - r_V)
  74. C
  75. C Since each linear system involves MATA, we have to "pseudoinvert"
  76. C it.
  77. C
  78. C**** Inputs:
  79. C
  80. C MELSOM = the 'SOMMET' meleme
  81. C MELCEN = the 'CENTRE' meleme
  82. C MELLI1 = the support of Dirichlet boundary conditions
  83. C MELLI2 = the support of von Neumann boundary conditions
  84. C INOMR = CHAMPOINT des normales aux faces
  85. C MLEPOI = list of integers.
  86. C MLEPOI.LECT(i) points to the list neighbors of
  87. C MELSOM.NUM(1,i)
  88. C
  89. C**** Output:
  90. C
  91. C MLECOE = list of integers.
  92. C
  93. C MLECOE.LECT(i) points to the MLREEL MLRCOE which
  94. C contain the a(i,neig)
  95. C
  96. IMPLICIT INTEGER(I-N)
  97. INTEGER INORM, NSOMM, INOEU, NGS, IPCOOR, IVOI, NVOI, NGV, NLV
  98. & ,NLV1,NVMAX,NVMIN,IERSVD,IERR0,NLN
  99. & ,I1,I2,I3,I4
  100. REAL*8 XS,YS,ZS,XV,YV,ZV,DX,ERRTOL,SMAX,SMIN
  101. PARAMETER(ERRTOL=1.0D-16)
  102. CHARACTER*8 TYPE
  103. LOGICAL LOGSVD
  104.  
  105. -INC PPARAM
  106. -INC CCOPTIO
  107. -INC SMCOORD
  108. -INC SMELEME
  109. -INC SMLREEL
  110. -INC SMLENTI
  111. -INC SMCHPOI
  112. INTEGER JG
  113. INTEGER N1,N2
  114. SEGMENT MATRIX
  115. REAL*8 MAT(N1,N2)
  116. ENDSEGMENT
  117. POINTEUR MELSOM.MELEME, MLEPOI.MLENTI,MELLI1.MELEME,MELLI2.MELEME
  118. & ,MLELI1.MLENTI,MLELI2.MLENTI,MELCEN.MELEME,MLECEN.MLENTI
  119. & ,MPNORM.MPOVAL, MATA.MATRIX,MATU.MATRIX,MATV.MATRIX
  120. & ,MLRCOE.MLREEL,MLRSIG.MLREEL,MLRTRA.MLREEL
  121. & ,MTAA.MATRIX, MINTAA.MATRIX,MLRIN1.MLREEL,MLRIN2.MLREEL
  122. & ,MLRIN3.MLREEL, MLECOE.MLENTI, MLRB.MLREEL
  123. & ,MELFAC.MELEME,MLEFAC.MLENTI
  124. C
  125. C**** We create the MLENTI for the centers
  126. C
  127. CALL KRIPAD(MELCEN,MLECEN)
  128. IF(IERR .NE. 0)GOTO 9999
  129. C En KRIPAD
  130. C SEGACT MELCEN
  131. C SEGINI MLECEN
  132. C
  133. C**** We create the MLENTI for the BC
  134. C
  135. CALL KRIPAD(MELLI1,MLELI1)
  136. IF(IERR .NE. 0)GOTO 9999
  137. CALL KRIPAD(MELLI2,MLELI2)
  138. IF(IERR .NE. 0)GOTO 9999
  139. C SEGACT MELLI1
  140. C SEGINI MLELI1
  141. C SEGACT MELLI2
  142. C SEGINI MLELI2
  143. C
  144. SEGACT MELSOM
  145. NSOMM=MELSOM.NUM(/2)
  146. JG=NSOMM
  147. SEGINI MLECOE
  148. SEGACT MLEPOI
  149. C
  150. C**** Le MPOVAL des normales
  151. C
  152. CALL LICHT(INORM,MPNORM,TYPE,MELFAC)
  153. C SEGACT MPNORM
  154. C
  155. C**** We create the MLENTI for the MELFAC
  156. C
  157. CALL KRIPAD(MELFAC,MLEFAC)
  158. IF(IERR .NE. 0)GOTO 9999
  159. C SEGACT MELFAC
  160. C SEGINI MLEFAC
  161. C
  162. C**** Loop on the sommet to compute NVMAX
  163. C (maximum number of neighbors)
  164. C
  165. NVMAX=0
  166. DO INOEU=1,NSOMM,1
  167. C
  168. C******* The neighbors of NGS
  169. C
  170. MLENTI=MLEPOI.LECT(INOEU)
  171. SEGACT MLENTI
  172. NVOI=MLENTI.LECT(/1)
  173. NVMAX=MAX(NVMAX,NVOI)
  174. ENDDO
  175. C
  176. C MATA = matrix to "pseudoinvert" (NVMAX,IDIM+1)
  177. C MATU = matrix of the singular right eigenvectors of MATA
  178. C (NVMAX,IDIM+1)
  179. C MATV = matrix of the singular left eigenvectors of MATA
  180. C (IDIM+1,IDIM+1)
  181. C But in invsvd.eso, MATV dimensions are NVMAX,IDIM+1
  182. C MLRSIG = singular values of MATA (IDIM+1)
  183. C MLRB = vector (NVMAX)
  184. C MLRB.PROG(j) = 1 if j is a center point or a 'Dirichlet
  185. C boundary condition' point
  186. C MLRB.PROG(j) = (r_j - r_V) id j is a 'von Neumann
  187. C boundary condition point.
  188. C
  189. C N.B. MATA = MATU MATSIG t(MATV)
  190. C If MATA is non singular,
  191. C inv(MATA) = MATV inv(MATSIG) t(MATU)
  192. C
  193. C MLRTRA temporary vector of invsvd.eso
  194. C NVMIN = IDIM + 1 (the most little dimension of the matrices)
  195. C
  196. N1=NVMAX
  197. N2=IDIM+1
  198. SEGINI MATA
  199. SEGINI MATU
  200. SEGINI MATV
  201. JG=NVMAX
  202. SEGINI MLRB
  203. JG=IDIM+1
  204. SEGINI MLRSIG
  205. SEGINI MLRTRA
  206. NVMIN=N2
  207. C
  208. C MTAA : [t(MATA).MATA]
  209. C MINTAA : [inve(t(MATA) MATA)]
  210. C MLRIN1,2,3 : "temporary vectors"
  211. C
  212. N1=NVMIN
  213. N2=NVMIN
  214. SEGINI MTAA
  215. SEGINI MINTAA
  216. JG=NVMIN
  217. SEGINI MLRIN1
  218. SEGINI MLRIN2
  219. SEGINI MLRIN3
  220. C
  221. C**** Loop on the sommet to compute the coefficient
  222. C
  223.  
  224. DO INOEU=1,NSOMM,1
  225. NGS=MELSOM.NUM(1,INOEU)
  226. IPCOOR=((NGS-1)*(IDIM+1))+1
  227. XS=MCOORD.XCOOR(IPCOOR)
  228. YS=MCOORD.XCOOR(IPCOOR+1)
  229. IF(IDIM .EQ. 3) ZS=MCOORD.XCOOR(IPCOOR+2)
  230. C
  231. C******* The neighbors of NGS
  232. C
  233. MLENTI=MLEPOI.LECT(INOEU)
  234. NVOI=MLENTI.LECT(/1)
  235. C
  236. C******* The matrix where we store the coefficients
  237. C
  238. JG=NVOI
  239. SEGINI MLRCOE
  240. MLECOE.LECT(INOEU)=MLRCOE
  241. C
  242. C******* Loop involving the neighbors
  243. C We create the matrix to "pseudoinvert"
  244. C
  245. DO IVOI=1,NVOI,1
  246. NGV=MLENTI.LECT(IVOI)
  247. NLV=MLECEN.LECT(NGV)
  248. NLV1=MLELI1.LECT(NGV)
  249. IF((NLV .NE. 0) .OR. (NLV1 .NE. 0))THEN
  250. C
  251. C********** NGV is a 'centre' point or a Dirichlet point
  252. C
  253. IPCOOR=((NGV-1)*(IDIM+1))+1
  254. XV=MCOORD.XCOOR(IPCOOR)
  255. YV=MCOORD.XCOOR(IPCOOR+1)
  256. MATA.MAT(IVOI,1)=1
  257. MATA.MAT(IVOI,2)=XV-XS
  258. MATA.MAT(IVOI,3)=YV-YS
  259. IF(IDIM.EQ.3)THEN
  260. ZV=MCOORD.XCOOR(IPCOOR+2)
  261. MATA.MAT(IVOI,4)=ZV-ZS
  262. ENDIF
  263. MLRB.PROG(IVOI)=1.0D0
  264. ELSE
  265. NLV=MLELI2.LECT(NGV)
  266. IF(NLV .EQ. 0)THEN
  267. C
  268. C**************** NO B.C. specified on this point
  269. C
  270. WRITE(IOIMP,*) 'Boundary conditions ???'
  271. CALL ERREUR(21)
  272. GOTO 9999
  273. ELSE
  274. IPCOOR=((NGV-1)*(IDIM+1))+1
  275. XV=MCOORD.XCOOR(IPCOOR)
  276. YV=MCOORD.XCOOR(IPCOOR+1)
  277. DX=((XV - XS)**2)+((YV - YS)**2)
  278. IF(IDIM .EQ. 3)THEN
  279. ZV=MCOORD.XCOOR(IPCOOR+2)
  280. DX=DX+((ZV - ZS)**2)
  281. ENDIF
  282. NLN=MLEFAC.LECT(NGV)
  283. DX=DX**0.5D0
  284. MATA.MAT(IVOI,1)=0
  285. MATA.MAT(IVOI,2)=DX*MPNORM.VPOCHA(NLN,1)
  286. MATA.MAT(IVOI,3)=DX*MPNORM.VPOCHA(NLN,2)
  287. IF(IDIM .EQ. 3)THEN
  288. MATA.MAT(IVOI,4)=DX*MPNORM.VPOCHA(NLN,3)
  289. ENDIF
  290. MLRB.PROG(IVOI)=DX
  291. ENDIF
  292. ENDIF
  293. ENDDO
  294. C
  295. C TEST
  296. C do ivoi=1,nvoi,1
  297. C write(*,*)
  298. C & 'mata.mat(',ivoi,')=',(mata.mat(ivoi,i1),i1=1,nvmin,1)
  299. C write(*,*) 'b(',ivoi,')=',mlrb.prog(ivoi)
  300. C enddo
  301. C
  302. C
  303. C********** Now we have to invert this matrix
  304. C
  305. LOGSVD=.TRUE.
  306. CALL INVSVD( NVMAX, NVOI, NVMIN, MATA.MAT,
  307. & MLRSIG.PROG,.TRUE.,MATU.MAT,.TRUE.,MATV.MAT,IERSVD,
  308. & MLRTRA.PROG)
  309. IF(IERSVD.NE.0)THEN
  310. C
  311. C************* SVD decomposition of the matrix does not work
  312. C
  313. LOGSVD=.FALSE.
  314. ELSE
  315. C
  316. C************ We check the condition number of MATA
  317. C
  318. SMAX=0.0D0
  319. DO I1=1,NVMIN,1
  320. SMAX=MAX(SMAX,MLRSIG.PROG(I1))
  321. ENDDO
  322. SMIN=SMAX
  323. DO I1=1,NVMIN,1
  324. SMIN=MIN(SMIN,MLRSIG.PROG(I1))
  325. ENDDO
  326. IF((SMIN/SMAX) .LT. ERRTOL)THEN
  327. LOGSVD=.FALSE.
  328. ENDIF
  329. ENDIF
  330. C
  331. C TEST
  332. C write(*,*) 'LOGSVD=.FALSE.'
  333. C LOGSVD=.FALSE.
  334. C
  335. IF(LOGSVD)THEN
  336. C
  337. C********** INVSVD worked
  338. C
  339. C MATA = MATU MATSIG t(MATV)
  340. C inv(MATA) = MATV inv(MATSIG) t(MATU)
  341. C
  342. DO I4=1,NVMIN,1
  343. DO IVOI=1,NVOI,1
  344. DO I2=1,1,1
  345. C I2=1 is the only coefficient we are interested in
  346. MLRCOE.PROG(IVOI)=MLRCOE.PROG(IVOI)+
  347. & (MATV.MAT(I2,I4)*MATU.MAT(IVOI,I4)
  348. & *MLRB.PROG(IVOI)/MLRSIG.PROG(I4))
  349. ENDDO
  350. ENDDO
  351. ENDDO
  352. ELSE
  353. WRITE (IOIMP,*) 'rlenco.eso'
  354. C 22 0
  355. C Opération malvenue. Résultat douteux
  356. CALL ERREUR(22)
  357. C
  358. C********** INVSVD does not worked
  359. C For each neighbor k we have to compute the solution
  360. C of
  361. C
  362. C t(MATA) MATA x = t(MATA) * b
  363. C
  364. C where b= \sum_l e_l \delta(k,l) = e_k
  365. C
  366. C To do that, we compute
  367. C
  368. C X_0 = [inve(t(MATA) MATA)] [t(MATA) * b]
  369. C
  370. C X_1 = X_0 + [inve(t(MATA) MATA)] [t(MATA) * b -
  371. C [t(MATA) MATA] X_0]
  372. C
  373. C
  374. C********** We compute [t(MATA) MATA]
  375. C We store it in the upper triangle of MTAA(NVMIN,NVMIN)
  376. C
  377. DO I1=1,NVMIN,1
  378. DO I2=I1,NVMIN,1
  379. MTAA.MAT(I1,I2)=0.0D0
  380. ENDDO
  381. ENDDO
  382.  
  383. DO I1=1,NVMIN,1
  384. DO I2=I1,NVMIN,1
  385. DO I3=1,NVOI,1
  386. MTAA.MAT(I1,I2)=MTAA.MAT(I1,I2)+
  387. & (MATA.MAT(I3,I1)*MATA.MAT(I3,I2))
  388. ENDDO
  389. ENDDO
  390. ENDDO
  391. C
  392. C********** We compute [inve(t(MATA) MATA)]
  393. C CHOLDC stores it in the upper trianle of MINTAA(NVMIN,NVMIN)
  394. C
  395. CALL CHOLDC(NVMIN,NVMIN,MTAA.MAT,MLRIN1.PROG,MINTAA.MAT,
  396. & MLRIN2.PROG,IERR0)
  397. IF(IERR0.NE.0)THEN
  398. WRITE(IOIMP,*) 'subroutine rlenco.eso.'
  399. C 26 2
  400. C Tache impossible. Probablement données erronées
  401. CALL ERREUR(26)
  402. GOTO 9999
  403. ENDIF
  404. C
  405. C********** We complete MTAA and MINTAA
  406. C
  407. DO I1=1,NVMIN,1
  408. DO I2=I1+1,NVMIN,1
  409. MINTAA.MAT(I2,I1)=MINTAA.MAT(I1,I2)
  410. MTAA.MAT(I2,I1)=MTAA.MAT(I1,I2)
  411. ENDDO
  412. ENDDO
  413. C
  414. DO IVOI=1,NVOI,1
  415. C
  416. C************* We compute [t(MATA) . b] and we store it in MLRIN1.PROG
  417. C
  418. DO I1=1,NVMIN,1
  419. MLRIN1.PROG(I1)=MATA.MAT(IVOI,I1)*MLRB.PROG(IVOI)
  420. MLRIN2.PROG(I1)=0.0D0
  421. MLRIN3.PROG(I1)=0.0D0
  422. ENDDO
  423. C
  424. C************* X_0 = [inve(t(MATA) MATA)] [t(MATA) * b]
  425. C X_0(i1) into MLRIN2.PROG(I1)
  426. C
  427. DO I2=1,NVMIN,1
  428. DO I1=1,NVMIN,1
  429. MLRIN2.PROG(I1)=MLRIN2.PROG(I1)+
  430. & (MINTAA.MAT(I1,I2)*MLRIN1.PROG(I2))
  431. ENDDO
  432. ENDDO
  433. C
  434. C************ X_1 = X_0 + [inve(t(MATA) MATA)] [t(MATA) * b -
  435. C [t(MATA) MATA] X_0]
  436. C
  437. C [t(MATA) MATA] X_0 into MLRIN3.PROG
  438. C
  439. DO I2=1,NVMIN,1
  440. DO I1=1,NVMIN,1
  441. MLRIN3.PROG(I1)=MLRIN3.PROG(I1)+
  442. & (MTAA.MAT(I1,I2)*MLRIN2.PROG(I2))
  443. ENDDO
  444. ENDDO
  445. C
  446. C************* Now we have
  447. C [t(MATA) . b] in MLRIN1.PROG
  448. C X_0(i1) in MLRIN2.PROG(I1)
  449. C [t(MATA) MATA] X_0 in MLRIN3.PROG
  450. C
  451. C X_1(i1) in MLRCOE.MAT(i1,IVOI)
  452. C
  453. DO I1=1,1,1
  454. C The only interesting one is I1=1
  455. DO I2=1,NVMIN,1
  456. MLRCOE.PROG(IVOI)=MLRCOE.PROG(IVOI)+
  457. & (MINTAA.MAT(I1,I2)*
  458. & (MLRIN1.PROG(I2)-MLRIN3.PROG(I2)))
  459. ENDDO
  460. MLRCOE.PROG(IVOI)=MLRCOE.PROG(IVOI)+
  461. & MLRIN2.PROG(I1)
  462. ENDDO
  463. ENDDO
  464. ENDIF
  465. CC
  466. CC TEST
  467. C write(*,*) 'ngs =', NGS
  468. C write(*,*) 'invide',LOGSVD
  469. C write(*,*) 'nvois =',(mlenti.lect(ivoi),ivoi=1,nvoi,1)
  470. C write(*,*) 'coeff =',(mlrcoe.prog(ivoi),ivoi=1,nvoi,1)
  471. C dx=0.0D0
  472. C do ivoi=1,nvoi,1
  473. C dx=dx+mlrcoe.prog(ivoi)
  474. C enddo
  475. C write(*,*) 'sum=',dx
  476. MLENTI=MLEPOI.LECT(INOEU)
  477. SEGDES MLENTI
  478. MLRCOE=MLECOE.LECT(INOEU)
  479. SEGDES MLRCOE
  480. ENDDO
  481. C
  482. SEGDES MELCEN
  483. SEGSUP MLECEN
  484. C
  485. IF(MELLI1 .NE. 0) SEGDES MELLI1
  486. IF(MELLI2 .NE. 0) SEGDES MELLI2
  487. SEGSUP MLELI1
  488. SEGSUP MLELI2
  489. C
  490. SEGDES MELSOM
  491. C
  492. SEGDES MLECOE
  493. SEGDES MLEPOI
  494. C
  495. SEGSUP MATA
  496. SEGSUP MATU
  497. SEGSUP MATV
  498. SEGSUP MLRSIG
  499. SEGSUP MLRTRA
  500. SEGSUP MLRB
  501. C
  502. SEGSUP MTAA
  503. SEGSUP MINTAA
  504. SEGSUP MLRIN1
  505. SEGSUP MLRIN2
  506. SEGSUP MLRIN3
  507. C
  508. SEGDES MPNORM
  509. SEGDES MELFAC
  510. SEGSUP MLEFAC
  511. C
  512. 9999 CONTINUE
  513. RETURN
  514. END
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales