From: hackbard Date: Fri, 7 Nov 2008 18:39:19 +0000 (+0100) Subject: added partition support in create_lattice function X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=787848dc9bf3daa2ccb76296de904688cc504a45;p=physik%2Fposic.git added partition support in create_lattice function --- diff --git a/mdrun.c b/mdrun.c index 17ce277..83f501c 100644 --- a/mdrun.c +++ b/mdrun.c @@ -1166,24 +1166,24 @@ int main(int argc,char **argv) { create_lattice(&moldyn,FCC,mdrun.lc,mdrun.fill_element, mdrun.m1,DEFAULT_ATOM_ATTR, mdrun.fill_brand,mdrun.lx, - mdrun.ly,mdrun.lz,NULL); + mdrun.ly,mdrun.lz,NULL,0,NULL); break; case DIAMOND: create_lattice(&moldyn,DIAMOND,mdrun.lc, mdrun.fill_element, mdrun.m1,DEFAULT_ATOM_ATTR, mdrun.fill_brand,mdrun.lx, - mdrun.ly,mdrun.lz,NULL); + mdrun.ly,mdrun.lz,NULL,0,NULL); break; case ZINCBLENDE: o.x=0.5*0.25*mdrun.lc; o.y=o.x; o.z=o.x; create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element1, mdrun.m1,DEFAULT_ATOM_ATTR,0,mdrun.lx, - mdrun.ly,mdrun.lz,&o); + mdrun.ly,mdrun.lz,&o,0,NULL); o.x+=0.25*mdrun.lc; o.y=o.x; o.z=o.x; create_lattice(&moldyn,FCC,mdrun.lc,mdrun.element2, mdrun.m2,DEFAULT_ATOM_ATTR,1,mdrun.lx, - mdrun.ly,mdrun.lz,&o); + mdrun.ly,mdrun.lz,&o,0,NULL); break; case NONE: set_nn_dist(&moldyn,mdrun.nnd); diff --git a/moldyn.c b/moldyn.c index 13d7e5d..8451c44 100644 --- a/moldyn.c +++ b/moldyn.c @@ -513,7 +513,8 @@ int moldyn_log_shutdown(t_moldyn *moldyn) { */ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass, - u8 attr,u8 brand,int a,int b,int c,t_3dvec *origin) { + u8 attr,u8 brand,int a,int b,int c,t_3dvec *origin, + u8 p_type,t_part_vals *p_vals) { int new,count; int ret; @@ -571,21 +572,21 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass, switch(type) { case CUBIC: set_nn_dist(moldyn,lc); - ret=cubic_init(a,b,c,lc,atom,&orig); + ret=cubic_init(a,b,c,lc,atom,&orig,p_type,p_vals); strcpy(name,"cubic"); break; case FCC: if(!origin) v3_scale(&orig,&orig,0.5); set_nn_dist(moldyn,0.5*sqrt(2.0)*lc); - ret=fcc_init(a,b,c,lc,atom,&orig); + ret=fcc_init(a,b,c,lc,atom,&orig,p_type,p_vals); strcpy(name,"fcc"); break; case DIAMOND: if(!origin) v3_scale(&orig,&orig,0.25); set_nn_dist(moldyn,0.25*sqrt(3.0)*lc); - ret=diamond_init(a,b,c,lc,atom,&orig); + ret=diamond_init(a,b,c,lc,atom,&orig,p_type,p_vals); strcpy(name,"diamond"); break; default: @@ -710,12 +711,14 @@ int del_atom(t_moldyn *moldyn,int tag) { } /* cubic init */ -int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { +int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin, + u8 p_type,t_part_vals *p_vals) { int count; t_3dvec r; int i,j,k; t_3dvec o; + t_3dvec dist; count=0; if(origin) @@ -723,14 +726,39 @@ int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { else v3_zero(&o); + /* shift partition values */ + if(p_type) { + p_vals->p.x+=(a*lc)/2.0; + p_vals->p.y+=(b*lc)/2.0; + p_vals->p.z+=(c*lc)/2.0; + } + r.x=o.x; for(i=0;ip)); + if(v3_absolute_square(&dist)<(p_vals->r*p_vals->r)) { v3_copy(&(atom[count].r),&r); count+=1; + } + break; + case PART_OUTSIDE_R: + v3_sub(&dist,&r,&(p_vals->p)); + if(v3_absolute_square(&dist)>=(p_vals->r*p_vals->r)) { + v3_copy(&(atom[count].r),&r); + count+=1; + } + break; + default: + v3_copy(&(atom[count].r),&r); + count+=1; + break; + } r.z+=lc; } r.y+=lc; @@ -748,12 +776,14 @@ int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { } /* fcc lattice init */ -int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { +int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin, + u8 p_type,t_part_vals *p_vals) { int count; int i,j,k,l; t_3dvec o,r,n; t_3dvec basis[3]; + t_3dvec dist; count=0; if(origin) @@ -770,6 +800,13 @@ int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { basis[2].y=0.5*lc; basis[2].z=0.5*lc; + /* shift partition values */ + if(p_type) { + p_vals->p.x+=(a*lc)/2.0; + p_vals->p.y+=(b*lc)/2.0; + p_vals->p.z+=(c*lc)/2.0; + } + /* fill up the room */ r.x=o.x; for(i=0;ip)); + if(v3_absolute_square(&dist)<(p_vals->r*p_vals->r)) { v3_copy(&(atom[count].r),&r); count+=1; - r.z+=lc; + } + break; + case PART_OUTSIDE_R: + v3_sub(&dist,&r,&(p_vals->p)); + if(v3_absolute_square(&dist)>=(p_vals->r*p_vals->r)) { + v3_copy(&(atom[count].r),&r); + count+=1; + } + break; + default: + v3_copy(&(atom[count].r),&r); + count+=1; + break; + } /* the three face centered atoms */ for(l=0;l<3;l++) { v3_add(&n,&r,&basis[l]); + switch(p_type) { + case PART_INSIDE_R: + v3_sub(&dist,&n,&(p_vals->p)); + if(v3_absolute_square(&dist)<(p_vals->r*p_vals->r)) { + v3_copy(&(atom[count].r),&r); + count+=1; + } + break; + case PART_OUTSIDE_R: + v3_sub(&dist,&n,&(p_vals->p)); + if(v3_absolute_square(&dist)>=(p_vals->r*p_vals->r)) { + v3_copy(&(atom[count].r),&r); + count+=1; + } + break; + default: v3_copy(&(atom[count].r),&n); count+=1; + break; + } } + r.z+=lc; } r.y+=lc; } @@ -803,12 +876,13 @@ int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { return count; } -int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { +int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin, + u8 p_type,t_part_vals *p_vals) { int count; t_3dvec o; - count=fcc_init(a,b,c,lc,atom,origin); + count=fcc_init(a,b,c,lc,atom,origin,p_type,p_vals); o.x=0.25*lc; o.y=0.25*lc; @@ -816,7 +890,7 @@ int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { if(origin) v3_add(&o,&o,origin); - count+=fcc_init(a,b,c,lc,&atom[count],&o); + count+=fcc_init(a,b,c,lc,&atom[count],&o,p_type,p_vals); return count; } diff --git a/moldyn.h b/moldyn.h index ee0a6dc..1e9db2a 100644 --- a/moldyn.h +++ b/moldyn.h @@ -250,6 +250,15 @@ typedef struct s_vb { int fd; } t_vb; +typedef struct s_part_vals { + double r; + t_3dvec p; + t_3dvec d; +} t_part_vals; + +#define PART_INSIDE_R 1 +#define PART_OUTSIDE_R 2 + /* * * defines @@ -397,13 +406,17 @@ int moldyn_set_log(t_moldyn *moldyn,u8 type,int timer); int moldyn_log_shutdown(t_moldyn *moldyn); int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass, - u8 attr,u8 brand,int a,int b,int c,t_3dvec *origin); + u8 attr,u8 brand,int a,int b,int c,t_3dvec *origin, + u8 p_type,t_part_vals *p_vals); int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr, t_3dvec *r,t_3dvec *v); int del_atom(t_moldyn *moldyn,int tag); -int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin); -int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin); -int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin); +int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin, + u8 p_type,t_part_vals *p_vals); +int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin, + u8 p_type,t_part_vals *p_vals); +int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin, + u8 p_type,t_part_vals *p_vals); int destroy_atoms(t_moldyn *moldyn); int thermal_init(t_moldyn *moldyn,u8 equi_init); diff --git a/sic.c b/sic.c index e33d934..f769f6f 100644 --- a/sic.c +++ b/sic.c @@ -327,23 +327,23 @@ int main(int argc,char **argv) { #ifdef INIT_SI create_lattice(&md,DIAMOND,ALBE_LC_SI,SI,M_SI, ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, - 0,LCNTX,LCNTY,LCNTZ,NULL); + 0,LCNTX,LCNTY,LCNTZ,NULL,0,NULL); #endif #ifdef INIT_C create_lattice(&md,DIAMOND,ALBE_LC_C,C,M_C, ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, - 1,LCNTX,LCNTY,LCNTZ,NULL); + 1,LCNTX,LCNTY,LCNTZ,NULL,0,NULL); #endif #else #ifdef INIT_SI create_lattice(&md,DIAMOND,LC_SI,SI,M_SI, ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, - 0,LCNTX,LCNTY,LCNTZ,NULL); + 0,LCNTX,LCNTY,LCNTZ,NULL,0,NULL); #endif #ifdef INIT_C create_lattice(&md,DIAMOND,LC_C,SI,M_SI, ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, - 1,LCNTX,LCNTY,LCNTZ,NULL); + 1,LCNTX,LCNTY,LCNTZ,NULL,0,NULL); #endif #endif @@ -353,20 +353,20 @@ int main(int argc,char **argv) { r.x=0.5*0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x; create_lattice(&md,FCC,ALBE_LC_SIC,SI,M_SI, ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, - 0,LCNTX,LCNTY,LCNTZ,&r); + 0,LCNTX,LCNTY,LCNTZ,&r,0,NULL); r.x+=0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x; create_lattice(&md,FCC,ALBE_LC_SIC,C,M_C, ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB|ATOM_ATTR_VB, - 1,LCNTX,LCNTY,LCNTZ,&r); + 1,LCNTX,LCNTY,LCNTZ,&r,0,NULL); #else r.x=0.5*0.25*TM_LC_SIC; r.y=r.x; r.z=r.x; create_lattice(&md,FCC,TM_LC_SIC,SI,M_SI, ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, - 0,LCNTX,LCNTY,LCNTZ,&r); + 0,LCNTX,LCNTY,LCNTZ,&r,0,NULL); r.x+=0.25*TM_LC_SIC; r.y=r.x; r.z=r.x; create_lattice(&md,FCC,TM_LC_SIC,C,M_C, ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, - 1,LCNTX,LCNTY,LCNTZ,&r); + 1,LCNTX,LCNTY,LCNTZ,&r,0,NULL); #endif #endif