Trisurf Monte Carlo simulator
Samo Penic
2019-03-08 06f70cc6f065746cf79c9792228356e3f015f4ec
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
#include <stdlib.h>
#include<math.h>
 
#include "general.h"
#include "vertex.h"
#include "cell.h"
#include "vesicle.h"
#include "frame.h"
char plugin_name[] = "Constant volume";
char plugin_description[]= "Plugin that enables constant volume of the vesicle.";
char plugin_author[] = "SAMO PENIC";
 
 
typedef struct {
    ts_double dvol;
    ts_double V0;
    ts_double epsvol;
} plugin_data;
 
 
ts_plugin_details *init (){
    ts_plugin_details *details=(ts_plugin_details *)calloc(1,sizeof(ts_plugin_details));
    details->name = plugin_name;
    details->data = (plugin_data *)calloc(1,sizeof(plugin_data)); //storing data
    return details;    
}
 
 
ts_vesicle *after_vesicle_init(ts_vesicle *vesicle){
    plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data;
    ts_fprintf(stdout,"constant volume initialized\n");
 
    centermass(vesicle);
    cell_occupation(vesicle);
    vesicle_volume(vesicle); //needed for constant volume at this moment
 
    data->V0=vesicle->volume;
    data->epsvol=4.0*sqrt(2.0*M_PI)/pow(3.0,3.0/4.0)*data->V0/pow(vesicle->tlist->n,3.0/2.0);
    return vesicle;
}
 
 
void vm_energy_before_prepare(ts_vesicle *vesicle, ts_vertex *vtx){
    if(vesicle->tape->constvolswitch>0){
        plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data;
        data->dvol=0;
        ts_uint i;
        for(i=0;i<vtx->tristar_no;i++) data->dvol-=vtx->tristar[i]->volume;
    }
}
 
ts_double vm_before_montecarlo_constraint(ts_vesicle *vesicle, ts_vertex *vtx, ts_vertex *old_vtx){
    if(vesicle->tape->constvolswitch >0){
        plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data;
        ts_uint i;
        for(i=0;i<vtx->tristar_no;i++) data->dvol+=vtx->tristar[i]->volume;
        if(fabs(vesicle->volume+data->dvol-data->V0)>data->epsvol) return TS_FAIL;
    }
    return TS_SUCCESS;
}
 
 
void vm_new_state_accepted(ts_vesicle *vesicle, ts_vertex *vtx, ts_vertex *old_vtx){
    if(vesicle->tape->constvolswitch >0){
        plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data;
        vesicle->volume+=data->dvol;
    }
}