mirror of
https://git.gfz-potsdam.de/naaice/poet.git
synced 2025-12-16 12:54:50 +01:00
migrate: separate control logic from ChemistryModule into dedicated ControlModule
This commit is contained in:
parent
d1d6211c30
commit
0f4051dbee
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,72 +0,0 @@
|
||||
Iteration Rollback Species MAPE RRSME
|
||||
---------------------------------------------------------------------------
|
||||
100 0 cell_ID 0 0
|
||||
100 0 ID 0 0
|
||||
100 0 H 3.12231e-14 1.1509e-15
|
||||
100 0 O 5.71631e-09 1.52456e-10
|
||||
100 0 Charge 0.00277434 0.000180148
|
||||
100 0 C 0.000123678 2.12884e-05
|
||||
100 0 Ca 0.00012359 2.12719e-05
|
||||
100 0 Cl 52.4183 0.723995
|
||||
100 0 Mg 0.25793 0.0507445
|
||||
100 0 Calcite 7.41077e-06 1.27769e-06
|
||||
100 0 Calcite_p1 0 0
|
||||
100 0 Dolomite 0 0
|
||||
100 0 Dolomite_p1 0 0
|
||||
|
||||
200 1 cell_ID 0 0
|
||||
200 1 ID 0 0
|
||||
200 1 H 2.95859e-14 9.60014e-16
|
||||
200 1 O 5.02824e-09 6.20613e-11
|
||||
200 1 Charge 0.00161321 8.9929e-05
|
||||
200 1 C 2.83375e-05 3.68986e-06
|
||||
200 1 Ca 2.82814e-05 3.6869e-06
|
||||
200 1 Cl 4.33261 0.208132
|
||||
200 1 Mg 0.261454 0.0511126
|
||||
200 1 Calcite 1.69344e-06 2.19948e-07
|
||||
200 1 Calcite_p1 0 0
|
||||
200 1 Dolomite 2.12138e-07 4.39278e-07
|
||||
200 1 Dolomite_p1 0 0
|
||||
|
||||
300 1 cell_ID 0 0
|
||||
300 1 ID 0 0
|
||||
300 1 H 2.61483e-14 8.44115e-16
|
||||
300 1 O 4.20912e-09 5.28953e-11
|
||||
300 1 Charge 0.00111694 4.8082e-05
|
||||
300 1 C 9.01588e-06 1.37917e-06
|
||||
300 1 Ca 8.98915e-06 1.37725e-06
|
||||
300 1 Cl 0.0250508 0.0158114
|
||||
300 1 Mg 0.0368942 0.0192029
|
||||
300 1 Calcite 5.42801e-07 8.23432e-08
|
||||
300 1 Calcite_p1 0 0
|
||||
300 1 Dolomite 1.34065e-05 1.50929e-05
|
||||
300 1 Dolomite_p1 0 0
|
||||
|
||||
400 1 cell_ID 0 0
|
||||
400 1 ID 0 0
|
||||
400 1 H 2.52669e-14 7.70988e-16
|
||||
400 1 O 3.13537e-09 4.41261e-11
|
||||
400 1 Charge 0.00111045 4.73189e-05
|
||||
400 1 C 5.21852e-06 4.67209e-07
|
||||
400 1 Ca 5.28321e-06 4.7664e-07
|
||||
400 1 Cl 1.88383e-08 1.72516e-08
|
||||
400 1 Mg 1.6654e-07 7.23985e-08
|
||||
400 1 Calcite 3.29709e-07 3.02443e-08
|
||||
400 1 Calcite_p1 0 0
|
||||
400 1 Dolomite 0.000108165 7.44989e-05
|
||||
400 1 Dolomite_p1 0 0
|
||||
|
||||
500 1 cell_ID 0 0
|
||||
500 1 ID 0 0
|
||||
500 1 H 2.5648e-14 8.49637e-16
|
||||
500 1 O 2.06816e-09 3.48582e-11
|
||||
500 1 Charge 0.00117171 7.1904e-05
|
||||
500 1 C 4.68561e-06 3.1246e-07
|
||||
500 1 Ca 4.847e-06 3.29307e-07
|
||||
500 1 Cl 8.19957e-11 4.15952e-11
|
||||
500 1 Mg 2.88349e-07 1.01377e-07
|
||||
500 1 Calcite 3.12577e-07 2.30026e-08
|
||||
500 1 Calcite_p1 0 0
|
||||
500 1 Dolomite 7.6329e-05 3.37797e-05
|
||||
500 1 Dolomite_p1 0 0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,72 +0,0 @@
|
||||
Iteration Rollback Species MAPE RRSME
|
||||
---------------------------------------------------------------------------
|
||||
100 0 cell_ID 0 0
|
||||
100 0 ID 0 0
|
||||
100 0 H 3.47278e-14 1.28046e-15
|
||||
100 0 O 3.91041e-09 1.46205e-10
|
||||
100 0 Charge 0.00341346 0.000209852
|
||||
100 0 C 0.00012351 2.10537e-05
|
||||
100 0 Ca 0.00012342 2.10371e-05
|
||||
100 0 Cl 51.8517 0.720026
|
||||
100 0 Mg 0.0164251 0.0119904
|
||||
100 0 Calcite 7.40172e-06 1.26365e-06
|
||||
100 0 Calcite_p1 0 0
|
||||
100 0 Dolomite 0 0
|
||||
100 0 Dolomite_p1 0 0
|
||||
|
||||
200 1 cell_ID 0 0
|
||||
200 1 ID 0 0
|
||||
200 1 H 2.85412e-14 9.17937e-16
|
||||
200 1 O 4.25235e-09 5.35197e-11
|
||||
200 1 Charge 0.00115635 6.27422e-05
|
||||
200 1 C 2.84308e-05 3.72039e-06
|
||||
200 1 Ca 2.83753e-05 3.71755e-06
|
||||
200 1 Cl 4.21085 0.205107
|
||||
200 1 Mg 0.0583267 0.0238491
|
||||
200 1 Calcite 1.6987e-06 2.21727e-07
|
||||
200 1 Calcite_p1 0 0
|
||||
200 1 Dolomite 1.4852e-07 2.49534e-07
|
||||
200 1 Dolomite_p1 0 0
|
||||
|
||||
300 1 cell_ID 0 0
|
||||
300 1 ID 0 0
|
||||
300 1 H 3.09033e-14 1.04628e-15
|
||||
300 1 O 3.61033e-09 4.49029e-11
|
||||
300 1 Charge 0.00199629 0.000104649
|
||||
300 1 C 8.92201e-06 1.3502e-06
|
||||
300 1 Ca 8.88482e-06 1.34813e-06
|
||||
300 1 Cl 0.0252149 0.0158115
|
||||
300 1 Mg 0.0271398 0.0163938
|
||||
300 1 Calcite 5.36046e-07 8.05148e-08
|
||||
300 1 Calcite_p1 0 0
|
||||
300 1 Dolomite 8.76776e-06 8.08383e-06
|
||||
300 1 Dolomite_p1 0 0
|
||||
|
||||
400 1 cell_ID 0 0
|
||||
400 1 ID 0 0
|
||||
400 1 H 2.47784e-14 8.02966e-16
|
||||
400 1 O 2.77372e-09 3.82347e-11
|
||||
400 1 Charge 0.00109769 4.46829e-05
|
||||
400 1 C 5.18807e-06 4.53038e-07
|
||||
400 1 Ca 5.25706e-06 4.58743e-07
|
||||
400 1 Cl 7.98413e-08 6.88159e-08
|
||||
400 1 Mg 3.17154e-07 1.76467e-07
|
||||
400 1 Calcite 3.28375e-07 2.88573e-08
|
||||
400 1 Calcite_p1 0 0
|
||||
400 1 Dolomite 9.74408e-05 5.10781e-05
|
||||
400 1 Dolomite_p1 0 0
|
||||
|
||||
500 1 cell_ID 0 0
|
||||
500 1 ID 0 0
|
||||
500 1 H 2.58635e-14 8.70649e-16
|
||||
500 1 O 1.81852e-09 2.99676e-11
|
||||
500 1 Charge 0.00140547 7.9273e-05
|
||||
500 1 C 4.61893e-06 3.09187e-07
|
||||
500 1 Ca 4.79576e-06 3.21992e-07
|
||||
500 1 Cl 2.35937e-10 1.70544e-10
|
||||
500 1 Mg 3.04927e-07 9.42059e-08
|
||||
500 1 Calcite 3.10603e-07 2.22112e-08
|
||||
500 1 Calcite_p1 0 0
|
||||
500 1 Dolomite 7.05202e-05 2.85239e-05
|
||||
500 1 Dolomite_p1 0 0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,18 +0,0 @@
|
||||
Iteration Rollback Species MAPE RRSME
|
||||
---------------------------------------------------------------------------
|
||||
40 0 cell_ID 0 0
|
||||
40 0 ID 0 0
|
||||
40 0 H 1.97536e-14 3.39767e-16
|
||||
40 0 O 0.108667 0.00113058
|
||||
40 0 Charge 0.0149527 0.000159859
|
||||
40 0 C 0.000320855 3.77065e-05
|
||||
40 0 Ca 0.000320918 3.77053e-05
|
||||
40 0 Cl 2.94255 0.0564879
|
||||
40 0 Mg 2.99364 0.058404
|
||||
40 0 Calcite 0.000193155 2.27958e-05
|
||||
40 0 Calcite_p1 0 0
|
||||
40 0 Dolomite 5.53123e-06 7.32342e-06
|
||||
40 0 Dolomite_p1 0 0
|
||||
40 0 O2g_eq 0.292811 0.0030472
|
||||
40 0 O2g_si 0 0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,82 +0,0 @@
|
||||
Iteration Rollback Species MAPE RRSME
|
||||
---------------------------------------------------------------------------
|
||||
200 0 cell_ID 0 0
|
||||
200 0 ID 0 0
|
||||
200 0 H 4.24216e-14 7.93767e-16
|
||||
200 0 O 0.266416 0.00345942
|
||||
200 0 Charge 0.0108553 0.00016141
|
||||
200 0 C 0.00105879 4.62528e-05
|
||||
200 0 Ca 0.00106128 4.64714e-05
|
||||
200 0 Cl 0.183638 0.0281206
|
||||
200 0 Mg 0.357623 0.068502
|
||||
200 0 Calcite 0.000660749 3.05684e-05
|
||||
200 0 Calcite_p1 0 0
|
||||
200 0 Dolomite 0.0377868 0.018717
|
||||
200 0 Dolomite_p1 0 0
|
||||
200 0 O2g_eq 0.727525 0.00942789
|
||||
200 0 O2g_si 0 0
|
||||
|
||||
400 1 cell_ID 0 0
|
||||
400 1 ID 0 0
|
||||
400 1 H 4.96116e-14 1.03074e-15
|
||||
400 1 O 0.0625096 0.00089073
|
||||
400 1 Charge 0.00179685 5.81218e-05
|
||||
400 1 C 0.00138513 4.19276e-05
|
||||
400 1 Ca 0.00138939 4.22617e-05
|
||||
400 1 Cl 2.01049e-10 1.12062e-11
|
||||
400 1 Mg 1.73388e-05 1.58885e-06
|
||||
400 1 Calcite 0.000887349 3.09872e-05
|
||||
400 1 Calcite_p1 0 0
|
||||
400 1 Dolomite 0.0508038 0.0422224
|
||||
400 1 Dolomite_p1 0 0
|
||||
400 1 O2g_eq 0.169632 0.00241576
|
||||
400 1 O2g_si 0 0
|
||||
|
||||
600 2 cell_ID 0 0
|
||||
600 2 ID 0 0
|
||||
600 2 H 5.02907e-14 1.04743e-15
|
||||
600 2 O 0.0339388 0.000529191
|
||||
600 2 Charge 0.000872335 3.88643e-05
|
||||
600 2 C 0.00161187 4.55169e-05
|
||||
600 2 Ca 0.00161202 4.55691e-05
|
||||
600 2 Cl 2.00968e-10 7.09682e-12
|
||||
600 2 Mg 1.78737e-05 1.52671e-06
|
||||
600 2 Calcite 0.00112915 5.57669e-05
|
||||
600 2 Calcite_p1 0 0
|
||||
600 2 Dolomite 0.0464188 0.020625
|
||||
600 2 Dolomite_p1 0 0
|
||||
600 2 O2g_eq 0.0916364 0.00144097
|
||||
600 2 O2g_si 0 0
|
||||
|
||||
800 3 cell_ID 0 0
|
||||
800 3 ID 0 0
|
||||
800 3 H 5.02456e-14 1.07954e-15
|
||||
800 3 O 0.0348835 0.000593709
|
||||
800 3 Charge 0.000981333 4.59987e-05
|
||||
800 3 C 0.00188335 5.51043e-05
|
||||
800 3 Ca 0.00187866 5.48754e-05
|
||||
800 3 Cl 1.91647e-10 6.80693e-12
|
||||
800 3 Mg 1.99396e-05 1.4224e-06
|
||||
800 3 Calcite 0.00133831 7.37938e-05
|
||||
800 3 Calcite_p1 0 0
|
||||
800 3 Dolomite 0.0122079 0.00910585
|
||||
800 3 Dolomite_p1 0 0
|
||||
800 3 O2g_eq 0.094699 0.00161554
|
||||
800 3 O2g_si 0 0
|
||||
|
||||
1000 4 cell_ID 0 0
|
||||
1000 4 ID 0 0
|
||||
1000 4 H 4.58333e-14 9.19552e-16
|
||||
1000 4 O 0.03928 0.000658637
|
||||
1000 4 Charge 0.000850352 3.64268e-05
|
||||
1000 4 C 0.00162933 4.32013e-05
|
||||
1000 4 Ca 0.00162399 4.31629e-05
|
||||
1000 4 Cl 1.78469e-10 6.32135e-12
|
||||
1000 4 Mg 2.54679e-05 1.5059e-06
|
||||
1000 4 Calcite 0.00110095 3.85726e-05
|
||||
1000 4 Calcite_p1 0 0
|
||||
1000 4 Dolomite 0.115066 0.0336203
|
||||
1000 4 Dolomite_p1 0 0
|
||||
1000 4 O2g_eq 0.10644 0.00178803
|
||||
1000 4 O2g_si 0 0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,82 +0,0 @@
|
||||
Iteration Rollback Species MAPE RRSME
|
||||
---------------------------------------------------------------------------
|
||||
200 0 cell_ID 0 0
|
||||
200 0 ID 0 0
|
||||
200 0 H 4.35833e-14 7.81087e-16
|
||||
200 0 O 0.265974 0.00345273
|
||||
200 0 Charge 0.0139127 0.00021089
|
||||
200 0 C 0.00106544 4.68727e-05
|
||||
200 0 Ca 0.00106775 4.71101e-05
|
||||
200 0 Cl 0.153803 0.0309734
|
||||
200 0 Mg 0.259249 0.0557173
|
||||
200 0 Calcite 0.000666058 3.09596e-05
|
||||
200 0 Calcite_p1 0 0
|
||||
200 0 Dolomite 0.0378628 0.0187185
|
||||
200 0 Dolomite_p1 0 0
|
||||
200 0 O2g_eq 0.726346 0.00940997
|
||||
200 0 O2g_si 0 0
|
||||
|
||||
400 1 cell_ID 0 0
|
||||
400 1 ID 0 0
|
||||
400 1 H 4.96779e-14 1.02625e-15
|
||||
400 1 O 0.0612117 0.000885574
|
||||
400 1 Charge 0.00211885 7.23582e-05
|
||||
400 1 C 0.0013936 4.246e-05
|
||||
400 1 Ca 0.00139683 4.27607e-05
|
||||
400 1 Cl 1.92492e-10 7.96912e-12
|
||||
400 1 Mg 1.72798e-05 1.57044e-06
|
||||
400 1 Calcite 0.000893972 3.23061e-05
|
||||
400 1 Calcite_p1 0 0
|
||||
400 1 Dolomite 0.0508392 0.0424705
|
||||
400 1 Dolomite_p1 0 0
|
||||
400 1 O2g_eq 0.166295 0.00240305
|
||||
400 1 O2g_si 0 0
|
||||
|
||||
600 2 cell_ID 0 0
|
||||
600 2 ID 0 0
|
||||
600 2 H 4.98299e-14 1.03244e-15
|
||||
600 2 O 0.0337469 0.000532858
|
||||
600 2 Charge 0.000886747 3.95933e-05
|
||||
600 2 C 0.00157754 4.32746e-05
|
||||
600 2 Ca 0.0015787 4.33921e-05
|
||||
600 2 Cl 1.99043e-10 6.97877e-12
|
||||
600 2 Mg 1.78781e-05 1.51655e-06
|
||||
600 2 Calcite 0.00112008 9.94027e-05
|
||||
600 2 Calcite_p1 0 0
|
||||
600 2 Dolomite 0.0440381 0.0200137
|
||||
600 2 Dolomite_p1 0 0
|
||||
600 2 O2g_eq 0.0911647 0.00145098
|
||||
600 2 O2g_si 0 0
|
||||
|
||||
800 3 cell_ID 0 0
|
||||
800 3 ID 0 0
|
||||
800 3 H 4.95687e-14 1.04941e-15
|
||||
800 3 O 0.0342771 0.000595825
|
||||
800 3 Charge 0.000999783 4.79781e-05
|
||||
800 3 C 0.00187815 5.36255e-05
|
||||
800 3 Ca 0.00187373 5.34439e-05
|
||||
800 3 Cl 1.90419e-10 6.73422e-12
|
||||
800 3 Mg 2.00131e-05 1.42672e-06
|
||||
800 3 Calcite 0.00127536 4.6846e-05
|
||||
800 3 Calcite_p1 0 0
|
||||
800 3 Dolomite 0.0116904 0.00900077
|
||||
800 3 Dolomite_p1 0 0
|
||||
800 3 O2g_eq 0.092918 0.00162017
|
||||
800 3 O2g_si 0 0
|
||||
|
||||
1000 4 cell_ID 0 0
|
||||
1000 4 ID 0 0
|
||||
1000 4 H 4.46262e-14 8.84025e-16
|
||||
1000 4 O 0.0393243 0.000668632
|
||||
1000 4 Charge 0.000823168 3.55208e-05
|
||||
1000 4 C 0.00163087 4.28808e-05
|
||||
1000 4 Ca 0.00162568 4.28564e-05
|
||||
1000 4 Cl 1.74767e-10 6.13816e-12
|
||||
1000 4 Mg 2.51858e-05 1.49617e-06
|
||||
1000 4 Calcite 0.00109436 3.63441e-05
|
||||
1000 4 Calcite_p1 0 0
|
||||
1000 4 Dolomite 0.115761 0.0351099
|
||||
1000 4 Dolomite_p1 0 0
|
||||
1000 4 O2g_eq 0.106644 0.00181596
|
||||
1000 4 O2g_si 0 0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,82 +0,0 @@
|
||||
Iteration Rollback Species MAPE RRSME
|
||||
---------------------------------------------------------------------------
|
||||
200 0 cell_ID 0 0
|
||||
200 0 ID 0 0
|
||||
200 0 H 4.40607e-14 7.90085e-16
|
||||
200 0 O 0.26477 0.0034449
|
||||
200 0 Charge 0.0152426 0.000228736
|
||||
200 0 C 0.00106749 4.69434e-05
|
||||
200 0 Ca 0.00106988 4.71795e-05
|
||||
200 0 Cl 0.19963 0.0417236
|
||||
200 0 Mg 0.302507 0.109754
|
||||
200 0 Calcite 0.000668562 3.12626e-05
|
||||
200 0 Calcite_p1 0 0
|
||||
200 0 Dolomite 0.022869 0.0141522
|
||||
200 0 Dolomite_p1 0 0
|
||||
200 0 O2g_eq 0.723052 0.0093885
|
||||
200 0 O2g_si 0 0
|
||||
|
||||
400 1 cell_ID 0 0
|
||||
400 1 ID 0 0
|
||||
400 1 H 5.10132e-14 1.04621e-15
|
||||
400 1 O 0.0620153 0.000909136
|
||||
400 1 Charge 0.00227654 7.76102e-05
|
||||
400 1 C 0.00140883 4.26784e-05
|
||||
400 1 Ca 0.00141118 4.30019e-05
|
||||
400 1 Cl 1.98506e-10 6.90649e-12
|
||||
400 1 Mg 1.76159e-05 1.60076e-06
|
||||
400 1 Calcite 0.000905335 3.16292e-05
|
||||
400 1 Calcite_p1 0 0
|
||||
400 1 Dolomite 0.0596336 0.0492175
|
||||
400 1 Dolomite_p1 0 0
|
||||
400 1 O2g_eq 0.168173 0.00246656
|
||||
400 1 O2g_si 0 0
|
||||
|
||||
600 2 cell_ID 0 0
|
||||
600 2 ID 0 0
|
||||
600 2 H 5.0337e-14 1.03769e-15
|
||||
600 2 O 0.0321049 0.000508398
|
||||
600 2 Charge 0.000888608 3.9048e-05
|
||||
600 2 C 0.00157038 4.35036e-05
|
||||
600 2 Ca 0.00157147 4.36029e-05
|
||||
600 2 Cl 2.03573e-10 7.1497e-12
|
||||
600 2 Mg 1.78228e-05 1.51293e-06
|
||||
600 2 Calcite 0.00110004 5.90231e-05
|
||||
600 2 Calcite_p1 0 0
|
||||
600 2 Dolomite 0.0444966 0.0200246
|
||||
600 2 Dolomite_p1 0 0
|
||||
600 2 O2g_eq 0.0867418 0.00138316
|
||||
600 2 O2g_si 0 0
|
||||
|
||||
800 3 cell_ID 0 0
|
||||
800 3 ID 0 0
|
||||
800 3 H 5.07032e-14 1.07836e-15
|
||||
800 3 O 0.0304553 0.000543198
|
||||
800 3 Charge 0.000987327 4.5855e-05
|
||||
800 3 C 0.00189037 5.46494e-05
|
||||
800 3 Ca 0.00188634 5.4454e-05
|
||||
800 3 Cl 1.9489e-10 6.83318e-12
|
||||
800 3 Mg 2.04861e-05 1.45815e-06
|
||||
800 3 Calcite 0.00129733 5.02191e-05
|
||||
800 3 Calcite_p1 0 0
|
||||
800 3 Dolomite 0.0132718 0.0097894
|
||||
800 3 Dolomite_p1 0 0
|
||||
800 3 O2g_eq 0.0823463 0.00147483
|
||||
800 3 O2g_si 0 0
|
||||
|
||||
1000 4 cell_ID 0 0
|
||||
1000 4 ID 0 0
|
||||
1000 4 H 4.5926e-14 8.98972e-16
|
||||
1000 4 O 0.0346924 0.000605097
|
||||
1000 4 Charge 0.000854348 3.62669e-05
|
||||
1000 4 C 0.00165366 4.37053e-05
|
||||
1000 4 Ca 0.00164887 4.36839e-05
|
||||
1000 4 Cl 1.81984e-10 6.37135e-12
|
||||
1000 4 Mg 2.50557e-05 1.50812e-06
|
||||
1000 4 Calcite 0.0011238 4.37014e-05
|
||||
1000 4 Calcite_p1 0 0
|
||||
1000 4 Dolomite 0.111075 0.0348126
|
||||
1000 4 Dolomite_p1 0 0
|
||||
1000 4 O2g_eq 0.0937111 0.00164022
|
||||
1000 4 O2g_si 0 0
|
||||
|
||||
Binary file not shown.
@ -33,6 +33,7 @@ add_library(POETLib
|
||||
Chemistry/SurrogateModels/HashFunctions.cpp
|
||||
Chemistry/SurrogateModels/InterpolationModule.cpp
|
||||
Chemistry/SurrogateModels/ProximityHashTable.cpp
|
||||
Control/ControlModule.cpp
|
||||
)
|
||||
|
||||
set(POET_TUG_APPROACH "Implicit" CACHE STRING "tug numerical approach to use")
|
||||
|
||||
@ -4,17 +4,14 @@
|
||||
|
||||
#include "DataStructures/Field.hpp"
|
||||
#include "DataStructures/NamedVector.hpp"
|
||||
|
||||
#include "ChemistryDefs.hpp"
|
||||
|
||||
#include "Control/ControlModule.hpp"
|
||||
#include "Init/InitialList.hpp"
|
||||
#include "NameDouble.h"
|
||||
#include "SurrogateModels/DHT_Wrapper.hpp"
|
||||
#include "SurrogateModels/Interpolation.hpp"
|
||||
|
||||
#include "poet.hpp"
|
||||
|
||||
#include "PhreeqcRunner.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
@ -23,454 +20,412 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace poet
|
||||
{
|
||||
namespace poet {
|
||||
class ControlModule;
|
||||
/**
|
||||
* \brief Wrapper around PhreeqcRM to provide POET specific parallelization with
|
||||
* easy access.
|
||||
*/
|
||||
class ChemistryModule {
|
||||
public:
|
||||
/**
|
||||
* \brief Wrapper around PhreeqcRM to provide POET specific parallelization with
|
||||
* easy access.
|
||||
* Creates a new instance of Chemistry module with given grid cell count, work
|
||||
* package size and communicator.
|
||||
*
|
||||
* This constructor shall only be called by the master. To create workers, see
|
||||
* ChemistryModule::createWorker .
|
||||
*
|
||||
* When the use of parallelization is intended, the nxyz value shall be set to
|
||||
* 1 to save memory and only one node is needed for initialization.
|
||||
*
|
||||
* \param nxyz Count of grid cells to allocate and initialize for each
|
||||
* process. For parellel use set to 1 at the master.
|
||||
* \param wp_size Count of grid cells to fill each work package at maximum.
|
||||
* \param communicator MPI communicator to distribute work in.
|
||||
*/
|
||||
class ChemistryModule
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates a new instance of Chemistry module with given grid cell count, work
|
||||
* package size and communicator.
|
||||
*
|
||||
* This constructor shall only be called by the master. To create workers, see
|
||||
* ChemistryModule::createWorker .
|
||||
*
|
||||
* When the use of parallelization is intended, the nxyz value shall be set to
|
||||
* 1 to save memory and only one node is needed for initialization.
|
||||
*
|
||||
* \param nxyz Count of grid cells to allocate and initialize for each
|
||||
* process. For parellel use set to 1 at the master.
|
||||
* \param wp_size Count of grid cells to fill each work package at maximum.
|
||||
* \param communicator MPI communicator to distribute work in.
|
||||
*/
|
||||
ChemistryModule(uint32_t wp_size,
|
||||
const InitialList::ChemistryInit chem_params,
|
||||
MPI_Comm communicator);
|
||||
|
||||
/**
|
||||
* Deconstructor, which frees DHT data structure if used.
|
||||
*/
|
||||
~ChemistryModule();
|
||||
|
||||
void masterSetField(Field field);
|
||||
/**
|
||||
* Run the chemical simulation with parameters set.
|
||||
*/
|
||||
void simulate(double dt);
|
||||
|
||||
/**
|
||||
* Returns all known species names, including not only aqueous species, but
|
||||
* also equilibrium, exchange, surface and kinetic reactants.
|
||||
*/
|
||||
// auto GetPropNames() const { return this->prop_names; }
|
||||
|
||||
/**
|
||||
* Return the accumulated runtime in seconds for chemical simulation.
|
||||
*/
|
||||
auto GetChemistryTime() const { return this->chem_t; }
|
||||
|
||||
void setFilePadding(std::uint32_t maxiter)
|
||||
{
|
||||
this->file_pad =
|
||||
static_cast<std::uint8_t>(std::ceil(std::log10(maxiter + 1)));
|
||||
}
|
||||
|
||||
struct SurrogateSetup
|
||||
{
|
||||
std::vector<std::string> prop_names;
|
||||
std::array<double, 2> base_totals;
|
||||
bool has_het_ids;
|
||||
|
||||
bool dht_enabled;
|
||||
std::uint32_t dht_size_mb;
|
||||
int dht_snaps;
|
||||
std::string dht_out_dir;
|
||||
|
||||
bool interp_enabled;
|
||||
std::uint32_t interp_bucket_size;
|
||||
std::uint32_t interp_size_mb;
|
||||
std::uint32_t interp_min_entries;
|
||||
bool ai_surrogate_enabled;
|
||||
};
|
||||
|
||||
void masterEnableSurrogates(const SurrogateSetup &setup)
|
||||
{
|
||||
// FIXME: This is a hack to get the prop_names and prop_count from the setup
|
||||
this->prop_names = setup.prop_names;
|
||||
this->prop_count = setup.prop_names.size();
|
||||
|
||||
this->dht_enabled = setup.dht_enabled;
|
||||
this->interp_enabled = setup.interp_enabled;
|
||||
this->ai_surrogate_enabled = setup.ai_surrogate_enabled;
|
||||
|
||||
this->base_totals = setup.base_totals;
|
||||
|
||||
if (this->dht_enabled || this->interp_enabled)
|
||||
{
|
||||
this->initializeDHT(setup.dht_size_mb, this->params.dht_species,
|
||||
setup.has_het_ids);
|
||||
|
||||
if (setup.dht_snaps != DHT_SNAPS_DISABLED)
|
||||
{
|
||||
this->setDHTSnapshots(setup.dht_snaps, setup.dht_out_dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->interp_enabled)
|
||||
{
|
||||
this->initializeInterp(setup.interp_bucket_size, setup.interp_size_mb,
|
||||
setup.interp_min_entries,
|
||||
this->params.interp_species);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intended to alias input parameters for grid initialization with a single
|
||||
* value per species.
|
||||
*/
|
||||
using SingleCMap = std::unordered_map<std::string, double>;
|
||||
|
||||
/**
|
||||
* Intended to alias input parameters for grid initialization with mutlitple
|
||||
* values per species.
|
||||
*/
|
||||
using VectorCMap = std::unordered_map<std::string, std::vector<double>>;
|
||||
|
||||
/**
|
||||
* Enumerating DHT file options
|
||||
*/
|
||||
enum
|
||||
{
|
||||
DHT_SNAPS_DISABLED = 0, //!< disabled file output
|
||||
DHT_SNAPS_SIMEND, //!< only output of snapshot after simulation
|
||||
DHT_SNAPS_ITEREND //!< output snapshots after each iteration
|
||||
};
|
||||
|
||||
/**
|
||||
* **Only called by workers!** Start the worker listening loop.
|
||||
*/
|
||||
void WorkerLoop();
|
||||
|
||||
/**
|
||||
* **Called by master** Advise the workers to break the loop.
|
||||
*/
|
||||
void MasterLoopBreak();
|
||||
|
||||
/**
|
||||
* **Master only** Return count of grid cells.
|
||||
*/
|
||||
auto GetNCells() const { return this->n_cells; }
|
||||
/**
|
||||
* **Master only** Return work package size.
|
||||
*/
|
||||
auto GetWPSize() const { return this->wp_size; }
|
||||
/**
|
||||
* **Master only** Return the time in seconds the master spent waiting for any
|
||||
* free worker.
|
||||
*/
|
||||
auto GetMasterIdleTime() const { return this->idle_t; }
|
||||
/**
|
||||
* **Master only** Return the time in seconds the master spent in sequential
|
||||
* part of the simulation, including times for shuffling/unshuffling field
|
||||
* etc.
|
||||
*/
|
||||
auto GetMasterSequentialTime() const { return this->seq_t; }
|
||||
/**
|
||||
* **Master only** Return the time in seconds the master spent in the
|
||||
* send/receive loop.
|
||||
*/
|
||||
auto GetMasterLoopTime() const { return this->send_recv_t; }
|
||||
|
||||
|
||||
auto GetMasterCtrlLogicTime() const { return this->ctrl_t; }
|
||||
|
||||
auto GetMasterCtrlBcastTime() const { return this->bcast_ctrl_t; }
|
||||
|
||||
auto GetMasterRecvCtrlLogicTime() const { return this->recv_ctrl_t; }
|
||||
|
||||
/**
|
||||
* **Master only** Collect and return all accumulated timings recorded by
|
||||
* workers to run Phreeqc simulation.
|
||||
*
|
||||
* \return Vector of all accumulated Phreeqc timings.
|
||||
*/
|
||||
std::vector<double> GetWorkerPhreeqcTimings() const;
|
||||
/**
|
||||
* **Master only** Collect and return all accumulated timings recorded by
|
||||
* workers to get values from the DHT.
|
||||
*
|
||||
* \return Vector of all accumulated DHT get times.
|
||||
*/
|
||||
std::vector<double> GetWorkerDHTGetTimings() const;
|
||||
/**
|
||||
* **Master only** Collect and return all accumulated timings recorded by
|
||||
* workers to write values to the DHT.
|
||||
*
|
||||
* \return Vector of all accumulated DHT fill times.
|
||||
*/
|
||||
std::vector<double> GetWorkerDHTFillTimings() const;
|
||||
/**
|
||||
* **Master only** Collect and return all accumulated timings recorded by
|
||||
* workers waiting for work packages from the master.
|
||||
*
|
||||
* \return Vector of all accumulated waiting times.
|
||||
*/
|
||||
std::vector<double> GetWorkerIdleTimings() const;
|
||||
|
||||
std::vector<double> GetWorkerControlTimings() const;
|
||||
|
||||
/**
|
||||
* **Master only** Collect and return DHT hits of all workers.
|
||||
*
|
||||
* \return Vector of all count of DHT hits.
|
||||
*/
|
||||
std::vector<uint32_t> GetWorkerDHTHits() const;
|
||||
|
||||
/**
|
||||
* **Master only** Collect and return DHT evictions of all workers.
|
||||
*
|
||||
* \return Vector of all count of DHT evictions.
|
||||
*/
|
||||
std::vector<uint32_t> GetWorkerDHTEvictions() const;
|
||||
|
||||
/**
|
||||
* **Master only** Returns the current state of the chemical field.
|
||||
*
|
||||
* \return Reference to the chemical field.
|
||||
*/
|
||||
Field &getField() { return this->chem_field; }
|
||||
|
||||
/**
|
||||
* **Master only** Enable/disable progress bar.
|
||||
*
|
||||
* \param enabled True if print progressbar, false if not.
|
||||
*/
|
||||
void setProgressBarPrintout(bool enabled)
|
||||
{
|
||||
this->print_progessbar = enabled;
|
||||
};
|
||||
|
||||
/**
|
||||
* **Master only** Set the ai surrogate validity vector from R
|
||||
*/
|
||||
void set_ai_surrogate_validity_vector(std::vector<int> r_vector);
|
||||
|
||||
std::vector<uint32_t> GetWorkerInterpolationCalls() const;
|
||||
|
||||
std::vector<double> GetWorkerInterpolationWriteTimings() const;
|
||||
std::vector<double> GetWorkerInterpolationReadTimings() const;
|
||||
std::vector<double> GetWorkerInterpolationGatherTimings() const;
|
||||
std::vector<double> GetWorkerInterpolationFunctionCallTimings() const;
|
||||
|
||||
std::vector<uint32_t> GetWorkerPHTCacheHits() const;
|
||||
|
||||
std::vector<int> ai_surrogate_validity_vector;
|
||||
|
||||
RuntimeParameters *runtime_params = nullptr;
|
||||
|
||||
struct SimulationErrorStats
|
||||
{
|
||||
std::vector<double> mape;
|
||||
std::vector<double> rrmse;
|
||||
uint32_t iteration; // iterations in simulation after rollbacks
|
||||
uint32_t rollback_count;
|
||||
|
||||
SimulationErrorStats(size_t species_count, uint32_t iter, uint32_t counter)
|
||||
: mape(species_count, 0.0),
|
||||
rrmse(species_count, 0.0),
|
||||
iteration(iter),
|
||||
rollback_count(counter){}
|
||||
};
|
||||
|
||||
std::vector<SimulationErrorStats> error_history;
|
||||
|
||||
static void computeSpeciesErrors(const std::vector<double> &reference_values,
|
||||
const std::vector<double> &surrogate_values,
|
||||
uint32_t size_per_prop,
|
||||
uint32_t species_count,
|
||||
SimulationErrorStats &species_error_stats);
|
||||
|
||||
protected:
|
||||
void initializeDHT(uint32_t size_mb,
|
||||
const NamedVector<std::uint32_t> &key_species,
|
||||
bool has_het_ids);
|
||||
void setDHTSnapshots(int type, const std::string &out_dir);
|
||||
void setDHTReadFile(const std::string &input_file);
|
||||
|
||||
void initializeInterp(std::uint32_t bucket_size, std::uint32_t size_mb,
|
||||
std::uint32_t min_entries,
|
||||
const NamedVector<std::uint32_t> &key_species);
|
||||
|
||||
enum
|
||||
{
|
||||
CHEM_FIELD_INIT,
|
||||
CHEM_DHT_ENABLE,
|
||||
CHEM_DHT_SIGNIF_VEC,
|
||||
CHEM_DHT_SNAPS,
|
||||
CHEM_DHT_READ_FILE,
|
||||
CHEM_INTERP,
|
||||
CHEM_IP_ENABLE,
|
||||
CHEM_IP_MIN_ENTRIES,
|
||||
CHEM_IP_SIGNIF_VEC,
|
||||
CHEM_WORK_LOOP,
|
||||
CHEM_PERF,
|
||||
CHEM_BREAK_MAIN_LOOP,
|
||||
CHEM_AI_BCAST_VALIDITY
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
LOOP_WORK,
|
||||
LOOP_END,
|
||||
LOOP_CTRL
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
WORKER_PHREEQC,
|
||||
WORKER_CTRL_ITER,
|
||||
WORKER_DHT_GET,
|
||||
WORKER_DHT_FILL,
|
||||
WORKER_IDLE,
|
||||
WORKER_IP_WRITE,
|
||||
WORKER_IP_READ,
|
||||
WORKER_IP_GATHER,
|
||||
WORKER_IP_FC,
|
||||
WORKER_DHT_HITS,
|
||||
WORKER_DHT_EVICTIONS,
|
||||
WORKER_PHT_CACHE_HITS,
|
||||
WORKER_IP_CALLS
|
||||
};
|
||||
|
||||
std::vector<uint32_t> interp_calls;
|
||||
std::vector<uint32_t> dht_hits;
|
||||
std::vector<uint32_t> dht_evictions;
|
||||
|
||||
struct worker_s
|
||||
{
|
||||
double phreeqc_t = 0.;
|
||||
double dht_get = 0.;
|
||||
double dht_fill = 0.;
|
||||
double idle_t = 0.;
|
||||
double ctrl_t = 0.;
|
||||
};
|
||||
|
||||
struct worker_info_s
|
||||
{
|
||||
char has_work = 0;
|
||||
double *send_addr;
|
||||
double *surrogate_addr;
|
||||
};
|
||||
|
||||
using worker_list_t = std::vector<struct worker_info_s>;
|
||||
using workpointer_t = std::vector<double>::iterator;
|
||||
|
||||
void MasterRunParallel(double dt);
|
||||
void MasterRunSequential();
|
||||
|
||||
void MasterSendPkgs(worker_list_t &w_list, workpointer_t &work_pointer, workpointer_t &sur_pointer,
|
||||
int &pkg_to_send, int &count_pkgs, int &free_workers,
|
||||
double dt, uint32_t iteration, uint32_t control_iteration,
|
||||
const std::vector<uint32_t> &wp_sizes_vector);
|
||||
void MasterRecvPkgs(worker_list_t &w_list, int &pkg_to_recv, bool to_send,
|
||||
int &free_workers);
|
||||
|
||||
std::vector<double> MasterGatherWorkerTimings(int type) const;
|
||||
std::vector<uint32_t> MasterGatherWorkerMetrics(int type) const;
|
||||
|
||||
void WorkerProcessPkgs(struct worker_s &timings, uint32_t &iteration);
|
||||
|
||||
void WorkerDoWork(MPI_Status &probe_status, int double_count,
|
||||
struct worker_s &timings);
|
||||
void WorkerPostIter(MPI_Status &prope_status, uint32_t iteration);
|
||||
void WorkerPostSim(uint32_t iteration);
|
||||
|
||||
void WorkerWriteDHTDump(uint32_t iteration);
|
||||
void WorkerReadDHTDump(const std::string &dht_input_file);
|
||||
|
||||
void WorkerPerfToMaster(int type, const struct worker_s &timings);
|
||||
void WorkerMetricsToMaster(int type);
|
||||
|
||||
void WorkerRunWorkPackage(WorkPackage &work_package, double dSimTime,
|
||||
double dTimestep);
|
||||
|
||||
std::vector<uint32_t> CalculateWPSizesVector(uint32_t n_cells,
|
||||
uint32_t wp_size) const;
|
||||
std::vector<double> shuffleField(const std::vector<double> &in_field,
|
||||
uint32_t size_per_prop, uint32_t prop_count,
|
||||
uint32_t wp_count);
|
||||
void unshuffleField(const std::vector<double> &in_buffer,
|
||||
uint32_t size_per_prop, uint32_t prop_count,
|
||||
uint32_t wp_count, std::vector<double> &out_field);
|
||||
std::vector<std::int32_t>
|
||||
parseDHTSpeciesVec(const NamedVector<std::uint32_t> &key_species,
|
||||
const std::vector<std::string> &to_compare) const;
|
||||
|
||||
void BCastStringVec(std::vector<std::string> &io);
|
||||
|
||||
int comm_size, comm_rank;
|
||||
MPI_Comm group_comm;
|
||||
|
||||
bool is_sequential;
|
||||
bool is_master;
|
||||
|
||||
uint32_t wp_size;
|
||||
bool dht_enabled{false};
|
||||
int dht_snaps_type{DHT_SNAPS_DISABLED};
|
||||
std::string dht_file_out_dir;
|
||||
|
||||
poet::DHT_Wrapper *dht = nullptr;
|
||||
|
||||
bool dht_fill_during_rollback{false};
|
||||
bool interp_enabled{false};
|
||||
std::unique_ptr<poet::InterpolationModule> interp;
|
||||
|
||||
bool ai_surrogate_enabled{false};
|
||||
|
||||
static constexpr uint32_t BUFFER_OFFSET = 6;
|
||||
|
||||
inline void ChemBCast(void *buf, int count, MPI_Datatype datatype) const
|
||||
{
|
||||
MPI_Bcast(buf, count, datatype, 0, this->group_comm);
|
||||
}
|
||||
|
||||
inline void PropagateFunctionType(int &type) const
|
||||
{
|
||||
ChemBCast(&type, 1, MPI_INT);
|
||||
}
|
||||
double simtime = 0.;
|
||||
double idle_t = 0.;
|
||||
double seq_t = 0.;
|
||||
double send_recv_t = 0.;
|
||||
|
||||
double ctrl_t = 0.;
|
||||
double bcast_ctrl_t = 0.;
|
||||
double recv_ctrl_t = 0.;
|
||||
|
||||
std::array<double, 2> base_totals{0};
|
||||
|
||||
bool print_progessbar{false};
|
||||
|
||||
std::uint8_t file_pad{1};
|
||||
|
||||
double chem_t{0.};
|
||||
|
||||
uint32_t n_cells = 0;
|
||||
uint32_t prop_count = 0;
|
||||
ChemistryModule(uint32_t wp_size,
|
||||
const InitialList::ChemistryInit chem_params,
|
||||
MPI_Comm communicator);
|
||||
|
||||
/**
|
||||
* Deconstructor, which frees DHT data structure if used.
|
||||
*/
|
||||
~ChemistryModule();
|
||||
|
||||
void masterSetField(Field field);
|
||||
/**
|
||||
* Run the chemical simulation with parameters set.
|
||||
*/
|
||||
void simulate(double dt);
|
||||
|
||||
/**
|
||||
* Returns all known species names, including not only aqueous species, but
|
||||
* also equilibrium, exchange, surface and kinetic reactants.
|
||||
*/
|
||||
// auto GetPropNames() const { return this->prop_names; }
|
||||
|
||||
/**
|
||||
* Return the accumulated runtime in seconds for chemical simulation.
|
||||
*/
|
||||
auto GetChemistryTime() const { return this->chem_t; }
|
||||
|
||||
void setFilePadding(std::uint32_t maxiter) {
|
||||
this->file_pad =
|
||||
static_cast<std::uint8_t>(std::ceil(std::log10(maxiter + 1)));
|
||||
}
|
||||
|
||||
struct SurrogateSetup {
|
||||
std::vector<std::string> prop_names;
|
||||
std::array<double, 2> base_totals;
|
||||
bool has_het_ids;
|
||||
|
||||
Field chem_field;
|
||||
bool dht_enabled;
|
||||
std::uint32_t dht_size_mb;
|
||||
int dht_snaps;
|
||||
std::string dht_out_dir;
|
||||
|
||||
const InitialList::ChemistryInit params;
|
||||
|
||||
std::unique_ptr<PhreeqcRunner> pqc_runner;
|
||||
|
||||
std::vector<double> sur_shuffled;
|
||||
bool interp_enabled;
|
||||
std::uint32_t interp_bucket_size;
|
||||
std::uint32_t interp_size_mb;
|
||||
std::uint32_t interp_min_entries;
|
||||
bool ai_surrogate_enabled;
|
||||
};
|
||||
|
||||
void masterEnableSurrogates(const SurrogateSetup &setup) {
|
||||
// FIXME: This is a hack to get the prop_names and prop_count from the setup
|
||||
this->prop_names = setup.prop_names;
|
||||
this->prop_count = setup.prop_names.size();
|
||||
|
||||
this->dht_enabled = setup.dht_enabled;
|
||||
this->interp_enabled = setup.interp_enabled;
|
||||
this->ai_surrogate_enabled = setup.ai_surrogate_enabled;
|
||||
|
||||
this->base_totals = setup.base_totals;
|
||||
|
||||
if (this->dht_enabled || this->interp_enabled) {
|
||||
this->initializeDHT(setup.dht_size_mb, this->params.dht_species,
|
||||
setup.has_het_ids);
|
||||
|
||||
if (setup.dht_snaps != DHT_SNAPS_DISABLED) {
|
||||
this->setDHTSnapshots(setup.dht_snaps, setup.dht_out_dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->interp_enabled) {
|
||||
this->initializeInterp(setup.interp_bucket_size, setup.interp_size_mb,
|
||||
setup.interp_min_entries,
|
||||
this->params.interp_species);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intended to alias input parameters for grid initialization with a single
|
||||
* value per species.
|
||||
*/
|
||||
using SingleCMap = std::unordered_map<std::string, double>;
|
||||
|
||||
/**
|
||||
* Intended to alias input parameters for grid initialization with mutlitple
|
||||
* values per species.
|
||||
*/
|
||||
using VectorCMap = std::unordered_map<std::string, std::vector<double>>;
|
||||
|
||||
/**
|
||||
* Enumerating DHT file options
|
||||
*/
|
||||
enum {
|
||||
DHT_SNAPS_DISABLED = 0, //!< disabled file output
|
||||
DHT_SNAPS_SIMEND, //!< only output of snapshot after simulation
|
||||
DHT_SNAPS_ITEREND //!< output snapshots after each iteration
|
||||
};
|
||||
|
||||
/**
|
||||
* **Only called by workers!** Start the worker listening loop.
|
||||
*/
|
||||
void WorkerLoop();
|
||||
|
||||
/**
|
||||
* **Called by master** Advise the workers to break the loop.
|
||||
*/
|
||||
void MasterLoopBreak();
|
||||
|
||||
/**
|
||||
* **Master only** Return count of grid cells.
|
||||
*/
|
||||
auto GetNCells() const { return this->n_cells; }
|
||||
/**
|
||||
* **Master only** Return work package size.
|
||||
*/
|
||||
auto GetWPSize() const { return this->wp_size; }
|
||||
/**
|
||||
* **Master only** Return the time in seconds the master spent waiting for any
|
||||
* free worker.
|
||||
*/
|
||||
auto GetMasterIdleTime() const { return this->idle_t; }
|
||||
/**
|
||||
* **Master only** Return the time in seconds the master spent in sequential
|
||||
* part of the simulation, including times for shuffling/unshuffling field
|
||||
* etc.
|
||||
*/
|
||||
auto GetMasterSequentialTime() const { return this->seq_t; }
|
||||
/**
|
||||
* **Master only** Return the time in seconds the master spent in the
|
||||
* send/receive loop.
|
||||
*/
|
||||
auto GetMasterLoopTime() const { return this->send_recv_t; }
|
||||
|
||||
auto GetMasterCtrlLogicTime() const { return this->ctrl_t; }
|
||||
|
||||
auto GetMasterCtrlBcastTime() const { return this->bcast_ctrl_t; }
|
||||
|
||||
auto GetMasterRecvCtrlLogicTime() const { return this->recv_ctrl_t; }
|
||||
|
||||
/**
|
||||
* **Master only** Collect and return all accumulated timings recorded by
|
||||
* workers to run Phreeqc simulation.
|
||||
*
|
||||
* \return Vector of all accumulated Phreeqc timings.
|
||||
*/
|
||||
std::vector<double> GetWorkerPhreeqcTimings() const;
|
||||
/**
|
||||
* **Master only** Collect and return all accumulated timings recorded by
|
||||
* workers to get values from the DHT.
|
||||
*
|
||||
* \return Vector of all accumulated DHT get times.
|
||||
*/
|
||||
std::vector<double> GetWorkerDHTGetTimings() const;
|
||||
/**
|
||||
* **Master only** Collect and return all accumulated timings recorded by
|
||||
* workers to write values to the DHT.
|
||||
*
|
||||
* \return Vector of all accumulated DHT fill times.
|
||||
*/
|
||||
std::vector<double> GetWorkerDHTFillTimings() const;
|
||||
/**
|
||||
* **Master only** Collect and return all accumulated timings recorded by
|
||||
* workers waiting for work packages from the master.
|
||||
*
|
||||
* \return Vector of all accumulated waiting times.
|
||||
*/
|
||||
std::vector<double> GetWorkerIdleTimings() const;
|
||||
|
||||
std::vector<double> GetWorkerControlTimings() const;
|
||||
|
||||
/**
|
||||
* **Master only** Collect and return DHT hits of all workers.
|
||||
*
|
||||
* \return Vector of all count of DHT hits.
|
||||
*/
|
||||
std::vector<uint32_t> GetWorkerDHTHits() const;
|
||||
|
||||
/**
|
||||
* **Master only** Collect and return DHT evictions of all workers.
|
||||
*
|
||||
* \return Vector of all count of DHT evictions.
|
||||
*/
|
||||
std::vector<uint32_t> GetWorkerDHTEvictions() const;
|
||||
|
||||
/**
|
||||
* **Master only** Returns the current state of the chemical field.
|
||||
*
|
||||
* \return Reference to the chemical field.
|
||||
*/
|
||||
Field &getField() { return this->chem_field; }
|
||||
|
||||
/**
|
||||
* **Master only** Enable/disable progress bar.
|
||||
*
|
||||
* \param enabled True if print progressbar, false if not.
|
||||
*/
|
||||
void setProgressBarPrintout(bool enabled) {
|
||||
this->print_progessbar = enabled;
|
||||
};
|
||||
|
||||
/**
|
||||
* **Master only** Set the ai surrogate validity vector from R
|
||||
*/
|
||||
void set_ai_surrogate_validity_vector(std::vector<int> r_vector);
|
||||
|
||||
std::vector<uint32_t> GetWorkerInterpolationCalls() const;
|
||||
|
||||
std::vector<double> GetWorkerInterpolationWriteTimings() const;
|
||||
std::vector<double> GetWorkerInterpolationReadTimings() const;
|
||||
std::vector<double> GetWorkerInterpolationGatherTimings() const;
|
||||
std::vector<double> GetWorkerInterpolationFunctionCallTimings() const;
|
||||
|
||||
std::vector<uint32_t> GetWorkerPHTCacheHits() const;
|
||||
|
||||
std::vector<int> ai_surrogate_validity_vector;
|
||||
|
||||
protected:
|
||||
void initializeDHT(uint32_t size_mb,
|
||||
const NamedVector<std::uint32_t> &key_species,
|
||||
bool has_het_ids);
|
||||
void setDHTSnapshots(int type, const std::string &out_dir);
|
||||
void setDHTReadFile(const std::string &input_file);
|
||||
|
||||
void initializeInterp(std::uint32_t bucket_size, std::uint32_t size_mb,
|
||||
std::uint32_t min_entries,
|
||||
const NamedVector<std::uint32_t> &key_species);
|
||||
|
||||
enum {
|
||||
CHEM_FIELD_INIT,
|
||||
CHEM_DHT_ENABLE,
|
||||
CHEM_DHT_SIGNIF_VEC,
|
||||
CHEM_DHT_SNAPS,
|
||||
CHEM_DHT_READ_FILE,
|
||||
CHEM_IP, // Control Flag
|
||||
CHEM_IP_ENABLE,
|
||||
CHEM_IP_MIN_ENTRIES,
|
||||
CHEM_IP_SIGNIF_VEC,
|
||||
CHEM_WORK_LOOP,
|
||||
CHEM_PERF,
|
||||
CHEM_BREAK_MAIN_LOOP,
|
||||
CHEM_AI_BCAST_VALIDITY
|
||||
};
|
||||
|
||||
enum { LOOP_WORK, LOOP_END, LOOP_CTRL };
|
||||
|
||||
enum {
|
||||
WORKER_PHREEQC,
|
||||
WORKER_CTRL_ITER,
|
||||
WORKER_DHT_GET,
|
||||
WORKER_DHT_FILL,
|
||||
WORKER_IDLE,
|
||||
WORKER_IP_WRITE,
|
||||
WORKER_IP_READ,
|
||||
WORKER_IP_GATHER,
|
||||
WORKER_IP_FC,
|
||||
WORKER_DHT_HITS,
|
||||
WORKER_DHT_EVICTIONS,
|
||||
WORKER_PHT_CACHE_HITS,
|
||||
WORKER_IP_CALLS
|
||||
};
|
||||
|
||||
std::vector<uint32_t> interp_calls;
|
||||
std::vector<uint32_t> dht_hits;
|
||||
std::vector<uint32_t> dht_evictions;
|
||||
|
||||
struct worker_s {
|
||||
double phreeqc_t = 0.;
|
||||
double dht_get = 0.;
|
||||
double dht_fill = 0.;
|
||||
double idle_t = 0.;
|
||||
double ctrl_t = 0.;
|
||||
};
|
||||
|
||||
struct worker_info_s {
|
||||
char has_work = 0;
|
||||
double *send_addr;
|
||||
double *surrogate_addr;
|
||||
};
|
||||
|
||||
using worker_list_t = std::vector<struct worker_info_s>;
|
||||
using workpointer_t = std::vector<double>::iterator;
|
||||
|
||||
void MasterRunParallel(double dt);
|
||||
void MasterRunSequential();
|
||||
|
||||
void MasterSendPkgs(worker_list_t &w_list, workpointer_t &work_pointer,
|
||||
workpointer_t &sur_pointer, int &pkg_to_send,
|
||||
int &count_pkgs, int &free_workers, double dt,
|
||||
uint32_t iteration, uint32_t control_iteration,
|
||||
const std::vector<uint32_t> &wp_sizes_vector);
|
||||
void MasterRecvPkgs(worker_list_t &w_list, int &pkg_to_recv, bool to_send,
|
||||
int &free_workers);
|
||||
|
||||
std::vector<double> MasterGatherWorkerTimings(int type) const;
|
||||
std::vector<uint32_t> MasterGatherWorkerMetrics(int type) const;
|
||||
|
||||
void WorkerProcessPkgs(struct worker_s &timings, uint32_t &iteration);
|
||||
|
||||
void WorkerDoWork(MPI_Status &probe_status, int double_count,
|
||||
struct worker_s &timings);
|
||||
void WorkerPostIter(MPI_Status &prope_status, uint32_t iteration);
|
||||
void WorkerPostSim(uint32_t iteration);
|
||||
|
||||
void WorkerWriteDHTDump(uint32_t iteration);
|
||||
void WorkerReadDHTDump(const std::string &dht_input_file);
|
||||
|
||||
void WorkerPerfToMaster(int type, const struct worker_s &timings);
|
||||
void WorkerMetricsToMaster(int type);
|
||||
|
||||
void WorkerRunWorkPackage(WorkPackage &work_package, double dSimTime,
|
||||
double dTimestep);
|
||||
|
||||
std::vector<uint32_t> CalculateWPSizesVector(uint32_t n_cells,
|
||||
uint32_t wp_size) const;
|
||||
std::vector<double> shuffleField(const std::vector<double> &in_field,
|
||||
uint32_t size_per_prop, uint32_t prop_count,
|
||||
uint32_t wp_count);
|
||||
void unshuffleField(const std::vector<double> &in_buffer,
|
||||
uint32_t size_per_prop, uint32_t prop_count,
|
||||
uint32_t wp_count, std::vector<double> &out_field);
|
||||
std::vector<std::int32_t>
|
||||
parseDHTSpeciesVec(const NamedVector<std::uint32_t> &key_species,
|
||||
const std::vector<std::string> &to_compare) const;
|
||||
|
||||
void BCastStringVec(std::vector<std::string> &io);
|
||||
|
||||
int comm_size, comm_rank;
|
||||
MPI_Comm group_comm;
|
||||
|
||||
bool is_sequential;
|
||||
bool is_master;
|
||||
|
||||
uint32_t wp_size;
|
||||
bool dht_enabled{false};
|
||||
int dht_snaps_type{DHT_SNAPS_DISABLED};
|
||||
std::string dht_file_out_dir;
|
||||
|
||||
poet::DHT_Wrapper *dht = nullptr;
|
||||
|
||||
bool dht_fill_during_rollback{false};
|
||||
bool interp_enabled{false};
|
||||
std::unique_ptr<poet::InterpolationModule> interp;
|
||||
|
||||
bool ai_surrogate_enabled{false};
|
||||
|
||||
static constexpr uint32_t BUFFER_OFFSET = 6;
|
||||
|
||||
inline void ChemBCast(void *buf, int count, MPI_Datatype datatype) const {
|
||||
MPI_Bcast(buf, count, datatype, 0, this->group_comm);
|
||||
}
|
||||
|
||||
inline void PropagateFunctionType(int &type) const {
|
||||
ChemBCast(&type, 1, MPI_INT);
|
||||
}
|
||||
double simtime = 0.;
|
||||
double idle_t = 0.;
|
||||
double seq_t = 0.;
|
||||
double send_recv_t = 0.;
|
||||
|
||||
double ctrl_t = 0.;
|
||||
double bcast_ctrl_t = 0.;
|
||||
double recv_ctrl_t = 0.;
|
||||
|
||||
std::array<double, 2> base_totals{0};
|
||||
|
||||
bool print_progessbar{false};
|
||||
|
||||
std::uint8_t file_pad{1};
|
||||
|
||||
double chem_t{0.};
|
||||
|
||||
uint32_t n_cells = 0;
|
||||
uint32_t prop_count = 0;
|
||||
std::vector<std::string> prop_names;
|
||||
|
||||
Field chem_field;
|
||||
|
||||
const InitialList::ChemistryInit params;
|
||||
|
||||
std::unique_ptr<PhreeqcRunner> pqc_runner;
|
||||
|
||||
std::unique_ptr<poet::ControlModule> ctrl_module;
|
||||
|
||||
//std::vector<double> sur_shuffled;
|
||||
};
|
||||
} // namespace poet
|
||||
|
||||
#endif // CHEMISTRYMODULE_H_
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <mpi.h>
|
||||
#include <vector>
|
||||
|
||||
@ -166,39 +165,6 @@ std::vector<uint32_t> poet::ChemistryModule::GetWorkerPHTCacheHits() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void poet::ChemistryModule::computeSpeciesErrors(const std::vector<double> &reference_values,
|
||||
const std::vector<double> &surrogate_values,
|
||||
uint32_t size_per_prop,
|
||||
uint32_t species_count,
|
||||
SimulationErrorStats &species_error_stats) {
|
||||
for (uint32_t i = 0; i < species_count; ++i) {
|
||||
double err_sum = 0.0;
|
||||
double sqr_err_sum = 0.0;
|
||||
uint32_t base_idx = i * size_per_prop;
|
||||
|
||||
for (uint32_t j = 0; j < size_per_prop; ++j) {
|
||||
const double ref_value = reference_values[base_idx + j];
|
||||
const double sur_value = surrogate_values[base_idx + j];
|
||||
|
||||
if (ref_value == 0.0) {
|
||||
if (sur_value != 0.0) {
|
||||
err_sum += 1.0;
|
||||
sqr_err_sum += 1.0;
|
||||
}
|
||||
// Both zero: skip
|
||||
} else {
|
||||
double alpha = 1.0 - (sur_value / ref_value);
|
||||
err_sum += std::abs(alpha);
|
||||
sqr_err_sum += alpha * alpha;
|
||||
}
|
||||
}
|
||||
|
||||
species_error_stats.mape[i] = 100.0 * (err_sum / size_per_prop);
|
||||
species_error_stats.rrmse[i] =
|
||||
(size_per_prop > 0) ? std::sqrt(sqr_err_sum / size_per_prop) : 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::vector<int> shuffleVector(const std::vector<int> &in_vector,
|
||||
uint32_t size_per_prop,
|
||||
uint32_t wp_count) {
|
||||
@ -269,8 +235,8 @@ inline void printProgressbar(int count_pkgs, int n_wp, int barWidth = 70) {
|
||||
inline void poet::ChemistryModule::MasterSendPkgs(
|
||||
worker_list_t &w_list, workpointer_t &work_pointer,
|
||||
workpointer_t &sur_pointer, int &pkg_to_send, int &count_pkgs,
|
||||
int &free_workers, double dt, uint32_t iteration,
|
||||
uint32_t control_interval, const std::vector<uint32_t> &wp_sizes_vector) {
|
||||
int &free_workers, double dt, uint32_t iteration, uint32_t control_interval,
|
||||
const std::vector<uint32_t> &wp_sizes_vector) {
|
||||
/* declare variables */
|
||||
int local_work_package_size;
|
||||
|
||||
@ -335,7 +301,7 @@ inline void poet::ChemistryModule::MasterRecvPkgs(worker_list_t &w_list,
|
||||
int need_to_receive = 1;
|
||||
double idle_a, idle_b;
|
||||
int p, size;
|
||||
double recv_a, recv_b;
|
||||
double recv_a, recv_b;
|
||||
|
||||
MPI_Status probe_status;
|
||||
// master_recv_a = MPI_Wtime();
|
||||
@ -461,28 +427,9 @@ void poet::ChemistryModule::MasterRunParallel(double dt) {
|
||||
|
||||
/* start time measurement of broadcasting interpolation status */
|
||||
ctrl_bcast_a = MPI_Wtime();
|
||||
|
||||
ftype = CHEM_INTERP;
|
||||
ftype = CHEM_IP;
|
||||
PropagateFunctionType(ftype);
|
||||
|
||||
int interp_flag = 0;
|
||||
int dht_fill_flag = 0;
|
||||
|
||||
if(this->runtime_params->rollback_enabled){
|
||||
this->interp_enabled = false;
|
||||
this->dht_fill_during_rollback = true;
|
||||
interp_flag = 0;
|
||||
dht_fill_flag = 1;
|
||||
}
|
||||
else {
|
||||
this->interp_enabled = true;
|
||||
this->dht_fill_during_rollback = false;
|
||||
interp_flag = 1;
|
||||
dht_fill_flag = 0;
|
||||
}
|
||||
ChemBCast(&interp_flag, 1, MPI_INT);
|
||||
ChemBCast(&dht_fill_flag, 1, MPI_INT);
|
||||
|
||||
ctrl_module->BCastControlFlags();
|
||||
/* end time measurement of broadcasting interpolation status */
|
||||
ctrl_bcast_b = MPI_Wtime();
|
||||
this->bcast_ctrl_t += ctrl_bcast_b - ctrl_bcast_a;
|
||||
@ -494,11 +441,12 @@ void poet::ChemistryModule::MasterRunParallel(double dt) {
|
||||
|
||||
static uint32_t iteration = 0;
|
||||
|
||||
uint32_t control_logic_enabled = this->runtime_params->control_interval_enabled ? 1 : 0;
|
||||
uint32_t control_logic_enabled =
|
||||
ctrl_module->control_interval_enabled ? 1 : 0;
|
||||
|
||||
if (control_logic_enabled) {
|
||||
sur_shuffled.clear();
|
||||
sur_shuffled.reserve(this->n_cells * this->prop_count);
|
||||
ctrl_module->sur_shuffled.clear();
|
||||
ctrl_module->sur_shuffled.reserve(this->n_cells * this->prop_count);
|
||||
}
|
||||
|
||||
/* start time measurement of sequential part */
|
||||
@ -511,14 +459,14 @@ void poet::ChemistryModule::MasterRunParallel(double dt) {
|
||||
shuffleField(chem_field.AsVector(), this->n_cells, this->prop_count,
|
||||
wp_sizes_vector.size());
|
||||
|
||||
this->sur_shuffled.resize(mpi_buffer.size());
|
||||
ctrl_module->sur_shuffled.resize(mpi_buffer.size());
|
||||
|
||||
/* setup local variables */
|
||||
pkg_to_send = wp_sizes_vector.size();
|
||||
pkg_to_recv = wp_sizes_vector.size();
|
||||
|
||||
workpointer_t work_pointer = mpi_buffer.begin();
|
||||
workpointer_t sur_pointer = sur_shuffled.begin();
|
||||
workpointer_t sur_pointer = ctrl_module->sur_shuffled.begin();
|
||||
worker_list_t worker_list(this->comm_size - 1);
|
||||
|
||||
free_workers = this->comm_size - 1;
|
||||
@ -552,43 +500,37 @@ void poet::ChemistryModule::MasterRunParallel(double dt) {
|
||||
// Just to complete the progressbar
|
||||
std::cout << std::endl;
|
||||
|
||||
/* stop time measurement of chemistry time needed for send/recv loop */
|
||||
worker_chemistry_b = MPI_Wtime();
|
||||
this->send_recv_t += worker_chemistry_b - worker_chemistry_a;
|
||||
/* stop time measurement of chemistry time needed for send/recv loop */
|
||||
worker_chemistry_b = MPI_Wtime();
|
||||
this->send_recv_t += worker_chemistry_b - worker_chemistry_a;
|
||||
|
||||
/* start time measurement of sequential part */
|
||||
seq_c = MPI_Wtime();
|
||||
/* start time measurement of sequential part */
|
||||
seq_c = MPI_Wtime();
|
||||
|
||||
/* unshuffle grid */
|
||||
// grid.importAndUnshuffle(mpi_buffer);
|
||||
std::vector<double> out_vec{mpi_buffer};
|
||||
unshuffleField(mpi_buffer, this->n_cells, this->prop_count,
|
||||
wp_sizes_vector.size(), out_vec);
|
||||
chem_field = out_vec;
|
||||
/* unshuffle grid */
|
||||
// grid.importAndUnshuffle(mpi_buffer);
|
||||
std::vector<double> out_vec{mpi_buffer};
|
||||
unshuffleField(mpi_buffer, this->n_cells, this->prop_count,
|
||||
wp_sizes_vector.size(), out_vec);
|
||||
chem_field = out_vec;
|
||||
|
||||
/* do master stuff */
|
||||
/* do master stuff */
|
||||
|
||||
/* start time measurement of control logic */
|
||||
ctrl_a = MPI_Wtime();
|
||||
/* start time measurement of control logic */
|
||||
ctrl_a = MPI_Wtime();
|
||||
|
||||
if (control_logic_enabled && !this->runtime_params->rollback_enabled) {
|
||||
if (control_logic_enabled && !ctrl_module->rollback_enabled) {
|
||||
std::cout << "[Master] Control logic enabled for this iteration." << std::endl;
|
||||
std::vector<double> sur_unshuffled{ctrl_module->sur_shuffled};
|
||||
unshuffleField(ctrl_module->sur_shuffled, this->n_cells, this->prop_count,
|
||||
wp_sizes_vector.size(), sur_unshuffled);
|
||||
|
||||
std::vector<double> sur_unshuffled{sur_shuffled};;
|
||||
|
||||
unshuffleField(sur_shuffled, this->n_cells, this->prop_count,
|
||||
wp_sizes_vector.size(), sur_unshuffled);
|
||||
|
||||
SimulationErrorStats stats(this->prop_count, this->runtime_params->global_iter, this->runtime_params->rollback_counter);
|
||||
|
||||
computeSpeciesErrors(out_vec, sur_unshuffled, this->n_cells, this->prop_count, stats);
|
||||
|
||||
error_history.push_back(stats);
|
||||
}
|
||||
|
||||
/* end time measurement of control logic */
|
||||
ctrl_b = MPI_Wtime();
|
||||
this->ctrl_t += ctrl_b - ctrl_a;
|
||||
ctrl_module->computeSpeciesErrors(out_vec, sur_unshuffled, this->n_cells);
|
||||
}
|
||||
|
||||
/* end time measurement of control logic */
|
||||
ctrl_b = MPI_Wtime();
|
||||
this->ctrl_t += ctrl_b - ctrl_a;
|
||||
|
||||
/* start time measurement of master chemistry */
|
||||
sim_e_chemistry = MPI_Wtime();
|
||||
|
||||
@ -67,7 +67,7 @@ namespace poet
|
||||
MPI_INT, 0, this->group_comm);
|
||||
break;
|
||||
}
|
||||
case CHEM_INTERP:
|
||||
case CHEM_IP:
|
||||
{
|
||||
int interp_flag = 0;
|
||||
int dht_fill_flag = 0;
|
||||
|
||||
131
src/Control/ControlModule.cpp
Normal file
131
src/Control/ControlModule.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
#include "ControlModule.hpp"
|
||||
#include "IO/Datatypes.hpp"
|
||||
#include "IO/HDF5Functions.hpp"
|
||||
#include "IO/StatsIO.hpp"
|
||||
#include <cmath>
|
||||
|
||||
bool poet::ControlModule::isControlIteration(uint32_t iter) {
|
||||
control_interval_enabled = (iter % control_interval == 0);
|
||||
if (control_interval_enabled) {
|
||||
MSG("[Control] Control interval triggered at iteration " +
|
||||
std::to_string(iter));
|
||||
}
|
||||
return control_interval_enabled;
|
||||
}
|
||||
|
||||
void poet::ControlModule::beginIteration() {
|
||||
if (rollback_enabled) {
|
||||
if (sur_disabled_counter > 0) {
|
||||
sur_disabled_counter--;
|
||||
MSG("Rollback counter: " + std::to_string(sur_disabled_counter));
|
||||
} else {
|
||||
rollback_enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void poet::ControlModule::endIteration(uint32_t iter) {
|
||||
/* Writing a checkpointing */
|
||||
if (checkpoint_interval > 0 && iter % checkpoint_interval == 0) {
|
||||
MSG("Writing checkpoint of iteration " + std::to_string(iter));
|
||||
write_checkpoint(out_dir, "checkpoint" + std::to_string(iter) + ".hdf5",
|
||||
{.field = chem->getField(), .iteration = iter});
|
||||
}
|
||||
|
||||
/* Control Logic*/
|
||||
if (control_interval_enabled && !rollback_enabled) {
|
||||
writeStatsToCSV(error_history, species_names, out_dir,
|
||||
"stats_overview");
|
||||
|
||||
if (triggerRollbackIfExceeded(*chem, *params, iter)) {
|
||||
rollback_enabled = true;
|
||||
rollback_counter++;
|
||||
sur_disabled_counter = control_interval;
|
||||
MSG("Interpolation disabled for the next " +
|
||||
std::to_string(control_interval) + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void poet::ControlModule::BCastControlFlags() {
|
||||
int interp_flag = rollback_enabled ? 0 : 1;
|
||||
int dht_fill_flag = rollback_enabled ? 1 : 0;
|
||||
chem->ChemBCast(&interp_flag, 1, MPI_INT);
|
||||
chem->ChemBCast(&dht_fill_flag, 1, MPI_INT);
|
||||
}
|
||||
|
||||
bool poet::ControlModule::triggerRollbackIfExceeded(ChemistryModule &chem,
|
||||
RuntimeParameters ¶ms,
|
||||
uint32_t &iter) {
|
||||
|
||||
if (error_history.empty()) {
|
||||
MSG("No error history yet; skipping rollback check.");
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &mape = chem.error_history.back().mape;
|
||||
const auto &props = chem.getField().GetProps();
|
||||
|
||||
for (uint32_t i = 0; i < params.mape_threshold.size(); ++i) {
|
||||
// Skip invalid entries
|
||||
if (mape[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
bool mape_exceeded = mape[i] > params.mape_threshold[i];
|
||||
|
||||
if (mape_exceeded) {
|
||||
uint32_t rollback_iter = ((iter - 1) / params.checkpoint_interval) *
|
||||
params.checkpoint_interval;
|
||||
|
||||
MSG("[THRESHOLD EXCEEDED] " + props[i] +
|
||||
" has MAPE = " + std::to_string(mape[i]) +
|
||||
" exceeding threshold = " + std::to_string(params.mape_threshold[i]) +
|
||||
" → rolling back to iteration " + std::to_string(rollback_iter));
|
||||
|
||||
Checkpoint_s checkpoint_read{.field = chem.getField()};
|
||||
read_checkpoint(params.out_dir,
|
||||
"checkpoint" + std::to_string(rollback_iter) + ".hdf5",
|
||||
checkpoint_read);
|
||||
iter = checkpoint_read.iteration;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MSG("All species are within their MAPE and RRMSE thresholds.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void poet::ControlModule::computeSpeciesErrors(
|
||||
const std::vector<double> &reference_values,
|
||||
const std::vector<double> &surrogate_values, uint32_t size_per_prop) {
|
||||
|
||||
SimulationErrorStats species_error_stats(species_count, params->global_iter,
|
||||
rollback_counter);
|
||||
|
||||
for (uint32_t i = 0; i < species_count; ++i) {
|
||||
double err_sum = 0.0;
|
||||
double sqr_err_sum = 0.0;
|
||||
uint32_t base_idx = i * size_per_prop;
|
||||
|
||||
for (uint32_t j = 0; j < size_per_prop; ++j) {
|
||||
const double ref_value = reference_values[base_idx + j];
|
||||
const double sur_value = surrogate_values[base_idx + j];
|
||||
|
||||
if (ref_value == 0.0) {
|
||||
if (sur_value != 0.0) {
|
||||
err_sum += 1.0;
|
||||
sqr_err_sum += 1.0;
|
||||
}
|
||||
// Both zero: skip
|
||||
} else {
|
||||
double alpha = 1.0 - (sur_value / ref_value);
|
||||
err_sum += std::abs(alpha);
|
||||
sqr_err_sum += alpha * alpha;
|
||||
}
|
||||
}
|
||||
|
||||
species_error_stats.mape[i] = 100.0 * (err_sum / size_per_prop);
|
||||
species_error_stats.rrmse[i] =
|
||||
(size_per_prop > 0) ? std::sqrt(sqr_err_sum / size_per_prop) : 0.0;
|
||||
}
|
||||
error_history.push_back(species_error_stats);
|
||||
}
|
||||
110
src/Control/ControlModule.hpp
Normal file
110
src/Control/ControlModule.hpp
Normal file
@ -0,0 +1,110 @@
|
||||
#ifndef CONTROLMODULE_H_
|
||||
#define CONTROLMODULE_H_
|
||||
|
||||
#include "Base/Macros.hpp"
|
||||
#include "Chemistry/ChemistryModule.hpp"
|
||||
#include "poet.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace poet {
|
||||
|
||||
class ChemistryModule;
|
||||
|
||||
class ControlModule {
|
||||
|
||||
public:
|
||||
ControlModule(RuntimeParameters *run_params, ChemistryModule *chem_module)
|
||||
: params(run_params), chem(chem_module) {};
|
||||
|
||||
/* Control configuration*/
|
||||
std::vector<std::string> species_names;
|
||||
uint32_t species_count = 0;
|
||||
std::string out_dir;
|
||||
|
||||
bool rollback_enabled = false;
|
||||
bool control_interval_enabled = false;
|
||||
|
||||
std::uint32_t global_iter = 0;
|
||||
std::uint32_t sur_disabled_counter = 0;
|
||||
std::uint32_t rollback_counter = 0;
|
||||
std::uint32_t checkpoint_interval = 0;
|
||||
std::uint32_t control_interval = 0;
|
||||
|
||||
std::vector<double> mape_threshold;
|
||||
std::vector<double> rrmse_threshold;
|
||||
|
||||
double ctrl_t = 0.;
|
||||
double bcast_ctrl_t = 0.;
|
||||
double recv_ctrl_t = 0.;
|
||||
|
||||
/* Buffer for shuffled surrogate data */
|
||||
std::vector<double> sur_shuffled;
|
||||
|
||||
bool isControlIteration(uint32_t iter);
|
||||
|
||||
void beginIteration();
|
||||
|
||||
void endIteration(uint32_t iter);
|
||||
|
||||
void BCastControlFlags();
|
||||
|
||||
bool triggerRollbackIfExceeded(ChemistryModule &chem,
|
||||
RuntimeParameters ¶ms, uint32_t &iter);
|
||||
|
||||
struct SimulationErrorStats {
|
||||
std::vector<double> mape;
|
||||
std::vector<double> rrmse;
|
||||
uint32_t iteration; // iterations in simulation after rollbacks
|
||||
uint32_t rollback_count;
|
||||
|
||||
SimulationErrorStats(size_t species_count, uint32_t iter, uint32_t counter)
|
||||
: mape(species_count, 0.0), rrmse(species_count, 0.0), iteration(iter),
|
||||
rollback_count(counter) {}
|
||||
};
|
||||
|
||||
static void computeSpeciesErrors(const std::vector<double> &reference_values,
|
||||
const std::vector<double> &surrogate_values,
|
||||
uint32_t size_per_prop);
|
||||
|
||||
std::vector<SimulationErrorStats> error_history;
|
||||
|
||||
struct ControlSetup {
|
||||
std::string out_dir;
|
||||
std::uint32_t checkpoint_interval;
|
||||
std::uint32_t control_interval;
|
||||
std::uint32_t species_count;
|
||||
|
||||
std::vector<std::string> species_names;
|
||||
std::vector<double> mape_threshold;
|
||||
std::vector<double> rrmse_threshold;
|
||||
};
|
||||
|
||||
void enableControlLogic(const ControlSetup &setup) {
|
||||
out_dir = setup.out_dir;
|
||||
checkpoint_interval = setup.checkpoint_interval;
|
||||
control_interval = setup.control_interval;
|
||||
species_count = setup.species_count;
|
||||
|
||||
species_names = setup.species_names;
|
||||
mape_threshold = setup.mape_threshold;
|
||||
rrmse_threshold = setup.rrmse_threshold;
|
||||
}
|
||||
|
||||
/* Profiling getters */
|
||||
auto GetMasterCtrlLogicTime() const { return this->ctrl_t; }
|
||||
|
||||
auto GetMasterCtrlBcastTime() const { return this->bcast_ctrl_t; }
|
||||
|
||||
auto GetMasterRecvCtrlLogicTime() const { return this->recv_ctrl_t; }
|
||||
|
||||
private:
|
||||
RuntimeParameters *params;
|
||||
ChemistryModule *chem;
|
||||
};
|
||||
|
||||
} // namespace poet
|
||||
|
||||
#endif // CONTROLMODULE_H_
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
namespace poet
|
||||
{
|
||||
void writeStatsToCSV(const std::vector<ChemistryModule::SimulationErrorStats> &all_stats,
|
||||
void writeStatsToCSV(const std::vector<ControlModule::SimulationErrorStats> &all_stats,
|
||||
const std::vector<std::string> &species_names,
|
||||
const std::string &out_dir,
|
||||
const std::string &filename)
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#include <string>
|
||||
#include "Chemistry/ChemistryModule.hpp"
|
||||
#include "Control/ControlModule.hpp"
|
||||
|
||||
namespace poet
|
||||
{
|
||||
void writeStatsToCSV(const std::vector<ChemistryModule::SimulationErrorStats> &all_stats,
|
||||
void writeStatsToCSV(const std::vector<ControlModule::SimulationErrorStats> &all_stats,
|
||||
const std::vector<std::string> &species_names,
|
||||
const std::string &out_dir,
|
||||
const std::string &filename);
|
||||
|
||||
227
src/poet.cpp
227
src/poet.cpp
@ -25,10 +25,8 @@
|
||||
#include "Base/RInsidePOET.hpp"
|
||||
#include "CLI/CLI.hpp"
|
||||
#include "Chemistry/ChemistryModule.hpp"
|
||||
#include "Control/ControlManager.hpp"
|
||||
#include "DataStructures/Field.hpp"
|
||||
#include "IO/Datatypes.hpp"
|
||||
#include "IO/HDF5Functions.hpp"
|
||||
#include "IO/StatsIO.hpp"
|
||||
#include "Init/InitialList.hpp"
|
||||
#include "Transport/DiffusionModule.hpp"
|
||||
|
||||
@ -68,8 +66,7 @@ static poet::DEFunc ReadRObj_R;
|
||||
static poet::DEFunc SaveRObj_R;
|
||||
static poet::DEFunc source_R;
|
||||
|
||||
static void init_global_functions(RInside &R)
|
||||
{
|
||||
static void init_global_functions(RInside &R) {
|
||||
R.parseEval(kin_r_library);
|
||||
master_init_R = DEFunc("master_init");
|
||||
master_iteration_end_R = DEFunc("master_iteration_end");
|
||||
@ -92,15 +89,9 @@ static void init_global_functions(RInside &R)
|
||||
// R.parseEval("mysetup$state_C <- TMP");
|
||||
// }
|
||||
|
||||
enum ParseRet
|
||||
{
|
||||
PARSER_OK,
|
||||
PARSER_ERROR,
|
||||
PARSER_HELP
|
||||
};
|
||||
enum ParseRet { PARSER_OK, PARSER_ERROR, PARSER_HELP };
|
||||
|
||||
int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms)
|
||||
{
|
||||
int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms) {
|
||||
|
||||
CLI::App app{"POET - Potsdam rEactive Transport simulator"};
|
||||
|
||||
@ -182,12 +173,9 @@ int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms)
|
||||
"Output directory of the simulation")
|
||||
->required();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
app.parse(argc, argv);
|
||||
}
|
||||
catch (const CLI::ParseError &e)
|
||||
{
|
||||
} catch (const CLI::ParseError &e) {
|
||||
app.exit(e);
|
||||
return -1;
|
||||
}
|
||||
@ -199,16 +187,14 @@ int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms)
|
||||
if (params.as_qs)
|
||||
params.out_ext = "qs";
|
||||
|
||||
if (MY_RANK == 0)
|
||||
{
|
||||
if (MY_RANK == 0) {
|
||||
// MSG("Complete results storage is " + BOOL_PRINT(simparams.store_result));
|
||||
MSG("Output format/extension is " + params.out_ext);
|
||||
MSG("Work Package Size: " + std::to_string(params.work_package_size));
|
||||
MSG("DHT is " + BOOL_PRINT(params.use_dht));
|
||||
MSG("AI Surrogate is " + BOOL_PRINT(params.use_ai_surrogate));
|
||||
|
||||
if (params.use_dht)
|
||||
{
|
||||
if (params.use_dht) {
|
||||
// MSG("DHT strategy is " + std::to_string(simparams.dht_strategy));
|
||||
// MDL: these should be outdated (?)
|
||||
// MSG("DHT key default digits (ignored if 'signif_vector' is "
|
||||
@ -222,8 +208,7 @@ int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms)
|
||||
// MSG("DHT load file is " + chem_params.dht_file);
|
||||
}
|
||||
|
||||
if (params.use_interp)
|
||||
{
|
||||
if (params.use_interp) {
|
||||
MSG("PHT interpolation enabled: " + BOOL_PRINT(params.use_interp));
|
||||
MSG("PHT interp-size = " + std::to_string(params.interp_size));
|
||||
MSG("PHT interp-min = " + std::to_string(params.interp_min_entries));
|
||||
@ -251,8 +236,7 @@ int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms)
|
||||
// // log before rounding?
|
||||
// R["dht_log"] = simparams.dht_log;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
Rcpp::List init_params_(ReadRObj_R(init_file));
|
||||
params.init_params = init_params_;
|
||||
|
||||
@ -269,13 +253,11 @@ int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms)
|
||||
Rcpp::as<uint32_t>(global_rt_setup->operator[]("control_interval"));
|
||||
params.checkpoint_interval =
|
||||
Rcpp::as<uint32_t>(global_rt_setup->operator[]("checkpoint_interval"));
|
||||
params.mape_threshold =
|
||||
Rcpp::as<std::vector<double>>(global_rt_setup->operator[]("mape_threshold"));
|
||||
params.rrmse_threshold =
|
||||
Rcpp::as<std::vector<double>>(global_rt_setup->operator[]("rrmse_threshold"));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
params.mape_threshold = Rcpp::as<std::vector<double>>(
|
||||
global_rt_setup->operator[]("mape_threshold"));
|
||||
params.rrmse_threshold = Rcpp::as<std::vector<double>>(
|
||||
global_rt_setup->operator[]("rrmse_threshold"));
|
||||
} catch (const std::exception &e) {
|
||||
ERRMSG("Error while parsing R scripts: " + std::string(e.what()));
|
||||
return ParseRet::PARSER_ERROR;
|
||||
}
|
||||
@ -285,8 +267,7 @@ int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms)
|
||||
|
||||
// HACK: this is a step back as the order and also the count of fields is
|
||||
// predefined, but it will change in the future
|
||||
void call_master_iter_end(RInside &R, const Field &trans, const Field &chem)
|
||||
{
|
||||
void call_master_iter_end(RInside &R, const Field &trans, const Field &chem) {
|
||||
R["TMP"] = Rcpp::wrap(trans.AsVector());
|
||||
R["TMP_PROPS"] = Rcpp::wrap(trans.GetProps());
|
||||
R.parseEval(std::string("state_T <- setNames(data.frame(matrix(TMP, nrow=" +
|
||||
@ -303,53 +284,15 @@ void call_master_iter_end(RInside &R, const Field &trans, const Field &chem)
|
||||
*global_rt_setup = R["setup"];
|
||||
}
|
||||
|
||||
bool triggerRollbackIfExceeded(ChemistryModule &chem, RuntimeParameters ¶ms, uint32_t ¤t_iteration)
|
||||
{
|
||||
const auto &mape = chem.error_history.back().mape;
|
||||
const auto &rrmse = chem.error_history.back().rrmse;
|
||||
const auto &props = chem.getField().GetProps();
|
||||
|
||||
for (uint32_t i = 0; i < params.mape_threshold.size(); ++i)
|
||||
{
|
||||
// Skip invalid entries
|
||||
if ((mape[i] == 0 && rrmse[i] == 0))
|
||||
continue;
|
||||
|
||||
bool mape_exceeded = mape[i] > params.mape_threshold[i];
|
||||
bool rrmse_exceeded = rrmse[i] > params.rrmse_threshold[i];
|
||||
|
||||
if (mape_exceeded || rrmse_exceeded)
|
||||
{
|
||||
uint32_t rollback_iter = ((current_iteration - 1) / params.checkpoint_interval) * params.checkpoint_interval;
|
||||
std::string metric = mape_exceeded ? "MAPE" : "RRMSE";
|
||||
double value = mape_exceeded ? mape[i] : rrmse[i];
|
||||
double threshold = mape_exceeded ? params.mape_threshold[i] : params.rrmse_threshold[i];
|
||||
|
||||
MSG("[THRESHOLD EXCEEDED] " + props[i] + " has " + metric + " = " +
|
||||
std::to_string(value) + " exceeding threshold = " + std::to_string(threshold) +
|
||||
" → rolling back to iteration " + std::to_string(rollback_iter));
|
||||
|
||||
Checkpoint_s checkpoint_read{.field = chem.getField()};
|
||||
read_checkpoint(params.out_dir, "checkpoint" + std::to_string(rollback_iter) + ".hdf5", checkpoint_read);
|
||||
current_iteration = checkpoint_read.iteration;
|
||||
return true; // rollback happened
|
||||
}
|
||||
}
|
||||
MSG("All species are within their MAPE and RRMSE thresholds.");
|
||||
return false;
|
||||
}
|
||||
|
||||
static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms,
|
||||
DiffusionModule &diffusion,
|
||||
ChemistryModule &chem)
|
||||
{
|
||||
ChemistryModule &chem, ControlModule &control) {
|
||||
|
||||
/* Iteration Count is dynamic, retrieving value from R (is only needed by
|
||||
* master for the following loop) */
|
||||
uint32_t maxiter = params.timesteps.size();
|
||||
|
||||
if (params.print_progress)
|
||||
{
|
||||
if (params.print_progress) {
|
||||
chem.setProgressBarPrintout(true);
|
||||
}
|
||||
R["TMP_PROPS"] = Rcpp::wrap(chem.getField().GetProps());
|
||||
@ -359,20 +302,24 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms,
|
||||
double dSimTime{0};
|
||||
double chkTime = 0.0;
|
||||
|
||||
for (uint32_t iter = 1; iter < maxiter + 1; iter++)
|
||||
{
|
||||
for (uint32_t iter = 1; iter < maxiter + 1; iter++) {
|
||||
// Rollback countdowm
|
||||
if (params.rollback_enabled) {
|
||||
if (params.sur_disabled_counter > 0) {
|
||||
|
||||
/*
|
||||
if (params.rollback_enabled) {
|
||||
if (params.sur_disabled_counter > 0) {
|
||||
--params.sur_disabled_counter;
|
||||
MSG("Rollback counter: " + std::to_string(params.sur_disabled_counter));
|
||||
} else {
|
||||
} else {
|
||||
params.rollback_enabled = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
control.beginIteration(iter);
|
||||
|
||||
params.global_iter = iter;
|
||||
params.control_interval_enabled = (iter % params.control_interval == 0);
|
||||
// params.global_iter = iter;
|
||||
control.isControlIteration(iter);
|
||||
// params.control_interval_enabled = (iter % params.control_interval == 0);
|
||||
|
||||
double start_t = MPI_Wtime();
|
||||
|
||||
@ -389,13 +336,12 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms,
|
||||
/* run transport */
|
||||
diffusion.simulate(dt);
|
||||
|
||||
chem.runtime_params = ¶ms;
|
||||
// chem.runtime_params = ¶ms;
|
||||
|
||||
chem.getField().update(diffusion.getField());
|
||||
|
||||
// MSG("Chemistry start");
|
||||
if (params.use_ai_surrogate)
|
||||
{
|
||||
if (params.use_ai_surrogate) {
|
||||
double ai_start_t = MPI_Wtime();
|
||||
// Save current values from the tug field as predictor for the ai step
|
||||
R["TMP"] = Rcpp::wrap(chem.getField().AsVector());
|
||||
@ -446,8 +392,7 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms,
|
||||
chem.simulate(dt);
|
||||
|
||||
/* AI surrogate iterative training*/
|
||||
if (params.use_ai_surrogate)
|
||||
{
|
||||
if (params.use_ai_surrogate) {
|
||||
double ai_start_t = MPI_Wtime();
|
||||
|
||||
R["TMP"] = Rcpp::wrap(chem.getField().AsVector());
|
||||
@ -487,25 +432,32 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms,
|
||||
std::to_string(maxiter));
|
||||
|
||||
double chk_start = MPI_Wtime();
|
||||
control.endIteration(iter)
|
||||
/*
|
||||
if (iter % params.checkpoint_interval == 0) {
|
||||
MSG("Writing checkpoint of iteration " + std::to_string(iter));
|
||||
write_checkpoint(params.out_dir,
|
||||
"checkpoint" + std::to_string(iter) + ".hdf5",
|
||||
{.field = chem.getField(), .iteration = iter});
|
||||
}
|
||||
|
||||
if(iter % params.checkpoint_interval == 0){
|
||||
MSG("Writing checkpoint of iteration " + std::to_string(iter));
|
||||
write_checkpoint(params.out_dir, "checkpoint" + std::to_string(iter) + ".hdf5",
|
||||
{.field = chem.getField(), .iteration = iter});
|
||||
}
|
||||
|
||||
if (params.control_interval_enabled && !params.rollback_enabled)
|
||||
{
|
||||
writeStatsToCSV(chem.error_history, chem.getField().GetProps(), params.out_dir,"stats_overview");
|
||||
if (params.control_interval_enabled && !params.rollback_enabled) {
|
||||
writeStatsToCSV(chem.error_history, chem.getField().GetProps(),
|
||||
params.out_dir, "stats_overview");
|
||||
|
||||
if(triggerRollbackIfExceeded(chem, params, iter)){
|
||||
params.rollback_enabled = true;
|
||||
params.rollback_counter ++;
|
||||
params.sur_disabled_counter = params.control_interval;
|
||||
MSG("Interpolation disabled for the next " + std::to_string(params.control_interval) + ".");
|
||||
}
|
||||
}
|
||||
double chk_end = MPI_Wtime();
|
||||
if (triggerRollbackIfExceeded(chem, params, iter)) {
|
||||
params.rollback_enabled = true;
|
||||
params.rollback_counter++;
|
||||
params.sur_disabled_counter = params.control_interval;
|
||||
MSG("Interpolation disabled for the next " +
|
||||
std::to_string(params.control_interval) + ".");
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
double chk_end = MPI_Wtime();
|
||||
chkTime += chk_end - chk_start;
|
||||
|
||||
// MSG();
|
||||
@ -529,10 +481,10 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms,
|
||||
ctrl_profiling["ctrl_logic_master"] = chem.GetMasterCtrlLogicTime();
|
||||
ctrl_profiling["bcast_ctrl_logic_master"] = chem.GetMasterCtrlBcastTime();
|
||||
ctrl_profiling["recv_ctrl_logic_maser"] = chem.GetMasterRecvCtrlLogicTime();
|
||||
ctrl_profiling["ctrl_logic_worker"] = Rcpp::wrap(chem.GetWorkerControlTimings());
|
||||
ctrl_profiling["ctrl_logic_worker"] =
|
||||
Rcpp::wrap(chem.GetWorkerControlTimings());
|
||||
|
||||
if (params.use_dht)
|
||||
{
|
||||
if (params.use_dht) {
|
||||
chem_profiling["dht_hits"] = Rcpp::wrap(chem.GetWorkerDHTHits());
|
||||
chem_profiling["dht_evictions"] = Rcpp::wrap(chem.GetWorkerDHTEvictions());
|
||||
chem_profiling["dht_get_time"] = Rcpp::wrap(chem.GetWorkerDHTGetTimings());
|
||||
@ -540,8 +492,7 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms,
|
||||
Rcpp::wrap(chem.GetWorkerDHTFillTimings());
|
||||
}
|
||||
|
||||
if (params.use_interp)
|
||||
{
|
||||
if (params.use_interp) {
|
||||
chem_profiling["interp_w"] =
|
||||
Rcpp::wrap(chem.GetWorkerInterpolationWriteTimings());
|
||||
chem_profiling["interp_r"] =
|
||||
@ -561,15 +512,13 @@ static Rcpp::List RunMasterLoop(RInsidePOET &R, RuntimeParameters ¶ms,
|
||||
profiling["diffusion"] = diffusion_profiling;
|
||||
profiling["ctrl_logic"] = ctrl_profiling;
|
||||
|
||||
|
||||
chem.MasterLoopBreak();
|
||||
|
||||
return profiling;
|
||||
}
|
||||
|
||||
std::vector<std::string> getSpeciesNames(const Field &&field, int root,
|
||||
MPI_Comm comm)
|
||||
{
|
||||
MPI_Comm comm) {
|
||||
std::uint32_t n_elements;
|
||||
std::uint32_t n_string_size;
|
||||
|
||||
@ -579,13 +528,11 @@ std::vector<std::string> getSpeciesNames(const Field &&field, int root,
|
||||
const bool is_master = root == rank;
|
||||
|
||||
// first, the master sends all the species names iterative
|
||||
if (is_master)
|
||||
{
|
||||
if (is_master) {
|
||||
n_elements = field.GetProps().size();
|
||||
MPI_Bcast(&n_elements, 1, MPI_UINT32_T, root, MPI_COMM_WORLD);
|
||||
|
||||
for (std::uint32_t i = 0; i < n_elements; i++)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < n_elements; i++) {
|
||||
n_string_size = field.GetProps()[i].size();
|
||||
MPI_Bcast(&n_string_size, 1, MPI_UINT32_T, root, MPI_COMM_WORLD);
|
||||
MPI_Bcast(const_cast<char *>(field.GetProps()[i].c_str()), n_string_size,
|
||||
@ -600,8 +547,7 @@ std::vector<std::string> getSpeciesNames(const Field &&field, int root,
|
||||
|
||||
std::vector<std::string> species_names_out(n_elements);
|
||||
|
||||
for (std::uint32_t i = 0; i < n_elements; i++)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < n_elements; i++) {
|
||||
MPI_Bcast(&n_string_size, 1, MPI_UINT32_T, root, MPI_COMM_WORLD);
|
||||
|
||||
char recv_buf[n_string_size];
|
||||
@ -614,8 +560,7 @@ std::vector<std::string> getSpeciesNames(const Field &&field, int root,
|
||||
return species_names_out;
|
||||
}
|
||||
|
||||
std::array<double, 2> getBaseTotals(Field &&field, int root, MPI_Comm comm)
|
||||
{
|
||||
std::array<double, 2> getBaseTotals(Field &&field, int root, MPI_Comm comm) {
|
||||
std::array<double, 2> base_totals;
|
||||
|
||||
int rank;
|
||||
@ -623,8 +568,7 @@ std::array<double, 2> getBaseTotals(Field &&field, int root, MPI_Comm comm)
|
||||
|
||||
const bool is_master = root == rank;
|
||||
|
||||
if (is_master)
|
||||
{
|
||||
if (is_master) {
|
||||
const auto h_col = field["H"];
|
||||
const auto o_col = field["O"];
|
||||
|
||||
@ -639,8 +583,7 @@ std::array<double, 2> getBaseTotals(Field &&field, int root, MPI_Comm comm)
|
||||
return base_totals;
|
||||
}
|
||||
|
||||
bool getHasID(Field &&field, int root, MPI_Comm comm)
|
||||
{
|
||||
bool getHasID(Field &&field, int root, MPI_Comm comm) {
|
||||
bool has_id;
|
||||
|
||||
int rank;
|
||||
@ -648,8 +591,7 @@ bool getHasID(Field &&field, int root, MPI_Comm comm)
|
||||
|
||||
const bool is_master = root == rank;
|
||||
|
||||
if (is_master)
|
||||
{
|
||||
if (is_master) {
|
||||
const auto ID_field = field["ID"];
|
||||
|
||||
std::set<double> unique_IDs(ID_field.begin(), ID_field.end());
|
||||
@ -666,8 +608,7 @@ bool getHasID(Field &&field, int root, MPI_Comm comm)
|
||||
return has_id;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
int world_size;
|
||||
|
||||
MPI_Init(&argc, &argv);
|
||||
@ -678,8 +619,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
RInsidePOET &R = RInsidePOET::getInstance();
|
||||
|
||||
if (MY_RANK == 0)
|
||||
{
|
||||
if (MY_RANK == 0) {
|
||||
MSG("Running POET version " + std::string(poet_version));
|
||||
}
|
||||
|
||||
@ -687,8 +627,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
RuntimeParameters run_params;
|
||||
|
||||
if (parseInitValues(argc, argv, run_params) != 0)
|
||||
{
|
||||
if (parseInitValues(argc, argv, run_params) != 0) {
|
||||
MPI_Finalize();
|
||||
return 0;
|
||||
}
|
||||
@ -713,6 +652,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
ChemistryModule chemistry(run_params.work_package_size,
|
||||
init_list.getChemistryInit(), MPI_COMM_WORLD);
|
||||
ControlModule control(&run_params, &chemistry);
|
||||
|
||||
const ChemistryModule::SurrogateSetup surr_setup = {
|
||||
getSpeciesNames(init_list.getInitialGrid(), 0, MPI_COMM_WORLD),
|
||||
@ -730,12 +670,21 @@ int main(int argc, char *argv[])
|
||||
|
||||
chemistry.masterEnableSurrogates(surr_setup);
|
||||
|
||||
if (MY_RANK > 0)
|
||||
{
|
||||
const ControlModule::ControlSetup ctrl_setup = {
|
||||
run_params.out_dir, // added
|
||||
run_params.checkpoint_interval,
|
||||
run_params.control_interval,
|
||||
run_params.species_count,
|
||||
run_params.species_names,
|
||||
run_params.mape_threshold,
|
||||
run_params.rrmse_threshold};
|
||||
|
||||
control.enableControlLogic(ctrl_setup);
|
||||
|
||||
|
||||
if (MY_RANK > 0) {
|
||||
chemistry.WorkerLoop();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// R.parseEvalQ("mysetup <- setup");
|
||||
// // if (MY_RANK == 0) { // get timestep vector from
|
||||
// // grid_init function ... //
|
||||
@ -749,8 +698,7 @@ int main(int argc, char *argv[])
|
||||
R["out_ext"] = run_params.out_ext;
|
||||
R["out_dir"] = run_params.out_dir;
|
||||
|
||||
if (run_params.use_ai_surrogate)
|
||||
{
|
||||
if (run_params.use_ai_surrogate) {
|
||||
/* Incorporate ai surrogate from R */
|
||||
R.parseEvalQ(ai_surrogate_r_library);
|
||||
/* Use dht species for model input and output */
|
||||
@ -799,8 +747,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
if (MY_RANK == 0)
|
||||
{
|
||||
if (MY_RANK == 0) {
|
||||
MSG("done, bye!");
|
||||
}
|
||||
|
||||
|
||||
@ -38,8 +38,7 @@ static const inline std::string ai_surrogate_r_library =
|
||||
R"(@R_AI_SURROGATE_LIB@)";
|
||||
static const inline std::string r_runtime_parameters = "mysetup";
|
||||
|
||||
struct RuntimeParameters
|
||||
{
|
||||
struct RuntimeParameters {
|
||||
std::string out_dir;
|
||||
std::vector<double> timesteps;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user