From 250de4d124ea8dc4929a9c334d94fc51018fa53c Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@fe.uni-lj.si>
Date: Wed, 06 Jul 2016 08:25:54 +0000
Subject: [PATCH] Finished spontaneous force

---
 src/energy.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/energy.c b/src/energy.c
index 4f2b386..7c29c0b 100644
--- a/src/energy.c
+++ b/src/energy.c
@@ -185,3 +185,52 @@
 
     return TS_SUCCESS;
 }
+
+
+
+ts_bool sweep_attraction_bond_energy(ts_vesicle *vesicle){
+	int i;
+	for(i=0;i<vesicle->blist->n;i++){
+		attraction_bond_energy(vesicle->blist->bond[i], vesicle->tape->w);
+	}
+	return TS_SUCCESS;
+}
+
+
+inline ts_bool attraction_bond_energy(ts_bond *bond, ts_double w){
+
+	if(fabs(bond->vtx1->c)>1e-16 && fabs(bond->vtx2->c)>1e-16){
+		bond->energy=-w;
+	}
+	else {
+		bond->energy=0.0;
+	}
+	return TS_SUCCESS;
+}
+
+ts_double direct_force_energy(ts_vesicle *vesicle, ts_vertex *vtx, ts_vertex *vtx_old){
+	if(fabs(vtx->c)<1e-15) return 0.0;
+//	printf("was here");
+	if(fabs(vesicle->tape->F)<1e-15) return 0.0;
+
+	ts_double norml,ddp=0.0;
+	ts_uint i;
+	ts_double xnorm=0.0,ynorm=0.0,znorm=0.0;
+	/*find normal of the vertex as average normal of all the triangles surrounding it. */
+	for(i=0;i<vtx->tristar_no;i++){
+			xnorm=vtx->tristar[i]->xnorm;
+			ynorm=vtx->tristar[i]->ynorm;
+			znorm=vtx->tristar[i]->znorm;
+	}
+	/*normalize*/
+	norml=sqrt(xnorm*xnorm+ynorm*ynorm+znorm*znorm);
+	xnorm/=norml;
+	ynorm/=norml;
+	znorm/=norml;
+	/*calculate ddp, perpendicular displacement*/
+	ddp=xnorm*(vtx->x-vtx_old->x)+xnorm*(vtx->y-vtx_old->y)+znorm*(vtx->z-vtx_old->z);
+	/*calculate dE*/
+//	printf("ddp=%e",ddp);
+	return vesicle->tape->F*ddp;		
+	
+}

--
Gitblit v1.9.3