From 8db569a42c280be13ea9edbe4c528e0041b6fd3f Mon Sep 17 00:00:00 2001 From: mihaf <miha.fosnaric@gmail.com> Date: Tue, 03 Dec 2013 13:05:49 +0000 Subject: [PATCH] Samo&Miha poly_list_free added. --- src/Makefile.am | 2 src/main.c | 8 ++++ src/poly.c | 70 ++++++++++++++++++++++++++++++++--- src/vesicle.c | 3 + aclocal.m4 | 10 ++-- src/poly.h | 4 ++ 6 files changed, 84 insertions(+), 13 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index 3094178..da06da5 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,4 +1,4 @@ -# generated automatically by aclocal 1.11.6 -*- Autoconf -*- +# generated automatically by aclocal 1.11.3 -*- Autoconf -*- # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, # 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, @@ -14,8 +14,8 @@ m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, -[m4_warning([this file was generated for autoconf 2.69. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],, +[m4_warning([this file was generated for autoconf 2.68. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically `autoreconf'.])]) @@ -38,7 +38,7 @@ [am__api_version='1.11' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.11.6], [], +m4_if([$1], [1.11.3], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -54,7 +54,7 @@ # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.11.6])dnl +[AM_AUTOMAKE_VERSION([1.11.3])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) diff --git a/src/Makefile.am b/src/Makefile.am index 1221acb..bd95811 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ trisurfdir=../ trisurf_PROGRAMS = trisurf -trisurf_SOURCES = general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c frame.c energy.c timestep.c vertexmove.c bondflip.c main.c +trisurf_SOURCES = general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c frame.c energy.c timestep.c vertexmove.c bondflip.c main.c poly.c #trisurf_LDFLAGS = -lm -lconfuse shdiscoverdir=../ shdiscover_PROGRAMS= shdiscover diff --git a/src/main.c b/src/main.c index 7e12c1c..b756320 100644 --- a/src/main.c +++ b/src/main.c @@ -10,6 +10,7 @@ #include "initial_distribution.h" #include "frame.h" #include "timestep.h" +#include "poly.h" /** Entrance function to the program * @param argv is a number of parameters used in program call (including the program name @@ -64,6 +65,13 @@ printf("Tests complete.\n"); */ vesicle=parsetape(&mcsweeps, &inititer, &iterations); + +/*Testing */ +vesicle->poly_list=init_poly_list(1400,20,vesicle->vlist); + +poly_list_free(vesicle->poly_list); +/*End testing*/ + run_simulation(vesicle, mcsweeps, inititer, iterations); write_master_xml_file("test.pvd"); diff --git a/src/poly.c b/src/poly.c index f362dd0..20529e2 100644 --- a/src/poly.c +++ b/src/poly.c @@ -1,3 +1,11 @@ +#include"general.h" +#include"poly.h" +#include<stdlib.h> +#include"vertex.h" +#include"bond.h" +#include<math.h> + + ts_poly *init_poly(ts_uint n, ts_vertex *grafted_vtx){ ts_poly *poly=(ts_poly *)calloc(1,sizeof(ts_poly)); poly->vlist = init_vertex_list(n); @@ -6,31 +14,81 @@ grafted_vtx->grafted_poly = poly; ts_uint i; - for(i=0,i<n-1,i++){ + for(i=0;i<n-1;i++){ vtx_add_cneighbour(poly->blist, poly->vlist->vtx[i], poly->vlist->vtx[i+1]); + vtx_add_neighbour(poly->vlist->vtx[i+1], poly->vlist->vtx[i]); } return poly; } -ts_poly_list *init_poly_list(ts_uint n_poly, ts_uint n_mono, ts_vertex_list vlist){ +ts_poly_list *init_poly_list(ts_uint n_poly, ts_uint n_mono, ts_vertex_list *vlist){ 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=0,j=0; + ts_uint gvtxi; + ts_double xnorm,ynorm,znorm,normlength; if (n_poly > vlist->n){fatal("Number of polymers larger then numbero f vertices on a vesicle.",310);} - ts_uint i=0; - ts_uint gvtxi; while(i<n_poly){ - gvtxi = rand() % vlist->n + gvtxi = rand() % vlist->n; if (vlist->vtx[gvtxi]->grafted_poly == NULL){ - poly_list->poly = init_poly(n_mono, vlist->vtx[gvtxi]); + poly_list->poly[i] = init_poly(n_mono, vlist->vtx[gvtxi]); i++; } } poly_list->n = n_poly; +/* Make straight poylmers normal to membrane. Dist. between poly vertices put to 1*/ + for (i=0;i<poly_list->n;i++){ + + xnorm=0.0; + ynorm=0.0; + znorm=0.0; + for (j=0;j<poly_list->poly[i]->grafted_vtx->tristar_no;j++){ + xnorm+=poly_list->poly[i]->grafted_vtx->tristar[j]->xnorm; + ynorm+=poly_list->poly[i]->grafted_vtx->tristar[j]->ynorm; + znorm+=poly_list->poly[i]->grafted_vtx->tristar[j]->znorm; + } + normlength=sqrt(xnorm*xnorm+ynorm*ynorm+znorm*znorm); + xnorm=xnorm/normlength; + ynorm=ynorm/normlength; + znorm=znorm/normlength; + + for (j=0;j<poly_list->poly[i]->vlist->n;j++){ + poly_list->poly[i]->vlist->vtx[j]->x = poly_list->poly[i]->grafted_vtx->x + xnorm*(ts_double)(j+1); + poly_list->poly[i]->vlist->vtx[j]->y = poly_list->poly[i]->grafted_vtx->y + ynorm*(ts_double)(j+1); + poly_list->poly[i]->vlist->vtx[j]->z = poly_list->poly[i]->grafted_vtx->z + znorm*(ts_double)(j+1); + } + } + return poly_list; } + +ts_bool poly_free(ts_poly *poly){ + + if (poly->grafted_vtx!=NULL){ + poly->grafted_vtx->grafted_poly=NULL; + } + vtx_list_free(poly->vlist); + bond_list_free(poly->blist); + free(poly); + + return TS_SUCCESS; +} + +ts_bool poly_list_free(ts_poly_list *poly_list){ + ts_uint i; + + for(i=0;i<poly_list->n;i++){ + poly_free(poly_list->poly[i]); + } + free(poly_list->poly); + free(poly_list); + + return TS_SUCCESS; +} diff --git a/src/poly.h b/src/poly.h index 395b486..89392ba 100644 --- a/src/poly.h +++ b/src/poly.h @@ -7,4 +7,8 @@ ts_poly_list *init_poly_list(ts_uint n_poly, ts_uint n_mono, ts_vertex_list *vlist); +ts_bool poly_free(ts_poly *poly); + +ts_bool poly_list_free(ts_poly_list *poly_list); + #endif diff --git a/src/vesicle.c b/src/vesicle.c index d2caf4b..9c5342a 100644 --- a/src/vesicle.c +++ b/src/vesicle.c @@ -6,9 +6,10 @@ #include "cell.h" #include "stdlib.h" + ts_vesicle *init_vesicle(ts_uint N, ts_uint ncmax1, ts_uint ncmax2, ts_uint ncmax3, ts_double stepsize){ - ts_vesicle *vesicle=(ts_vesicle *)malloc(sizeof(ts_vesicle)); + ts_vesicle *vesicle=(ts_vesicle *)calloc(1,sizeof(ts_vesicle)); vesicle->vlist=init_vertex_list(N); vesicle->blist=init_bond_list(); vesicle->tlist=init_triangle_list(); -- Gitblit v1.9.3