Trisurf Monte Carlo simulator
Samo Penic
2018-12-25 08559613e0fe7c23d329092679a2ff347a92ff4f
commit | author | age
eb7d7e 1 /* This is a first attempt in implementation of plugins to Trisurf-ng. */
SP 2
3 /*
4
085596 5 Options for tape:
eb7d7e 6
085596 7 extra_plugin_path = "..." (OPTIONAL)
eb7d7e 8
085596 9 vesicle bipyramid {
SP 10     nshell=23    
11 }
eb7d7e 12
085596 13 vesicle vtufile {
SP 14     filename="filename"
15 }
eb7d7e 16
085596 17 vesicle vtudatabase {
SP 18     run_id=123
19     timestep=999
20 }
eb7d7e 21
085596 22 vesicle properties {
SP 23     xk0=20
24     dmax=1.7
25     dmin_interspecies=1.2
26     stepsize=0.15
27 }
eb7d7e 28
085596 29 space properties {
SP 30     nxmax=60
31     nymax=60
32     nzmax=60
33 }
34
35 loop control {
36     inner=1000
37     outer=1000
38 }
39
40 plugin pressure {
41     pressure=10
42 }
43
44 plugin constant_volume {
45     precision=1e14
46 }
47
48 plugin constant_area {
49
50 }
51
52 plugin confinement_plate {
53     distance=5
54     force=10
55     coordinate=2 // 0=x,1=y,2=z
56 }
57
58 plugin spherical_harmonics {
59     lmax=21
60     filename="abc.csv"
61 }
62
63 plugin spontaneous_curvature {
64     c0=2
65     N=100
66     w=10
67     force=3
68 }
69
70 plugin filament {
71     monomers=100
72     xi=10
73 }
74
75 plugin polymer {
76     polymers = 100
77     monomers = 10
78     elastic_coefficient=100
79     is_internal = true
80 }
81
82 plugin nucleus {
83     R_nucleus=10
84     R_nucleusX=0
85     R_nucleusY=0
86     R_nucleusZ=0
87 }
88
eb7d7e 89 */
SP 90 #include "plugins.h"
91 #include <stdlib.h>
92 #include <dlfcn.h>
93 #include <string.h>
94 #include "general.h"
95
96 ts_plugin *init_plugin(ts_char *filename){
97     ts_plugin *plugin = (ts_plugin *)calloc(1, sizeof(ts_plugin));
98     plugin->filename=(ts_char *)calloc(strlen(filename),sizeof(ts_char));
99     strcpy(plugin->filename,filename);
100     plugin->libhandle = dlopen(plugin->filename, RTLD_NOW);
101     if(!plugin->libhandle){
102         ts_fprintf(stderr,"Error loading plugin: %s\n", filename);
103         fatal("Exiting",235);
104     }
105     ts_plugin_details* (*get_plugin_details)(void) = dlsym(plugin->libhandle, "init");
106     plugin->details = get_plugin_details();
107     plugin->function = (ts_plugin_function *)calloc(1,sizeof(ts_plugin_function));
108     
109     plugin->function->cleanup = dlsym(plugin->libhandle, "cleanup");
110     plugin->function->at_start = dlsym(plugin->libhandle, "at_start");
111     plugin->function->after_vesicle_init = dlsym(plugin->libhandle, "after_vesicle_init");
112     plugin->function->vm_hard_constraint = dlsym(plugin->libhandle, "vm_hard_constraint");
113     plugin->function->vm_energy_before = dlsym(plugin->libhandle, "vm_energy_before");
114     plugin->function->vm_energy_after = dlsym(plugin->libhandle, "vm_energy_after");
115     plugin->function->vm_new_state_rejected = dlsym(plugin->libhandle, "vm_new_state_rejected");
116     plugin->function->vm_new_state_accepted = dlsym(plugin->libhandle, "vm_new_state_accepted");
117
118     return plugin;
119 }
120
121
122 ts_plugin_list *init_plugin_list(ts_char **plugin_filenames, ts_uint number_of_plugins){
123     ts_plugin_list *plist=(ts_plugin_list *)calloc(1, sizeof(ts_plugin_list));
124     plist->plugin=(ts_plugin **)calloc(number_of_plugins, sizeof(ts_plugin *));
125     for(int i=0;i<number_of_plugins;i++){
126         plist->plugin[i]=init_plugin(plugin_filenames[i]);
127     }
128     return plist;
129 }    
130
131 void free_plugin(ts_plugin *plugin){
132     plugin->function->cleanup();
133     free(plugin->function);
134     free(plugin->details);
135     free(plugin->filename);
136     dlclose(plugin->libhandle);
137     free(plugin);
138 }
139
140 void free_plugin_list(ts_plugin_list *plist){
141     for(int i=0;i<plist->n;i++){
142         free_plugin(plist->plugin[i]);
143     }
144     free(plist);
145 }