40 u gridman_unit,gridman_dbg,gridman_check
44 INTRINSIC sqrt,huge,max,trim,tiny
58 REAL(GRIDMAN_DP),
INTENT(IN) :: TOL
60 INTEGER,
INTENT(OUT) :: IERR
62 INTEGER(GRIDMAN_SP) ::
63 i iedge,iedge1,iedge2,nedges,enedges,nedges0,
64 i p(2),q(2),npoints,ipoint,ind(6),
65 i ipoint1,ipoint2, npoints1,ncells,tpq(2,2),
67 i cells(2,2*grid1%NEDGES+2*grid2%NEDGES),
68 i mapp(grid2%NPOINTS),
69 i rpoints(grid2%NPOINTS)
70 INTEGER(GRIDMAN_SP) ::
71 i imape1(2,grid1%NEDGES+grid2%NEDGES),
72 i imape2(2,grid1%NEDGES+grid2%NEDGES),
73 i lmap0(max(grid1%NEDGES,grid2%NEDGES))
74 INTEGER :: RES,IERR0,NEDGEINDEX,NCELLINDEX,II,II2
76 LOGICAL MEDGE1(grid1%nedges),MEDGE2(grid2%nedges)
78 REAL(GRIDMAN_DP) :: LE1(grid1%nedges),
80 REAL(GRIDMAN_DP) :: XP(2),YP(2),XQ(2),YQ(2),
81 r x1,y1,x2,y2,dlp,dlq,fscl,dlt,eps
84 f
WRITE(gridman_unit,*)
"Starting GRIDMAN_GRID2D_MERGE"
88 IF(grid1%TYPE.NE.2.OR.grid1%PDIM.NE.2.OR.grid1%EDIM.NE.2)
THEN
90 WRITE(gridman_unit,*)
"GRIDMAN_GRID2D_TRIANG: ",
91 w
"1st grid is not of 2D type"
92 WRITE(gridman_unit,*)
" TYPE, PDIM, EDIM ",
93 w grid1%TYPE,grid1%PDIM,grid1%EDIM
97 IF(grid2%TYPE.NE.2.OR.grid2%PDIM.NE.2.OR.grid2%EDIM.NE.2)
THEN
99 WRITE(gridman_unit,*)
"GRIDMAN_GRID2D_TRIANG: ",
100 w
"1st grid is not of 2D type"
101 WRITE(gridman_unit,*)
" TYPE, PDIM, EDIM ",
102 w grid2%TYPE,grid2%PDIM,grid2%EDIM
106 IF(gridman_check)
THEN
108 IF(res.NE.0.OR.ierr.GT.0)
THEN
110 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
115 IF(res.NE.0.OR.ierr.GT.0)
THEN
117 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
125 IF(grid1%UNIT2SI.LT.eps)
THEN
127 WRITE(gridman_unit,*)
"ERROR detected in GRIDMAN_GRID2D_MERGE: ",
129 WRITE(gridman_unit,*)
" GRID1%UNIT2SI ",grid1%UNIT2SI
132 fscl=grid2%UNIT2SI/grid1%UNIT2SI
138 npoints=grid1%NPOINTS
146 DO iedge1=1,grid1%NEDGES
147 IF(grid1%CELLS(1,iedge1).GT.0.AND.
148 f grid1%CELLS(2,iedge1).GT.0) cycle
150 p(1)=grid1%POINTS(1,iedge1)
151 p(2)=grid1%POINTS(2,iedge1)
152 xp(1)=grid1%X(1,p(1))
153 yp(1)=grid1%X(2,p(1))
154 xp(2)=grid1%X(1,p(2))
155 yp(2)=grid1%X(2,p(2))
156 DO iedge2=1,grid2%NEDGES
157 IF(grid2%CELLS(1,iedge2).GT.0.AND.
158 f grid2%CELLS(2,iedge2).GT.0) cycle
160 q(1)=grid2%POINTS(1,iedge2)
161 q(2)=grid2%POINTS(2,iedge2)
162 xq(1)=grid2%X(1,q(1))*fscl
163 yq(1)=grid2%X(2,q(1))*fscl
164 xq(2)=grid2%X(1,q(2))*fscl
165 yq(2)=grid2%X(2,q(2))*fscl
170 CALL find_overlap(p,q,xp,yp,xq,yq,tol,ind,tpq)
175 IF(ind(3).GT.0.AND.ind(4).GT.0)
THEN
178 points(1,nedges)=ind(3)
179 points(2,nedges)=ind(4)
180 cells(1,nedges)=nonzer_cell(grid1%CELLS(:,iedge1))
181 cells(2,nedges)=nonzer_cell(grid2%CELLS(:,iedge2))
182 IF(cells(2,nedges).GT.0) cells(2,nedges)=cells(2,nedges)+ncells
183 medge1(iedge1)=.false.
184 medge2(iedge2)=.false.
188 IF(ipoint1.GT.npoints)
THEN
189 x1=grid2%X(1,ipoint1-npoints)*fscl
190 y1=grid2%X(2,ipoint1-npoints)*fscl
192 x1=grid1%X(1,ipoint1)
193 y1=grid1%X(2,ipoint1)
196 IF(ipoint2.GT.npoints)
THEN
197 x2=grid2%X(1,ipoint2-npoints)*fscl
198 y2=grid2%X(2,ipoint2-npoints)*fscl
200 x2=grid1%X(1,ipoint2)
201 y2=grid1%X(2,ipoint2)
203 dlp=sqrt((x1-x2)**2+(y1-y2)**2)
204 le1(iedge1)=le1(iedge1)+dlp
205 le2(iedge2)=le2(iedge2)+dlp
207 imape1(1,nedges)=iedge1
208 imape1(2,nedges)=nedges
209 imape2(1,nedges)=iedge2
210 imape2(2,nedges)=nedges
215 IF(ipoint1.GT.0) rpoints(tpq(1,1)-npoints)=ipoint1
216 IF(ipoint2.GT.0) rpoints(tpq(1,2)-npoints)=ipoint2
222 WRITE(gridman_unit,*)
"WARNING from GRIDMAN_GRID2D_MERGE:",
223 " grids are not attached (no common edges)"
230 DO ipoint2=1,grid2%NPOINTS
231 ipoint1=rpoints(ipoint2)
232 IF(ipoint1.GT.0)
THEN
233 x1=grid1%X(1,ipoint1)
234 x2=grid2%X(1,ipoint2)*fscl
235 y1=grid1%X(2,ipoint1)
236 y2=grid2%X(2,ipoint2)*fscl
237 dlp=(x1-x2)**2+(y1-y2)**2
238 dlt=abs(x2-x1)*(abs(x1)+abs(x2)+eps)+
239 + abs(y2-y1)*(abs(y1)+abs(y2)+eps)
243 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
245 WRITE(gridman_unit,*)
246 w
"points marked as overlapped are not same, "
247 WRITE(gridman_unit,*)
248 w
" IPOINT1, IPOINT2, DLP, DLT, TOL",
249 w ipoint1, ipoint2, dlp, dlt, tol
250 WRITE(gridman_unit,*)
" X1, Y1 ",x1,y1
251 WRITE(gridman_unit,*)
" X2, Y2 ",x2,y2
258 DO iedge1=1,grid1%NEDGES
259 IF(.NOT.medge1(iedge1))
THEN
260 ipoint=grid1%POINTS(1,iedge1)
263 ipoint=grid1%POINTS(2,iedge1)
266 dlp=(x1-x2)**2+(y1-y2)**2
268 dlt=abs(x2-x1)*(abs(x1)+abs(x2)+eps)+
269 + abs(y2-y1)*(abs(y1)+abs(y2)+eps)
272 IF(abs(dlp-dlq).GT.dlt)
GOTO 30
276 DO iedge2=1,grid2%NEDGES
277 IF(.NOT.medge2(iedge2))
THEN
278 ipoint=grid2%POINTS(1,iedge2)
279 x1=grid2%X(1,ipoint)*fscl
280 y1=grid2%X(2,ipoint)*fscl
281 ipoint=grid2%POINTS(2,iedge2)
282 x2=grid2%X(1,ipoint)*fscl
283 y2=grid2%X(2,ipoint)*fscl
284 dlp=(x1-x2)**2+(y1-y2)**2
286 dlt=abs(x2-x1)*(abs(x1)+abs(x2)+eps)+
287 + abs(y2-y1)*(abs(y1)+abs(y2)+eps)
290 IF(abs(dlp-dlq).GT.dlt)
GOTO 30
296 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
298 WRITE(gridman_unit,*)
299 w
" Intersection does not cover the whole edge."
300 WRITE(gridman_unit,*)
301 w
" Unfortunately, current version can not ",
302 w
" treat this situation properly."
303 WRITE(gridman_unit,*)
" DLP, DLQ, DLT, TOL ",dlp,dlq,dlt,tol
310 DO iedge1=1,grid1%NEDGES
311 IF(medge1(iedge1))
THEN
315 lmap0(iedge1)=nedges0
319 DO iedge1=1,grid1%NEDGES
320 IF(medge1(iedge1))
THEN
322 IF(grid1%CELLS(1,iedge1).GE.0)
THEN
323 cells(1,nedges)=grid1%CELLS(1,iedge1)
324 ELSE IF(grid1%CELLS(1,iedge1).LT.0)
THEN
326 iedge=-grid1%CELLS(1,iedge1)
327 IF(iedge.GT.grid1%NEDGES)
GOTO 200
328 IF(iedge.GT.0) cells(1,nedges)=-lmap0(iedge)
330 IF(grid1%CELLS(2,iedge1).GE.0)
THEN
331 cells(2,nedges)=grid1%CELLS(2,iedge1)
332 ELSE IF(grid1%CELLS(2,iedge1).LT.0)
THEN
334 iedge=-grid1%CELLS(2,iedge1)
335 IF(iedge.GT.grid1%NEDGES)
GOTO 200
336 cells(2,nedges)=-lmap0(iedge)
338 points(1,nedges)=grid1%POINTS(1,iedge1)
339 points(2,nedges)=grid1%POINTS(2,iedge1)
340 imape1(1,nedges)=iedge1
341 imape1(2,nedges)=nedges
348 DO iedge2=1,grid2%NEDGES
349 IF(medge2(iedge2))
THEN
353 lmap0(iedge2)=nedges0
357 npoints=grid1%NPOINTS
360 DO iedge2=1,grid2%NEDGES
361 IF(medge2(iedge2))
THEN
363 IF(grid2%CELLS(1,iedge2).GT.0)
THEN
364 cells(1,nedges)=grid2%CELLS(1,iedge2)+ncells
365 ELSE IF(grid2%CELLS(1,iedge2).LT.0)
THEN
367 iedge=-grid2%CELLS(1,iedge2)
368 IF(iedge.GT.grid2%NEDGES)
GOTO 300
369 cells(1,nedges)=-lmap0(iedge)
373 IF(grid2%CELLS(2,iedge2).GT.0)
THEN
374 cells(2,nedges)=grid2%CELLS(2,iedge2)+ncells
375 ELSE IF(grid2%CELLS(2,iedge2).LT.0)
THEN
377 iedge=-grid2%CELLS(2,iedge2)
378 IF(iedge.GT.grid2%NEDGES)
GOTO 300
379 cells(2,nedges)=-lmap0(iedge)
383 ipoint=grid2%POINTS(1,iedge2)
384 IF(rpoints(ipoint).GT.0)
THEN
386 points(1,nedges)=rpoints(ipoint)
389 points(1,nedges)=ipoint+npoints
391 ipoint=grid2%POINTS(2,iedge2)
392 IF(rpoints(ipoint).GT.0)
THEN
393 points(2,nedges)=rpoints(ipoint)
395 points(2,nedges)=ipoint+npoints
397 imape2(1,nedges)=iedge2
398 imape2(2,nedges)=nedges
403 npoints=grid1%NPOINTS
405 DO ipoint=1,grid2%NPOINTS
406 IF(rpoints(ipoint).GT.0) cycle
413 npoints1=grid1%NPOINTS
415 ipoint=points(1,iedge)
416 IF(ipoint.GT.npoints1)
THEN
417 IF(mapp(ipoint-npoints1).GT.0)
THEN
418 points(1,iedge)=mapp(ipoint-npoints1)
423 ipoint=points(2,iedge)
424 IF(ipoint.GT.npoints1)
THEN
425 IF(mapp(ipoint-npoints1).GT.0)
THEN
426 points(2,iedge)=mapp(ipoint-npoints1)
434 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
436 WRITE(gridman_unit,*)
"no shift information for a point, ",
437 w
" IEDGE, IPOINT ",iedge, ipoint
442 ncells=grid1%NCELLS+grid2%NCELLS
443 nedgeindex=grid1%NEDGEINDEX+grid2%NEDGEINDEX
444 ncellindex=grid1%NCELLINDEX+grid2%NCELLINDEX
446 c nedgeindex,ncellindex)
447 IF(ierr.GT.0)
GOTO 400
450 grid%CELLS(1,1:nedges)=cells(1,1:nedges)
451 grid%CELLS(2,1:nedges)=cells(2,1:nedges)
452 grid%POINTS(1,1:nedges)=points(1,1:nedges)
453 grid%POINTS(2,1:nedges)=points(2,1:nedges)
454 DO ipoint=1,grid1%NPOINTS
455 grid%X(1,ipoint)=grid1%X(1,ipoint)
456 grid%X(2,ipoint)=grid1%X(2,ipoint)
458 DO ipoint=1,grid2%NPOINTS
459 IF(mapp(ipoint).GT.0)
THEN
460 grid%X(1,mapp(ipoint))=grid2%X(1,ipoint)*fscl
461 grid%X(2,mapp(ipoint))=grid2%X(2,ipoint)*fscl
464 grid%UNIT2SI=grid1%UNIT2SI
465 grid%UNITS=grid1%UNITS
466 grid%DESCRIPTION=trim(grid1%DESCRIPTION)//
' <merged with> '//
467 / trim(grid2%DESCRIPTION)
469 DO ii=1,grid1%NEDGEINDEX
471 c grid1%EDGEINDEX(ii),imape1,nedges,ierr)
472 IF(ierr.NE.0)
GOTO 410
474 DO ii2=1,grid2%NEDGEINDEX
475 ii=ii2+grid1%NEDGEINDEX
477 c grid2%EDGEINDEX(ii2),imape2,nedges,ierr)
478 IF(ierr.NE.0)
GOTO 420
480 DO ii=1,grid1%NCELLINDEX
482 c grid1%CELLINDEX(ii),ierr)
483 IF(ierr.NE.0)
GOTO 430
485 DO ii2=1,grid2%NCELLINDEX
486 ii=ii2+grid1%NCELLINDEX
488 c grid2%CELLINDEX(ii2),ierr)
489 grid%CELLINDEX(ii)%INDEXES(0,:)=grid%CELLINDEX(ii)%INDEXES(0,:)+
491 IF(ierr.NE.0)
GOTO 440
495 IF(res.NE.0.OR.ierr.GT.0)
GOTO 100
498 w
WRITE(gridman_unit,*)
"GRIDMAN_GRID2D_MERGE finished"
503 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
504 w
"internal error - wrong resulting GRID"
505 WRITE(gridman_unit,*)
" RES ",res
509 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
510 w
"index for teleportation on GRID1 is out of range"
511 WRITE(gridman_unit,*)
" IEDGE1, IEDGE ",iedge1, iedge
515 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
516 w
"index for teleportation on GRID2 is out of range"
517 WRITE(gridman_unit,*)
" IEDGE2, IEDGE ",iedge1, iedge
520 400
WRITE(gridman_unit,*)
"GRIDMAN_GRID2D_MERGE terminated"
524 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
525 w
"cannot create edge index II1 ",ii
528 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
529 w
"cannot create edge index II2 ",ii2
532 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
533 w
"cannot create cell index II1 ",ii
536 WRITE(gridman_unit,*)
"ERROR in GRIDMAN_GRID2D_MERGE: ",
537 w
"cannot create cell index II2 ",ii2
549 SUBROUTINE find_overlap(P,Q,XP,YP,XQ,YQ,TOL,IND,TPQ)
553 INTEGER(GRIDMAN_SP),
INTENT(IN) :: P(2),Q(2)
554 REAL(GRIDMAN_DP),
INTENT(IN) :: XP(2),YP(2),
556 REAL(GRIDMAN_DP),
INTENT(IN) :: TOL
557 INTEGER(GRIDMAN_SP),
INTENT(OUT) :: IND(6),
560 REAL(GRIDMAN_DP) :: T,DEL,ZP1,ZP2,ZQ1,ZQ2,EPS
561 INTEGER(GRIDMAN_SP) :: P1,P2,Q1,Q2
562 INTEGER(GRIDMAN_SP),
PARAMETER :: NULL=0
567 del=abs(yp(2)-yp(1))*(abs(xq(1))+abs(xp(1))+eps)+
568 + abs(xq(1)-xp(1))*(abs(yp(2))+abs(yp(1))+eps)+
569 + abs(xp(2)-xp(1))*(abs(yq(1))+abs(yp(1))+eps)+
570 + abs(yq(1)-yp(1))*(abs(xp(2))+abs(xp(1))+eps)
572 t=(xq(1)-xp(1))*(yp(2)-yp(1))
573 t=t-(yq(1)-yp(1))*(xp(2)-xp(1))
577 IF(abs(t).GT.del)
THEN
584 del=abs(yp(2)-yp(1))*(abs(xq(2))+abs(xp(1)))+
585 + abs(xq(2)-xp(1))*(abs(yp(2))+abs(yp(1)))+
586 + abs(xp(2)-xp(1))*(abs(yq(2))+abs(yp(1)))+
587 + abs(yq(2)-yp(1))*(abs(xp(2))+abs(xp(1)))
589 t=(xq(2)-xp(1))*(yp(2)-yp(1))
590 t=t-(yq(2)-yp(1))*(xp(2)-xp(1))
591 IF(abs(t).GT.del)
THEN
597 IF(abs(xp(2)-xp(1)).GT.abs(yp(2)-yp(1)))
THEN
600 IF(xp(2).GT.xp(1))
THEN
613 IF(xq(2).GT.xq(1))
THEN
629 IF(yp(2).GT.yp(1))
THEN
642 IF(yq(2).GT.yq(1))
THEN
657 IF(abs(zq1-zp1).LT.tol*(abs(zq1)+abs(zp1)+eps).AND.
658 f abs(zq2-zp2).LT.tol*(abs(zq2)+abs(zp2)+eps))
THEN
659 ind=(/null,null,p1,p2,null,null/)
662 ELSE IF(abs(zq1-zp1).LT.tol*(abs(zq1)+abs(zp1)+eps))
THEN
664 ind=(/null,null,p1,p2,p2,q2/)
666 ind=(/null,null,p1,q2,q2,p1/)
670 ELSE IF(abs(zq2-zp2).LT.tol*(abs(zq2)+abs(zp2)+eps))
THEN
672 ind=(/q1,p1,p1,p2,null,null/)
674 ind=(/p1,q1,q1,p2,null,null/)
678 ELSE IF(abs(zq2-zp1).LT.tol*(abs(zq2)+abs(zp1)+eps))
THEN
679 ind=(/q1,p1,p1,null,p1,p2/)
682 ELSE IF(abs(zq1-zp2).LT.tol*(abs(zq1)+abs(zp2)+eps))
THEN
683 ind=(/p1,p2,null,p2,p2,q2/)
686 ELSE IF(zq1.LT.zp1)
THEN
688 ind=(/q1,q2,null,null,p1,p2/)
689 ELSE IF(zq2.GT.zp2)
THEN
690 ind=(/q1,p1,p1,p2,p2,q2/)
692 ind=(/q1,p1,p1,q2,q2,p1/)
694 ELSE IF(zq1.GT.zp2)
THEN
695 ind=(/p1,p2,null,null,q1,q2/)
698 ind=(/p1,q1,q1,q2,q2,p2/)
700 ind=(/p1,q1,q1,p2,p2,q2/)
704 END SUBROUTINE find_overlap
710 FUNCTION nonzer_cell(CELLS)
711 INTEGER(GRIDMAN_SP),
INTENT(IN) :: CELLS(2)
712 INTEGER(GRIDMAN_SP) :: NONZER_CELL
713 IF(cells(1).GT.0)
THEN
715 ELSE IF(cells(2).GT.0)
THEN
720 END FUNCTION nonzer_cell
subroutine gridman_grid2d_merge(GRID, GRID1, GRID2, TOL, IERR)
Merge two 2D grids by connecting their boundary edges.
integer, parameter, public gridman_dp
Kind parameter for real numbers.
Explicit interfaces to GRIDMAN subroutines and functions.
subroutine gridman_grid_allocate(GRID, TYPE, NEDGES, NPOINTS, NCELLS, IERR, NEDGEINDEX, NCELLINDEX)
Allocate GRIDMAN_GRID object.
subroutine gridman_index_copy(INDEX2, INDEX1, IERR)
Create a copy of the index object.
subroutine gridman_grid2d_check(GRID, RES, IERR)
Check correctness of the 2D grid object.
subroutine gridman_index_transform(INDEX2, INDEX1, IMAP12, N12, IERR)
Transform indices of elements - IND(0,:)
Data-type which describes a grid as a set of edges, methods in grid.f.
Definition of data types, global constants and variables.
integer, parameter, public gridman_sp
Kind parameter for integer numbers.