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