Statistiques
| Révision :

root / bin / save_data.cpp @ 1

Historique | Voir | Annoter | Télécharger (5,09 ko)

1
#include <string.h>
2
#include <stdlib.h>
3
#include <stdio.h>
4
#include "save_data.h"
5
#include <math.h>
6
#include "constants.h"
7
#include <gsl/gsl_matrix.h>
8
#include <gsl/gsl_blas.h>
9
#include <gsl/gsl_eigen.h>
10
#include <gsl/gsl_math.h>
11
#include <gsl/gsl_cblas.h>
12
#include <gsl/gsl_linalg.h>
13
/* this function saves the tissue and its chemical and mechanical state */
14

    
15
void save_data(FILE *f, int vertices_number, double *vertices, int cell_number, int *vertices_number_in_each_cell, int *cells_vertices, int wall_number,
16
               double *barycenters, double *stress_periclinal, double *stress_anticlinal, int *boundary, double *cell_areas, double *lengths,
17
               double *shapes, double *targets, double *growth_rate, int *cell_walls){
18

    
19
int i,j;//,k,min,max,index;
20

    
21
gsl_matrix *matrix=gsl_matrix_calloc(2,2); gsl_eigen_symmv_workspace *workspace=gsl_eigen_symmv_alloc(2);
22
gsl_vector *eigenvalues=gsl_vector_alloc(2); gsl_matrix *eigenvectors=gsl_matrix_alloc(2,2);
23
int max_eigenvalue;
24

    
25
fprintf(f,"//shear_modulus %f lame_periclinal %f  lame_anticlinal %f\n",shear_modulus,lame_first_periclinal,lame_first_anticlinal);
26
fprintf(f,"cell_number= %i;\n",cell_number);
27
fprintf(f,"vertices_number= %i;\n",vertices_number);
28
fprintf(f,"wall_number= %i;\n",wall_number);
29
fprintf(f,"ablated_cell= %i;\n",ablated_cell);
30

    
31
fprintf(f,"vertices=[\n");
32
for (i=0;i<vertices_number;i++){
33
    fprintf(f,"%f %f\n",vertices[2*i],vertices[2*i+1]);}
34
fprintf(f,"];\n");
35

    
36
fprintf(f,"vertices_number_in=[\n");
37
for (i=0;i<cell_number+1;i++){
38
    fprintf(f,"%i\n",vertices_number_in_each_cell[i]);}
39
fprintf(f,"];\n");
40

    
41
fprintf(f,"cells_vertices=[\n");
42
for (i=0;i<cell_number;i++){
43
    for (j=vertices_number_in_each_cell[i];j<vertices_number_in_each_cell[i+1];j++){
44
        fprintf(f,"%i\n",cells_vertices[j]);}}
45
fprintf(f,"];\n");
46

    
47
//fprintf(f,"cell_walls=[\n");
48
//for (i=0;i<cell_number;i++){
49
//    for (j=vertices_number_in_each_cell[i];j<vertices_number_in_each_cell[i+1];j++){
50
//        fprintf(f,"%i\n",cell_walls[j]);}}
51
//fprintf(f,"];\n");
52

    
53
fprintf(f,"growth_rate=[ ");
54
for (i=0;i<cell_number;i++){
55
    fprintf(f,"%f \n",growth_rate[i]);}
56
fprintf(f," ];\n");
57

    
58
fprintf(f,"barycenters=[ ");
59
for (i=0;i<cell_number;i++){fprintf(f,"%f %f\n",barycenters[2*i],barycenters[2*i+1]);}
60
fprintf(f," ];\n");
61

    
62
fprintf(f,"cell_areas=[ ");
63
for (i=0;i<cell_number;i++){fprintf(f,"%f\n",cell_areas[i]);}
64
fprintf(f," ];\n");
65

    
66
fprintf(f,"stress=[");
67
for (int i=0; i<cell_number;i++){
68
    gsl_matrix_set(matrix,0,0,stress_periclinal[3*i]); gsl_matrix_set(matrix,1,1,stress_periclinal[3*i+1]);
69
    gsl_matrix_set(matrix,1,0,stress_periclinal[3*i+2]); gsl_matrix_set(matrix,0,1,stress_periclinal[3*i+2]);
70
    gsl_eigen_symmv(matrix,eigenvalues,eigenvectors,workspace);
71
    max_eigenvalue=0; if (gsl_vector_get(eigenvalues,1)>gsl_vector_get(eigenvalues,0)){max_eigenvalue=1;}
72
    fprintf(f,"%f %f %f %f\n",gsl_vector_get(eigenvalues,max_eigenvalue),gsl_vector_get(eigenvalues,1-max_eigenvalue),
73
            copysign(1.,gsl_matrix_get(eigenvectors,0,max_eigenvalue))*gsl_matrix_get(eigenvectors,0,max_eigenvalue),
74
            copysign(1.,gsl_matrix_get(eigenvectors,0,max_eigenvalue))*gsl_matrix_get(eigenvectors,1,max_eigenvalue));
75
}
76
fprintf(f," ];\n");
77

    
78
//fprintf(f,"stress_anticlinal=[");
79
//for (i=0;i<wall_number;i++){fprintf(f,"%f %f %f\n",stress_anticlinal[3*i],stress_anticlinal[3*i+1],stress_anticlinal[3*i+2]);}
80
//fprintf(f," ];\n");
81

    
82
fprintf(f,"shapes=[");
83
for (int i=0; i<cell_number;i++){
84
    gsl_matrix_set(matrix,0,0,shapes[3*i]); gsl_matrix_set(matrix,1,1,shapes[3*i+1]);
85
    gsl_matrix_set(matrix,1,0,shapes[3*i+2]); gsl_matrix_set(matrix,0,1,shapes[3*i+2]);
86
    gsl_eigen_symmv(matrix,eigenvalues,eigenvectors,workspace);
87
    max_eigenvalue=0; if (gsl_vector_get(eigenvalues,1)>gsl_vector_get(eigenvalues,0)){max_eigenvalue=1;}
88
    fprintf(f,"%f %f %f %f\n",gsl_vector_get(eigenvalues,max_eigenvalue),gsl_vector_get(eigenvalues,1-max_eigenvalue),
89
            copysign(1.,gsl_matrix_get(eigenvectors,0,max_eigenvalue))*gsl_matrix_get(eigenvectors,0,max_eigenvalue),
90
            copysign(1.,gsl_matrix_get(eigenvectors,0,max_eigenvalue))*gsl_matrix_get(eigenvectors,1,max_eigenvalue));
91
}
92
fprintf(f," ];\n");
93

    
94

    
95
fprintf(f,"targets=[");
96
for (int i=0; i<cell_number;i++){
97
    gsl_matrix_set(matrix,0,0,targets[3*i]); gsl_matrix_set(matrix,1,1,targets[3*i+1]);
98
    gsl_matrix_set(matrix,1,0,targets[3*i+2]); gsl_matrix_set(matrix,0,1,targets[3*i+2]);
99
    gsl_eigen_symmv(matrix,eigenvalues,eigenvectors,workspace);
100
    max_eigenvalue=0; if (gsl_vector_get(eigenvalues,1)>gsl_vector_get(eigenvalues,0)){max_eigenvalue=1;}
101
    fprintf(f,"%f %f %f %f\n",gsl_vector_get(eigenvalues,max_eigenvalue),gsl_vector_get(eigenvalues,1-max_eigenvalue),
102
            copysign(1.,gsl_matrix_get(eigenvectors,0,max_eigenvalue))*gsl_matrix_get(eigenvectors,0,max_eigenvalue),
103
            copysign(1.,gsl_matrix_get(eigenvectors,0,max_eigenvalue))*gsl_matrix_get(eigenvectors,1,max_eigenvalue));
104
}
105
fprintf(f," ];\n");
106

    
107
//fprintf(f,"boundary=[");
108
//for (i=0;i<cell_number;i++){
109
//    for (j=vertices_number_in_each_cell[i];j<vertices_number_in_each_cell[i+1];j++){
110
//        fprintf(f,"%d\n",boundary[j]);}}
111
//fprintf(f," ];\n");
112

    
113
}