From 36dba86649e71d2a56657320ddf98a1af2055023 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Thu, 28 Feb 2019 20:04:16 +0000
Subject: [PATCH] Some changes to plugins to allow storage of data. Pressure is a plugin now

---
 src/plugins/.libs/demoplugin.a  |    0 
 src/main.c                      |    7 +
 src/plugins.c                   |   10 +++
 src/plugins/Makefile.am         |    5 +
 src/plugins/.libs/demo_plugin.o |    0 
 src/plugins/Makefile            |   18 +++++-
 src/plugins/Makefile.in         |   18 +++++-
 src/plugins/demo_plugin.o       |    0 
 src/plugins/pressure.c          |   37 ++++++++++++
 src/general.h                   |    6 +
 src/vertexmove.c                |   20 +++---
 src/plugins/.libs/demoplugin.so |    0 
 12 files changed, 100 insertions(+), 21 deletions(-)

diff --git a/src/general.h b/src/general.h
index 16025f2..4e834ed 100644
--- a/src/general.h
+++ b/src/general.h
@@ -309,7 +309,7 @@
 	void (*at_start)(int argc, char **argv);
 	void *(*after_vesicle_init)(void *vesicle);
 	ts_bool (*vm_hard_constraint)(void *vesicle, ts_vertex *vtx, ts_vertex *odl_vtx);
-	ts_double (*vm_energy_before_prepare)(void *vesicle, ts_vertex *vtx);
+	void (*vm_energy_before_prepare)(void *vesicle, ts_vertex *vtx);
 	ts_double (*vm_energy_before_execute)(void *vesicle, ts_vertex *vtx);
 	ts_double (*vm_energy_after_prepare)(void *vesicle, ts_vertex *vtx);
 	ts_double (*vm_energy_after_execute)(void *vesicle, ts_vertex *vtx);
@@ -322,6 +322,7 @@
 	ts_char *name;
 	ts_char *description;
 	ts_char *author;
+	void *data;
 } ts_plugin_details;
 
 typedef struct {
@@ -341,6 +342,8 @@
 	ts_plugin_chain *at_start;
 	ts_plugin_chain *after_vesicle_init;
 	ts_plugin_chain *vm_hard_constraint;
+	ts_plugin_chain *vm_energy_before_prepare;
+	ts_plugin_chain *vm_energy_after_execute;
 	ts_plugin_chain *cleanup;
 } ts_plugin_chains;
 
@@ -349,6 +352,7 @@
 	ts_uint n;
 	ts_plugin **plugin;
 	ts_plugin_chains *chain;
+	ts_plugin_chain *pointer;
 } ts_plugin_list;
 
 /* end plugins */
diff --git a/src/main.c b/src/main.c
index 3cfc2af..6d19213 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,14 +29,17 @@
 	ts_char *plugin0 = (ts_char *)calloc(255,sizeof(ts_char));
 	ts_char *plugin1 = (ts_char *)calloc(255,sizeof(ts_char));
 	ts_char *plugin2 = (ts_char *)calloc(255,sizeof(ts_char));
+	ts_char *plugin3 = (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");
-	ts_char **plugins=(ts_char **)calloc(3,sizeof(ts_char *));
+	strcpy(plugin3,"/home/samo/programiranje/trisurf-ng/src/plugins/.libs/pressure.so");
+	ts_char **plugins=(ts_char **)calloc(4,sizeof(ts_char *));
 	*plugins=plugin0;
 	plugins[1]=plugin1;
 	plugins[2]=plugin2;
-	ts_plugin_list *plist=init_plugin_list(plugins,3);
+	plugins[3]=plugin3;
+	ts_plugin_list *plist=init_plugin_list(plugins,4);
 	//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.c b/src/plugins.c
index 84983aa..e94241f 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -155,9 +155,17 @@
 		if(plist->plugin[i]->function->at_start!=NULL){
 			plist->chain->at_start=plugin_to_chain(plist->chain->at_start, plist->plugin[i]);
 		}
+		if(plist->plugin[i]->function->vm_hard_constraint!=NULL){
+			plist->chain->vm_hard_constraint=plugin_to_chain(plist->chain->vm_hard_constraint, plist->plugin[i]);
+		}
+		if(plist->plugin[i]->function->vm_energy_before_prepare!=NULL){
+			plist->chain->vm_energy_before_prepare=plugin_to_chain(plist->chain->vm_energy_before_prepare, plist->plugin[i]);
+		}
+		if(plist->plugin[i]->function->vm_energy_after_execute!=NULL){
+			plist->chain->vm_energy_after_execute=plugin_to_chain(plist->chain->vm_energy_after_execute, plist->plugin[i]);
+		}
 
 	}
