-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgca_m3pfem.f90
1407 lines (1117 loc) · 41.8 KB
/
cgca_m3pfem.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
!*robodoc*m* CGPACK/cgca_m3pfem
! NAME
! cgca_m3pfem
! SYNOPSIS
!$Id: cgca_m3pfem.f90 380 2017-03-22 11:03:09Z mexas $
module cgca_m3pfem
! DESCRIPTION
! Module dealing with interfacing CGPACK with ParaFEM.
! AUTHOR
! Anton Shterenlikht, Luis Cebamanos
! COPYRIGHT
! See LICENSE
! CONTAINS
! Public coarray variables of derived types:
! cgca_pfem_centroid_tmp,
! cgca_pfem_integrity,
! cgca_pfem_stress.
!
! Public *local*, non-coarray, variable:
! cgca_pfem_enew.
!
! Private *local*, non-coarray, variables:
! lcentr.
!
! Public routines:
! cgca_pfem_boxin, cgca_pfem_cellin,
! cgca_pfem_cenc, cgca_pfem_cendmp, cgca_pfem_ctalloc,
! cgca_pfem_ctdalloc, cgca_pfem_ealloc, cgca_pfem_edalloc,
! cgca_pfem_intcalc1, cgca_pfem_integalloc, cgca_pfem_integdalloc,
! cgca_pfem_lcentr_dump (in submodule m3pfem_sm1),
! cgca_pfem_map (in submodule m3pfem_sm1),
! cgca_pfem_partin,
! cgca_pfem_salloc, cgca_pfem_sdalloc, cgca_pfem_sdmp,
! cgca_pfem_simg, cgca_pfem_uym, cgca_pfem_wholein
! USES
! Modules cgca_m1co, cgca_m2lnklst, cgca_m2geom
! USED BY
! end user?
! SOURCE
use :: cgca_m1co
use :: cgca_m2lnklst, only : cgca_lnklst_tpayld, cgca_lnklst_node, &
cgca_inithead, cgca_addhead, cgca_lstdmp, cgca_rmhead
use :: cgca_m2geom, only : cgca_boxsplit
implicit none
private
public :: &
! routines
cgca_pfem_boxin, cgca_pfem_cellin, &
cgca_pfem_cenc, cgca_pfem_cendmp, cgca_pfem_ctalloc, &
cgca_pfem_ctdalloc, cgca_pfem_ealloc, cgca_pfem_edalloc, &
cgca_pfem_integalloc, cgca_pfem_integdalloc, cgca_pfem_intcalc1, &
cgca_pfem_lcentr_dump, & ! in submodule m3pfem_sm1
cgca_pfem_map, & ! in submodule m3pfem_sm1
cgca_pfem_partin, &
cgca_pfem_salloc, cgca_pfem_sdalloc, cgca_pfem_sdmp, cgca_pfem_simg,&
cgca_pfem_uym, cgca_pfem_wholein, &
! variables
cgca_pfem_centroid_tmp, cgca_pfem_enew, cgca_pfem_integrity, &
cgca_pfem_stress
! corresponds to typical double precision real.
integer, parameter :: cgca_pfem_iwp = selected_real_kind(15,300)
interface
module subroutine cgca_pfem_lcentr_dump
end subroutine cgca_pfem_lcentr_dump
module subroutine cgca_pfem_map( origin, rot, bcol, bcou )
real( kind=rdef ), intent( in ) :: &
origin(3), & ! origin of the "box" cs, in FE cs
rot(3,3), & ! rotation tensor *from* FE cs *to* CA cs
bcol(3), & ! lower phys. coords of the coarray on image
bcou(3) ! upper phys. coords of the coarray on image
end subroutine cgca_pfem_map
end interface
!*roboend*
!*robodoc*d* cgca_m3pfem/lcentr
! NAME
! lcentr
! SYNOPSIS
type mcen
integer( kind=idef ) :: image
integer( kind=idef ) :: elnum
real( kind=cgca_pfem_iwp ) :: centr(3)
end type mcen
type( mcen ), allocatable :: lcentr(:)
! DESCRIPTION
! A *private* *local* allocatable array of derived type with 3
! components: (1) image number (2) the local element number on that
! image and (3) centroid coordinates in CA CS.
! Each entry in this array
! corresponds to an FE with centroid coordinates within the coarray
! "box" on this image.
!
! Assumption!! This is a 3D problems, so the centroid is
! defined by 3 coordinates, hence centr(3).
!
! MCEN stands for Mixed CENtroid data type.
! LCENTR stands for *Local* array of CENTRoids.
! NOTE
! This is *private* array, hence the name does not start
! with "cgca_pfem".
! USED BY
! Many routines of this module.
!*roboend*
!*robodoc*d* cgca_m3pfem/cgca_pfem_centroid_tmp
! NAME
! cgca_pfem_centroid_tmp
! SYNOPSIS
type rca
real( kind=cgca_pfem_iwp ), allocatable :: r(:,:)
end type rca
type( rca ) :: cgca_pfem_centroid_tmp[*]
! DESCRIPTION
! RCA stands for Rugged CoArray.
! cgca_pfem_centroid_tmp is a temporary scalar *coarray* of derived
! type with allocatable array component, storing centroids of ParaFEM
! finite elements, in FE coord. system, on this image.
! The array might be of different length on different images,
! so have to use an allocatable component of a coarray variable
! of derived type.
! USED BY
! routines of this module + end user
!*roboend*
!*robodoc*d* cgca_m3pfem/cgca_pfem_stress
! NAME
! cgca_pfem_stress
! SYNOPSIS
type type_stress
real( kind=cgca_pfem_iwp ), allocatable :: stress(:,:,:)
end type type_stress
type( type_stress ) :: cgca_pfem_stress[*]
! DESCRIPTION
! This is a coarray with a single allocatable array component,
! to store all stress components for all integration points
! for all elements on an image. Have to use a derived type
! because cgca_pfem_stress%stress can be allocated to different
! length on different images.
! This data will be read by all images.
!*roboend*
!*robodoc*d* cgca_m3pfem/cgca_pfem_integrity
! NAME
! cgca_pfem_integrity
! SYNOPSIS
type cgca_pfem_integ_type
real( kind=rdef ), allocatable :: i(:)
end type cgca_pfem_integ_type
type( cgca_pfem_integ_type ) :: cgca_pfem_integrity[*]
! DESCRIPTION
! A derived type is needed because the length of the integrity
! array will differ from image to image. So this is a scalar coarray
! of derived type with a single component: allocatable array of
! integrity, i. i=1 means to damage, i=0 means no remaining load
! bearing capacity.
! This data will be used to update the Young's modulus
! NOTE
! Set i to 1 on allocation to avoid problems later.
! The reason is that in cases when some FE are not
! connected to CA, the integrity of these FE will never be
! set of changed. So setting i to 1 on allocation is fool proof.
! USED BY
! cgca_pfem_uym + end user?
!*roboend*
!*robodoc*d* cgca_m3pfem/cgca_pfem_enew
! NAME
! cgca_pfem_enew
! SYNOPSIS
real( kind=cgca_pfem_iwp ), allocatable :: cgca_pfem_enew(:,:)
! DESCRIPTION
! Naming: E New as in new Young's modulus. This *local* array
! stores Young's moduli for each integration point of each
! FE on this image.
! USED BY
! cgca_pfem_uym + end user
!*roboend*
contains
!*robodoc*s* cgca_m3pfem/cgca_pfem_integalloc
! NAME
! cgca_pfem_integalloc
! SYNOPSIS
subroutine cgca_pfem_integalloc( nels_pp )
! INPUT
! nels_pp - elements per MPI process (per image).
integer, intent(in) :: nels_pp
! SIDE EFFECTS
! Allocatable array component cgca_pfem_integrity%i becomes allocated
! DESCRIPTION
! This routine allocates cgca_pfem_integrity%i on this image.
! This is a *local*, non-coarray, array. Hence this routine can be
! called by any or all images. It should be called by all images,
! of course.
!
! The array is allocated with the length equal to the number FE
! stored on *that* image.
!
! Must set i to 1, to take care of cases when some FE are not
! linked to CA. integrity for such FESuch FE which are
! USES
! cgca_pfem_integrity via host association.
! USED BY
! end user?
! SOURCE
integer :: errstat=0
allocate( cgca_pfem_integrity%i( nels_pp ), source=1.0_rdef, &
stat=errstat )
if ( errstat .ne. 0 ) then
write (*,"(a,i0)") &
"ERROR: cgca_pfem_integalloc: allocate( cgca_pfem_integrity%i )", &
errstat
error stop
end if
end subroutine cgca_pfem_integalloc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_integdalloc
! NAME
! cgca_pfem_integdalloc
! SYNOPSIS
subroutine cgca_pfem_integdalloc
! SIDE EFFECTS
! Allocatable array component of cgca_pfem_integrity coarray becomes
! deallocated.
! DESCRIPTION
! This routine deallocates allocatable array component of integrity:
! cgca_pfem_integrity%i.
! USES
! cgca_pfem_integrity via host association
! USED BY
! end user?
! SOURCE
integer :: errstat=0
deallocate( cgca_pfem_integrity%i, stat=errstat )
if ( errstat .ne. 0 ) then
write (*,"(a,i0)") &
"ERROR: cgca_pfem_integalloc: deallocate( cgca_pfem_integrity%i )", &
errstat
error stop
end if
end subroutine cgca_pfem_integdalloc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_ealloc
! NAME
! cgca_pfem_ealloc
! SYNOPSIS
subroutine cgca_pfem_ealloc( nip, nels_pp )
! INPUTS
! nip - integer, number of integration points
! nels_pp - elements per MPI process (per image).
integer, intent( in ) :: nip, nels_pp
! SIDE EFFECTS
! Allocatable *local* array enew becomes allocated
! DESCRIPTION
! This routine allocates an allocatable *local* array.
! The allocatable array stores the Young's modulus
! per FE element and integration point, for all FE
! that are stored on this image.
! USED BY
! end user?
! SOURCE
integer :: errstat=0
allocate( cgca_pfem_enew( nip, nels_pp ), stat=errstat )
if ( errstat .ne. 0 ) then
write (*,"(a,i0)") &
"ERROR: cgca_pfem_ealloc: allocate( cgca_pfem_enew ), err. status", &
errstat
error stop
end if
end subroutine cgca_pfem_ealloc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_edalloc
! NAME
! cgca_pfem_edalloc
! SYNOPSIS
subroutine cgca_pfem_edalloc
! SIDE EFFECTS
! Allocatable *local* array cgca_pfem_enew becomes deallocated.
! DESCRIPTION
! This routine deallocates an allocatable *local* array used to
! store the Young's modulus per FE element and integration point
! USES
! cgca_pfem_enew via host association.
! USED BY
! end user?
! SOURCE
integer :: errstat=0
deallocate( cgca_pfem_enew, stat=errstat )
if ( errstat .ne. 0 ) error stop &
"ERROR: cgca_pfem_ealloc: deallocate( cgca_pfem_enew )"
end subroutine cgca_pfem_edalloc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_uym
! NAME
! cgca_pfem_uym
! SYNOPSIS
subroutine cgca_pfem_uym( e_orig, nels_pp )
! INPUTS
! e_orig - *real* is the original Young's modulus.
! For now assume a single value, i.e. all int points
! have identical original value.
! nels_pp - number of FEs for this image.
real( kind=cgca_pfem_iwp ), intent(in) :: e_orig
integer, intent(in) :: nels_pp
! SIDE EFFECTS
! The Young's modulus gets updated with integrity
! DESCRIPTION
! UYM stands for Update Young's Modulus
! This routine updates the value of the Young's modulus, e,
! e = e_original * integrity.
! Integrity - integer, cell integrity (from 0.0 to 1.0)
! NOTES
! Purely local routine, no coarray operations.
! It seems the Young's modulus of 0 causes instability.
! So don't let it get to 0, use a small factor instead, e.g. 1.0e-3.
! USES
! cgca_pfem_enew, cgca_pfem_integrity, all via host association.
! USED BY
! end user?
! SOURCE
real( kind=rdef ), parameter :: factor = 1.0e-3_rdef
integer :: fe
do fe = 1, nels_pp
cgca_pfem_enew( : , fe ) = max( factor*e_orig, &
e_orig * cgca_pfem_integrity % i( fe ) )
end do
end subroutine cgca_pfem_uym
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_ctalloc
! NAME
! cgca_pfem_ctalloc
! SYNOPSIS
subroutine cgca_pfem_ctalloc( ndim, nels_pp )
! INPUTS
integer, intent( in ) :: ndim, nels_pp
! ndim - integer, number of DOF per node.
! nels_pp - elements per MPI process (per image).
! SIDE EFFECTS
! Allocatable array component cgca_pfem_centroid_tmp%r becomes
! allocated.
! DESCRIPTION
! CTA stands for Centroids Temporary Allocate.
! This routine allocates an allocatable array component of scalar
! coarray cgca_pfem_centroid_tmp.
! The allocatable array stores FE centroid coordinates
! together with their numbers and MPI ranks where these are stored.
! NOTES
! The array component can of different length on different images.
! USES
! USED BY
! SOURCE
integer :: errstat=0
allocate( cgca_pfem_centroid_tmp%r( ndim, nels_pp ), &
source=0.0_cgca_pfem_iwp, &
stat=errstat )
if ( errstat .ne. 0 ) error stop &
"ERROR: cgca_pfem_ctalloc: allocate( cgca_pfem_centroid_tmp%r )"
end subroutine cgca_pfem_ctalloc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_ctdalloc
! NAME
! cgca_pfem_ctdalloc
! SYNOPSIS
subroutine cgca_pfem_ctdalloc
! SIDE EFFECTS
! Allocatable array component of cgca_pfem_centroid_tmp becomes
! deallocate
! DESCRIPTION
! CTD stands for Centroids Temporary Allocate.
! This routine deallocates an allocatable array component of coar.
! This must be done only after all images copied the contents of
! type( rca ) :: cgca_pfem_centroid_tmp[*] into their local,
! *not* coarray centroid arrays.
! USES
! USED BY
! SOURCE
integer :: errstat=0
deallocate( cgca_pfem_centroid_tmp%r, stat=errstat )
if ( errstat .ne. 0 ) error stop &
"ERROR: cgca_pfem_ctd: deallocate( cgca_pfem_centroid_tmp%r )"
end subroutine cgca_pfem_ctdalloc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_cenc
! NAME
! cgca_pfem_cenc
! SYNOPSIS
subroutine cgca_pfem_cenc( origin, rot, bcol, bcou )
! INPUTS
real( kind=rdef ), intent( in ) :: &
origin(3), & ! origin of the "box" cs, in FE cs
rot(3,3), & ! rotation tensor *from* FE cs *to* CA cs
bcol(3), & ! lower phys. coords of the coarray on image
bcou(3) ! upper phys. coords of the coarray on image
! SIDE EFFECTS
! Array lcentr is changed.
! DESCRIPTION
! CENC stands for CENtroids Collection.
! This routine reads centroids of all elements, in FE coord.
! system, from all MPI processes and adds those with centroids
! within its CA "box" to its lcentr array.
! NOTES
! This routine must be called only after coarray
! cgca_pfem_centroid_tmp has been established on all images.
! This routine *reads* coarrays on other images, hence
! sync must be used before calling this routine.
! However, the routine *does not* change coarrays, only reads.
! So no syncs are required inside this routine, as it constitutes
! a single execution segment.
! This routine uses all-to-all comm pattern. This might be
! inefficient on large numbers of PEs. In this case on can use
! cgca_pfem_map (in submodule m3pfem_sm1) instead, which
! does the same calculation using collectives and large tmp arrays.
! USES
! lcentr via host association.
! SOURCE
! initial length of lcentr array. A good choice will reduce the number
! of deallocate/allocate and will use the memory better.
integer, parameter :: lclenini = 100
integer :: errstat, i, j, nimgs, nelements, img_curr, ndims, rndint, &
lclen, & ! current length of the lcentr array
lcel ! number of elements in lcentr array
! centroid coords in CA cs
real( kind=cgca_pfem_iwp ) :: cen_ca(3) ! 3D case only
real( kind=cgca_pfem_iwp ), allocatable :: tmp(:,:)
real :: rnd
! temp array to expand/contract lcentr
type( mcen ), allocatable :: lctmp(:)
nimgs = num_images()
! Allocate lcentr to the initial guess size.
lclen = lclenini
allocate( lcentr( lclen ), stat=errstat )
if ( errstat .ne. 0 ) then
write (*,'(a,i0)') &
"ERROR: cgca_pfem_cenc: allocate( lcentr ), error code: ", errstat
error stop
end if
! There are no elements yet in lcentr array
lcel = 0
! Choose the first image at random
! It is assumed that the RND has been initialised by a call
! to cgca_irs earlier on.
call random_number( rnd ) ! [ 0 .. 1 )
rndint = int( rnd*nimgs )+1 ! [ 1 .. nimgs ]
! loop over all images, starting at a randomly chosen image
images: do i=rndint, rndint+nimgs-1
! Get the current image number.
! If it's > nimgs, subtract nimgs
img_curr = i
if ( img_curr .gt. nimgs ) img_curr = img_curr - nimgs
! how many elements
ndims = size( cgca_pfem_centroid_tmp[ img_curr ] % r, dim=1 )
nelements = size( cgca_pfem_centroid_tmp[ img_curr ] % r, dim=2 )
! use a temp array to pull all centroids data in one call
allocate( tmp( ndims, nelements ), source=0.0_cgca_pfem_iwp, &
stat=errstat )
if ( errstat .ne. 0 ) &
error stop "ERROR: cgca_m3pfem/cgca_pfem_cenc: allocate( tmp )"
tmp = cgca_pfem_centroid_tmp[ img_curr ] % r
! loop over all elements on that image
elements: do j = 1, nelements
! Convert centroid coordinates from FE cs to CA cs
! cgca_pfem_centroid_tmp[i] - variable on image i
! cgca_pfem_centroid_tmp[i]%r - component that is the centroids
! real array
! cgca_pfem_centroid_tmp[i]%r(:,j) - take finite element j, and all
! centroid coordinates for it.
!
! old algorithm - lots of small remote calls:
! cen_ca = &
! matmul( rot, cgca_pfem_centroid_tmp[ img_curr ]%r(:,j) - origin )
!
cen_ca = matmul( rot, tmp(:,j) - origin )
! Check whether CA cs centroid is within the box.
! If all CA cs centroid coordinates are greater or equal to
! the lower bound of the box, and all of them are also
! less of equal to the upper bound of the box, then the centroid
! is inside. Then add the new entry.
inside: if ( all( cen_ca .ge. bcol ) .and. &
all( cen_ca .le. bcou ) ) then
! Increment the number of elements
lcel = lcel + 1
! Expand the array if there is no space left to add the new entry.
expand: if ( lclen .lt. lcel ) then
! Double the length of the array
lclen = 2 * lclen
! Allocate a temp array of this length
allocate( lctmp( lclen ), stat=errstat )
if ( errstat .ne. 0 ) error stop &
"ERROR: cgca_pfem_cenc: allocate( lctmp ) 1"
! copy lcentr into the beginning of lctmp
lctmp( 1:size( lcentr ) ) = lcentr
! move allocation from the temp array back to lcentr
call move_alloc( lctmp, lcentr )
end if expand
! Add new entry
lcentr( lcel ) = mcen( img_curr, j, cen_ca )
end if inside
end do elements
deallocate( tmp, stat=errstat )
if ( errstat .ne. 0 ) &
error stop "ERROR: cgca_pfem_cenc: deallocate( tmp )"
end do images
! Trim lcentr if it is longer than the number of elements
if ( lclen .gt. lcel ) then
! Allocate temp array to the number of elements
allocate( lctmp( lcel ), stat=errstat )
if ( errstat .ne. 0 ) error stop &
"ERROR: cgca_pfem_cenc: allocate( lctmp ) 2"
! Copy lcentr elements to the temp array
lctmp = lcentr( 1 : lcel )
! move allocation from lctmp back to lcentr
call move_alloc( lctmp, lcentr )
end if
end subroutine cgca_pfem_cenc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_cendmp
! NAME
! cgca_pfem_cendmp
! SYNOPSIS
subroutine cgca_pfem_cendmp
! SIDE EFFECTS
! Dumps some data to stdout
! DESCRIPTION
! CENDMP stands for CENtroids array dump.
! This routine dumps lcentr to stdout.
! NOTES
! Must call from all images.
! SOURCE
integer :: i, img
img = this_image()
do i = 1, size( lcentr )
write (*,"(3(a,i0),a,3(es10.2,tr1))") &
"CA on img " , img , &
" <-> FE " , lcentr(i)%elnum , &
" on img " , lcentr(i)%image , &
" centr. in CA cs" , lcentr(i)%centr
end do
end subroutine cgca_pfem_cendmp
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_salloc
! NAME
! cgca_pfem_salloc
! SYNOPSIS
subroutine cgca_pfem_salloc( nels_pp, intp, comp )
! INPUTS
! nels_pp - number of elements on this image
! intp - number of integration points per element
! comp - number of stress tensor components
integer, intent( in ) :: nels_pp, intp, comp
! SIDE EFFECTS
! Allocatable component array cgca_pfem_stress%stress becomes
! allocated
! DESCRIPTION
! SALLOC stands for Allocate Stress tensor array.
! This routine allocates an allocatable array component of coar.
! The allocatable array stores all stress tensor components,
! for all integration points on all elements on an image.
! USES
! cgca_pfem_iwp, host association
! USED BY
! end user
! SOURCE
integer :: errstat=0
allocate( cgca_pfem_stress%stress( nels_pp, intp, comp ), &
source=0.0_cgca_pfem_iwp, stat=errstat )
if ( errstat .ne. 0 ) then
write (*,"(a,i0)") "ERROR: cgca_pfem_salloc: allocate( &
&cgca_pfem_stress%stress ), err. status: ", errstat
error stop
end if
end subroutine cgca_pfem_salloc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_sdalloc
! NAME
! cgca_pfem_sdalloc
! SYNOPSIS
subroutine cgca_pfem_sdalloc
! SIDE EFFECTS
! allocatable array cgca_pfem_stress%stress become deallocated
! DESCRIPTION
! SDALLOC stands for Deallocate Stress tensor array.
! This routine deallocates allocatable array component of coar.
! This routine should be called only when the analysis is complete.
! Any and every image can call this routine.
! USES
! cgca_pfem_stress%stress, host association
! USED BY
! SOURCE
integer :: errstat=0
deallocate( cgca_pfem_stress%stress, stat=errstat )
if ( errstat .ne. 0 ) then
write (*,"(a,i0)") "ERROR: cgca_pfem_sdalloc: deallocate( &
&cgca_pfem_stress%stress ), err. status: ", errstat
error stop
end if
end subroutine cgca_pfem_sdalloc
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_sdmp
! NAME
! cgca_pfem_sdmp
! SYNOPSIS
subroutine cgca_pfem_sdmp
! SIDE EFFECTS
! Dumps some data to stdout
! DESCRIPTION
! SDMP stands for Stress tensor dump.
! This routine dumps stress tensors to stdout.
! NOTES
! Must call from all images.
! SOURCE
integer :: img, nel, nintp, el, intp
img = this_image()
nel = size( cgca_pfem_stress%stress, dim=1 )
nintp = size( cgca_pfem_stress%stress, dim=2 )
do el = 1, nel
do intp = 1, nintp
write (*,*) "img", img, "FE", el, "int p.", intp, "stress", &
cgca_pfem_stress%stress( el, intp, : )
end do
end do
end subroutine cgca_pfem_sdmp
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_simg
! NAME
! cgca_pfem_simg
! SYNOPSIS
subroutine cgca_pfem_simg( simg )
! OUTPUT
! simg - mean stress tensor over all integration points on all
! finite elements linked to CA on this image.
! Note that I use CGPACK kind, because this var will be input to
! a CGPACK routine.
real( kind=rdef ), intent(out) :: simg(3,3)
! DESCRIPTION
! SIMG stands for mean Stress on an Image.
! The routine reads all stress tensors from all integration
! points for all elements which are linked to CA on this image,
! i.e. from lcentr array, and calculates the mean value.
! This value is then used to pass to the cleavage routine.
! NOTE
! If size( lcentr ) .eq. 0, then there are no FE associated
! with coarray on this image. The set simg to 0.
! SOURCE
integer, parameter :: comp=6 ! number of stress components
! Running total stress array
real( kind=rdef ) :: stot( comp )
! Temp stress array, to store remotely read values
real( kind=rdef ), allocatable :: str_tmp( : , : )
integer :: el, nel, rel, nintp, rimg, errstat
! Assertion check
! The number of stress components (6) is the same as dimension 3 of
! cgca_pfem_stress%stress
if ( size( cgca_pfem_stress%stress, dim=3 ) .ne. comp ) &
error stop "ERROR: cgca_pfem_simg: &
&size( cgca_pfem_stress%stress, dim=3 ) .ne. comp"
! Total number of elements linked to CA model on this image
! Total number of int. points per element
nel = size( lcentr )
nintp = size( cgca_pfem_stress%stress, dim=2 )
! If there are no FE linked to this image, set simg to 0
! and return immediately.
if ( nel .eq. 0 ) then
simg = 0.0_rdef
return
end if
! Allocate tmp stress array
allocate( str_tmp( nintp, comp ), source=0.0_rdef, stat=errstat )
if ( errstat .ne. 0 ) &
error stop "ERROR: cgca_pfem_simg: allocate( str_tmp )"
! Add all stress tensors together. Loop over all elements linked
! to CA on this image and over all int. points.
stot = 0.0_rdef
do el=1, nel
! Calculate the image and the element numbers to read the stress
! data from.
rimg = lcentr(el) % image
rel = lcentr(el) % elnum
! Remote read of all stress values for this element
str_tmp = &
real( cgca_pfem_stress[ rimg ] % stress( rel, : , : ), kind=rdef )
! Sum over all int. points, i.e. 1st dimension
stot = stot + sum( str_tmp( : , : ), dim=1 )
end do
! Construct a (3,3) matrix from (6) vector.
! Observe the component order of ParaFEM
! sx=stress(1)
! sy=stress(2)
! sz=stress(3)
! txy=stress(4)
! tyz=stress(5)
! tzx=stress(6)
! sigm=(sx+sy+sz)/three
!https://code.google.com/p/parafem/source/browse/trunk/parafem/src/modules/shared/new_library.f90
simg(1,1) = stot(1)
simg(2,2) = stot(2)
simg(3,3) = stot(3)
simg(1,2) = stot(4)
simg(2,3) = stot(5)
simg(3,1) = stot(6)
simg(2,1) = simg(1,2)
simg(3,2) = simg(2,3)
simg(1,3) = simg(3,1)
! calculate the mean
simg = simg / real( nel*nintp, kind=rdef )
! deallocate temp stress array
deallocate( str_tmp, stat=errstat )
if ( errstat .ne. 0 ) then
write (*,'(a,i0)') &
"ERROR: cgca_pfem_simg: deallocate( str_tmp ), err. code: ", errstat
error stop
end if
end subroutine cgca_pfem_simg
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_intcalc1
! NAME
! cgca_pfem_intcalc1
! SYNOPSIS
subroutine cgca_pfem_intcalc1( arrsize, fracvol )
! INPUTS
! arrsize - contains the 3 sizes of the space coarray.
! Using the coarray sizes, the characteristic coarray
! area is calculated.
! fracvol - *real*, the number of failed (fractured) cells for each
! image. It is calculated by cgca_fv, which *must* be called prior to
! calling this routine.
integer( kind=iarr ), intent( in ) :: arrsize(3)
real( kind=rdef), intent( in ) :: fracvol
! SIDE EFFECTS
! cgca_pfem_integrity array changes
! DESCRIPTION
! All FEs linked to this image get the same value of integrity.
! These are all FEs in lcentr array. For entry i in this
! array this is FE cgca_pfem_integrity( lcentr(i)%elnum )
! on image lcentr(i)%image.
!
! The integrity is 1 minus the ratio of number of
! failed cells to the cracteristic coarray area.
! If integrity < 0, set it to zero.
! USES
! lcentr via host association
! USED BY
! end user?
! SOURCE
real :: carea ! characteristic area
integer, parameter :: kind_integ = kind( cgca_pfem_integrity % i )
real( kind=kind_integ ), parameter :: one = 1_kind_integ
integer( kind=idef ) :: i
! Volume, in cells, is the product of 3 coarray sizes.
! Don't forget to remove the halo cells!
! Characteristic area is volume ** 2/3
carea = product( real( arrsize-2 ) ) ** 0.66666666666666666667
do i = 1, size( lcentr )
! integrity is calculate as: i = 1 - min(1,f),
! Integrity has the range [1..0], where i=1 for f=0, i=0 for f=1.
! f=fracvol / carea - Fraction of failed cells, 0 if no fracture,
! 1 or above when I consider the CA to have no
! load bearing capacity.
! min( 1, fraction) - To make sure fraction is [0..1].
cgca_pfem_integrity[ lcentr(i)%image ] % i( lcentr(i)%elnum ) = &
one - min( one, fracvol / carea )
end do
end subroutine cgca_pfem_intcalc1
!*roboend*
!*robodoc*s* cgca_m3pfem/cgca_pfem_cellin
! NAME
! cgca_pfem_cellin
! SYNOPSIS
subroutine cgca_pfem_cellin( index, lc, lres, bcol, charlen, debug, flag )
! INPUTS
! index - represents each corner cell
! lc(3) - integer, local coordinates of a cell in the space
! coarray on *this* image.
! lres - real, linear resolution of the model, how many cells per
! linear physical unit of length.
! bcol(3) - real, coordinates of the coarray box on this image
! in physical units, in CA coord. system.
! charlen - real, characteristic length of an FE in the model.
! This parameter is used to determine whether a cell is "close
! enough" to a centroid of an FE.
! debug - logical. If .true. will dump some debug info
integer( kind=idef ), intent( in ) :: index
integer( kind=idef ), intent( in ) :: lc(index,3)
real( kind=rdef ), intent( in ) :: lres, bcol(3), charlen
logical( kind=ldef ), intent( in ) :: debug
! OUTPUTS
! flag - logical, .true. if the cell in "inside" the FE model,
! .false. otherwise
logical( kind=ldef ), intent( out ) :: flag
! SIDE EFFECTS
! if debug is .true. dumps some output to stdout. Othewise none.