From 1ab449a2d9d4433794736566014f5c311d5a9317 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Sat, 08 Mar 2014 16:33:08 +0000 Subject: [PATCH] tape fixed, output has additional timestamp, ncurrent iteration is dumped and reread, but simulation is not restarted at correct time --- src/main.c | 66 ++----------- src/timestep.c | 2 src/initial_distribution.h | 1 src/io.c | 95 ++++++++----------- src/tape | 4 src/initial_distribution.c | 63 +++++++++--- src/general.h | 23 ++++ src/general.c | 14 ++ src/io.h | 7 9 files changed, 138 insertions(+), 137 deletions(-) diff --git a/src/general.c b/src/general.c index ed06398..a600800 100644 --- a/src/general.c +++ b/src/general.c @@ -3,10 +3,20 @@ #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); + 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; diff --git a/src/general.h b/src/general.h index 2999090..8da1878 100644 --- a/src/general.h +++ b/src/general.h @@ -3,7 +3,6 @@ #include<stdarg.h> #include<stdio.h> - /* @brief This is a header file, defining general constants and structures. * @file header.h * @author Samo Penic @@ -266,6 +265,28 @@ +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 */ diff --git a/src/initial_distribution.c b/src/initial_distribution.c index b8f5965..4d5f565 100644 --- a/src/initial_distribution.c +++ b/src/initial_distribution.c @@ -9,33 +9,60 @@ #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 = pentagonal_dipyramid_vertex_distribution(vesicle->vlist); - retval = init_vertex_neighbours(vesicle->vlist); - vesicle->vlist = init_sort_neighbours(vesicle->blist,vesicle->vlist); + 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 = pentagonal_dipyramid_vertex_distribution(vesicle->vlist); + retval = init_vertex_neighbours(vesicle->vlist); + vesicle->vlist = init_sort_neighbours(vesicle->blist,vesicle->vlist); // retval = init_vesicle_bonds(vesicle); // bonds are created in sort_neigh - retval = init_triangles(vesicle); - retval = init_triangle_neighbours(vesicle); - 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"); + retval = init_triangles(vesicle); + retval = init_triangle_neighbours(vesicle); + retval = init_common_vertex_triangle_neighbours(vesicle); + retval = init_normal_vectors(vesicle->tlist); + retval = mean_curvature_and_energy(vesicle); + 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); diff --git a/src/initial_distribution.h b/src/initial_distribution.h index 7b3e2ba..ef07da9 100644 --- a/src/initial_distribution.h +++ b/src/initial_distribution.h @@ -10,6 +10,7 @@ */ 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 * diff --git a/src/io.c b/src/io.c index 93fda4c..d1a2e3e 100644 --- a/src/io.c +++ b/src/io.c @@ -18,7 +18,7 @@ #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; @@ -131,14 +131,15 @@ */ 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; @@ -316,6 +317,7 @@ 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; @@ -750,80 +752,63 @@ -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); - - return vesicle; + /* global variables are set automatically */ + quiet=tape->quiet; + return tape; +} +ts_bool tape_free(ts_tape *tape){ + free(tape->multiprocessing); + free(tape); + return TS_SUCCESS; } diff --git a/src/io.h b/src/io.h index f76eb09..8f14b68 100644 --- a/src/io.h +++ b/src/io.h @@ -60,8 +60,9 @@ 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 diff --git a/src/main.c b/src/main.c index 0c955dc..44d90e2 100644 --- a/src/main.c +++ b/src/main.c @@ -19,74 +19,30 @@ */ int main(int argv, char *argc[]){ -ts_uint inititer,mcsweeps, iterations; -ts_vesicle *vesicle, *vesicle1; - - -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_vesicle *vesicle; + ts_tape *tape; + ts_uint start_iteration=0; + parse_args(argv,argc); + 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. } diff --git a/src/tape b/src/tape index 18eea15..59b417a 100644 --- a/src/tape +++ b/src/tape @@ -4,7 +4,7 @@ # 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 @@ -16,7 +16,7 @@ ####### 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 diff --git a/src/timestep.c b/src/timestep.c index 8ae5a30..4ac20be 100644 --- a/src/timestep.c +++ b/src/timestep.c @@ -22,7 +22,7 @@ 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); } -- Gitblit v1.9.3