From: hackbard Date: Thu, 28 Oct 2004 18:53:36 +0000 (+0000) Subject: added nlsop_client code X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fnlsop.git;a=commitdiff_plain;h=611c4dc08cdfc058f96352cde92496c501102030 added nlsop_client code --- diff --git a/nlsop_client.c b/nlsop_client.c new file mode 100644 index 0000000..403bfe0 --- /dev/null +++ b/nlsop_client.c @@ -0,0 +1,557 @@ +/* + * client nlsop code + * + * author: frank zirkelbach (frank.zirkelbach@physik.uni-augsburg.de) + * + * this program tries helping to understand the amorphous depuration + * and recrystallization of SiCx while ion implantation at temperatures + * below 400 degree celsius. + * hopefully the program will simulate the stabilization of the + * selforganizing lamella structure in the observed behaviour. + * + * refs: + * - J. K. N. Lindner. Habil.Schrift, Universitaet Augsburg. + * - Maik Haeberlen. Diplomarbeit, Universitaet Augsburg. + * + * Copyright (C) 2004 Frank Zirkelbach + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "nlsop.h" +#include "dfbapi.h" +#include "random.h" + +#include "../api/network.h" +#include "../api/event.h" +#include "../api/list.h" + +#define MAKE_AMORPH(N) *(N)|=AMORPH +#define MAKE_CRYST(N) *(N)&=~AMORPH + +int usage(char *prog) +{ + puts("usage:"); + printf("%s \n",prog); + return 1; +} + +/* + * nlsop internal functions + */ + +int sputter(d3_lattice *d3_l) +{ + int i,size; + int offh,offl; + + size=d3_l->max_x*d3_l->max_y; + offl=0; + offh=size; + + for(i=0;imax_z-1;i++) + { + memcpy(d3_l->status+offl,d3_l->status+offh,size); + memcpy(d3_l->extra+offl,d3_l->extra+offh,size*sizeof(int)); + offl=offh; + offh+=size; + } + memset(d3_l->status+offl,0,size); + memset(d3_l->extra+offl,0,size); + + return 1; +} + +int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,info *my_info,u32 nel_z) +{ + unsigned char *thiz; + int *conc; + int i,j; + int off; + double p,q; + + thiz=d3_l->status+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; + conc=d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; + p=my_info->b*nel_z; + for(i=-(my_info->range);i<=my_info->range;i++) + { + for(j=-(my_info->range);j<=my_info->range;j++) + { + if(!(i==0 && j==0)) + { + off=((x+d3_l->max_x+i)%d3_l->max_x)+((y+d3_l->max_y+j)%d3_l->max_x)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y; + if(*(d3_l->status+off)&AMORPH) p+=my_info->s*(*(d3_l->extra+off))*URAND_MAX/(i*i+j*j); + } + } + } + p+=*conc*my_info->c*URAND_MAX; + if(!(*thiz&AMORPH)) + { + if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz); + } else + { + /* assume 1-p probability */ + /* also look for neighbours ! */ + q=(URAND_MAX-p)>0?URAND_MAX-p:0; + j=0; + j+=(*(d3_l->status+((x+d3_l->max_x+1)%d3_l->max_x)+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+((x+d3_l->max_x-1)%d3_l->max_x)+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+x+((y+1+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+x+((y-1+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+x+y*d3_l->max_x+((z+1+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + j+=(*(d3_l->status+x+y*d3_l->max_x+((z-1+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y)&AMORPH)?1:0; + + p+=((q/6)*j); + if(get_rand(URAND_MAX)>p) MAKE_CRYST(thiz); + } + + return 1; +} + +int distrib_c(d3_lattice *d3_l,info *my_info,int step,u32 rj_m,u32 *rj_g) +{ + u32 x,y,z; + int i,j,k,c; + int offset,off; + int carry; + + /* put one c ion somewhere in the lattice */ + x=get_rand(d3_l->max_x); + y=get_rand(d3_l->max_y); + z=get_rand_reject(d3_l->max_z,rj_m,rj_g); + *(d3_l->extra+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)+=1; + (my_info->cc)++; + + if(step%my_info->diff_rate==0) + { + + for(i=0;imax_x;i++) + { + for(j=0;jmax_y;j++) + { + for(k=0;kmax_z;k++) + { + offset=i+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y; + /* case amorph: amorph <- cryst diffusion */ + if(*(d3_l->status+offset)&AMORPH) + { + for(c=-1;c<=1;c++) + { + if(c!=0) + { + off=((i+d3_l->max_x+c)%d3_l->max_x)+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y; + carry=0; + if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off))); + if(carry!=0) + { + *(d3_l->extra+offset)+=carry; + *(d3_l->extra+off)-=carry; + } + } + } + for(c=-1;c<=1;c++) + { + if(c!=0) + { + off=i+((j+c+d3_l->max_y)%d3_l->max_y)*d3_l->max_x+k*d3_l->max_x*d3_l->max_y; + carry=0; + if(!(*(d3_l->status+off)&AMORPH)) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off))); + if(carry!=0) + { + *(d3_l->extra+offset)+=carry; + *(d3_l->extra+off)-=carry; + } + } + } + if(my_info->z_diff) + { + if(k!=0) + { + off=i+j*d3_l->max_x+(k-1)*d3_l->max_x*d3_l->max_y; + carry=0; + if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off))); + if(carry!=0) + { + *(d3_l->extra+off)-=carry; + *(d3_l->extra+offset)+=carry; + } + } + if(k!=d3_l->max_z-1) + { + off=i+j*d3_l->max_x+(k+1)*d3_l->max_x*d3_l->max_y; + carry=0; + if(!*(d3_l->status+off)&AMORPH) carry=(int)(my_info->dr_ac*(*(d3_l->extra+off))); + if(carry!=0) + { + *(d3_l->extra+off)-=carry; + *(d3_l->extra+offset)+=carry; + } + } + } + } + } /* for z */ + } /* for y */ + } /* for x */ + + } /* if step modulo diff_rate == 0 */ + + return 1; +} + +/* save to file --> send to server :) --> T O D O <-- */ +int send_data( ) { + + return 1; +} + +int save_to_file(char *sf,d3_lattice *d3_l,info *my_inf) +{ + int sf_fd,c; + + if((sf_fd=open(sf,O_WRONLY|O_CREAT))<0) + { + puts("cannot open save file"); + return -1; + } + if(write(sf_fd,d3_l,sizeof(d3_lattice))max_x*d3_l->max_y*d3_l->max_z; + if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))extra,c*sizeof(int)) receive from server :) --> T O D O <-- */ +int receive_data( ) { + + return 1; +} + +int load_from_file(char *lf,d3_lattice *d3_l,info *my_inf) +{ + + int lf_fd,c,pos,end,data,data_len,strip; + + if((lf_fd=open(lf,O_RDONLY))<0) + { + puts("cannot open load file"); + return -1; + } + if(read(lf_fd,d3_l,sizeof(d3_lattice))max_x*d3_l->max_y*d3_l->max_z; + data_len=data*(sizeof(int)+sizeof(unsigned char)); + printf("there are %d volumes so we need %d of bytes\n",data,data_len); + end=lseek(lf_fd,0,SEEK_END); + c=end-pos-data_len; + printf("end: %d => length: %d => guessed info size: %d bytes\n",end,end-pos,c); + strip=sizeof(info)-c; + printf("as real programs info size is %d, we strip %d bytes\n",sizeof(info),strip); + lseek(lf_fd,pos,SEEK_SET); + c=sizeof(info); + if(strip>0) c-=strip; + if(c<0) + { + puts("info smaller then strip size"); + return -1; + } + if(read(lf_fd,my_inf,c)0) memset(my_inf+c,0,strip); + if(strip<0) lseek(lf_fd,(-1*strip),SEEK_CUR); + c=d3_l->max_x*d3_l->max_y*d3_l->max_z; + if((d3_l->status=(unsigned char*)malloc(c*sizeof(unsigned char)))==NULL) + { + puts("cannot allocate status buffer"); + return -1; + } + if((d3_l->extra=(int *)malloc(c*sizeof(int)))==NULL) + { + puts("cannot allocate concentration buffer"); + return -1; + } + if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))extra,c*sizeof(int))max_z))==NULL) + { + puts("cannot malloc flag memory for rejection graph"); + return -1; + } + memset(flag,0,d3_l->max_z); + memset(graph,0,d3_l->max_z*sizeof(u32)); + /* get fixpoints */ + k=1; + while(k) + { + for(i=0;i<32;i++) + { + k=read(fd,&buf[i],1); + if((buf[i]=='\n')||(k==0)) break; + } + if(k) + { + p=strtok(buf," "); + a=atof(p)/10; /* nm */ + p=strtok(NULL," "); + b=atof(p); + if(a>d3_l->max_z*CELL_LENGTH) k=0; + else + { + graph[(int)(a/CELL_LENGTH)]=(int)(URAND_MAX/100*b); + flag[(int)(a/CELL_LENGTH)]=1; + } + } + } + /* do (linear) interpolation here! */ + i=0; + a=0; + while(imax_z) + { + /* graph[0] is 0! */ + j=i; + i++; + while(flag[i]==0&&imax_z) i++; + for(k=j+1;kmax) max=graph[i]; + } + + free(flag); + +#ifdef DEBUG_INTERPOL_PROFILE + printf("debug: %s (interpolated profile)\n",file); + for(i=0;imax_z;i++) printf("%d %d\n",i,graph[i]); +#endif + + return max; +} + + + +/* + * main program + */ + +int main(int argc,char **argv) +{ + + u32 x,y,z,x_c,y_c,z_c; + int i,j; + int resave; + int c_step; + char server_ip[16]; + int port; + char p_file[MAX_CHARS]; + char n_e_file[MAX_CHARS]; + char r_file[MAX_CHARS]; + d3_lattice d3_l; + info my_info; + u32 *c_profile; + u32 *n_e_loss; + u32 ne_max,ip_max; + u32 *nel_z; + unsigned char err_dc,dc; +#define DC_QUIT (1<<0) +#define DC_OK (1<<1) +#define DC_END (1<<2) + t_net net; + + /* default values */ + resave=RESAVE; + c_step=0; + strcpy(server_ip,""); + strcpy(p_file,IMP_PROFILE); + strcpy(n_e_file,NEL_PROFILE); + strcpy(r_file,""); + ne_max=0; + ip_max=0; + err_dc=0; + dc=0; + port=1025; + + /* parse/check argv */ + for(i=1;i