From 49981c5ddda35e6defd63d860bccfbc66e7158ca Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@fe.uni-lj.si>
Date: Thu, 02 Jun 2016 10:13:11 +0000
Subject: [PATCH] ConstVol and ConstArea area+volume are now also in the snapshost. Fix in timing of writting the .status file to the disk.

---
 src/timestep.c |   22 +++++++++++++---------
 src/snapshot.c |    9 ++++++++-
 src/restore.h  |    2 ++
 src/restore.c  |   22 ++++++++++++++++++++++
 src/snapshot.h |    1 +
 5 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/src/restore.c b/src/restore.c
index 196df76..3a93d3f 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -168,6 +168,13 @@
 		 if ((!xmlStrcmp(child->name, (const xmlChar *)"nucleus"))){
 			parseTrisurfNucleus(vesicle, doc, child);
 		}
+	 	 if ((!xmlStrcmp(child->name, (const xmlChar *)"constant_volume"))){
+			parseTrisurfConstantVolume(doc, child);
+		}
+	 	 if ((!xmlStrcmp(child->name, (const xmlChar *)"constant_area"))){
+			parseTrisurfConstantArea(doc, child);
+		}
+
 
 	child = child->next;
 	}
@@ -182,6 +189,21 @@
 
 
 /* Low level tags parsers */
+ts_bool parseTrisurfConstantVolume(xmlDocPtr doc, xmlNodePtr cur){
+	xmlChar *cvol = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	char *n=(char *)cvol;
+	V0=atof(n);
+	xmlFree(cvol);
+	return TS_SUCCESS;
+}
+ts_bool parseTrisurfConstantArea(xmlDocPtr doc, xmlNodePtr cur){
+	xmlChar *carea = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	char *n=(char *)carea;
+	A0=atof(n);
+	xmlFree(carea);
+	return TS_SUCCESS;
+}
+
 ts_bool parseTrisurfNucleus(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){
 	xmlChar *coords = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	char *n=(char *)coords;
diff --git a/src/restore.h b/src/restore.h
index 934d6e8..cfc6b66 100644
--- a/src/restore.h
+++ b/src/restore.h
@@ -12,4 +12,6 @@
 ts_bool parseXMLVertexPosition(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur);
 ts_bool parseXMLBonds(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur);
 ts_bool parseTrisurfNucleus(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur);
+ts_bool parseTrisurfConstantVolume(xmlDocPtr doc, xmlNodePtr cur);
+ts_bool parseTrisurfConstantArea(xmlDocPtr doc, xmlNodePtr cur);
 #endif
diff --git a/src/snapshot.c b/src/snapshot.c
index 8b71e83..fbb6d4b 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -33,6 +33,7 @@
 	xml_trisurf_vtx_neigh(data,vesicle->vlist);	
 	xml_trisurf_vtx_tristar(data,vesicle->vlist);
 	xml_trisurf_nucleus(data,vesicle);
+	xml_trisurf_constvolarea(data,V0,A0);
 #ifdef COMPRESSION
 	char *compressed;
 	ts_uint nbytes=ts_compress_string64(data->string, data->beg-1, &compressed); //suppress null character at the end with by substracting 1
@@ -127,10 +128,16 @@
 
 ts_bool xml_trisurf_nucleus(ts_string *data, ts_vesicle* vesicle){
 	if(vesicle->R_nucleus>0.0 || (vesicle->R_nucleusX>0.0 && vesicle->R_nucleusY>0.0 && vesicle->R_nucleusZ>0.0)){
-		ts_sprintf(data,"<nucleus>%.17e %.17e %.7e</nucleus>",vesicle->nucleus_center[0], vesicle->nucleus_center[1], vesicle->nucleus_center[2]);
+		ts_sprintf(data,"<nucleus>%.17e %.17e %.17e</nucleus>",vesicle->nucleus_center[0], vesicle->nucleus_center[1], vesicle->nucleus_center[2]);
 	}
 	return TS_SUCCESS;
 }
+ts_bool xml_trisurf_constvolarea(ts_string *data, ts_double volume, ts_double area){
+	ts_sprintf(data,"<constant_volume>%.17e</constant_volume>",volume);
+	ts_sprintf(data,"<constant_area>%.17e</constant_area>",area);
+
+	return TS_SUCCESS;
+}
 
 
 /* UTILITIES */
diff --git a/src/snapshot.h b/src/snapshot.h
index 0db57f4..7bc617b 100644
--- a/src/snapshot.h
+++ b/src/snapshot.h
@@ -19,6 +19,7 @@
 ts_bool xml_trisurf_vtx_neigh(ts_string *data, ts_vertex_list *vlist);
 ts_bool xml_trisurf_vtx_tristar(ts_string *data, ts_vertex_list *vlist);
 ts_bool xml_trisurf_nucleus(ts_string *data, ts_vesicle* vesicle);
+ts_bool xml_trisurf_constvolarea(ts_string *data, ts_double volume, ts_double area);
 /* UTILITIES */
 char *base64_encode(const unsigned char *data, size_t input_length, size_t *output_length);
 unsigned char *base64_decode(const char *data, size_t input_length, size_t *output_length);
diff --git a/src/timestep.c b/src/timestep.c
index df74c43..9f40e1c 100644
--- a/src/timestep.c
+++ b/src/timestep.c
@@ -65,8 +65,12 @@
 	cell_occupation(vesicle);
 	vesicle_volume(vesicle); //needed for constant volume at this moment
     vesicle_area(vesicle); //needed for constant area at this moment
-	V0=vesicle->volume; 
-    A0=vesicle->area;
+	if(V0<0.000001) 
+		V0=vesicle->volume; 
+	ts_fprintf(stdout,"Setting volume V0=%.17f\n",V0);
+	if(A0<0.000001)
+		A0=vesicle->area;
+		ts_fprintf(stdout,"Setting area A0=%.17f\n",A0);
 	epsvol=4.0*sqrt(2.0*M_PI)/pow(3.0,3.0/4.0)*V0/pow(vesicle->tlist->n,3.0/2.0);
     epsarea=A0/(ts_double)vesicle->tlist->n;
   //  fprintf(stderr, "DVol=%1.16f (%1.16f), V0=%1.16f\n", epsvol,0.003e-2*V0,V0);
@@ -88,14 +92,7 @@
 		bfsr/=(ts_double)mcsweeps;
 		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,i);
-		fd3=fopen(".status","w");
-		if(fd3==NULL){
-			fatal("Cannot open .status file for writing",1);
-		}
-		fprintf(fd3,"%d",i);
-		fclose(fd3);
 		if(i>=inititer){
 			write_vertex_xml_file(vesicle,i-inititer);
 			write_master_xml_file(command_line_args.output_fullfilename);
@@ -146,7 +143,14 @@
 		    fflush(fd);	
 		//	sprintf(filename,"timestep-%05d.pov",i-inititer);
 		//	write_pov_file(vesicle,filename);
+		} //end if(inititer....)
+		fd3=fopen(".status","w"); //write status file when everything is written to disk.
+		if(fd3==NULL){
+			fatal("Cannot open .status file for writing",1);
 		}
+		fprintf(fd3,"%d",i);
+		fclose(fd3);
+		ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps);
 	}
 	fclose(fd);
 	if(fd2!=NULL) fclose(fd2);

--
Gitblit v1.9.3