Trisurf Monte Carlo simulator
Samo Penic
2012-07-13 672ae43d88ba88cf1f4183511bd56f90c7c4d2ed
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
#include<stdio.h>
#include<math.h>
#include "general.h"
#include "vertex.h"
#include "bond.h"
#include "triangle.h"
#include "cell.h"
#include "vesicle.h"
#include "io.h"
#include "initial_distribution.h"
#include "frame.h"
#include "timestep.h"
#include "sh.h"
 
/** Entrance function to the program
  * @param argv is a number of parameters used in program call (including the program name
  * @param argc is a pointer to strings (character arrays) which holds the arguments
  * @returns returns 0 on success, any other number on fail.
*/
ts_bool saveAvgUlm2(ts_vesicle *vesicle);
int main(int argv, char *argc[]){
ts_uint i,j,k;
ts_vesicle *vesicle;
ts_double r0;
vesicle=initial_distribution_dipyramid(17,60,60,60,0.15);
//parsetape(vesicle,&i);
 
//these four must come from parsetype!
vesicle->dmax=1.67*1.67;
vesicle->stepsize=0.15;
vesicle->clist->max_occupancy=8;
vesicle->bending_rigidity=25.0;
//fprintf(stderr,"xk=%f",vesicle->bending_rigidity);
 
    centermass(vesicle);
cell_occupation(vesicle);
 
//test if the structure is internally organized into cells correctly 
ts_uint cind;
for(i=0;i<vesicle->vlist->n;i++){
    cind=vertex_self_avoidance(vesicle, vesicle->vlist->vtx[i]);
 
    if(vesicle->clist->cell[cind]==vesicle->vlist->vtx[i]->cell){
        //fprintf(stdout,"(T) Idx match!\n");
    } else {
        fprintf(stderr,"(T) ***** Idx don't match!\n");
 
    }
}
//end test
vesicle->sphHarmonics=sph_init(vesicle->vlist, 21);
 
vesicle_volume(vesicle);
r0=getR0(vesicle);
 
preparationSh(vesicle,r0);
calculateYlmi(vesicle);
calculateUlm(vesicle);
 
 
for(i=0;i<10;i++){
    for(j=0;j<200;j++){
        cell_occupation(vesicle);
        for(k=0;k<5;k++){
        single_timestep(vesicle);
        }
        centermass(vesicle);
    }    
    vesicle_volume(vesicle);
    r0=getR0(vesicle);
 
    preparationSh(vesicle,r0);
    calculateYlmi(vesicle);
    calculateUlm(vesicle);
 
    storeUlm2(vesicle);
    saveAvgUlm2(vesicle);
 
    write_vertex_xml_file(vesicle,i);
    fprintf(stderr, "Loop %d completed.\n",i+1);
 
}
 
write_master_xml_file("test.pvd");
write_dout_fcompat_file(vesicle,"dout");
vesicle_free(vesicle);
 
return 0; //program finished perfectly ok. We return 0.
}
 
 
 
ts_bool saveAvgUlm2(ts_vesicle *vesicle){
 
    FILE *fh;
    
    fh=fopen("sph2out.dat", "w");
    if(fh==NULL){
        err("Cannot open file %s for writing");
        return TS_FAIL;
    }
 
    ts_spharm *sph=vesicle->sphHarmonics;
    ts_int i,j;
    fprintf(fh,"l,\tm,\tulm^2avg\n");
    for(i=0;i<sph->l;i++){
            for(j=0;j<2*i+1;j++){
        fprintf(fh,"%d,\t%d,\t%e\n", i, j-i, sph->sumUlm2[i][j]/(ts_double)sph->N);
 
            }
    fprintf(fh,"\n");
    }
    fclose(fh);
    return TS_SUCCESS;
}