From 200815edf1548d444aa3b5db908a1628adeb2a05 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Tue, 05 Nov 2013 17:53:51 +0000
Subject: [PATCH] Vertex tainting done

---
 src/timestep.c |    9 +++++++++
 src/vertex.c   |   33 +++++++++++++++++++++++++++++++++
 src/general.h  |    1 +
 src/vertex.h   |    4 +++-
 4 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/src/general.h b/src/general.h
index f3328f6..1dfb3a7 100644
--- a/src/general.h
+++ b/src/general.h
@@ -154,6 +154,7 @@
         ts_double projArea;
         ts_double relR;
         ts_double solAngle;
+	ts_int locked;
 };
 typedef struct ts_vertex ts_vertex;
 
diff --git a/src/timestep.c b/src/timestep.c
index 9e5e61c..1ac1eb4 100644
--- a/src/timestep.c
+++ b/src/timestep.c
@@ -7,6 +7,7 @@
 #include "vertexmove.h"
 #include "bondflip.h"
 #include "frame.h"
+#include "vertex.h"
 #include "io.h"
 ts_bool run_simulation(ts_vesicle *vesicle, ts_uint mcsweeps, ts_uint inititer, ts_uint iterations){
 	ts_uint i, j;
@@ -35,7 +36,15 @@
         rnvec[0]=drand48();
         rnvec[1]=drand48();
         rnvec[2]=drand48();
+	vertex_taint(vesicle->vlist->vtx[i],1);
+//		ts_fprintf(stdout, "Vertex %d should be tainted, level=%d.\n", i, vesicle->vlist->vtx[i]->locked);
+	if(vertex_tainted(vesicle->vlist->vtx[i],1,1)){
+		ts_fprintf(stdout, "Vertex %d tainted, level=%d. Waiting....\n", i, vesicle->vlist->vtx[i]->locked);
+		while(vertex_tainted(vesicle->vlist->vtx[i],1,1));
+	}
         retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
+	vertex_untaint(vesicle->vlist->vtx[i],1);
+//		ts_fprintf(stdout, "Vertex %d should be untainted, level=%d.\n", i, vesicle->vlist->vtx[i]->locked);
     }
 
 //	ts_int cnt=0;
diff --git a/src/vertex.c b/src/vertex.c
index 38647aa..1993856 100644
--- a/src/vertex.c
+++ b/src/vertex.c
@@ -311,3 +311,36 @@
 
     return vlist;
 }
+
+
+
+ts_bool vertex_taint(ts_vertex *vtx, ts_uint level){
+	if(level==0){
+		vtx->locked++;
+		return TS_SUCCESS;	
+	}	
+	ts_uint i;
+	for(i=0; i<vtx->neigh_no; i++){
+		vertex_taint(vtx->neigh[i], level-1);
+	}
+		vtx->locked++;
+	return TS_SUCCESS;
+}
+
+ts_bool vertex_untaint(ts_vertex *vtx, ts_uint level){
+	if(level==0){
+		vtx->locked--;
+		return TS_SUCCESS;	
+	}	
+	ts_uint i;
+	for(i=0; i<vtx->neigh_no; i++){
+		vertex_untaint(vtx->neigh[i], level-1);
+	}
+		vtx->locked--;
+	return TS_SUCCESS;
+}
+
+inline ts_bool vertex_tainted(ts_vertex *vtx, ts_uint level, ts_uint amount){
+	if(vtx->locked>amount) return 1;
+	else return 0;
+}
diff --git a/src/vertex.h b/src/vertex.h
index 97775d2..7f494c6 100644
--- a/src/vertex.h
+++ b/src/vertex.h
@@ -30,5 +30,7 @@
 ts_bool vtx_duplicate(ts_vertex *cvtx, ts_vertex *ovtx);
 ts_vertex **vtx_neigh_copy(ts_vertex_list *vlist,ts_vertex *ovtx);
 ts_vertex_list *vertex_list_copy(ts_vertex_list *ovlist);
-
+ts_bool vertex_taint(ts_vertex *vtx, ts_uint level);
+ts_bool vertex_untaint(ts_vertex *vtx, ts_uint level);
+inline ts_bool vertex_tainted(ts_vertex *vtx, ts_uint level, ts_uint amount);
 #endif

--
Gitblit v1.9.3