-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmesh.f90
1041 lines (889 loc) · 31.7 KB
/
mesh.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!*==mp01.spg processed by SPAG 6.70Rc at 14:19 on 25 Oct 2015
! Remove 3 layers of atoms around crack faces, for
!
! Define detection band rings around crack tip
! mesh generator for atomically sharp crack tip
! 1 2 3 4 5 6 7
!23456789012345678901234567890123456789012345678901234567890123456789012
! build a blunt *center, crack
SUBROUTINE MP01(Id,X,Ix,F,B,Itx, lmp)
USE MOD_GRAIN
USE MOD_GLOBAL
USE MOD_FILE
USE MOD_BOUNDARY
USE MOD_CRACK
USE MOD_MATERIAL
USE MOD_DD_SLIP
use MOD_DISL_PARAMETERS
use lammps
IMPLICIT NONE
!*--MP0118
! Input variables
type(c_ptr) :: lmp
INTEGER Id , Ix , Itx(3,*)
DOUBLE PRECISION X , F , B
DIMENSION Id(NDF,1) , X(NXDm,1) , Ix(NEN1,1) , F(NDF,1) , B(NDF,1)
! common declarations
COMMON /DEBUGGER/ DEBug
LOGICAL DEBug
DOUBLE PRECISION tol
! local variables
LOGICAL n1 , n2 , n3 , m1 , m2 , m3 , usedetectionband
DOUBLE PRECISION , POINTER :: nodeangle(:)
INTEGER nxregions , nyregions , icell , ndxdy , numnodes , numx ,&
& numy , ispace , ixrem , iyrem , igrain , coincidentnodes ,&
& nodestart , inode , nsort , np1 , numnp0 , countlast , i ,&
& j , k , node1 , node2 , node3
INTEGER nr1 , nr2 , nr3 , nr4
DOUBLE PRECISION xmax(0:20) , ymax(0:20) , nodesite(3) , dx , dy ,&
& dxdy , xxmin , xxmax , yymin , yymax ,&
& yyminorig , delx , dely , xx , yy , mindb ,&
& rcutmesh , DIST2 , large
DATA tol/1.D-6/
LOGICAL placenode , top , bot , left , right , mirror
TYPE REGION
DOUBLE PRECISION XMIN , xmax , YMIN , ymax
END TYPE REGION
TYPE (REGION) atomregion , detectionband , innerregion , mirroratomregion , simulationcell
LOGICAL INSIDEREGION , inside
INTEGER temp_slip , ii , jj , islp , iii
DOUBLE PRECISION xslip_start , xslip_end , yslip_start , yslip_end
DOUBLE PRECISION slip_angle(3) , xxx1 , yyy1 , dxslip , dyslip
DOUBLE PRECISION xslp1 , xendslp1 , zbqlu01 , rr1 , lnuc , sn , smax
INTEGER*4 timearray(3)
!! VBS added this to read in tolerances
COMMON /ELEMCONV/ NUMelold
INTEGER lcrack , NUMelold , numnpc
!c--JS: Specially for crack asymmetry
INTEGER dwnumx , dwnumy , dwfactorx , dwfactory
INTEGER logic
CHARACTER*80 filename
!c--JS: dwfactor 2 for asym and 1 for sym
dwfactorx = 1
dwfactory = 1
!c
WRITE (*,*)
WRITE (*,*) 'Generating mesh containing an embedded crack'
WRITE (*,*)
X0Crack = 0.01
Y0Crack = 0.01
!
xmax(0) = -1.
ymax(0) = -1.
! Read mesh data
READ (input_file_unit, *) nxregions , nyregions
READ (input_file_unit, *) (xmax(i),i=1,nxregions)
READ (input_file_unit, *) (ymax(i),i=1,nyregions)
READ (input_file_unit, *) mindb
READ (input_file_unit, *) rcutmesh
READ (input_file_unit, *) X0Crack , Y0Crack
READ (input_file_unit, *) PAD_width
mirror = .FALSE.
! if(rcutmesh.lt.0.d0) then
! rcutmesh=abs(rcutmesh)
! write (6,*) 'Mirror not allowed'
! stop
! endif
DO k = MIN(nxregions,nyregions) + 1 , MAX(nxregions,nyregions)
IF ( nxregions<nyregions ) THEN
xmax(k) = xmax(nxregions)
ELSE
ymax(k) = ymax(nyregions)
ENDIF
ENDDO
! Extract lattice data
! Normally, the second atom is dx away from the first due to the
! way cell is sorted.
! if there is only 1 atom on the lowest y-plane of cell, then dx is the
! cell width in the x dirn.
dx = GRAins(1)%CELL(1,2)
IF ( GRAins(1)%CELL(2,2)>tol ) dx = GRAins(1)%DCELL(1)
!
DO icell = 1 , GRAins(1)%NCELL
IF ( GRAins(1)%CELL(2,icell)>tol ) THEN
dy = GRAins(1)%CELL(2,icell)
dxdy = GRAins(1)%CELL(1,icell)
EXIT
ENDIF
ENDDO
IF ( dxdy/=0. ) THEN
ndxdy = NINT(dx/dxdy)
ELSE
ndxdy = 1
ENDIF
PRINT * , 'Generating nodes'
! Generate the nodes in each box, the mesh is coarsened with increasing
! distance from the center of the box.
numx = INT(xmax(nxregions)/dx) + 1
numy = INT(ymax(nyregions)/dy) + 1
numnodes = 0
DO i = -numx , numx
xx = i*dx
IF ( ABS(xx)<=xmax(nxregions) ) THEN
!
DO j = -numy , numy
!
yy = j*dy
IF ( ABS(yy)<=ymax(nyregions) ) THEN
!
!! Determine the region in which the node is being placed
DO k = MAX(nxregions,nyregions) - 1 , 1 , -1
!c--JS: Symmetric geometry-Commented if ther is crack
! if ( (abs(xx).gt.XMax(k))
! $ .or.(abs(yy).gt.YMax(k)) ) go to 21
!c--JS: Asymetry due to the presence of crack
IF ( (xx>xmax(k)) .OR. (yy>ymax(k)/dwfactory) ) EXIT
IF ( (xx<-xmax(k)/dwfactorx) .OR. (yy>ymax(k)/dwfactory) ) EXIT
IF ( (xx>xmax(k)) .OR. (yy<-ymax(k)) ) EXIT
IF ( (xx<-xmax(k)/dwfactorx) .OR. (yy<-ymax(k)) ) EXIT
ENDDO
ispace = 2**k
IF ( ispace==0 ) ispace = 1
!! Decide if a node should be placed in this region
ixrem = MOD(ABS(i),ispace)
iyrem = MOD(ABS(j),ispace)
placenode = (ixrem+iyrem)==0
IF ( placenode ) THEN
! Assign the node a position
numnodes = numnodes + 1
X(1,numnodes) = xx + MOD(j,ndxdy)*dxdy
X(2,numnodes) = yy
! Qu modification to remove extra layers of atoms around crack faces
!$$$ if((j.eq.0.and.x(1,numNodes).lt.-0.01*dx).or.
!$$$ & (j.eq.1.and.x(1,numNodes).lt.-0.01*dx) .or.
!$$$ & (j.eq.-1.and.x(1,numNodes).lt.-dx) )then
!$$$c ***************************************************************
!$$$c Add this line for a sharp crack
!$$$c Comment this line and uncomment to the last 3 lines to
!$$$c for blunt crack with 3 layers missing
!$$$c ***************************************************************
!$$$c if(j.eq.0.and.x(1,numNodes).lt.-0.1*dx) then
!$$$ numNodes=numNodes-1
!$$$ endif
! FOR NOW ONLY, assign nodes to the crack faces. Leo mentions
! this is a hack. But this appears legitimate.
! Add back nodes according to desired crack shape
IF ( j==0 .AND. X(1,numnodes)<-0.01*dx ) THEN
numnodes = numnodes + 2
X(1,numnodes-1) = xx + MOD(j,ndxdy)*dxdy
! x(2,numNodes-1) = yy+2*dy
X(2,numnodes-1) = yy + dy
X(1,numnodes) = xx + MOD(j,ndxdy)*dxdy
! x(2,numNodes) = yy-2*dy
X(2,numnodes) = yy
! print *, i, x(1, numNodes)
IF ( i==-320 ) countlast = numnodes - 1
ENDIF
ENDIF
ENDIF
! Qu modification ends
ENDDO
ENDIF
ENDDO
PRINT * , 'Moving nodes to the nearest atomic sites'
! Move nodes to the nearest atomic sites
large = 1.E30
xxmax = -large
xxmin = large
yymax = -large
yymin = large
DO i = 1 , numnodes
!
nodesite(1) = X(1,i)
nodesite(2) = X(2,i)
IF ( i/=countlast ) CALL NEARESTBSITE(nodesite,1,.FALSE.,X(1,i),igrain)
!! find xxmax, xxmin, etc.
xxmax = MAX(X(1,i),xxmax)
xxmin = MIN(X(1,i),xxmin)
yymax = MAX(X(2,i),yymax)
yymin = MIN(X(2,i),yymin)
! print *, i, x(1,i), x(2,i)
IF ( X(1,i)==0.0D0 ) THEN
IF ( X(2,i)==0.0D0 ) temp_slip = i
ENDIF
ENDDO
xslip_start = X(1,temp_slip+1)
yslip_start = (X(2,temp_slip)+X(2,temp_slip+1))/2.D0
xxx1 = X(1,temp_slip+1) - X(1,temp_slip)
yyy1 = X(2,temp_slip+1) - X(2,temp_slip)
slip_angle(1) = ATAN2(yyy1,xxx1)
dxslip = ABS(xxx1)*2.D0
dyslip = ABS(yyy1)
PRINT * , xxx1 , yyy1 , slip_angle(1)
PRINT * , 'Slip plane start and end' , temp_slip
PRINT * , 'x_start' , xslip_start , X(1,temp_slip+1)
PRINT * , 'y_start' , yslip_start
xxx1 = X(1,temp_slip-1) - X(1,temp_slip)
yyy1 = ABS(X(2,temp_slip-1)-X(2,temp_slip))
slip_angle(2) = ATAN2(yyy1,xxx1)
PRINT * , xxx1 , yyy1 , slip_angle(2)
slip_angle(3) = 0.0D0
PRINT * , 'DX' , dxslip
PRINT * , 'DY' , dyslip
slip_angle(3) = 0.0D0
simulationcell%XMIN = xxmin
simulationcell%xmax = xxmax
simulationcell%YMIN = yymin
simulationcell%ymax = yymax
! hard coded for 1 grain
IF ( mirror ) THEN
NUMnp = numnodes
DO i = 1 , NUMnp
!
IF ( X(2,i)<yymin+tol ) THEN
nodesite(1) = X(1,i)
nodesite(2) = -136.85
CALL NEARESTBSITE(nodesite,1,.FALSE.,X(1,i),igrain)
ENDIF
!
numnodes = numnodes + 1
nodesite(1) = X(1,i)
nodesite(2) = 2*yymin - X(2,i)
CALL NEARESTBSITE(nodesite,1,.FALSE.,X(1,numnodes),igrain)
!
ENDDO
!
yyminorig = yymin
yymin = 2*yymin - yymax
!
simulationcell%YMIN = yymin
ENDIF
! Remove coincident nodes
PRINT * , 'Removing coincident nodes'
coincidentnodes = 0
NUMnp = numnodes
DO i = NUMnp , 2 , -1
IF ( i<=numnodes ) THEN
DO j = 1 , i - 1
delx = ABS(X(1,i)-X(1,j))
dely = ABS(X(2,i)-X(2,j))
IF ( delx+dely<2.*tol ) THEN
X(1,j) = X(1,numnodes)
X(2,j) = X(2,numnodes)
numnodes = numnodes - 1
coincidentnodes = coincidentnodes + 1
ENDIF
ENDDO
ENDIF
ENDDO
IF ( coincidentnodes/=0 ) WRITE (6,*) coincidentnodes , ' coincident nodes removed'
NUMnp = numnodes
IF ( NUMnp>MAXnp ) THEN
WRITE (6,*) '***ERROR: Insufficient storage for nodes'
WRITE (6,*) ' numnp = ' , NUMnp
STOP
ENDIF
WRITE (6,*) 'Total nodes: numnp = ' , NUMnp
! Apply boundary conditions and define the boundary for the
! triangulator
NCE = 0
nodestart = 0
PRINT * , 'Detecting the lower crack ledge'
! FIND THE LOWER CRACK LEDGE
DO i = 1 , NUMnp
! Qu modification to remove extra layers of atoms around crack faces
IF ( DABS(X(2,i))<tol .AND. X(1,i)<0.1*dx ) THEN
! if(dabs(x(2,i)+dy).lt.tol.and.x(1,i).lt.0.1*dx) then
! if(dabs(x(2,i)+2*dy).lt.tol.and.x(1,i).lt.-dx) then
! Qu modification ends
! if(dabs(x(2,i)).lt.tol.and.x(1,i).lt.XMax(1)-4*rcutmesh) then
! if(dabs(x(2,i)).lt.tol.and.x(1,i).lt.-XMax(1)+2*dx) then
NCE = NCE + 1
IF ( NCE>NCEmax ) THEN
IF ( NCE>NCEmax ) CALL INCREASEELIST(100)
ENDIF
ELIst(1,NCE) = i
ENDIF
ENDDO
! sort the lower ledge so that is goes CW (from right to left).
ALLOCATE (nodeangle(NUMnp))
nodeangle = 0.
DO i = 1 , NCE
inode = ELIst(1,i)
nodeangle(inode) = DATAN2(dy,X(1,inode))
ENDDO
nsort = NCE
CALL QSORTR(nsort,ELIst(1,1),nodeangle,1,1,1.D0)
DEALLOCATE (nodeangle)
! remove the last node from the list
!c!!! Bill's changes!!!!
NCE = NCE - 1
nodestart = NCE
! find all external boundary nodes
simulationcell%XMIN = simulationcell%XMIN + 10.D0
simulationcell%xmax = simulationcell%xmax - 10.D0
simulationcell%YMIN = simulationcell%YMIN + 10.D0
simulationcell%ymax = simulationcell%ymax - 10.D0
PRINT * , 'Detecting the outer cell boundary' , NUMnp
PRINT * , simulationcell%XMIN , simulationcell%xmax
PRINT * , simulationcell%YMIN , simulationcell%ymax
DO i = 1 , NUMnp
top = (X(2,i)>simulationcell%ymax)
bot = (X(2,i)<simulationcell%YMIN)
left = (X(1,i)<simulationcell%XMIN)
right = (X(1,i)>simulationcell%xmax)
! store all boundary points, but put crack faces at the beginning of
! elist. While you are at it, apply the b.c.s
IF ( top .OR. bot .OR. right .OR. left ) THEN
NCE = NCE + 1
IF ( NCE>NCEmax ) THEN
IF ( NCE>NCEmax ) CALL INCREASEELIST(100)
ENDIF
ELIst(1,NCE) = i
! apply the b.c's
IF ( top .OR. bot .OR. right .OR. left ) THEN
Id(1,i) = 1
Id(2,i) = 1
PRINT * , 'BCs on node' , i
ENDIF
!
ENDIF
ENDDO
! sort the boundary so that is goes CW.
ALLOCATE (nodeangle(NUMnp))
nodeangle = 0.
DO i = nodestart + 1 , NCE
inode = ELIst(1,i)
! YET ANOTHER HACK
nodeangle(inode) = DATAN2(X(2,inode)-tol,X(1,inode))
ENDDO
nsort = NCE - nodestart
CALL QSORTR(nsort,ELIst(1,nodestart+1),nodeangle,1,1,1.D0)
DEALLOCATE (nodeangle)
! remove the last node from the list
NCE = NCE - 1
nodestart = NCE
! FIND THE UPPER CRACK LEDGE
PRINT * , 'Detecting the upper crack ledge'
DO i = 1 , NUMnp
! Qu modification to remove extra layers of atoms around crack faces
IF ( DABS(X(2,i)-1.0*dy)<tol .AND. X(1,i)<0.1*dx ) THEN
! if(dabs(x(2,i)-2.0*dy).lt.tol.and.x(1,i).lt.0.1*dx) then
! if(dabs(x(2,i)-dy).lt.tol.and.x(1,i).lt.XMax(1)-4*rcutmesh) then
! if(dabs(x(2,i)-dy).lt.tol.and.x(1,i).lt.-XMax(1)+2*dx) then
NCE = NCE + 1
IF ( NCE>NCEmax ) THEN
IF ( NCE>NCEmax ) CALL INCREASEELIST(100)
ENDIF
ELIst(1,NCE) = i
ENDIF
ENDDO
! sort the upper ledge so that is goes CW (from left to right).
ALLOCATE (nodeangle(NUMnp))
nodeangle = 0.
DO i = nodestart + 1 , NCE
inode = ELIst(1,i)
nodeangle(inode) = -DATAN2(X(2,inode),X(1,inode))
ENDDO
nsort = NCE - nodestart
CALL QSORTR(nsort,ELIst(1,nodestart+1),nodeangle,1,1,1.D0)
DEALLOCATE (nodeangle)
! finish defining the boundary
DO i = 1 , NCE - 1
ELIst(2,i) = ELIst(1,i+1)
ENDDO
ELIst(2,NCE) = ELIst(1,1)
NCB = NCE
!$$$ do i=1,numnp
!$$$ if(dabs((x(2,i))-dy).lt.tol.and.x(1,i).gt.-dx
!$$$ & .and.x(1,i).lt.0.5*dx)then
!$$$ nce=nce+1
!$$$ if(nce.gt.NCEMAX) then
!$$$ if(nce.gt.NCEMAX) call IncreaseElist(100)
!$$$ endif
!$$$
!$$$ elist(1,nce)=i
!$$$ ncb=nce
!$$$ elist(2,nce)=elist(1,1)
!$$$ elist(2,nce-1)=elist(1,nce)
!$$$ endif
!$$$ enddo
!$$$ do i=1,numnp
!$$$ if(dabs(x(2,i)).lt.tol.and.x(1,i).gt.-0.5*dx
!$$$ & .and.x(1,i).lt.0.5*dx)then
!$$$ nce=nce+1
!$$$ if(nce.gt.NCEMAX) then
!$$$ if(nce.gt.NCEMAX) call IncreaseElist(100)
!$$$ endif
!$$$
!$$$ elist(1,nce)=i
!$$$ ncb=nce
!$$$ elist(2,nce)=elist(1,1)
!$$$ elist(2,nce-1)=elist(1,nce)
!$$$ endif
!$$$ enddo
!$$$
!$$$ do i=1,numnp
!$$$ if(dabs((x(2,i))+dy).lt.tol.and.x(1,i).gt.-dx
!$$$ & .and.x(1,i).lt.tol)then
!$$$ nce=nce+1
!$$$ if(nce.gt.NCEMAX) then
!$$$ if(nce.gt.NCEMAX) call IncreaseElist(100)
!$$$ endif
!$$$
!$$$ elist(1,nce)=i
!$$$ ncb=nce
!$$$ elist(2,nce)=elist(1,1)
!$$$ elist(2,nce-1)=elist(1,nce)
!$$$ endif
!$$$ enddo
! Triangulate, sets all elements to material 1 for this mesh
PRINT * , 'Triangulating'
numnpc = NUMnp
CALL DELAUNAY(Id,X,Ix,F,B,Itx)
PRINT * , 'Done'
WRITE (*,*) 'BEFORE adding overlap'
WRITE (6,*) 'Number of nodes: numnp = ' , NUMnp
WRITE (6,*) 'Number of elements: numel = ' , NUMel
IF ( NUMel>MAXel ) STOP 'too many elements'
IF ( NUMnp>MAXnp ) STOP 'too many nodes'
! Find max/min of atomistic region
innerregion%XMIN = -xmax(1)/dwfactorx
innerregion%xmax = xmax(1)
innerregion%YMIN = -ymax(1)
innerregion%ymax = ymax(1)/dwfactory
CALL FINDATOMREGIONSIZE(X,dx,dy,tol,innerregion,atomregion)
DO i = 1 , NUMel
Ix(NEN1,i) = 1
ENDDO
! Find continuum region elements
IF ( mirror ) THEN
mirroratomregion%XMIN = atomregion%XMIN
mirroratomregion%xmax = atomregion%xmax
mirroratomregion%YMIN = 2*yyminorig - atomregion%YMIN
mirroratomregion%ymax = 2*yyminorig - atomregion%ymax
ENDIF
!
! Check if each node of any continuum element is in the
! atomistic region
DO i = 1 , NUMel
!
node1 = Ix(1,i)
node2 = Ix(2,i)
node3 = Ix(3,i)
!
!! Determine if any node is in the atomistic region
n1 = .NOT.INSIDEREGION(X(1:2,node1),atomregion)
n2 = .NOT.INSIDEREGION(X(1:2,node2),atomregion)
n3 = .NOT.INSIDEREGION(X(1:2,node3),atomregion)
!! Determine if any node is in the mirrored atomistic region
IF ( mirror ) THEN
m1 = .NOT.INSIDEREGION(X(1:2,node1),mirroratomregion)
m2 = .NOT.INSIDEREGION(X(1:2,node2),mirroratomregion)
m3 = .NOT.INSIDEREGION(X(1:2,node3),mirroratomregion)
ELSE
m1 = .TRUE.
m2 = .TRUE.
m3 = .TRUE.
ENDIF
!
IF ( (n1 .AND. n2 .AND. n3) .AND. (m1 .AND. m2 .AND. m3) ) Ix(NEN1,i) = 0
ENDDO
! Add pad atoms in the interface region. Note that elements are
! not needed in this region, so just add atoms.
! go to 1234
PRINT * , 'Adding pad atoms' , PAD_width
numnodes = NUMnp
! XMax(2)=XMax(1)+2.d0*rcutmesh
! YMax(2)=YMax(1)+2.d0*rcutmesh
xmax(2) = xmax(1) + PAD_width
ymax(2) = ymax(1) + PAD_width
numx = INT(xmax(2)/dx) + 1
numy = INT(ymax(2)/dy) + 1
dwnumx = INT(xmax(2)/dwfactorx/dx) + 1
dwnumy = INT(ymax(2)/dwfactory/dy) + 1
DO i = -dwnumx , numx
xx = i*dx
DO j = -numy , dwnumy
yy = j*dy
!
numnodes = numnodes + 1
!
nodesite(1) = xx + MOD(j,ndxdy)*dxdy
nodesite(2) = yy
!
CALL NEARESTBSITE(nodesite,1,.FALSE.,X(1,numnodes),igrain)
!! Skip this node if it is the atomistic region
IF ( ABS(j)<0 .AND. i<0 ) THEN
numnodes = numnodes - 1
ELSEIF ( INSIDEREGION(X(1:2,numnodes),atomregion) ) THEN
numnodes = numnodes - 1
ENDIF
!
IF ( mirror ) THEN
nodesite(1) = X(1,numnodes)
nodesite(2) = 2*yyminorig - X(2,numnodes)
numnodes = numnodes + 1
CALL NEARESTBSITE(nodesite,1,.FALSE.,X(1,numnodes),igrain)
ENDIF
ENDDO
ENDDO
PRINT * , 'Done adding pad atoms'
np1 = NUMnp + 1
numnp0 = NUMnp
NUMnp = numnodes
IF ( NUMel>MAXel ) STOP 'Too many elements'
IF ( NUMnp>MAXnp ) STOP 'Too many nodes'
! Determine nodal character -- continuum, interface, atomistic etc.
NUM2dnode = NUMnp
CALL STATUSCALC(X,Ix,.TRUE.)
! remove the coincident nodes on the interface
PRINT * , 'Removing coincident nodes near the interface'
DO i = NUMnp , np1 , -1
DO j = 1 , numnp0
IF ( ISRelaxed(j)/=0 ) THEN
IF ( DIST2(X(1:2,i),X(1:2,j),2)<1.E-6 ) THEN
F(1:NDF,i) = F(1:NDF,NUMnp)
X(1:NXDm,i) = X(1:NXDm,NUMnp)
NUMnp = NUMnp - 1
EXIT
ENDIF
ENDIF
ENDDO
ENDDO
NUM2dnode = NUMnp
IF ( NUMperiodz>1 ) CALL INCATOMS(X)
IF ( NUMnp>MAXnp ) STOP 'Too many nodes'
! allocate(atomSpecie(numnp))
! do i=1,numnp
! atomSpecie(i)=1
! enddo
!--- Qu added on 08/26/2005
!----- For multimaterils purpose
numnp0 = NUMnp
!#########################################################################
!------- insert H atoms in the crack tip region
PRINT * , 'nmaterials' , NMAterials
IF ( NMAterials>1 ) THEN
CALL INSERTHATOM(X)
PRINT * , ' Adding interstitial atom'
ENDIF
IF ( NUMnp>MAXnp ) STOP 'Too many nodes'
ALLOCATE (ATOmspecie(NUMnp))
DO i = 1 , numnp0
ATOmspecie(i) = 1
ENDDO
DO i = numnp0 + 1 , NUMnp
PRINT * , '# of H atom' , i
ATOmspecie(i) = 2
WRITE (6,*) , 'int' , X(1,i) , '' , X(2,i) , '' , X(3,i)
ENDDO
IHNumber = i
!M modif for removing one atom
PRINT * , 'done'
WRITE (*,*) 'Final mesh size'
WRITE (6,*) 'Total nodes: numnp = ' , NUMnp
WRITE (6,*) 'Total elements: numel = ' , NUMel
WRITE (6,*) 'rcutmesh = ' , rcutmesh
NUMnpp1 = -1
call write_lammps_data(Id, X, Ix, F, B, Itx, -(xmax(1)+pad_width+10.0), xmax(1)+pad_width+10.0,-(ymax(1) + pad_width+10.0),(ymax(1) + pad_width+10.0) )
! Create a detection band
! Identify a path, defined by a closed polygon, ccw around the
! vertices, along which the detection band elements will be placed.
! If the atomistic continuum interface is not a closed path, define
! this polygon to extend outside the mesh and surround the atomistic
! region.
usedetectionband = .TRUE.
IF ( .NOT.usedetectionband ) THEN
NDBpoly = 0
RETURN
ENDIF
PRINT * , 'Using a detection band'
! There is one detection band with 4 points
! Qu modified detection band rings starts
detectionband%XMIN = atomregion%XMIN + rcutmesh
detectionband%xmax = atomregion%xmax - rcutmesh
detectionband%YMIN = atomregion%YMIN + rcutmesh
detectionband%ymax = atomregion%ymax - rcutmesh
mindb = INT(mindb/dy)*dy
nr1 = INT((ABS(detectionband%XMIN)-mindb)/dx) + 1
nr2 = INT((ABS(detectionband%xmax)-mindb)/dx) + 1
nr2 = nr1
nr3 = INT((ABS(detectionband%YMIN)-mindb)/dy) + 1
nr4 = INT((ABS(detectionband%ymax)-mindb)/dy) + 1
NDBpoly = MAX(nr1,nr2,nr3,nr4) + 1
!$$$ ndbpoly = 4
PRINT * , 'Detection band' , nr1 , nr2 , nr3 , nr4 , NDBpoly
CALL ALLOCATE_DB
DO i = 1 , NDBpoly
detectionband%XMIN = atomregion%XMIN + rcutmesh
!$$$ detectionBand%xmax = atomRegion%xmax - 2.0*rcutmesh
!$$$ detectionBand%ymin = atomRegion%ymin + 2.0*rcutmesh
!$$$ detectionBand%ymax = atomRegion%ymax - 2.0*rcutmesh
detectionband%xmax = atomregion%xmax - rcutmesh - (i-1)*dx
detectionband%YMIN = atomregion%YMIN + rcutmesh + (i-1)*dy
detectionband%ymax = atomregion%ymax - rcutmesh - (i-1)*dy
!$$$
!$$$ detectionBand%xmax = min( minDb+(i-1)*dx
!$$$ $ ,atomRegion%xmax - rcutmesh)
!$$$ detectionBand%ymin = max(-minDb-(i-1)*dy
!$$$ $ ,atomRegion%ymin + rcutmesh)
!$$$ detectionBand%ymax = min( minDb+(i-1)*dy
!$$$ $ ,atomRegion%ymax - rcutmesh)
DBPoly(1,1,i) = detectionband%XMIN
DBPoly(2,1,i) = detectionband%YMIN
DBPoly(1,2,i) = detectionband%xmax
DBPoly(2,2,i) = detectionband%YMIN
DBPoly(1,3,i) = detectionband%xmax
DBPoly(2,3,i) = detectionband%ymax
DBPoly(1,4,i) = detectionband%XMIN
DBPoly(2,4,i) = detectionband%ymax
!$$$ For this particular detection band the first layer is closest
!$$$ to the boundary
!$$$ Any other logic can be used ...
IF ( i==1 ) DBBoundnear(i) = .TRUE.
!$$$ print *, 'Detection band region', i,
!$$$ $ dbpoly(1,1,i), dbpoly(2,1,i)
!$$$ print *,
!$$$ $ 'Detection band region', i,dbpoly(1,2,i), dbpoly(2,2,i)
!$$$ print
!$$$ $ *, 'Detection band region', i,dbpoly(1,3,i), dbpoly(2,3,i)
!$$$ print
!$$$ $ *, 'Detection band region', i,dbpoly(1,4,i), dbpoly(2,4,i)
PRINT * , 'Detection Band Region' , i
WRITE (*,'(8f10.3)') DBPoly(1,1,i) , DBPoly(2,1,i) ,&
& DBPoly(1,2,i) , DBPoly(2,2,i) ,&
& DBPoly(1,3,i) , DBPoly(2,3,i) ,&
& DBPoly(1,4,i) , DBPoly(2,4,i)
ENDDO
! Qu modified detection band rings ends
WRITE (6,*) 'width of the detection band: rcutmesh = ' , rcutmesh
! CALL GEN_SLIP_PLANES(simulationcell%XMIN,simulationcell%xmax,&
! & simulationcell%YMIN,simulationcell%ymax,&
! & atomregion%XMIN,atomregion%xmax,&
! & atomregion%YMIN,atomregion%ymax,slip_angle,&
! & GRAins(1)%DCELL(1),xslip_start,yslip_start,&
! & dxslip,dyslip,PAD_width)
X_Move_mesh = 5.D0*dxslip
MOVemesh = .FALSE.
MOVed = .FALSE.
call initialize_lammps(Id,X,Ix,F,B,Itx,lmp)
END SUBROUTINE MP01
!*==insideregion.spg processed by SPAG 6.70Rc at 14:19 on 25 Oct 2015
!
!***********************************************************************
! Checks to see if a 2D point x is located inside thisRegion.
LOGICAL FUNCTION INSIDEREGION(X,Thisregion)
IMPLICIT NONE
!*--INSIDEREGION793
TYPE REGION
DOUBLE PRECISION XMIN , XMAX , YMIN , YMAX
END TYPE REGION
TYPE (REGION) Thisregion
DOUBLE PRECISION X(2)
INSIDEREGION = (X(1)>Thisregion%XMIN .AND. X(1)<Thisregion%XMAX .AND. X(2)>Thisregion%YMIN .AND. X(2)<Thisregion%YMAX)
END FUNCTION INSIDEREGION
!*==qsortr.spg processed by SPAG 6.70Rc at 14:19 on 25 Oct 2015
!***********************************************************************
SUBROUTINE QSORTR(N,List,Xkey,Nxdm,Ind,Sign)
IMPLICIT NONE
!*--QSORTR811
!*** Start of declarations inserted by SPAG
DOUBLE PRECISION guess , Sign , Xkey
INTEGER Ind , Nxdm
!*** End of declarations inserted by SPAG
!
DIMENSION Xkey(Nxdm,1)
INTEGER List(2,*) , N , ll , lr , lm , nl , nr , ltemp , stktop , MAXSTK
!
PARAMETER (MAXSTK=32)
!
INTEGER lstack(MAXSTK) , rstack(MAXSTK)
!
ll = 1
lr = N
stktop = 0
DO
IF ( ll<lr ) THEN
nl = ll
nr = lr
lm = (ll+lr)/2
guess = Sign*Xkey(Ind,List(1,lm))
!
! Find xkeys for exchange
!
20 DO WHILE ( Sign*Xkey(Ind,List(1,nl))<guess )
nl = nl + 1
ENDDO
DO
IF ( guess<Sign*Xkey(Ind,List(1,nr)) ) THEN
nr = nr - 1
CYCLE
ENDIF
IF ( nl<(nr-1) ) THEN
ltemp = List(1,nl)
List(1,nl) = List(1,nr)
List(1,nr) = ltemp
nl = nl + 1
nr = nr - 1
GOTO 20
ENDIF
!
! Deal with crossing of pointers
!
IF ( nl<=nr ) THEN
IF ( nl<nr ) THEN
ltemp = List(1,nl)
List(1,nl) = List(1,nr)
List(1,nr) = ltemp
ENDIF
nl = nl + 1
nr = nr - 1
ENDIF
!
! Select sub-list to be processed next
!
stktop = stktop + 1
IF ( nr<lm ) THEN
lstack(stktop) = nl
rstack(stktop) = lr
lr = nr
ELSE
lstack(stktop) = ll
rstack(stktop) = nr
ll = nl
ENDIF
GOTO 100
ENDDO
ENDIF
!
! Process any stacked sub-lists
!
IF ( stktop/=0 ) THEN
ll = lstack(stktop)
lr = rstack(stktop)
stktop = stktop - 1
CYCLE
ENDIF
EXIT
100 ENDDO
!
END SUBROUTINE QSORTR
!*==findatomregionsize.spg processed by SPAG 6.70Rc at 14:19 on 25 Oct 2015
! Find max/min of atomistic region
SUBROUTINE FINDATOMREGIONSIZE(Atomcoord,Dx,Dy,Tol,Innerregion,Atomregion)
USE MOD_GLOBAL
IMPLICIT NONE
!*--FINDATOMREGIONSIZE903
TYPE REGION
DOUBLE PRECISION xmin , xmax , ymin , ymax
END TYPE REGION
TYPE (REGION) Atomregion , Innerregion
DOUBLE PRECISION Atomcoord(NDF,*) , Dx , Dy , Tol
! local variables
DOUBLE PRECISION xmin , xmax , ymin , ymax , x , y , large
INTEGER inode
! functions
LOGICAL INSIDEREGION
large = 1.E30
xmax = -large
xmin = large
ymax = -large
ymin = large
DO inode = 1 , NUMnp
x = Atomcoord(1,inode)
y = Atomcoord(2,inode)
!
IF ( INSIDEREGION(Atomcoord(1:2,inode),Innerregion) ) THEN
xmax = MAX(xmax,x)
ymax = MAX(ymax,y)
xmin = MIN(xmin,x)
ymin = MIN(ymin,y)
ENDIF
!
ENDDO
xmax = xmax - Dx + Tol
ymax = ymax + Tol
xmin = xmin + Dx - Tol
ymin = ymin - Tol
xmax = xmax - Dx
xmin = xmin + Dx
ymax = ymax - Dy
ymin = ymin + Dy
Atomregion%xmin = xmin
Atomregion%xmax = xmax
Atomregion%ymin = ymin
Atomregion%ymax = ymax
END SUBROUTINE FINDATOMREGIONSIZE
!*==incatoms.spg processed by SPAG 6.70Rc at 14:19 on 25 Oct 2015
! Qu added begin
!
SUBROUTINE INCATOMS(X)
USE MOD_GLOBAL
USE MOD_GRAIN
IMPLICIT NONE
!*--INCATOMS963
DOUBLE PRECISION X
DIMENSION X(NXDm,1)
INTEGER i , j , numnp0
numnp0 = NUMnp
DO i = 2 , NUMperiodz
DO j = 1 , numnp0
IF ( ISRelaxed(j)/=0 ) THEN
NUMnp = NUMnp + 1
ISRelaxed(NUMnp) = ISRelaxed(j)
X(1:2,NUMnp) = X(1:2,j)
X(3,NUMnp) = X(3,j) + (i-1)*GRAins(1)%DCELL(3)
ENDIF
ENDDO
ENDDO
END SUBROUTINE INCATOMS
!*==inserthatom.spg processed by SPAG 6.70Rc at 14:19 on 25 Oct 2015
!
! Qu added ends
! c*********************************************************************
SUBROUTINE INSERTHATOM(X)
USE MOD_GLOBAL
USE MOD_GRAIN
IMPLICIT NONE
!*--INSERTHATOM992
DOUBLE PRECISION X
DIMENSION X(NXDm,1)
!----Local variables
INTEGER i , j , atomhnum , inhatoms
CHARACTER*80 input_file
input_file = 'interstitial.inp'
OPEN (UNIT=10,FILE=input_file,STATUS='old')
READ (10,*) inhatoms
!c-- JS
NUMtoth = inhatoms
DO i = 1 , inhatoms
NUMnp = NUMnp + 1
PRINT * , '# of H atom' , NUMnp
READ (10,*) atomhnum , (X(j,NUMnp),j=1,3)