-	//printf("%s", plist->chain->at_start->next->plugin->filename);
 	plist->n=number_of_plugins;
 	return plist;
 }	
diff --git a/src/plugins/.libs/demo_plugin.o b/src/plugins/.libs/demo_plugin.o
index e51de57..8706a04 100644
--- a/src/plugins/.libs/demo_plugin.o
+++ b/src/plugins/.libs/demo_plugin.o
Binary files differ
diff --git a/src/plugins/.libs/demoplugin.a b/src/plugins/.libs/demoplugin.a
index cf30305..0ce6a19 100644
--- a/src/plugins/.libs/demoplugin.a
+++ b/src/plugins/.libs/demoplugin.a
Binary files differ
diff --git a/src/plugins/.libs/demoplugin.so b/src/plugins/.libs/demoplugin.so
index 14ba685..b2316d0 100755
--- a/src/plugins/.libs/demoplugin.so
+++ b/src/plugins/.libs/demoplugin.so
Binary files differ
diff --git a/src/plugins/Makefile b/src/plugins/Makefile
index 3ff2734..08bbd37 100644
--- a/src/plugins/Makefile
+++ b/src/plugins/Makefile
@@ -150,6 +150,12 @@
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
 	$(AM_CFLAGS) $(CFLAGS) $(plane_confinement_la_LDFLAGS) \
 	$(LDFLAGS) -o $@
+pressure_la_LIBADD =
+am_pressure_la_OBJECTS = pressure.lo
+pressure_la_OBJECTS = $(am_pressure_la_OBJECTS)
+pressure_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(pressure_la_LDFLAGS) $(LDFLAGS) -o $@
 vmdefaulthardconstraints_la_LIBADD =
 am_vmdefaulthardconstraints_la_OBJECTS = default_hard_constraints.lo
 vmdefaulthardconstraints_la_OBJECTS =  \
@@ -193,10 +199,10 @@
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
 SOURCES = $(demoplugin_la_SOURCES) $(nucleus_la_SOURCES) \
-	$(plane_confinement_la_SOURCES) \
+	$(plane_confinement_la_SOURCES) $(pressure_la_SOURCES) \
 	$(vmdefaulthardconstraints_la_SOURCES)
 DIST_SOURCES = $(demoplugin_la_SOURCES) $(nucleus_la_SOURCES) \
-	$(plane_confinement_la_SOURCES) \
+	$(plane_confinement_la_SOURCES) $(pressure_la_SOURCES) \
 	$(vmdefaulthardconstraints_la_SOURCES)
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
@@ -346,7 +352,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
+lib_LTLIBRARIES = demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la
 demoplugin_la_SOURCES = demo_plugin.c
 demoplugin_la_LDFLAGS = -module -avoid-version -export-dynamic
 vmdefaulthardconstraints_la_SOURCES = default_hard_constraints.c
@@ -355,6 +361,8 @@
 nucleus_la_LDFLAGS = -module -avoid-version -export-dynamic
 plane_confinement_la_SOURCES = plane_confinement.c 
 plane_confinement_la_LDFLAGS = -module -avoid-version -export-dynamic
+pressure_la_SOURCES = pressure.c 
+pressure_la_LDFLAGS = -module -avoid-version -export-dynamic
 all: all-am
 
 .SUFFIXES:
@@ -433,6 +441,9 @@
 plane_confinement.la: $(plane_confinement_la_OBJECTS) $(plane_confinement_la_DEPENDENCIES) $(EXTRA_plane_confinement_la_DEPENDENCIES) 
 	$(AM_V_CCLD)$(plane_confinement_la_LINK) -rpath $(libdir) $(plane_confinement_la_OBJECTS) $(plane_confinement_la_LIBADD) $(LIBS)
 
+pressure.la: $(pressure_la_OBJECTS) $(pressure_la_DEPENDENCIES) $(EXTRA_pressure_la_DEPENDENCIES) 
+	$(AM_V_CCLD)$(pressure_la_LINK) -rpath $(libdir) $(pressure_la_OBJECTS) $(pressure_la_LIBADD) $(LIBS)
+
 vmdefaulthardconstraints.la: $(vmdefaulthardconstraints_la_OBJECTS) $(vmdefaulthardconstraints_la_DEPENDENCIES) $(EXTRA_vmdefaulthardconstraints_la_DEPENDENCIES) 
 	$(AM_V_CCLD)$(vmdefaulthardconstraints_la_LINK) -rpath $(libdir) $(vmdefaulthardconstraints_la_OBJECTS) $(vmdefaulthardconstraints_la_LIBADD) $(LIBS)
 
