tape fixed, output has additional timestamp, ncurrent iteration is dumped and reread, but simulation is not restarted at correct time
| | |
| | | #include "general.h" |
| | | #include<stdarg.h> |
| | | |
| | | #include <sys/time.h> |
| | | #include <unistd.h> |
| | | #include <time.h> |
| | | |
| | | |
| | | ts_uint ts_fprintf(FILE *fd, char *fmt, ...){ |
| | | if(quiet) return TS_SUCCESS; |
| | | va_list ap; |
| | | va_start(ap,fmt); |
| | | char tmbuf[255]; |
| | | struct timeval now; |
| | | gettimeofday(&now, 0); |
| | | strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", localtime(&now.tv_sec)); |
| | | fprintf(fd, "[%s] ",tmbuf); |
| | | vfprintf(fd, fmt, ap); /* Call vfprintf */ |
| | | va_end(ap); /* Cleanup the va_list */ |
| | | return TS_SUCCESS; |
| | |
| | | |
| | | #include<stdarg.h> |
| | | #include<stdio.h> |
| | | |
| | | /* @brief This is a header file, defining general constants and structures. |
| | | * @file header.h |
| | | * @author Samo Penic |
| | |
| | | |
| | | |
| | | |
| | | typedef struct { |
| | | long int nshell; |
| | | long int ncxmax; |
| | | long int ncymax; |
| | | long int nczmax; |
| | | long int npoly; |
| | | long int nmono; |
| | | long int pswitch; |
| | | char *multiprocessing; |
| | | long int brezveze0; |
| | | long int brezveze1; |
| | | long int brezveze2; |
| | | ts_double xk0; |
| | | ts_double dmax; |
| | | ts_double stepsize; |
| | | ts_double kspring; |
| | | ts_double pressure; |
| | | long int iterations; |
| | | long int inititer; |
| | | long int mcsweeps; |
| | | long int quiet; |
| | | } ts_tape; |
| | | |
| | | /* GLOBAL VARIABLES */ |
| | | |
| | |
| | | #include "triangle.h" |
| | | #include "initial_distribution.h" |
| | | #include "energy.h" |
| | | #include "poly.h" |
| | | |
| | | ts_vesicle *initial_distribution_dipyramid(ts_uint nshell, ts_uint ncmax1, ts_uint ncmax2, ts_uint ncmax3, ts_double stepsize){ |
| | | ts_fprintf(stderr,"Starting initial_distribution on vesicle with %u shells!...\n",nshell); |
| | | ts_fprintf(stdout,"Starting initial_distribution on vesicle with %u shells!...\n",nshell); |
| | | ts_bool retval; |
| | | ts_uint no_vertices=5*nshell*nshell+2; |
| | | |
| | | |
| | | |
| | | ts_vesicle *vesicle=init_vesicle(no_vertices,ncmax1,ncmax2,ncmax3,stepsize); |
| | | |
| | | vesicle->nshell=nshell; |
| | | retval = vtx_set_global_values(vesicle); |
| | | //retval = vtx_set_global_values(vesicle); |
| | | retval = pentagonal_dipyramid_vertex_distribution(vesicle->vlist); |
| | | retval = init_vertex_neighbours(vesicle->vlist); |
| | | vesicle->vlist = init_sort_neighbours(vesicle->blist,vesicle->vlist); |
| | |
| | | retval = init_common_vertex_triangle_neighbours(vesicle); |
| | | retval = init_normal_vectors(vesicle->tlist); |
| | | retval = mean_curvature_and_energy(vesicle); |
| | | ts_fprintf(stderr,"initial_distribution finished!\n"); |
| | | ts_fprintf(stdout,"initial_distribution finished!\n"); |
| | | if(retval); |
| | | return vesicle; |
| | | } |
| | | |
| | | |
| | | |
| | | ts_vesicle *create_vesicle_from_tape(ts_tape *tape){ |
| | | ts_vesicle *vesicle; |
| | | vesicle=initial_distribution_dipyramid(tape->nshell,tape->ncxmax,tape->ncymax,tape->nczmax,tape->stepsize); |
| | | vesicle->poly_list=init_poly_list(tape->npoly,tape->nmono, vesicle->vlist); |
| | | vesicle->spring_constant=tape->kspring; |
| | | poly_assign_spring_const(vesicle); |
| | | |
| | | vesicle->nshell=tape->nshell; |
| | | vesicle->dmax=tape->dmax*tape->dmax; /* dmax^2 in the vesicle dmax variable */ |
| | | vesicle->bending_rigidity=tape->xk0; |
| | | vtx_set_global_values(vesicle); /* make xk0 default value for every vertex */ |
| | | ts_fprintf(stdout, "Tape setting: xk0=%e\n",tape->xk0); |
| | | vesicle->stepsize=tape->stepsize; |
| | | vesicle->clist->ncmax[0]=tape->ncxmax; |
| | | vesicle->clist->ncmax[1]=tape->ncymax; |
| | | vesicle->clist->ncmax[2]=tape->nczmax; |
| | | vesicle->clist->max_occupancy=8; /* hard coded max occupancy? */ |
| | | |
| | | vesicle->pressure= tape->pressure; |
| | | vesicle->pswitch=tape->pswitch; |
| | | |
| | | return vesicle; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | ts_bool pentagonal_dipyramid_vertex_distribution(ts_vertex_list *vlist){ |
| | | /* Some often used relations */ |
| | | const ts_double s1= sin(2.0*M_PI/5.0); |
| | |
| | | */ |
| | | ts_vesicle *initial_distribution_dipyramid(ts_uint nshell, ts_uint ncmax1, ts_uint ncmax2, ts_uint ncmax3, ts_double stepsize); |
| | | |
| | | ts_vesicle *create_vesicle_from_tape(ts_tape *tape); |
| | | |
| | | /** Sets the initial position of the vertexes to dipyramid |
| | | * |
| | |
| | | #include <errno.h> |
| | | /** DUMP STATE TO DISK DRIVE **/ |
| | | |
| | | ts_bool dump_state(ts_vesicle *vesicle){ |
| | | ts_bool dump_state(ts_vesicle *vesicle, ts_uint iteration){ |
| | | |
| | | /* save current state with wrong pointers. Will fix that later */ |
| | | ts_uint i,j,k; |
| | |
| | | |
| | | fwrite(vesicle->clist, sizeof(ts_cell_list),1, fh); |
| | | |
| | | fwrite(&iteration, sizeof(ts_uint),1,fh); |
| | | fclose(fh); |
| | | return TS_SUCCESS; |
| | | } |
| | | |
| | | |
| | | /** RESTORE DUMP FROM DISK **/ |
| | | ts_vesicle *restore_state(){ |
| | | ts_vesicle *restore_state(ts_uint *iteration){ |
| | | ts_uint i,j,k; |
| | | FILE *fh=fopen("dump.bin","rb"); |
| | | ts_uint retval; |
| | |
| | | vesicle->clist->cell[i]->idx=i+1; // We enumerate cells! Probably never required! |
| | | } |
| | | |
| | | retval=fread(iteration,sizeof(ts_uint),1,fh); |
| | | if(retval); |
| | | fclose(fh); |
| | | return vesicle; |
| | |
| | | |
| | | |
| | | |
| | | ts_vesicle *parsetape(ts_uint *mcsweeps, ts_uint *inititer, ts_uint *iterations){ |
| | | long int nshell=17,ncxmax=60, ncymax=60, nczmax=60, npoly=10, nmono=20, pswitch=0; // THIS IS DUE TO CONFUSE BUG! |
| | | char *buf=malloc(255*sizeof(char)); |
| | | long int brezveze0=1; |
| | | ts_tape *parsetape(char *filename){ |
| | | // long int nshell=17,ncxmax=60, ncymax=60, nczmax=60, npoly=10, nmono=20, pswitch=0; // THIS IS DUE TO CONFUSE BUG! |
| | | ts_tape *tape=(ts_tape *)calloc(1,sizeof(ts_tape)); |
| | | tape->multiprocessing=calloc(255,sizeof(char)); |
| | | /* long int brezveze0=1; |
| | | long int brezveze1=1; |
| | | long int brezveze2=1; |
| | | ts_double xk0=25.0, dmax=1.67,stepsize=0.15,kspring=800.0,pressure=0.0; |
| | | long int iter=1000, init=1000, mcsw=1000; |
| | | |
| | | */ |
| | | |
| | | cfg_opt_t opts[] = { |
| | | CFG_SIMPLE_INT("nshell", &nshell), |
| | | CFG_SIMPLE_INT("npoly", &npoly), |
| | | CFG_SIMPLE_INT("nmono", &nmono), |
| | | CFG_SIMPLE_FLOAT("dmax", &dmax), |
| | | CFG_SIMPLE_FLOAT("xk0",&xk0), |
| | | CFG_SIMPLE_INT("pswitch",&pswitch), |
| | | CFG_SIMPLE_FLOAT("pressure",&pressure), |
| | | CFG_SIMPLE_FLOAT("k_spring",&kspring), |
| | | CFG_SIMPLE_FLOAT("stepsize",&stepsize), |
| | | CFG_SIMPLE_INT("nxmax", &ncxmax), |
| | | CFG_SIMPLE_INT("nymax", &ncymax), |
| | | CFG_SIMPLE_INT("nzmax", &nczmax), |
| | | CFG_SIMPLE_INT("iterations",&iter), |
| | | CFG_SIMPLE_INT("mcsweeps",&mcsw), |
| | | CFG_SIMPLE_INT("inititer", &init), |
| | | CFG_SIMPLE_BOOL("quiet",&quiet), |
| | | CFG_SIMPLE_STR("multiprocessing",buf), |
| | | CFG_SIMPLE_INT("smp_cores",&brezveze0), |
| | | CFG_SIMPLE_INT("cluster_nodes",&brezveze1), |
| | | CFG_SIMPLE_INT("distributed_processes",&brezveze2), |
| | | CFG_SIMPLE_INT("nshell", &tape->nshell), |
| | | CFG_SIMPLE_INT("npoly", &tape->npoly), |
| | | CFG_SIMPLE_INT("nmono", &tape->nmono), |
| | | CFG_SIMPLE_FLOAT("dmax", &tape->dmax), |
| | | CFG_SIMPLE_FLOAT("xk0",&tape->xk0), |
| | | CFG_SIMPLE_INT("pswitch",&tape->pswitch), |
| | | CFG_SIMPLE_FLOAT("pressure",&tape->pressure), |
| | | CFG_SIMPLE_FLOAT("k_spring",&tape->kspring), |
| | | CFG_SIMPLE_FLOAT("stepsize",&tape->stepsize), |
| | | CFG_SIMPLE_INT("nxmax", &tape->ncxmax), |
| | | CFG_SIMPLE_INT("nymax", &tape->ncymax), |
| | | CFG_SIMPLE_INT("nzmax", &tape->nczmax), |
| | | CFG_SIMPLE_INT("iterations",&tape->iterations), |
| | | CFG_SIMPLE_INT("mcsweeps",&tape->mcsweeps), |
| | | CFG_SIMPLE_INT("inititer", &tape->inititer), |
| | | CFG_SIMPLE_BOOL("quiet",&tape->quiet), |
| | | CFG_SIMPLE_STR("multiprocessing",tape->multiprocessing), |
| | | CFG_SIMPLE_INT("smp_cores",&tape->brezveze0), |
| | | CFG_SIMPLE_INT("cluster_nodes",&tape->brezveze1), |
| | | CFG_SIMPLE_INT("distributed_processes",&tape->brezveze2), |
| | | CFG_END() |
| | | }; |
| | | cfg_t *cfg; |
| | | ts_uint retval; |
| | | cfg = cfg_init(opts, 0); |
| | | retval=cfg_parse(cfg, "tape"); |
| | | retval=cfg_parse(cfg, filename); |
| | | if(retval==CFG_FILE_ERROR){ |
| | | fatal("No tape file.",100); |
| | | } |
| | | else if(retval==CFG_PARSE_ERROR){ |
| | | fatal("Invalid tape!",100); |
| | | } |
| | | ts_vesicle *vesicle; |
| | | *iterations=iter; |
| | | *inititer=init; |
| | | *mcsweeps=mcsw; |
| | | vesicle=initial_distribution_dipyramid(nshell,ncxmax,ncymax,nczmax,stepsize); |
| | | vesicle->poly_list=init_poly_list(npoly,nmono, vesicle->vlist); |
| | | vesicle->spring_constant=kspring; |
| | | poly_assign_spring_const(vesicle); |
| | | |
| | | |
| | | vesicle->nshell=nshell; |
| | | vesicle->dmax=dmax*dmax; |
| | | vesicle->bending_rigidity=xk0; |
| | | vtx_set_global_values(vesicle); //copies xk0 to every vertex |
| | | |
| | | |
| | | vesicle->stepsize=stepsize; |
| | | vesicle->clist->ncmax[0]=ncxmax; |
| | | vesicle->clist->ncmax[1]=ncymax; |
| | | vesicle->clist->ncmax[2]=nczmax; |
| | | vesicle->clist->max_occupancy=8; |
| | | vesicle->pressure=pressure/vesicle->bending_rigidity; //all energy contributions need to be divided by bending_rigidity! |
| | | vesicle->pswitch=pswitch; |
| | | cfg_free(cfg); |
| | | free(buf); |
| | | // fprintf(stderr,"NSHELL=%u\n",vesicle->nshell); |
| | | |
| | | |
| | | /* global variables are set automatically */ |
| | | quiet=tape->quiet; |
| | | return tape; |
| | | } |
| | | |
| | | return vesicle; |
| | | |
| | | ts_bool tape_free(ts_tape *tape){ |
| | | free(tape->multiprocessing); |
| | | free(tape); |
| | | return TS_SUCCESS; |
| | | } |
| | | |
| | | |
| | |
| | | ts_bool write_vertex_vtk_file(ts_vesicle *vesicle,ts_char *filename, ts_char *text); |
| | | ts_bool write_vertex_xml_file(ts_vesicle *vesicle, ts_uint timestepno); |
| | | ts_bool write_master_xml_file(ts_char *filename); |
| | | ts_vesicle *parsetape(ts_uint *mcsweeps, ts_uint *inititer, ts_uint *iterations); |
| | | ts_tape *parsetape(char *filename); |
| | | ts_bool tape_free(ts_tape *tape); |
| | | |
| | | ts_bool dump_state(ts_vesicle *vesicle); |
| | | ts_vesicle *restore_state(); |
| | | ts_bool dump_state(ts_vesicle *vesicle, ts_uint iteration); |
| | | ts_vesicle *restore_state(ts_uint *iteration); |
| | | #endif |
| | |
| | | */ |
| | | |
| | | int main(int argv, char *argc[]){ |
| | | ts_uint inititer,mcsweeps, iterations; |
| | | ts_vesicle *vesicle, *vesicle1; |
| | | |
| | | |
| | | ts_vesicle *vesicle; |
| | | ts_tape *tape; |
| | | ts_uint start_iteration=0; |
| | | parse_args(argv,argc); |
| | | |
| | | /* THIS SHOULD GO INTO UNIT TEST |
| | | ts_bool retval; |
| | | ts_vertex_list *vlist=init_vertex_list(5); |
| | | ts_vertex_list *vlist1; |
| | | ts_bond_list *blist=init_bond_list(); |
| | | ts_triangle_list *tlist=init_triangle_list(); |
| | | ts_cell_list *clist=init_cell_list(3,3,3,0.3); |
| | | |
| | | retval=vtx_add_cneighbour(blist,vlist->vtx[1],vlist->vtx[0]); |
| | | if(retval==TS_FAIL) printf("1. already a member or vertex is null!\n"); |
| | | |
| | | retval=vtx_add_neighbour(vlist->vtx[0],vlist->vtx[1]); |
| | | if(retval==TS_FAIL) printf("2. already a member or vertex is null!\n"); |
| | | fprintf(stderr,"Was here"); |
| | | retval=vtx_remove_neighbour(vlist->vtx[1],vlist->vtx[0]); |
| | | vtx_add_neighbour(vlist->vtx[0],vlist->vtx[1]); |
| | | fprintf(stderr,"Was here too!\n"); |
| | | |
| | | vlist->vtx[0]->x=1.0; |
| | | vlist->vtx[0]->x=1.1; |
| | | vlist1=vertex_list_copy(vlist); |
| | | bond_add(blist, vlist->vtx[1],vlist->vtx[0]); |
| | | triangle_add(tlist,vlist->vtx[1],vlist->vtx[2],vlist->vtx[3]); |
| | | |
| | | triangle_add(tlist,vlist->vtx[1],vlist->vtx[2],vlist->vtx[3]); |
| | | |
| | | printf("Cell idx=1 has vertices=%u\n",clist->cell[0]->nvertex); |
| | | cell_add_vertex(clist->cell[0], vlist->vtx[0]); |
| | | printf("Cell idx=1 has vertices=%u\n",clist->cell[0]->nvertex); |
| | | printf("Cell idx=1 has vertex[0] has x coordinate=%e\n",clist->cell[0]->vertex[0]->x); |
| | | cell_list_cell_occupation_clear(clist); |
| | | printf("Cell idx=1 has vertices=%u\n",clist->cell[0]->nvertex); |
| | | cell_add_vertex(clist->cell[0], vlist->vtx[0]); |
| | | |
| | | |
| | | triangle_list_free(tlist); |
| | | bond_list_free(blist); |
| | | vtx_list_free(vlist); |
| | | cell_list_free(clist); |
| | | |
| | | vtx_list_free(vlist1); |
| | | printf("Tests complete.\n"); |
| | | */ |
| | | ts_fprintf(stdout,"\nStarting program...\n\n"); |
| | | if(force_from_tape){ |
| | | ts_fprintf(stdout,"****************************************************\n"); |
| | | ts_fprintf(stdout,"**** Reinitializing initial geometry from tape *****\n"); |
| | | ts_fprintf(stdout,"****************************************************\n\n"); |
| | | vesicle=parsetape(&mcsweeps, &inititer, &iterations); |
| | | tape=parsetape("tape"); |
| | | vesicle=create_vesicle_from_tape(tape); |
| | | } else { |
| | | |
| | | ts_fprintf(stdout,"**********************************************************************\n"); |
| | | ts_fprintf(stdout,"**** Recreating vesicle from dump file and continuing simulation *****\n"); |
| | | ts_fprintf(stdout,"**********************************************************************\n\n"); |
| | | vesicle1=parsetape(&mcsweeps, &inititer, &iterations); |
| | | vesicle=restore_state(); |
| | | vesicle_free(vesicle1); |
| | | tape=parsetape("tape"); |
| | | vesicle=restore_state(&start_iteration); |
| | | } |
| | | |
| | | run_simulation(vesicle, mcsweeps, inititer, iterations); |
| | | run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations); |
| | | write_master_xml_file("test.pvd"); |
| | | write_dout_fcompat_file(vesicle,"dout"); |
| | | vesicle_free(vesicle); |
| | | |
| | | tape_free(tape); |
| | | return 0; //program finished perfectly ok. We return 0. |
| | | } |
| | |
| | | # dmax is the max. bond length (in units l_min) |
| | | dmax=1.7 |
| | | # bending rigidity of the membrane (in units kT) |
| | | xk0=1.0 |
| | | xk0=25.0 |
| | | # max step size (in units l_min) |
| | | stepsize=0.15 |
| | | |
| | |
| | | |
| | | ####### Polymer definitions ########### |
| | | # npoly is a number of polymers attached to npoly distinct vertices on vesicle |
| | | npoly=0 |
| | | npoly=20 |
| | | # nmono is a number of monomers in each polymer |
| | | nmono=10 |
| | | # Spring constant between monomers of the polymer |
| | |
| | | centermass(vesicle); |
| | | cell_occupation(vesicle); |
| | | ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps); |
| | | dump_state(vesicle); |
| | | dump_state(vesicle,i); |
| | | if(i>inititer){ |
| | | write_vertex_xml_file(vesicle,i-inititer); |
| | | } |