DAMASK with grid solvers  Revision: v2.0.3-2204-gdb1f2151
The Düsseldorf Advanced Material Simulation Kit with Grid Solvers
spectral_utilities.f90
Go to the documentation of this file.
1 # 1 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/grid/spectral_utilities.f90"
2 # 1 "<built-in>"
3 # 1 "<command-line>"
4 # 1 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/grid/spectral_utilities.f90"
5 !--------------------------------------------------------------------------------------------------
9 !--------------------------------------------------------------------------------------------------
11  use, intrinsic :: iso_c_binding
12 
13 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 1
14 !
15 !
16 ! Part of the base include file for Fortran use of 1.
17 ! Note: This file should contain only define statements and
18 ! not the declaration of variables.
19 
20 ! No spaces for #defines as some compilers (PGI) also adds
21 ! those additional spaces during preprocessing - bad for fixed format
22 !
23 
24 
25 
26 # 1 "/opt/petsc-3.10.3/Intel-18.4-IntelMPI-2018/include/petscconf.h" 1
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 
1001 
1002 
1003 
1004 
1005 
1006 
1007 
1008 
1009 
1010 
1011 
1012 
1013 
1014 
1015 
1016 
1017 
1018 
1019 
1020 
1021 
1022 
1023 
1024 
1025 
1026 
1027 
1028 
1029 
1030 
1031 
1032 
1033 
1034 
1035 
1036 
1037 
1038 
1039 
1040 
1041 
1042 
1043 
1044 
1045 
1046 
1047 
1048 
1049 
1050 
1051 
1052 
1053 
1054 
1055 
1056 
1057 
1058 
1059 
1060 
1061 
1062 
1063 
1064 
1065 
1066 
1067 
1068 
1069 
1070 
1071 
1072 
1073 
1074 
1075 
1076 
1077 
1078 
1079 
1080 
1081 
1082 
1083 
1084 
1085 
1086 
1087 
1088 
1089 
1090 
1091 
1092 
1093 
1094 
1095 
1096 
1097 
1098 
1099 
1100 
1101 
1102 
1103 
1104 
1105 
1106 
1107 
1108 
1109 
1110 
1111 
1112 
1113 
1114 
1115 
1116 
1117 
1118 
1119 
1120 
1121 
1122 
1123 
1124 
1125 
1126 
1127 
1128 
1129 
1130 
1131 
1132 
1133 
1134 
1135 
1136 
1137 
1138 
1139 
1140 
1141 
1142 
1143 
1144 
1145 
1146 
1147 
1148 
1149 
1150 
1151 
1152 
1153 
1154 
1155 
1156 
1157 
1158 
1159 
1160 
1161 
1162 
1163 
1164 
1165 
1166 
1167 
1168 
1169 
1170 
1171 
1172 
1173 
1174 
1175 
1176 
1177 
1178 
1179 
1180 
1181 
1182 
1183 
1184 
1185 
1186 
1187 
1188 
1189 
1190 
1191 
1192 
1193 
1194 
1195 
1196 
1197 
1198 
1199 
1200 
1201 
1202 
1203 
1204 
1205 
1206 
1207 
1208 
1209 
1210 
1211 
1212 
1213 
1214 
1215 
1216 
1217 
1218 
1219 
1220 
1221 
1222 
1223 
1224 
1225 
1226 
1227 
1228 
1229 
1230 
1231 
1232 
1233 
1234 # 13 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1235 
1236 
1237 
1238 
1239 # 1 "/opt/petsc-3.10.3/include/petscversion.h" 1
1240 
1241 
1242 
1243 
1244 
1245 
1246 
1247 
1248 
1249 
1250 
1251 
1252 
1253 
1254 
1255 
1256 
1257 
1258 
1259 
1260 
1261 
1262 
1263 
1264 
1265 
1266 
1267 
1268 
1269 
1270 
1271 
1272 
1273 
1274 
1275 
1276 
1277 
1278 
1279 
1280 
1281 
1282 
1283 
1284 
1285 # 17 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1286 
1287 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petscviewer.h" 1
1288 !
1289 ! Include file for Fortran use of the PetscViewer package in 1
1290 !
1291 
1292 
1293 
1294 
1295 
1296 
1297 
1298 
1299 
1300 
1301 
1302 
1303 
1304 # 31 "/opt/petsc-3.10.3/include/petsc/finclude/petscviewer.h"
1305 
1306 # 18 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1307 
1308 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petscerror.h" 1
1309 
1310 !
1311 ! Include file for Fortran error codes
1312 ! These are also in include/petscerror.h
1313 !
1314 
1315 
1316 
1317 # 24 "/opt/petsc-3.10.3/include/petsc/finclude/petscerror.h"
1318 
1319 # 38 "/opt/petsc-3.10.3/include/petsc/finclude/petscerror.h"
1320 
1321 
1322 
1323 
1324 
1325 
1326 
1327 
1328 
1329 
1330 
1331 
1332 
1333 
1334 
1335 
1336 # 19 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1337 
1338 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petsclog.h" 1
1339 !
1340 ! No includes needed for logging
1341 # 20 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1342 
1343 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petscbag.h" 1
1344 !
1345 !
1346 ! Include file for Fortran use of the Bag package in 1
1347 !
1348 
1349 
1350 
1351 
1352 
1353 !
1354 ! End of Fortran include file for the IS package in 1
1355 
1356 # 21 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1357 
1358 !
1359 ! The real*8,complex*16 notatiton is used so that the
1360 ! 1 double/complex variables are not affected by
1361 ! compiler options like -r4,-r8, sometimes invoked
1362 ! by the user. NAG compiler does not like integer*4,real*8
1363 
1364 # 41 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1365 
1366 
1367 
1368 
1369 
1370 
1371 
1372 
1373 
1374 # 63 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1375 
1376 
1377 
1378 
1379 
1380 
1381 !
1382 
1383 
1384 
1385 
1386 
1387 !
1388 # 85 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1389 !
1390 
1391 
1392 
1393 
1394 
1395 
1396 !
1397 
1398 
1399 
1400 
1401 !
1402 
1403 !
1404 
1405 
1406 !
1407 # 128 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1408 
1409 # 150 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1410 !
1411 ! Macro for templating between real and complex
1412 !
1413 # 174 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1414 
1415 
1416 
1417 
1418 
1419 
1420 
1421 
1422 
1423 !
1424 ! Allows the matrix Fortran Kernels to work with single precision
1425 ! matrix data structures
1426 !
1427 
1428 !
1429 ! PetscLogDouble variables are used to contain double precision numbers
1430 ! that are not used in the numerical computations, but rather in logging,
1431 ! timing etc.
1432 !
1433 
1434 
1435 !
1436 ! Macros for error checking
1437 !
1438 
1439 
1440 
1441 
1442 
1443 
1444 
1445 
1446 # 215 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1447 
1448 
1449 
1450 
1451 
1452 
1453 
1454 
1455 
1456 
1457 
1458 
1459 # 9 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/grid/spectral_utilities.f90" 2
1460  use petscsys
1461 
1462  use prec
1463  use damask_interface
1464  use math
1465  use rotations
1466  use io
1468  use numerics
1469  use debug
1470  use config
1471  use discretization
1472  use homogenization
1473 
1474  implicit none
1475  private
1476 
1477  include 'fftw3-mpi.f03'
1478 
1479 !--------------------------------------------------------------------------------------------------
1480 ! field labels information
1481  enum, bind(c); enumerator :: &
1483  field_mech_id, &
1484  field_thermal_id, &
1486  end enum
1487 
1488 !--------------------------------------------------------------------------------------------------
1489 ! grid related information information
1490  real(preal), protected, public :: wgt
1491  integer, protected, public :: grid1red
1492  real(preal), protected, public, dimension(3) :: scaledgeomsize
1493 
1494 !--------------------------------------------------------------------------------------------------
1495 ! variables storing information for spectral method and FFTW
1496 
1497  real (c_double), public, dimension(:,:,:,:,:), pointer :: tensorfield_real
1498  complex(C_DOUBLE_COMPLEX),public, dimension(:,:,:,:,:), pointer :: tensorfield_fourier
1499  real(c_double), public, dimension(:,:,:,:), pointer :: vectorfield_real
1500  complex(C_DOUBLE_COMPLEX),public, dimension(:,:,:,:), pointer :: vectorfield_fourier
1501  real(c_double), public, dimension(:,:,:), pointer :: scalarfield_real
1502  complex(C_DOUBLE_COMPLEX),public, dimension(:,:,:), pointer :: scalarfield_fourier
1503  complex(pReal), private, dimension(:,:,:,:,:,:,:), allocatable :: gamma_hat
1504  complex(pReal), private, dimension(:,:,:,:), allocatable :: xi1st
1505  complex(pReal), private, dimension(:,:,:,:), allocatable :: xi2nd
1506  real(preal), private, dimension(3,3,3,3) :: c_ref
1507 
1508 
1509 !--------------------------------------------------------------------------------------------------
1510 ! plans for FFTW
1511  type(c_ptr), private :: &
1512  plantensorforth, & !< FFTW MPI plan P(x) to P(k)
1513  plantensorback, & !< FFTW MPI plan F(k) to F(x)
1514  planvectorforth, & !< FFTW MPI plan v(x) to v(k)
1515  planvectorback, & !< FFTW MPI plan v(k) to v(x)
1516  planscalarforth, & !< FFTW MPI plan s(x) to s(k)
1518 
1519 !--------------------------------------------------------------------------------------------------
1520 ! variables controlling debugging
1521  logical, private :: &
1522  debuggeneral, & !< general debugging of spectral solver
1523  debugrotation, & !< also printing out results in lab frame
1524  debugpetsc
1525 
1526 !--------------------------------------------------------------------------------------------------
1527 ! derived types
1528  type, public :: tsolutionstate
1529  integer :: &
1530  iterationsneeded = 0
1531  logical :: &
1532  converged = .true., &
1533  stagconverged = .true., &
1534  termill = .false.
1535  end type tsolutionstate
1536 
1537  type, public :: tboundarycondition
1538  real(preal), dimension(3,3) :: values = 0.0_preal, &
1539  maskfloat = 0.0_preal
1540  logical, dimension(3,3) :: masklogical = .false.
1541  character(len=pStringLen) :: mytype = 'None'
1542  end type tboundarycondition
1543 
1544  type, public :: tloadcase
1545  type(rotation) :: rot
1546  type(tboundarycondition) :: stress, & !< stress BC
1547  deformation
1548  real(preal) :: time = 0.0_preal
1549  integer :: incs = 0, & !< number of increments
1550  outputfrequency = 1, &
1551  restartfrequency = huge(0), &
1552  logscale = 0
1553  logical :: followformertrajectory = .true.
1554  integer(kind(FIELD_UNDEFINED_ID)), allocatable :: id(:)
1555  end type tloadcase
1556 
1557  type, public :: tsolutionparams
1558  real(preal), dimension(3,3) :: stress_mask, stress_bc
1559  type(rotation) :: rotation_bc
1560  real(preal) :: timeinc
1561  real(preal) :: timeincold
1562  end type tsolutionparams
1563 
1564  type, private :: tnumerics
1565  real(preal) :: &
1566  fftw_timelimit
1567  integer :: &
1568  divergence_correction
1569  logical :: &
1570  memory_efficient
1571  character(len=pStringLen) :: &
1572  spectral_derivative, & !< approximation used for derivatives in Fourier space
1573  fftw_plan_mode, & !< FFTW plan mode, see www.fftw.org
1574  petsc_options
1575  end type tnumerics
1576 
1577  type(tnumerics) :: num ! numerics parameters. Better name?
1578 
1579  enum, bind(c); enumerator :: &
1583  end enum
1584 
1585  integer(kind(DERIVATIVE_CONTINUOUS_ID)) :: &
1587 
1588  public :: &
1589  utilities_init, &
1612  field_mech_id, &
1613  field_thermal_id, &
1615 
1616 contains
1617 
1618 !--------------------------------------------------------------------------------------------------
1625 !--------------------------------------------------------------------------------------------------
1626 subroutine utilities_init
1628  integer(kind=selected_int_kind(5)) :: ierr
1629  integer :: i, j, k, &
1630  fftw_planner_flag
1631  integer, dimension(3) :: k_s
1632  type(c_ptr) :: &
1633  tensorfield, & !< field containing data for FFTW in real and fourier space (in place)
1634  vectorfield, & !< field containing data for FFTW in real space when debugging FFTW (no in place)
1635  scalarfield
1636  integer(C_INTPTR_T), dimension(3) :: gridfftw
1637  integer(C_INTPTR_T) :: alloc_local, local_k, local_k_offset
1638  integer(C_INTPTR_T), parameter :: &
1639  scalarsize = 1_c_intptr_t, &
1640  vecsize = 3_c_intptr_t, &
1641  tensorsize = 9_c_intptr_t
1642 
1643  write(6,'(/,a)') ' <<<+- spectral_utilities init -+>>>'
1644 
1645  write(6,'(/,a)') ' Diehl, Diploma Thesis TU München, 2010'
1646  write(6,'(a)') ' https://doi.org/10.13140/2.1.3234.3840'
1647 
1648  write(6,'(/,a)') ' Eisenlohr et al., International Journal of Plasticity 46:37–53, 2013'
1649  write(6,'(a)') ' https://doi.org/10.1016/j.ijplas.2012.09.012'
1650 
1651  write(6,'(/,a)') ' Shanthraj et al., International Journal of Plasticity 66:31–45, 2015'
1652  write(6,'(a)') ' https://doi.org/10.1016/j.ijplas.2014.02.006'
1653 
1654  write(6,'(/,a)') ' Shanthraj et al., Handbook of Mechanics of Materials, 2019'
1655  write(6,'(a)') ' https://doi.org/10.1007/978-981-10-6855-3_80'
1656 
1657 !--------------------------------------------------------------------------------------------------
1658 ! set debugging parameters
1662 
1663  if(debugpetsc) write(6,'(3(/,a),/)') &
1664  ' Initializing PETSc with debug options: ', &
1665  trim(petscdebug), &
1666  ' add more using the PETSc_Options keyword in numerics.config '; flush(6)
1667 
1668  call petscoptionsclear(petsc_null_options,ierr)
1669  if (ierr .ne. 0) then;call petscerrorf(ierr);return;endif
1670  if(debugpetsc) call petscoptionsinsertstring(petsc_null_options,trim(petscdebug),ierr)
1671  if (ierr .ne. 0) then;call petscerrorf(ierr);return;endif
1672  call petscoptionsinsertstring(petsc_null_options,trim(petsc_options),ierr)
1673  if (ierr .ne. 0) then;call petscerrorf(ierr);return;endif
1674 
1675  grid1red = grid(1)/2 + 1
1676  wgt = 1.0/real(product(grid),preal)
1677 
1678  write(6,'(/,a,3(i12 ))') ' grid a b c: ', grid
1679  write(6,'(a,3(es12.5))') ' size x y z: ', geomsize
1680 
1681  num%memory_efficient = config_numerics%getInt ('memory_efficient', defaultval=1) > 0
1682  num%FFTW_timelimit = config_numerics%getFloat ('fftw_timelimit', defaultval=-1.0_preal)
1683  num%divergence_correction = config_numerics%getInt ('divergence_correction', defaultval=2)
1684  num%spectral_derivative = config_numerics%getString('spectral_derivative', defaultval='continuous')
1685  num%FFTW_plan_mode = config_numerics%getString('fftw_plan_mode', defaultval='FFTW_MEASURE')
1686 
1687  if (num%divergence_correction < 0 .or. num%divergence_correction > 2) &
1688  call io_error(301,ext_msg='divergence_correction')
1689 
1690  select case (num%spectral_derivative)
1691  case ('continuous')
1693  case ('central_difference')
1695  case ('fwbw_difference')
1697  case default
1698  call io_error(892,ext_msg=trim(num%spectral_derivative))
1699  end select
1700 
1701 !--------------------------------------------------------------------------------------------------
1702 ! scale dimension to calculate either uncorrected, dimension-independent, or dimension- and
1703 ! resolution-independent divergence
1704  if (num%divergence_correction == 1) then
1705  do j = 1, 3
1706  if (j /= minloc(geomsize,1) .and. j /= maxloc(geomsize,1)) &
1708  enddo
1709  elseif (num%divergence_correction == 2) then
1710  do j = 1, 3
1711  if ( j /= int(minloc(geomsize/real(grid,preal),1)) &
1712  .and. j /= int(maxloc(geomsize/real(grid,preal),1))) &
1713  scaledgeomsize = geomsize/geomsize(j)*real(grid(j),preal)
1714  enddo
1715  else
1717  endif
1718 
1719 
1720  select case(io_lc(num%FFTW_plan_mode)) ! setting parameters for the plan creation of FFTW. Basically a translation from fftw3.f
1721  case('fftw_estimate') ! ordered from slow execution (but fast plan creation) to fast execution
1722  fftw_planner_flag = fftw_estimate
1723  case('fftw_measure')
1724  fftw_planner_flag = fftw_measure
1725  case('fftw_patient')
1726  fftw_planner_flag = fftw_patient
1727  case('fftw_exhaustive')
1728  fftw_planner_flag = fftw_exhaustive
1729  case default
1730  call io_warning(warning_id=47,ext_msg=trim(io_lc(num%FFTW_plan_mode)))
1731  fftw_planner_flag = fftw_measure
1732  end select
1733 
1734 !--------------------------------------------------------------------------------------------------
1735 ! general initialization of FFTW (see manual on fftw.org for more details)
1736  if (preal /= c_double .or. kind(1) /= c_int) call io_error(0,ext_msg='Fortran to C') ! check for correct precision in C
1737  call fftw_set_timelimit(num%FFTW_timelimit) ! set timelimit for plan creation
1738 
1739  if (debuggeneral) write(6,'(/,a)') ' FFTW initialized'; flush(6)
1740 
1741 !--------------------------------------------------------------------------------------------------
1742 ! MPI allocation
1743  gridfftw = int(grid,c_intptr_t)
1744  alloc_local = fftw_mpi_local_size_3d(gridfftw(3), gridfftw(2), gridfftw(1)/2 +1, &
1745  petsc_comm_world, local_k, local_k_offset)
1746  allocate (xi1st(3,grid1red,grid(2),grid3),source = cmplx(0.0_preal,0.0_preal,preal)) ! frequencies for first derivatives, only half the size for first dimension
1747  allocate (xi2nd(3,grid1red,grid(2),grid3),source = cmplx(0.0_preal,0.0_preal,preal)) ! frequencies for second derivatives, only half the size for first dimension
1748 
1749  tensorfield = fftw_alloc_complex(tensorsize*alloc_local)
1750  call c_f_pointer(tensorfield, tensorfield_real, [3_c_intptr_t,3_c_intptr_t, &
1751  2_c_intptr_t*(gridfftw(1)/2_c_intptr_t + 1_c_intptr_t),gridfftw(2),local_k]) ! place a pointer for a real tensor representation
1752  call c_f_pointer(tensorfield, tensorfield_fourier, [3_c_intptr_t,3_c_intptr_t, &
1753  gridfftw(1)/2_c_intptr_t + 1_c_intptr_t , gridfftw(2),local_k]) ! place a pointer for a fourier tensor representation
1754 
1755  vectorfield = fftw_alloc_complex(vecsize*alloc_local)
1756  call c_f_pointer(vectorfield, vectorfield_real, [3_c_intptr_t,&
1757  2_c_intptr_t*(gridfftw(1)/2_c_intptr_t + 1_c_intptr_t),gridfftw(2),local_k]) ! place a pointer for a real vector representation
1758  call c_f_pointer(vectorfield, vectorfield_fourier,[3_c_intptr_t,&
1759  gridfftw(1)/2_c_intptr_t + 1_c_intptr_t, gridfftw(2),local_k]) ! place a pointer for a fourier vector representation
1760 
1761  scalarfield = fftw_alloc_complex(scalarsize*alloc_local) ! allocate data for real representation (no in place transform)
1762  call c_f_pointer(scalarfield, scalarfield_real, &
1763  [2_c_intptr_t*(gridfftw(1)/2_c_intptr_t + 1),gridfftw(2),local_k]) ! place a pointer for a real scalar representation
1764  call c_f_pointer(scalarfield, scalarfield_fourier, &
1765  [ gridfftw(1)/2_c_intptr_t + 1 ,gridfftw(2),local_k]) ! place a pointer for a fourier scarlar representation
1766 
1767 !--------------------------------------------------------------------------------------------------
1768 ! tensor MPI fftw plans
1769  plantensorforth = fftw_mpi_plan_many_dft_r2c(3, [gridfftw(3),gridfftw(2),gridfftw(1)], & ! dimension, logical length in each dimension in reversed order
1770  tensorsize, fftw_mpi_default_block, fftw_mpi_default_block, &! no. of transforms, default iblock and oblock
1771  tensorfield_real, tensorfield_fourier, & ! input data, output data
1772  petsc_comm_world, fftw_planner_flag) ! use all processors, planer precision
1773  if (.not. c_associated(plantensorforth)) call io_error(810, ext_msg='planTensorForth')
1774  plantensorback = fftw_mpi_plan_many_dft_c2r(3, [gridfftw(3),gridfftw(2),gridfftw(1)], & ! dimension, logical length in each dimension in reversed order
1775  tensorsize, fftw_mpi_default_block, fftw_mpi_default_block, &! no. of transforms, default iblock and oblock
1776  tensorfield_fourier,tensorfield_real, & ! input data, output data
1777  petsc_comm_world, fftw_planner_flag) ! all processors, planer precision
1778  if (.not. c_associated(plantensorback)) call io_error(810, ext_msg='planTensorBack')
1779 
1780 !--------------------------------------------------------------------------------------------------
1781 ! vector MPI fftw plans
1782  planvectorforth = fftw_mpi_plan_many_dft_r2c(3, [gridfftw(3),gridfftw(2),gridfftw(1)], & ! dimension, logical length in each dimension in reversed order
1783  vecsize, fftw_mpi_default_block, fftw_mpi_default_block,&! no. of transforms, default iblock and oblock
1784  vectorfield_real, vectorfield_fourier, & ! input data, output data
1785  petsc_comm_world, fftw_planner_flag) ! use all processors, planer precision
1786  if (.not. c_associated(planvectorforth)) call io_error(810, ext_msg='planVectorForth')
1787  planvectorback = fftw_mpi_plan_many_dft_c2r(3, [gridfftw(3),gridfftw(2),gridfftw(1)], & ! dimension, logical length in each dimension in reversed order
1788  vecsize, fftw_mpi_default_block, fftw_mpi_default_block, & ! no. of transforms, default iblock and oblock
1789  vectorfield_fourier,vectorfield_real, & ! input data, output data
1790  petsc_comm_world, fftw_planner_flag) ! all processors, planer precision
1791  if (.not. c_associated(planvectorback)) call io_error(810, ext_msg='planVectorBack')
1792 
1793 !--------------------------------------------------------------------------------------------------
1794 ! scalar MPI fftw plans
1795  planscalarforth = fftw_mpi_plan_many_dft_r2c(3, [gridfftw(3),gridfftw(2),gridfftw(1)], & ! dimension, logical length in each dimension in reversed order
1796  scalarsize, fftw_mpi_default_block, fftw_mpi_default_block, &! no. of transforms, default iblock and oblock
1797  scalarfield_real, scalarfield_fourier, & ! input data, output data
1798  petsc_comm_world, fftw_planner_flag) ! use all processors, planer precision
1799  if (.not. c_associated(planscalarforth)) call io_error(810, ext_msg='planScalarForth')
1800  planscalarback = fftw_mpi_plan_many_dft_c2r(3, [gridfftw(3),gridfftw(2),gridfftw(1)], & ! dimension, logical length in each dimension in reversed order, no. of transforms
1801  scalarsize, fftw_mpi_default_block, fftw_mpi_default_block, &! no. of transforms, default iblock and oblock
1802  scalarfield_fourier,scalarfield_real, & ! input data, output data
1803  petsc_comm_world, fftw_planner_flag) ! use all processors, planer precision
1804  if (.not. c_associated(planscalarback)) call io_error(810, ext_msg='planScalarBack')
1805 
1806 !--------------------------------------------------------------------------------------------------
1807 ! calculation of discrete angular frequencies, ordered as in FFTW (wrap around)
1808  do k = grid3offset+1, grid3offset+grid3
1809  k_s(3) = k - 1
1810  if(k > grid(3)/2 + 1) k_s(3) = k_s(3) - grid(3) ! running from 0,1,...,N/2,N/2+1,-N/2,-N/2+1,...,-1
1811  do j = 1, grid(2)
1812  k_s(2) = j - 1
1813  if(j > grid(2)/2 + 1) k_s(2) = k_s(2) - grid(2) ! running from 0,1,...,N/2,N/2+1,-N/2,-N/2+1,...,-1
1814  do i = 1, grid1red
1815  k_s(1) = i - 1 ! symmetry, junst running from 0,1,...,N/2,N/2+1
1817  where(mod(grid,2)==0 .and. [i,j,k] == grid/2+1 .and. &
1818  spectral_derivative_id == derivative_continuous_id) ! for even grids, set the Nyquist Freq component to 0.0
1819  xi1st(1:3,i,j,k-grid3offset) = cmplx(0.0_preal,0.0_preal,preal)
1820  elsewhere
1821  xi1st(1:3,i,j,k-grid3offset) = xi2nd(1:3,i,j,k-grid3offset)
1822  endwhere
1823  enddo; enddo; enddo
1824 
1825  if(num%memory_efficient) then ! allocate just single fourth order tensor
1826  allocate (gamma_hat(3,3,3,3,1,1,1), source = cmplx(0.0_preal,0.0_preal,preal))
1827  else ! precalculation of gamma_hat field
1828  allocate (gamma_hat(3,3,3,3,grid1red,grid(2),grid3), source = cmplx(0.0_preal,0.0_preal,preal))
1829  endif
1830 
1831 end subroutine utilities_init
1832 
1833 
1834 !---------------------------------------------------------------------------------------------------
1839 !---------------------------------------------------------------------------------------------------
1840 subroutine utilities_updategamma(C)
1842  real(preal), intent(in), dimension(3,3,3,3) :: c
1843  complex(pReal), dimension(3,3) :: temp33_complex, xidyad_cmplx
1844  real(preal), dimension(6,6) :: a, a_inv
1845  integer :: &
1846  i, j, k, &
1847  l, m, n, o
1848  logical :: err
1849 
1850  c_ref = c
1851 
1852  if(.not. num%memory_efficient) then
1853  gamma_hat = cmplx(0.0_preal,0.0_preal,preal) ! for the singular point and any non invertible A
1854  do k = grid3offset+1, grid3offset+grid3; do j = 1, grid(2); do i = 1, grid1red
1855  if (any([i,j,k] /= 1)) then ! singular point at xi=(0.0,0.0,0.0) i.e. i=j=k=1
1856  forall(l = 1:3, m = 1:3) &
1857  xidyad_cmplx(l,m) = conjg(-xi1st(l,i,j,k-grid3offset))*xi1st(m,i,j,k-grid3offset)
1858  forall(l = 1:3, m = 1:3) &
1859  temp33_complex(l,m) = sum(cmplx(c_ref(l,1:3,m,1:3),0.0_preal)*xidyad_cmplx)
1860  a(1:3,1:3) = real(temp33_complex); a(4:6,4:6) = real(temp33_complex)
1861  a(1:3,4:6) = aimag(temp33_complex); a(4:6,1:3) = -aimag(temp33_complex)
1862  if (abs(math_det33(a(1:3,1:3))) > 1e-16) then
1863  call math_invert(a_inv, err, a)
1864  temp33_complex = cmplx(a_inv(1:3,1:3),a_inv(1:3,4:6),preal)
1865  forall(l=1:3, m=1:3, n=1:3, o=1:3) &
1866  gamma_hat(l,m,n,o,i,j,k-grid3offset) = temp33_complex(l,n)* &
1867  conjg(-xi1st(o,i,j,k-grid3offset))*xi1st(m,i,j,k-grid3offset)
1868  endif
1869  endif
1870  enddo; enddo; enddo
1871  endif
1872 
1873 end subroutine utilities_updategamma
1874 
1875 
1876 !--------------------------------------------------------------------------------------------------
1879 ! to 0.0
1880 !--------------------------------------------------------------------------------------------------
1881 subroutine utilities_ffttensorforward
1883  tensorfield_real(1:3,1:3,grid(1)+1:grid1red*2,:,:) = 0.0_preal
1884  call fftw_mpi_execute_dft_r2c(plantensorforth,tensorfield_real,tensorfield_fourier)
1885 
1886 end subroutine utilities_ffttensorforward
1887 
1888 
1889 !--------------------------------------------------------------------------------------------------
1892 !--------------------------------------------------------------------------------------------------
1893 subroutine utilities_ffttensorbackward
1895  call fftw_mpi_execute_dft_c2r(plantensorback,tensorfield_fourier,tensorfield_real)
1896  tensorfield_real = tensorfield_real * wgt ! normalize the result by number of elements
1897 
1898 end subroutine utilities_ffttensorbackward
1899 
1900 !--------------------------------------------------------------------------------------------------
1903 ! to 0.0
1904 !--------------------------------------------------------------------------------------------------
1905 subroutine utilities_fftscalarforward
1907  scalarfield_real(grid(1)+1:grid1red*2,:,:) = 0.0_preal
1908  call fftw_mpi_execute_dft_r2c(planscalarforth,scalarfield_real,scalarfield_fourier)
1909 
1910 end subroutine utilities_fftscalarforward
1911 
1912 
1913 !--------------------------------------------------------------------------------------------------
1916 !--------------------------------------------------------------------------------------------------
1917 subroutine utilities_fftscalarbackward
1919  call fftw_mpi_execute_dft_c2r(planscalarback,scalarfield_fourier,scalarfield_real)
1920  scalarfield_real = scalarfield_real * wgt ! normalize the result by number of elements
1921 
1922 end subroutine utilities_fftscalarbackward
1923 
1924 
1925 !--------------------------------------------------------------------------------------------------
1928 ! to 0.0
1929 !--------------------------------------------------------------------------------------------------
1930 subroutine utilities_fftvectorforward
1932  vectorfield_real(1:3,grid(1)+1:grid1red*2,:,:) = 0.0_preal
1933  call fftw_mpi_execute_dft_r2c(planvectorforth,vectorfield_real,vectorfield_fourier)
1934 
1935 end subroutine utilities_fftvectorforward
1936 
1937 
1938 !--------------------------------------------------------------------------------------------------
1941 !--------------------------------------------------------------------------------------------------
1942 subroutine utilities_fftvectorbackward
1944  call fftw_mpi_execute_dft_c2r(planvectorback,vectorfield_fourier,vectorfield_real)
1945  vectorfield_real = vectorfield_real * wgt ! normalize the result by number of elements
1946 
1947 end subroutine utilities_fftvectorbackward
1948 
1949 
1950 !--------------------------------------------------------------------------------------------------
1952 !--------------------------------------------------------------------------------------------------
1953 subroutine utilities_fouriergammaconvolution(fieldAim)
1955  real(preal), intent(in), dimension(3,3) :: fieldaim
1956  complex(pReal), dimension(3,3) :: temp33_complex, xidyad_cmplx
1957  real(preal), dimension(6,6) :: a, a_inv
1958 
1959  integer :: &
1960  i, j, k, &
1961  l, m, n, o
1962  logical :: err
1963 
1964 
1965  write(6,'(/,a)') ' ... doing gamma convolution ...............................................'
1966  flush(6)
1967 
1968 !--------------------------------------------------------------------------------------------------
1969 ! do the actual spectral method calculation (mechanical equilibrium)
1970  memoryefficient: if(num%memory_efficient) then
1971  do k = 1, grid3; do j = 1, grid(2); do i = 1, grid1red
1972  if (any([i,j,k+grid3offset] /= 1)) then ! singular point at xi=(0.0,0.0,0.0) i.e. i=j=k=1
1973  forall(l = 1:3, m = 1:3) &
1974  xidyad_cmplx(l,m) = conjg(-xi1st(l,i,j,k))*xi1st(m,i,j,k)
1975  forall(l = 1:3, m = 1:3) &
1976  temp33_complex(l,m) = sum(cmplx(c_ref(l,1:3,m,1:3),0.0_preal)*xidyad_cmplx)
1977  a(1:3,1:3) = real(temp33_complex); a(4:6,4:6) = real(temp33_complex)
1978  a(1:3,4:6) = aimag(temp33_complex); a(4:6,1:3) = -aimag(temp33_complex)
1979  if (abs(math_det33(a(1:3,1:3))) > 1e-16) then
1980  call math_invert(a_inv, err, a)
1981  temp33_complex = cmplx(a_inv(1:3,1:3),a_inv(1:3,4:6),preal)
1982  forall(l=1:3, m=1:3, n=1:3, o=1:3) &
1983  gamma_hat(l,m,n,o,1,1,1) = temp33_complex(l,n)*conjg(-xi1st(o,i,j,k))*xi1st(m,i,j,k)
1984  else
1985  gamma_hat(1:3,1:3,1:3,1:3,1,1,1) = cmplx(0.0_preal,0.0_preal,preal)
1986  endif
1987  forall(l = 1:3, m = 1:3) &
1988  temp33_complex(l,m) = sum(gamma_hat(l,m,1:3,1:3,1,1,1)*tensorfield_fourier(1:3,1:3,i,j,k))
1989  tensorfield_fourier(1:3,1:3,i,j,k) = temp33_complex
1990  endif
1991  enddo; enddo; enddo
1992  else memoryefficient
1993  do k = 1, grid3; do j = 1, grid(2); do i = 1,grid1red
1994  forall(l = 1:3, m = 1:3) &
1995  temp33_complex(l,m) = sum(gamma_hat(l,m,1:3,1:3,i,j,k) * tensorfield_fourier(1:3,1:3,i,j,k))
1996  tensorfield_fourier(1:3,1:3,i,j,k) = temp33_complex
1997  enddo; enddo; enddo
1998  endif memoryefficient
1999 
2000  if (grid3offset == 0) tensorfield_fourier(1:3,1:3,1,1,1) = cmplx(fieldaim/wgt,0.0_preal,preal)
2001 
2002 end subroutine utilities_fouriergammaconvolution
2003 
2004 
2005 !--------------------------------------------------------------------------------------------------
2007 !--------------------------------------------------------------------------------------------------
2008 subroutine utilities_fouriergreenconvolution(D_ref, mobility_ref, deltaT)
2010  real(preal), dimension(3,3), intent(in) :: d_ref
2011  real(preal), intent(in) :: mobility_ref, deltat
2012  complex(pReal) :: greenop_hat
2013  integer :: i, j, k
2014 
2015 !--------------------------------------------------------------------------------------------------
2016 ! do the actual spectral method calculation
2017  do k = 1, grid3; do j = 1, grid(2) ;do i = 1, grid1red
2018  greenop_hat = cmplx(1.0_preal,0.0_preal,preal)/ &
2019  (cmplx(mobility_ref,0.0_preal,preal) + cmplx(deltat,0.0_preal)*&
2020  sum(conjg(xi1st(1:3,i,j,k))* matmul(cmplx(d_ref,0.0_preal),xi1st(1:3,i,j,k))))
2021  scalarfield_fourier(i,j,k) = scalarfield_fourier(i,j,k)*greenop_hat
2022  enddo; enddo; enddo
2023 
2024 end subroutine utilities_fouriergreenconvolution
2025 
2026 
2027 !--------------------------------------------------------------------------------------------------
2029 !--------------------------------------------------------------------------------------------------
2030 real(pReal) function utilities_divergencerms()
2032  integer :: i, j, k, ierr
2033  complex(pReal), dimension(3) :: rescaledgeom
2034 
2035  write(6,'(/,a)') ' ... calculating divergence ................................................'
2036  flush(6)
2037 
2038  rescaledgeom = cmplx(geomsize/scaledgeomsize,0.0_preal)
2039 
2040 !--------------------------------------------------------------------------------------------------
2041 ! calculating RMS divergence criterion in Fourier space
2042  utilities_divergencerms = 0.0_preal
2043  do k = 1, grid3; do j = 1, grid(2)
2044  do i = 2, grid1red -1 ! Has somewhere a conj. complex counterpart. Therefore count it twice.
2046  + 2.0_preal*(sum(real(matmul(tensorfield_fourier(1:3,1:3,i,j,k),& ! (sqrt(real(a)**2 + aimag(a)**2))**2 = real(a)**2 + aimag(a)**2. do not take square root and square again
2047  conjg(-xi1st(1:3,i,j,k))*rescaledgeom))**2.0_preal)& ! --> sum squared L_2 norm of vector
2048  +sum(aimag(matmul(tensorfield_fourier(1:3,1:3,i,j,k),&
2049  conjg(-xi1st(1:3,i,j,k))*rescaledgeom))**2.0_preal))
2050  enddo
2051  utilities_divergencerms = utilities_divergencerms & ! these two layers (DC and Nyquist) do not have a conjugate complex counterpart (if grid(1) /= 1)
2052  + sum( real(matmul(tensorfield_fourier(1:3,1:3,1 ,j,k), &
2053  conjg(-xi1st(1:3,1,j,k))*rescaledgeom))**2.0_preal) &
2054  + sum(aimag(matmul(tensorfield_fourier(1:3,1:3,1 ,j,k), &
2055  conjg(-xi1st(1:3,1,j,k))*rescaledgeom))**2.0_preal) &
2056  + sum( real(matmul(tensorfield_fourier(1:3,1:3,grid1red,j,k), &
2057  conjg(-xi1st(1:3,grid1red,j,k))*rescaledgeom))**2.0_preal) &
2058  + sum(aimag(matmul(tensorfield_fourier(1:3,1:3,grid1red,j,k), &
2059  conjg(-xi1st(1:3,grid1red,j,k))*rescaledgeom))**2.0_preal)
2060  enddo; enddo
2061  if(grid(1) == 1) utilities_divergencerms = utilities_divergencerms * 0.5_preal ! counted twice in case of grid(1) == 1
2062  call mpi_allreduce(mpi_in_place,utilities_divergencerms,1,mpi_double,mpi_sum,petsc_comm_world,ierr)
2063  if(ierr /=0) call io_error(894, ext_msg='utilities_divergenceRMS')
2064  utilities_divergencerms = sqrt(utilities_divergencerms) * wgt ! RMS in real space calculated with Parsevals theorem from Fourier space
2065 
2066 
2067 end function utilities_divergencerms
2068 
2069 
2070 !--------------------------------------------------------------------------------------------------
2072 !--------------------------------------------------------------------------------------------------
2073 real(pReal) function utilities_curlrms()
2075  integer :: i, j, k, l, ierr
2076  complex(pReal), dimension(3,3) :: curl_fourier
2077  complex(pReal), dimension(3) :: rescaledgeom
2078 
2079  write(6,'(/,a)') ' ... calculating curl ......................................................'
2080  flush(6)
2081 
2082  rescaledgeom = cmplx(geomsize/scaledgeomsize,0.0_preal)
2083 
2084 !--------------------------------------------------------------------------------------------------
2085 ! calculating max curl criterion in Fourier space
2086  utilities_curlrms = 0.0_preal
2087 
2088  do k = 1, grid3; do j = 1, grid(2);
2089  do i = 2, grid1red - 1
2090  do l = 1, 3
2091  curl_fourier(l,1) = (+tensorfield_fourier(l,3,i,j,k)*xi1st(2,i,j,k)*rescaledgeom(2) &
2092  -tensorfield_fourier(l,2,i,j,k)*xi1st(3,i,j,k)*rescaledgeom(3))
2093  curl_fourier(l,2) = (+tensorfield_fourier(l,1,i,j,k)*xi1st(3,i,j,k)*rescaledgeom(3) &
2094  -tensorfield_fourier(l,3,i,j,k)*xi1st(1,i,j,k)*rescaledgeom(1))
2095  curl_fourier(l,3) = (+tensorfield_fourier(l,2,i,j,k)*xi1st(1,i,j,k)*rescaledgeom(1) &
2096  -tensorfield_fourier(l,1,i,j,k)*xi1st(2,i,j,k)*rescaledgeom(2))
2097  enddo
2099  +2.0_preal*sum(real(curl_fourier)**2.0_preal+aimag(curl_fourier)**2.0_preal)! Has somewhere a conj. complex counterpart. Therefore count it twice.
2100  enddo
2101  do l = 1, 3
2102  curl_fourier = (+tensorfield_fourier(l,3,1,j,k)*xi1st(2,1,j,k)*rescaledgeom(2) &
2103  -tensorfield_fourier(l,2,1,j,k)*xi1st(3,1,j,k)*rescaledgeom(3))
2104  curl_fourier = (+tensorfield_fourier(l,1,1,j,k)*xi1st(3,1,j,k)*rescaledgeom(3) &
2105  -tensorfield_fourier(l,3,1,j,k)*xi1st(1,1,j,k)*rescaledgeom(1))
2106  curl_fourier = (+tensorfield_fourier(l,2,1,j,k)*xi1st(1,1,j,k)*rescaledgeom(1) &
2107  -tensorfield_fourier(l,1,1,j,k)*xi1st(2,1,j,k)*rescaledgeom(2))
2108  enddo
2110  + sum(real(curl_fourier)**2.0_preal + aimag(curl_fourier)**2.0_preal) ! this layer (DC) does not have a conjugate complex counterpart (if grid(1) /= 1)
2111  do l = 1, 3
2112  curl_fourier = (+tensorfield_fourier(l,3,grid1red,j,k)*xi1st(2,grid1red,j,k)*rescaledgeom(2) &
2113  -tensorfield_fourier(l,2,grid1red,j,k)*xi1st(3,grid1red,j,k)*rescaledgeom(3))
2114  curl_fourier = (+tensorfield_fourier(l,1,grid1red,j,k)*xi1st(3,grid1red,j,k)*rescaledgeom(3) &
2115  -tensorfield_fourier(l,3,grid1red,j,k)*xi1st(1,grid1red,j,k)*rescaledgeom(1))
2116  curl_fourier = (+tensorfield_fourier(l,2,grid1red,j,k)*xi1st(1,grid1red,j,k)*rescaledgeom(1) &
2117  -tensorfield_fourier(l,1,grid1red,j,k)*xi1st(2,grid1red,j,k)*rescaledgeom(2))
2118  enddo
2120  + sum(real(curl_fourier)**2.0_preal + aimag(curl_fourier)**2.0_preal) ! this layer (Nyquist) does not have a conjugate complex counterpart (if grid(1) /= 1)
2121  enddo; enddo
2122 
2123  call mpi_allreduce(mpi_in_place,utilities_curlrms,1,mpi_double,mpi_sum,petsc_comm_world,ierr)
2124  if(ierr /=0) call io_error(894, ext_msg='utilities_curlRMS')
2126  if(grid(1) == 1) utilities_curlrms = utilities_curlrms * 0.5_preal ! counted twice in case of grid(1) == 1
2127 
2128 end function utilities_curlrms
2129 
2130 
2131 !--------------------------------------------------------------------------------------------------
2133 !--------------------------------------------------------------------------------------------------
2134 function utilities_maskedcompliance(rot_BC,mask_stress,C)
2136  real(preal), dimension(3,3,3,3) :: utilities_maskedcompliance
2137  real(preal), intent(in), dimension(3,3,3,3) :: c
2138  type(rotation), intent(in) :: rot_bc
2139  logical, intent(in), dimension(3,3) :: mask_stress
2140 
2141  integer :: i, j
2142  logical, dimension(9) :: mask_stressvector
2143  logical, dimension(9,9) :: mask
2144  real(preal), dimension(9,9) :: temp99_real
2145  integer :: size_reduced = 0
2146  real(preal), dimension(:,:), allocatable :: &
2147  s_reduced, & !< reduced compliance matrix (depending on number of stress BC)
2148  c_reduced, & !< reduced stiffness (depending on number of stress BC)
2149  stimesc
2150  logical :: errmatinv
2151  character(len=pStringLen):: formatstring
2152 
2153  mask_stressvector = reshape(transpose(mask_stress), [9])
2154  size_reduced = count(mask_stressvector)
2155  if(size_reduced > 0) then
2156  temp99_real = math_3333to99(rot_bc%rotate(c))
2157 
2158  if(debuggeneral) then
2159  write(6,'(/,a)') ' ... updating masked compliance ............................................'
2160  write(6,'(/,a,/,9(9(2x,f12.7,1x)/))',advance='no') ' Stiffness C (load) / GPa =',&
2161  transpose(temp99_real)*1.0e-9_preal
2162  flush(6)
2163  endif
2164 
2165  do i = 1,9; do j = 1,9
2166  mask(i,j) = mask_stressvector(i) .and. mask_stressvector(j)
2167  enddo; enddo
2168  c_reduced = reshape(pack(temp99_real,mask),[size_reduced,size_reduced])
2169 
2170  allocate(s_reduced,mold = c_reduced)
2171  call math_invert(s_reduced, errmatinv, c_reduced) ! invert reduced stiffness
2172  if (any(ieee_is_nan(s_reduced))) errmatinv = .true.
2173  if (errmatinv) call io_error(error_id=400,ext_msg='utilities_maskedCompliance')
2174 
2175 !--------------------------------------------------------------------------------------------------
2176 ! check if inversion was successful
2177  stimesc = matmul(c_reduced,s_reduced)
2178  errmatinv = errmatinv .or. any(dneq(stimesc,math_identity2nd(size_reduced),1.0e-12_preal))
2179  if (debuggeneral .or. errmatinv) then
2180  write(formatstring, '(i2)') size_reduced
2181  formatstring = '(/,a,/,'//trim(formatstring)//'('//trim(formatstring)//'(2x,es9.2,1x)/))'
2182  write(6,trim(formatstring),advance='no') ' C * S (load) ', &
2183  transpose(matmul(c_reduced,s_reduced))
2184  write(6,trim(formatstring),advance='no') ' S (load) ', transpose(s_reduced)
2185  if(errmatinv) call io_error(error_id=400,ext_msg='utilities_maskedCompliance')
2186  endif
2187  temp99_real = reshape(unpack(reshape(s_reduced,[size_reduced**2]),reshape(mask,[81]),0.0_preal),[9,9])
2188  else
2189  temp99_real = 0.0_preal
2190  endif
2191 
2193 
2194  if(debuggeneral) then
2195  write(6,'(/,a,/,9(9(2x,f10.5,1x)/),/)',advance='no') &
2196  ' Masked Compliance (load) * GPa =', transpose(temp99_real)*1.0e9_preal
2197  flush(6)
2198  endif
2199 
2200 end function utilities_maskedcompliance
2201 
2202 
2203 !--------------------------------------------------------------------------------------------------
2205 !--------------------------------------------------------------------------------------------------
2208  integer :: i, j, k
2209 
2210  do k = 1, grid3; do j = 1, grid(2); do i = 1,grid1red
2211  vectorfield_fourier(1:3,i,j,k) = scalarfield_fourier(i,j,k)*xi1st(1:3,i,j,k) ! ToDo: no -conjg?
2212  enddo; enddo; enddo
2213 
2214 end subroutine utilities_fourierscalargradient
2215 
2216 
2217 !--------------------------------------------------------------------------------------------------
2219 !--------------------------------------------------------------------------------------------------
2222  integer :: i, j, k
2223 
2224  do k = 1, grid3; do j = 1, grid(2); do i = 1,grid1red
2225  scalarfield_fourier(i,j,k) = sum(vectorfield_fourier(1:3,i,j,k)*conjg(-xi1st(1:3,i,j,k)))
2226  enddo; enddo; enddo
2227 
2228 end subroutine utilities_fouriervectordivergence
2229 
2230 
2231 !--------------------------------------------------------------------------------------------------
2233 !--------------------------------------------------------------------------------------------------
2236  integer :: i, j, k, m, n
2237 
2238  do k = 1, grid3; do j = 1, grid(2); do i = 1,grid1red
2239  do m = 1, 3; do n = 1, 3
2240  tensorfield_fourier(m,n,i,j,k) = vectorfield_fourier(m,i,j,k)*xi1st(n,i,j,k)
2241  enddo; enddo
2242  enddo; enddo; enddo
2243 
2244 end subroutine utilities_fouriervectorgradient
2245 
2246 
2247 !--------------------------------------------------------------------------------------------------
2249 !--------------------------------------------------------------------------------------------------
2252  integer :: i, j, k
2253 
2254  do k = 1, grid3; do j = 1, grid(2); do i = 1,grid1red
2255  vectorfield_fourier(:,i,j,k) = matmul(tensorfield_fourier(:,:,i,j,k),conjg(-xi1st(:,i,j,k)))
2256  enddo; enddo; enddo
2257 
2258 end subroutine utilities_fouriertensordivergence
2259 
2260 
2261 !--------------------------------------------------------------------------------------------------
2263 !--------------------------------------------------------------------------------------------------
2264 subroutine utilities_constitutiveresponse(P,P_av,C_volAvg,C_minmaxAvg,&
2265  F,timeinc,rotation_BC)
2267  real(preal), intent(out), dimension(3,3,3,3) :: c_volavg, c_minmaxavg
2268  real(preal), intent(out), dimension(3,3) :: p_av
2269  real(preal), intent(out), dimension(3,3,grid(1),grid(2),grid3) :: p
2270  real(preal), intent(in), dimension(3,3,grid(1),grid(2),grid3) :: f
2271  real(preal), intent(in) :: timeinc
2272  type(rotation), intent(in), optional :: rotation_bc
2273 
2274 
2275  integer :: &
2276  i,ierr
2277  real(preal), dimension(3,3,3,3) :: dpdf_max, dpdf_min
2278  real(preal) :: dpdf_norm_max, dpdf_norm_min
2279  real(preal), dimension(2) :: valueandrank
2280 
2281  write(6,'(/,a)') ' ... evaluating constitutive response ......................................'
2282  flush(6)
2283 
2284  materialpoint_f = reshape(f,[3,3,1,product(grid(1:2))*grid3]) ! set materialpoint target F to estimated field
2285 
2286  call materialpoint_stressanditstangent(.true.,timeinc) ! calculate P field
2287 
2288  p = reshape(materialpoint_p, [3,3,grid(1),grid(2),grid3])
2289  p_av = sum(sum(sum(p,dim=5),dim=4),dim=3) * wgt ! average of P
2290  call mpi_allreduce(mpi_in_place,p_av,9,mpi_double,mpi_sum,petsc_comm_world,ierr)
2291  if (debugrotation) &
2292  write(6,'(/,a,/,3(3(2x,f12.4,1x)/))',advance='no') ' Piola--Kirchhoff stress (lab) / MPa =',&
2293  transpose(p_av)*1.e-6_preal
2294  if(present(rotation_bc)) &
2295  p_av = rotation_bc%rotate(p_av)
2296  write(6,'(/,a,/,3(3(2x,f12.4,1x)/))',advance='no') ' Piola--Kirchhoff stress / MPa =',&
2297  transpose(p_av)*1.e-6_preal
2298  flush(6)
2299 
2300  dpdf_max = 0.0_preal
2301  dpdf_norm_max = 0.0_preal
2302  dpdf_min = huge(1.0_preal)
2303  dpdf_norm_min = huge(1.0_preal)
2304  do i = 1, product(grid(1:2))*grid3
2305  if (dpdf_norm_max < sum(materialpoint_dpdf(1:3,1:3,1:3,1:3,1,i)**2.0_preal)) then
2306  dpdf_max = materialpoint_dpdf(1:3,1:3,1:3,1:3,1,i)
2307  dpdf_norm_max = sum(materialpoint_dpdf(1:3,1:3,1:3,1:3,1,i)**2.0_preal)
2308  endif
2309  if (dpdf_norm_min > sum(materialpoint_dpdf(1:3,1:3,1:3,1:3,1,i)**2.0_preal)) then
2310  dpdf_min = materialpoint_dpdf(1:3,1:3,1:3,1:3,1,i)
2311  dpdf_norm_min = sum(materialpoint_dpdf(1:3,1:3,1:3,1:3,1,i)**2.0_preal)
2312  endif
2313  end do
2314 
2315  valueandrank = [dpdf_norm_max,real(worldrank,preal)]
2316  call mpi_allreduce(mpi_in_place,valueandrank,1, mpi_2double_precision, mpi_maxloc, petsc_comm_world, ierr)
2317  if (ierr /= 0) call io_error(894, ext_msg='MPI_Allreduce max')
2318  call mpi_bcast(dpdf_max,81,mpi_double,int(valueandrank(2)),petsc_comm_world, ierr)
2319  if (ierr /= 0) call io_error(894, ext_msg='MPI_Bcast max')
2320 
2321  valueandrank = [dpdf_norm_min,real(worldrank,preal)]
2322  call mpi_allreduce(mpi_in_place,valueandrank,1, mpi_2double_precision, mpi_minloc, petsc_comm_world, ierr)
2323  if (ierr /= 0) call io_error(894, ext_msg='MPI_Allreduce min')
2324  call mpi_bcast(dpdf_min,81,mpi_double,int(valueandrank(2)),petsc_comm_world, ierr)
2325  if (ierr /= 0) call io_error(894, ext_msg='MPI_Bcast min')
2326 
2327  c_minmaxavg = 0.5_preal*(dpdf_max + dpdf_min)
2328 
2329  c_volavg = sum(sum(materialpoint_dpdf,dim=6),dim=5)
2330  call mpi_allreduce(mpi_in_place,c_volavg,81,mpi_double,mpi_sum,petsc_comm_world,ierr)
2331  c_volavg = c_volavg * wgt
2332 
2333 
2334 end subroutine utilities_constitutiveresponse
2335 
2336 
2337 !--------------------------------------------------------------------------------------------------
2339 !--------------------------------------------------------------------------------------------------
2340 pure function utilities_calculaterate(heterogeneous,field0,field,dt,avRate)
2342  real(preal), intent(in), dimension(3,3) :: &
2343  avrate
2344  real(preal), intent(in) :: &
2345  dt
2346  logical, intent(in) :: &
2347  heterogeneous
2348  real(preal), intent(in), dimension(3,3,grid(1),grid(2),grid3) :: &
2349  field0, & !< data of previous step
2350  field
2351  real(preal), dimension(3,3,grid(1),grid(2),grid3) :: &
2353 
2354  if (heterogeneous) then
2355  utilities_calculaterate = (field-field0) / dt
2356  else
2357  utilities_calculaterate = spread(spread(spread(avrate,3,grid(1)),4,grid(2)),5,grid3)
2358  endif
2359 
2360 end function utilities_calculaterate
2361 
2362 
2363 !--------------------------------------------------------------------------------------------------
2366 !--------------------------------------------------------------------------------------------------
2367 function utilities_forwardfield(timeinc,field_lastInc,rate,aim)
2369  real(preal), intent(in) :: &
2370  timeinc
2371  real(preal), intent(in), dimension(3,3,grid(1),grid(2),grid3) :: &
2372  field_lastinc, & !< initial field
2373  rate
2374  real(preal), intent(in), optional, dimension(3,3) :: &
2375  aim
2376  real(preal), dimension(3,3,grid(1),grid(2),grid3) :: &
2378  real(preal), dimension(3,3) :: fielddiff
2379  integer(kind=selected_int_kind(5)) :: ierr
2380 
2381  utilities_forwardfield = field_lastinc + rate*timeinc
2382  if (present(aim)) then
2383  fielddiff = sum(sum(sum(utilities_forwardfield,dim=5),dim=4),dim=3)*wgt
2384  call mpi_allreduce(mpi_in_place,fielddiff,9,mpi_double,mpi_sum,petsc_comm_world,ierr)
2385  fielddiff = fielddiff - aim
2387  spread(spread(spread(fielddiff,3,grid(1)),4,grid(2)),5,grid3)
2388  endif
2389 
2390 end function utilities_forwardfield
2391 
2392 
2393 !--------------------------------------------------------------------------------------------------
2396 ! standard approach
2397 !--------------------------------------------------------------------------------------------------
2398 pure function utilities_getfreqderivative(k_s)
2400  integer, intent(in), dimension(3) :: k_s
2401  complex(pReal), dimension(3) :: utilities_getfreqderivative
2402 
2403  select case (spectral_derivative_id)
2405  utilities_getfreqderivative = cmplx(0.0_preal, 2.0_preal*pi*real(k_s,preal)/geomsize,preal)
2406 
2408  utilities_getfreqderivative = cmplx(0.0_preal, sin(2.0_preal*pi*real(k_s,preal)/real(grid,preal)), preal)/ &
2409  cmplx(2.0_preal*geomsize/real(grid,preal), 0.0_preal, preal)
2410 
2413  cmplx(cos(2.0_preal*pi*real(k_s(1),preal)/real(grid(1),preal)) - 1.0_preal, &
2414  sin(2.0_preal*pi*real(k_s(1),preal)/real(grid(1),preal)), preal)* &
2415  cmplx(cos(2.0_preal*pi*real(k_s(2),preal)/real(grid(2),preal)) + 1.0_preal, &
2416  sin(2.0_preal*pi*real(k_s(2),preal)/real(grid(2),preal)), preal)* &
2417  cmplx(cos(2.0_preal*pi*real(k_s(3),preal)/real(grid(3),preal)) + 1.0_preal, &
2418  sin(2.0_preal*pi*real(k_s(3),preal)/real(grid(3),preal)), preal)/ &
2419  cmplx(4.0_preal*geomsize(1)/real(grid(1),preal), 0.0_preal, preal)
2421  cmplx(cos(2.0_preal*pi*real(k_s(1),preal)/real(grid(1),preal)) + 1.0_preal, &
2422  sin(2.0_preal*pi*real(k_s(1),preal)/real(grid(1),preal)), preal)* &
2423  cmplx(cos(2.0_preal*pi*real(k_s(2),preal)/real(grid(2),preal)) - 1.0_preal, &
2424  sin(2.0_preal*pi*real(k_s(2),preal)/real(grid(2),preal)), preal)* &
2425  cmplx(cos(2.0_preal*pi*real(k_s(3),preal)/real(grid(3),preal)) + 1.0_preal, &
2426  sin(2.0_preal*pi*real(k_s(3),preal)/real(grid(3),preal)), preal)/ &
2427  cmplx(4.0_preal*geomsize(2)/real(grid(2),preal), 0.0_preal, preal)
2429  cmplx(cos(2.0_preal*pi*real(k_s(1),preal)/real(grid(1),preal)) + 1.0_preal, &
2430  sin(2.0_preal*pi*real(k_s(1),preal)/real(grid(1),preal)), preal)* &
2431  cmplx(cos(2.0_preal*pi*real(k_s(2),preal)/real(grid(2),preal)) + 1.0_preal, &
2432  sin(2.0_preal*pi*real(k_s(2),preal)/real(grid(2),preal)), preal)* &
2433  cmplx(cos(2.0_preal*pi*real(k_s(3),preal)/real(grid(3),preal)) - 1.0_preal, &
2434  sin(2.0_preal*pi*real(k_s(3),preal)/real(grid(3),preal)), preal)/ &
2435  cmplx(4.0_preal*geomsize(3)/real(grid(3),preal), 0.0_preal, preal)
2436  end select
2437 
2438 end function utilities_getfreqderivative
2439 
2440 
2441 !--------------------------------------------------------------------------------------------------
2443 ! using integration in Fourier space. Similar as in mesh.f90, but using data already defined for
2444 ! convolution
2445 !--------------------------------------------------------------------------------------------------
2446 subroutine utilities_updatecoords(F)
2448  real(preal), dimension(3,3,grid(1),grid(2),grid3), intent(in) :: f
2449  real(preal), dimension(3, grid(1),grid(2),grid3) :: ipcoords
2450  real(preal), dimension(3, grid(1),grid(2),grid3+2) :: ipfluct_padded ! Fluctuations of cell center displacement (padded along z for MPI)
2451  real(preal), dimension(3, grid(1)+1,grid(2)+1,grid3+1) :: nodecoords
2452  integer :: &
2453  i,j,k,n, &
2454  rank_t, &
2455  rank_b, &
2456  c, r, &
2457  ierr
2458  integer, dimension(MPI_STATUS_SIZE) :: &
2459  s
2460  real(preal), dimension(3) :: step
2461  real(preal), dimension(3,3) :: favg
2462  integer, dimension(3) :: me
2463  integer, dimension(3,8) :: &
2464  neighbor = reshape([ &
2465  0, 0, 0, &
2466  1, 0, 0, &
2467  1, 1, 0, &
2468  0, 1, 0, &
2469  0, 0, 1, &
2470  1, 0, 1, &
2471  1, 1, 1, &
2472  0, 1, 1 ], [3,8])
2473 
2474  step = geomsize/real(grid, preal)
2475  !--------------------------------------------------------------------------------------------------
2476  ! integration in Fourier space to get fluctuations of cell center discplacements
2477  tensorfield_real(1:3,1:3,1:grid(1),1:grid(2),1:grid3) = f
2479 
2480  do k = 1, grid3; do j = 1, grid(2); do i = 1, grid1red
2481  if(any([i,j,k+grid3offset] /= 1)) then
2482  vectorfield_fourier(1:3,i,j,k) = matmul(tensorfield_fourier(1:3,1:3,i,j,k),xi2nd(1:3,i,j,k)) &
2483  / sum(conjg(-xi2nd(1:3,i,j,k))*xi2nd(1:3,i,j,k)) * cmplx(wgt,0.0,preal)
2484  else
2485  vectorfield_fourier(1:3,i,j,k) = cmplx(0.0,0.0,preal)
2486  endif
2487  enddo; enddo; enddo
2488 
2489  call fftw_mpi_execute_dft_c2r(planvectorback,vectorfield_fourier,vectorfield_real)
2490 
2491  !--------------------------------------------------------------------------------------------------
2492  ! average F
2493  if (grid3offset == 0) favg = real(tensorfield_fourier(1:3,1:3,1,1,1),preal)*wgt
2494  call mpi_bcast(favg,9,mpi_double,0,petsc_comm_world,ierr)
2495  if(ierr /=0) call io_error(894, ext_msg='update_IPcoords/MPI_Bcast')
2496 
2497  !--------------------------------------------------------------------------------------------------
2498  ! pad cell center fluctuations along z-direction (needed when running MPI simulation)
2499  ipfluct_padded(1:3,1:grid(1),1:grid(2),2:grid3+1) = vectorfield_real(1:3,1:grid(1),1:grid(2),1:grid3)
2500  c = product(shape(ipfluct_padded(:,:,:,1)))
2501  rank_t = modulo(worldrank+1,worldsize)
2502  rank_b = modulo(worldrank-1,worldsize)
2503 
2504  ! send bottom layer to process below
2505  call mpi_isend(ipfluct_padded(:,:,:,2), c,mpi_double,rank_b,0,petsc_comm_world,r,ierr)
2506  if(ierr /=0) call io_error(894, ext_msg='update_IPcoords/MPI_Isend')
2507  call mpi_irecv(ipfluct_padded(:,:,:,grid3+2),c,mpi_double,rank_t,0,petsc_comm_world,r,ierr)
2508  if(ierr /=0) call io_error(894, ext_msg='update_IPcoords/MPI_Irecv')
2509  call mpi_wait(r,s,ierr)
2510 
2511  ! send top layer to process above
2512  if(ierr /=0) call io_error(894, ext_msg='update_IPcoords/MPI_Wait')
2513  call mpi_isend(ipfluct_padded(:,:,:,grid3+1),c,mpi_double,rank_t,0,petsc_comm_world,r,ierr)
2514  if(ierr /=0) call io_error(894, ext_msg='update_IPcoords/MPI_Isend')
2515  call mpi_irecv(ipfluct_padded(:,:,:,1), c,mpi_double,rank_b,0,petsc_comm_world,r,ierr)
2516  if(ierr /=0) call io_error(894, ext_msg='update_IPcoords/MPI_Irecv')
2517  call mpi_wait(r,s,ierr)
2518 
2519  !--------------------------------------------------------------------------------------------------
2520  ! calculate nodal displacements
2521  nodecoords = 0.0_preal
2522  do k = 0,grid3; do j = 0,grid(2); do i = 0,grid(1)
2523  nodecoords(1:3,i+1,j+1,k+1) = matmul(favg,step*(real([i,j,k+grid3offset],preal)))
2524  averagefluct: do n = 1,8
2525  me = [i+neighbor(1,n),j+neighbor(2,n),k+neighbor(3,n)]
2526  nodecoords(1:3,i+1,j+1,k+1) = nodecoords(1:3,i+1,j+1,k+1) &
2527  + ipfluct_padded(1:3,modulo(me(1)-1,grid(1))+1,modulo(me(2)-1,grid(2))+1,me(3)+1)*0.125_preal
2528  enddo averagefluct
2529  enddo; enddo; enddo
2530 
2531  !--------------------------------------------------------------------------------------------------
2532  ! calculate cell center displacements
2533  do k = 1,grid3; do j = 1,grid(2); do i = 1,grid(1)
2534  ipcoords(1:3,i,j,k) = vectorfield_real(1:3,i,j,k) &
2535  + matmul(favg,step*(real([i,j,k+grid3offset],preal)-0.5_preal))
2536  enddo; enddo; enddo
2537 
2538  call discretization_setnodecoords(reshape(nodecoords,[3,(grid(1)+1)*(grid(2)+1)*(grid3+1)]))
2539  call discretization_setipcoords (reshape(ipcoords, [3,grid(1)*grid(2)*grid3]))
2540 
2541 end subroutine utilities_updatecoords
2542 
2543 
2544 !---------------------------------------------------------------------------------------------------
2546 !---------------------------------------------------------------------------------------------------
2549  integer :: &
2550  fileunit
2551 
2552  if (worldrank == 0) then
2553  write(6,'(a)') ' writing reference stiffness data required for restart to file'; flush(6)
2554  fileunit = io_open_binary(trim(getsolverjobname())//'.C_ref','w')
2555  write(fileunit) c_ref
2556  close(fileunit)
2557  endif
2558 
2559 end subroutine utilities_savereferencestiffness
2560 
2561 end module spectral_utilities
discretization::discretization_setipcoords
subroutine, public discretization_setipcoords(IPcoords)
stores current IP coordinates
Definition: discretization.f90:105
spectral_utilities::utilities_fftscalarbackward
subroutine, public utilities_fftscalarbackward
backward FFT of data in scalarField_fourier to scalarField_real
Definition: spectral_utilities.f90:1918
rotations
rotation storage and conversion
Definition: rotations.f90:53
spectral_utilities::scalarfield_real
real(c_double), dimension(:,:,:), pointer, public scalarfield_real
scalar field real representation for fftw
Definition: spectral_utilities.f90:1501
homogenization::materialpoint_dpdf
real(preal), dimension(:,:,:,:,:,:), allocatable, public materialpoint_dpdf
tangent of first P–K stress at IP
Definition: homogenization.f90:40
homogenization::materialpoint_p
real(preal), dimension(:,:,:,:), allocatable, public materialpoint_p
first P–K stress of IP
Definition: homogenization.f90:36
spectral_utilities::field_mech_id
@, public field_mech_id
Definition: spectral_utilities.f90:1485
spectral_utilities::planvectorback
type(c_ptr), private planvectorback
FFTW MPI plan v(k) to v(x)
Definition: spectral_utilities.f90:1511
io::io_error
subroutine, public io_error(error_ID, el, ip, g, instance, ext_msg)
write error statements to standard out and terminate the Marc/spectral run with exit #9xxx
Definition: IO.f90:305
rotations::rotation
Definition: rotations.f90:63
debug::debug_level
integer, dimension(debug_maxntype+2), public, protected debug_level
Definition: debug.f90:48
spectral_utilities::field_thermal_id
@, public field_thermal_id
Definition: spectral_utilities.f90:1485
math::math_99to3333
pure real(preal) function, dimension(3, 3, 3, 3) math_99to3333(m99)
convert 9x9 matrix into 3x3x3x3 matrix
Definition: math.f90:758
math::math_3333to99
pure real(preal) function, dimension(9, 9) math_3333to99(m3333)
convert 3x3x3x3 matrix into 9x9 matrix
Definition: math.f90:741
math::math_identity2nd
pure real(preal) function, dimension(d, d) math_identity2nd(d)
second rank identity tensor of specified dimension
Definition: math.f90:240
spectral_utilities::utilities_fouriervectorgradient
subroutine, public utilities_fouriervectorgradient()
calculate vector gradient in fourier field
Definition: spectral_utilities.f90:2235
spectral_utilities::derivative_central_diff_id
@ derivative_central_diff_id
Definition: spectral_utilities.f90:1582
spectral_utilities::derivative_continuous_id
@ derivative_continuous_id
Definition: spectral_utilities.f90:1582
homogenization::materialpoint_f
real(preal), dimension(:,:,:,:), allocatable, public materialpoint_f
def grad of IP to be reached at end of FE increment
Definition: homogenization.f90:36
spectral_utilities::tsolutionparams
Definition: spectral_utilities.f90:1557
spectral_utilities::planscalarback
type(c_ptr), private planscalarback
FFTW MPI plan s(k) to s(x)
Definition: spectral_utilities.f90:1511
spectral_utilities
Utilities used by the different spectral solver variants.
Definition: spectral_utilities.f90:10
discretization::discretization_setnodecoords
subroutine, public discretization_setnodecoords(NodeCoords)
stores current IP coordinates
Definition: discretization.f90:117
numerics::worldsize
integer, public, protected worldsize
MPI worldsize (/=1 for MPI simulations only)
Definition: numerics.f90:1470
spectral_utilities::field_undefined_id
@, public field_undefined_id
Definition: spectral_utilities.f90:1485
spectral_utilities::utilities_divergencerms
real(preal) function, public utilities_divergencerms()
calculate root mean square of divergence of field_fourier
Definition: spectral_utilities.f90:2031
config
Reads in the material configuration from file.
Definition: config.f90:13
discretization_grid::grid3
integer, public, protected grid3
(local) grid in 3rd direction
Definition: discretization_grid.f90:1478
spectral_utilities::c_ref
real(preal), dimension(3, 3, 3, 3), private c_ref
mechanic reference stiffness
Definition: spectral_utilities.f90:1506
spectral_utilities::field_damage_id
@, public field_damage_id
Definition: spectral_utilities.f90:1485
spectral_utilities::utilities_curlrms
real(preal) function, public utilities_curlrms()
calculate max of curl of field_fourier
Definition: spectral_utilities.f90:2074
discretization_grid
Parse geometry file to set up discretization and geometry for nonlocal model.
Definition: discretization_grid.f90:11
prec
setting precision for real and int type
Definition: prec.f90:13
discretization_grid::geomsize
real(preal), dimension(3), public, protected geomsize
(global) physical size
Definition: discretization_grid.f90:1481
spectral_utilities::spectral_derivative_id
integer(kind(derivative_continuous_id)) spectral_derivative_id
Definition: spectral_utilities.f90:1585
math::math_det33
real(preal) pure function math_det33(m)
determinant of a 3x3 matrix
Definition: math.f90:623
spectral_utilities::utilities_fftvectorbackward
subroutine, public utilities_fftvectorbackward
backward FFT of data in field_fourier to field_real
Definition: spectral_utilities.f90:1943
spectral_utilities::vectorfield_real
real(c_double), dimension(:,:,:,:), pointer, public vectorfield_real
vector field real representation for fftw
Definition: spectral_utilities.f90:1499
discretization
spatial discretization
Definition: discretization.f90:9
spectral_utilities::planvectorforth
type(c_ptr), private planvectorforth
FFTW MPI plan v(x) to v(k)
Definition: spectral_utilities.f90:1511
spectral_utilities::xi1st
complex(preal), dimension(:,:,:,:), allocatable, private xi1st
wave vector field for first derivatives
Definition: spectral_utilities.f90:1504
spectral_utilities::utilities_init
subroutine, public utilities_init
allocates all neccessary fields, sets debug flags, create plans for FFTW
Definition: spectral_utilities.f90:1627
spectral_utilities::utilities_savereferencestiffness
subroutine, public utilities_savereferencestiffness
Write out the current reference stiffness for restart.
Definition: spectral_utilities.f90:2548
debug::petscdebug
character(len=1024), parameter, public petscdebug
Definition: debug.f90:70
spectral_utilities::utilities_ffttensorforward
subroutine, public utilities_ffttensorforward
forward FFT of data in field_real to field_fourier
Definition: spectral_utilities.f90:1882
spectral_utilities::vectorfield_fourier
complex(c_double_complex), dimension(:,:,:,:), pointer, public vectorfield_fourier
vector field fourier representation for fftw
Definition: spectral_utilities.f90:1500
io::io_warning
subroutine, public io_warning(warning_ID, el, ip, g, ext_msg)
writes warning statement to standard out
Definition: IO.f90:535
spectral_utilities::utilities_fouriervectordivergence
subroutine, public utilities_fouriervectordivergence()
calculate vector divergence in fourier field
Definition: spectral_utilities.f90:2221
io
input/output functions, partly depending on chosen solver
Definition: IO.f90:12
homogenization
homogenization manager, organizing deformation partitioning and stress homogenization
Definition: homogenization.f90:11
debug::debug_levelbasic
integer, parameter, public debug_levelbasic
Definition: debug.f90:19
prec::preal
integer, parameter preal
number with 15 significant digits, up to 1e+-307 (typically 64 bit)
Definition: prec.f90:20
spectral_utilities::utilities_getfreqderivative
pure complex(preal) function, dimension(3) utilities_getfreqderivative(k_s)
calculates filter for fourier convolution depending on type given in numerics.config
Definition: spectral_utilities.f90:2399
spectral_utilities::utilities_fftscalarforward
subroutine, public utilities_fftscalarforward
forward FFT of data in scalarField_real to scalarField_fourier
Definition: spectral_utilities.f90:1906
debug
Reading in and interpretating the debugging settings for the various modules.
Definition: debug.f90:12
spectral_utilities::scaledgeomsize
real(preal), dimension(3), public, protected scaledgeomsize
scaled geometry size for calculation of divergence
Definition: spectral_utilities.f90:1492
spectral_utilities::debuggeneral
logical, private debuggeneral
general debugging of spectral solver
Definition: spectral_utilities.f90:1521
spectral_utilities::utilities_fftvectorforward
subroutine, public utilities_fftvectorforward
forward FFT of data in field_real to field_fourier with highest freqs. removed
Definition: spectral_utilities.f90:1931
spectral_utilities::plantensorforth
type(c_ptr), private plantensorforth
FFTW MPI plan P(x) to P(k)
Definition: spectral_utilities.f90:1511
spectral_utilities::utilities_fouriergammaconvolution
subroutine, public utilities_fouriergammaconvolution(fieldAim)
doing convolution gamma_hat * field_real, ensuring that average value = fieldAim
Definition: spectral_utilities.f90:1954
spectral_utilities::utilities_fourierscalargradient
subroutine, public utilities_fourierscalargradient()
calculate scalar gradient in fourier field
Definition: spectral_utilities.f90:2207
prec::dneq
logical elemental pure function dneq(a, b, tol)
inequality comparison for float with double precision
Definition: prec.f90:146
spectral_utilities::num
type(tnumerics) num
Definition: spectral_utilities.f90:1577
spectral_utilities::grid1red
integer, public, protected grid1red
grid(1)/2
Definition: spectral_utilities.f90:1491
spectral_utilities::utilities_updatecoords
subroutine, public utilities_updatecoords(F)
calculate coordinates in current configuration for given defgrad field
Definition: spectral_utilities.f90:2447
spectral_utilities::utilities_forwardfield
real(preal) function, dimension(3, 3, grid(1), grid(2), grid3), public utilities_forwardfield(timeinc, field_lastInc, rate, aim)
forwards a field with a pointwise given rate, if aim is given, ensures that the average matches the a...
Definition: spectral_utilities.f90:2368
discretization_grid::grid3offset
integer, public, protected grid3offset
(local) grid offset in 3rd direction
Definition: discretization_grid.f90:1478
math::math_invert
subroutine math_invert(InvA, error, A)
invert quadratic matrix of arbitrary dimension
Definition: math.f90:521
spectral_utilities::utilities_constitutiveresponse
subroutine, public utilities_constitutiveresponse(P, P_av, C_volAvg, C_minmaxAvg, F, timeinc, rotation_BC)
calculate constitutive response from materialpoint_F0 to F during timeinc
Definition: spectral_utilities.f90:2266
spectral_utilities::planscalarforth
type(c_ptr), private planscalarforth
FFTW MPI plan s(x) to s(k)
Definition: spectral_utilities.f90:1511
damask_interface
Interfacing between the 1-based solvers and the material subroutines provided by DAMASK.
Definition: DAMASK_interface.f90:22
config::config_numerics
type(tpartitionedstringlist), public, protected config_numerics
Definition: config.f90:30
spectral_utilities::tensorfield_real
real(c_double), dimension(:,:,:,:,:), pointer, public tensorfield_real
real representation (some stress or deformation) of field_fourier
Definition: spectral_utilities.f90:1497
debug::debug_spectral
integer, parameter, public debug_spectral
Definition: debug.f90:32
spectral_utilities::debugrotation
logical, private debugrotation
also printing out results in lab frame
Definition: spectral_utilities.f90:1521
spectral_utilities::plantensorback
type(c_ptr), private plantensorback
FFTW MPI plan F(k) to F(x)
Definition: spectral_utilities.f90:1511
numerics::worldrank
integer, public, protected worldrank
MPI worldrank (/=0 for MPI simulations only)
Definition: numerics.f90:1470
math
Mathematical library, including random number generation and tensor representations.
Definition: math.f90:12
spectral_utilities::gamma_hat
complex(preal), dimension(:,:,:,:,:,:,:), allocatable, private gamma_hat
gamma operator (field) for spectral method
Definition: spectral_utilities.f90:1503
spectral_utilities::wgt
real(preal), public, protected wgt
weighting factor 1/Nelems
Definition: spectral_utilities.f90:1490
discretization_grid::grid
integer, dimension(3), public, protected grid
(global) grid
Definition: discretization_grid.f90:1476
spectral_utilities::scalarfield_fourier
complex(c_double_complex), dimension(:,:,:), pointer, public scalarfield_fourier
scalar field fourier representation for fftw
Definition: spectral_utilities.f90:1502
spectral_utilities::tensorfield_fourier
complex(c_double_complex), dimension(:,:,:,:,:), pointer, public tensorfield_fourier
field on which the Fourier transform operates
Definition: spectral_utilities.f90:1498
debug::debug_spectralpetsc
integer, parameter, public debug_spectralpetsc
Definition: debug.f90:25
spectral_utilities::debugpetsc
logical, private debugpetsc
use some in debug defined options for more verbose 1 solution
Definition: spectral_utilities.f90:1521
debug::debug_spectralrotation
integer, parameter, public debug_spectralrotation
Definition: debug.f90:25
damask_interface::getsolverjobname
character(len=:) function, allocatable, public getsolverjobname()
solver job name (no extension) as combination of geometry and load case name
Definition: DAMASK_interface.f90:1737
io::io_open_binary
integer function, public io_open_binary(fileName, mode)
opens an existing file for reading or a new file for writing.
Definition: IO.f90:128
spectral_utilities::utilities_fouriergreenconvolution
subroutine, public utilities_fouriergreenconvolution(D_ref, mobility_ref, deltaT)
doing convolution DamageGreenOp_hat * field_real
Definition: spectral_utilities.f90:2009
spectral_utilities::tloadcase
Definition: spectral_utilities.f90:1544
io::io_lc
pure character(len=len(string)) function, public io_lc(string)
changes characters in string to lower case
Definition: IO.f90:280
spectral_utilities::xi2nd
complex(preal), dimension(:,:,:,:), allocatable, private xi2nd
wave vector field for second derivatives
Definition: spectral_utilities.f90:1505
spectral_utilities::utilities_maskedcompliance
real(preal) function, dimension(3, 3, 3, 3), public utilities_maskedcompliance(rot_BC, mask_stress, C)
calculates mask compliance tensor used to adjust F to fullfill stress BC
Definition: spectral_utilities.f90:2135
spectral_utilities::utilities_updategamma
subroutine, public utilities_updategamma(C)
updates reference stiffness and potentially precalculated gamma operator
Definition: spectral_utilities.f90:1841
math::pi
real(preal), parameter pi
ratio of a circle's circumference to its diameter
Definition: math.f90:27
spectral_utilities::tboundarycondition
set of parameters defining a boundary condition
Definition: spectral_utilities.f90:1537
spectral_utilities::derivative_fwbw_diff_id
@ derivative_fwbw_diff_id
Definition: spectral_utilities.f90:1582
numerics
Managing of parameters related to numerics.
Definition: numerics.f90:10
spectral_utilities::tsolutionstate
return type of solution from spectral solver variants
Definition: spectral_utilities.f90:1528
spectral_utilities::utilities_ffttensorbackward
subroutine, public utilities_ffttensorbackward
backward FFT of data in field_fourier to field_real
Definition: spectral_utilities.f90:1894
spectral_utilities::utilities_calculaterate
pure real(preal) function, dimension(3, 3, grid(1), grid(2), grid3), public utilities_calculaterate(heterogeneous, field0, field, dt, avRate)
calculates forward rate, either guessing or just add delta/timeinc
Definition: spectral_utilities.f90:2341
spectral_utilities::tnumerics
Definition: spectral_utilities.f90:1564
homogenization::materialpoint_stressanditstangent
subroutine, public materialpoint_stressanditstangent(updateJaco, dt)
parallelized calculation of stress and corresponding tangent at material points
Definition: homogenization.f90:213
spectral_utilities::utilities_fouriertensordivergence
subroutine, public utilities_fouriertensordivergence()
calculate tensor divergence in fourier field
Definition: spectral_utilities.f90:2251