@@ -446,6 +457,7 @@
 include ./$(DEPDIR)/demo_plugin.Plo
 include ./$(DEPDIR)/nucleus.Plo
 include ./$(DEPDIR)/plane_confinement.Plo
+include ./$(DEPDIR)/pressure.Plo
 
 .c.o:
 	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index c65261c..b28b8ff 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
+lib_LTLIBRARIES= demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la
 demoplugin_la_SOURCES= demo_plugin.c
 demoplugin_la_LDFLAGS = -module -avoid-version -export-dynamic
 
@@ -12,3 +12,6 @@
 plane_confinement_la_SOURCES = plane_confinement.c 
 plane_confinement_la_LDFLAGS = -module -avoid-version -export-dynamic
 
+pressure_la_SOURCES = pressure.c 
+pressure_la_LDFLAGS = -module -avoid-version -export-dynamic
+
diff --git a/src/plugins/Makefile.in b/src/plugins/Makefile.in
index bf7b06d..8239434 100644
--- a/src/plugins/Makefile.in
+++ b/src/plugins/Makefile.in
@@ -150,6 +150,12 @@
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
 	$(AM_CFLAGS) $(CFLAGS) $(plane_confinement_la_LDFLAGS) \
 	$(LDFLAGS) -o $@
+pressure_la_LIBADD =
+am_pressure_la_OBJECTS = pressure.lo
+pressure_la_OBJECTS = $(am_pressure_la_OBJECTS)
+pressure_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(pressure_la_LDFLAGS) $(LDFLAGS) -o $@
 vmdefaulthardconstraints_la_LIBADD =
 am_vmdefaulthardconstraints_la_OBJECTS = default_hard_constraints.lo
 vmdefaulthardconstraints_la_OBJECTS =  \
@@ -193,10 +199,10 @@
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
 SOURCES = $(demoplugin_la_SOURCES) $(nucleus_la_SOURCES) \
-	$(plane_confinement_la_SOURCES) \
+	$(plane_confinement_la_SOURCES) $(pressure_la_SOURCES) \
 	$(vmdefaulthardconstraints_la_SOURCES)
 DIST_SOURCES = $(demoplugin_la_SOURCES) $(nucleus_la_SOURCES) \
-	$(plane_confinement_la_SOURCES) \
+	$(plane_confinement_la_SOURCES) $(pressure_la_SOURCES) \
 	$(vmdefaulthardconstraints_la_SOURCES)
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
@@ -346,7 +352,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
+lib_LTLIBRARIES = demoplugin.la vmdefaulthardconstraints.la nucleus.la plane_confinement.la pressure.la
 demoplugin_la_SOURCES = demo_plugin.c
 demoplugin_la_LDFLAGS = -module -avoid-version -export-dynamic
 vmdefaulthardconstraints_la_SOURCES = default_hard_constraints.c
@@ -355,6 +361,8 @@
 nucleus_la_LDFLAGS = -module -avoid-version -export-dynamic
 plane_confinement_la_SOURCES = plane_confinement.c 
 plane_confinement_la_LDFLAGS = -module -avoid-version -export-dynamic
+pressure_la_SOURCES = pressure.c 
+pressure_la_LDFLAGS = -module -avoid-version -export-dynamic
 all: all-am
 
 .SUFFIXES:
@@ -433,6 +441,9 @@
 plane_confinement.la: $(plane_confinement_la_OBJECTS) $(plane_confinement_la_DEPENDENCIES) $(EXTRA_plane_confinement_la_DEPENDENCIES) 
 	$(AM_V_CCLD)$(plane_confinement_la_LINK) -rpath $(libdir) $(plane_confinement_la_OBJECTS) $(plane_confinement_la_LIBADD) $(LIBS)
 
+pressure.la: $(pressure_la_OBJECTS) $(pressure_la_DEPENDENCIES) $(EXTRA_pressure_la_DEPENDENCIES) 
+	$(AM_V_CCLD)$(pressure_la_LINK) -rpath $(libdir) $(pressure_la_OBJECTS) $(pressure_la_LIBADD) $(LIBS)
+
 vmdefaulthardconstraints.la: $(vmdefaulthardconstraints_la_OBJECTS) $(vmdefaulthardconstraints_la_DEPENDENCIES) $(EXTRA_vmdefaulthardconstraints_la_DEPENDENCIES) 
 	$(AM_V_CCLD)$(vmdefaulthardconstraints_la_LINK) -rpath $(libdir) $(vmdefaulthardconstraints_la_OBJECTS) $(vmdefaulthardconstraints_la_LIBADD) $(LIBS)
 
