Trisurf Monte Carlo simulator
Samo Penic
2016-03-02 7f607660a91b969daa19dbdb62628691bfee8f7e
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"
d7639a 20 /** Entrance function to the program
SP 21   * @param argv is a number of parameters used in program call (including the program name
22   * @param argc is a pointer to strings (character arrays) which holds the arguments
23   * @returns returns 0 on success, any other number on fail.
24 */
25
26 int main(int argv, char *argc[]){
1ab449 27     ts_vesicle *vesicle;
SP 28     ts_tape *tape;
8a6614 29     ts_uint start_iteration=0;
152052 30     force_from_tape=0;
8a6614 31     parse_args(argv,argc); // sets global variable command_line_args (defined in io.h)
7f6076 32     ts_fprintf(stdout,"TRISURF-NG v. %s, compiled on: %s %s.\n", TS_VERSION, __DATE__, __TIME__);
SP 33     ts_fprintf(stdout,"Programming done by: Samo Penic and Miha Fosnaric\n");
34     ts_fprintf(stdout,"Released under terms of GPLv3\n");
8a6614 35     ts_fprintf(stdout,"Starting program...\n\n");
ab798b 36 //    vesicle = parseDump("timestep_000000.vtu");
SP 37 //        run_simulation(vesicle, vesicle->tape->mcsweeps, vesicle->tape->inititer, vesicle->tape->iterations, 1);
38
ee84bd 39     if(command_line_args.dump_from_vtk[0]!=0){
SP 40         ts_fprintf(stdout,"************************************************\n");
41         ts_fprintf(stdout,"***** Dumping vesicle from VTK points list *****\n");
42         ts_fprintf(stdout,"************************************************\n\n");
ab798b 43         vesicle = parseDump(command_line_args.dump_from_vtk);
SP 44         tape = vesicle->tape;
45 //        tape=parsetape(command_line_args.tape_fullfilename);
46   //      vesicle=vtk2vesicle(command_line_args.dump_from_vtk,tape);
ee84bd 47     }
SP 48     else if(command_line_args.force_from_tape){
8a6614 49         ts_fprintf(stdout,"************************************************\n");
SP 50         ts_fprintf(stdout,"**** Generating initial geometry from tape *****\n");
51         ts_fprintf(stdout,"************************************************\n\n");
267db5 52         tape=parsetape(command_line_args.tape_fullfilename);
8a6614 53         vesicle=create_vesicle_from_tape(tape);
SP 54     } else {
083e03 55
8a6614 56         ts_fprintf(stdout,"**********************************************************************\n");
SP 57         ts_fprintf(stdout,"**** Recreating vesicle from dump file and continuing simulation *****\n");
58         ts_fprintf(stdout,"**********************************************************************\n\n");
267db5 59         tape=parsetape(command_line_args.tape_fullfilename);
8a6614 60         vesicle=restore_state(&start_iteration);
3f5c83 61         if(vesicle==NULL){
SP 62             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");
63             return 1;
64         }
152052 65         // nove vrednosti iz tapea...
d9cb01 66         vesicle->bending_rigidity=tape->xk0;
M 67         vtx_set_global_values(vesicle);
bc9583 68         vesicle->pswitch =tape->pswitch;
152052 69         vesicle->pressure=tape->pressure;
2dcc65 70         vesicle->dmax=tape->dmax*tape->dmax;
bcf455 71         poly_assign_filament_xi(vesicle,tape);
2b14da 72         free(vesicle->tape);
9166cb 73         vesicle->tape=tape;
ea1cce 74         vesicle->clist->dmin_interspecies = tape->dmin_interspecies*tape->dmin_interspecies;
47a7ac 75
SP 76
77
632960 78         /* spherical harmonics */
SP 79         if(tape->shc>0){
459ff9 80             vesicle->sphHarmonics=complex_sph_init(vesicle->vlist,tape->shc);
632960 81         }
SP 82         else {
83             vesicle->sphHarmonics=NULL;
84         }
d9cb01 85
144784 86         if(command_line_args.reset_iteration_count) start_iteration=tape->inititer;
8a6614 87         else start_iteration++;
083e03 88
8a6614 89         if(start_iteration>=tape->iterations){
SP 90             ts_fprintf(stdout, "Simulation already completed. if you want to rerun it try with --force-from-tape or --reset-iteration-count\n\n");
91             return 0;
92         }
a752b5 93
SP 94     /* if requested in tape, we can have smaller number of polymeres attached to membrane than the number of polymeres in dump file */
95         if(vesicle->tape->npoly != vesicle->poly_list->n){
96
97         ts_fprintf(stdout,"(INFO) the number of polymeres attached to membrane in tape is different than a number of polymeres in dump file!\n");
98         if(vesicle->tape->npoly > vesicle->poly_list->n){
99             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);
100             fatal("Terminating due to increase of number of polymeres",1);
101         } else {
102             remove_random_polymeres(vesicle->poly_list, vesicle->poly_list->n - vesicle->tape->npoly);
103             ts_fprintf(stdout,"(INFO)\n(INFO) The new number of polymeres from tape is %d.\n\n",vesicle->poly_list->n);
104
105         }
106         }
8a6614 107     }
SP 108
109     run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration);
267db5 110     write_master_xml_file(command_line_args.output_fullfilename);
8a6614 111     write_dout_fcompat_file(vesicle,"dout");
SP 112     vesicle_free(vesicle);
113     tape_free(tape);
114     return 0; //program finished perfectly ok. We return 0.
d7639a 115