From a3dbf0899f9a077c025136336b597ae9b22e414f Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@fe.uni-lj.si>
Date: Fri, 26 Feb 2016 10:34:38 +0000
Subject: [PATCH] Basic vesicle is dumped and restored, however, memory is not ok.

---
 src/snapshot.c |   22 ++++++++--
 src/tape       |    4 +-
 src/restore.h  |    1 
 src/restore.c  |   34 +++++++++++++++++
 4 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/src/restore.c b/src/restore.c
index 13617c3..94e2621 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -10,6 +10,9 @@
 #include "vesicle.h"
 #include "vertex.h"
 #include "triangle.h"
+#include "bond.h"
+#include "energy.h"
+#include "initial_distribution.h"
 
 ts_bool parseDump(char *dumpfname) {
 	xmlDocPtr doc;
@@ -51,6 +54,8 @@
 						}
 						if ((!xmlStrcmp(cur2->name, (const xmlChar *)"Cells"))){
 						fprintf(stderr,"Found cell(Bonds) data\n");
+							if(vesicle!=NULL)
+								parseXMLBonds(vesicle, doc, cur);
 						}
 						cur2=cur2->next;
 					}	
@@ -63,6 +68,11 @@
 	}
 	
 	xmlFreeDoc(doc);
+	init_normal_vectors(vesicle->tlist);
+	mean_curvature_and_energy(vesicle);
+
+/* TODO: cells, polymeres, filaments, core, tape */
+
 	fprintf(stderr,"Restoration completed\n");
 	exit(0);
 	vesicle_free(vesicle);
@@ -245,5 +255,29 @@
 	}
 	return TS_SUCCESS;
 }
+ts_bool parseXMLBonds(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur){
+	xmlNodePtr child = cur->xmlChildrenNode;
+	xmlChar *bonds;
+	char *b;
+	int i, idx;
+	char *token[2];
+	while (child != NULL) {
+		if ((!xmlStrcmp(child->name, (const xmlChar *)"DataArray"))){
+			bonds = xmlNodeListGetString(doc, child->xmlChildrenNode, 1);
+			b=(char *)bonds;
+			for(i=0;i<2;i++)	token[i]=strtok(b," ");
+			idx=0;
+			while(token[0]!=NULL){
+				bond_add(vesicle->blist, vesicle->vlist->vtx[atoi(token[0])], vesicle->vlist->vtx[atoi(token[1])]);
+				for(i=0;i<2;i++)	token[i]=strtok(NULL," ");	
+				idx++;
+			}
+			xmlFree(bonds);
+		}
+		child=child->next;
+	}
+	return TS_SUCCESS;
+}
+
 
 
diff --git a/src/restore.h b/src/restore.h
index b5df851..414bb62 100644
--- a/src/restore.h
+++ b/src/restore.h
@@ -7,4 +7,5 @@
 ts_bool parseTrisurfTria(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur);
 ts_bool parseTrisurfTristar(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur);
 ts_bool parseXMLVertexPosition(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur);
+ts_bool parseXMLBonds(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur);
 #endif
diff --git a/src/snapshot.c b/src/snapshot.c
index f279dd0..e4681b0 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -8,6 +8,7 @@
 #include<config.h>
 #include <time.h>
 
+/* a helper function that utilizes ts_string data structure and performs same as sprintf */
 ts_uint ts_sprintf(ts_string *str, char *fmt, ...){
 	va_list ap;
 	va_start(ap,fmt);
@@ -17,7 +18,7 @@
 	return n;
 }
 
-
+/* outputs additional data into paraview xml file */
 ts_bool xml_trisurf_data(FILE *fh, ts_vesicle *vesicle){
 
 	ts_string *data=(ts_string *)malloc(sizeof(ts_sprintf));
@@ -37,7 +38,7 @@
 #else
 	fprintf(fh,"%s", data->string);
 #endif
-	free(data->string);
+	free(data->string);  /* TODO: valgrind is not ok with this! */
 	free(data);
 	xml_trisurf_footer(fh);
 	return TS_SUCCESS;
@@ -49,15 +50,26 @@
     	char *c_time_string;
 	current_time = time(NULL);
 	c_time_string = ctime(&current_time);
-	
+	int npoly, nfono;	
+
 	fprintf(fh, "<trisurfversion>Trisurf (commit %s), compiled on %s %s</trisurfversion>\n",TS_VERSION, __DATE__,  __TIME__);
 	fprintf(fh, "<dumpdate>%s</dumpdate>\n", c_time_string);
-	//free (c_time_string);
 
 	fprintf(fh, "<tape>\n");
 	
 	fprintf(fh, "</tape>\n");
-	fprintf(fh, "<trisurf nvtx=\"%u\" npoly=\"%u\" nfono=\"%u\">\n", vesicle->vlist->n, vesicle->poly_list->n, vesicle->poly_list->poly[0]->vlist->n);
+	if(vesicle->poly_list!=NULL){
+		npoly=vesicle->poly_list->n;
+		if(npoly!=0){
+			nfono=vesicle->poly_list->poly[0]->vlist->n;
+		} else {
+			nfono=0;
+		}
+	} else {
+		npoly=0;
+		nfono=0;
+	}
+	fprintf(fh, "<trisurf nvtx=\"%u\" npoly=\"%u\" nfono=\"%u\">\n", vesicle->vlist->n, npoly, nfono);
 	return TS_SUCCESS;
 }
 
diff --git a/src/tape b/src/tape
index 3e6290b..4fd57e5 100644
--- a/src/tape
+++ b/src/tape
@@ -1,6 +1,6 @@
 ####### Vesicle definitions ###########
 # nshell is a number of divisions of dipyramid
-nshell=19
+nshell=5
 # dmax is the max. bond length (in units l_min)
 dmax=1.7
 # dmin_interspecies in the min. dist. between different vertex species (in units l_min)
@@ -25,7 +25,7 @@
 
 ####### Polymer (brush) definitions ###########
 # npoly is a number of polymers attached to npoly distinct vertices on vesicle
-npoly=10
+npoly=0
 # nmono is a number of monomers in each polymer
 nmono=10
 # Spring constant between monomers of the polymer

--
Gitblit v1.9.3