Trisurf Monte Carlo simulator
Samo Penic
2015-03-09 a00f10fd48a1de31c3ac923c2106969f84e831e0
commit | author | age
d7639a 1 #include<stdio.h>
SP 2 #include<math.h>
2b14da 3 #include<stdlib.h>
d7639a 4 #include "general.h"
SP 5 #include "vertex.h"
a10dd5 6 #include "bond.h"
a2a676 7 #include "triangle.h"
bb77ca 8 #include "cell.h"
7958e9 9 #include "vesicle.h"
a6b1b5 10 #include "io.h"
7958e9 11 #include "initial_distribution.h"
dac2e5 12 #include "frame.h"
aec47d 13 #include "timestep.h"
8db569 14 #include "poly.h"
dc77e8 15 #include "sh.h"
459ff9 16 #include "shcomplex.h"
ee84bd 17 #include "dumpstate.h"
d7639a 18
SP 19 /** Entrance function to the program
20   * @param argv is a number of parameters used in program call (including the program name
21   * @param argc is a pointer to strings (character arrays) which holds the arguments
22   * @returns returns 0 on success, any other number on fail.
23 */
24
25 int main(int argv, char *argc[]){
1ab449 26     ts_vesicle *vesicle;
SP 27     ts_tape *tape;
8a6614 28     ts_uint start_iteration=0;
152052 29     force_from_tape=0;
8a6614 30     parse_args(argv,argc); // sets global variable command_line_args (defined in io.h)
SP 31     ts_fprintf(stdout,"Starting program...\n\n");
ee84bd 32
SP 33     if(command_line_args.dump_from_vtk[0]!=0){
34         ts_fprintf(stdout,"************************************************\n");
35         ts_fprintf(stdout,"***** Dumping vesicle from VTK points list *****\n");
36         ts_fprintf(stdout,"************************************************\n\n");
37         tape=parsetape(command_line_args.tape_fullfilename);
38         vesicle=vtk2vesicle(command_line_args.dump_from_vtk,tape);
39     }
40     else if(command_line_args.force_from_tape){
8a6614 41         ts_fprintf(stdout,"************************************************\n");
SP 42         ts_fprintf(stdout,"**** Generating initial geometry from tape *****\n");
43         ts_fprintf(stdout,"************************************************\n\n");
267db5 44         tape=parsetape(command_line_args.tape_fullfilename);
8a6614 45         vesicle=create_vesicle_from_tape(tape);
SP 46     } else {
083e03 47
8a6614 48         ts_fprintf(stdout,"**********************************************************************\n");
SP 49         ts_fprintf(stdout,"**** Recreating vesicle from dump file and continuing simulation *****\n");
50         ts_fprintf(stdout,"**********************************************************************\n\n");
267db5 51         tape=parsetape(command_line_args.tape_fullfilename);
8a6614 52         vesicle=restore_state(&start_iteration);
3f5c83 53         if(vesicle==NULL){
SP 54             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");
55             return 1;
56         }
152052 57         // nove vrednosti iz tapea...
d9cb01 58         vesicle->bending_rigidity=tape->xk0;
M 59         vtx_set_global_values(vesicle);
bc9583 60         vesicle->pswitch =tape->pswitch;
152052 61         vesicle->pressure=tape->pressure;
2dcc65 62         vesicle->dmax=tape->dmax*tape->dmax;
bcf455 63         poly_assign_filament_xi(vesicle,tape);
2b14da 64         free(vesicle->tape);
9166cb 65         vesicle->tape=tape;
ea1cce 66         vesicle->clist->dmin_interspecies = tape->dmin_interspecies*tape->dmin_interspecies;
47a7ac 67
SP 68
69
632960 70         /* spherical harmonics */
SP 71         if(tape->shc>0){
459ff9 72             vesicle->sphHarmonics=complex_sph_init(vesicle->vlist,tape->shc);
632960 73         }
SP 74         else {
75             vesicle->sphHarmonics=NULL;
76         }
d9cb01 77
144784 78         if(command_line_args.reset_iteration_count) start_iteration=tape->inititer;
8a6614 79         else start_iteration++;
083e03 80
8a6614 81         if(start_iteration>=tape->iterations){
SP 82             ts_fprintf(stdout, "Simulation already completed. if you want to rerun it try with --force-from-tape or --reset-iteration-count\n\n");
83             return 0;
84         }
a752b5 85
SP 86     /* if requested in tape, we can have smaller number of polymeres attached to membrane than the number of polymeres in dump file */
87         if(vesicle->tape->npoly != vesicle->poly_list->n){
88
89         ts_fprintf(stdout,"(INFO) the number of polymeres attached to membrane in tape is different than a number of polymeres in dump file!\n");
90         if(vesicle->tape->npoly > vesicle->poly_list->n){
91             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);
92             fatal("Terminating due to increase of number of polymeres",1);
93         } else {
94             remove_random_polymeres(vesicle->poly_list, vesicle->poly_list->n - vesicle->tape->npoly);
95             ts_fprintf(stdout,"(INFO)\n(INFO) The new number of polymeres from tape is %d.\n\n",vesicle->poly_list->n);
96
97         }
98         }
8a6614 99     }
SP 100
101     run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration);
267db5 102     write_master_xml_file(command_line_args.output_fullfilename);
8a6614 103     write_dout_fcompat_file(vesicle,"dout");
SP 104     vesicle_free(vesicle);
105     tape_free(tape);
106     return 0; //program finished perfectly ok. We return 0.
d7639a 107