DAMASK with grid solvers  Revision: v2.0.3-2204-gdb1f2151
The Düsseldorf Advanced Material Simulation Kit with Grid Solvers
DAMASK_interface.f90
Go to the documentation of this file.
1 # 1 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/DAMASK_interface.f90"
2 # 1 "<built-in>"
3 # 1 "<command-line>"
4 # 1 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/DAMASK_interface.f90"
5 !--------------------------------------------------------------------------------------------------
15 !--------------------------------------------------------------------------------------------------
16 
17 
18 
19 
20 
21 
23  use, intrinsic :: iso_fortran_env
24 
25  use petscsys
26 
27  use prec
28  use system_routines
29 
30  implicit none
31  private
32  logical, public, protected :: &
33  sigterm, & !< termination signal
34  sigusr1, & !< 1. user-defined signal
35  sigusr2
36  integer, public, protected :: &
38  character(len=:), allocatable, public, protected :: &
39  geometryfile, & !< parameter given for geometry file
41 
42  public :: &
45  setsigterm, &
46  setsigusr1, &
48 
49 contains
50 
51 !--------------------------------------------------------------------------------------------------
54 !--------------------------------------------------------------------------------------------------
55 subroutine damask_interface_init
56 
57 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 1
58 !
59 !
60 ! Part of the base include file for Fortran use of 1.
61 ! Note: This file should contain only define statements and
62 ! not the declaration of variables.
63 
64 ! No spaces for #defines as some compilers (PGI) also adds
65 ! those additional spaces during preprocessing - bad for fixed format
66 !
67 
68 
69 
70 # 1 "/opt/petsc-3.10.3/Intel-18.4-IntelMPI-2018/include/petscconf.h" 1
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 
1235 
1236 
1237 
1238 
1239 
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 # 13 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1279 
1280 
1281 
1282 
1283 # 1 "/opt/petsc-3.10.3/include/petscversion.h" 1
1284 
1285 
1286 
1287 
1288 
1289 
1290 
1291 
1292 
1293 
1294 
1295 
1296 
1297 
1298 
1299 
1300 
1301 
1302 
1303 
1304 
1305 
1306 
1307 
1308 
1309 
1310 
1311 
1312 
1313 
1314 
1315 
1316 
1317 
1318 
1319 
1320 
1321 
1322 
1323 
1324 
1325 
1326 
1327 
1328 
1329 # 17 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1330 
1331 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petscviewer.h" 1
1332 !
1333 ! Include file for Fortran use of the PetscViewer package in 1
1334 !
1335 
1336 
1337 
1338 
1339 
1340 
1341 
1342 
1343 
1344 
1345 
1346 
1347 
1348 # 31 "/opt/petsc-3.10.3/include/petsc/finclude/petscviewer.h"
1349 
1350 # 18 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1351 
1352 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petscerror.h" 1
1353 
1354 !
1355 ! Include file for Fortran error codes
1356 ! These are also in include/petscerror.h
1357 !
1358 
1359 
1360 
1361 # 24 "/opt/petsc-3.10.3/include/petsc/finclude/petscerror.h"
1362 
1363 # 38 "/opt/petsc-3.10.3/include/petsc/finclude/petscerror.h"
1364 
1365 
1366 
1367 
1368 
1369 
1370 
1371 
1372 
1373 
1374 
1375 
1376 
1377 
1378 
1379 
1380 # 19 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1381 
1382 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petsclog.h" 1
1383 !
1384 ! No includes needed for logging
1385 # 20 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1386 
1387 # 1 "/opt/petsc-3.10.3/include/petsc/finclude/petscbag.h" 1
1388 !
1389 !
1390 ! Include file for Fortran use of the Bag package in 1
1391 !
1392 
1393 
1394 
1395 
1396 
1397 !
1398 ! End of Fortran include file for the IS package in 1
1399 
1400 # 21 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h" 2
1401 
1402 !
1403 ! The real*8,complex*16 notatiton is used so that the
1404 ! 1 double/complex variables are not affected by
1405 ! compiler options like -r4,-r8, sometimes invoked
1406 ! by the user. NAG compiler does not like integer*4,real*8
1407 
1408 # 41 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1409 
1410 
1411 
1412 
1413 
1414 
1415 
1416 
1417 
1418 # 63 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1419 
1420 
1421 
1422 
1423 
1424 
1425 !
1426 
1427 
1428 
1429 
1430 
1431 !
1432 # 85 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1433 !
1434 
1435 
1436 
1437 
1438 
1439 
1440 !
1441 
1442 
1443 
1444 
1445 !
1446 
1447 !
1448 
1449 
1450 !
1451 # 128 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1452 
1453 # 150 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1454 !
1455 ! Macro for templating between real and complex
1456 !
1457 # 174 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1458 
1459 
1460 
1461 
1462 
1463 
1464 
1465 
1466 
1467 !
1468 ! Allows the matrix Fortran Kernels to work with single precision
1469 ! matrix data structures
1470 !
1471 
1472 !
1473 ! PetscLogDouble variables are used to contain double precision numbers
1474 ! that are not used in the numerical computations, but rather in logging,
1475 ! timing etc.
1476 !
1477 
1478 
1479 !
1480 ! Macros for error checking
1481 !
1482 
1483 
1484 
1485 
1486 
1487 
1488 
1489 
1490 # 215 "/opt/petsc-3.10.3/include/petsc/finclude/petscsys.h"
1491 
1492 
1493 
1494 
1495 
1496 
1497 
1498 
1499 
1500 
1501 
1502 
1503 # 53 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/DAMASK_interface.f90" 2
1504 # 64 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/DAMASK_interface.f90"
1505 
1506 # 76 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/DAMASK_interface.f90"
1507 
1508 # 88 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/DAMASK_interface.f90"
1509 
1510  character(len=pPathLen*3+pStringLen) :: &
1511  commandline
1512  character(len=pPathLen) :: &
1513  arg, & !< individual argument
1514  loadcasearg = '', & !< -l argument given to the executable
1515  geometryarg = '', &
1516  workingdirarg = ''
1517  character(len=pStringLen) :: &
1518  username
1519  integer :: &
1520  stat, &
1521  i, &
1522 
1523 
1524 
1525  worldrank = 0, &
1526  worldsize = 0, &
1527  typesize
1528  integer, dimension(8) :: &
1529  dateandtime
1530  integer :: mpi_err
1531  integer(kind=selected_int_kind(5)) :: petsc_err
1532  external :: &
1533  quit
1534 
1535  open(6, encoding='UTF-8') ! for special characters in output
1536 
1537 !--------------------------------------------------------------------------------------------------
1538 ! 1 Init
1539 # 128 "/home/damask_user/GitLabCI_Pipeline_4301/DAMASK/src/DAMASK_interface.f90"
1540  call petscinitializenoarguments(petsc_err) ! according to 1 manual, that should be the first line in the code
1541  if (petsc_err .ne. 0) then;call petscerrorf(petsc_err);return;endif ! this is a macro definition, it is case sensitive
1542 
1543  call mpi_comm_rank(petsc_comm_world,worldrank,mpi_err)
1544  if (mpi_err /= 0) call quit(1)
1545  call mpi_comm_size(petsc_comm_world,worldsize,mpi_err)
1546  if (mpi_err /= 0) call quit(1)
1547 
1548  mainprocess: if (worldrank == 0) then
1549  if (output_unit /= 6) then
1550  write(output_unit,'(/,a)') ' ERROR: STDOUT != 6'
1551  call quit(1)
1552  endif
1553  if (error_unit /= 0) then
1554  write(output_unit,'(/,a)') ' ERROR: STDERR != 0'
1555  call quit(1)
1556  endif
1557  else mainprocess
1558  close(6) ! disable output for non-master processes (open 6 to rank specific file for debug)
1559  open(6,file='/dev/null',status='replace') ! close(6) alone will leave some temp files in cwd
1560  endif mainprocess
1561 
1562  write(6,'(/,a)') ' <<<+- DAMASK_interface init -+>>>'
1563 
1564  ! http://patorjk.com/software/taag/#p=display&f=Lean&t=DAMASK
1565  write(6,*) achar(27)//'[94m'
1566  write(6,*) ' _/_/_/ _/_/ _/ _/ _/_/ _/_/_/ _/ _/'
1567  write(6,*) ' _/ _/ _/ _/ _/_/ _/_/ _/ _/ _/ _/ _/'
1568  write(6,*) ' _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/_/ _/_/ _/_/'
1569  write(6,*) ' _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/'
1570  write(6,*) ' _/_/_/ _/ _/ _/ _/ _/ _/ _/_/_/ _/ _/'
1571  write(6,*) achar(27)//'[0m'
1572 
1573  write(6,'(/,a)') ' Roters et al., Computational Materials Science 158:420–478, 2019'
1574  write(6,'(a)') ' https://doi.org/10.1016/j.commatsci.2018.04.030'
1575 
1576  write(6,'(/,a)') ' Version: '//damaskversion
1577 
1578  ! https://github.com/jeffhammond/HPCInfo/blob/master/docs/Preprocessor-Macros.md
1579 
1580  write(6,'(/,a)') ' Compiled with: '//compiler_version()
1581  write(6,'(a)') ' Compiler options: '//compiler_options()
1582 
1583 
1584 
1585 
1586 
1587 
1588 
1589 
1590  write(6,'(/,a)') ' Compiled on: '//"Apr 1 2020"//' at '//"18:44:57"
1591 
1592  call date_and_time(values = dateandtime)
1593  write(6,'(/,a,2(i2.2,a),i4.4)') ' Date: ',dateandtime(3),'/',dateandtime(2),'/', dateandtime(1)
1594  write(6,'(a,2(i2.2,a),i2.2)') ' Time: ',dateandtime(5),':', dateandtime(6),':', dateandtime(7)
1595 
1596  call mpi_type_size(mpi_integer,typesize,mpi_err)
1597  if (mpi_err /= 0) call quit(1)
1598  if (typesize*8 /= bit_size(0)) then
1599  write(6,'(a)') ' Mismatch between MPI and DAMASK integer'
1600  call quit(1)
1601  endif
1602 
1603  call mpi_type_size(mpi_double,typesize,mpi_err)
1604  if (mpi_err /= 0) call quit(1)
1605  if (typesize*8 /= storage_size(0.0_preal)) then
1606  write(6,'(a)') ' Mismatch between MPI and DAMASK real'
1607  call quit(1)
1608  endif
1609 
1610  do i = 1, command_argument_count()
1611  call get_command_argument(i,arg)
1612  select case(trim(arg)) ! extract key
1613  case ('-h','--help')
1614  write(6,'(a)') ' #######################################################################'
1615  write(6,'(a)') ' DAMASK Command Line Interface:'
1616  write(6,'(a)') ' For PETSc-based solvers for the Düsseldorf Advanced Material Simulation Kit'
1617  write(6,'(a,/)')' #######################################################################'
1618  write(6,'(a,/)')' Valid command line switches:'
1619  write(6,'(a)') ' --geom (-g, --geometry)'
1620  write(6,'(a)') ' --load (-l, --loadcase)'
1621  write(6,'(a)') ' --workingdir (-w, --wd, --workingdirectory, -d, --directory)'
1622  write(6,'(a)') ' --restart (-r, --rs)'
1623  write(6,'(a)') ' --help (-h)'
1624  write(6,'(/,a)')' -----------------------------------------------------------------------'
1625  write(6,'(a)') ' Mandatory arguments:'
1626  write(6,'(/,a)')' --geom PathToGeomFile/NameOfGeom'
1627  write(6,'(a)') ' Specifies the location of the geometry definition file.'
1628  write(6,'(/,a)')' --load PathToLoadFile/NameOfLoadFile'
1629  write(6,'(a)') ' Specifies the location of the load case definition file.'
1630  write(6,'(/,a)')' -----------------------------------------------------------------------'
1631  write(6,'(a)') ' Optional arguments:'
1632  write(6,'(/,a)')' --workingdirectory PathToWorkingDirectory'
1633  write(6,'(a)') ' Specifies the working directory and overwrites the default ./'
1634  write(6,'(a)') ' Make sure the file "material.config" exists in the working'
1635  write(6,'(a)') ' directory.'
1636  write(6,'(a)') ' For further configuration place "numerics.config"'
1637  write(6,'(a)')' and "debug.config" in that directory.'
1638  write(6,'(/,a)')' --restart XX'
1639  write(6,'(a)') ' Reads in increment XX and continues with calculating'
1640  write(6,'(a)') ' increment XX+1 based on this.'
1641  write(6,'(a)') ' Appends to existing results file'
1642  write(6,'(a)') ' "NameOfGeom_NameOfLoadFile".'
1643  write(6,'(a)') ' Works only if the restart information for increment XX'
1644  write(6,'(a)') ' is available in the working directory.'
1645  write(6,'(/,a)')' -----------------------------------------------------------------------'
1646  write(6,'(a)') ' Help:'
1647  write(6,'(/,a)')' --help'
1648  write(6,'(a,/)')' Prints this message and exits'
1649  call quit(0) ! normal Termination
1650  case ('-l', '--load', '--loadcase')
1651  call get_command_argument(i+1,loadcasearg)
1652  case ('-g', '--geom', '--geometry')
1653  call get_command_argument(i+1,geometryarg)
1654  case ('-w', '-d', '--wd', '--directory', '--workingdir', '--workingdirectory')
1655  call get_command_argument(i+1,workingdirarg)
1656  case ('-r', '--rs', '--restart')
1657  call get_command_argument(i+1,arg)
1658  read(arg,*,iostat=stat) interface_restartinc
1659  if (interface_restartinc < 0 .or. stat /=0) then
1660  write(6,'(/,a)') ' ERROR: Could not parse restart increment: '//trim(arg)
1661  call quit(1)
1662  endif
1663  end select
1664  enddo
1665 
1666  if (len_trim(loadcasearg) == 0 .or. len_trim(geometryarg) == 0) then
1667  write(6,'(/,a)') ' ERROR: Please specify geometry AND load case (-h for help)'
1668  call quit(1)
1669  endif
1670 
1671  if (len_trim(workingdirarg) > 0) call setworkingdirectory(trim(workingdirarg))
1672  geometryfile = getgeometryfile(geometryarg)
1673  loadcasefile = getloadcasefile(loadcasearg)
1674 
1675  call get_command(commandline)
1676  call get_environment_variable('USER',username)
1677  ! ToDo: https://stackoverflow.com/questions/8953424/how-to-get-the-username-in-c-c-in-linux
1678  write(6,'(/,a,i4.1)') ' MPI processes: ',worldsize
1679  write(6,'(a,a)') ' Host name: ', trim(gethostname())
1680  write(6,'(a,a)') ' User name: ', trim(username)
1681 
1682  write(6,'(/a,a)') ' Command line call: ', trim(commandline)
1683  if (len_trim(workingdirarg) > 0) &
1684  write(6,'(a,a)') ' Working dir argument: ', trim(workingdirarg)
1685  write(6,'(a,a)') ' Geometry argument: ', trim(geometryarg)
1686  write(6,'(a,a)') ' Load case argument: ', trim(loadcasearg)
1687  write(6,'(a,a)') ' Working directory: ', getcwd()
1688  write(6,'(a,a)') ' Geometry file: ', geometryfile
1689  write(6,'(a,a)') ' Loadcase file: ', loadcasefile
1690  write(6,'(a,a)') ' Solver job name: ', getsolverjobname()
1691  if (interface_restartinc > 0) &
1692  write(6,'(a,i6.6)') ' Restart from increment: ', interface_restartinc
1693 
1694  !call signalterm_c(c_funloc(catchSIGTERM))
1695  call signalusr1_c(c_funloc(catchsigusr1))
1696  call signalusr2_c(c_funloc(catchsigusr2))
1697  call setsigterm(.false.)
1698  call setsigusr1(.false.)
1699  call setsigusr2(.false.)
1700 
1701 
1702 end subroutine damask_interface_init
1703 
1704 
1705 !--------------------------------------------------------------------------------------------------
1708 !--------------------------------------------------------------------------------------------------
1709 subroutine setworkingdirectory(workingDirectoryArg)
1711  character(len=*), intent(in) :: workingDirectoryArg
1712  character(len=pPathLen) :: workingDirectory
1713  logical :: error
1714  external :: quit
1715 
1716  absolutepath: if (workingdirectoryarg(1:1) == '/') then
1717  workingdirectory = workingdirectoryarg
1718  else absolutepath
1719  workingdirectory = getcwd()
1720  workingdirectory = trim(workingdirectory)//'/'//workingdirectoryarg
1721  endif absolutepath
1722 
1723  workingdirectory = trim(rectifypath(workingdirectory))
1724  error = setcwd(trim(workingdirectory))
1725  if(error) then
1726  write(6,'(/,a)') ' ERROR: Invalid Working directory: '//trim(workingdirectory)
1727  call quit(1)
1728  endif
1729 
1730 end subroutine setworkingdirectory
1731 
1732 
1733 !--------------------------------------------------------------------------------------------------
1735 !--------------------------------------------------------------------------------------------------
1736 function getsolverjobname()
1738  character(len=:), allocatable :: getsolverjobname
1739  integer :: posext,possep
1740 
1741  posext = scan(geometryfile,'.',back=.true.)
1742  possep = scan(geometryfile,'/',back=.true.)
1743 
1744  getsolverjobname = geometryfile(possep+1:posext-1)
1745 
1746  posext = scan(loadcasefile,'.',back=.true.)
1747  possep = scan(loadcasefile,'/',back=.true.)
1748 
1749  getsolverjobname = getsolverjobname//'_'//loadcasefile(possep+1:posext-1)
1750 
1751 end function getsolverjobname
1752 
1753 
1754 !--------------------------------------------------------------------------------------------------
1756 !--------------------------------------------------------------------------------------------------
1757 function getgeometryfile(geometryParameter)
1759  character(len=:), allocatable :: getgeometryfile
1760  character(len=*), intent(in) :: geometryparameter
1761  logical :: file_exists
1762  external :: quit
1763 
1764  getgeometryfile = trim(geometryparameter)
1765  if (scan(getgeometryfile,'/') /= 1) getgeometryfile = getcwd()//'/'//trim(getgeometryfile)
1767 
1768  inquire(file=getgeometryfile, exist=file_exists)
1769  if (.not. file_exists) then
1770  write(6,'(/,a)') ' ERROR: Geometry file does not exists ('//trim(getgeometryfile)//')'
1771  call quit(1)
1772  endif
1773 
1774 end function getgeometryfile
1775 
1776 
1777 !--------------------------------------------------------------------------------------------------
1779 !--------------------------------------------------------------------------------------------------
1780 function getloadcasefile(loadCaseParameter)
1782  character(len=:), allocatable :: getloadcasefile
1783  character(len=*), intent(in) :: loadcaseparameter
1784  logical :: file_exists
1785  external :: quit
1786 
1787  getloadcasefile = trim(loadcaseparameter)
1788  if (scan(getloadcasefile,'/') /= 1) getloadcasefile = getcwd()//'/'//trim(getloadcasefile)
1790 
1791  inquire(file=getloadcasefile, exist=file_exists)
1792  if (.not. file_exists) then
1793  write(6,'(/,a)') ' ERROR: Load case file does not exists ('//trim(getloadcasefile)//')'
1794  call quit(1)
1795  endif
1796 
1797 end function getloadcasefile
1798 
1799 
1800 !--------------------------------------------------------------------------------------------------
1803 !--------------------------------------------------------------------------------------------------
1804 function rectifypath(path)
1806  character(len=*), intent(in) :: path
1807  character(len=:), allocatable :: rectifypath
1808  integer :: i,j,k,l
1809 
1810 !--------------------------------------------------------------------------------------------------
1811 ! remove /./ from path
1812  rectifypath = trim(path)
1813  l = len_trim(rectifypath)
1814  do i = l,3,-1
1815  if (rectifypath(i-2:i) == '/./') rectifypath(i-1:l) = rectifypath(i+1:l)//' '
1816  enddo
1817 
1818 !--------------------------------------------------------------------------------------------------
1819 ! remove // from path
1820  l = len_trim(rectifypath)
1821  do i = l,2,-1
1822  if (rectifypath(i-1:i) == '//') rectifypath(i-1:l) = rectifypath(i:l)//' '
1823  enddo
1824 
1825 !--------------------------------------------------------------------------------------------------
1826 ! remove ../ and corresponding directory from rectifyPath
1827  l = len_trim(rectifypath)
1828  i = index(rectifypath(i:l),'../')
1829  j = 0
1830  do while (i > j)
1831  j = scan(rectifypath(1:i-2),'/',back=.true.)
1832  rectifypath(j+1:l) = rectifypath(i+3:l)//repeat(' ',2+i-j)
1833  if (rectifypath(j+1:j+1) == '/') then !search for '//' that appear in case of XXX/../../XXX
1834  k = len_trim(rectifypath)
1835  rectifypath(j+1:k-1) = rectifypath(j+2:k)
1836  rectifypath(k:k) = ' '
1837  endif
1838  i = j+index(rectifypath(j+1:l),'../')
1839  enddo
1840  if(len_trim(rectifypath) == 0) rectifypath = '/'
1841 
1842  rectifypath = trim(rectifypath)
1843 
1844 end function rectifypath
1845 
1846 
1847 !--------------------------------------------------------------------------------------------------
1849 !--------------------------------------------------------------------------------------------------
1850 function makerelativepath(a,b)
1852  character (len=*), intent(in) :: a,b
1853  character (len=pPathLen) :: a_cleaned,b_cleaned
1854  character(len=:), allocatable :: makerelativepath
1855  integer :: i,poslastcommonslash,remainingslashes
1856 
1857  poslastcommonslash = 0
1858  remainingslashes = 0
1859  a_cleaned = rectifypath(trim(a)//'/')
1860  b_cleaned = rectifypath(b)
1861 
1862  do i = 1, min(1024,len_trim(a_cleaned),len_trim(rectifypath(b_cleaned)))
1863  if (a_cleaned(i:i) /= b_cleaned(i:i)) exit
1864  if (a_cleaned(i:i) == '/') poslastcommonslash = i
1865  enddo
1866  do i = poslastcommonslash+1,len_trim(a_cleaned)
1867  if (a_cleaned(i:i) == '/') remainingslashes = remainingslashes + 1
1868  enddo
1869 
1870  makerelativepath = repeat('..'//'/',remainingslashes)//b_cleaned(poslastcommonslash+1:len_trim(b_cleaned))
1871 
1872 end function makerelativepath
1873 
1874 
1875 !--------------------------------------------------------------------------------------------------
1877 !--------------------------------------------------------------------------------------------------
1878 subroutine catchsigterm(signal) bind(C)
1880  integer(C_INT), value :: signal
1881  sigterm = .true.
1882 
1883  write(6,'(a,i2.2,a)') ' received signal ',signal, ', set SIGTERM'
1884 
1885 end subroutine catchsigterm
1886 
1887 
1888 !--------------------------------------------------------------------------------------------------
1890 !--------------------------------------------------------------------------------------------------
1891 subroutine setsigterm(state)
1893  logical, intent(in) :: state
1894  sigterm = state
1895 
1896 end subroutine setsigterm
1897 
1898 
1899 !--------------------------------------------------------------------------------------------------
1901 !--------------------------------------------------------------------------------------------------
1902 subroutine catchsigusr1(signal) bind(C)
1904  integer(C_INT), value :: signal
1905  sigusr1 = .true.
1906 
1907  write(6,'(a,i2.2,a)') ' received signal ',signal, ', set SIGUSR1'
1908 
1909 end subroutine catchsigusr1
1910 
1911 
1912 !--------------------------------------------------------------------------------------------------
1914 !--------------------------------------------------------------------------------------------------
1915 subroutine setsigusr1(state)
1917  logical, intent(in) :: state
1918  sigusr1 = state
1919 
1920 end subroutine setsigusr1
1921 
1922 
1923 !--------------------------------------------------------------------------------------------------
1925 !--------------------------------------------------------------------------------------------------
1926 subroutine catchsigusr2(signal) bind(C)
1928  integer(C_INT), value :: signal
1929  sigusr2 = .true.
1930 
1931  write(6,'(a,i2.2,a)') ' received signal ',signal, ', set SIGUSR2'
1932 
1933 end subroutine catchsigusr2
1934 
1935 
1936 !--------------------------------------------------------------------------------------------------
1938 !--------------------------------------------------------------------------------------------------
1939 subroutine setsigusr2(state)
1941  logical, intent(in) :: state
1942  sigusr2 = state
1943 
1944 end subroutine setsigusr2
1945 
1946 
1947 end module
damask_interface::makerelativepath
character(len=:) function, allocatable makerelativepath(a, b)
relative path from absolute a to absolute b
Definition: DAMASK_interface.f90:1851
damask_interface::setsigterm
subroutine, public setsigterm(state)
sets global variable SIGTERM
Definition: DAMASK_interface.f90:1892
system_routines::setcwd
logical function, public setcwd(path)
changes the current working directory
Definition: system_routines.f90:176
damask_interface::setsigusr1
subroutine, public setsigusr1(state)
sets global variable SIGUSR1
Definition: DAMASK_interface.f90:1916
damask_interface::geometryfile
character(len=:), allocatable, public, protected geometryfile
parameter given for geometry file
Definition: DAMASK_interface.f90:38
damask_interface::catchsigusr2
subroutine catchsigusr2(signal)
sets global variable SIGUSR2 to .true. if program receives SIGUSR2
Definition: DAMASK_interface.f90:1927
damask_interface::getloadcasefile
character(len=:) function, allocatable getloadcasefile(loadCaseParameter)
relative path of loadcase from command line arguments
Definition: DAMASK_interface.f90:1781
damask_interface::loadcasefile
character(len=:), allocatable, public, protected loadcasefile
parameter given for load case file
Definition: DAMASK_interface.f90:38
system_routines::getcwd
character(len=:) function, allocatable, public getcwd()
gets the current working directory
Definition: system_routines.f90:118
damask_interface::sigusr1
logical, public, protected sigusr1
user-defined signal
Definition: DAMASK_interface.f90:32
damask_interface::catchsigusr1
subroutine catchsigusr1(signal)
sets global variable SIGUSR1 to .true.
Definition: DAMASK_interface.f90:1903
prec
setting precision for real and int type
Definition: prec.f90:13
damask_interface::damask_interface_init
subroutine, public damask_interface_init
initializes the solver by interpreting the command line arguments. Also writes information on computa...
Definition: DAMASK_interface.f90:56
damask_interface::setworkingdirectory
subroutine setworkingdirectory(workingDirectoryArg)
extract working directory from given argument or from location of geometry file, possibly converting ...
Definition: DAMASK_interface.f90:1710
quit
subroutine quit(stop_id)
quit subroutine
Definition: quit.f90:12
damask_interface::sigusr2
logical, public, protected sigusr2
Definition: DAMASK_interface.f90:32
damask_interface::getgeometryfile
character(len=:) function, allocatable getgeometryfile(geometryParameter)
basename of geometry file with extension from command line arguments
Definition: DAMASK_interface.f90:1758
system_routines
provides wrappers to C routines
Definition: system_routines.f90:9
damask_interface::sigterm
logical, public, protected sigterm
termination signal
Definition: DAMASK_interface.f90:32
damask_interface::rectifypath
character(len=:) function, allocatable rectifypath(path)
remove ../, /./, and // from path.
Definition: DAMASK_interface.f90:1805
damask_interface::interface_restartinc
integer, public, protected interface_restartinc
Increment at which calculation starts.
Definition: DAMASK_interface.f90:36
damask_interface
Interfacing between the 1-based solvers and the material subroutines provided by DAMASK.
Definition: DAMASK_interface.f90:22
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
damask_interface::catchsigterm
subroutine catchsigterm(signal)
sets global variable SIGTERM to .true.
Definition: DAMASK_interface.f90:1879
damask_interface::setsigusr2
subroutine, public setsigusr2(state)
sets global variable SIGUSR2
Definition: DAMASK_interface.f90:1940
system_routines::gethostname
character(len=:) function, allocatable, public gethostname()
gets the current host name
Definition: system_routines.f90:147