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