From 6da644f98434d3eac8b4e19981754f6030a315a5 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Wed, 27 Jun 2018 12:05:32 +0000
Subject: [PATCH] Resolving the issues with restoring vesicles from vtu and fixing the volume. Dump to vtu has been repaired.

---
 src/main.c       |    1 +
 src/timestep.c   |    4 ++--
 src/snapshot.c   |   12 ++++++++++--
 src/vertexmove.c |    5 +++--
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/main.c b/src/main.c
index 3f91f43..0d20cad 100644
--- a/src/main.c
+++ b/src/main.c
@@ -131,6 +131,7 @@
 //	exit(1);
 
 			//write_vertex_xml_file(vesicle,1000);
+	fprintf(stderr,"constvol=%ld, precision=%e\n", tape->constvolswitch, tape->constvolprecision);
 	run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration);
 	write_master_xml_file(command_line_args.output_fullfilename);
 	write_dout_fcompat_file(vesicle,"dout");
diff --git a/src/snapshot.c b/src/snapshot.c
index da21498..6c628b4 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -22,7 +22,7 @@
 
 /* outputs additional data into paraview xml file */
 ts_bool xml_trisurf_data(FILE *fh, ts_vesicle *vesicle){
-
+	ts_double cvol_write=0, carea_write=0;
 	ts_string *data=(ts_string *)malloc(sizeof(ts_sprintf));
 	data->string=(char *)malloc(5120000*sizeof(char)); /*TODO: warning, can break if the string is to long */
 	data->beg=0;
@@ -33,7 +33,15 @@
 	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);
+	if(vesicle->tape->constvolswitch==0)
+		cvol_write=vesicle->volume;
+	else
+		cvol_write=V0;
+	if(vesicle->tape->constareaswitch==0)
+		carea_write=vesicle->area;
+	else
+		carea_write=A0;
+	xml_trisurf_constvolarea(data,cvol_write,carea_write);
 #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
diff --git a/src/timestep.c b/src/timestep.c
index d4748e6..c74e3e1 100644
--- a/src/timestep.c
+++ b/src/timestep.c
@@ -92,12 +92,12 @@
 		cell_occupation(vesicle);
             dump_state(vesicle,i);
 		if(i>=inititer){
+			vesicle_volume(vesicle); //calculates just volume. 
+            		vesicle_area(vesicle); //calculates area.
 			write_vertex_xml_file(vesicle,i-inititer,NULL);
 			write_master_xml_file(command_line_args.output_fullfilename);
 			epochtime=get_epoch();			
 			gyration_eigen(vesicle, &l1, &l2, &l3);
-			vesicle_volume(vesicle); //calculates just volume. 
-            vesicle_area(vesicle); //calculates area.
 			r0=getR0(vesicle);
             if(vesicle->sphHarmonics!=NULL){
 			    preparationSh(vesicle,r0);
diff --git a/src/vertexmove.c b/src/vertexmove.c
index 1d5d7fa..3483965 100644
--- a/src/vertexmove.c
+++ b/src/vertexmove.c
@@ -165,7 +165,7 @@
 
 	if(vesicle->tape->constvolswitch==2){
 		/*check whether the dvol is gt than epsvol */
-			//fprintf(stderr,"DVOL=%1.16e\n",dvol);
+			//fprintf(stderr,"DVOL=%1.16e, V0=%1.16e, vesicleVolume=%1.16e, |volume+dvol-V0|=%1.16e\n",dvol, V0, vesicle->volume, fabs(vesicle->volume+dvol-V0));
 		if(fabs(vesicle->volume+dvol-V0)>epsvol){
 			//restore old state.
  			vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex));
@@ -173,11 +173,12 @@
 		        	vtx->neigh[i]=memcpy((void *)vtx->neigh[i],(void *)&backupvtx[i+1],sizeof(ts_vertex));
 	        	}
             		for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]); 
-            		//fprintf(stderr,"fajlam!\n");
+            	//	fprintf(stderr,"fajlam!\n");
             		return TS_FAIL;
 		}
 
 	} else
+		//fprintf(stderr, "success\n");
 //    vesicle_volume(vesicle);
 //    fprintf(stderr,"Volume before=%1.16e\n", vesicle->volume);
    if(vesicle->tape->constvolswitch == 1){

--
Gitblit v1.9.3