added postproc stuff, sic mods (today i was a lazy ass!)
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Mon, 23 Jul 2007 15:09:26 +0000 (17:09 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Mon, 23 Jul 2007 15:09:26 +0000 (17:09 +0200)
Makefile
moldyn.c
moldyn.h
postproc.c
sic.c

index 72904f5..ee6e927 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,11 +16,14 @@ POT_SRC=potentials/tersoff.c
 POT_SRC+=potentials/albe.c
 POT_SRC+= potentials/lennard_jones.c potentials/harmonic_oscillator.c
 
-all: sic fluctuation_calc
+all: sic fluctuation_calc postproc
 
 sic: 
        $(CC) $(CFLAGS) $(LDFLAGS) $(POT_SRC) $(SOURCE) sic.c -o sic
 
+postproc:
+       $(CC) $(CFLAGS) $(LDFLAGS) $(POT_SRC) $(SOURCE) postproc.c -o postproc
+
 .PHONY:clean
 clean:
-       rm -f sic
+       rm -f sic postproc
index 7d27965..a310e91 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -24,6 +24,9 @@ int moldyn_init(t_moldyn *moldyn,int argc,char **argv) {
 
        memset(moldyn,0,sizeof(t_moldyn));
 
+       moldyn->argc=argc;
+       moldyn->args=argv;
+
        rand_init(&(moldyn->random),NULL,1);
        moldyn->random.status|=RAND_STAT_VERBOSE;
 
@@ -1483,7 +1486,7 @@ return 0;
        printf("\rsched:%d, steps:%d, T:%3.1f/%3.1f P:%4.1f/%4.1f V:%6.1f",
               sched->count,i,
               moldyn->t,moldyn->t_avg,
-              moldyn->p_avg/BAR,moldyn->p/BAR,
+              moldyn->p_avg/BAR,moldyn->gp_avg/BAR,
               moldyn->volume);
        fflush(stdout);
                }
index a595585..9f9d0f7 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -78,6 +78,9 @@ typedef struct s_moldyn_schedule {
 
 /* moldyn main structure */
 typedef struct s_moldyn {
+       int argc;               /* number of arguments */
+       char **args;            /* pointer to arguments */
+
        int count;              /* total amount of atoms */
        double mass;            /* total system mass */
        t_atom *atom;           /* pointer to the atoms */
index 68e0918..18834af 100644 (file)
  *
  */
 
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include <math.h>
  
 #include "moldyn.h"
+#include "math/math.h"
+
+#define FILEMAX        127
+#define BUFMAX 127
+
+#define DISPLACEMENT   (1<<0)
+#define VELOCITY       (1<<1)
+
+static char *pse[]={
+        "*",
+        "H",
+        "He",
+        "Li",
+        "Be",
+        "B",
+        "C",
+        "N",
+        "O",
+        "F",
+        "Ne",
+        "Na",
+        "Mg",
+        "Al",
+        "Si",
+        "P",
+        "S",
+        "Cl",
+        "Ar",
+};
+
+int usage(void) {
+       printf("usage:\n");
+       printf("  -i <infile> -o <outfile>\n");
+       printf("  -d/v (displacement,velocity)\n");
+       printf(" \n");
+       return 1;
+}
 
 int main(int argc,char **argv) {
 
        t_moldyn md;
+       t_atom *atom;
+       char infile[FILEMAX+1];
+       int infd;
+       char outfile[FILEMAX+1];
+       int outfd;
+       int ret,size;
+       unsigned char mode;
+       char buf[BUFMAX+1];
+       t_3dvec dist;
+       int i;
+
+       memset(infile,0,FILEMAX+1);
+       memset(outfile,0,FILEMAX+1);
+       memset(buf,0,BUFMAX+1);
+       mode=0;
+
+       /* parse argv */
+       for(i=1;i<argc;i++) {
+
+               if(argv[i][0]!='-') {
+                       usage();
+                       return -1;
+               }
+               
+               switch(argv[i][1]) {
+                       case 'h':
+                               usage();
+                               return 1;
+                       case 'i':
+                               strncpy(infile,argv[++i],FILEMAX);
+                               break;
+                       case 'o':
+                               strncpy(outfile,argv[++i],FILEMAX);
+                               break;
+                       case 'd':
+                               mode=DISPLACEMENT;
+                               break;
+                       case 'v':
+                               mode=VELOCITY;
+                               break;
+                       default:
+                               usage();
+                               return -1;
+               }
+
+       }
+
+       /* open infile */
 
+       if(!strcmp(infile,"")) {
+               printf("no infile specified!\n");
+               return -1;
+       }
+       printf("infile -> %s\n",infile);
+
+       infd=open(infile,O_RDONLY);
+       if(infd<3) {
+               perror("infile");
+               return infd;
+       }
+
+       /* open outfile */
        
+       if(!strcmp(outfile,"")) {
+               printf("no outfile specified!\n");
+               return -1;
+       }
+       printf("outfile -> %s\n",outfile);
+
+       outfd=open(outfile,O_WRONLY|O_CREAT);
+       if(outfd<3) {
+               perror("outfile");
+               return outfd;
+       }
+
+       /* read in data */
+
+       size=sizeof(t_moldyn);
+       ret=0;
+       while(size-ret)
+               ret+=read(infd,&md,size-ret);
+       printf("read %d bytes moldyn struct data\n",size);
+
+       /* allocate memory for atoms */
+       size=md.count*sizeof(t_atom);
+       md.atom=malloc(size);
+       if(md.atom==NULL) {
+               perror("malloc");
+               goto end;
+       }
+
+       /* read in atom data */
+
+       ret=0;
+       atom=md.atom;
+       while(size-ret)
+               ret+=read(infd,atom,size-ret);
+       printf("read %d bytes atom data\n",size);
+
+       /* postprocess ... */
+       dprintf(outfd,"%d\n",md.count+8);
+       dprintf(outfd,"atoms at time %f\n",md.time);
+       for(i=0;i<md.count;i++) {
+printf("%d ",i);
+               dprintf(outfd,"%s %f %f %f",pse[atom[i].element],
+                                          atom[i].r.x,atom[i].r.y,atom[i].r.z);
+               if(mode&DISPLACEMENT) {
+                       v3_sub(&dist,&(atom[i].r),&(atom[i].r_0));
+                       check_per_bound(&md,&dist);
+                       dprintf(outfd," %f",v3_norm(&dist));
+               }
+               if(mode&VELOCITY) {
+                       dprintf(outfd," %f",atom[i].ekin);
+               }
+               dprintf(outfd,"\n");
+       }
+
+       /* free memory & close file descriptors */
+
+end:
+       free(md.atom);
+       close(infd);
+       close(outfd);
 
        return 0;
 }
diff --git a/sic.c b/sic.c
index 5f2a8db..fa2a396 100644 (file)
--- a/sic.c
+++ b/sic.c
 
 #define INJECT         1
 #define NR_ATOMS       1
-#define R_C            2.0
+#define R_C            1.0
 #define T_C            10.0
-#define LCNT           2
+#define LCNT           5
 
 typedef struct s_hp {
        int a_count;    /* atom count */
        u8 quit;        /* quit mark */
+       int argc;       /* arg count */
+       char **argv;    /* args */
 } t_hp;
 
 int hook(void *moldyn,void *hook_params) {
@@ -75,6 +77,9 @@ int hook(void *moldyn,void *hook_params) {
                        r.x=(rand_get_double(&(md->random))-0.5)*md->dim.x*0.37;
                        r.y=(rand_get_double(&(md->random))-0.5)*md->dim.y*0.37;
                        r.z=(rand_get_double(&(md->random))-0.5)*md->dim.z*0.37;
+                       //r.x=(1.0*atoi(hp->argv[3])-4.5)/9.0*ALBE_LC_SI;
+                       //r.y=(1.0*atoi(hp->argv[4])-4.5)/9.0*ALBE_LC_SI;
+                       //r.z=(1.0*atoi(hp->argv[5])-4.5)/9.0*ALBE_LC_SI;
                        /* assume valid coordinates */
                        run=0;
                        for(i=0;i<md->count;i++) {
@@ -104,10 +109,10 @@ int hook(void *moldyn,void *hook_params) {
 int main(int argc,char **argv) {
 
        /* check argv */
-       if(argc!=3) {
-               printf("[sic] usage: %s <logdir> <temperatur>\n",argv[0]);
-               return -1;
-       }
+       //if(argc!=3) {
+       //      printf("[sic] usage: %s <logdir> <temperatur>\n",argv[0]);
+       //      return -1;
+       //}
 
        /* main moldyn structure */
        t_moldyn md;
@@ -352,6 +357,8 @@ int main(int argc,char **argv) {
 
        /* schedule hook function */
        memset(&hookparam,0,sizeof(t_hp));
+       hookparam.argc=argc;
+       hookparam.argv=argv;
        moldyn_set_schedule_hook(&md,&hook,&hookparam);
 
        /* activate logging */