From 1153c110781fc3add2c22ab2d996e05b0e0b10de Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Sat, 08 Mar 2014 11:56:00 +0000
Subject: [PATCH] Merged branches polyel with constant volume

---
 src/io.c |   44 +++++++++++++++++++++++++++++++-------------
 1 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/io.c b/src/io.c
index 262e482..aab00bb 100644
--- a/src/io.c
+++ b/src/io.c
@@ -22,7 +22,7 @@
     FILE *fh=fopen("dump.bin","wb");
 
     /* dump vesicle */
-    fwrite(vesicle, sizeof(vesicle),1,fh);
+    fwrite(vesicle, sizeof(ts_vesicle),1,fh);
     /* dump vertex list */
     fwrite(vesicle->vlist, sizeof(ts_vertex_list),1,fh);
     /* dump bond list */
@@ -127,6 +127,8 @@
         poly_list->poly->bond
 */
 
+	fwrite(vesicle->clist, sizeof(ts_cell_list),1,  fh);
+
     fclose(fh);
     return TS_SUCCESS;
 }
@@ -142,7 +144,9 @@
 /* we restore all the data from the dump */
     /* restore vesicle */
     ts_vesicle *vesicle=(ts_vesicle *)calloc(1,sizeof(ts_vesicle));
-    retval=fread(vesicle, sizeof(vesicle),1,fh);
+    retval=fread(vesicle, sizeof(ts_vesicle),1,fh);
+//	fprintf(stderr,"was here! %e\n",vesicle->dmax);
+
     /* restore vertex list */
     vesicle->vlist=(ts_vertex_list *)malloc(sizeof(ts_vertex_list));
     retval=fread(vesicle->vlist, sizeof(ts_vertex_list),1,fh);
@@ -170,11 +174,13 @@
     for(i=0;i<vesicle->tlist->n;i++){
         vesicle->tlist->tria[i]=(ts_triangle *)malloc(sizeof(ts_triangle));
 }
-
-  /*restore vertices*/
+/* prerequisity. Vertices must be malloced before vertexes are recreated */
     vesicle->vlist->vtx=(ts_vertex **)calloc(vesicle->vlist->n,sizeof(ts_vertex *));
-    for(i=0;i<vesicle->vlist->n;i++){
+ for(i=0;i<vesicle->vlist->n;i++){
         vesicle->vlist->vtx[i]=(ts_vertex *)malloc(sizeof(ts_vertex));
+ }
+  /*restore vertices*/
+    for(i=0;i<vesicle->vlist->n;i++){
         retval=fread(vesicle->vlist->vtx[i],sizeof(ts_vertex),1,fh);
         /*restore neigh, bond, tristar. Ignoring cell */
         vesicle->vlist->vtx[i]->neigh=(ts_vertex **)calloc(vesicle->vlist->vtx[i]->neigh_no, sizeof(ts_vertex *));
@@ -298,8 +304,14 @@
         }
     }
 
-  
-
+// recreating space for cells // 
+	vesicle->clist=(ts_cell_list *)malloc(sizeof(ts_cell_list));
+	retval=fread(vesicle->clist, sizeof(ts_cell_list), 1,fh); 
+	vesicle->clist->cell=(ts_cell **)malloc(sizeof(ts_cell *)*vesicle->clist->ncmax[0]*vesicle->clist->ncmax[1]*vesicle->clist->ncmax[2]);
+	for(i=0;i<vesicle->clist->ncmax[0]*vesicle->clist->ncmax[1]*vesicle->clist->ncmax[2];i++){
+        	vesicle->clist->cell[i]=(ts_cell *)calloc(1,sizeof(ts_cell));
+        	vesicle->clist->cell[i]->idx=i+1; // We enumerate cells! Probably never required!
+    	}
 
     if(retval); 
     fclose(fh);
@@ -405,11 +417,11 @@
         fprintf(fh," %.17E\t%.17E\t%.17E\t%.17E\t%.17E\t%u\n",
         vlist->vtx[i]->xk,vlist->vtx[i]->c,vlist->vtx[i]->energy,
         vlist->vtx[i]->energy_h, vlist->vtx[i]->curvature, 0);
-        for(j=0;j<vlist->vtx[i]->neigh_no;j++){
+        for(j=0;j<vlist->vtx[i]->bond_no;j++){
             fprintf(fh," %.17E", vlist->vtx[i]->bond[j]->bond_length_dual);
         }
             fprintf(fh,"\n");
-        for(j=0;j<vlist->vtx[i]->neigh_no;j++){
+        for(j=0;j<vlist->vtx[i]->bond_no;j++){
             fprintf(fh," %.17E", vlist->vtx[i]->bond[j]->bond_length);
         }
             fprintf(fh,"\n");
@@ -636,12 +648,12 @@
 
 
 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;  // THIS IS DUE TO CONFUSE BUG!
+    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;
     long int brezveze1=1;
     long int brezveze2=1;
-    ts_double xk0=25.0, dmax=1.67,stepsize=0.15,kspring=800.0;
+    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;
 
 
@@ -651,7 +663,9 @@
         CFG_SIMPLE_INT("nmono", &nmono),
         CFG_SIMPLE_FLOAT("dmax", &dmax),
         CFG_SIMPLE_FLOAT("xk0",&xk0),
-        CFG_SIMPLE_FLOAT("k_spring",&kspring),
+	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),
@@ -689,12 +703,16 @@
     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);

--
Gitblit v1.9.3