From 5e08f27fac51e8f7261cd4484ab8878befac8fe1 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Fri, 08 Mar 2019 20:08:54 +0000
Subject: [PATCH] Constant area plugin done

---
 src/main.c                  |    7 +
 src/plugins/Makefile.am     |    5 +
 src/plugins/constant_area.c |   67 ++++++++++++++++++++++
 src/plugins/Makefile        |   31 +++++++--
 src/plugins/Makefile.in     |   31 +++++++--
 src/vertexmove.c            |   11 ---
 6 files changed, 124 insertions(+), 28 deletions(-)

diff --git a/src/main.c b/src/main.c
index 8344734..bf58e53 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,18 +31,21 @@
 	ts_char *plugin2 = (ts_char *)calloc(255,sizeof(ts_char));
 	ts_char *plugin3 = (ts_char *)calloc(255,sizeof(ts_char));
 	ts_char *plugin4 = (ts_char *)calloc(255,sizeof(ts_char));
+	ts_char *plugin5 = (ts_char *)calloc(255,sizeof(ts_char));
 	strcpy(plugin0,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/demoplugin.so");
 	strcpy(plugin1,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/vmdefaulthardconstraints.so");
 	strcpy(plugin2,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/plane_confinement.so");
 	strcpy(plugin3,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/pressure.so");
 	strcpy(plugin4,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/constant_volume.so");
-	ts_char **plugins=(ts_char **)calloc(5,sizeof(ts_char *));
+	strcpy(plugin5,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/constant_area.so");
+	ts_char **plugins=(ts_char **)calloc(6,sizeof(ts_char *));
 	plugins[0]=plugin0;
 	plugins[1]=plugin1;
 	plugins[2]=plugin2;
 	plugins[3]=plugin3;
 	plugins[4]=plugin4;
-	ts_plugin_list *plist=init_plugin_list(plugins,5);
+	plugins[5]=plugin5;
+	ts_plugin_list *plist=init_plugin_list(plugins,6);
 	//printf("%s", plist->chain->at_start->next->plugin->filename);
 	//ts_fprintf(stdout, "TRISURF in PRVI PLUGIN %s\n", plist->plugin[0]->details->name);
 	ts_vesicle *vesicle;
diff --git a/src/plugins/Makefile b/src/plugins/Makefile
index b5ec0e2..9b25029 100644
--- a/src/plugins/Makefile
+++ b/src/plugins/Makefile
@@ -127,13 +127,20 @@
   }
 am__installdirs = "$(DESTDIR)$(libdir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
-constant_volume_la_LIBADD =
-am_constant_volume_la_OBJECTS = constant_volume.lo
-constant_volume_la_OBJECTS = $(am_constant_volume_la_OBJECTS)
+constant_area_la_LIBADD =
+am_constant_area_la_OBJECTS = constant_area.lo
+constant_area_la_OBJECTS = $(am_constant_area_la_OBJECTS)
 AM_V_lt = $(am__v_lt_$(V))
 am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
 am__v_lt_0 = --silent
 am__v_lt_1 = 
+constant_area_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(AM_CFLAGS) $(CFLAGS) $(constant_area_la_LDFLAGS) $(LDFLAGS) \
+	-o $@
+constant_volume_la_LIBADD =
+am_constant_volume_la_OBJECTS = constant_volume.lo
+constant_volume_la_OBJECTS = $(am_constant_volume_la_OBJECTS)
 constant_volume_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
 	$(AM_CFLAGS) $(CFLAGS) $(constant_volume_la_LDFLAGS) \
@@ -205,10 +212,12 @@
 am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
-SOURCES = $(constant_volume_la_SOURCES) $(demoplugin_la_SOURCES) \
-	$(nucleus_la_SOURCES) $(plane_confinement_la_SOURCES) \
-	$(pressure_la_SOURCES) $(vmdefaulthardconstraints_la_SOURCES)
-DIST_SOURCES = $(constant_volume_la_SOURCES) $(demoplugin_la_SOURCES) \
+SOURCES = $(constant_area_la_SOURCES) $(constant_volume_la_SOURCES) \
+	$(demoplugin_la_SOURCES) $(nucleus_la_SOURCES) \
+	$(plane_confinement_la_SOURCES) $(pressure_la_SOURCES) \
+	$(vmdefaulthardconstraints_la_SOURCES)
+DIST_SOURCES = $(constant_area_la_SOURCES) \
+	$(constant_volume_la_SOURCES) $(demoplugin_la_SOURCES) \
 	$(nucleus_la_SOURCES) $(plane_confinement_la_SOURCES) \
 	$(pressure_la_SOURCES) $(vmdefaulthardconstraints_la_SOURCES)
 am__can_run_installinfo = \
@@ -359,7 +368,7 @@
 top_builddir = ../..
 top_srcdir = ../..
 AM_CFLAGS = -Wall -Werror -DTS_VERSION=\"$(GITVERSION)\" -fgnu89-inline -Wno-error=date-time -I..
-lib_LTLIBRARIES = demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la constant_volume.la
+lib_LTLIBRARIES = demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la constant_volume.la constant_area.la
 demoplugin_la_SOURCES = demo_plugin.c
 demoplugin_la_LDFLAGS = -module -avoid-version -export-dynamic
 vmdefaulthardconstraints_la_SOURCES = default_hard_constraints.c
@@ -372,6 +381,8 @@
 pressure_la_LDFLAGS = -module -avoid-version -export-dynamic
 constant_volume_la_SOURCES = constant_volume.c 
 constant_volume_la_LDFLAGS = -module -avoid-version -export-dynamic
+constant_area_la_SOURCES = constant_area.c 
+constant_area_la_LDFLAGS = -module -avoid-version -export-dynamic
 all: all-am
 
 .SUFFIXES:
@@ -441,6 +452,9 @@
 	  rm -f $${locs}; \
 	}
 
+constant_area.la: $(constant_area_la_OBJECTS) $(constant_area_la_DEPENDENCIES) $(EXTRA_constant_area_la_DEPENDENCIES) 
+	$(AM_V_CCLD)$(constant_area_la_LINK) -rpath $(libdir) $(constant_area_la_OBJECTS) $(constant_area_la_LIBADD) $(LIBS)
+
 constant_volume.la: $(constant_volume_la_OBJECTS) $(constant_volume_la_DEPENDENCIES) $(EXTRA_constant_volume_la_DEPENDENCIES) 
 	$(AM_V_CCLD)$(constant_volume_la_LINK) -rpath $(libdir) $(constant_volume_la_OBJECTS) $(constant_volume_la_LIBADD) $(LIBS)
 
@@ -465,6 +479,7 @@
 distclean-compile:
 	-rm -f *.tab.c
 
+include ./$(DEPDIR)/constant_area.Plo
 include ./$(DEPDIR)/constant_volume.Plo
 include ./$(DEPDIR)/default_hard_constraints.Plo
 include ./$(DEPDIR)/demo_plugin.Plo
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 1db5618..b3cfafe 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -1,5 +1,5 @@
 AM_CFLAGS = -Wall -Werror -DTS_VERSION=\"$(GITVERSION)\" -fgnu89-inline -Wno-error=date-time -I..
-lib_LTLIBRARIES= demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la constant_volume.la
+lib_LTLIBRARIES= demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la constant_volume.la constant_area.la
 demoplugin_la_SOURCES= demo_plugin.c
 demoplugin_la_LDFLAGS = -module -avoid-version -export-dynamic
 
@@ -18,3 +18,6 @@
 constant_volume_la_SOURCES = constant_volume.c 
 constant_volume_la_LDFLAGS = -module -avoid-version -export-dynamic
 
+constant_area_la_SOURCES = constant_area.c 
+constant_area_la_LDFLAGS = -module -avoid-version -export-dynamic
+
diff --git a/src/plugins/Makefile.in b/src/plugins/Makefile.in
index d6859fc..cd076f8 100644
--- a/src/plugins/Makefile.in
+++ b/src/plugins/Makefile.in
@@ -127,13 +127,20 @@
   }
 am__installdirs = "$(DESTDIR)$(libdir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
-constant_volume_la_LIBADD =
-am_constant_volume_la_OBJECTS = constant_volume.lo
-constant_volume_la_OBJECTS = $(am_constant_volume_la_OBJECTS)
+constant_area_la_LIBADD =
+am_constant_area_la_OBJECTS = constant_area.lo
+constant_area_la_OBJECTS = $(am_constant_area_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
 am__v_lt_1 = 
+constant_area_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(AM_CFLAGS) $(CFLAGS) $(constant_area_la_LDFLAGS) $(LDFLAGS) \
+	-o $@
+constant_volume_la_LIBADD =
+am_constant_volume_la_OBJECTS = constant_volume.lo
+constant_volume_la_OBJECTS = $(am_constant_volume_la_OBJECTS)
 constant_volume_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
 	$(AM_CFLAGS) $(CFLAGS) $(constant_volume_la_LDFLAGS) \
@@ -205,10 +212,12 @@
 am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
-SOURCES = $(constant_volume_la_SOURCES) $(demoplugin_la_SOURCES) \
-	$(nucleus_la_SOURCES) $(plane_confinement_la_SOURCES) \
-	$(pressure_la_SOURCES) $(vmdefaulthardconstraints_la_SOURCES)
-DIST_SOURCES = $(constant_volume_la_SOURCES) $(demoplugin_la_SOURCES) \
+SOURCES = $(constant_area_la_SOURCES) $(constant_volume_la_SOURCES) \
+	$(demoplugin_la_SOURCES) $(nucleus_la_SOURCES) \
+	$(plane_confinement_la_SOURCES) $(pressure_la_SOURCES) \
+	$(vmdefaulthardconstraints_la_SOURCES)
+DIST_SOURCES = $(constant_area_la_SOURCES) \
+	$(constant_volume_la_SOURCES) $(demoplugin_la_SOURCES) \
 	$(nucleus_la_SOURCES) $(plane_confinement_la_SOURCES) \
 	$(pressure_la_SOURCES) $(vmdefaulthardconstraints_la_SOURCES)
 am__can_run_installinfo = \
@@ -359,7 +368,7 @@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 AM_CFLAGS = -Wall -Werror -DTS_VERSION=\"$(GITVERSION)\" -fgnu89-inline -Wno-error=date-time -I..
-lib_LTLIBRARIES = demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la constant_volume.la
+lib_LTLIBRARIES = demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la constant_volume.la constant_area.la
 demoplugin_la_SOURCES = demo_plugin.c
 demoplugin_la_LDFLAGS = -module -avoid-version -export-dynamic
 vmdefaulthardconstraints_la_SOURCES = default_hard_constraints.c
@@ -372,6 +381,8 @@
 pressure_la_LDFLAGS = -module -avoid-version -export-dynamic
 constant_volume_la_SOURCES = constant_volume.c 
 constant_volume_la_LDFLAGS = -module -avoid-version -export-dynamic
+constant_area_la_SOURCES = constant_area.c 
+constant_area_la_LDFLAGS = -module -avoid-version -export-dynamic
 all: all-am
 
 .SUFFIXES:
@@ -441,6 +452,9 @@
 	  rm -f $${locs}; \
 	}
 
+constant_area.la: $(constant_area_la_OBJECTS) $(constant_area_la_DEPENDENCIES) $(EXTRA_constant_area_la_DEPENDENCIES) 
+	$(AM_V_CCLD)$(constant_area_la_LINK) -rpath $(libdir) $(constant_area_la_OBJECTS) $(constant_area_la_LIBADD) $(LIBS)
+
 constant_volume.la: $(constant_volume_la_OBJECTS) $(constant_volume_la_DEPENDENCIES) $(EXTRA_constant_volume_la_DEPENDENCIES) 
 	$(AM_V_CCLD)$(constant_volume_la_LINK) -rpath $(libdir) $(constant_volume_la_OBJECTS) $(constant_volume_la_LIBADD) $(LIBS)
 
@@ -465,6 +479,7 @@
 distclean-compile:
 	-rm -f *.tab.c
 
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/constant_area.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/constant_volume.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/default_hard_constraints.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/demo_plugin.Plo@am__quote@
diff --git a/src/plugins/constant_area.c b/src/plugins/constant_area.c
new file mode 100644
index 0000000..c454ec0
--- /dev/null
+++ b/src/plugins/constant_area.c
@@ -0,0 +1,67 @@
+#include <stdlib.h>
+#include<math.h>
+
+#include "general.h"
+#include "vertex.h"
+#include "cell.h"
+#include "vesicle.h"
+#include "frame.h"
+char plugin_name[] = "Constant area";
+char plugin_description[]= "Plugin that enables constant area of the vesicle.";
+char plugin_author[] = "SAMO PENIC";
+
+
+typedef struct {
+	ts_double darea;
+	ts_double A0;
+	ts_double epsarea;
+} plugin_data;
+
+
+ts_plugin_details *init (){
+	ts_plugin_details *details=(ts_plugin_details *)calloc(1,sizeof(ts_plugin_details));
+	details->name = plugin_name;
+	details->data = (plugin_data *)calloc(1,sizeof(plugin_data)); //storing data
+	return details;	
+}
+
+
+ts_vesicle *after_vesicle_init(ts_vesicle *vesicle){
+	plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data;
+	ts_fprintf(stdout,"area volume initialized\n");
+	centermass(vesicle);
+	cell_occupation(vesicle);
+	vesicle_area(vesicle);
+	data->A0=vesicle->area;
+	data->epsarea=data->A0/(ts_double)vesicle->tlist->n;
+	return vesicle;
+}
+
+
+void vm_energy_before_prepare(ts_vesicle *vesicle, ts_vertex *vtx){	
+    if(vesicle->tape->constareaswitch>0){
+		plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data;
+		data->darea=0;
+		ts_uint i;
+		for(i=0;i<vtx->tristar_no;i++) data->darea-=vtx->tristar[i]->area;
+    
+    }
+}
+
+ts_double vm_before_montecarlo_constraint(ts_vesicle *vesicle, ts_vertex *vtx, ts_vertex *old_vtx){
+	if(vesicle->tape->constareaswitch>0){
+		plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data;
+		ts_uint i;
+		for(i=0;i<vtx->tristar_no;i++) data->darea+=vtx->tristar[i]->area;
+	        if(fabs(vesicle->area+data->darea-data->A0)>data->epsarea) return TS_FAIL;
+    }
+	return TS_SUCCESS;
+}
+
+
+void vm_new_state_accepted(ts_vesicle *vesicle, ts_vertex *vtx, ts_vertex *old_vtx){
+	if(vesicle->tape->constareaswitch >0){
+		plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data;
+		vesicle->area+=data->darea;
+	}
+}
diff --git a/src/vertexmove.c b/src/vertexmove.c
index dc6c53f..ac29b18 100644
--- a/src/vertexmove.c
+++ b/src/vertexmove.c
@@ -60,22 +60,15 @@
 		vesicle->plist->pointer->plugin->function->vm_energy_before_prepare(vesicle, vtx);
 		vesicle->plist->pointer=vesicle->plist->pointer->next;
 	}
+/* End of vm_energy_before_prepare() */
 
-    if(vesicle->tape->constareaswitch==2){
-		for(i=0;i<vtx->tristar_no;i++) darea-=vtx->tristar[i]->area;
-    
-    }
 	//stretching energy 1 of 3
 	if(vesicle->tape->stretchswitch==1){
 		for(i=0;i<vtx->tristar_no;i++) dstretchenergy-=vtx->tristar[i]->energy;
 	}
     delta_energy=0;
 
-
-//    vesicle_volume(vesicle);
-//    fprintf(stderr,"Volume in the beginning=%1.16e\n", vesicle->volume);
-
-    //update the normals of triangles that share bead i.
+//update the normals of triangles that share bead i.
     for(i=0;i<vtx->tristar_no;i++) triangle_normal_vector(vtx->tristar[i]);
 	oenergy=vtx->energy;
     energy_vertex(vtx);

--
Gitblit v1.9.3