From 2afc2f4f1dd89518995f1b5a539aea932aecab65 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Fri, 08 Mar 2019 19:50:18 +0000 Subject: [PATCH] Full write of constant volume plugin --- src/plugins.c | 3 +++ src/general.h | 5 +++-- src/plugins/constant_volume.c | 16 ++++++---------- src/vertexmove.c | 33 +++++++++++++++++++++------------ 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/general.h b/src/general.h index 4c09b71..702ba19 100644 --- a/src/general.h +++ b/src/general.h @@ -314,8 +314,8 @@ ts_double (*vm_energy_after_prepare)(void *vesicle, ts_vertex *vtx); ts_double (*vm_energy_after_execute)(void *vesicle, ts_vertex *vtx); ts_double (*vm_before_montecarlo_constraint)(void *vesicle, ts_vertex *vtx, ts_vertex *old_vtx); - ts_double (*vm_new_state_accepted)(void *vesicle, ts_vertex *vtx); - ts_double (*vm_new_state_rejected)(void *vesicle, ts_vertex *vtx); + ts_double (*vm_new_state_accepted)(void *vesicle, ts_vertex *vtx, ts_vertex *old_vtx); + ts_double (*vm_new_state_rejected)(void *vesicle, ts_vertex *vtx, ts_vertex *old_vtx); void (*cleanup)(void); } ts_plugin_function; @@ -346,6 +346,7 @@ ts_plugin_chain *vm_energy_before_prepare; ts_plugin_chain *vm_energy_after_execute; ts_plugin_chain *vm_before_montecarlo_constraint; + ts_plugin_chain *vm_new_state_accepted; ts_plugin_chain *cleanup; } ts_plugin_chains; diff --git a/src/plugins.c b/src/plugins.c index 0af3d4f..a6b843b 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -171,6 +171,9 @@ if(plist->plugin[i]->function->vm_before_montecarlo_constraint!=NULL){ plist->chain->vm_before_montecarlo_constraint=plugin_to_chain(plist->chain->vm_before_montecarlo_constraint, plist->plugin[i]); } + if(plist->plugin[i]->function->vm_new_state_accepted!=NULL){ + plist->chain->vm_new_state_accepted=plugin_to_chain(plist->chain->vm_new_state_accepted, plist->plugin[i]); + } } plist->n=number_of_plugins; return plist; diff --git a/src/plugins/constant_volume.c b/src/plugins/constant_volume.c index f86eaee..11d17dd 100644 --- a/src/plugins/constant_volume.c +++ b/src/plugins/constant_volume.c @@ -57,16 +57,12 @@ if(fabs(vesicle->volume+data->dvol-data->V0)>data->epsvol) return TS_FAIL; } return TS_SUCCESS; -// if(vesicle->tape->constvolswitch==2){ -// /*check whether the dvol is gt than epsvol */ -// if(fabs(vesicle->volume+data->dvol-data->V0)>data->epsvol) return TS_FAIL; -//This part doesn't work as expected yet. Delta_energy_cv shoould be accounted for in the total energy change. +} -/* }else if(vesicle->tape->constvolswitch == 1){ - retval=constvolume(vesicle, vtx, -dvol, &delta_energy_cv, &constvol_vtx_moved,&constvol_vtx_backup); - if(retval==TS_FAIL){ // if we couldn't move the vertex to assure constant volume - return TS_FAIL; - } */ - return TS_SUCCESS; +void vm_new_state_accepted(ts_vesicle *vesicle, ts_vertex *vtx, ts_vertex *old_vtx){ + if(vesicle->tape->constvolswitch >0){ + plugin_data *data=(plugin_data *)vesicle->plist->pointer->plugin->details->data; + vesicle->volume+=data->dvol; + } } diff --git a/src/vertexmove.c b/src/vertexmove.c index d33207f..37508e9 100644 --- a/src/vertexmove.c +++ b/src/vertexmove.c @@ -23,7 +23,7 @@ ts_double delta_energy, oenergy,dvol=0.0, darea=0.0, dstretchenergy=0.0; ts_double costheta,sintheta,phi,r; //This will hold all the information of vtx and its neighbours - ts_vertex backupvtx[20], *constvol_vtx_moved=NULL, *constvol_vtx_backup=NULL; + ts_vertex backupvtx[20]; // *constvol_vtx_moved=NULL, *constvol_vtx_backup=NULL; memcpy((void *)&backupvtx[0],(void *)vtx,sizeof(ts_vertex)); //random move in a sphere with radius stepsize: @@ -202,9 +202,9 @@ } // fprintf(stderr, "before vtx(x,y,z)=%e,%e,%e\n",constvol_vtx_moved->x, constvol_vtx_moved->y, constvol_vtx_moved->z); - if(vesicle->tape->constvolswitch == 1){ - constvolumerestore(constvol_vtx_moved,constvol_vtx_backup); - } +// if(vesicle->tape->constvolswitch == 1){ +// constvolumerestore(constvol_vtx_moved,constvol_vtx_backup); +// } // fprintf(stderr, "after vtx(x,y,z)=%e,%e,%e\n",constvol_vtx_moved->x, constvol_vtx_moved->y, constvol_vtx_moved->z); // vesicle_volume(vesicle); // fprintf(stderr,"Volume after fail=%1.16e\n", vesicle->volume); @@ -224,18 +224,27 @@ if(vesicle->tape->constvolswitch == 2){ vesicle->volume+=dvol; - } else - if(vesicle->tape->constvolswitch == 1){ - constvolumeaccept(vesicle,constvol_vtx_moved,constvol_vtx_backup); - } + } + + if(vesicle->tape->constareaswitch==2){ vesicle->area+=darea; } -// if(oldcellidx); - //END MONTE CARLOOOOOOO -// vesicle_volume(vesicle); -// fprintf(stderr,"Volume after success=%1.16e\n", vesicle->volume); + + +/* Entry point for plugin vm_before_montecarlo_constraint() function */ + vesicle->plist->pointer=vesicle->plist->chain->vm_new_state_accepted; + while(vesicle->plist->pointer!=NULL){ + vesicle->plist->pointer->plugin->function->vm_new_state_accepted(vesicle,vtx, &backupvtx[0]); + vesicle->plist->pointer=vesicle->plist->pointer->next; + } +/* End of vm_before_montecarlo_constraint() */ + + + + + return TS_SUCCESS; } -- Gitblit v1.9.3