SFEMaNS  version 4.1 (work in progress)
Reference documentation for SFEMaNS
 All Classes Files Functions Variables Groups Pages
prep_mesh.f90
Go to the documentation of this file.
1 !
2 !Authors Jean-Luc Guermond, Luigi Quarapelle, Copyrights 1994, 2005
3 !Revised June 2008, Jean-Luc Guermond
4 !
5 MODULE prep_maill
6 
7  IMPLICIT NONE
8 
11  PRIVATE
12 
13 CONTAINS
14 
15  !------------------------------------------------------------------------------
16  SUBROUTINE load_dg_mesh_free_format(dir, fil, list_dom, list_inter, type_fe, &
17  mesh, mesh_formatted)
18 
19  USE def_type_mesh
21  USE dir_nodes
22  !TEST june 11 2008
23  !USE sub_plot
24  !TEST june 11 2008
25 
26 
27  IMPLICIT NONE
28  CHARACTER(len=200), INTENT(IN) :: dir, fil
29  INTEGER, DIMENSION(:), INTENT(IN) :: list_dom, list_inter
30  INTEGER, INTENT(IN) :: type_fe
31  TYPE(mesh_type) :: mesh
32  LOGICAL, INTENT(IN) :: mesh_formatted !formatted <=> mesh_formatted=.true.
33 
34  INTEGER, ALLOCATABLE, DIMENSION(:) :: nouv_nd, nouv_el, nouv_els
35  INTEGER, ALLOCATABLE, DIMENSION(:,:) :: jj_lect, neigh_lect, jjs_lect
36  INTEGER, ALLOCATABLE, DIMENSION(:) :: i_d_lect, sides_lect, neighs_lect, stat
37  LOGICAL, ALLOCATABLE, DIMENSION(:) :: virgin_nd, virgin_ms
38  REAL(KIND=8), ALLOCATABLE, DIMENSION(:,:) :: rr_lect
39  !TEST june 11 2008
40  !REAL(KIND=8), ALLOCATABLE, DIMENSION(:) :: const
41  !INTEGER, DIMENSION(2) :: nface, ngauss
42  !INTEGER :: n1, n2, face
43  !TEST june 11 2008
44  LOGICAL :: t1, t2
45  INTEGER :: mnouv, nnouv, i, dom
46  INTEGER :: n, m, mop, ms, msnouv, neighs1, neighs2
47  INTEGER :: d_end, f_end
48  INTEGER :: np, nw, me, nws, mes, kd, nwneigh
49  CHARACTER(len=40) :: text
50  CHARACTER(len=2) :: truc
51 
52  text = 'Mesh'
53  d_end = last_c_leng(20, text)
54  DO n = 1, SIZE(list_dom)
55  d_end = last_c_leng(20, text)
56  WRITE(truc,'(i2)') list_dom(n)
57  f_end = start_of_string(truc)
58  text = text(1:d_end)//'_'//truc(f_end:)
59  END DO
60 
61  d_end = last_c_leng(20, text)
62  IF (type_fe==1) THEN
63  text = text(1:d_end)//'_FE_1'
64  ELSE
65  text = text(1:d_end)//'_FE_2'
66  END IF
67 
68  !WRITE (*,*) 'Loading mesh-file ...'
69  IF (mesh_formatted) THEN
70  OPEN(30,file=trim(adjustl(dir))//'/'//trim(adjustl(fil)),form='formatted')
71  ELSE
72  OPEN(30,file=trim(adjustl(dir))//'/'//trim(adjustl(fil)),form='unformatted')
73  END IF
74  OPEN(unit=20,file=text, form='formatted', status='unknown')
75 
76  ! READ GRID DATA AND ARRAY ALLOCATION ----------------------------------------
77  IF (type_fe == 2) THEN ! Skip P1 data if needed
78  IF (mesh_formatted) THEN
79  READ(30,*) np, nw, me, nws, mes
80  DO m = 1, me
81  READ(30,*)
82  END DO
83  DO ms = 1, mes
84  READ(30,*)
85  END DO
86  DO n = 1, np
87  READ(30,*)
88  END DO
89  ELSE
90  READ(30) np, nw, me, nws, mes
91  READ(30)
92  READ(30)
93  READ(30)
94  END IF
95  END IF
96 
97  IF (mesh_formatted) THEN
98  READ(30, *) np, nw, me, nws, mes
99  ELSE
100  READ(30) np, nw, me, nws, mes
101  END IF
102 
103  IF (nw==3 .AND. nws==2) THEN ! Decide about space dimension
104  kd = 2; nwneigh = 3
105  ELSE IF (nw==6 .AND. nws==3) THEN
106  kd = 2; nwneigh = 3
107  ELSE IF (nw==4 .AND. nws==3) THEN
108  kd = 3; nwneigh = 4
109  ELSE IF (nw==10 .AND. nws==6) THEN
110  kd = 3; nwneigh = 4
111  ELSE
112  WRITE(*,*) ' Finite element not yet programmed '
113  WRITE(*,*) nw, nws
114  stop
115  END IF
116 
117  ALLOCATE (jj_lect(nw,me),neigh_lect(nwneigh,me),i_d_lect(me))
118  ALLOCATE (jjs_lect(nws,mes), neighs_lect(mes), sides_lect(mes))
119  ALLOCATE(rr_lect(kd,np))
120 
121  IF (mesh_formatted) THEN
122  DO m = 1, me
123  READ(30,*) jj_lect(:,m), neigh_lect(:,m), i_d_lect(m)
124  END DO
125  DO ms = 1, mes
126  READ(30,*) jjs_lect(:,ms), neighs_lect(ms), sides_lect(ms)
127  END DO
128  DO n = 1, np
129  READ(30,*) rr_lect(:,n)
130  END DO
131  ELSE
132  READ(30) jj_lect, neigh_lect, i_d_lect
133  READ(30) jjs_lect, neighs_lect, sides_lect
134  READ(30) rr_lect
135  END IF
136 
137 
138  !---Renumerotation------------------------------------------------------------
139  ! Identify the status of faces
140  ! stat = 1 (interface to be forgotten), stat = 2 (boundary), stat = 3 (real interface)
141  ALLOCATE (stat(mes))
142  DO ms = 1, mes
143  neighs1 = neighs_lect(ms)
144  IF (neighs1==0) THEN
145  WRITE(*,*) ' BUG in prep_mesh, neighs1=0 '
146  stop
147  END IF
148  IF (minval(abs(i_d_lect(neighs1) - list_dom))==0) THEN
149  t1 = .true.
150  ELSE
151  t1 = .false.
152  END IF
153  DO n = 1, nw
154  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT ! n not on the interface
155  END DO
156  neighs2 = neigh_lect(n,neighs1)
157  IF (neighs2==0) THEN
158  IF (t1) THEN
159  stat(ms) = 2 ! face on the boundary of the domain of interest
160  ELSE
161  stat(ms) = 1 ! face does not touch the domain of interest
162  END IF
163  cycle
164  END IF
165  ! neighs2 /=0
166  IF (minval(abs(i_d_lect(neighs2) - list_dom))==0) THEN
167  t2 = .true.
168  ELSE
169  t2 = .false.
170  END IF
171 
172  IF (t1) THEN
173  IF (t2) THEN
174  IF (SIZE(list_inter)==0) THEN
175  stat(ms) = 1 ! no inteface to treat
176  ELSE IF (minval(abs(sides_lect(ms)-list_inter))==0) THEN
177  stat(ms) = 3 ! real interface
178  ELSE
179  stat(ms) = 1 ! interface to be forgotten
180  END IF
181  ELSE
182  stat(ms) = 2 ! face at the boundary of the domain of interest
183  END IF
184  ELSE
185  IF (t2) THEN
186  stat(ms) = 2 ! face at the boundary of the domain of interest
187  ELSE
188  stat(ms) = 1 ! on an interface of no interest
189  END IF
190  END IF
191 
192  END DO
193 
194  ALLOCATE (nouv_nd(np), nouv_els(mes), virgin_nd(np), virgin_ms(mes), nouv_el(me))
195  nouv_nd = -1000
196  virgin_nd = .true.
197  virgin_ms = .true.
198  mnouv = 0
199  msnouv= 0
200  nnouv = 0
201  DO dom = 1, SIZE(list_dom)
202  DO m = 1, me ! Count new nodes from domain: i_d=dom
203  IF (list_dom(dom) /= i_d_lect(m)) cycle ! i_d(m) pas dans la liste
204  mnouv = mnouv + 1 ! Nouvel element
205  nouv_el(m) = mnouv
206  DO n = 1, nw; i = jj_lect(n,m)
207  IF (virgin_nd(i)) THEN ! Nouveau point
208  virgin_nd(i) = .false.
209  nnouv = nnouv + 1
210  END IF
211  END DO
212  END DO
213 
214  DO ms = 1, mes
215  IF (stat(ms) /= 1 .AND. stat(ms) /=2 .AND. stat(ms) /=3) THEN
216  WRITE(*,*) ' BUG in prep_mesh, stat out of bounds '
217  stop
218  END IF
219 
220  !I test if ms touches the current domain of interest: i_d = dom
221  IF (stat(ms) == 1) cycle
222  neighs1 = neighs_lect(ms)
223  DO n = 1, nw
224  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT
225  ! exit when n is not on the interface
226  END DO
227  neighs2 = neigh_lect(n,neighs1)
228  IF (i_d_lect(neighs1) /= list_dom(dom)) THEN
229  IF (neighs2 == 0) cycle ! face on the boundary and does not touch dom yet
230  IF (i_d_lect(neighs2) /= list_dom(dom)) cycle ! dom is on neither sides
231  END IF
232  !End test if ms touches the domain of interest
233 
234  IF (virgin_ms(ms)) THEN !New interface
235  virgin_ms(ms) = .false.
236  msnouv = msnouv + 1
237  END IF
238  IF (stat(ms) ==3) THEN
239  ! Nodes and sides on the interface are virgin again
240  virgin_nd(jjs_lect(:,ms)) = .true. ! interface nodes are virgin again
241  virgin_ms(ms) = .true.
242  END IF
243  END DO
244  END DO
245  mesh%me = mnouv
246  mesh%np = nnouv
247  mesh%mes = msnouv
248 
249 
250  ALLOCATE(mesh%jj(nw,mesh%me), mesh%neigh(nwneigh,mesh%me), mesh%i_d(mesh%me))
251  ALLOCATE(mesh%jjs(nws,mesh%mes), mesh%neighs(mesh%mes), mesh%sides(mesh%mes))
252  ALLOCATE(mesh%rr(kd,mesh%np))
253 
254  virgin_nd = .true.
255  virgin_ms = .true.
256  nnouv = 0
257  msnouv = 0
258  DO dom = 1, SIZE(list_dom)
259  !Loop on me and get nouv_el and nouv_nd right
260  DO m = 1, me
261  IF (list_dom(dom) /=i_d_lect(m)) cycle ! i_d(m) pas dans la liste
262  DO n = 1, nw; i = jj_lect(n,m)
263  IF (virgin_nd(i)) THEN ! Nouveau point
264  virgin_nd(i) = .false.
265  nnouv = nnouv + 1
266  nouv_nd(i) = nnouv
267  END IF
268  END DO
269  END DO
270 
271  !Loop again on me and update
272  DO m = 1, me
273  IF (list_dom(dom) /=i_d_lect(m)) cycle ! i_d(m) pas dans la liste
274  DO n = 1, nw; i = jj_lect(n,m)
275  IF (n .LE. nwneigh) THEN
276  mop = neigh_lect(n,m)
277  IF (mop .LE. 0) THEN
278  mesh%neigh(n,nouv_el(m)) = 0
279  ELSE IF (minval(abs(list_dom - i_d_lect(mop))) == 0) THEN
280  mesh%neigh(n,nouv_el(m)) = nouv_el(mop)
281  ELSE
282  mesh%neigh(n,nouv_el(m)) = 0
283  END IF
284  END IF
285  mesh%rr(:,nouv_nd(i)) = rr_lect(:,i)
286  END DO
287  mesh%i_d(nouv_el(m)) = i_d_lect(m)
288  mesh%jj(:,nouv_el(m)) = nouv_nd(jj_lect(:,m))
289  END DO
290 
291  !Loop on mes and get neighs_lect and nouv_els right
292  DO ms = 1, mes
293  !I test if ms touches the current domain of interest: i_d = dom
294  IF (stat(ms) == 1) cycle
295  neighs1 = neighs_lect(ms)
296  DO n = 1, nw
297  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT
298  ! exit when n is not on the interface
299  END DO
300  neighs2 = neigh_lect(n,neighs1)
301  IF (i_d_lect(neighs1) /= list_dom(dom)) THEN
302  IF (neighs2 == 0) cycle ! face on the boundary and does not touch dom yet
303  IF (i_d_lect(neighs2) /= list_dom(dom)) cycle ! dom is on neither sides
304  END IF
305  !End test if ms touches the domain of interest
306 
307  IF (virgin_ms(ms)) THEN !New interface
308  virgin_ms(ms) = .false.
309  msnouv = msnouv + 1
310  nouv_els(ms) = msnouv
311  END IF
312  IF (stat(ms) ==3) THEN
313  ! Nodes and sides on the interface are virgin again
314  virgin_nd(jjs_lect(:,ms)) = .true. ! interface nodes are virgin again
315  virgin_ms(ms) = .true.
316  END IF
317 
318  ! Swapping problem
319  neighs1 = neighs_lect(ms)
320  IF ((abs(i_d_lect(neighs1) - list_dom(dom)))==0) THEN
321  t1 = .true.
322  ELSE
323  t1 = .false.
324  END IF
325  DO n = 1, nw
326  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT ! n not on the interface
327  END DO
328  neighs2 = neigh_lect(n,neighs1)
329  IF (neighs2==0) THEN
330  cycle
331  END IF
332  ! neighs2 /=0
333  IF ((abs(i_d_lect(neighs2) - list_dom(dom)))==0) THEN
334  t2 = .true.
335  ELSE
336  t2 = .false.
337  END IF
338  IF (.NOT.t1 .AND. t2) THEN
339  neighs_lect(ms) = neighs2 !get things right (swap neighs)
340  END IF
341  END DO
342 
343  !Loop again on mes and update
344  DO ms = 1, mes
345 
346  !I test if ms touches the current domain of interest: i_d = dom
347  IF (stat(ms) == 1) cycle
348  neighs1 = neighs_lect(ms)
349  DO n = 1, nw
350  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT
351  ! exit when n is not on the interface
352  END DO
353  neighs2 = neigh_lect(n,neighs1)
354  IF (i_d_lect(neighs1) /= list_dom(dom)) THEN
355  IF (neighs2 == 0) cycle ! face on the boundary and does not touch dom yet
356  IF (i_d_lect(neighs2) /= list_dom(dom)) cycle ! dom is on neither sides
357  END IF
358  !End test if ms touches the domain of interest
359 
360  mesh%jjs(:,nouv_els(ms)) = nouv_nd(jjs_lect(:,ms))
361  mesh%neighs(nouv_els(ms)) = nouv_el(neighs_lect(ms))
362  mesh%sides(nouv_els(ms)) = sides_lect(ms)
363  IF (stat(ms)==3) THEN ! side is an interface to be kept
364  neighs1 = neighs_lect(ms)
365  DO n = 1, nw
366  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT ! n not on the interface
367  END DO
368  mesh%neigh(n,nouv_el(neighs1)) = 0
369  neighs2 = neigh_lect(n,neighs1)
370  DO n = 1, nw
371  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs2))) /= 0) EXIT ! n not on the interface
372  END DO
373  mesh%neigh(n,nouv_el(neighs2)) = 0
374  END IF
375  END DO
376 
377  END DO
378  !---Fin renumerotation--------------------------------------------------------
379  !TEST June 11, 2008
380  !write(*,*) 'ok'
381  !allocate(const(mesh%me))
382  !const = 3.d0
383  !do ms = 1, mesh%mes
384  ! const(mesh%neighs(ms)) = mesh%i_d(mesh%neighs(ms))
385  !end do
386  !write(*,*) 'ok'
387  !write(*,*) size(mesh%jj,2), size(const)
388  !call plot_const_p1_label(mesh%jj, mesh%rr, const, 't.plt')
389 
390  !DO ms = 1, mesh%mes
391  ! m = mesh%neighs(ms)
392  ! !Il faut savoir quelle face est la bonne
393  ! DO n = 1, 3
394  ! IF (MINVAL(ABS(mesh%jjs(:,ms)-mesh%jj(n,m)))==0) CYCLE
395  ! face = n
396  ! END DO
397  ! n1 = MODULO(face,3)+1; n2 = MODULO(face+1,3)+1
398  ! IF (mesh%jjs(1,ms)==mesh%jj(n1,m) .AND. mesh%jjs(2,ms)==mesh%jj(n2,m)) THEN
399  ! nface(1)=n1; nface(2)=n2
400  ! ngauss(1)=1; ngauss(2)=2
401  ! ELSE IF (mesh%jjs(1,ms)==mesh%jj(n2,m) .AND. mesh%jjs(2,ms)==mesh%jj(n1,m)) THEN
402  ! nface(1)=n2; nface(2)=n1
403  ! ngauss(1)=2; ngauss(2)=1
404  ! ELSE
405  ! WRITE(*,*) mesh%np
406  ! WRITE(*,*) mesh%rr(:,mesh%jj(n1,m))
407  ! WRITE(*,*) mesh%rr(:,mesh%jj(n2,m))
408  ! WRITE(*,*) mesh%rr(:,mesh%jj(face,m))
409  ! WRITE(*,*) mesh%rr(:,mesh%jjs(1,ms))
410  ! WRITE(*,*) mesh%rr(:,mesh%jjs(2,ms))
411  ! STOP
412  ! END IF
413  !END DO
414  !stop
415  !write(100,*) mesh%neigh
416  !write(100,*) mesh%jj
417  !write(100,*) mesh%i_d
418  !write(100,*) mesh%jjs
419  !write(100,*) mesh%neighs
420  !write(100,*) mesh%mes
421  !write(100,*) mesh%sides
422  !stop
423  !TEST June 11, 2008
424 
425 
426  DEALLOCATE(jj_lect, neigh_lect, i_d_lect)
427  DEALLOCATE(jjs_lect, neighs_lect, sides_lect)
428  DEALLOCATE(rr_lect, virgin_nd, virgin_ms, stat)
429  DEALLOCATE(nouv_nd,nouv_el,nouv_els)
430  ! END OF GRID READING --------------------------------------------------------
431 
432  ALLOCATE(mesh%iis(nws,mesh%mes))
433  CALL dirichlet_nodes(mesh%jjs, spread(1,1,mesh%mes), spread(.true.,1,1), mesh%j_s)
434  CALL surf_nodes_i(mesh%jjs, mesh%j_s, mesh%iis)
435  mesh%nps = SIZE(mesh%j_s)
436 
437  WRITE (20,*) 'np_lect',np,'nw_lect',nw,'nws_lect',nws,'me_lect',me,&
438  'mes_lect',mes
439  WRITE (20,*) 'np ', mesh%np, 'me ', mesh%me, &
440  'mes ',mesh%mes,'nps ', mesh%nps
441  CLOSE(20)
442  CLOSE(30)
443 
444  mesh%edge_stab = .false.
445 
446  END SUBROUTINE load_dg_mesh_free_format
447 
448  !------------------------------------------------------------------------------
449 
450  SUBROUTINE load_mesh_free_format_ordered(dir, fil, list_dom, type_fe, &
451  mesh, mesh_formatted, edge_stab)
452 
453  USE def_type_mesh
454  USE chaine_caractere
455  USE dir_nodes
456 
457  IMPLICIT NONE
458  CHARACTER(len=200), INTENT(IN) :: dir, fil
459  INTEGER, DIMENSION(:), INTENT(IN) :: list_dom
460  INTEGER, INTENT(IN) :: type_fe
461  TYPE(mesh_type) :: mesh
462  LOGICAL, INTENT(IN) :: mesh_formatted !formatted <=> mesh_formatted=.true.
463  LOGICAL, OPTIONAL, INTENT(IN) :: edge_stab
464 
465  INTEGER, ALLOCATABLE, DIMENSION(:) :: nouv_nd, nouv_el, nouv_els, &
466  ancien_nd, ancien_el, ancien_els
467  INTEGER, ALLOCATABLE, DIMENSION(:,:) :: jj_lect, neigh_lect, jjs_lect
468  INTEGER, ALLOCATABLE, DIMENSION(:) :: i_d_lect, sides_lect, neighs_lect
469  LOGICAL, ALLOCATABLE, DIMENSION(:) :: virgin_nd, virgin_el
470  REAL(KIND=8), ALLOCATABLE, DIMENSION(:,:) :: rr_lect
471 
472  LOGICAL :: test
473  INTEGER :: mnouv, nnouv, i, dom
474  INTEGER :: n, m, ms, msnouv, neighs1, neighs2
475  INTEGER :: d_end, f_end
476  INTEGER :: np, nw, me, nws, mes, kd, nwneigh
477  CHARACTER(len=60) :: text
478  CHARACTER(len=2) :: truc
479  text = 'Mesh'
480  d_end = last_c_leng(20, text)
481  DO n = 1, SIZE(list_dom)
482  d_end = last_c_leng(20, text)
483  WRITE(truc,'(i2)') list_dom(n)
484  f_end = start_of_string(truc)
485  text = text(1:d_end)//'_'//truc(f_end:)
486  END DO
487 
488  d_end = last_c_leng(20, text)
489  IF (type_fe==1) THEN
490  text = text(1:d_end)//'_FE_1'
491  ELSE
492  text = text(1:d_end)//'_FE_2'
493  END IF
494  !WRITE (*,*) 'Loading mesh-file ...'
495  !d_end = last_c_leng (64, dir)
496  !f_end = last_c_leng (64, fil)
497  IF (mesh_formatted) THEN
498  OPEN(30,file=trim(adjustl(dir))//'/'//trim(adjustl(fil)),form='formatted')
499  ELSE
500  OPEN(30,file=trim(adjustl(dir))//'/'//trim(adjustl(fil)),form='unformatted')
501  END IF
502  OPEN(unit=20,file=text, form='formatted', status='unknown')
503 
504  ! READ GRID DATA AND ARRAY ALLOCATION ----------------------------------------
505 
506  IF (type_fe == 2) THEN ! Skip P1 data if needed
507  IF (mesh_formatted) THEN
508  READ(30,*) np, nw, me, nws, mes
509  ELSE
510  READ(30) np, nw, me, nws, mes
511  END IF
512 
513  IF (mesh_formatted) THEN
514  DO m = 1, me
515  READ(30,*)
516  END DO
517  ELSE
518  READ(30)
519  END IF
520 
521  IF (mesh_formatted) THEN
522  DO ms = 1, mes
523  READ(30,*)
524  END DO
525  ELSE
526  READ(30)
527  END IF
528 
529  IF (mesh_formatted) THEN
530  DO n = 1, np
531  READ(30,*)
532  END DO
533  ELSE
534  READ(30)
535  END IF
536  END IF
537 
538  IF (mesh_formatted) THEN
539  READ (30, *) np, nw, me, nws, mes
540  ELSE
541  READ(30) np, nw, me, nws, mes
542  END IF
543 
544  IF (nw==3 .AND. nws==2) THEN ! Decide about space dimension
545  kd = 2; nwneigh = 3
546  ELSE IF (nw==6 .AND. nws==3) THEN
547  kd = 2; nwneigh = 3
548  ELSE IF (nw==4 .AND. nws==3) THEN
549  kd = 3; nwneigh = 4
550  ELSE IF (nw==10 .AND. nws==6) THEN
551  kd = 3; nwneigh = 4
552  ELSE
553  WRITE(*,*) ' Finite element not yet programmed '
554  WRITE(*,*) kd, nw, nws
555  stop
556  END IF
557 
558  ALLOCATE (jj_lect(nw,me),neigh_lect(nwneigh,me),i_d_lect(me))
559  ALLOCATE (nouv_nd(np), ancien_nd(np), virgin_nd(np), &
560  nouv_el(0:me), ancien_el(me), virgin_el(me))
561 
562  nouv_el = 0
563 
564  IF (mesh_formatted) THEN
565  DO m = 1, me
566  READ(30,*) jj_lect(:,m), neigh_lect(:,m), i_d_lect(m)
567  END DO
568  ELSE
569  READ(30) jj_lect, neigh_lect, i_d_lect
570  END IF
571 
572 
573 
574  !--- Renumerotation------------------------------------------------------------
575  virgin_nd = .true.
576  virgin_el = .true.
577  mnouv = 0
578  nnouv = 0
579  DO dom = 1, SIZE(list_dom)
580  DO m = 1, me
581  IF (abs(list_dom(dom)-i_d_lect(m)) /= 0) cycle ! i_d(m) dans la liste
582  virgin_el(m) = .false.
583  mnouv = mnouv + 1 ! Nouvel element
584  nouv_el(m) = mnouv
585  ancien_el(mnouv) = m
586  DO n = 1, nw; i = jj_lect(n,m)
587  IF (virgin_nd(i)) THEN ! Nouveau point
588  virgin_nd(i) = .false.
589  nnouv = nnouv + 1
590  nouv_nd(i) = nnouv
591  ancien_nd(nnouv) = i
592  END IF
593  END DO
594  END DO
595  END DO
596  mesh%me = mnouv
597  mesh%np = nnouv
598 
599  ALLOCATE(mesh%jj(nw,mesh%me), mesh%neigh(nwneigh,mesh%me), mesh%i_d(mesh%me))
600 
601  DO m = 1, mesh%me
602  mesh%jj(:,m) = nouv_nd(jj_lect(:,ancien_el(m)))
603  mesh%neigh(:,m) = nouv_el(neigh_lect(:,ancien_el(m)))
604  mesh%i_d(m) = i_d_lect(ancien_el(m))
605  END DO
606 
607  !--- Fin renumerotation--------------------------------------------------------
608  ALLOCATE (jjs_lect(nws,mes), neighs_lect(mes), sides_lect(mes))
609 
610  IF (mesh_formatted) THEN
611  DO ms = 1, mes
612  READ(30,*) jjs_lect(:,ms), neighs_lect(ms), sides_lect(ms)
613  END DO
614  ELSE
615  READ(30) jjs_lect, neighs_lect, sides_lect
616  END IF
617 
618  !--- Renumerotation------------------------------------------------------------
619  ALLOCATE(nouv_els(mes), ancien_els(mes))
620  DEALLOCATE(virgin_el)
621  ALLOCATE(virgin_el(mes))
622  virgin_el = .true.
623  msnouv = 0
624  DO dom = 1, SIZE(list_dom)
625  DO ms = 1, mes
626  neighs1 = neighs_lect(ms)
627  DO n = 1, nw
628  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT
629  END DO
630  neighs2 = neigh_lect(n,neighs1)
631  test = .false.
632  IF (abs(list_dom(dom)-i_d_lect(neighs1)) == 0) THEN
633  test=.true.
634  ELSE IF (neighs2 /= 0) THEN
635  IF (abs(list_dom(dom)-i_d_lect(neighs2)) == 0) THEN
636  test=.true.
637  neighs_lect(ms) = neighs2 ! On change de cote
638  END IF
639  END IF
640 
641  IF (.NOT.test) cycle
642  !11 June 2007
643  IF (.NOT.virgin_el(ms)) cycle
644  !11 June 2007
645  virgin_el(ms) = .false.
646  msnouv = msnouv + 1
647  nouv_els(ms) = msnouv
648  ancien_els(msnouv) = ms
649  END DO
650  END DO
651  mesh%mes = msnouv
652 
653  ALLOCATE (mesh%jjs(nws,mesh%mes), mesh%neighs(mesh%mes), &
654  mesh%sides(mesh%mes))
655 
656  DO ms = 1, mesh%mes
657  mesh%jjs(:,ms) = nouv_nd(jjs_lect(:,ancien_els(ms)))
658  mesh%neighs(ms) = nouv_el(neighs_lect(ancien_els(ms)))
659  mesh%sides(ms) = sides_lect(ancien_els(ms))
660  END DO
661 
662  !--- Fin renumerotation--------------------------------------------------------
663 
664  ALLOCATE(rr_lect(kd,np))
665 
666  IF (mesh_formatted) THEN
667  DO n = 1, np
668  READ(30,*) rr_lect(:,n)
669  END DO
670  ELSE
671  READ(30) rr_lect
672  END IF
673 
674  ALLOCATE(mesh%rr(kd,mesh%np))
675 
676  mesh%rr = rr_lect(:,ancien_nd(1:mesh%np))
677 
678  DEALLOCATE(jj_lect, neigh_lect, i_d_lect)
679  DEALLOCATE(jjs_lect, neighs_lect, sides_lect)
680  DEALLOCATE(rr_lect, virgin_el, virgin_nd)
681  DEALLOCATE(nouv_nd,nouv_el,nouv_els,ancien_nd,ancien_el,ancien_els)
682  ! END OF GRID READING --------------------------------------------------------
683 
684  ALLOCATE(mesh%iis(nws,mesh%mes))
685  CALL dirichlet_nodes(mesh%jjs, spread(1,1,mesh%mes), spread(.true.,1,1), mesh%j_s)
686  CALL surf_nodes_i(mesh%jjs, mesh%j_s, mesh%iis)
687  mesh%nps = SIZE(mesh%j_s)
688 
689  WRITE (20,*) 'np_lect',np,'nw_lect',nw,'nws_lect',nws,'me_lect',me,&
690  'mes_lect',mes
691  WRITE (20,*) 'np ', mesh%np, 'me ', mesh%me, &
692  'mes ',mesh%mes,'nps ', mesh%nps
693 
694  ! CALL Gauss_gen(mesh%np, mesh%me, mesh%nps, mesh%mes, &
695  ! mesh%jj, mesh%jjs, mesh%rr)
696  IF (present(edge_stab)) THEN
697  mesh%edge_stab = edge_stab
698  IF (mesh%edge_stab) CALL prep_interfaces(mesh) ! JLG Fevrier 2010
699  ELSE
700  mesh%edge_stab = .false.
701  END IF
702 
703  CLOSE(20)
704  CLOSE(30)
705 
706  END SUBROUTINE load_mesh_free_format_ordered
707 
708  !------------------------------------------------------------------------------
709 
710  SUBROUTINE load_mesh_free_format(dir, fil, list_dom, type_fe, mesh, mesh_formatted, edge_stab)
711 
712  USE def_type_mesh
713  USE chaine_caractere
714  USE dir_nodes
715 
716  IMPLICIT NONE
717  CHARACTER(len=200), INTENT(IN) :: dir, fil
718  INTEGER, DIMENSION(:), INTENT(IN) :: list_dom
719  INTEGER, INTENT(IN) :: type_fe
720  TYPE(mesh_type) :: mesh
721  LOGICAL, INTENT(IN) :: mesh_formatted !formatted <=> mesh_formatted=.true.
722  LOGICAL, OPTIONAL, INTENT(IN) :: edge_stab
723 
724  INTEGER, ALLOCATABLE, DIMENSION(:) :: nouv_nd, nouv_el, nouv_els, &
725  ancien_nd, ancien_el, ancien_els
726  INTEGER, ALLOCATABLE, DIMENSION(:,:) :: jj_lect, neigh_lect, jjs_lect
727  INTEGER, ALLOCATABLE, DIMENSION(:) :: i_d_lect, sides_lect, neighs_lect
728  LOGICAL, ALLOCATABLE, DIMENSION(:) :: virgin_nd, virgin_el
729  REAL(KIND=8), ALLOCATABLE, DIMENSION(:,:) :: rr_lect
730 
731  LOGICAL :: test
732  INTEGER :: mnouv, nnouv, i
733  INTEGER :: n, m, ms, msnouv, neighs1, neighs2
734  INTEGER :: d_end, f_end
735  INTEGER :: np, nw, me, nws, mes, kd, nwneigh
736  CHARACTER(len=60) :: text
737  CHARACTER(len=2) :: truc
738 
739  text = 'Mesh'
740  d_end = last_c_leng(20, text)
741  DO n = 1, SIZE(list_dom)
742  d_end = last_c_leng(20, text)
743  WRITE(truc,'(i2)') list_dom(n)
744  f_end = start_of_string(truc)
745  text = text(1:d_end)//'_'//truc(f_end:)
746  END DO
747 
748  d_end = last_c_leng(20, text)
749  IF (type_fe==1) THEN
750  text = text(1:d_end)//'_FE_1'
751  ELSE
752  text = text(1:d_end)//'_FE_2'
753  END IF
754 
755  !WRITE (*,*) 'Loading mesh-file ...'
756  !d_end = last_c_leng (64, dir)
757  !f_end = last_c_leng (64, fil)
758  IF (mesh_formatted) THEN
759  OPEN(30,file=trim(adjustl(dir))//'/'//trim(adjustl(fil)),form='formatted')
760  ELSE
761  OPEN(30,file=trim(adjustl(dir))//'/'//trim(adjustl(fil)),form='unformatted')
762  END IF
763  OPEN(unit=20,file=text, form='formatted', status='unknown')
764 
765  ! READ GRID DATA AND ARRAY ALLOCATION ----------------------------------------
766 
767  IF (type_fe == 2) THEN ! Skip P1 data if needed
768  IF (mesh_formatted) THEN
769  READ(30,*) np, nw, me, nws, mes
770  ELSE
771  READ(30) np, nw, me, nws, mes
772  END IF
773 
774  IF (mesh_formatted) THEN
775  DO m = 1, me
776  READ(30,*)
777  END DO
778  ELSE
779  READ(30)
780  END IF
781 
782  IF (mesh_formatted) THEN
783  DO ms = 1, mes
784  READ(30,*)
785  END DO
786  ELSE
787  READ(30)
788  END IF
789 
790  IF (mesh_formatted) THEN
791  DO n = 1, np
792  READ(30,*)
793  END DO
794  ELSE
795  READ(30)
796  END IF
797  END IF
798 
799  IF (mesh_formatted) THEN
800  READ (30, *) np, nw, me, nws, mes
801  ELSE
802  READ(30) np, nw, me, nws, mes
803  END IF
804 
805  IF (nw==3 .AND. nws==2) THEN ! Decide about space dimension
806  kd = 2; nwneigh = 3
807  ELSE IF (nw==6 .AND. nws==3) THEN
808  kd = 2; nwneigh = 3
809  ELSE IF (nw==4 .AND. nws==3) THEN
810  kd = 3; nwneigh = 4
811  ELSE IF (nw==10 .AND. nws==6) THEN
812  kd = 3; nwneigh = 4
813  ELSE
814  WRITE(*,*) ' Finite element not yet programmed '
815  stop
816  END IF
817 
818  ALLOCATE (jj_lect(nw,me),neigh_lect(nwneigh,me),i_d_lect(me))
819  ALLOCATE (nouv_nd(np), ancien_nd(np), virgin_nd(np), &
820  nouv_el(0:me), ancien_el(me), virgin_el(me))
821 
822  nouv_el = 0
823 
824  IF (mesh_formatted) THEN
825  DO m = 1, me
826  READ(30,*) jj_lect(:,m), neigh_lect(:,m), i_d_lect(m)
827  END DO
828  ELSE
829  READ(30) jj_lect, neigh_lect, i_d_lect
830  END IF
831 
832  !---Renumerotation------------------------------------------------------------
833  virgin_nd = .true.
834  virgin_el = .true.
835  mnouv = 0
836  nnouv = 0
837 
838  DO m = 1, me
839  IF (minval(abs(list_dom-i_d_lect(m))) /= 0) cycle ! i_d(m) dans la liste
840  virgin_el(m) = .false.
841  mnouv = mnouv + 1 ! Nouvel element
842  nouv_el(m) = mnouv
843  ancien_el(mnouv) = m
844  DO n = 1, nw; i = jj_lect(n,m)
845  IF (virgin_nd(i)) THEN ! Nouveau point
846  virgin_nd(i) = .false.
847  nnouv = nnouv + 1
848  nouv_nd(i) = nnouv
849  ancien_nd(nnouv) = i
850  END IF
851  END DO
852  END DO
853 
854  mesh%me = mnouv
855  mesh%np = nnouv
856 
857  ALLOCATE(mesh%jj(nw,mesh%me), mesh%neigh(nwneigh,mesh%me), mesh%i_d(mesh%me))
858 
859  DO m = 1, mesh%me
860  mesh%jj(:,m) = nouv_nd(jj_lect(:,ancien_el(m)))
861  mesh%neigh(:,m) = nouv_el(neigh_lect(:,ancien_el(m)))
862  mesh%i_d(m) = i_d_lect(ancien_el(m))
863  END DO
864 
865  !---Fin renumerotation--------------------------------------------------------
866  ALLOCATE (jjs_lect(nws,mes), neighs_lect(mes), sides_lect(mes))
867 
868  IF (mesh_formatted) THEN
869  DO ms = 1, mes
870  READ(30,*) jjs_lect(:,ms), neighs_lect(ms), sides_lect(ms)
871  END DO
872  ELSE
873  READ(30) jjs_lect, neighs_lect, sides_lect
874  END IF
875 
876  !---Renumerotation------------------------------------------------------------
877  ALLOCATE(nouv_els(mes), ancien_els(mes))
878  DEALLOCATE(virgin_el)
879  ALLOCATE(virgin_el(mes))
880  virgin_el = .true.
881  msnouv = 0
882  DO ms = 1, mes
883 
884  neighs1 = neighs_lect(ms)
885  DO n = 1, nw
886  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT
887  END DO
888  neighs2 = neigh_lect(n,neighs1)
889  test = .false.
890  IF (minval(abs(list_dom-i_d_lect(neighs1))) == 0) THEN
891  test=.true.
892  ELSE IF (neighs2 /= 0) THEN
893  IF (minval(abs(list_dom-i_d_lect(neighs2))) == 0) THEN
894  test=.true.
895  neighs_lect(ms) = neighs2 ! On change de cote
896  END IF
897  END IF
898 
899  IF (.NOT.test) cycle
900  virgin_el(ms) = .false.
901  msnouv = msnouv + 1
902  nouv_els(ms) = msnouv
903  ancien_els(msnouv) = ms
904  END DO
905 
906  mesh%mes = msnouv
907 
908  ALLOCATE (mesh%jjs(nws,mesh%mes), mesh%neighs(mesh%mes), &
909  mesh%sides(mesh%mes))
910 
911  DO ms = 1, mesh%mes
912  mesh%jjs(:,ms) = nouv_nd(jjs_lect(:,ancien_els(ms)))
913  mesh%neighs(ms) = nouv_el(neighs_lect(ancien_els(ms)))
914  mesh%sides(ms) = sides_lect(ancien_els(ms))
915  END DO
916 
917  !---Fin renumerotation--------------------------------------------------------
918 
919  ALLOCATE(rr_lect(kd,np))
920 
921  IF (mesh_formatted) THEN
922  DO n = 1, np
923  READ(30,*) rr_lect(:,n)
924  END DO
925  ELSE
926  READ(30) rr_lect
927  END IF
928 
929  ALLOCATE(mesh%rr(kd,mesh%np))
930 
931  mesh%rr = rr_lect(:,ancien_nd(1:mesh%np))
932 
933  DEALLOCATE(jj_lect, neigh_lect, i_d_lect)
934  DEALLOCATE(jjs_lect, neighs_lect, sides_lect)
935  DEALLOCATE(rr_lect, virgin_el, virgin_nd)
936  DEALLOCATE(nouv_nd,nouv_el,nouv_els,ancien_nd,ancien_el,ancien_els)
937  ! END OF GRID READING --------------------------------------------------------
938 
939  ALLOCATE(mesh%iis(nws,mesh%mes))
940  CALL dirichlet_nodes(mesh%jjs, spread(1,1,mesh%mes), spread(.true.,1,1), mesh%j_s)
941  CALL surf_nodes_i(mesh%jjs, mesh%j_s, mesh%iis)
942  mesh%nps = SIZE(mesh%j_s)
943 
944  WRITE (20,*) 'np_lect',np,'nw_lect',nw,'nws_lect',nws,'me_lect',me,&
945  'mes_lect',mes
946  WRITE (20,*) 'np ', mesh%np, 'me ', mesh%me, &
947  'mes ',mesh%mes,'nps ', mesh%nps
948 
949  ! CALL Gauss_gen(mesh%np, mesh%me, mesh%nps, mesh%mes, &
950  ! mesh%jj, mesh%jjs, mesh%rr)
951  IF (present(edge_stab)) THEN
952  mesh%edge_stab = edge_stab
953  IF (mesh%edge_stab) CALL prep_interfaces(mesh) ! JLG April 2009
954  ELSE
955  mesh%edge_stab = .false.
956  END IF
957 
958  CLOSE(20)
959  CLOSE(30)
960 
961  END SUBROUTINE load_mesh_free_format
962 
963  !------------------------------------------------------------------------------
964 
965  SUBROUTINE load_mesh_formatted(dir, fil, list_dom, type_fe, mesh)
966 
967  USE def_type_mesh
968  USE chaine_caractere
969  USE dir_nodes
970 
971  IMPLICIT NONE
972  CHARACTER(len=200), INTENT(IN) :: dir, fil
973  INTEGER, DIMENSION(:), INTENT(IN) :: list_dom
974  INTEGER, INTENT(IN) :: type_fe
975  TYPE(mesh_type) :: mesh
976 
977  INTEGER, ALLOCATABLE, DIMENSION(:) :: nouv_nd, nouv_el, nouv_els, &
978  ancien_nd, ancien_el, ancien_els
979  INTEGER, ALLOCATABLE, DIMENSION(:,:) :: jj_lect, neigh_lect, jjs_lect
980  INTEGER, ALLOCATABLE, DIMENSION(:) :: i_d_lect, sides_lect, neighs_lect
981  LOGICAL, ALLOCATABLE, DIMENSION(:) :: virgin_nd, virgin_el
982  REAL(KIND=8), ALLOCATABLE, DIMENSION(:,:) :: rr_lect
983 
984  LOGICAL :: test
985  INTEGER :: mnouv, nnouv, i
986  INTEGER :: n, m, ms, msnouv, neighs1, neighs2
987  INTEGER :: d_end, f_end
988  INTEGER :: np, nw, me, nws, mes, kd, nwneigh
989 
990  d_end = last_c_leng(64, dir)
991  f_end = last_c_leng(64, fil)
992 
993  !WRITE (*,*) 'Loading mesh-file ...'
994 
995  OPEN(30,file=trim(adjustl(dir))//'/'//trim(adjustl(fil)),form='formatted')
996  !OPEN(30,FILE=dir(1:d_end)//'/'//fil(1:f_end),FORM='unformatted')
997  OPEN(unit=20,file='error_mesh', form='formatted',status='unknown')
998 
999  ! READ GRID DATA AND ARRAY ALLOCATION ----------------------------------------
1000 
1001  IF (type_fe == 2) THEN ! Skip P1 data if needed
1002  READ(30,*) np, nw, me, nws, mes
1003  !READ(30) np, nw, me, nws, mes
1004  DO m = 1, me
1005  READ(30,*)
1006  END DO
1007  !READ(30)
1008  DO ms = 1, mes
1009  READ(30,*)
1010  END DO
1011  !READ(30)
1012  DO n = 1, np
1013  READ(30,*)
1014  END DO
1015  !READ(30)
1016  END IF
1017 
1018  READ (30, *) np, nw, me, nws, mes
1019  !READ (30) np, nw, me, nws, mes
1020 
1021  IF (nw==3 .AND. nws==2) THEN ! Decide about space dimension
1022  kd = 2; nwneigh = 3
1023  ELSE IF (nw==6 .AND. nws==3) THEN
1024  kd = 2; nwneigh = 3
1025  ELSE IF (nw==4 .AND. nws==3) THEN
1026  kd = 3; nwneigh = 4
1027  ELSE IF (nw==10 .AND. nws==6) THEN
1028  kd = 3; nwneigh = 4
1029  ELSE
1030  WRITE(*,*) ' Finite element not yet programmed '
1031  stop
1032  END IF
1033 
1034  ALLOCATE (jj_lect(nw,me),neigh_lect(nwneigh,me),i_d_lect(me))
1035  ALLOCATE (nouv_nd(np), ancien_nd(np), virgin_nd(np), &
1036  nouv_el(0:me), ancien_el(me), virgin_el(me))
1037 
1038  nouv_el = 0
1039 
1040  DO m = 1, me
1041  READ(30,*) jj_lect(:,m), neigh_lect(:,m), i_d_lect(m)
1042  END DO
1043 
1044  !READ(30) jj_lect, neigh_lect, i_d_lect
1045 
1046  !---Renumerotation------------------------------------------------------------
1047  virgin_nd = .true.
1048  virgin_el = .true.
1049  mnouv = 0
1050  nnouv = 0
1051 
1052  DO m = 1, me
1053  IF (minval(abs(list_dom-i_d_lect(m))) /= 0) cycle ! i_d(m) dans la liste
1054  virgin_el(m) = .false.
1055  mnouv = mnouv + 1 ! Nouvel element
1056  nouv_el(m) = mnouv
1057  ancien_el(mnouv) = m
1058  DO n = 1, nw; i = jj_lect(n,m)
1059  IF (virgin_nd(i)) THEN ! Nouveau point
1060  virgin_nd(i) = .false.
1061  nnouv = nnouv + 1
1062  nouv_nd(i) = nnouv
1063  ancien_nd(nnouv) = i
1064  END IF
1065  END DO
1066  END DO
1067 
1068  mesh%me = mnouv
1069  mesh%np = nnouv
1070 
1071  ALLOCATE(mesh%jj(nw,mesh%me), mesh%neigh(nwneigh,mesh%me), mesh%i_d(mesh%me))
1072 
1073  DO m = 1, mesh%me
1074  mesh%jj(:,m) = nouv_nd(jj_lect(:,ancien_el(m)))
1075  mesh%neigh(:,m) = nouv_el(neigh_lect(:,ancien_el(m)))
1076  mesh%i_d(m) = i_d_lect(ancien_el(m))
1077  END DO
1078 
1079  !---Fin renumerotation--------------------------------------------------------
1080  ALLOCATE (jjs_lect(nws,mes), neighs_lect(mes), sides_lect(mes))
1081 
1082  DO ms = 1, mes
1083  READ(30,*) jjs_lect(:,ms), neighs_lect(ms), sides_lect(ms)
1084  END DO
1085 
1086  !READ(30) jjs_lect, neighs_lect, sides_lect
1087 
1088  !---Renumerotation------------------------------------------------------------
1089  ALLOCATE(nouv_els(mes), ancien_els(mes))
1090  DEALLOCATE(virgin_el)
1091  ALLOCATE(virgin_el(mes))
1092  virgin_el = .true.
1093  msnouv = 0
1094  DO ms = 1, mes
1095  neighs1 = neighs_lect(ms)
1096  DO n = 1, nw
1097  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT
1098  END DO
1099  neighs2 = neigh_lect(n,neighs1)
1100  test = .false.
1101  IF (minval(abs(list_dom-i_d_lect(neighs1))) == 0) THEN
1102  test=.true.
1103  ELSE IF (neighs2 /= 0) THEN
1104  IF (minval(abs(list_dom-i_d_lect(neighs2))) == 0) THEN
1105  test=.true.
1106  neighs_lect(ms) = neighs2 ! On change de cote
1107  END IF
1108  END IF
1109  IF (.NOT.test) cycle
1110  virgin_el(ms) = .false.
1111  msnouv = msnouv + 1
1112  nouv_els(ms) = msnouv
1113  ancien_els(msnouv) = ms
1114  END DO
1115 
1116  mesh%mes = msnouv
1117 
1118  ALLOCATE (mesh%jjs(nws,mesh%mes), mesh%neighs(mesh%mes), &
1119  mesh%sides(mesh%mes))
1120 
1121  DO ms = 1, mesh%mes
1122  mesh%jjs(:,ms) = nouv_nd(jjs_lect(:,ancien_els(ms)))
1123  mesh%neighs(ms) = nouv_el(neighs_lect(ancien_els(ms)))
1124  mesh%sides(ms) = sides_lect(ancien_els(ms))
1125  END DO
1126 
1127  !---Fin renumerotation--------------------------------------------------------
1128 
1129  ALLOCATE(rr_lect(kd,np))
1130 
1131  DO n = 1, np
1132  READ(30,*) rr_lect(:,n)
1133  END DO
1134  !READ(30) rr_lect
1135 
1136  ALLOCATE(mesh%rr(kd,mesh%np))
1137 
1138  mesh%rr = rr_lect(:,ancien_nd(1:mesh%np))
1139 
1140  DEALLOCATE(jj_lect, neigh_lect, i_d_lect)
1141  DEALLOCATE(jjs_lect, neighs_lect, sides_lect)
1142  DEALLOCATE(rr_lect, virgin_el, virgin_nd)
1143  DEALLOCATE(nouv_nd,nouv_el,nouv_els,ancien_nd,ancien_el,ancien_els)
1144  ! END OF GRID READING --------------------------------------------------------
1145 
1146  ALLOCATE(mesh%iis(nws,mesh%mes))
1147  CALL dirichlet_nodes(mesh%jjs, spread(1,1,mesh%mes), spread(.true.,1,1), mesh%j_s)
1148  CALL surf_nodes_i(mesh%jjs, mesh%j_s, mesh%iis)
1149  mesh%nps = SIZE(mesh%j_s)
1150 
1151  WRITE (20,*) 'np_lect',np,'nw_lect',nw,'nws_lect',nws,'me_lect',me,&
1152  'mes_lect',mes
1153  WRITE (20,*) 'np ', mesh%np, 'me ', mesh%me, &
1154  'mes ',mesh%mes,'nps ', mesh%nps
1155 
1156  ! CALL Gauss_gen(mesh%np, mesh%me, mesh%nps, mesh%mes, &
1157  ! mesh%jj, mesh%jjs, mesh%rr)
1158 
1159  CLOSE(20)
1160  CLOSE(30)
1161 
1162  END SUBROUTINE load_mesh_formatted
1163 
1164  SUBROUTINE load_mesh(dir, fil, list_dom, type_fe, mesh)
1165 
1166  USE def_type_mesh
1167  USE chaine_caractere
1168  !USE gauss_points
1169  USE dir_nodes
1170 
1171  IMPLICIT NONE
1172  CHARACTER(len=200), INTENT(IN) :: dir, fil
1173  INTEGER, DIMENSION(:), INTENT(IN) :: list_dom
1174  INTEGER, INTENT(IN) :: type_fe
1175  TYPE(mesh_type) :: mesh
1176 
1177  INTEGER, ALLOCATABLE, DIMENSION(:) :: nouv_nd, nouv_el, nouv_els, &
1178  ancien_nd, ancien_el, ancien_els
1179  INTEGER, ALLOCATABLE, DIMENSION(:,:) :: jj_lect, neigh_lect, jjs_lect
1180  INTEGER, ALLOCATABLE, DIMENSION(:) :: i_d_lect, sides_lect, neighs_lect
1181  LOGICAL, ALLOCATABLE, DIMENSION(:) :: virgin_nd, virgin_el
1182  REAL(KIND=8), ALLOCATABLE, DIMENSION(:,:) :: rr_lect
1183 
1184  LOGICAL :: test
1185  INTEGER :: mnouv, nnouv, i
1186  INTEGER :: n, m, ms, msnouv, neighs1, neighs2
1187  INTEGER :: d_end, f_end
1188  INTEGER :: np, nw, me, nws, mes, kd, nwneigh
1189  CHARACTER(len=20) :: text
1190  CHARACTER(len=2) :: truc
1191 
1192  text = 'Mesh'
1193  d_end = last_c_leng(20, text)
1194  DO n = 1, SIZE(list_dom)
1195  d_end = last_c_leng(20, text)
1196  WRITE(truc,'(i2)') list_dom(n)
1197  f_end = start_of_string(truc)
1198  text = text(1:d_end)//'_'//truc(f_end:)
1199  END DO
1200 
1201  d_end = last_c_leng(20, text)
1202  IF (type_fe==1) THEN
1203  text = text(1:d_end)//'_FE_1'
1204  ELSE
1205  text = text(1:d_end)//'_FE_2'
1206  END IF
1207 
1208  !WRITE (*,*) 'Loading mesh-file ...'
1209  d_end = last_c_leng(64, dir)
1210  f_end = last_c_leng(64, fil)
1211  !OPEN(30,FILE=dir(1:d_end)//'/'//fil(1:f_end),FORM='formatted')
1212  OPEN(30,file=trim(adjustl(dir))//'/'//trim(adjustl(fil)),form='unformatted')
1213  OPEN(unit=20,file=text, form='formatted', status='unknown')
1214 
1215  ! READ GRID DATA AND ARRAY ALLOCATION ----------------------------------------
1216 
1217  IF (type_fe == 2) THEN ! Skip P1 data if needed
1218  !READ(30,*) np, nw, me, nws, mes
1219  READ(30) np, nw, me, nws, mes
1220 
1221  !DO m = 1, me
1222  ! READ(30,*)
1223  !END DO
1224  READ(30)
1225 
1226  !DO ms = 1, mes
1227  ! READ(30,*)
1228  !END DO
1229 
1230  ! DO m = 1, mes
1231  ! READ(30)
1232  ! END DO
1233  READ(30)
1234 
1235  !DO n = 1, np
1236  ! READ(30,*)
1237  !END DO
1238  READ(30)
1239  END IF
1240 
1241  !READ (30, *) np, nw, me, nws, mes
1242  READ(30) np, nw, me, nws, mes
1243 
1244  IF (nw==3 .AND. nws==2) THEN ! Decide about space dimension
1245  kd = 2; nwneigh = 3
1246  ELSE IF (nw==6 .AND. nws==3) THEN
1247  kd = 2; nwneigh = 3
1248  ELSE IF (nw==4 .AND. nws==3) THEN
1249  kd = 3; nwneigh = 4
1250  ELSE IF (nw==10 .AND. nws==6) THEN
1251  kd = 3; nwneigh = 4
1252  ELSE
1253  WRITE(*,*) ' Finite element not yet programmed '
1254  stop
1255  END IF
1256 
1257  ALLOCATE (jj_lect(nw,me),neigh_lect(nwneigh,me),i_d_lect(me))
1258  ALLOCATE (nouv_nd(np), ancien_nd(np), virgin_nd(np), &
1259  nouv_el(0:me), ancien_el(me), virgin_el(me))
1260 
1261  nouv_el = 0
1262 
1263  !DO m = 1, me
1264  ! READ(30,*) jj_lect(:,m), neigh_lect(:,m), i_d_lect(m)
1265  !END DO
1266 
1267  READ(30) jj_lect, neigh_lect, i_d_lect
1268 
1269  !---Renumerotation------------------------------------------------------------
1270  virgin_nd = .true.
1271  virgin_el = .true.
1272  mnouv = 0
1273  nnouv = 0
1274 
1275  DO m = 1, me
1276  IF (minval(abs(list_dom-i_d_lect(m))) /= 0) cycle ! i_d(m) dans la liste
1277  virgin_el(m) = .false.
1278  mnouv = mnouv + 1 ! Nouvel element
1279  nouv_el(m) = mnouv
1280  ancien_el(mnouv) = m
1281  DO n = 1, nw; i = jj_lect(n,m)
1282  IF (virgin_nd(i)) THEN ! Nouveau point
1283  virgin_nd(i) = .false.
1284  nnouv = nnouv + 1
1285  nouv_nd(i) = nnouv
1286  ancien_nd(nnouv) = i
1287  END IF
1288  END DO
1289  END DO
1290 
1291  mesh%me = mnouv
1292  mesh%np = nnouv
1293 
1294  ALLOCATE(mesh%jj(nw,mesh%me), mesh%neigh(nwneigh,mesh%me), mesh%i_d(mesh%me))
1295 
1296  DO m = 1, mesh%me
1297  mesh%jj(:,m) = nouv_nd(jj_lect(:,ancien_el(m)))
1298  mesh%neigh(:,m) = nouv_el(neigh_lect(:,ancien_el(m)))
1299  mesh%i_d(m) = i_d_lect(ancien_el(m))
1300  END DO
1301 
1302  !---Fin renumerotation--------------------------------------------------------
1303  ALLOCATE (jjs_lect(nws,mes), neighs_lect(mes), sides_lect(mes))
1304 
1305  !DO ms = 1, mes
1306  ! READ(30,*) jjs_lect(:,ms), neighs_lect(ms), sides_lect(ms)
1307  !END DO
1308 
1309 
1310  !TEST
1311  !DO ms = 1, mes
1312  !READ(30) jjs_lect(:,ms), neighs_lect(ms), sides_lect(ms)
1313  !END DO
1314  !TEST
1315  READ(30) jjs_lect, neighs_lect, sides_lect
1316 
1317  !---Renumerotation------------------------------------------------------------
1318  ALLOCATE(nouv_els(mes), ancien_els(mes))
1319  DEALLOCATE(virgin_el)
1320  ALLOCATE(virgin_el(mes))
1321  virgin_el = .true.
1322  msnouv = 0
1323  DO ms = 1, mes
1324 
1325  neighs1 = neighs_lect(ms)
1326  DO n = 1, nw
1327  IF (minval(abs(jjs_lect(:,ms)-jj_lect(n,neighs1))) /= 0) EXIT
1328  END DO
1329  neighs2 = neigh_lect(n,neighs1)
1330  test = .false.
1331  IF (minval(abs(list_dom-i_d_lect(neighs1))) == 0) THEN
1332  test=.true.
1333  ELSE IF (neighs2 /= 0) THEN
1334  IF (minval(abs(list_dom-i_d_lect(neighs2))) == 0) THEN
1335  test=.true.
1336  neighs_lect(ms) = neighs2 ! On change de cote
1337  END IF
1338  END IF
1339 
1340  IF (.NOT.test) cycle
1341  virgin_el(ms) = .false.
1342  msnouv = msnouv + 1
1343  nouv_els(ms) = msnouv
1344  ancien_els(msnouv) = ms
1345  END DO
1346 
1347  mesh%mes = msnouv
1348 
1349  ALLOCATE (mesh%jjs(nws,mesh%mes), mesh%neighs(mesh%mes), &
1350  mesh%sides(mesh%mes))
1351 
1352  DO ms = 1, mesh%mes
1353  mesh%jjs(:,ms) = nouv_nd(jjs_lect(:,ancien_els(ms)))
1354  mesh%neighs(ms) = nouv_el(neighs_lect(ancien_els(ms)))
1355  mesh%sides(ms) = sides_lect(ancien_els(ms))
1356  END DO
1357 
1358  !---Fin renumerotation--------------------------------------------------------
1359 
1360  ALLOCATE(rr_lect(kd,np))
1361 
1362  !DO n = 1, np
1363  ! READ(30,*) rr_lect(:,n)
1364  !END DO
1365 
1366  READ(30) rr_lect
1367 
1368  ALLOCATE(mesh%rr(kd,mesh%np))
1369 
1370  mesh%rr = rr_lect(:,ancien_nd(1:mesh%np))
1371 
1372  DEALLOCATE(jj_lect, neigh_lect, i_d_lect)
1373  DEALLOCATE(jjs_lect, neighs_lect, sides_lect)
1374  DEALLOCATE(rr_lect, virgin_el, virgin_nd)
1375  DEALLOCATE(nouv_nd,nouv_el,nouv_els,ancien_nd,ancien_el,ancien_els)
1376  ! END OF GRID READING --------------------------------------------------------
1377 
1378  ALLOCATE(mesh%iis(nws,mesh%mes))
1379  CALL dirichlet_nodes(mesh%jjs, spread(1,1,mesh%mes), spread(.true.,1,1), mesh%j_s)
1380  CALL surf_nodes_i(mesh%jjs, mesh%j_s, mesh%iis)
1381  mesh%nps = SIZE(mesh%j_s)
1382 
1383  WRITE (20,*) 'np_lect',np,'nw_lect',nw,'nws_lect',nws,'me_lect',me,&
1384  'mes_lect',mes
1385  WRITE (20,*) 'np ', mesh%np, 'me ', mesh%me, &
1386  'mes ',mesh%mes,'nps ', mesh%nps
1387 
1388  CLOSE(20)
1389  CLOSE(30)
1390 
1391  END SUBROUTINE load_mesh
1392 
1393 
1394  SUBROUTINE surf_nodes_i(jjs, j_s, iis)
1395 
1396  ! generation of the surface element connectivity matrix iis
1397  ! based on the surface node numbering, starting from the
1398  ! connectivity matrix jjs of the surface elements according
1399  ! to the volume node numbering, and from the array j_s of
1400  ! the boundary nodes according to the volume node numbering
1401 
1402  IMPLICIT NONE
1403 
1404  INTEGER, DIMENSION(:,:), INTENT(IN) :: jjs
1405  INTEGER, DIMENSION(:), INTENT(IN) :: j_s
1406  INTEGER, DIMENSION(:,:), INTENT(OUT) :: iis
1407 
1408  INTEGER :: ms, ls, j, i
1409 
1410  DO ms = 1, SIZE(jjs,2)
1411  DO ls = 1, SIZE(jjs,1)
1412  j = jjs(ls,ms)
1413  DO i = 1, SIZE(j_s)
1414  IF ( j == j_s(i) ) iis(ls,ms) = i
1415  ENDDO
1416  ENDDO
1417  ENDDO
1418 
1419  END SUBROUTINE surf_nodes_i
1420 
1421  SUBROUTINE prep_interfaces(mesh)
1422  USE def_type_mesh
1423  IMPLICIT NONE
1424  TYPE(mesh_type) :: mesh
1425  LOGICAL, DIMENSION(mesh%me) :: virgin
1426  INTEGER :: m, mop, nw, me, l, lop, n, n1, n2, edge, nt,nws
1427  nw = SIZE(mesh%jj,1)
1428  nws = SIZE(mesh%jjs,1)
1429  me = mesh%me
1430  IF (SIZE(mesh%rr,1)==2) THEN
1431  nt=3
1432  ELSE
1433  WRITE(*,*) ' BUG: prep_interfaces, 3D not programmed yet '
1434  stop
1435  nt=4
1436  END IF
1437 
1438  virgin = .true.
1439  edge = 0
1440  DO m = 1, me
1441  virgin(m) = .false.
1442  DO n = 1, nt
1443  mop = mesh%neigh(n,m)
1444  IF (mop==0) cycle !Edge on boundary
1445  IF (.NOT.virgin(mop)) cycle !Edge already done
1446  edge = edge + 1 !New edge
1447  END DO
1448  END DO
1449  IF (SIZE(mesh%rr,1)==2) THEN
1450  IF (edge/=(3*mesh%me - mesh%mes)/2) THEN
1451  WRITE(*,*) ' BUG in prep_interfaces, edge/=(3*mesh%me + mesh%mes)/2'
1452  WRITE(*,*) ' edge ', edge, (3*mesh%me - mesh%mes)/2
1453  WRITE(*,*) ' mesh%mes ', mesh%mes, ' mesh%me ',mesh%me
1454  stop
1455  END IF
1456  END IF
1457 
1458  mesh%mi = edge
1459  ALLOCATE(mesh%jji(nw,2,edge), mesh%jjsi(nws,edge),mesh%neighi(2,edge) )
1460 
1461  edge = 0
1462  virgin = .true.
1463  DO m = 1, me
1464  virgin(m) = .false.
1465  DO n = 1, nt
1466  mop = mesh%neigh(n,m)
1467  IF (mop==0) cycle !Edge on boundary
1468  IF (.NOT.virgin(mop)) cycle !Edge already done
1469  edge = edge + 1 !New edge
1470  n1 = modulo(n,nt) + 1
1471  n2 = modulo(n+1,nt) + 1 ! Works in 2D only
1472  mesh%jjsi(1,edge) = mesh%jj(n1,m)
1473  mesh%jjsi(2,edge) = mesh%jj(n2,m)
1474  IF (nws==3) THEN
1475  IF (n1+n2==3) THEN
1476  mesh%jjsi(3,edge) = mesh%jj(6,m)
1477  ELSE IF (n1+n2==5) THEN
1478  mesh%jjsi(3,edge) = mesh%jj(4,m)
1479  ELSE IF (n1+n2==4) THEN
1480  mesh%jjsi(3,edge) = mesh%jj(5,m)
1481  ELSE
1482  WRITE(*,*) ' BUG prep_interfaces n1+n2 not correct '
1483  stop
1484  END IF
1485  END IF
1486  IF (m<mop) THEN
1487  l = 1 ! Side 1 on smallest cell index
1488  lop = 2
1489  mesh%neighi(1,edge) = m
1490  mesh%neighi(2,edge) = mop
1491  ELSE
1492  l = 2 ! Side 2 on largest cell index
1493  lop = 1
1494  mesh%neighi(1,edge) = mop
1495  mesh%neighi(2,edge) = m
1496  END IF
1497  DO n1 = 1, nw
1498  mesh%jji(n1,l,edge) = mesh%jj(n1,m)
1499  mesh%jji(n1,lop,edge) = mesh%jj(n1,mop)
1500  END DO
1501  END DO
1502  END DO
1503 
1504  END SUBROUTINE prep_interfaces
1505 
1506 END MODULE prep_maill
1507 
1508 
1509 
1510 
subroutine, public load_mesh_formatted(dir, fil, list_dom, type_fe, mesh)
Definition: prep_mesh.f90:965
subroutine, public load_mesh(dir, fil, list_dom, type_fe, mesh)
Definition: prep_mesh.f90:1164
integer function, public start_of_string(string)
subroutine, public load_dg_mesh_free_format(dir, fil, list_dom, list_inter, type_fe, mesh, mesh_formatted)
Definition: prep_mesh.f90:16
section doc_intro_frame_work_num_app Numerical approximation subsection doc_intro_fram_work_num_app_Fourier_FEM Fourier Finite element representation The SFEMaNS code uses a hybrid Fourier Finite element formulation The Fourier decomposition allows to approximate the problem’s solutions for each Fourier mode modulo nonlinear terms that are made explicit The variables are then approximated on a meridian section of the domain with a finite element method The numerical approximation of a function f $f f is written in the following generic f with f $t f the time and f $M f the number of Fourier modes considered The unknown f f f f f f f f Omega_v f and f Omega f We also consider f a penalty method of the divergence of the velocity field is also implemented The method proceeds as the pressure and the pressure increments< li > For f $n geq0 f let f that matches the Dirichlet boundary conditions of the be the solutions of the following formulation for all f f text
Definition: doc_intro.h:342
subroutine, public load_mesh_free_format(dir, fil, list_dom, type_fe, mesh, mesh_formatted, edge_stab)
Definition: prep_mesh.f90:710
subroutine surf_nodes_i(jjs, j_s, iis)
Definition: prep_mesh.f90:1394
subroutine dirichlet_nodes(jjs_in, sides_in, dir_in, js_d)
Definition: dir_nodes.f90:495
subroutine, public load_mesh_free_format_ordered(dir, fil, list_dom, type_fe, mesh, mesh_formatted, edge_stab)
Definition: prep_mesh.f90:450
integer function, public last_c_leng(len_str, string)
subroutine, public prep_interfaces(mesh)
Definition: prep_mesh.f90:1421
section doc_intro_frame_work_num_app Numerical approximation subsection doc_intro_fram_work_num_app_Fourier_FEM Fourier Finite element representation The SFEMaNS code uses a hybrid Fourier Finite element formulation The Fourier decomposition allows to approximate the problem’s solutions for each Fourier mode modulo nonlinear terms that are made explicit The variables are then approximated on a meridian section of the domain with a finite element method The numerical approximation of a function f $f f is written in the following generic form
Definition: doc_intro.h:193