Trisurf Monte Carlo simulator
Samo Penic
2019-03-08 5e08f27fac51e8f7261cd4484ab8878befac8fe1
commit | author | age
7f6076 1 /* vim: set ts=4 sts=4 sw=4 noet : */
d7639a 2 #include<stdio.h>
SP 3 #include<math.h>
2b14da 4 #include<stdlib.h>
d7639a 5 #include "general.h"
SP 6 #include "vertex.h"
a10dd5 7 #include "bond.h"
a2a676 8 #include "triangle.h"
bb77ca 9 #include "cell.h"
7958e9 10 #include "vesicle.h"
a6b1b5 11 #include "io.h"
7958e9 12 #include "initial_distribution.h"
dac2e5 13 #include "frame.h"
aec47d 14 #include "timestep.h"
8db569 15 #include "poly.h"
dc77e8 16 #include "sh.h"
459ff9 17 #include "shcomplex.h"
ee84bd 18 #include "dumpstate.h"
8c1bb1 19 #include "restore.h"
eb7d7e 20 #include "plugins.h"
6e42ef 21 #include <fcntl.h>
d7639a 22 /** Entrance function to the program
SP 23   * @param argv is a number of parameters used in program call (including the program name
24   * @param argc is a pointer to strings (character arrays) which holds the arguments
25   * @returns returns 0 on success, any other number on fail.
26 */
eb7d7e 27 #include <string.h>
d7639a 28 int main(int argv, char *argc[]){
eb7d7e 29     ts_char *plugin0 = (ts_char *)calloc(255,sizeof(ts_char));
51b4f0 30     ts_char *plugin1 = (ts_char *)calloc(255,sizeof(ts_char));
b5cd8c 31     ts_char *plugin2 = (ts_char *)calloc(255,sizeof(ts_char));
36dba8 32     ts_char *plugin3 = (ts_char *)calloc(255,sizeof(ts_char));
77a2c7 33     ts_char *plugin4 = (ts_char *)calloc(255,sizeof(ts_char));
5e08f2 34     ts_char *plugin5 = (ts_char *)calloc(255,sizeof(ts_char));
74bf1e 35     strcpy(plugin0,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/demoplugin.so");
51b4f0 36     strcpy(plugin1,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/vmdefaulthardconstraints.so");
b5cd8c 37     strcpy(plugin2,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/plane_confinement.so");
36dba8 38     strcpy(plugin3,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/pressure.so");
77a2c7 39     strcpy(plugin4,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/constant_volume.so");
5e08f2 40     strcpy(plugin5,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/constant_area.so");
SP 41     ts_char **plugins=(ts_char **)calloc(6,sizeof(ts_char *));
77a2c7 42     plugins[0]=plugin0;
51b4f0 43     plugins[1]=plugin1;
b5cd8c 44     plugins[2]=plugin2;
36dba8 45     plugins[3]=plugin3;
77a2c7 46     plugins[4]=plugin4;
5e08f2 47     plugins[5]=plugin5;
SP 48     ts_plugin_list *plist=init_plugin_list(plugins,6);
ca9f26 49     //printf("%s", plist->chain->at_start->next->plugin->filename);
SP 50     //ts_fprintf(stdout, "TRISURF in PRVI PLUGIN %s\n", plist->plugin[0]->details->name);
1ab449 51     ts_vesicle *vesicle;
SP 52     ts_tape *tape;
8a6614 53     ts_uint start_iteration=0;
152052 54     force_from_tape=0;
fab2ad 55     /* Area and volume for constant area and constant volume are initialized to be zero */
SP 56     A0=0;
57     V0=0;
6e42ef 58     /* create lock file */
SP 59     createPidFile("ts_trisurf",".lock",0);
8a6614 60     parse_args(argv,argc); // sets global variable command_line_args (defined in io.h)
7f6076 61     ts_fprintf(stdout,"TRISURF-NG v. %s, compiled on: %s %s.\n", TS_VERSION, __DATE__, __TIME__);
SP 62     ts_fprintf(stdout,"Programming done by: Samo Penic and Miha Fosnaric\n");
63     ts_fprintf(stdout,"Released under terms of GPLv3\n");
8a6614 64     ts_fprintf(stdout,"Starting program...\n\n");
51b4f0 65     
SP 66 /* Entry point for plugin function at_start() */
ca9f26 67     ts_plugin_chain *ptr=plist->chain->at_start;
SP 68     while(ptr!=NULL){
69         ptr->plugin->function->at_start(argv,argc);
70         ptr=ptr->next;
51b4f0 71     }
ab798b 72
ee84bd 73     if(command_line_args.dump_from_vtk[0]!=0){
SP 74         ts_fprintf(stdout,"************************************************\n");
57f830 75         ts_fprintf(stdout,"**** Restoring vesicle from VTK points list ****\n");
ee84bd 76         ts_fprintf(stdout,"************************************************\n\n");
ab798b 77         vesicle = parseDump(command_line_args.dump_from_vtk);
SP 78         tape = vesicle->tape;
bb2074 79         int arguments_no;
3d0247 80         FILE *fd=fopen(".status","r");
SP 81         if(fd!=NULL){
bb2074 82             arguments_no=fscanf(fd,"%u", &start_iteration);
SP 83             if(arguments_no==0){
a17e91 84                 ts_fprintf(stdout,"No information of start iteration in .status file\n");
bb2074 85                 }
3d0247 86             fclose(fd);
a17e91 87             start_iteration++; 
3d0247 88         }
bb2074 89         else
a17e91 90             ts_fprintf(stdout,"No .status file. The iteration count will start from 0\n");
ee84bd 91     }
SP 92     else if(command_line_args.force_from_tape){
8a6614 93         ts_fprintf(stdout,"************************************************\n");
SP 94         ts_fprintf(stdout,"**** Generating initial geometry from tape *****\n");
95         ts_fprintf(stdout,"************************************************\n\n");
267db5 96         tape=parsetape(command_line_args.tape_fullfilename);
8a6614 97         vesicle=create_vesicle_from_tape(tape);
SP 98     } else {
083e03 99
8a6614 100         ts_fprintf(stdout,"**********************************************************************\n");
SP 101         ts_fprintf(stdout,"**** Recreating vesicle from dump file and continuing simulation *****\n");
102         ts_fprintf(stdout,"**********************************************************************\n\n");
267db5 103         tape=parsetape(command_line_args.tape_fullfilename);
8a6614 104         vesicle=restore_state(&start_iteration);
3f5c83 105         if(vesicle==NULL){
SP 106             ts_fprintf(stderr, "Dump file does not exist or is not a regular file! Did you mean to invoke trisurf with --force-from-tape option?\n\n");
107             return 1;
108         }
152052 109         // nove vrednosti iz tapea...
d9cb01 110         vesicle->bending_rigidity=tape->xk0;
M 111         vtx_set_global_values(vesicle);
bc9583 112         vesicle->pswitch =tape->pswitch;
152052 113         vesicle->pressure=tape->pressure;
2dcc65 114         vesicle->dmax=tape->dmax*tape->dmax;
bcf455 115         poly_assign_filament_xi(vesicle,tape);
2b14da 116         free(vesicle->tape);
9166cb 117         vesicle->tape=tape;
ea1cce 118         vesicle->clist->dmin_interspecies = tape->dmin_interspecies*tape->dmin_interspecies;
47a7ac 119
SP 120
121
632960 122         /* spherical harmonics */
SP 123         if(tape->shc>0){
459ff9 124             vesicle->sphHarmonics=complex_sph_init(vesicle->vlist,tape->shc);
632960 125         }
SP 126         else {
127             vesicle->sphHarmonics=NULL;
128         }
d9cb01 129
144784 130         if(command_line_args.reset_iteration_count) start_iteration=tape->inititer;
8a6614 131         else start_iteration++;
083e03 132
8a6614 133         if(start_iteration>=tape->iterations){
SP 134             ts_fprintf(stdout, "Simulation already completed. if you want to rerun it try with --force-from-tape or --reset-iteration-count\n\n");
135             return 0;
136         }
a752b5 137
SP 138     /* if requested in tape, we can have smaller number of polymeres attached to membrane than the number of polymeres in dump file */
139         if(vesicle->tape->npoly != vesicle->poly_list->n){
140
141         ts_fprintf(stdout,"(INFO) the number of polymeres attached to membrane in tape is different than a number of polymeres in dump file!\n");
142         if(vesicle->tape->npoly > vesicle->poly_list->n){
143             ts_fprintf(stdout,"(INFO) It is possible to decrease the number of polymeres on the membrane, but it is not allowed to increase its number. The maximal allowed number in tape is %d The execution of program will terminate!\n",vesicle->poly_list->n);
144             fatal("Terminating due to increase of number of polymeres",1);
145         } else {
146             remove_random_polymeres(vesicle->poly_list, vesicle->poly_list->n - vesicle->tape->npoly);
147             ts_fprintf(stdout,"(INFO)\n(INFO) The new number of polymeres from tape is %d.\n\n",vesicle->poly_list->n);
148
149         }
150         }
8a6614 151     }
SP 152
51b4f0 153     vesicle->plist=plist;
SP 154 /* Entry point for plugin after_vesicle_init() function */
77a2c7 155     vesicle->plist->pointer=vesicle->plist->chain->after_vesicle_init;
SP 156     while(vesicle->plist->pointer!=NULL){
157         vesicle=vesicle->plist->pointer->plugin->function->after_vesicle_init(vesicle);
158         vesicle->plist->pointer=vesicle->plist->pointer->next;
51b4f0 159     }
ca9f26 160
8a6614 161     run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration);
267db5 162     write_master_xml_file(command_line_args.output_fullfilename);
8a6614 163     write_dout_fcompat_file(vesicle,"dout");
ca9f26 164 /* Entry point for plugin cleanup() function */
SP 165     ptr=plist->chain->cleanup;
166     while(ptr!=NULL){
167         ptr->plugin->function->cleanup();
168         ptr=ptr->next;
169     }
170
171
8a6614 172     vesicle_free(vesicle);
SP 173     tape_free(tape);
174     return 0; //program finished perfectly ok. We return 0.
d7639a 175