@@ -446,6 +457,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/demo_plugin.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nucleus.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plane_confinement.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pressure.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/plugins/demo_plugin.o b/src/plugins/demo_plugin.o
index dbb066f..918e249 100644
--- a/src/plugins/demo_plugin.o
+++ b/src/plugins/demo_plugin.o
Binary files differ
diff --git a/src/plugins/pressure.c b/src/plugins/pressure.c
new file mode 100644
index 0000000..a79a438
--- /dev/null
+++ b/src/plugins/pressure.c
@@ -0,0 +1,37 @@
+#include <stdlib.h>
+#include "general.h"
+#include "vertex.h"
+#include "cell.h"
+char plugin_name[] = "Pressure";
+char plugin_description[]= "Defines extra energy term for relative pressure difference between the inner vesicle and outer vesicle";
+char plugin_author[] = "SAMO PENIC";
+
+ts_plugin_details *init (){
+	ts_plugin_details *details=(ts_plugin_details *)calloc(1,sizeof(ts_plugin_details));
+	details->name = plugin_name;
+	details->data = (void *)calloc(1,sizeof(ts_double));
+	return details;	
+}
+
+void vm_energy_before_prepare(ts_vesicle *vesicle, ts_vertex *vtx){
+	if(vesicle->pswitch == 1){
+	ts_double *dvol=(ts_double *)vesicle->plist->pointer->plugin->details->data;
+	ts_uint i;
+	//printf ("DVOL was %f\n", *dvol);
+	*dvol=0;
+	for(i=0;i<vtx->tristar_no;i++) *dvol-=vtx->tristar[i]->volume;
+	//printf ("DVOL is %f\n", *dvol);
+
+	}
+}
+
+ts_double vm_energy_after_execute(ts_vesicle *vesicle, ts_vertex *vtx){
+	ts_double delta_energy=0;
+	if(vesicle->pswitch == 1){
+		ts_double *dvol=(ts_double *)vesicle->plist->pointer->plugin->details->data;
+		ts_uint i;
+		for(i=0;i<vtx->tristar_no;i++) *dvol+=vtx->tristar[i]->volume;
+		delta_energy=-vesicle->pressure*(*dvol);
+	}
+	return delta_energy;
+}
diff --git a/src/vertexmove.c b/src/vertexmove.c
index c512ccd..0c08aff 100644
--- a/src/vertexmove.c
+++ b/src/vertexmove.c
@@ -35,13 +35,6 @@
     vtx->y=vtx->y+r*sintheta*sin(phi);
     vtx->z=vtx->z+r*costheta;
 
-// plane confinement check whether the new position of vertex will be out of bounds
-	if(vesicle->tape->plane_confinement_switch){
-		if(vtx->z>vesicle->confinement_plane.z_max || vtx->z<vesicle->confinement_plane.z_min){
-		vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex));
-		return TS_FAIL;
-		}
-	}
 
 /* Entry point for plugin vm_hard_constraint() function */
 	ts_plugin_chain *ptr=vesicle->plist->chain->vm_hard_constraint;
@@ -53,14 +46,21 @@
 		}
 		ptr=ptr->next;
 	}
+/* End of vm_hard_constraint() */
 
-
- 
-//if all the tests are successful, then energy for vtx and neighbours is calculated
+/* Backuping the neighbours */ 
 	for(i=0;i<vtx->neigh_no;i++){
 	memcpy((void *)&backupvtx[i+1],(void *)vtx->neigh[i],sizeof(ts_vertex));
 	}
 
+/* Entry point for plugin vm_energy_before_prepare() */
+
+	vesicle->plist->pointer=vesicle->plist->chain->vm_energy_before_prepare;
+	while(vesicle->plist->pointer!=NULL){
+		vesicle->plist->pointer->plugin->function->vm_energy_before_prepare(vesicle, vtx);
+		vesicle->plist->pointer=vesicle->plist->pointer->next;
+	}
+/* Calculate energy for vtx and neighbours */
 	if(vesicle->pswitch == 1 || vesicle->tape->constvolswitch>0){
 		for(i=0;i<vtx->tristar_no;i++) dvol-=vtx->tristar[i]->volume;
 	}

--
Gitblit v1.9.3