-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.cc
3920 lines (3211 loc) · 157 KB
/
run.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include<limits>
#include <fstream>
#include <unistd.h>
#include <getopt.h>
#include <ctime>
#include <cmath>
#include <numeric> // std::iota
#include <algorithm> // std::sort, std::stable_sort
#include<omp.h>
// -------------------- OpenMesh
#include <OpenMesh/Core/System/omstream.hh>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <OpenMesh/Core/Utils/PropertyManager.hh>
#include <OpenMesh/Apps/Assembly/topology.hh>
#include <OpenMesh/Apps/Assembly/geometry.hh>
#include <OpenMesh/Apps/Assembly/energy.hh>
#include <OpenMesh/Apps/Assembly/monte_carlo.hh>
#include <OpenMesh/Apps/Assembly/monte_carlo_wall.hh>
#include <OpenMesh/Apps/Assembly/monte_carlo_external_potential.hh>
#include <OpenMesh/Apps/Assembly/thermodynamic_integration_move.hh>
#include <OpenMesh/Apps/Assembly/excluders.hh>
#include <OpenMesh/Apps/Assembly/custom_mesh_props.hh>
#include <OpenMesh/Apps/Assembly/IO.hh>
#include <OpenMesh/Apps/Assembly/run.hh>
#include <OpenMesh/Apps/Assembly/random.hh>
#include <OpenMesh/Apps/Assembly/analyze.hh>
#include <OpenMesh/Apps/Assembly/subset_division.hh>
#include <OpenMesh/Apps/Assembly/json.hh>
// for convenience
using json = nlohmann::json;
std::vector<int> sort_indexes(const std::vector<int> &v) {
// initialize original index locations
std::vector<int> idx(v.size());
std::iota(idx.begin(), idx.end(), 0);
// sort indexes based on comparing values in v
// using std::stable_sort instead of std::sort
// to avoid unnecessary index re-orderings
// when v contains elements of equal values
std::stable_sort(idx.begin(), idx.end(),
[&v](int i1, int i2) {return v[i1] > v[i2];});
return idx;
}
void init_mesh(MyMesh & mesh, std::string init_filename, std::string input_filename, long long byte_position){
mesh.request_face_status();
mesh.request_edge_status();
mesh.request_vertex_status();
mesh.request_halfedge_status();
mesh.request_face_normals();
//std::string om_filename = "/home/btyukodi/assembly_openmesh/OpenMesh-9.0/build/outfileom4.om";
//std::string input_filename = "/home/btyukodi/assembly_openmesh/sandbox/input_carlos2.json";
//long long byte_position = 145;
init_mesh_from_om(mesh, init_filename, byte_position, input_filename);
}
//will need to add umbrella window
struct AcceptanceMonitor{
std::vector<double> n_acc;
std::vector<double> n_tot;
std::vector<double> r_acc;
int nmoves;
AcceptanceMonitor(int nmoves=13){
for (int i=0; i<nmoves; i++){
this->n_acc.push_back(0);
this->n_tot.push_back(0);
this->r_acc.push_back(0);
}
}
};
static AcceptanceMonitor default_AM = AcceptanceMonitor();
void propagate(MyMesh & mesh, long t_init, long t_final, RunParameters rp, std::ostream& outfile_om, std::ostream& outfile_data, UmbrellaWindow & uw, std::mt19937 & eng, AcceptanceMonitor & AM = default_AM){
int nmoves = 13;//10;
/*for (int iac=0; iac<(nmoves+1); iac++){
n_acc[iac]=0;
n_tot[iac]=0;
} */
bool accepted;
int which_move, which_type, which_rotation, number_of_rotational_configs;
double k_insertion, k_fusion, p_propose, r;
std::tuple< std::vector<MyMesh::VertexHandle>, std::vector<MyMesh::VertexHandle>, std::vector<MyMesh::VertexHandle> , std::vector<int>> wedges;
std::tuple< std::vector<MyMesh::VertexHandle>, std::vector<MyMesh::VertexHandle>, std::vector<MyMesh::VertexHandle> > fusion_vectors, type2_fission_vectors, holes;
std::tuple< std::vector<MyMesh::VertexHandle>, std::vector<MyMesh::VertexHandle> > fission_vectors;
std::vector <MyMesh::VertexHandle> w1, v1;
std::vector<MyMesh::HalfedgeHandle> boundary_halfedges, h1;
std::vector<MyMesh::FaceHandle> removable_faces_geom, removable_faces;
std::tuple<std::vector<MyMesh::HalfedgeHandle>, std::vector<MyMesh::HalfedgeHandle> > fusion_halfedges;
std::vector<MyMesh::EdgeHandle> fission_edges;
std::vector<MyMesh::VertexHandle*> handle_tracking_v;
std::vector<MyMesh::FaceHandle*> handle_tracking_f;
std::vector<MyMesh::HalfedgeHandle*> handle_tracking_h;
auto face_props = OpenMesh::FProp<FaceProp>(mesh, "face_props");
auto mesh_props = OpenMesh::MProp<MeshProp>(mesh, "mesh_props");
auto proto_face_props = OpenMesh::FProp<FaceProp>((*mesh_props).prototypes_mesh, "face_props");
float kT = (*mesh_props).kT;
double l_fuse = (*mesh_props).l_fuse;
//std::ofstream outfile("outfileom5.om", std::ios::out | std::ios::binary);
// std::ofstream datafile("data_out5.dat");
long long fpos;
long long opos;
int n_boundary_edges;
int n_type1, n_type2;
//dump_data(mesh, -1, outfile_data, fpos);
for (long t=t_init; t<t_final; t++){
if (mesh.n_faces() > rp.Nmax){
break;
}
if (t % rp.dtsave ==0){
std::cout<<"t = "<<t<<" n_faces="<<mesh.n_faces()<<std::endl;
n_boundary_edges = count_boundary_edges(mesh);
n_type1 = count_subunits_of_type(mesh, 0);
n_type2=count_subunits_of_type(mesh, 1);
//skip full dump for the first dtskip timesteps
if ( (t>rp.dtskip) && (t % rp.dtsave_snapshot==0)){
fpos = dump_om(mesh, t, outfile_om);
}
else{
//save the last snapshot if it will break
if (rp.stop_at_closure && (n_boundary_edges==0)){
fpos = dump_om(mesh, t, outfile_om);
}
else{
fpos=-1;
}
}
for (int iac=0; iac<(nmoves); iac++){
AM.r_acc[iac] = AM.n_acc[iac]/AM.n_tot[iac];
//std::cout<<"r_acc "<< AM.r_acc[iac]<<std::endl;
//std::cout<<"n_acc "<< AM.n_acc[iac]<<std::endl;
//std::cout<<"n_tot "<< AM.n_tot[iac]<<std::endl;
AM.n_acc[iac]=0;
AM.n_tot[iac]=0;
}
dump_data(mesh, t, outfile_data, fpos, AM.r_acc);
opos = outfile_data.tellp();
outfile_data.seekp (opos-1);
outfile_data<<"\t"<< n_type1<<"\t"<<n_type2<<"\t" << n_boundary_edges <<std::endl;
//dump_om(mesh, "omtest"+std::to_string(t)+".om");
//don't count boundary edges at every timestep
if (rp.stop_at_closure && (n_boundary_edges==0)){
break;
}
}
if (t % rp.checkpoint_freq ==0){
create_checkpoint(mesh, uw, t, rp.data_folder+"checkpoint.ckp");
}
/*
for (int n=0; n<(int)mesh.n_vertices(); n++){
AM.n_acc[0]+=attempt_move(mesh, eng);
AM.n_tot[0]++;
}
*/
/*std::cout<<"n_tot0 "<< n_tot[1]<<std::endl;
std::cout<<"n_acc0 "<< n_acc[1]<<std::endl;
std::cout<<"n_acc0/n_tot0 "<< n_acc[1]/n_tot[1]<<std::endl;*/
//!! IMPORTANT: in each t iteration, only one move should be selected because the garbage collector
// is only called once, at the end of each iteration. n_faces, n_vertices, etc won't get updated unless
// the garbage collector is called and we need them to be up to date for the bias potential and also for attempt_move()
//which_move = rand() % nmoves;
which_move = randint(nmoves, eng);
//std::cout<<"which move "<<which_move<<std::endl;
accepted=false;
switch (which_move){
case 0:
k_fusion = (*mesh_props).k_fusion;
fusion_vectors = get_type1_fusion_triplets(mesh, l_fuse);
v1 = std::get<0>(fusion_vectors);
p_propose = k_fusion * v1.size();
if ( (p_propose>1) && (!rp.adaptive_rates) ) std::cout<<"Warning! Decrease k_fusion rate! - type1_fusion"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_fusion rate... - type1_fusion"<<std::endl;
(*mesh_props).k_fusion*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_type1_fusion(mesh, eng);
AM.n_acc[which_move+1]+=accepted;
}
//if (accepted) std::cout<<"type1 fusion"<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 1:
k_fusion = (*mesh_props).k_fusion;
fission_vectors = get_type1_fission_pairs(mesh);
v1 = std::get<0>(fission_vectors);
p_propose = k_fusion * v1.size();
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_fusion rate! - type1_fission"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_fusion rate... - type1_fission"<<std::endl;
(*mesh_props).k_fusion*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_type1_fission(mesh, eng);
AM.n_acc[which_move+1]+=accepted;
}
//if (accepted) std::cout<<"type1 fission"<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 2:
k_fusion = (*mesh_props).k_fusion2;
fusion_vectors = get_type2_fusion_triplets(mesh, l_fuse); //each counted TWICE
v1 = std::get<0>(fusion_vectors);
p_propose = k_fusion * v1.size()*0.5; // x 1/2 to correct for double counting
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_fusion2 rate! - type2_fusion"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_fusion2 rate... - type2_fusion"<<std::endl;
(*mesh_props).k_fusion2*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_type2_fusion(mesh, eng);
AM.n_acc[which_move+1]+=accepted;
}
//if (accepted) std::cout<<"type2 fusion "<<p_propose<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 3:
k_fusion = (*mesh_props).k_fusion2;
type2_fission_vectors = get_type2_fission_triplets(mesh); //each counted TWICE
v1 = std::get<0>(type2_fission_vectors);
p_propose = k_fusion * v1.size()*0.5; // x 1/2 to correct for double counting
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_fusion2 rate! - type2_fission"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_fusion2 rate... - type2_fission"<<std::endl;
(*mesh_props).k_fusion2*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_type2_fission(mesh, eng);
AM.n_acc[which_move+1]+=accepted;
}
//if (accepted) std::cout<<"type2 fission "<<p_propose<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 4:
//if (mesh.n_faces()>n_umb_sim ) break;
//pick subunit type from prototype subunits
//which_type = rand() % (*mesh_props).prototype_faces.size();
which_type = randint( (*mesh_props).prototype_faces.size(), eng );
number_of_rotational_configs = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].number_of_rotational_configs;
//which_rotation = rand() % number_of_rotational_configs;
which_rotation = randint( number_of_rotational_configs, eng );
//----
k_insertion = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion;
boundary_halfedges = find_boundary_halfedges(mesh);
p_propose = k_insertion * boundary_halfedges.size() * number_of_rotational_configs;
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_insertion rate! - insertion"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_insertion rate... - insertion"<<std::endl;
proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_insertion(mesh, which_type, which_rotation, uw, eng);
AM.n_acc[which_move+1]+=accepted;
}
//if (accepted) std::cout<<"insertion type "<< which_type <<" "<<p_propose<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 5:
//if (mesh.n_faces()>n_umb_sim ) break;
//pick subunit type from prototype subunits
//which_type = rand() % (*mesh_props).prototype_faces.size();
which_type = randint( (*mesh_props).prototype_faces.size(), eng );
number_of_rotational_configs = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].number_of_rotational_configs;
//which_rotation = rand() % number_of_rotational_configs;
which_rotation = randint( number_of_rotational_configs, eng );
//---
k_insertion = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion;
wedges = get_open_wedge_triplets(mesh);
w1 = std::get<0>(wedges);
p_propose = k_insertion * w1.size() * number_of_rotational_configs;
if ((p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_insertion rate! - wedge_insertion"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_insertion rate... - wedge_insertion"<<std::endl;
proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_wedge_insertion(mesh, which_type, which_rotation, uw, eng);
AM.n_acc[which_move+1]+=accepted;
}
//if (accepted) std::cout<<"wedge insertion type "<< which_type <<" "<<p_propose<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 6:
//pick subunit type from prototype subunits
//which_type = rand() % (*mesh_props).prototype_faces.size();
which_type = randint( (*mesh_props).prototype_faces.size(), eng );
k_insertion = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion;
removable_faces = get_simply_removable_faces(mesh, which_type);
p_propose = k_insertion * removable_faces.size();
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_insertion rate! - removal"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_insertion rate... - removal"<<std::endl;
proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_removal(mesh, which_type, uw, eng);
AM.n_acc[which_move+1]+=accepted;
}
AM.n_tot[which_move+1]++;
break;
case 7:
//pick subunit type from prototype subunits
//which_type = rand() % (*mesh_props).prototype_faces.size();
which_type = randint( (*mesh_props).prototype_faces.size(), eng );
k_insertion = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion;
removable_faces = get_wedge_removable_faces(mesh, which_type);
p_propose = k_insertion * removable_faces.size();
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_insertion rate! - wedge_removal"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_insertion rate... - wedge_removal"<<std::endl;
proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_wedge_removal(mesh, which_type, uw, eng);
AM.n_acc[which_move+1]+=accepted;
}
AM.n_tot[which_move+1]++;
break;
case 8:
k_fusion = (*mesh_props).k_fusion_edge;
fusion_halfedges = get_halfedge_fusion_pairs(mesh, l_fuse); //each counted TWICE
h1 = std::get<0>(fusion_halfedges);
p_propose = k_fusion * h1.size()*0.5; // x 1/2 to correct for double counting
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_fusion_edge rate! - edge_fusion"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_fusion_edge rate... - edge_fusion"<<std::endl;
(*mesh_props).k_fusion_edge*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_edge_fusion(mesh, eng);
AM.n_acc[which_move+1]+=accepted;
}
//if (accepted) std::cout<<"EDGE fusion " <<" "<<p_propose<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 9:
k_fusion = (*mesh_props).k_fusion_edge;
fission_edges = get_fission_edges(mesh);
p_propose = k_fusion * fission_edges.size();
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_fusion_edge rate! - edge_fission"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_fusion_edge rate... - edge_fission"<<std::endl;
(*mesh_props).k_fusion_edge*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_edge_fission(mesh, eng);
AM.n_acc[which_move+1]+=accepted;
}
//if (accepted) std::cout<<"EDGE fission " <<" "<<p_propose<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 10:
for (int n=0; n<(int)mesh.n_vertices(); n++){
AM.n_acc[0]+=attempt_move(mesh, eng);
AM.n_tot[0]++;
}
break;
case 11:
which_type = randint( (*mesh_props).prototype_faces.size(), eng );
number_of_rotational_configs = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].number_of_rotational_configs;
//which_rotation = rand() % number_of_rotational_configs;
which_rotation = randint( number_of_rotational_configs, eng );
//---
k_insertion = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion;
holes = get_hole_triplets(mesh);
w1 = std::get<0>(holes);
p_propose = k_insertion * w1.size() * number_of_rotational_configs * 1.0/3.0; //<--- 1/3 because each hole is counted 3x
if ((p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_insertion rate! - wedge_insertion"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_insertion rate... - hole_insertion"<<std::endl;
proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_hole_insertion(mesh, which_type, which_rotation, uw, eng);
AM.n_acc[which_move+1]+=accepted;
}
if (accepted) std::cout<<"hole insertion type "<< which_type <<" "<<p_propose<<std::endl;
AM.n_tot[which_move+1]++;
break;
case 12:
which_type = randint( (*mesh_props).prototype_faces.size(), eng );
k_insertion = proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion;
removable_faces = get_hole_removable_faces(mesh, which_type);
p_propose = k_insertion * removable_faces.size();
if ( (p_propose>1) && (!rp.adaptive_rates)) std::cout<<"Warning! Decrease k_insertion rate! - hole_removal"<<std::endl;
if ( (p_propose>1) && (rp.adaptive_rates) ) {
std::cout<<"Decreasing k_insertion rate... - hole_removal"<<std::endl;
proto_face_props[ (*mesh_props).prototype_faces[which_type] ].k_insertion*=0.5;
break;//-------- don't do the move if violates detailed balance
}
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(eng);
if (r<p_propose){
accepted = attempt_hole_removal(mesh, which_type, uw, eng);
AM.n_acc[which_move+1]+=accepted;
}
AM.n_tot[which_move+1]++;
break;
}
//get all face's neighbor list handles to save them through the garbage collector
handle_tracking_f.clear();
for (MyMesh::FaceIter fit = mesh.faces_sbegin(); fit!=mesh.faces_end(); ++fit){
for (auto & neighbor: face_props[*fit].neighbor_list){
handle_tracking_f.push_back( &neighbor);
}
}
mesh.garbage_collection<std::vector<MyMesh::VertexHandle*>, std::vector<MyMesh::HalfedgeHandle*>, std::vector<MyMesh::FaceHandle*> >(handle_tracking_v, handle_tracking_h, handle_tracking_f);
if (t % 150 ==0){
update_full_neighbor_list(mesh);
//Could check overlaps for the full capsid here to verify
}
uw.add_value(mesh.n_faces());
}
return;
}
void run_dynamical(std::string input_file){
MyMesh mesh;
//add parameters to init_mesh; if init_config provided, init_from_om too
RunParameters rp;
read_set_run_params(rp, input_file);
//initialize RNG from ensemble seed
//std::srand(rp.ensemble*73 + 17);
std::mt19937 eng(rp.ensemble*73 + 17);
init_mesh(mesh, rp.init_file, input_file, rp.init_file_pos);
//should I create data_folder here?
system(("mkdir -p "+rp.data_folder).c_str());
std::ofstream outfile_om(rp.data_folder+"snapshots.om", std::ios::out | std::ios::binary);
std::ofstream outfile_data(rp.data_folder+"data_log.dat");
outfile_data<<"t"<<"\t"<<"key" <<"\t" <<"n_f" <<"\t"<<"n_v"<<"\t"<<"n_e"<<"\t"<< "E_el"<<"\t"<<"E_full"<<std::endl;
//burnin time to equilibrate initial structure
for (long t=0; t<rp.dt_burnin; t++){
for (int n=0; n<(int)mesh.n_vertices(); n++){
attempt_move(mesh, eng);
}
}
long t_init=0;
long t_final=rp.timesteps;
UmbrellaWindow uw_fake(0.0, 0.0);
propagate(mesh, t_init, t_final, rp, outfile_om, outfile_data, uw_fake, eng);
outfile_om.close();
outfile_data.close();
//do conversions if requested
//create a conversions directory
system(("mkdir -p "+rp.data_folder+"conversions").c_str());
if (rp.convert_to_lammps_trajectory)
convert_om_to_lammps_trajectory(rp.data_folder+"snapshots.om", rp.data_folder+"conversions/");
if (rp.convert_to_lammps)
convert_om_to_lammps_snapshots(rp.data_folder+"snapshots.om", rp.data_folder+"conversions/lammps_");
if (rp.convert_to_vtk)
convert_om_to_VTK_snapshots(rp.data_folder+"snapshots.om", rp.data_folder+"conversions/vtk_", rp.path_to_source+"vtk_colors.conf");
if (rp.convert_to_dat)
convert_om_to_dat_snapshots(rp.data_folder+"snapshots.om", rp.data_folder+"conversions/dat_");
return;
}
void run_umbrella(std::string input_file){
//create_single_subunit_om("single_subunit_trumpet.om", 0, 0, 1, 2);
MyMesh mesh;
//add parameters to init_mesh; if init_config provided, init_from_om too
RunParameters rp;
read_set_run_params(rp, input_file);
//initialize RNG from ensemble seed
//std::srand(rp.ensemble*73 + 17);
std::mt19937 eng(rp.ensemble*73 + 17);
init_mesh(mesh, rp.init_file, input_file, rp.init_file_pos);
//should I create data_folder here?
system(("mkdir -p "+rp.data_folder).c_str());
std::ofstream outfile_om;
std::ofstream outfile_data;
std::ofstream outfile_histogram;
bool continue_simulation = false;
//if required files for restart exist and continue_if_possible flag is set
if (rp.continue_if_possible & file_exists(rp.data_folder+"data_log.dat") & file_exists(rp.data_folder+"H_N.dat") & file_exists(rp.data_folder+"checkpoint.ckp")){
outfile_data.open(rp.data_folder+"data_log.dat", std::ios::app);
outfile_om.open(rp.data_folder+"snapshots.om", std::ios::out | std::ios::binary | std::ios::app);
outfile_histogram.open(rp.data_folder+"H_N.dat", std::ios::app);
continue_simulation = true;
}
else{
outfile_data.open(rp.data_folder+"data_log.dat");
outfile_om.open(rp.data_folder+"snapshots.om", std::ios::out | std::ios::binary);
outfile_histogram.open(rp.data_folder+"H_N.dat");
outfile_data<<"t"<<"\t"<<"key" <<"\t" <<"n_f" <<"\t"<<"n_v"<<"\t"<<"n_e"<<"\t"<< "E_el"<<"\t"<<"E_full"<<std::endl;
}
std::cout<<"Continue? "<<rp.continue_if_possible<<std::endl;
long t_init=0;
long t_final=0;//=rp.timesteps;
//histogram; counts up to 1000 subunits
std::vector<int> H_N(1000, 0);
UmbrellaWindow uw(rp.spring_const, mesh.n_faces());
if (continue_simulation){
load_from_checkpoint(mesh, uw, t_final, rp.data_folder+"checkpoint.ckp", input_file);
}
while (t_final<rp.timesteps){
t_init = t_final;
t_final = t_init + rp.nsteps_umbrella;
//std::cout<<"--- tinit, tfinal "<<t_init<<" "<<t_final<<std::endl;
propagate(mesh, t_init, t_final, rp, outfile_om, outfile_data, uw, eng);
//shift the umbrella window
uw.N0+=rp.dN_umbrella;
std::cout<<"umbrella N0="<<uw.N0<<std::endl;
for (int N: uw.values){
H_N[N]++;
}
for (const auto &hi : H_N) outfile_histogram << hi <<"\t";
outfile_histogram << std::endl;
uw.values.clear();
std::fill(H_N.begin(), H_N.end(), 0);
}
outfile_om.close();
outfile_data.close();
outfile_histogram.close();
/*****checkpoint test*****/
/*MyMesh mesh_ckp;
long timestep;
UmbrellaWindow uwc(0,0);
load_from_checkpoint(mesh_ckp, uwc, timestep, rp.data_folder+"checkpoint.ckp", input_file);
std::cout<<"Checkpoint read...."<<std::endl;
std::cout<<uwc.spring_const<<std::endl;
std::cout<<uwc.N0<<std::endl;
std::cout<<timestep<<std::endl;*/
/**********/
//do conversions if requested
//create a conversions directory
system(("mkdir -p "+rp.data_folder+"conversions").c_str());
if (rp.convert_to_lammps_trajectory)
convert_om_to_lammps_trajectory(rp.data_folder+"snapshots.om", rp.data_folder+"conversions/");
if (rp.convert_to_lammps)
convert_om_to_lammps_snapshots(rp.data_folder+"snapshots.om", rp.data_folder+"conversions/lammps_");
if (rp.convert_to_vtk)
convert_om_to_VTK_snapshots(rp.data_folder+"snapshots.om", rp.data_folder+"conversions/vtk_", rp.path_to_source+"vtk_colors.conf");
if (rp.convert_to_dat)
convert_om_to_dat_snapshots(rp.data_folder+"snapshots.om", rp.data_folder+"conversions/dat_");
//do the WHAM
//system(("cd "+rp.path_to_source).c_str());
//system(("cd "+rp.path_to_source + "&& python wham.py "+input_file ).c_str());
return;
}
//little helper to switch values of two double variables
/*void swap_uw(UmbrellaWindow & a, UmbrellaWindow & b){
//UmbrellaWindow tmp=a;
double spring_const;
double N0;
std::vector<int> values;
spring_const = a.spring_const;
N0 = a.N0;
values = a.values;
a.spring_const = b.spring_const;
a.N0 = b.N0;
a.values = b.values;
b.spring_const = spring_const;
b.N0 = N0;
b.values = values;
return;
}
*/
//work in progress
void run_umbrella_parallel_tempering(std::string PT_input_file){
std::vector<std::string> input_files;
//read/set input_files here from PT_input_file
json pt_params;
std::ifstream input_file(PT_input_file);
input_file >> pt_params;
input_file.close();
pt_params = pt_params["parameters"]["parall_tempering_parameters"];
long dt_exchange = pt_params["dt_exchange"];
input_files = pt_params["input_files"].get<std::vector<std::string>>();
std::cout<<" Exchanging between "<<std::endl;
for (auto inp: input_files){
std::cout<<inp<<std::endl;
}
unsigned int nruns = input_files.size();
std::vector<MyMesh> mesh(nruns);
std::vector<RunParameters> rp(nruns);
std::vector<AcceptanceMonitor> AM(nruns);
std::ofstream outfile_om[nruns];
std::ofstream outfile_data[nruns];
std::ofstream outfile_histogram[nruns];
std::ofstream outfile_k_N0[nruns];
std::vector<std::vector<int>> H_N( nruns , std::vector<int> (1000, 0));
std::vector<UmbrellaWindow> uw;//(nruns);
//should "thermalize" all rng engines
std::vector< std::mt19937 > engines;
std::mt19937 exch_engine(std::mt19937(rp[0].ensemble*73 + 17) );
for (unsigned int i=0; i<nruns; i++){
read_set_run_params(rp[i], input_files[i]);
if (rp[i].nsteps_umbrella % dt_exchange != 0 ){
std::cout<<"simulation #"<<i<<" : nsteps_umbrella % dt_exchange != 0. Exiting..."<<std::endl;
std::cout<<"This is necessary for proper window shifting. Make sure that nsteps_umbrella % dt_exchange=0 for all simulations."<<std::endl;
exit(1);
}
if (rp[i].dt_burnin % dt_exchange != 0 ){
std::cout<<"simulation #"<<i<<" : dt_burnin % dt_exchange != 0. Exiting..."<<std::endl;
std::cout<<"This is necessary for proper window shifting and sampling. Make sure that dt_burnin % dt_exchange=0 for all simulations."<<std::endl;
exit(1);
}
if (rp[i].dt_burnin >= rp[i].nsteps_umbrella ){
std::cout<<"simulation #"<<i<<" : dt_burnin >= nsteps_umbrella. Exiting..."<<std::endl;
std::cout<<"Make sure that dt_burnin < nsteps_umbrella for all simulations."<<std::endl;
exit(1);
}
//initialize RNG from ensemble seed
//std::srand(rp[i].ensemble*73 + 17);
engines.push_back( std::mt19937(rp[i].ensemble*73 + 17) );
init_mesh(mesh[i], rp[i].init_file, input_files[i], rp[i].init_file_pos);
//should I create data_folder here?
system(("mkdir -p "+rp[i].data_folder).c_str());
/* outfile_om[i].open(rp[i].data_folder+"snapshots.om", std::ios::out | std::ios::binary);
outfile_data[i].open(rp[i].data_folder+"data_log.dat");
outfile_histogram[i].open(rp[i].data_folder+"H_N.dat");
outfile_data[i]<<"t"<<"\t"<<"key" <<"\t" <<"n_f" <<"\t"<<"n_v"<<"\t"<<"n_e"<<"\t"<< "E_el"<<"\t"<<"E_full"<<std::endl;
*/
uw.push_back( UmbrellaWindow(rp[i].spring_const, mesh[i].n_faces()) );
AM.push_back(AcceptanceMonitor());
}
long t_init=0;
long t_final=0;//=rp.timesteps;
/****** continue? ********/
bool continue_simulation = true;
for (unsigned int i=0; i<nruns; i++){
if (rp[i].continue_if_possible & file_exists(rp[i].data_folder+"data_log.dat") & file_exists(rp[i].data_folder+"H_N.dat") & file_exists(rp[i].data_folder+"checkpoint.ckp")){
//do nothing if files are found; only continue if all files of all systems are there
}
else{
continue_simulation=false;
}
}
if (continue_simulation){
std::cout<<"Continuing.... "<<std::endl;
for (unsigned int i=0; i<nruns; i++){
outfile_om[i].open(rp[i].data_folder+"snapshots.om", std::ios::out | std::ios::binary | std::ios::app);
outfile_data[i].open(rp[i].data_folder+"data_log.dat", std::ios::app);
outfile_histogram[i].open(rp[i].data_folder+"H_N.dat", std::ios::app);
outfile_k_N0[i].open(rp[i].data_folder+"k_N0.dat", std::ios::app);
//will pick the last t_final here; they should be all equal
load_from_checkpoint(mesh[i], uw[i], t_final, rp[i].data_folder+"checkpoint.ckp", input_files[i]);
}
}
else{
std::cout<<"New simulation.... "<<std::endl;
for (unsigned int i=0; i<nruns; i++){
outfile_om[i].open(rp[i].data_folder+"snapshots.om", std::ios::out | std::ios::binary);
outfile_data[i].open(rp[i].data_folder+"data_log.dat");
outfile_histogram[i].open(rp[i].data_folder+"H_N.dat");
outfile_k_N0[i].open(rp[i].data_folder+"k_N0.dat");
outfile_data[i]<<"t"<<"\t"<<"key" <<"\t" <<"n_f" <<"\t"<<"n_v"<<"\t"<<"n_e"<<"\t"<< "E_el"<<"\t"<<"E_full"<<std::endl;
}
}
/*************/
// auto mesh_props = OpenMesh::MProp<MeshProp>(mesh, "mesh_props");
std::vector<OpenMesh::MProp<MeshProp>> mesh_props;// = OpenMesh::MProp<MeshProp>(mesh[0], "mesh_props");
std::vector<OpenMesh::FProp<FaceProp>> face_props;
for (unsigned int i=0; i<nruns; i++){
mesh_props.push_back( OpenMesh::MProp<MeshProp>(mesh[i], "mesh_props") );
face_props.push_back( OpenMesh::FProp<FaceProp>(mesh[i], "face_props") );
}
//histogram; counts up to 1000 subunits
//std::vector<int> H_N(1000, 0);
unsigned int i;
//pick the smallest of all timesteps
long t_min=rp[0].timesteps;
for (i=0; i<nruns; i++){
if (rp[i].timesteps < t_min){
t_min = rp[i].timesteps;
}
}
int ix1, ix2, n1, n2, fpos;
double r, p, E1, E2, kT1, kT2, wtf, a, b;
double betaUi, betaUj, betaUi_swapped, betaUj_swapped;
bool parallel;
MyMesh * mesh_tmp;
std::vector<MyMesh*> mesh_ptr;
std::vector<OpenMesh::MProp<MeshProp>*> mesh_props_ptr;
for (i=0; i<nruns; i++){
mesh_ptr.push_back(&mesh[i]);
mesh_props_ptr.push_back(&mesh_props[i]);
}
auto start = std::chrono::system_clock::now();
// Some computation here
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
//std::time_t end_time = std::chrono::system_clock::to_time_t(end);
std::vector<int> n_faces;
std::vector<int> sorted_i;
std::ofstream swapfile;
std::string pt_datafolder = pt_params["data_folder"];
pt_datafolder=getenv_str("tmp_dir")+pt_datafolder;
system(("mkdir -p "+pt_datafolder).c_str());
swapfile.open(pt_datafolder+"swap_file.dat");
omlog();
//main loop
while (t_final<t_min){
t_init = t_final;
t_final = t_init + dt_exchange;//rp.nsteps_umbrella; //<--- needs to change to min( dt_exchange, rp[i].nsteps_umbrella ); timesteps will be the min(rp[i].timesteps)
//std::cout<<"--- tinit, tfinal "<<t_init<<" "<<t_final<<std::endl;
parallel=true;//(*mesh_ptr[0]).n_faces()>30;
//should loop over a sorted array to make sure largest n_faces() meshes get to separate threads
//build the vector to be sorted first
n_faces.clear();
for (i=0; i<nruns; i++){
n_faces.push_back( (*mesh_ptr[i]).n_faces() );
}
//----
//#pragma omp parallel for private(i) schedule(static) if(parallel)
/* #pragma omp parallel for private(i) if(parallel)
for (i=0; i<nruns; i++){
propagate(*mesh_ptr[i], t_init, t_final, rp[i], outfile_om[i], outfile_data[i], uw[i], engines[i]);
}
*/
sorted_i = sort_indexes(n_faces);
/*std::cout<<"----- sorted_i------"<<std::endl;
for (auto j: sorted_i){
std::cout<<j<<std::endl;
}*/
#pragma omp parallel for private(i) schedule(static, 1) if(parallel)
for (i=0; i<nruns; i++){
propagate(*mesh_ptr[sorted_i[i]], t_init, t_final, rp[sorted_i[i]], outfile_om[sorted_i[i]], outfile_data[sorted_i[i]], uw[sorted_i[i]], engines[sorted_i[i]], AM[sorted_i[i]]);
}
//std::cout<<"exchanging..."<<std::endl;
//EXCHANGE ATTEMPT HERE ----
ix1 = randint(nruns, exch_engine);//int(rand() % nruns);
ix2 = randint(nruns, exch_engine);//int(rand() % nruns);
n1 = (*mesh_ptr[ix1]).n_faces();
n2 = (*mesh_ptr[ix2]).n_faces();
betaUi = ( full_energy(*mesh_ptr[ix1]) + uw[ix1].bias_potential(n1) - full_mu_N(*mesh_ptr[ix1]) ) / (**mesh_props_ptr[ix1]).kT;
betaUj = ( full_energy(*mesh_ptr[ix2]) + uw[ix2].bias_potential(n2) - full_mu_N(*mesh_ptr[ix2]) ) / (**mesh_props_ptr[ix2]).kT;
swap_configurations(*mesh_ptr[ix1], *mesh_ptr[ix2]);
std::swap(mesh_ptr[ix1], mesh_ptr[ix2]);
std::swap(mesh_props_ptr[ix1], mesh_props_ptr[ix2]);
//swap_uw(uw[ix1], uw[ix2]);
n1 = (*mesh_ptr[ix1]).n_faces();
n2 = (*mesh_ptr[ix2]).n_faces();
betaUi_swapped = ( full_energy(*mesh_ptr[ix1]) + uw[ix1].bias_potential(n1) - full_mu_N(*mesh_ptr[ix1]) ) / (**mesh_props_ptr[ix1]).kT;
betaUj_swapped = ( full_energy(*mesh_ptr[ix2]) + uw[ix2].bias_potential(n2) - full_mu_N(*mesh_ptr[ix2]) ) / (**mesh_props_ptr[ix2]).kT;
p = exp( -betaUi_swapped - betaUj_swapped + betaUi + betaUj );
//r = rand()/(RAND_MAX + 1.0);
r = randdouble(exch_engine);//
if (r<p){
//std::cout<<"swapped "<<ix1<<" "<<ix2<<" "<<std::setprecision(10)<<p<<" "<<betaUi<<" "<<betaUi_swapped <<" "<<-betaUi_swapped - betaUj_swapped + betaUi + betaUj<<std::endl;
swapfile<<t_final<<" "<<ix1<<" "<<ix2<<std::endl;
}
else{
//std::cout<<"swap rejected, swapping back "<<ix1<<" "<<ix2<<std::endl;
swap_configurations(*mesh_ptr[ix1], *mesh_ptr[ix2]);
std::swap(mesh_ptr[ix1], mesh_ptr[ix2]);
std::swap(mesh_props_ptr[ix1], mesh_props_ptr[ix2]);
//swap_uw(uw[ix1], uw[ix2]);
//switch capsids
//mesh_tmp
//std::cout<<std::setprecision(10)<<"pre "<<full_binding_energy(mesh[ix1])<<" "<<full_binding_energy(mesh[ix2])<<std::endl;
//std::cout<<std::setprecision(10)<<"pre "<<full_mu_N(mesh[ix1])<<" "<<full_mu_N(mesh[ix2])<<std::endl;
//std::cout<<"----> swap "<<ix1<<" "<<ix2<<std::endl;
//std::cout<<"E_b "<< std::setprecision(40)<< full_binding_energy(mesh[ix1])<<" "<<full_binding_energy(mesh[ix2])<<std::endl;
//std::cout<<"E_elast "<< std::setprecision(40)<< full_elastic_energy(mesh[ix1])<<" "<<full_elastic_energy(mesh[ix2])<<std::endl;
//std::cout<<"mu N "<< std::setprecision(40)<<"post "<<full_mu_N(mesh[ix1])<<" "<<full_mu_N(mesh[ix2])<<std::endl;
//swap_configurations(mesh[ix1], mesh[ix2]);
//std::cout<<" sw E_b "<< std::setprecision(20)<< full_binding_energy(mesh[ix1])<<" "<<full_binding_energy(mesh[ix2])<<std::endl;
//swap_configurations(mesh[ix1], mesh[ix2]);
//
//std::cout<<"<-------- "<<std::endl;
//std::cout<<"E_b "<< std::setprecision(40)<< full_binding_energy(mesh[ix1])<<" "<<full_binding_energy(mesh[ix2])<<std::endl;
//std::cout<<"E_elast "<< std::setprecision(40)<< full_elastic_energy(mesh[ix1])<<" "<<full_elastic_energy(mesh[ix2])<<std::endl;
//std::cout<<"mu N "<< std::setprecision(40)<<"post "<<full_mu_N(mesh[ix1])<<" "<<full_mu_N(mesh[ix2])<<std::endl;
//std::cout<<"swapped "<<ix1<<" "<<ix2<<std::endl;
//std::cout<<std::setprecision(10)<<"post "<<full_binding_energy(mesh[ix1])<<" "<<full_binding_energy(mesh[ix2])<<std::endl; //switch temperatures too; better define a switch_capsid function
//std::cout<<std::setprecision(10)<<"post "<<full_mu_N(mesh[ix1])<<" "<<full_mu_N(mesh[ix2])<<std::endl;
//this can get more complicated when tempering for e_b, mu, etc. because then prototype subunits have to be changed too
}
//shift the umbrella windows;
//individually?... depending on each nsteps_umbrella?
for (i=0; i<nruns; i++){
if (t_final % rp[i].nsteps_umbrella == 0){
outfile_k_N0[i]<<uw[i].N0<<"\t"<< uw[i].spring_const <<std::endl;
uw[i].N0+=rp[i].dN_umbrella;
//std::cout<<"umbrella N0="<<uw.N0<<std::endl;
for (int N: uw[i].values){
H_N[i][N]++;
}
for (const auto &hi : H_N[i]) outfile_histogram[i] << hi <<"\t";
outfile_histogram[i] << std::endl;
uw[i].values.clear();
std::fill(H_N[i].begin(), H_N[i].end(), 0);
if (i==0){
end = std::chrono::system_clock::now();
std::cout<< "elapsed time: " << elapsed_seconds.count() <<" "<<(*mesh_ptr[0]).n_faces()<< std::endl;
elapsed_seconds = end-start;
//start=end;
}
}
//clear umbrella window values after burnin time is reached; that's when sampling begins
if ((t_final - rp[i].dt_burnin) % rp[i].nsteps_umbrella == 0 ){
uw[i].values.clear();
}
//need dt dump here, not nstep umbrella
/*if (t_final % rp[i].nsteps_umbrella == 0){
if (t_final>rp[i].dtskip){
fpos = dump_om(*mesh_ptr[i], t_final, outfile_om[i]);
}
else{
fpos=-1;
}
dump_data(*mesh_ptr[i], t_final, outfile_data[i], fpos);
}*/