Trisurf Monte Carlo simulator
Samo Penic
2012-07-12 a7a6d6d521ea3006963ae3f1a3fd8975cf3ba9b2
commit | author | age
aec47d 1 #include<stdlib.h>
SP 2 #include<math.h>
3 #include "general.h"
4 #include "vertex.h"
5 #include "bond.h"
6 #include "triangle.h"
7 #include "vesicle.h"
8 #include "energy.h"
9 #include "timestep.h"
10 #include "cell.h"
11 //#include "io.h"
12 #include<stdio.h>
13 #include "vertexmove.h"
1ad6d1 14 #include <string.h>
aec47d 15
SP 16 ts_bool single_verticle_timestep(ts_vesicle *vesicle,ts_vertex *vtx,ts_double
17 *rn){
18     ts_uint i;
19     ts_double dist;
20     ts_bool retval; 
21     ts_uint cellidx; 
22     ts_double delta_energy,oenergy;
1ad6d1 23     //This will hold all the information of vtx and its neighbours
dcd350 24     ts_vertex backupvtx[20];
SP 25     memcpy((void *)&backupvtx[0],(void *)vtx,sizeof(ts_vertex));
352fad 26         //temporarly moving the vertex
SP 27     vtx->x=vtx->x+vesicle->stepsize*(2.0*rn[0]-1.0);
28         vtx->y=vtx->y+vesicle->stepsize*(2.0*rn[1]-1.0);
29         vtx->z=vtx->z+vesicle->stepsize*(2.0*rn[2]-1.0);
30         //check we if some length to neighbours are too much
8f6a69 31     for(i=0;i<vtx->neigh_no;i++){
352fad 32         dist=vtx_distance_sq(vtx,vtx->neigh[i]);
8f6a69 33         if(dist<1.0 || dist>vesicle->dmax) {
dcd350 34         vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex));
8f6a69 35         return TS_FAIL;
SP 36         }
aec47d 37     }
SP 38     //self avoidance check with distant vertices
352fad 39      cellidx=vertex_self_avoidance(vesicle, vtx);
aec47d 40     //check occupation number
dcd350 41      retval=cell_occupation_number_and_internal_proximity(vesicle->clist,cellidx,&backupvtx[0],vtx);
aec47d 42     if(retval==TS_FAIL){
dcd350 43         vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex));
aec47d 44         return TS_FAIL;
SP 45     } 
1ad6d1 46    
SP 47  
352fad 48     //if all the tests are successful, then energy for vtx and neighbours is calculated
1ad6d1 49     for(i=0;i<vtx->neigh_no;i++){
dcd350 50     memcpy((void *)&backupvtx[i+1],(void *)vtx->neigh[i],sizeof(ts_vertex));
1ad6d1 51     }
aec47d 52
SP 53     delta_energy=0;
54     //update the normals of triangles that share bead i.
8f6a69 55     for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]);
aec47d 56     energy_vertex(vtx);
dcd350 57     delta_energy=vtx->xk*(vtx->energy - (&backupvtx[0])->energy);
aec47d 58     //the same is done for neighbouring vertices
8f6a69 59     for(i=0;i<vtx->neigh_no;i++){
SP 60         oenergy=vtx->neigh[i]->energy;
61         energy_vertex(vtx->neigh[i]);
62         delta_energy+=vtx->neigh[i]->xk*(vtx->neigh[i]->energy-oenergy);
aec47d 63     }
314f2d 64 //   fprintf(stderr, "DE=%f\n",delta_energy);
aec47d 65     //MONTE CARLOOOOOOOO
SP 66     if(delta_energy>=0){
67 #ifdef TS_DOUBLE_DOUBLE
68         if(exp(-delta_energy)< drand48() )
69 #endif
70 #ifdef TS_DOUBLE_FLOAT
71         if(expf(-delta_energy)< (ts_float)drand48())
72 #endif
73 #ifdef TS_DOUBLE_LONGDOUBLE
74         if(expl(-delta_energy)< (ts_ldouble)drand48())
75 #endif
76     {
77     //not accepted, reverting changes
dcd350 78     vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex));
1ad6d1 79     for(i=0;i<vtx->neigh_no;i++){
dcd350 80     vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex));
1ad6d1 81     }
SP 82 //    fprintf(stderr,"Reverted\n");
83     
aec47d 84     //update the normals of triangles that share bead i.
dcd350 85    for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]);
1ad6d1 86
aec47d 87     return TS_FAIL; 
SP 88     }
89 }
90     //END MONTE CARLOOOOOOO
91     return TS_SUCCESS;
92 }
93