Trisurf Monte Carlo simulator
Samo Penic
2019-02-28 ca9f26089df29fec5995ed4f19a06c29f7f4b12e
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));
74bf1e 31     strcpy(plugin0,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/demoplugin.so");
51b4f0 32     strcpy(plugin1,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/vmdefaulthardconstraints.so");
SP 33     ts_char **plugins=(ts_char **)calloc(2,sizeof(ts_char *));
eb7d7e 34     *plugins=plugin0;
51b4f0 35     plugins[1]=plugin1;
SP 36     ts_plugin_list *plist=init_plugin_list(plugins,2);
ca9f26 37     //printf("%s", plist->chain->at_start->next->plugin->filename);
SP 38     //ts_fprintf(stdout, "TRISURF in PRVI PLUGIN %s\n", plist->plugin[0]->details->name);
1ab449 39     ts_vesicle *vesicle;
SP 40     ts_tape *tape;
8a6614 41     ts_uint start_iteration=0;
152052 42     force_from_tape=0;
fab2ad 43     /* Area and volume for constant area and constant volume are initialized to be zero */
SP 44     A0=0;
45     V0=0;
6e42ef 46     /* create lock file */
SP 47     createPidFile("ts_trisurf",".lock",0);
8a6614 48     parse_args(argv,argc); // sets global variable command_line_args (defined in io.h)
7f6076 49     ts_fprintf(stdout,"TRISURF-NG v. %s, compiled on: %s %s.\n", TS_VERSION, __DATE__, __TIME__);
SP 50     ts_fprintf(stdout,"Programming done by: Samo Penic and Miha Fosnaric\n");
51     ts_fprintf(stdout,"Released under terms of GPLv3\n");
8a6614 52     ts_fprintf(stdout,"Starting program...\n\n");
51b4f0 53     
SP 54 /* Entry point for plugin function at_start() */
ca9f26 55     ts_plugin_chain *ptr=plist->chain->at_start;
SP 56     while(ptr!=NULL){
57         ptr->plugin->function->at_start(argv,argc);
58         ptr=ptr->next;
51b4f0 59     }
ab798b 60
ee84bd 61     if(command_line_args.dump_from_vtk[0]!=0){
SP 62         ts_fprintf(stdout,"************************************************\n");
57f830 63         ts_fprintf(stdout,"**** Restoring vesicle from VTK points list ****\n");
ee84bd 64         ts_fprintf(stdout,"************************************************\n\n");
ab798b 65         vesicle = parseDump(command_line_args.dump_from_vtk);
SP 66         tape = vesicle->tape;
bb2074 67         int arguments_no;
3d0247 68         FILE *fd=fopen(".status","r");
SP 69         if(fd!=NULL){
bb2074 70             arguments_no=fscanf(fd,"%u", &start_iteration);
SP 71             if(arguments_no==0){
a17e91 72                 ts_fprintf(stdout,"No information of start iteration in .status file\n");
bb2074 73                 }
3d0247 74             fclose(fd);
a17e91 75             start_iteration++; 
3d0247 76         }
bb2074 77         else
a17e91 78             ts_fprintf(stdout,"No .status file. The iteration count will start from 0\n");
ee84bd 79     }
SP 80     else if(command_line_args.force_from_tape){
8a6614 81         ts_fprintf(stdout,"************************************************\n");
SP 82         ts_fprintf(stdout,"**** Generating initial geometry from tape *****\n");
83         ts_fprintf(stdout,"************************************************\n\n");
267db5 84         tape=parsetape(command_line_args.tape_fullfilename);
8a6614 85         vesicle=create_vesicle_from_tape(tape);
SP 86     } else {
083e03 87
8a6614 88         ts_fprintf(stdout,"**********************************************************************\n");
SP 89         ts_fprintf(stdout,"**** Recreating vesicle from dump file and continuing simulation *****\n");
90         ts_fprintf(stdout,"**********************************************************************\n\n");
267db5 91         tape=parsetape(command_line_args.tape_fullfilename);
8a6614 92         vesicle=restore_state(&start_iteration);
3f5c83 93         if(vesicle==NULL){
SP 94             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");
95             return 1;
96         }
152052 97         // nove vrednosti iz tapea...
d9cb01 98         vesicle->bending_rigidity=tape->xk0;
M 99         vtx_set_global_values(vesicle);
bc9583 100         vesicle->pswitch =tape->pswitch;
152052 101         vesicle->pressure=tape->pressure;
2dcc65 102         vesicle->dmax=tape->dmax*tape->dmax;
bcf455 103         poly_assign_filament_xi(vesicle,tape);
2b14da 104         free(vesicle->tape);
9166cb 105         vesicle->tape=tape;
ea1cce 106         vesicle->clist->dmin_interspecies = tape->dmin_interspecies*tape->dmin_interspecies;
47a7ac 107
SP 108
109
632960 110         /* spherical harmonics */
SP 111         if(tape->shc>0){
459ff9 112             vesicle->sphHarmonics=complex_sph_init(vesicle->vlist,tape->shc);
632960 113         }
SP 114         else {
115             vesicle->sphHarmonics=NULL;
116         }
d9cb01 117
144784 118         if(command_line_args.reset_iteration_count) start_iteration=tape->inititer;
8a6614 119         else start_iteration++;
083e03 120
8a6614 121         if(start_iteration>=tape->iterations){
SP 122             ts_fprintf(stdout, "Simulation already completed. if you want to rerun it try with --force-from-tape or --reset-iteration-count\n\n");
123             return 0;
124         }
a752b5 125
SP 126     /* if requested in tape, we can have smaller number of polymeres attached to membrane than the number of polymeres in dump file */
127         if(vesicle->tape->npoly != vesicle->poly_list->n){
128
129         ts_fprintf(stdout,"(INFO) the number of polymeres attached to membrane in tape is different than a number of polymeres in dump file!\n");
130         if(vesicle->tape->npoly > vesicle->poly_list->n){
131             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);
132             fatal("Terminating due to increase of number of polymeres",1);
133         } else {
134             remove_random_polymeres(vesicle->poly_list, vesicle->poly_list->n - vesicle->tape->npoly);
135             ts_fprintf(stdout,"(INFO)\n(INFO) The new number of polymeres from tape is %d.\n\n",vesicle->poly_list->n);
136
137         }
138         }
8a6614 139     }
SP 140
51b4f0 141     vesicle->plist=plist;
SP 142 /* Entry point for plugin after_vesicle_init() function */
ca9f26 143     ptr=plist->chain->after_vesicle_init;
SP 144     while(ptr!=NULL){
145         ptr->plugin->function->after_vesicle_init(vesicle);
146         ptr=ptr->next;
51b4f0 147     }
ca9f26 148
8a6614 149     run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration);
267db5 150     write_master_xml_file(command_line_args.output_fullfilename);
8a6614 151     write_dout_fcompat_file(vesicle,"dout");
ca9f26 152 /* Entry point for plugin cleanup() function */
SP 153     ptr=plist->chain->cleanup;
154     while(ptr!=NULL){
155         ptr->plugin->function->cleanup();
156         ptr=ptr->next;
157     }
158
159
8a6614 160     vesicle_free(vesicle);
SP 161     tape_free(tape);
162     return 0; //program finished perfectly ok. We return 0.
d7639a 163