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)); |
77a2c7
|
98 |
plugin->filename=(ts_char *)calloc(strlen(filename)+1,sizeof(ts_char)); |
eb7d7e
|
99 |
strcpy(plugin->filename,filename); |
SP |
100 |
plugin->libhandle = dlopen(plugin->filename, RTLD_NOW); |
|
101 |
if(!plugin->libhandle){ |
77a2c7
|
102 |
ts_fprintf(stderr,"Error loading plugin: %s\n", plugin->filename); |
eb7d7e
|
103 |
fatal("Exiting",235); |
SP |
104 |
} |
|
105 |
ts_plugin_details* (*get_plugin_details)(void) = dlsym(plugin->libhandle, "init"); |
ca9f26
|
106 |
if(get_plugin_details==NULL){ |
77a2c7
|
107 |
ts_fprintf(stderr,"Plugin %s invalid. No init() function.\n", plugin->filename); |
SP |
108 |
fatal("Exiting", 236); |
ca9f26
|
109 |
} |
eb7d7e
|
110 |
plugin->details = get_plugin_details(); |
SP |
111 |
plugin->function = (ts_plugin_function *)calloc(1,sizeof(ts_plugin_function)); |
|
112 |
|
|
113 |
plugin->function->cleanup = dlsym(plugin->libhandle, "cleanup"); |
|
114 |
plugin->function->at_start = dlsym(plugin->libhandle, "at_start"); |
|
115 |
plugin->function->after_vesicle_init = dlsym(plugin->libhandle, "after_vesicle_init"); |
|
116 |
plugin->function->vm_hard_constraint = dlsym(plugin->libhandle, "vm_hard_constraint"); |
51b4f0
|
117 |
plugin->function->vm_energy_before_prepare = dlsym(plugin->libhandle, "vm_energy_before_prepare"); |
SP |
118 |
plugin->function->vm_energy_before_execute = dlsym(plugin->libhandle, "vm_energy_before_execute"); |
|
119 |
plugin->function->vm_energy_after_prepare = dlsym(plugin->libhandle, "vm_energy_after_prepare"); |
|
120 |
plugin->function->vm_energy_after_execute = dlsym(plugin->libhandle, "vm_energy_after_execute"); |
77a2c7
|
121 |
plugin->function->vm_before_montecarlo_constraint = dlsym(plugin->libhandle, "vm_before_montecarlo_constraint"); |
eb7d7e
|
122 |
plugin->function->vm_new_state_rejected = dlsym(plugin->libhandle, "vm_new_state_rejected"); |
SP |
123 |
plugin->function->vm_new_state_accepted = dlsym(plugin->libhandle, "vm_new_state_accepted"); |
|
124 |
|
|
125 |
return plugin; |
|
126 |
} |
|
127 |
|
|
128 |
|
ca9f26
|
129 |
ts_plugin_chain *plugin_to_chain(ts_plugin_chain *chain, ts_plugin *plugin){ |
SP |
130 |
ts_plugin_chain *retchain; |
|
131 |
if(chain!=NULL){ |
|
132 |
retchain=chain; |
|
133 |
while(chain->next!=NULL){ |
|
134 |
chain=chain->next; |
|
135 |
} |
|
136 |
chain->next=(ts_plugin_chain *)calloc(1,sizeof(ts_plugin_chain)); |
|
137 |
chain->next->plugin=plugin; |
|
138 |
return retchain; |
|
139 |
} else { |
|
140 |
chain=(ts_plugin_chain *)calloc(1,sizeof(ts_plugin_chain)); |
|
141 |
chain->plugin=plugin; |
|
142 |
return chain; |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
|
eb7d7e
|
147 |
ts_plugin_list *init_plugin_list(ts_char **plugin_filenames, ts_uint number_of_plugins){ |
SP |
148 |
ts_plugin_list *plist=(ts_plugin_list *)calloc(1, sizeof(ts_plugin_list)); |
|
149 |
plist->plugin=(ts_plugin **)calloc(number_of_plugins, sizeof(ts_plugin *)); |
ca9f26
|
150 |
plist->chain=(ts_plugin_chains *)calloc(1, sizeof(ts_plugin_chains)); |
eb7d7e
|
151 |
for(int i=0;i<number_of_plugins;i++){ |
SP |
152 |
plist->plugin[i]=init_plugin(plugin_filenames[i]); |
ca9f26
|
153 |
if(plist->plugin[i]->function->cleanup!=NULL){ |
SP |
154 |
plist->chain->cleanup=plugin_to_chain(plist->chain->cleanup, plist->plugin[i]); |
|
155 |
} |
|
156 |
if(plist->plugin[i]->function->at_start!=NULL){ |
|
157 |
plist->chain->at_start=plugin_to_chain(plist->chain->at_start, plist->plugin[i]); |
|
158 |
} |
77a2c7
|
159 |
if(plist->plugin[i]->function->after_vesicle_init!=NULL){ |
SP |
160 |
plist->chain->after_vesicle_init=plugin_to_chain(plist->chain->after_vesicle_init, plist->plugin[i]); |
|
161 |
} |
36dba8
|
162 |
if(plist->plugin[i]->function->vm_hard_constraint!=NULL){ |
SP |
163 |
plist->chain->vm_hard_constraint=plugin_to_chain(plist->chain->vm_hard_constraint, plist->plugin[i]); |
|
164 |
} |
|
165 |
if(plist->plugin[i]->function->vm_energy_before_prepare!=NULL){ |
|
166 |
plist->chain->vm_energy_before_prepare=plugin_to_chain(plist->chain->vm_energy_before_prepare, plist->plugin[i]); |
|
167 |
} |
|
168 |
if(plist->plugin[i]->function->vm_energy_after_execute!=NULL){ |
|
169 |
plist->chain->vm_energy_after_execute=plugin_to_chain(plist->chain->vm_energy_after_execute, plist->plugin[i]); |
|
170 |
} |
77a2c7
|
171 |
if(plist->plugin[i]->function->vm_before_montecarlo_constraint!=NULL){ |
SP |
172 |
plist->chain->vm_before_montecarlo_constraint=plugin_to_chain(plist->chain->vm_before_montecarlo_constraint, plist->plugin[i]); |
|
173 |
} |
2afc2f
|
174 |
if(plist->plugin[i]->function->vm_new_state_accepted!=NULL){ |
SP |
175 |
plist->chain->vm_new_state_accepted=plugin_to_chain(plist->chain->vm_new_state_accepted, plist->plugin[i]); |
|
176 |
} |
7522b8
|
177 |
if(plist->plugin[i]->function->vm_new_state_rejected!=NULL){ |
SP |
178 |
plist->chain->vm_new_state_rejected=plugin_to_chain(plist->chain->vm_new_state_rejected, plist->plugin[i]); |
|
179 |
} |
eb7d7e
|
180 |
} |
51b4f0
|
181 |
plist->n=number_of_plugins; |
eb7d7e
|
182 |
return plist; |
SP |
183 |
} |
|
184 |
|
|
185 |
void free_plugin(ts_plugin *plugin){ |
|
186 |
plugin->function->cleanup(); |
|
187 |
free(plugin->function); |
|
188 |
free(plugin->details); |
|
189 |
free(plugin->filename); |
|
190 |
dlclose(plugin->libhandle); |
|
191 |
free(plugin); |
|
192 |
} |
|
193 |
|
ca9f26
|
194 |
void plugin_list_free(ts_plugin_list *plist){ |
eb7d7e
|
195 |
for(int i=0;i<plist->n;i++){ |
SP |
196 |
free_plugin(plist->plugin[i]); |
|
197 |
} |
ca9f26
|
198 |
free(plist->chain); |
eb7d7e
|
199 |
free(plist); |
SP |
200 |
} |