root / bin / main.cpp @ 1
Historique | Voir | Annoter | Télécharger (6,59 ko)
1 | 1 | akiss | #include <iostream> |
---|---|---|---|
2 | 1 | akiss | #include <string.h> |
3 | 1 | akiss | #include <stdlib.h> |
4 | 1 | akiss | #include <stdio.h> |
5 | 1 | akiss | #include <time.h> |
6 | 1 | akiss | #include "step.h" |
7 | 1 | akiss | #include "constants.h" |
8 | 1 | akiss | #include <math.h> |
9 | 1 | akiss | #include <fstream> |
10 | 1 | akiss | #include "minimize_BFGS.h" |
11 | 1 | akiss | #include <omp.h> |
12 | 1 | akiss | #include <dirent.h> |
13 | 1 | akiss | #include "save_data.h" |
14 | 1 | akiss | #include "save_data_2.h" |
15 | 1 | akiss | #include <cmath> |
16 | 1 | akiss | #include "compute_lengths.h" |
17 | 1 | akiss | #include "optimize_width.h" |
18 | 1 | akiss | |
19 | 1 | akiss | using namespace std; |
20 | 1 | akiss | |
21 | 1 | akiss | int main(){
|
22 | 1 | akiss | |
23 | 1 | akiss | /// initialization of the seed for the random number generator
|
24 | 1 | akiss | srand(time(NULL));
|
25 | 1 | akiss | |
26 | 1 | akiss | /// parallelizing over the 3 loops
|
27 | 1 | akiss | #pragma omp parallel for collapse(3) schedule(dynamic,1) |
28 | 1 | akiss | for (int index_growth=0;index_growth<=4;index_growth+=1){ // law for growth of the veins |
29 | 1 | akiss | for (int index_stress=11;index_stress<=20;index_stress+=1){ // level of applied stress |
30 | 1 | akiss | for (int index_tissue=1;index_tissue<=57;index_tissue+=1){ // index of the tissue |
31 | 1 | akiss | |
32 | 1 | akiss | //growth=2;
|
33 | 1 | akiss | growth=index_growth; |
34 | 1 | akiss | growth_threshold=6;//10.; |
35 | 1 | akiss | //growth_threshold=1.+12.*(double)index_growth/20.;
|
36 | 1 | akiss | //growth_threshold=0.6*(1.+12.*(double)index_growth/20.);
|
37 | 1 | akiss | stress_x=0.;
|
38 | 1 | akiss | |
39 | 1 | akiss | /// the folder in which the data are saved
|
40 | 1 | akiss | char folder[32]; strcpy(folder,"optimized_2/"); |
41 | 1 | akiss | /// in this folder, the folder corresponding to each growth mode
|
42 | 1 | akiss | char growth_char[32]; //sprintf(growth_char,"%d/",index_growth); |
43 | 1 | akiss | if (growth==0){ strcpy(growth_char,"linear/");} |
44 | 1 | akiss | if (growth==1){ strcpy(growth_char,"saturated/");} |
45 | 1 | akiss | if (growth==2){ strcpy(growth_char,"threshold/");} |
46 | 1 | akiss | if (growth==3){ strcpy(growth_char,"quadratic/");} |
47 | 1 | akiss | if (growth==4){ strcpy(growth_char,"max/");} |
48 | 1 | akiss | /// in this folder, the folder corresponding to the external stress level, then the beginning of the name of the file which corresponds to the index of the initial condition
|
49 | 1 | akiss | char indices[8]; sprintf(indices,"%i/%i_",index_stress,index_tissue); |
50 | 1 | akiss | /// the total path to the file which will be saved
|
51 | 1 | akiss | char file_name[256]; strcpy(file_name,"results/"); strcat(file_name,folder); strcat(file_name,growth_char); strcat(file_name,indices); |
52 | 1 | akiss | |
53 | 1 | akiss | /// extraction of the intial data from Yohai
|
54 | 1 | akiss | int vertex_number, edge_number, cell_number;
|
55 | 1 | akiss | double * width; width=(double*)calloc(1,sizeof(double)); |
56 | 1 | akiss | double * height; height=(double*)calloc(1,sizeof(double)); |
57 | 1 | akiss | |
58 | 1 | akiss | char file_name_init[256]; |
59 | 1 | akiss | sprintf(file_name_init,"/home/jjulien/Documents/Programmation/Leaf/Init/%i.toy",index_tissue);
|
60 | 1 | akiss | |
61 | 1 | akiss | ifstream file; |
62 | 1 | akiss | file.open(file_name_init); |
63 | 1 | akiss | file >> width[0];
|
64 | 1 | akiss | file >> height[0];
|
65 | 1 | akiss | file >> vertex_number; |
66 | 1 | akiss | file >> edge_number; |
67 | 1 | akiss | file >> cell_number; |
68 | 1 | akiss | |
69 | 1 | akiss | |
70 | 1 | akiss | double * vertices; vertices=(double*)calloc(2*vertex_number,sizeof(double)); |
71 | 1 | akiss | double * lengths; lengths=(double*)calloc(edge_number,sizeof(double)); /* lengths of the walls */ |
72 | 1 | akiss | double * rest_lengths; rest_lengths=(double*)calloc(edge_number,sizeof(double)); /* targets of the walls */ |
73 | 1 | akiss | double * edges_width; edges_width=(double*)calloc(edge_number,sizeof(double)); |
74 | 1 | akiss | int * edges_cells; edges_cells=(int*)calloc(2*edge_number,sizeof(int)); |
75 | 1 | akiss | int * edges_vertices; edges_vertices=(int*)calloc(2*edge_number,sizeof(double)); |
76 | 1 | akiss | int * periodizer; periodizer=(int*)calloc(4*edge_number,sizeof(double)); |
77 | 1 | akiss | |
78 | 1 | akiss | int count=0; |
79 | 1 | akiss | while (count<(2*vertex_number)){ |
80 | 1 | akiss | |
81 | 1 | akiss | file >> vertices[count]; |
82 | 1 | akiss | count++; |
83 | 1 | akiss | } |
84 | 1 | akiss | |
85 | 1 | akiss | count=0;
|
86 | 1 | akiss | while (count<edge_number){
|
87 | 1 | akiss | |
88 | 1 | akiss | file >> edges_cells[2*count];
|
89 | 1 | akiss | file >> edges_cells[2*count+1]; |
90 | 1 | akiss | file >> edges_vertices[2*count];
|
91 | 1 | akiss | file >> periodizer[4*count];
|
92 | 1 | akiss | file >> periodizer[4*count+1]; |
93 | 1 | akiss | file >> edges_vertices[2*count+1]; |
94 | 1 | akiss | file >> periodizer[4*count+2]; |
95 | 1 | akiss | file >> periodizer[4*count+3]; |
96 | 1 | akiss | file >> rest_lengths[count]; |
97 | 1 | akiss | file >> edges_width[count]; |
98 | 1 | akiss | count++; |
99 | 1 | akiss | } |
100 | 1 | akiss | /// extraction of the initial data over
|
101 | 1 | akiss | |
102 | 1 | akiss | |
103 | 1 | akiss | /// optimization of the width of the veins in order to get an homogeneous stress, then saving of the tissue
|
104 | 1 | akiss | optimize_width(vertex_number, vertices, edge_number, edges_vertices, lengths, rest_lengths, edges_width, periodizer, width, height); |
105 | 1 | akiss | compute_lengths(vertices, edges_vertices, edge_number, lengths, periodizer, width[0], height[0]); |
106 | 1 | akiss | sigma=sqrt(30.*width[0]*height[0]/(pi*cell_number)); |
107 | 1 | akiss | {FILE *f=NULL; char file_name_2[256]; strcpy(file_name_2,file_name); strcat(file_name_2,"optimized.sce"); |
108 | 1 | akiss | f=fopen(file_name_2,"w+");
|
109 | 1 | akiss | save_data(f, vertex_number, vertices, edge_number, edges_vertices, lengths, rest_lengths, edges_width, edges_cells, periodizer, width[0], height[0], cell_number); |
110 | 1 | akiss | fclose(f);} // width optimized
|
111 | 1 | akiss | |
112 | 1 | akiss | /// noise in the width of the veins in order to get the non-affinity index consistent with the experimental data
|
113 | 1 | akiss | for (int i=0; i<edge_number; i++){ edges_width[i]*=1.+0.4*(2.*(double)rand()/(double)RAND_MAX-1.);} |
114 | 1 | akiss | |
115 | 1 | akiss | //{
|
116 | 1 | akiss | // double mean_width=0.;
|
117 | 1 | akiss | // for (int i=0; i<edge_number; i++){ mean_width+=edges_width[i];}
|
118 | 1 | akiss | // mean_width/=edge_number;
|
119 | 1 | akiss | // growth_threshold/=mean_width;
|
120 | 1 | akiss | //}
|
121 | 1 | akiss | |
122 | 1 | akiss | /// application of the external stretching, then saving of the tissue
|
123 | 1 | akiss | stress_x=(double)index_stress/10.; |
124 | 1 | akiss | minimize_BFGS(vertex_number, vertices, edge_number, edges_vertices, lengths, rest_lengths, edges_width, periodizer, width, height); |
125 | 1 | akiss | compute_lengths(vertices, edges_vertices, edge_number, lengths, periodizer, width[0], height[0]); //for (int i=0; i<edge_number;i++){printf("%f \n",(lengths[i]/*-rest_lengths[i]*/)/(rest_lengths[i]));} |
126 | 1 | akiss | sigma=sqrt(30.*width[0]*height[0]/(pi*cell_number)); |
127 | 1 | akiss | {FILE *f=NULL; char file_name_2[256]; strcpy(file_name_2,file_name); strcat(file_name_2,"before.sce"); |
128 | 1 | akiss | f=fopen(file_name_2,"w+");
|
129 | 1 | akiss | save_data(f, vertex_number, vertices, edge_number, edges_vertices, lengths, rest_lengths, edges_width, edges_cells, periodizer, width[0], height[0], cell_number); |
130 | 1 | akiss | fclose(f);} // tissue stretched
|
131 | 1 | akiss | |
132 | 1 | akiss | /// growth until the tissue double its size
|
133 | 1 | akiss | int iteration=0.; double max_area=2.*width[0]*height[0]; |
134 | 1 | akiss | while ((width[0]*height[0])<max_area){ |
135 | 1 | akiss | |
136 | 1 | akiss | step(vertices, vertex_number, edge_number, edges_vertices, lengths, rest_lengths, edges_width, periodizer, width, height); |
137 | 1 | akiss | compute_lengths(vertices, edges_vertices, edge_number, lengths, periodizer, width[0], height[0]); |
138 | 1 | akiss | |
139 | 1 | akiss | iteration++; printf("%d %d %d\n",index_stress,index_tissue, iteration);
|
140 | 1 | akiss | } // end of growth
|
141 | 1 | akiss | |
142 | 1 | akiss | /// saving of the tissue
|
143 | 1 | akiss | minimize_BFGS(vertex_number, vertices, edge_number, edges_vertices, lengths, rest_lengths, edges_width, periodizer, width, height); |
144 | 1 | akiss | compute_lengths(vertices, edges_vertices, edge_number, lengths, periodizer, width[0], height[0]); |
145 | 1 | akiss | sigma=sqrt(30.*width[0]*height[0]/(pi*cell_number)); |
146 | 1 | akiss | {FILE *f=NULL; char file_name_2[256]; strcpy(file_name_2,file_name); strcat(file_name_2,"after.sce"); |
147 | 1 | akiss | f=fopen(file_name_2,"w+");
|
148 | 1 | akiss | save_data_2(f, vertex_number, vertices, edge_number, edges_vertices, lengths, rest_lengths, edges_width, edges_cells, periodizer, width[0], height[0], cell_number); |
149 | 1 | akiss | fclose(f);} /// tissue saved
|
150 | 1 | akiss | |
151 | 1 | akiss | /// free the memory
|
152 | 1 | akiss | free(vertices); free(edges_vertices); free(lengths); free(rest_lengths); free(edges_width); free(edges_cells); free(periodizer); free(width); free(height); |
153 | 1 | akiss | }}} |
154 | 1 | akiss | |
155 | 1 | akiss | return 0; |
156 | 1 | akiss | } |