From dba66b4f8a25cb7eb18de5f7ffca97e179d7a5d9 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Sat, 19 Oct 2019 11:45:15 +0000
Subject: [PATCH] Moved compression/decompression routines to separate file

---
 src/poly.c |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/poly.c b/src/poly.c
index 39d0723..cf416b5 100644
--- a/src/poly.c
+++ b/src/poly.c
@@ -126,7 +126,6 @@
 							m++;
 							if(m>1000) {
 								k=9999; //break also ot of the outer loop
-								printf("was here\n");
 								break;
 							}
 						}
@@ -135,7 +134,7 @@
 					k++;
 					if(k>1000){
 						//undo changes to the cell
-						for(l=0;l<j-1;l++){
+						for(l=0;l<j;l++){
 							cellidx=vertex_self_avoidance(vesicle, poly_list->poly[i]->vlist->vtx[l]);
 							cell_remove_vertex(vesicle->clist->cell[cellidx],poly_list->poly[i]->vlist->vtx[l]);
 						}
@@ -159,11 +158,12 @@
 	ts_uint gvtxi;
 	ts_bool retval;
 	ts_double dphi,dh;
+
 	cell_occupation(vesicle); //needed for evading the membrane
 	// Grafting polymers:
+	int tries=0;
 	if (vlist!=NULL){
 		if (n_poly > vlist->n){fatal("Number of polymers larger than numbero f vertices on a vesicle.",310);}
-	
 		while(i<n_poly){
 			gvtxi = rand() % vlist->n;
 			if (vlist->vtx[gvtxi]->grafted_poly == NULL){
@@ -171,9 +171,15 @@
 				retval=poly_initial_distribution(poly_list, i, vesicle);
 				if(retval==TS_FAIL){
 					ts_fprintf(stdout,"Found new potential grafting vertex %d for poly %d\n",gvtxi,i);
+					poly_free(poly_list->poly[i]);
+					tries++;
 				}
 				else {
+					tries=0;
 					i++;
+				}
+				if(tries>5000){
+					fatal("Cannot find space for inner polymeres",1001);
 				}
 			}
 		}
@@ -236,9 +242,9 @@
 
 ts_bool poly_free(ts_poly *poly){
 
-	if (poly->grafted_vtx!=NULL){
-		poly->grafted_vtx->grafted_poly=NULL;
-	}
+//	if (poly->grafted_vtx!=NULL){
+//		poly->grafted_vtx->grafted_poly=NULL;
+//	}
 	vtx_list_free(poly->vlist);
 	bond_list_free(poly->blist);
 	free(poly);
@@ -248,8 +254,9 @@
 
 ts_bool poly_list_free(ts_poly_list *poly_list){
 	ts_uint i;
-
+	//fprintf(stderr,"no. of polys=%d\n", poly_list->n);
 	for(i=0;i<poly_list->n;i++){
+	//	fprintf(stderr,"%d poly address in mem=%ld\n",i+1,(long)&(poly_list->poly[i]));
 		poly_free(poly_list->poly[i]);
 	}
 	free(poly_list->poly);
@@ -296,3 +303,15 @@
 	return TS_SUCCESS;
 }
 
+
+
+ts_poly_list *init_empty_poly_list(ts_uint n_poly, ts_uint n_mono){
+	ts_poly_list *poly_list=(ts_poly_list *)calloc(1,sizeof(ts_poly_list));
+	poly_list->poly=(ts_poly **)calloc(n_poly,sizeof(ts_poly *));
+	ts_uint i;
+	for (i=0; i<n_poly;i++){
+		poly_list->poly[i]=init_poly(n_mono, NULL);
+	}
+	poly_list->n = n_poly;
+	return poly_list;
+}

--
Gitblit v1.9.3