-
Notifications
You must be signed in to change notification settings - Fork 0
/
pressure_ABM
1610 lines (1498 loc) · 67.9 KB
/
pressure_ABM
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 "general_libraries.h"
#include "cell_abm.h"
#include "main_abm_oxy.h"
#include "chrono"
//###########################################################################
// 0 - Dead Cells
// 1 - Tumor Cells
// 2 - Proliferative Tumor Cells
// 3 - Hypoxic Tumor Cells
// 4 - Dying Tumor Cells
// 5 - G1 Tumor Cells
// 6 - Normoxic Cells
// 7 - Endothelial Cells
// 8 - Tip Cells
// 9 - Stalk Cells
// 10 - Activated Tip Cells
// 11 - Growing Stalk Cells
//###########################################################################
vector<Cell> Cells_global;
Number exact_value_ox(const Point& ,const Parameters& ,const std::string& ,const std::string& ){return 0.0;}
Number exact_value_vessel(const Point& ,const Parameters& ,const std::string& ,const std::string& ){return 0.0;}
double triangle_area(const Point& e1,const Point& e2,const Point& e3){return 0.5*fabs((e1(0)-e3(0))*(e2(1)-e1(1))-(e1(0)-e2(0))*(e3(1)-e1(1)));}
//double triangle_area(const Point& e1,const Point& e2,const Point& e3){return 0.5*fabs( e1(0)*(e2(1)-e3(1)) + e2(0)*(e3(1)-e1(1)) + e3(0)*(e1(1)-e2(1)) );}
double scalar_prod(const Point& e1,const Point& e2){return e1(0)*e2(0)+e1(1)*e2(1);}
void main_code(int argc, char** argv,MPI_Comm lib_comm,vector<double> Parameters,int file_number){
// The parameters follow this order
//double nut_d,double nut_coeff,double con_t,double vegf_diff,double vegf_prod,double vegf_cons
//========== Initialize the library ==========
LibMeshInit init (argc, argv,lib_comm);
//========== Declare cells list ==========****
list <Cell> Cells_local;
list <Cell> Cells_vessel_start;
list <Cell> Cells_vessel_end;
list <Cell*> Tip_local;
vector<Cell> Cells_tip;
//========== Read argumments ==========
GetPot input_file("options.in");
const bool read_solution = input_file("read_solution",0);
const bool verbose = input_file("verbose",0);
const bool unbreakable = input_file("unbreakable",0);
const bool deactivation = input_file("deactivation",0);
const bool anastomosis = input_file("anastomosis",0);
const int max_tip_cells = input_file("max_tip_cells",100);
const bool dirichlet = input_file("dirichlet",0);
const unsigned int n_elements = input_file("n_elements",20);
const unsigned int n_timesteps = input_file("n_timesteps",100);
const unsigned int initial_tum = input_file("initial_tum",20);
int init_timestep = input_file("init_timestep",0);
const unsigned int print_inter = input_file("print_inter",100);
const unsigned int ic_type = input_file("ic_type",1);
const unsigned int rand_seed = input_file("rand_seed",7);
const unsigned int max_outside = input_file("max_outside",1500);
const std::string mesh_name = input_file("mesh_name", "rec_struct.msh");
const unsigned int read_mesh = input_file("read_mesh",0);
const double initial_con = input_file("initial_con",20.0);
const double con_b = input_file("con_b",1.0);
const double con_n = input_file("con_n",1.0);
const double end_r = input_file("end_r",1.0);
const double domain_diameter = input_file("domain_diameter",1.0);
const double time_step = input_file("time_step",0.05);
const double prol_intens = input_file("prol_intens",1.0);
const double nucleus_radius = input_file("nucleus_radius",5.295);
const double cell_radius = input_file("cell_radius",9.953);
const double action_prop = input_file("action_prop",1.214);
const double c_ccr = input_file("c_ccr",10.0);
const double c_eea = input_file("c_eea",0.588836);
const double mesh_x = input_file("mesh_x",800);
const double mesh_y = input_file("mesh_y",400);
//int tip_cell_c = input_file("tip_cell_c",0);
Ran ran(rand_seed);
int outside_cells = 0;
int total_tumor = initial_tum;
char buffer[30];
char buffer2[30];
ofstream out_data;
std::stringstream cell_holder;
std::string extension = ".txt";
//cell_holder << "cells_dice_test" << file_number << extension;
//std::string file = cell_holder.str();
//out_data.open(file);
ofstream dice;
std::stringstream cell_hold;
// cell_hold << "dice" << t_step << extension;
cell_hold << "dice" << file_number << extension;
std::string dice_file = cell_hold.str();
dice.open(dice_file);
/*ofstream out_data2;
std::stringstream cell_holder2;
cell_holder2 << "density" << file_number << extension;
std::string file2 = cell_holder2.str();
out_data2.open(file2); */
//========== Create a uniform mesh ==========
SerialMesh mesh(init.comm());
if(!read_solution){
if(read_mesh){
mesh.read(mesh_name);
}
else{
cout <<"made it to here" << endl;
MeshTools::Generation::build_cube (mesh,
n_elements,
n_elements,
0,
0., mesh_x,
0., mesh_y,
0., 0.,
QUAD9);
cout <<"and made it out!" << endl;
mesh.write("mesh.msh");
}
}
else{
mesh.read(mesh_name);
}
if(verbose){mesh.print_info();}
double H_MAX = 0;
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
for ( ; el != end_el ; ++el){
const Elem* elem = *el;
if(H_MAX<elem->hmax())
H_MAX = elem->hmax();
}
//========== Create an equation systems object and set a simulation-specific parameter ==========
//0 - nut_d, 1 - nut_coeff, 2 - con_t, 3 - vegf_diff, 4 - vegf_prod, 5 - vegf_cons
//
EquationSystems equation_systems(mesh);
equation_systems.parameters.set<Real> ("vegf_ths") = Parameters[0];
equation_systems.parameters.set<Real> ("vegf_diff") = Parameters[1];
equation_systems.parameters.set<Real> ("vegf_cons") = Parameters[2]; // pg/mL per hour per cell
equation_systems.parameters.set<Real> ("vegf_prod") = Parameters[3]; // 0.08477 pg/mL per hour per cell
// equation_systems.parameters.set<Real> ("tip_distance") = Parameters[4];
equation_systems.parameters.set<Real> ("tip_distance") = 8;
// equation_systems.parameters.set<Real> ("vegf_diff") = 600;
// equation_systems.parameters.set<Real> ("vegf_diff") = 419; // microns^2 / 10 minutes PSYCH THIS IS 6 MINUTES
// equation_systems.parameters.set<Real> ("vegf_cons") = 0.001; // pg/mL per hour per cell
// equation_systems.parameters.set<Real> ("vegf_cons") = Parameters[1];
//equation_systems.parameters.set<Real> ("tip_distance") = Parameters[3];
equation_systems.parameters.set<Real> ("tau_E_time") = 24;
equation_systems.parameters.set<Real> ("stalk_divide_time") = 24;
equation_systems.parameters.set<Real> ("stalk_growth_time") = 6;
equation_systems.parameters.set<Real> ("nut_coeff") = 0;//3.5*Parameters[3];
equation_systems.parameters.set<Real> ("nut_d") = 200.0;
equation_systems.parameters.set<Real> ("con_t") = 2.0;
//equation_systems.parameters.set<Real> ("vegf_prod") = Parameters[0];
equation_systems.parameters.set<Real> ("c_ccr") = c_ccr;
equation_systems.parameters.set<Real> ("c_eea") = c_eea;
// equation_systems.parameters.set<Real> ("nut_coeff") = 0;
// equation_systems.parameters.set<Real> ("vegf_ths") = vegf_ths;
//equation_systems.parameters.set<Real> ("tip_distance") = Parameters[1];
equation_systems.parameters.set<Real> ("repulsion_distance") = 1.1;
equation_systems.parameters.set<Real> ("con_b") = con_b;
equation_systems.parameters.set<Real> ("con_n") = con_n;
equation_systems.parameters.set<Real> ("end_r") = end_r;
equation_systems.parameters.set<Real> ("time_step_size") = time_step;
equation_systems.parameters.set<int> ("initial_tumor") = total_tumor;
equation_systems.parameters.set<bool> ("deactivation") = deactivation;
equation_systems.parameters.set<bool> ("unbreakable") = unbreakable;
equation_systems.parameters.set<bool> ("anastomosis") = anastomosis;
equation_systems.parameters.set<int> ("max_tip_cells") = max_tip_cells;
equation_systems.parameters.set<int> ("ic_type") = ic_type;
equation_systems.parameters.set<Real> ("initial_con") = initial_con;
equation_systems.parameters.set<Real> ("nucleus_radius") = nucleus_radius;
equation_systems.parameters.set<Real> ("cell_radius") = cell_radius;
equation_systems.parameters.set<Real> ("action_radius") = action_prop*cell_radius;
equation_systems.parameters.set<Real> ("apop_time") = 8.6;
// equation_systems.parameters.set<Real> ("g1_time") = 9.0;
equation_systems.parameters.set<Real> ("g1_time") = 13.0;
equation_systems.parameters.set<Real> ("lysing_time") = 6.0;
equation_systems.parameters.set<Real> ("calc_time") = 360.0;
// equation_systems.parameters.set<Real> ("cellc_time") = 18.0;
equation_systems.parameters.set<Real> ("cellc_time") = 18.0;
equation_systems.parameters.set<Real> ("hypoxic_thrs") = 0.3;
equation_systems.parameters.set<Real> ("prol_intes") = prol_intens/1.921166667;
equation_systems.parameters.set<Real> ("apop_intes") = 1.0/786.61;
equation_systems.parameters.set<Real> ("delta_tt") = 1.0;
equation_systems.parameters.set<Real> ("f_NS") = 1.0;
equation_systems.parameters.set<Real> ("lambda_cell") = 0.1;
equation_systems.parameters.set<Real> ("domain_diameter") = domain_diameter;
equation_systems.parameters.set<Real> ("max_out_cells") = max_outside;
equation_systems.parameters.set<Real> ("h_max_mesh") = H_MAX;
equation_systems.parameters.set<Real> ("mesh_x") = mesh_x;
equation_systems.parameters.set<Real> ("mesh_y") = mesh_y;
equation_systems.parameters.set<list <Cell> *>("l_cells") = &Cells_local;
//========== Declare the system ==========
TransientLinearImplicitSystem &vegf = equation_systems.add_system<TransientLinearImplicitSystem> ("VEGF");
TransientLinearImplicitSystem &nutr = equation_systems.add_system<TransientLinearImplicitSystem> ("Nutrient");
TransientLinearImplicitSystem &vessel = equation_systems.add_system<TransientLinearImplicitSystem> ("Vessel");
TransientLinearImplicitSystem &pressure = equation_systems.add_system<TransientLinearImplicitSystem> ("Pressure");
ExplicitSystem &velocity = equation_systems.add_system<ExplicitSystem>("Velocity");
TransientLinearImplicitSystem &drug = equation_systems.add_system<TransientLinearImplicitSystem>("Drug");
if(!read_solution){
//========== Timestep always 0 ==============
init_timestep = 0;
//========== Declare the variables ==========
unsigned int v_var = vegf.add_variable("vegf_var", FIRST);
unsigned int nut_var = nutr.add_variable("nut_var", FIRST);
unsigned int ves_var = vessel.add_variable("ves_var", FIRST);
unsigned int pres_var = pressure.add_variable("pres_var", SECOND);
unsigned int drug_var = drug.add_variable("drug_var", FIRST);
velocity.add_variable("vel_x", FIRST);
velocity.add_variable("vel_y", FIRST);
//nutr.add_variable("nut_var", FIRST);
//========== Matrix assembly and initial condition functions ==========
vegf.attach_assemble_function(assemble_vegf);
drug.attach_assemble_function(assemble_vegf);
nutr.attach_assemble_function(assemble_ox);
pressure.attach_assemble_function(assemble_pressure);
drug.attach_assemble_function(assemble_drug);
nutr.attach_init_function(initial_condition_ox);
// I dont' believe pressure needs an intitial condition,
// since it doesn't evolve in time in the classical sense.
// vessel.attach_assemble_function(assemble_vessel);
// vegf.attach_init_function(initial_condition_vegf);
// vessel.attach_init_function(initial_condition_vessel);
//========== Initialize the data structures for the equation system ==========
// Let's set pressure to 1 on the top serface.
// I'm not actually sure that the mesh has anything
// like this labeled. Maybe set everything to 1..? Lol
std::set<boundary_id_type> boundary_ids_one;
if(read_mesh){
boundary_ids_one.insert(0);
}
else{
boundary_ids_one.insert(0);
boundary_ids_one.insert(1);
boundary_ids_one.insert(2);
boundary_ids_one.insert(3);
}
std::vector<unsigned int> variables;
variables.push_back(v_var);
ConstFunction<Number> bc_value(0.0);
std::vector<unsigned int> vessel_variables;
vessel_variables.push_back(ves_var);
ConstFunction<Number> bcves_value(0.0);
//std::vector<unsigned int> pressure_variables;
//pressure_variables.push_back(pres_var);
//ConstFunction<Number> bcpres_value(0.0);
if(dirichlet){
DirichletBoundary dirichlet_bc_one(boundary_ids_one,variables,&bc_value);
vegf.get_dof_map().add_dirichlet_boundary(dirichlet_bc_one);
DirichletBoundary dirichlet_bc_two(boundary_ids_one,vessel_variables,&bcves_value);
vessel.get_dof_map().add_dirichlet_boundary(dirichlet_bc_two);
}
//DirichletBoundary dirichlet_bc_pres(boundary_ids_one,pressure_variables,&bcpres_value);
//pressure.get_dof_map().add_dirichlet_boundary(dirichlet_bc_pres);
std::vector<unsigned int> variablesn;
variablesn.push_back(nut_var);
ConstFunction<Number> bcnut_value(1.0);
//DirichletBoundary dirichlet_bc_two(boundary_ids_one,variablesn,&bcnut_value);
//nutr.get_dof_map().add_dirichlet_boundary(dirichlet_bc_two);
equation_systems.init();
init_cond_cells(Cells_local,equation_systems.parameters,ran);
}
else{
std::stringstream ss;
std::string ext = ".e";
ss << "saved_solution" << file_number << "_" << setfill('0') << setw(5) << init_timestep << ext;
std::string results = ss.str();
//equation_systems.read(results, libMeshEnums::READ);
equation_systems.read(results);
vegf.update();
nutr.update();
// vessel.update();
//========== Initialize the data structures for the equation system ==========
unsigned int v_var = vegf.variable_number("vegf_var");
unsigned int nut_var = nutr.variable_number("nut_var");
unsigned int ves_var = vessel.variable_number("ves_var");
unsigned int pres_var = pressure.add_variable("pres_var", SECOND);
unsigned int drug_var = drug.add_variable("drug_var", FIRST);
velocity.add_variable("vel_x", FIRST);
velocity.add_variable("vel_y", FIRST);
std::set<boundary_id_type> boundary_ids_one;
if(read_mesh){
boundary_ids_one.insert(0);
}
else{
boundary_ids_one.insert(0);
boundary_ids_one.insert(1);
boundary_ids_one.insert(2);
boundary_ids_one.insert(3);
}
std::vector<unsigned int> variables;
variables.push_back(v_var);
ConstFunction<Number> bc_value(0.0);
std::vector<unsigned int> vessel_variables;
variables.push_back(ves_var);
ConstFunction<Number> bcves_value(0.0);
//std::vector<unsigned int> pressure_variables;
//pressure_variables.push_back(pres_var);
//ConstFunction<Number> bcpres_value(1.0);
if(dirichlet){
DirichletBoundary dirichlet_bc_one(boundary_ids_one,variables,&bc_value);
vegf.get_dof_map().add_dirichlet_boundary(dirichlet_bc_one);
DirichletBoundary dirichlet_bc_two(boundary_ids_one,vessel_variables,&bcves_value);
vessel.get_dof_map().add_dirichlet_boundary(dirichlet_bc_two);
}
//DirichletBoundary dirichlet_bc_pres(boundary_ids_one,pressure_variables,&bcpres_value);
//pressure.get_dof_map().add_dirichlet_boundary(dirichlet_bc_pres);
DirichletBoundary dirichlet_bc_two(boundary_ids_one,vessel_variables,&bcves_value);
vessel.get_dof_map().add_dirichlet_boundary(dirichlet_bc_two);
std::vector<unsigned int> variablesn;
variablesn.push_back(nut_var);
ConstFunction<Number> bcnut_value(1.0);
//DirichletBoundary dirichlet_bc_two(boundary_ids_one,variablesn,&bcnut_value);
//nutr.get_dof_map().add_dirichlet_boundary(dirichlet_bc_two);
vegf.attach_assemble_function(assemble_vegf);
nutr.attach_assemble_function(assemble_ox);
pressure.attach_assemble_function(assemble_pressure);
drug.attach_assemble_function(assemble_drug);
// vessel.attach_assemble_function(assemble_vessel);
equation_systems.reinit();
std::stringstream abm;
std::string extension = ".txt";
abm << "results" << file_number << "_" << setfill('0') << setw(5) << init_timestep << extension;
std::string Caleb = abm.str();
restart_function(Cells_local,Tip_local,Caleb);
}
if(verbose){
equation_systems.print_info();
sprintf(buffer, "exo%d.e",file_number);
ExodusII_IO(mesh).write_equation_systems(buffer,equation_systems);
save_cells(Cells_local,domain_diameter,"saida",file_number,0);
print_order(Cells_local,domain_diameter,"output",file_number,init_timestep);
save_grad_vegf(equation_systems,"grad_vegf",file_number,0);
//out_data << 0.0 << " " << Cells_global.size() << " " << total_tumor << " " << outside_cells << " " << initial_con << endl;
/*
const std::vector<double> vec;
vessel.write_serialized_vector(io,&vec);
springf(buffer,"field_test.txt");
for(int caleb = 0; caleb < vec.size(); caleb++){
out_data2 << vec[caleb] << endl;
}
*/
}
//========== Loop over time ==========
unsigned int t_step = init_timestep;
do{
//========== Increase time_step counter ==========
//cout << "time_step = " << t_step << ", file_number = " << file_number << endl;
t_step++;
vegf.time = t_step*time_step;
nutr.time = t_step*time_step;
vessel.time = t_step*time_step;
drug.time = t_step*time_step;
//========== Copy solution of previous time step ==========
*vegf.old_local_solution = *vegf.current_local_solution;
*nutr.old_local_solution = *nutr.current_local_solution;
*drug.old_local_solution = *drug.current_local_solution;
*vessel.old_local_solution = *vessel.current_local_solution;
cout << "pre-update_states: file number = " << file_number << endl;
//========== Solve ABM system ==========
if( t_step < 3000 ){
update_states(Cells_local,Tip_local,Cells_vessel_start,Cells_vessel_end,t_step,ran,equation_systems,outside_cells);
cout << "post-update_states: file number = " << file_number << endl;
if(verbose && t_step%print_inter==0){
print_order(Cells_local,domain_diameter,"output",file_number,-t_step);
}
compute_forces(Cells_local,Tip_local,Cells_vessel_start,Cells_vessel_end,equation_systems,domain_diameter,outside_cells,t_step);
cout << "post-compute_forces: final number = " << file_number << endl;
/////----- Solve systems -----/////
// if( t_step%2==0){
// vegf.solve();
cout << "post-vegf: final number = " << file_number << endl;
if(verbose && t_step%print_inter==0){
auto start = std::chrono::steady_clock::now();
pressure.solve();
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
cout << "pressure_compute time: = " << elapsed_seconds.count() << endl;
//cout << "post-pres " << endl;
// compute_velocity(equation_systems);
cout << "post-vel " << endl;
// drug.solve();
}
}else{
// compute drug delivery equation
drug.solve();
}
// nutr.solve();
// }
//cout << "post-solve" << endl;
if(verbose && t_step%print_inter==0){
save_cells(Cells_local,domain_diameter,"saida",file_number,t_step);
print_order(Cells_local,domain_diameter,"output",file_number,t_step);
save_grad_vegf(equation_systems,"grad_vegf",file_number,t_step);
//-- Save system to restart later --//
std::stringstream abm;
std::string extension = ".txt";
abm << "results" << file_number << "_" << setfill('0') << setw(5) << t_step << extension;
std::string Caleb = abm.str();
restart_save(Cells_local,Caleb);
std::stringstream ss;
std::string ext = ".e";
ss << "saved_solution" << file_number << "_" << setfill('0') << setw(5) << t_step << ext;
std::string results = ss.str();
libmesh_assert_equal_to(libMesh::processor_id(), 0);
//equation_systems.write(results, libMeshEnums::WRITE);
equation_systems.write(results);
//========== Write output to paraview ==========
ExodusII_IO exo(mesh);
exo.append(true);
exo.write_timestep(buffer, equation_systems, t_step+1, vegf.time);
//}
/*
ofstream dice;
std::stringstream cell_hold;
// cell_hold << "dice" << t_step << extension;
cell_hold << "paper_generate_flow" << t_step << extension;
std::string dice_file = cell_hold.str();
dice.open(dice_file);
vector<double> dice_vec((mesh_x-1)*(mesh_y-1));
double area;
get_dice_vec(equation_systems,t_step,dice_vec,area);
for(int caleb = 0; caleb < dice_vec.size(); caleb++){
//out_data2 << dice_vec[caleb] << endl;
dice << dice_vec[caleb] << endl;
} */
}
double confluence = 0.;
int Quiescent = 0, Proliferative = 0, Hypoxic = 0, Necrotic = 0, Stalk = 0, Endothelial = 0;
std::list<Cell>::iterator it;
for(it = Cells_local.begin(); it != Cells_local.end(); ++it){
confluence += std::pow((*it).C_radius,2)/std::pow(0.5*domain_diameter,2);
if((*it).state == 1) Quiescent += 1;
if((*it).state == 2) Proliferative += 1;
if((*it).state == 3) Hypoxic += 1;
if((*it).state == 0) Necrotic += 1;
if((*it).state == 9 || (*it).state == 11) Stalk += 1;
if((*it).state == 7) Endothelial += 1;
}
int total_t = Quiescent + Proliferative + Hypoxic + Necrotic;
if(verbose){
cout << "==================================================" << endl;
cout << "Confluence = " << confluence << endl;
cout << "Number of cells = " << Cells_local.size() << endl;
cout << "Tumor cells = " << total_t << endl;
cout << "Necrotic cells = " << Necrotic << endl; // 5
cout << "Quiescent cells = " << Quiescent << endl; // 2
cout << "Proliferative cells = " << Proliferative << endl; // 3
cout << "Hypoxic cells = " << Hypoxic << endl; // 4
cout << "Endothelial cells = " << Endothelial << endl; // 7
cout << "Tip cells = " << Tip_local.size() << endl; // 1
cout << "Stalk cells = " << Stalk << endl; // 6
cout << "Outside cells = " << outside_cells << endl;
cout << "Time = " << t_step << endl;
cout << "==================================================" << endl;
}
//out_data << t_step << " " << Necrotic << " " << Quiescent << " " << Proliferative << " " << Hypoxic << " " << Endothelial << " " << Tip_local.size() << " " << Stalk << endl;
}while(t_step<n_timesteps);
const Real vegf_ths = equation_systems.parameters.get<Real>("vegf_ths");
const Real vegf_diff = equation_systems.parameters.get<Real>("vegf_diff");
const Real vegf_cons = equation_systems.parameters.get<Real>("vegf_cons");
const Real tip_distance = equation_systems.parameters.get<Real>("tip_distance");
dice << vegf_ths << " " << vegf_diff << " " << vegf_cons << " " << tip_distance << endl;
//out_data.close();
//out_data2.close();
Cells_global.clear();
}
void save_grad_vegf(EquationSystems& es,string s,int file_number,int t){
const char *c = s.c_str();
char n[100],name[200];
sprintf(n,"%d_%05d.m",file_number,t);
strcpy(name,c);
strcat(name,n);
stringstream ss;
string name_s;
ss << name;
ss >> name_s;
ofstream out_file;
out_file.open (name_s);
//=======*** Saving the data =====***==//
const MeshBase& mesh = es.get_mesh();
out_file << "grad = zeros(" << mesh.n_elem() << "," << 4 << ");" <<endl;
out_file << "grad = [";
const unsigned int dim = mesh.mesh_dimension();
TransientLinearImplicitSystem & system = es.get_system<TransientLinearImplicitSystem>("VEGF");
const unsigned int v_nut = system.variable_number("vegf_var");
const DofMap& dof_map = system.get_dof_map();
FEType fe_type = dof_map.variable_type(0);
UniquePtr<FEBase> fe (FEBase::build(dim, fe_type));
QGauss qrule (dim, fe_type.default_quadrature_order());
fe->attach_quadrature_rule (&qrule);
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
std::vector<dof_id_type> dof_indices;
std::vector<dof_id_type> dof_indices_nut;
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
for ( ; el != end_el ; ++el){
const Elem* elem = *el;
dof_map.dof_indices(elem,dof_indices);
dof_map.dof_indices(elem,dof_indices_nut,v_nut);
fe->reinit(elem);
unsigned int qp=0;
Gradient gradient_vegf;
for(unsigned int l=0; l<dof_indices.size(); l++){
gradient_vegf.add_scaled(dphi[l][qp], system.old_solution(dof_indices[l]));
}
out_file << elem->centroid()(0) << " " << elem->centroid()(1) << " " << gradient_vegf(0) << " " << gradient_vegf(1) << endl;
}
out_file << "];";
out_file.close();
}
void compute_velocity(EquationSystems& es){
const MeshBase & mesh = es.get_mesh();
const unsigned int dim = mesh.mesh_dimension();
// To compute velocity, we need u = -k(x)\grad(p)
// we need vessel to compute k(x)
// we need pressure to compute \grad(p)
TransientLinearImplicitSystem & ves_sys = es.get_system<TransientLinearImplicitSystem>("Vessel");
TransientLinearImplicitSystem & pres_sys = es.get_system<TransientLinearImplicitSystem>("Pressure");
ExplicitSystem & vel_sys = es.get_system<ExplicitSystem>("Velocity");
//cout << "check 1" <<endl;
unsigned int velocity_vars[2];
velocity_vars[0] = vel_sys.variable_number ("vel_x");
velocity_vars[1] = vel_sys.variable_number ("vel_y");
const DofMap& velocity_dof_map = vel_sys.get_dof_map();
std::vector<dof_id_type> velocity_dof_indices_var;
//cout << "check 2" <<endl;
const DofMap& dof_map = pres_sys.get_dof_map();
FEType fe_type = dof_map.variable_type(0);
UniquePtr<FEBase> fe (FEBase::build(dim, fe_type));
QGauss qrule (dim, fe_type.default_quadrature_order());
fe->attach_quadrature_rule (&qrule);
std::vector<dof_id_type> dof_indices;
//cout << "check 3" <<endl;
const std::vector<std::vector<Real>> & phi = fe->get_phi();
const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
const std::vector<Real>& JxW = fe->get_JxW();
//cout << "check 4" <<endl;
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
for ( ; el != end_el ; ++el){
const Elem* elem = *el;
dof_map.dof_indices(elem,dof_indices);
fe->reinit(elem);
double k_0 = 1.0; // tissue permeability
double k_S = 1.0; // vessel surface permeability
double k_V = 100.0; // vessel permeability
double kappa = 0;
Gradient velocity_grad = 0.;
// cout << "check 5" <<endl;
for(unsigned int qp=0; qp<qrule.n_points(); qp++){
double vessel_value = 0;
for(unsigned int l=0; l<dof_indices.size(); l++){
vessel_value += phi[l][qp]*ves_sys.current_solution(dof_indices[l]);
} // dof
/* if( vessel_value >= 0.9){
kappa = k_0 + k_V*vessel_value;
}else if( vessel_value >= 0.1 && vessel_value <= 0.9){
kappa = k_S; // + k_V*vessel_value;
} else
kappa = k_0; */
kappa = k_0 + k_V*vessel_value;
// kappa = 1.0 * pow(10,4);
for(unsigned int l=0; l<dof_indices.size(); l++){
// cout << "check 8" <<endl;
velocity_grad.add_scaled(dphi[l][qp],-kappa*pres_sys.current_solution(dof_indices[l]));
// cout << "check 9" <<endl;
} // dof
//vel_sys.solution->set(dof_indices, velocity_quad);
} // quadrature points
for(unsigned int j=0; j<2; j++){
velocity_dof_map.dof_indices (elem, velocity_dof_indices_var, velocity_vars[j]);
dof_id_type dof_index = velocity_dof_indices_var[0];
if( (vel_sys.solution->first_local_index() <= dof_index) && (dof_index < vel_sys.solution->last_local_index()) ){
vel_sys.solution->set(dof_index, velocity_grad(j));
}
}
} // element
}
void assemble_vegf(EquationSystems& es,const std::string& libmesh_dbg_var(system_name)){
libmesh_assert_equal_to (system_name, "VEGF");
const MeshBase& mesh = es.get_mesh();
const unsigned int dim = mesh.mesh_dimension();
TransientLinearImplicitSystem & system = es.get_system<TransientLinearImplicitSystem>("VEGF");
TransientLinearImplicitSystem &ves = es.get_system<TransientLinearImplicitSystem>("Vessel");
const unsigned int v_nut = system.variable_number("vegf_var");
const Real time_size = es.parameters.get<Real>("time_step_size");
const Real vegf_diff = es.parameters.get<Real>("vegf_diff");
const Real vegf_prod = es.parameters.get<Real>("vegf_prod");
const Real vegf_cons = es.parameters.get<Real>("vegf_cons");
//cout << " in assemble_vegf vegf_cons = " << vegf_cons << endl;
const Real ac_radius = es.parameters.get<Real>("action_radius");
const Real h_max_msh = es.parameters.get<Real>("h_max_mesh");
const Real height = es.parameters.get<Real>("domain_diameter");
const Real mesh_x = es.parameters.get<Real>("mesh_x");
const Real mesh_y = es.parameters.get<Real>("mesh_y");
list <Cell> *Cells_local = es.parameters.get<list <Cell> *>("l_cells");
const double h_bin = ac_radius+h_max_msh;
const int number_bins0 = ceil(mesh_x/h_bin);
const int number_bins1 = ceil(mesh_y/h_bin);
const int total_bins = number_bins0*number_bins1;
//========== Generate bins ==========
vector< list < Cell * > > Cell_Bins(total_bins);
std::list<Cell>::iterator it;
for(it = Cells_local->begin(); it != Cells_local->end(); ++it){
int ix = floor((*it).x/h_bin);
int jy = floor((*it).y/h_bin);
int xy = ix+jy*number_bins0;
if((*it).x<0 || (*it).y<0 || (*it).x> mesh_x || (*it).y> mesh_y || jy>=number_bins1 || ix>=number_bins0 || xy >=total_bins){
cout << "Error" << endl;
cout << "Cell = ( " << (*it).x << " , " << (*it).y << " ) = ( " << ix << " , " << jy << " ) = " << xy << endl;
cout << "State = " << (*it).state << endl;
cout << "total_bins = " << total_bins << endl;
cout << "number_bins0 = " << number_bins0 << endl;
cout << "number_bins1 = " << number_bins1 << endl;
cout << "h_bin = " << h_bin << endl;
getchar();
}
Cell_Bins[xy].push_back(&*it);
}
//========== Continue stnd ==========
// cout << "honestly no idea what's happening" << endl;
const DofMap& dof_map = system.get_dof_map();
FEType fe_type = dof_map.variable_type(0);
UniquePtr<FEBase> fe (FEBase::build(dim, fe_type));
QGauss qrule (dim, fe_type.default_quadrature_order());
fe->attach_quadrature_rule (&qrule);
const std::vector<Real>& JxW = fe->get_JxW();
const std::vector<std::vector<Real> >& phi = fe->get_phi();
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
DenseMatrix<Number> Ke;
DenseVector<Number> Fe;
std::vector<dof_id_type> dof_indices;
std::vector<dof_id_type> dof_indices_nut;
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
// cout << "yeah?" << endl;
for ( ; el != end_el ; ++el){
const Elem* elem = *el;
//========== Computed volume fraction ==========
Point e_center = elem->centroid();
int ix = floor(e_center(0)/h_bin);
int jy = floor(e_center(1)/h_bin);
double p_t,p_n,p_h,p_e,p_s;
double elem_volume = elem->volume();
p_t = p_n = p_h = p_e = p_s = 0.;
for(int xx = -1; xx<=1; xx++){
if(ix+xx>=0 && ix+xx<number_bins0){
for(int yy = -1; yy<=1; yy++){
if(jy+yy>=0 && jy+yy<number_bins1){
int bin_xy = (ix+xx)+(jy+yy)*number_bins0;
std::list<Cell*>::iterator cell_ab;
for(cell_ab = Cell_Bins[bin_xy].begin(); cell_ab != Cell_Bins[bin_xy].end(); ++cell_ab){
if( (*(*cell_ab)).state == 0 || (*(*cell_ab)).state == 4) continue;
else{
Point p( (*(*cell_ab)).x,(*(*cell_ab)).y,0.);
double area_computed = 0.;
// if(elem->type()==3){
// area_computed = area_inside_tri(p,elem->point(0),elem->point(1),elem->point(2),(*(*cell_ab)).C_radius,elem_volume);
// }
// else{
cout <<"area_computed? " <<endl;
cout <<"nope " <<endl;
area_computed = area_inside_quad(p,elem->point(0),elem->point(1),elem->point(2),elem->point(3),(*(*cell_ab)).C_radius);
// }
// this is the area computed for the element but really I want to divide area_computed by area_cell
if(area_computed > 0){
double area = 3.1415926535* pow( (*(*cell_ab)).C_radius,2);
//2 if((*(*cell_ab)).state == 6) p_n+=(area_computed/elem_volume);
if((*(*cell_ab)).state == 6) p_n+=(area_computed/area);
else if((*(*cell_ab)).state == 3) p_h+=(area_computed/area);
else if((*(*cell_ab)).prev_state == 7) p_e+=(area_computed/area);
else if((*(*cell_ab)).state == 9) p_e+=(area_computed/area);
else if((*(*cell_ab)).state == 11) p_e+=(area_computed/area);
else if((*(*cell_ab)).state == 8) p_e+=(area_computed/area);
else if((*(*cell_ab)).prev_state == 13) p_e+=(area_computed/area);
else if((*(*cell_ab)).prev_state == 14) p_e+=(area_computed/area);
else p_t+=(area_computed/area);
}
}
}
}
}
}
}
// p_e still lives here.
cout << "is it vessel" << endl;
// if(p_e > 0 || (e_center(0) >= 2.254*20+35-9.953/2.0 && e_center(0) <= 2.254*20+58+9.953/2.0) ){
// if(p_e > 0 || (e_center(0) >= 2 && e_center(0) <= 2.254*20+23+9.953/2.0) ){
if(p_e > 0 || (e_center(0) >= 2 && e_center(0) <=28+9.953/2.0) ){
cout <<"did it fail in vessel loop?" <<endl;
for(unsigned int caleb = 0; caleb<elem->n_nodes(); caleb++){
vector<double> value(1);
vector<unsigned int> position(1,elem->node_id(caleb));
(ves.solution)->get(position,value);
(ves.solution)->set(elem->node_id(caleb),1);//value[0]+0.1*(1.0-value[0]));
cout << "value = " << value[0] << endl;
}
cout <<"nope, not fail in vessel loop" <<endl;
}
//cout << " yes it vessel" << endl;
/*else{
cout << " is it vessel" << endl;
for(unsigned int caleb = 0; caleb<elem->n_nodes(); caleb++){
vector<double> value(1);
vector<unsigned int> position(1,elem->node(caleb));
(ves.solution)->get(position,value);
(ves.solution)->set(elem->node(caleb),0);
}
}*/
//========== Continue stnd ==========
dof_map.dof_indices(elem,dof_indices);
dof_map.dof_indices(elem,dof_indices_nut,v_nut);
fe->reinit(elem);
Ke.resize(dof_indices.size(),dof_indices.size());
Fe.resize(dof_indices.size());
//cout << "vegf_cons = " << vegf_cons << ", p_e = " << p_e << endl;
for (unsigned int qp=0; qp<qrule.n_points(); qp++){
Number vegf_old = 0.0;
for(unsigned int l=0; l<phi.size(); l++){
vegf_old += phi[l][qp]*system.old_solution(dof_indices_nut[l]);
}
for (unsigned int i=0; i<phi.size(); i++){
Fe(i) += JxW[qp]*(vegf_old
+time_size*p_h*vegf_prod
)*phi[i][qp];
for (unsigned int j=0; j<phi.size(); j++){
Ke(i,j) += JxW[qp]*time_size*vegf_diff*dphi[i][qp]*dphi[j][qp];
Ke(i,j) += JxW[qp]*(1.0+time_size*(p_h*vegf_prod+(p_e+p_s)*vegf_cons))*phi[i][qp]*phi[j][qp];
}
}
}
//cout << "pre fancy" << endl;
dof_map.heterogenously_constrain_element_matrix_and_vector(Ke,Fe,dof_indices);
system.matrix->add_matrix (Ke,dof_indices);
system.rhs->add_vector (Fe,dof_indices);
//cout << "post fancy" << endl;
}
}
void assemble_drug(EquationSystems& es,const std::string& libmesh_dbg_var(system_name)){
libmesh_assert_equal_to (system_name, "Drug");
const MeshBase& mesh = es.get_mesh();
const unsigned int dim = mesh.mesh_dimension();
TransientLinearImplicitSystem &system = es.get_system<TransientLinearImplicitSystem>("Drug");
TransientLinearImplicitSystem &vessel = es.get_system<TransientLinearImplicitSystem>("Vessel");
TransientLinearImplicitSystem &vegf = es.get_system<TransientLinearImplicitSystem>("VEGF");
ExplicitSystem &vel_sys = es.get_system<ExplicitSystem>("Velocity");
const unsigned int u_var = vel_sys.variable_number ("vel_x");
const unsigned int v_var = vel_sys.variable_number ("vel_y");
const unsigned int v_drug = system.variable_number("drug_var");
const Real time_size = es.parameters.get<Real>("time_step_size");
const Real vegf_diff = es.parameters.get<Real>("vegf_diff");
const Real vegf_prod = es.parameters.get<Real>("vegf_prod");
const Real vegf_cons = es.parameters.get<Real>("vegf_cons");
const Real ac_radius = es.parameters.get<Real>("action_radius");
const Real h_max_msh = es.parameters.get<Real>("h_max_mesh");
const Real height = es.parameters.get<Real>("domain_diameter");
const Real mesh_x = es.parameters.get<Real>("mesh_x");
const Real mesh_y = es.parameters.get<Real>("mesh_y");
list <Cell> *Cells_local = es.parameters.get<list <Cell> *>("l_cells");
const double h_bin = ac_radius+h_max_msh;
const int number_bins0 = ceil(mesh_x/h_bin);
const int number_bins1 = ceil(mesh_y/h_bin);
const int total_bins = number_bins0*number_bins1;
const DofMap& dof_map = system.get_dof_map();
const DofMap& dof_vel = vel_sys.get_dof_map();
FEType fe_type = dof_map.variable_type(0);
UniquePtr<FEBase> fe (FEBase::build(dim, fe_type));
UniquePtr<FEBase> fe_face (FEBase::build(dim, fe_type));
QGauss qrule (dim, fe_type.default_quadrature_order());
QGauss qface (dim-1, fe_type.default_quadrature_order());
fe->attach_quadrature_rule (&qrule);
fe_face->attach_quadrature_rule (&qface);
const std::vector<Real>& JxW = fe->get_JxW();
const std::vector<Real>& JxW_face = fe_face->get_JxW();
const std::vector<std::vector<Real> >& phi = fe->get_phi();
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
const std::vector<std::vector<Real> >& phi_face = fe_face->get_phi();
const std::vector<std::vector<RealGradient> >& dphi_face = fe_face->get_dphi();
const std::vector<Point> & qface_points = fe_face->get_xyz();
const std::vector<Point> & normals = fe_face->get_normals();
DenseMatrix<Number> Ke;
DenseVector<Number> Fe;
std::vector<dof_id_type> dof_indices;
std::vector<dof_id_type> dof_indices_drug;
std::vector<dof_id_type> dof_indices_u;
std::vector<dof_id_type> dof_indices_v;
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
double x_min = 35; // 12*2.2;
double x_max = 58; // 20*2.2;
double y_min = mesh_y - (250+12.2);
double y_max = mesh_y - 250;
double y_max_out = 12.2;
double y_min_out = 0;
for ( ; el != end_el ; ++el){
const Elem* elem = *el;
Point e_center = elem->centroid();
int ix = floor(e_center(0)/h_bin);
int jy = floor(e_center(1)/h_bin);
double p_t,p_n,p_h,p_e,p_s;
double elem_volume = elem->volume();
p_t = p_n = p_h = p_e = p_s = 0.;
dof_map.dof_indices(elem,dof_indices);
dof_map.dof_indices(elem,dof_indices_drug,v_drug);
dof_vel.dof_indices(elem,dof_indices_u,u_var);
dof_vel.dof_indices(elem,dof_indices_v,v_var);
fe->reinit(elem);
Ke.resize(dof_indices.size(),dof_indices.size());
Fe.resize(dof_indices.size());
for (unsigned int qp=0; qp<qrule.n_points(); qp++){
Gradient grad_drug_old;
Number drug_old = 0.0;
RealVectorValue vel_sol;
Number velocity_x = 0.0;
Number velocity_y = 0.0;
for(unsigned int l=0; l<phi.size(); l++){
drug_old += phi[l][qp]*system.old_solution(dof_indices_drug[l]);
grad_drug_old.add_scaled(dphi[l][qp], system.old_solution (dof_indices[l]));
vel_sol(0) += phi[l][qp]*vel_sys.current_solution(dof_indices_u[l]);
vel_sol(1) += phi[l][qp]*vel_sys.current_solution(dof_indices_v[l]);
}
for (unsigned int i=0; i<phi.size(); i++){
bool matrix_set = 0;
Fe(i) += JxW[qp]*(drug_old)*phi[i][qp];
for (unsigned int j=0; j<phi.size(); j++){
vector<double> vessel_value(1);
for(unsigned int caleb = 0; caleb < elem->n_nodes(); caleb++)
{
vector<unsigned int> position(1,elem->node_id(caleb));
(vessel.solution)->get(position,vessel_value);
if(vessel_value[0] >= 1)
vessel_value[0] = 1;
}
double diff_ves = 1000.0;
double diff_tissue = 10.0;
double diffusion = diff_tissue + diff_ves*vessel_value[0];
Ke(i,j) += JxW[qp]*time_size*(diffusion)*dphi[i][qp]*dphi[j][qp];
Ke(i,j) += JxW[qp]*(1.0)*phi[i][qp]*phi[j][qp];
Ke(i,j) += JxW[qp]*vel_sol*dphi[j][qp]*phi[i][qp];
double h = 2.254;
double h_min = elem->hmin();
double h_max = elem->hmax();
double anorm = sqrt( pow( vel_sol(0) , 2) + pow(vel_sol(1),2) );
double Pe = h_max*anorm / (2*diffusion);
double tau = (h_max/(2*anorm)) * (1/tanh(Pe) - 1/(Pe) );
Ke(i,j) += JxW[qp]*tau* (vel_sol*dphi[j][qp])* vel_sol*dphi[i][qp];
}// j
}// i
}// qp
if(system.time < 4*0.05)
{
double value = 0.;
for(auto s : elem->side_index_range())
if(elem->neighbor_ptr(s) == nullptr)
{
Point e_center = elem->centroid();
if( e_center(0) <= 2.254*20+58 && e_center(0) >= 2.254*20+35 && system.time < 10)
{
fe_face->reinit(elem, s);
if( e_center(1) > 100){
value = 1.e-2;
}else if( e_center(1) < 100){
}
if( abs(value) > .0001 ){
for (unsigned int qp=0; qp<qface.n_points(); qp++)
{
cout << "system.time = " << system.time << endl;
for (std::size_t i = 0; i<phi.size(); i++)
Fe(i) += JxW_face[qp]*value*phi_face[i][qp];
}
}
}
}
}
dof_map.heterogenously_constrain_element_matrix_and_vector(Ke,Fe,dof_indices);
system.matrix->add_matrix (Ke,dof_indices);
system.rhs->add_vector (Fe,dof_indices);
}
}
void assemble_pressure(EquationSystems& es,const std::string& libmesh_dbg_var(system_name)){
libmesh_assert_equal_to (system_name, "Pressure");
const MeshBase& mesh = es.get_mesh();
const unsigned int dim = mesh.mesh_dimension();
TransientLinearImplicitSystem & system = es.get_system<TransientLinearImplicitSystem>("Pressure");
TransientLinearImplicitSystem & vessel = es.get_system<TransientLinearImplicitSystem>("Vessel");
const unsigned int pres_nut = system.variable_number("pres_var");
const Real time_size = es.parameters.get<Real>("time_step_size");
const Real mesh_x = es.parameters.get<Real>("mesh_x");
const Real mesh_y = es.parameters.get<Real>("mesh_y");
/* I don't think any of this is necessary
*/
//========== Continue stnd ==========
const DofMap& dof_map = system.get_dof_map();
FEType fe_type = dof_map.variable_type(0);
UniquePtr<FEBase> fe (FEBase::build(dim, fe_type));
UniquePtr<FEBase> fe_face (FEBase::build(dim, fe_type));
QGauss qrule (dim, FIFTH); // fe_type.default_quadrature_order());
QGauss qface (dim-1, FIFTH);//fe_type.default_quadrature_order());
fe->attach_quadrature_rule (&qrule);
fe_face->attach_quadrature_rule (&qface);
const std::vector<Real>& JxW = fe->get_JxW();
//const std::vector<Real>& JxW_face = fe_face->get_JxW();
const std::vector<std::vector<Real> >& phi = fe->get_phi();
//const std::vector<std::vector<Real> >& psi = fe_face->get_phi();
const std::vector<std::vector<RealGradient> >& dphi = fe->get_dphi();
// const std::vector<Point> & qface_points = fe_face->get_xyz();
DenseMatrix<Number> Ke;
DenseVector<Number> Fe;
std::vector<dof_id_type> dof_indices;
// std::vector<dof_id_type> dof_indices_nut;
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
double x_min = 12*2.2;
double x_max = 20*2.2;
double y_min = mesh_y - 12.2;
double y_max = mesh_y;
double y_max_out = 12.2;
double y_min_out = 0;
auto start2 = std::chrono::steady_clock::now();
// check inlet conditions
for ( ; el != end_el ; ++el){
const Elem* elem = *el;
//========== Computed volume fraction ==========
// Here is the element centroid.. is that enough information?
Point e_center = elem->centroid();
//========== Continue stnd ==========
dof_map.dof_indices(elem,dof_indices);
// dof_map.dof_indices(elem,dof_indices_nut,pres_nut);
const unsigned int n_dofs =
cast_int<unsigned int>(dof_indices.size());
//cout << "n_dofs = " << n_dofs << endl;