Пример #1
0
SaneWinMain( argc, argv )
{
	FILE *input;
	if( argc > 2 )
	{
		input = sack_fopen( 0, argv[2], WIDE("rb+") );
		if( input )
		{
			if( StrCaseCmpEx( argv[1], WIDE( "u" ), 1 ) == 0 )
			{
				read_ascii( input );
				ascii_to_unicode();
				write_unicode( input );
			}
			else
			{
				read_unicode( input );
				unicode_to_ascii();
				write_ascii( input );
			}
			fclose( input );
		}
		else
			printf( WIDE( "Failed to open %s" ), argv[2] );
	}
	else
	{
		printf( WIDE("Usage: %s [u/a] [filename]\n"), argv[0] );
		printf( WIDE("  u or a is unicode or ascii mode; unicode translates from ascii to unicode\n") );
		printf( WIDE("  ascii translates from unicode to ascii\n") );
		printf( WIDE("  file will be written back in-place\n") );
	}
	return 0;
}
Пример #2
0
static int valid_handler(struct nl_msg *msg, void *arg)
{
	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
	struct nlattr *head_attr = genlmsg_attrdata(gnlh, 0);
	int attr_len = genlmsg_attrlen(gnlh, 0);

	LOG_DBG_("%s\n", __func__);
	(void) arg;
	if (print_ascii)
		return write_ascii(1, (uint8_t *) head_attr, attr_len);

	(void) write(1, (uint8_t *) head_attr, attr_len);

	return NL_OK;
}
Пример #3
0
int main(int argc, char** argv )
{
   unsigned n_surface_verts, n_depth_verts;
   unsigned n_surface_els, n_depth_els;
   double outer_radius, inner_radius;
   Sixth sixths[6];
   CS giant;
   unsigned sixthSize[3], ijk[3], tmp;
   int nVerts, nEls, s_i, v_i, n_id, e_i;
   int **nbrs;
   double **verts;
   double angleDelta;
   double r_limits[2], eta_limits[2], xi_limits[2];

   int **e_n, elsBuilt;

   double **global_coord;
   int nGlobalEls;
   int nGlobalVerts;
   int c;

   clock_t t2, t1 = clock();

   char error[] = "execute with\n ./go -l 11 -d 6 -r 10 -i 5\n" \
            "where:\tl is the length resolution and d is the depth resolution\n" \
            "\tr is the outer radius and i is the inner radius\n";

   /***
     get input:
     geometry and number of elements
   ****/

   n_surface_els=-1;
   n_depth_els=-1;
   outer_radius=-1;
   inner_radius=-1;
   while ( (c = getopt(argc, argv, "l:d:r:i:")) != -1) {
      switch( c ) {
      case 'l':
         n_surface_els=atoi(optarg);
         break;
      case 'd':
         n_depth_els=atoi(optarg);
         break;
      case 'r':
         outer_radius=atof(optarg);
         break;
      case 'i':
         inner_radius=atof(optarg);
         break;
      case '?':
         printf("%s", error);
         exit(1);
      default:
         printf("%s", error);
         exit(1);
      }

   }
   if( n_surface_els==-1 || n_depth_els==-1 || outer_radius==-1 || inner_radius==-1 ) {
      printf("%s", error);
      exit(1);
   }



   /***
     get e_n, epart, n_n, npart
   ***/
   /* set initial sixth definition */
   n_surface_verts = n_surface_els+1;
   n_depth_verts = n_depth_els+1;

   angleDelta = (M_PI/2)/(double)(n_surface_verts-1);

   nGlobalEls = 6*n_surface_els*n_surface_els*n_depth_els;
   nGlobalVerts = 6*n_surface_verts*n_surface_verts*n_depth_verts;

   // initialise counter as they will be used to count the overall number of verts and elements as the sixths get stitched together
   giant.nVerts=0;
   giant.nEls=0;
   giant.nvattribs=1; // BC attribute

   giant.my_e_n = malloc( nGlobalEls * sizeof(int*) );
   for( e_i=0; e_i<nGlobalEls; e_i++ ) {
      giant.my_e_n[e_i] = malloc( 8*sizeof(int) );
   }

   giant.activeList = malloc( nGlobalVerts * sizeof(int) );
   giant.my_nadj = malloc( nGlobalVerts * sizeof(int*) );
   giant.vattribs = malloc( nGlobalVerts * sizeof(int*) );
   giant.my_coords = malloc( nGlobalVerts * sizeof(double*) );
   for( v_i=0; v_i<nGlobalVerts; v_i++ ) {
      giant.my_nadj[v_i] = malloc( 6*sizeof(int) );
      giant.vattribs[v_i] = malloc( giant.nvattribs*sizeof(int) );
      giant.my_coords[v_i] = malloc( 6*sizeof(double) );
   }

   sixthSize[2] = n_depth_verts;
   r_limits[0] = inner_radius;
   r_limits[1] = outer_radius;
   sixthSize[0] = n_surface_verts;
   sixthSize[1] = n_surface_verts;
   xi_limits[0]  = -M_PI/4;
   xi_limits[1]  = M_PI/4;
   eta_limits[0] = -M_PI/4;
   eta_limits[1] = M_PI/4;

   Sixth_Setup(&(sixths[0]), 0, 0, sixthSize, xi_limits, eta_limits, r_limits );
   build_sixth_nadj( &sixths[0] );
   build_sixth_e_n( &sixths[0] );
   evaluate_sixth_geom( &sixths[0],0,0 );

   Sixth_Setup(&(sixths[1]), sixths[0].nEls, sixths[0].nVerts, sixthSize, xi_limits, eta_limits, r_limits );
   build_sixth_nadj( &sixths[1] );
   build_sixth_e_n( &sixths[1] );
   evaluate_sixth_geom( &sixths[1],0,-M_PI/2 );

   Sixth_Setup(&(sixths[2]), 2*sixths[0].nEls, 2*sixths[0].nVerts, sixthSize, xi_limits, eta_limits, r_limits );
   build_sixth_nadj( &sixths[2] );
   build_sixth_e_n( &sixths[2] );
   evaluate_sixth_geom( &sixths[2],0,-M_PI );

   Sixth_Setup(&(sixths[3]), 3*sixths[0].nEls, 3*sixths[0].nVerts, sixthSize, xi_limits, eta_limits, r_limits );
   build_sixth_nadj( &sixths[3] );
   build_sixth_e_n( &sixths[3] );
   evaluate_sixth_geom( &sixths[3],0,M_PI/2 );

   Sixth_Setup(&(sixths[4]), 4*sixths[0].nEls, 4*sixths[0].nVerts, sixthSize, xi_limits, eta_limits, r_limits );
   build_sixth_nadj( &sixths[4] );
   build_sixth_e_n( &sixths[4] );
   evaluate_sixth_geom( &sixths[4],-M_PI/2,0 );

   Sixth_Setup(&(sixths[5]), 5*sixths[0].nEls, 5*sixths[0].nVerts, sixthSize, xi_limits, eta_limits, r_limits );
   build_sixth_nadj( &sixths[5] );
   build_sixth_e_n( &sixths[5] );
   evaluate_sixth_geom( &sixths[5],M_PI/2,0 );

   t2 = clock();
   printf("Time to initialise sixth %g sec\n", (double)(t2-t1)/CLOCKS_PER_SEC );

   /* */
   // debug
   write_sixth_vtu( &sixths[0], "sixth-0.vtu" );
   write_sixth_vtu( &sixths[1], "sixth-1.vtu" );
   write_sixth_vtu( &sixths[2], "sixth-2.vtu" );
   write_sixth_vtu( &sixths[3], "sixth-3.vtu" );
   write_sixth_vtu( &sixths[4], "sixth-4.vtu" );
   write_sixth_vtu( &sixths[5], "sixth-5.vtu" );

   /*
      run function to join walls
   */

   t1=clock();

   join_wall_verts( &sixths[0], NBR_E, &sixths[1], NBR_W, 0 );
   join_wall_verts( &sixths[1], NBR_E, &sixths[2], NBR_W, 0 );
   join_wall_verts( &sixths[2], NBR_E, &sixths[3], NBR_W, 0 );
   join_wall_verts( &sixths[0], NBR_W, &sixths[3], NBR_E, 0 );

   join_wall_verts( &sixths[0], NBR_N, &sixths[4], NBR_S, 0 );
   join_wall_verts( &sixths[1], NBR_N, &sixths[4], NBR_E, 0 );
   join_wall_verts( &sixths[2], NBR_N, &sixths[4], NBR_N, 1 );
   join_wall_verts( &sixths[3], NBR_N, &sixths[4], NBR_W, 1 );

   join_wall_verts( &sixths[0], NBR_S, &sixths[5], NBR_N, 0 );
   join_wall_verts( &sixths[1], NBR_S, &sixths[5], NBR_E, 1 );
   join_wall_verts( &sixths[2], NBR_S, &sixths[5], NBR_S, 1 );
   join_wall_verts( &sixths[3], NBR_S, &sixths[5], NBR_W, 0 );

   t2=clock();
   printf("Time to join sixths %g sec\n", (double)(t2-t1)/CLOCKS_PER_SEC );

   /* add all sixths together into a giant mesh */
   t1=clock();
   addSixthToGiant( &giant, &sixths[0] );
   addSixthToGiant( &giant, &sixths[1] );
   addSixthToGiant( &giant, &sixths[2] );
   addSixthToGiant( &giant, &sixths[3] );
   addSixthToGiant( &giant, &sixths[4] );
   addSixthToGiant( &giant, &sixths[5] );
   t2=clock();
   printf("Time to add sixths to global  %g sec\n", (double)(t2-t1)/CLOCKS_PER_SEC );

   /* reorder the indices of the giant mesh as the removal of duplicate nodes
      - made during the join_wall_verts func - means the giant data structure is
      not contiguous.
      Reording makes is contiguous again
    */
   t1=clock();
   reorderCS(&giant, nGlobalVerts );
   t2=clock();
   printf("Time to add sixths to global  %g sec\n", (double)(t2-t1)/CLOCKS_PER_SEC );

   giant.epart = malloc( giant.nEls*sizeof(int) );
   giant.vpart = malloc( giant.nVerts*sizeof(int) );

#if METIS_ENABLED
   /* go METIS go ! */
   t1=clock();
   partitionCS( &giant );
   t2=clock();
   printf("Time to METIS global  %g sec\n", (double)(t2-t1)/CLOCKS_PER_SEC );
#else
   printf("no metis action because it wasn't found in compile\n" );
#endif

   write_vtu( &giant, "globe.vtu" );
   write_ascii( &giant );


   for( v_i=0; v_i<giant.nVerts; v_i++ ) {
      free(giant.my_nadj[v_i]);
      free(giant.vattribs[v_i]);
      free(giant.my_coords[v_i]);
   }
   free(giant.epart);
   free(giant.vpart);
   free(giant.my_nadj);
   free(giant.vattribs);
   free(giant.my_coords);
   for( e_i=0; e_i<nGlobalEls; e_i++ ) {
      free( giant.my_e_n[e_i]);
   }
   free(giant.my_e_n);
   free(giant.activeList);

   for( s_i=0; s_i<6; s_i++ ) {
      Sixth_FreeMem( &sixths[s_i] );
   }

   printf("Success\n");
   exit(0);

}
Пример #4
0
/*	Handle one message
**	------------------
**
** On entry,
**	soc		A file descriptor for input and output.
** On exit,
**	returns		>0	Channel is still open.
**			0	End of file was found, please close file
**			<0	Error found, please close file.
*/
int handle(int soc)
{
#define COMMAND_SIZE	255
#define MAX_LINES 10000			/* Maximum number of lines returned */
    char command[COMMAND_SIZE+1];
    char		    buffer[BUFFER_SIZE];
    int	status;
    char * arg;		/* Pointer to the argument string */
    char * filename;	/* Pointer to filename or group list*/
    char * keywords;	/* pointer to keywords */
    char system_command[COMMAND_SIZE+1];
    int lines;		/* Number of lines returned by EXEC file */
    int fd;		/* File descriptor number */
    int	isIndex = 0;	/* Is the thing asked for an index? */
   
    for (;;) {
	status = read(soc, command, COMMAND_SIZE);
	if (status<=0) {
	    if (TRACE) printf("read returned %i, errno=%i\n", status, errno);
	    return status;	/* Return and close file */
	}
	command[status]=0;	/* terminate the string */
#ifdef VM
	{
	    char * p;
	    for (p=command; *p; p++) {
		*p = FROMASCII(*p);
		if (*p == '\n') *p = ' ';
	    }
	}
#endif
	if (TRACE) printf("read string is `%s'\n", command);

	arg=strchr(command,' ');
	if (arg) {
	    *arg++ = 0;				/* Terminate command 	*/
	    arg = strip(arg);			/* Strip space 		*/
	    if (0==strcmp("GET", command)) {	/* Get a file 		*/

/* 	Remove host and any punctuation. (Could use HTParse to remove access too @)
*/      
		filename = arg;
		if (arg[0]=='/') {
		    if (arg[1]=='/') {
		        filename = strchr(arg+2, '/');	/* Skip //host/ */
			if (!filename) filename=arg+strlen(arg);
		    } else {
		        filename = arg+1;		/* Assume root: skip slash */
		    }
		}

		if (*filename) {		/* (else return test message) 	*/
		    keywords=strchr(filename, '?');
		    if (keywords) *keywords++=0;	/* Split into two */
#ifdef VM

/*	Formats supported by FIND are:
**
**	/FIND				Help for find general index
**	/FIND/				(same)
**	/FIND/?				(same)
**	/FIND/group.disk.ft.fn		Get a document from a disk- NOT INDEX
**	/FIND/grouplist?		Help for group index
**	/FIND/grouplist?keylist		Search a set of disks for keywords
**					where grouplist = group+group+group.. or void
**					keylist = key+key+key... (not void)
*/
		    if((
		    		(0==strncmp(filename,"FIND",4))
		    		|| (0==strncmp(filename,"find",4))
			) && (
		           (filename[4]==0)
			   || (filename[4]=='/')
			   || (filename[4]='?')
			)) {
		    
		        filename=filename+4;
			if (*filename=='/') filename++;	/* Skip first slash */
			 
			if (!*filename) {	 /* If no data at all,    */
			    if (!keywords)
			     keywords = filename; /* Respond as if just "?" given */			
			}
    
			if (keywords) {
			    char *p;
			    while((p=strchr(filename,'+'))!=0) *p=' ';/* Remove +s */
			    while((p=strchr(keywords,'+'))!=0) *p=' ';/* Remove +s */
			    
			    if (!*keywords) {	/* If no keywords    */
				write_ascii(soc, "<IsIndex><TITLE>");
				write_ascii(soc, filename);
				write_ascii(soc, " keyword index</TITLE>\n");
				if (*filename) {
				    write_ascii(soc, "This index covers groups: `");
				    write_ascii(soc, filename);
				    write_ascii(soc, "'");
				} else {
			    	    write_ascii(soc,
		"This is the general CERN public document index");
				}
				write_ascii(soc,
		".<P>You may use your browser's keyword search on this index.<P>\n");
				return 0;
			    }
    
			    strcpy(system_command,"EXEC NICFIND1 ");
			    strcat(system_command, keywords);
			    if (*filename) {
				strcat(system_command, " ( ");
				strcat(system_command, filename);
			    }
			    isIndex = 1;
			} else {
			    strcpy(system_command,"EXEC NICFOUN1 ");
			    strcat(system_command, filename);
			    isIndex = 0;
			}
			
		    }  /* if FIND */

/*	Formats supported by NEWS are:
**
**	/NEWS				General news
**	/NEWS/grouplist			News for given groups
**	/NEWS/grouplist?		All news for all given groups
**	/NEWS/grouplist?keylist		Search news for keywords
**					where grouplist = group+group+group.. or void
**					keylist = key+key+key... (can be void)
*/
		    else if((
		    		(0==strncmp(filename,"NEWS",4))
		    		|| (0==strncmp(filename,"news",4))
			    ) && (
				(filename[4]==0)
				|| (filename[4]=='/')
				|| (filename[4]='?')
			    )) {
		    
			isIndex = 1;
		        filename=filename+4;
			if (*filename=='/') filename++;		/* Skip first slash */
			 
			if (!*filename) {	 /* If no data at all,    */
			    if (!keywords)
			     keywords = filename; /* Respond as if just "?" given */			
			}
			
			if (!keywords) keywords = ""; /* "If nun, write none"-1066 */
			
			{
			    char *p;
			    while((p=strchr(filename,'+'))!=0) *p=' ';/* Remove +s */
			    while((p=strchr(keywords,'+'))!=0) *p=' ';/* Remove +s */
			    
			    strcpy(system_command,"EXEC NICFIND1 ");
			    if (keywords) strcat(system_command, keywords);
			    strcat(system_command, " ( NEWS ");
			    if (*filename) {
				strcat(system_command, "(");
				strcat(system_command, filename);
				strcat(system_command, ") ");
			    }
			}
			
		    } else { /* not FIND or NEWS */
			write_ascii(soc, "Bad syntax. No such document.\n");
			return 0;
		    }

/*	Execute system command and get the results
*/
		    lines = system(system_command);
		    if (TRACE) printf("Command `%s' returned %i lines.\n",
			     system_command, lines);
		    if (lines<=0) {
			write_ascii(soc,
			"\nSorry, the FIND server could not execute\n  `");
			write_ascii(soc, system_command);
			write_ascii(soc, "'\n\n");
			return 0;
		    }
		    
		    /*	Copy the file across: */
		    
		    if (isIndex) write_ascii(soc, "<IsIndex>\n");
		    for(;lines; lines--){		/* Speed necessary here */
			char *p;
			fgets(buffer, BUFFER_SIZE, stdin);
	    /*	    if (strcmp(buffer,"<END_OF_FILE>")==0) break;	*/
			for(p=buffer; *p; p++) *p = TOASCII(*p);
			write(soc, buffer, p-buffer);
		    }
		    return 0;
			


#else
		    fd = open(arg, O_RDONLY, 0 );	/* un*x open @@ */
		    if (fd<0) return fd;
		    status = read_file(soc, fd);
		    close(fd);
		    return 0;
#endif
		}
	    }	
	}

	write_ascii(soc, "<h1>FIND Server v1.03</h1><h2>Test response</h2>\n");
	write_ascii(soc, "\n\nThe (unrecognised) command used was `");
	write_ascii(soc, command);
	write_ascii(soc, "'.\n\n");
	
	if (TRACE) printf("Return test string written back'\n");
	return 0;		/* End of file - please close socket */
    } /* for */
    
} /* handle */
Пример #5
0
int main(int argc, char **argv)
{
	int  i, j, snapshot_number;	
	
	/* Read input and output files */
	i=1;
	if (argc==1) usage();
	while (i<argc)
	  {
      
	    if (!strcmp(argv[i],"-f"))
	      {
		i++;
		strcpy(filename,argv[i]);
		i++;
	      }
	    else if (*argv[i]!='-')
	      {
		strcpy(filename,argv[i]);
		i++;
	      }
	    else if (!strcmp(argv[i],"-i"))
	      {
		i++;
		strcpy(filename,argv[i]);
		i++;
	      }
	    else if (!strcmp(argv[i],"-use"))
	      {
		i++;
		use_cm=atoi(argv[i]);
		i++;
	      }
	    else if (!strcmp(argv[i],"-ind"))
	      {
		i++;
		use_ind = 1;
	      }
	    else if (!strcmp(argv[i],"-s"))
	      {		
		i++;
		StarMassThreshold = atof(argv[i]);
		i++;
	      }
	    else if (!strcmp(argv[i],"-sfid"))
	      {		
		i++;
		sfid = atoi(argv[i]);
		i++;
	      }
	    else if (!strcmp(argv[i],"-m"))
	      {		
		i++;
		TotalMassThreshold = atof(argv[i]);
		i++;
	      }
	    else usage();
	  }
	char snap_number_dum[4];
	sprintf(snap_number_dum, "%.*s", 3, &filename[ strlen(filename)-3]);
	snapshot_number = atoi( snap_number_dum );
	printf("num %d\n", snapshot_number);

	load_groups(snapshot_number);
	
	load_group_ids(snapshot_number);

	load_snapshot(filename, snapshot_number);
	
	write_ascii(snapshot_number);
	
	return 0;
}
Пример #6
0
static void do_decode(void)
{
	int rc = 0, in_fd, out_fd;
	size_t in_buf_len = 0;
	struct nljson_error error;
	bool decode_error = false;

	if (input_file_set)
		in_fd = open(input_file, O_RDONLY);
	else
		in_fd = 0;

	if (in_fd < 0)
		goto out;

	if (output_file_set)
		out_fd = open(output_file, O_WRONLY);
	else
		out_fd = 1;

	if (out_fd < 0)
		goto out;

	/**
	 * Main processing loop:
	 * Reads the input stream and decodes the data.
	 * Trailing input data (data not processed by the decoding function)
	 * is saved for the next iteration.
	 */
	for (;;) {
		ssize_t read_len, write_len;
		size_t consumed, produced;
		bool eof_reached = false;

		read_len = read(in_fd, in_buf + in_buf_len,
				sizeof(in_buf) - in_buf_len);
		if (read_len <= 0) {
			read_len = 0;
			eof_reached = true;
		}

		in_buf_len += read_len;

		while (in_buf_len > 0) {
			size_t i;

			rc = nljson_decode_nla(in_buf, out_buf,
					       sizeof(out_buf),
					       &consumed, &produced,
					       json_format_flags,
					       &error);

			if (rc) {
				/* We don't print the error here since the
				 * error could be caused by an incomplete
				 * JSON string and we could get more data
				 * in the next iteration.
				 */
				decode_error = true;
				break;
			}

			decode_error = false;

			if ((produced == 0) || (consumed == 0))
				break;

			if (ascii_output)
				write_len = write_ascii(out_fd, out_buf,
							produced);
			else
				write_len = write(out_fd, out_buf, produced);
			if ((size_t) write_len != produced)
				break;
			if (consumed > (size_t) in_buf_len) {
				fprintf(stderr, "Error: Consumed %u bytes "
					"out of %u", consumed, produced);
				break;
			}

			in_buf_len -= consumed;
			memmove(in_buf, in_buf + consumed, in_buf_len);

			/* Make sure in_buf begins with a '{', otherwise
			 * nljson_decode_nla will fail.
			 */
			for (i = 0; i < in_buf_len; i++) {
				if (in_buf[i] == '{')
					break;
			}

			if (i > 0) {
				in_buf_len -= i;
				memmove(in_buf, in_buf + i, in_buf_len);
			}
		}

		if (eof_reached)
			break;
	}

	if (decode_error)
		/* The last iteration was an error */
		fprintf(stderr, "Decoding error: %s\n", error.err_msg);
out:
	if (in_fd > 0)
		close(in_fd);
	if (out_fd > 1)
		close(out_fd);
}
Пример #7
0
static void
time_integration_loop_hubble(Forceinfo *fi, Nbodyinfo *nb)
{
    double zval; /* red shift at T=0 */
    double tmpzz;
    double t, t0, dt1, tpresent;
    double W, K, E0, E, Q;
    double cm[3], cmv[3];
    int step = 0;
    double tsnapout, timageout;

    t = 0.0;
    tpresent = 16.0; /* present time must be 16.0 */
    zval = 24.0;
    tmpzz = pow(1.0/(zval+1), 3.0/2.0);
    t0 = tmpzz/(1.0-tmpzz)*tpresent;
    fi->eps = (zval+1)*pow(t0/(tpresent+t0), 2.0/3.0)*eps0;
    dt1 = dt0;

    tsnapout = dtsnapout;
    timageout = dtimageout;

    PR(t0, f); PR(dt0, f); PRL(dt1, f);

    PR(tstart,f); PR(tpresent,f); PR(dt,f); PRL(dtsnapout,f); PRL(dtimageout,f);

    if (cputime_flag) {
	vtc_turnon_cputime();
    }
    vtc_init_cputime();
    vtc_print_cputime("initial vtc_get_force start at");

#if DIRECT /* direct sum */
    if (grape_flag) {
	vtc_set_scale(512.0, nb->m[0]);
	fi->calculator = GRAPE_FORCEONLY;
	vtc_get_force_direct(fi, nb);
#if CALCPOTENTIAL
        fi->calculator = GRAPE_POTENTIALONLY;
	vtc_get_force_direct(fi, nb);
	fi->calculator = GRAPE_FORCEONLY;
#endif
    }
    else {
	vtc_get_force_direct(fi, nb);
    }
#else /* tree */
    if (grape_flag) {
	fi->calculator = GRAPE_FORCEONLY;
	vtc_get_force_tree(fi, nb);
#if CALCPOTENTIAL
        fi->calculator = GRAPE_POTENTIALONLY;
        vtc_get_force_tree(fi, nb);
	fi->calculator = GRAPE_FORCEONLY;
#endif
    }
    else {
	vtc_get_force_tree(fi, nb);
    }
#endif /* direct/tree */
    vtc_print_cputime("initial vtc_get_force end at");
    fprintf(stderr, "ninteraction: %e list_len_avg: %6.5f nwalk: %d\n",
	    fi->ninteraction, (double)fi->ninteraction/nb->n, fi->nwalk);
    K = get_kinetic_energy(nb);
#if CALCPOTENTIAL
    W = get_potential_energy(nb);
    E = E0 = W+K;
    PR(E0, f); PR(W, f);
#endif
    PRL(K, f);
    plot_nbody(t, nb);

    /* calculate force at T=0 and quit */
    if (snapout_flag && dtsnapout == 0.0) {
	static int nout = 0;
	char fn[255];
	snapout_acc_flag = 1;
	sprintf(fn, snapoutfile, nout);
	PRL(fn, s);
	if (ionemo_flag) {
	    write_binary(fn, t, nb);
	}
	else if (usepob_flag) {
	    write_pob(fn, t, nb);
	}
	else {
	    write_ascii(fn, t, nb);
	}
	vtc_print_cputime("exit at");
	return;
    }

    while (t < tend) {
	if (fi->eps < eps) {
	    double eps1;
	    eps1 = (zval+1)*pow((t+t0)/(tpresent+t0), 2.0/3.0)*eps0;
	    fi->eps = (eps1 < eps ? eps1 : eps);
	}
	else {
	    fi->eps = eps;
	}
	if (dt1 < dt) {
	    dt1 = dt0*(t+t0)/t0;
	}
	else {
	    dt1 = dt;
	}
 	if (step%outlogstep == outlogstep - 1 && cputime_flag) {
	    vtc_turnon_cputime();
	}
	else {
	    vtc_turnoff_cputime();
	}
        push_velocity(0.5*dt1, nb);
        push_position(dt1, nb);
	vtc_init_cputime();
#if DIRECT /* direct sum */
	vtc_get_force_direct(fi, nb);
#else /* tree */
	vtc_get_force_tree(fi, nb);
#endif /* direct/tree */
	vtc_print_cputime("vtc_get_force end at");
        push_velocity(0.5*dt1, nb);
	vtc_print_cputime("integration end at");

	plot_nbody(t, nb);
 	if (step%outlogstep == outlogstep - 1) {
	    fprintf(stderr, "ninteraction: %e list_len_avg: %6.5f nwalk: %d\n",
		    fi->ninteraction, fi->ninteraction/nb->n, fi->nwalk);
	    K = get_kinetic_energy(nb);
#if CALCPOTENTIAL
	    if (grape_flag) {
		fi->calculator = GRAPE_POTENTIALONLY;
#if DIRECT /* direct sum */
		vtc_get_force_direct(fi, nb);
#else /* tree */
		vtc_get_force_tree(fi, nb);
#endif /* direct/tree */
		fi->calculator = GRAPE_FORCEONLY;
	    }
	    W = get_potential_energy(nb);
	    E = W+K;
	    Q = K/(K-E);
	    fprintf(stderr, "\nT= %f K= %f Q= %f E= %f Eerr= %f Eabserr= %f\n",
		    t, K, Q, E, (E0-E)/E0, E0-E);
#else
	    fprintf(stderr, "\nT= %f K= %f\n", t, K);
#endif
	    fprintf(stderr, "step: %d\n", step);
	    fprintf(stderr, "T: %f current eps: %f dt: %f\n",
		    t, fi->eps, dt1);
	    get_cmterms(nb, cm, cmv);
	    fprintf(stderr, "CM  %15.13e %15.13e %15.13e\n",
		    cm[0], cm[1], cm[2]);
	    fprintf(stderr, "CMV %15.13e %15.13e %15.13e\n",
		    cmv[0], cmv[1], cmv[2]);
 	}
	if (tsnapout < t && snapout_flag) {
	    static int nout = 0;
	    char fn[255];
	    char cmd[255];

	    sprintf(fn, snapoutfile, nout);
	    PRL(fn, s);
	    if (ionemo_flag) {
		write_binary(fn, t, nb);
	    }
	    else if (usepob_flag) {
		write_pob(fn, t, nb);
	    }
	    else {
		write_ascii(fn, t, nb);
	    }

	    if (command_exec_flag) {
		sprintf(cmd, "%s %s %03d", command_name, fn, nout);
		fprintf(stderr, "execute %s\n", cmd);
		system(cmd);
	    }
	    nout++;
	    PR(t, f); PRL(fn, s);
	    tsnapout += dtsnapout;
	}
	if (timageout < t && imageout_flag) {
	    static int nout = 0;
	    char fn[255];
	    char cmd[255];

	    sprintf(fn, snapoutfile, nout);
	    strcat(fn, ".gif");
	    PRL(fn, s);
	    vtc_plotstar(nb->x, nb->n, t, image_scale, fn);
	    nout++;
	    PR(t, f); PRL(fn, s);
	    timageout += dtimageout;
	}
	t += dt1;
	step++;
	vtc_print_cputime("exit at");
    } /* main loop */
}
Пример #8
0
static void
time_integration_loop(Forceinfo *fi, Nbodyinfo *nb)
{
    int i, nstep;
    int outsnapstep, outimagestep;
    double W, K, E0, E, Q;
    double cm[3], cmv[3];
    double t = tstart;

    nstep = (int)((tend-tstart)/dt+0.1);
    dt = (tend-tstart)/nstep;
    outsnapstep = (int) (dtsnapout/dt+0.1);
    outimagestep = (int) (dtimageout/dt+0.1);
    PR(tstart,f); PR(tend,f); PR(dt,f); PRL(dtsnapout,f); PRL(dtimageout,f);

    if (cputime_flag) {
	vtc_turnon_cputime();
    }
    vtc_init_cputime();
    vtc_print_cputime("initial vtc_get_force start at");

#if DIRECT /* direct sum */
    if (grape_flag) {
	vtc_set_scale(512.0, nb->m[0]);
#if MDGRAPE2
	fi->calculator = GRAPE_FORCEONLY;
#else
	fi->calculator = GRAPE;
#endif /* MDGRAPE2 */
	vtc_get_force_direct(fi, nb);
#if CALCPOTENTIAL && MDGRAPE2
        fi->calculator = GRAPE_POTENTIALONLY;
        vtc_get_force_direct(fi, nb);
	fi->calculator = GRAPE_FORCEONLY;
#endif /* CALCPOTENTIAL && MDGRAPE2 */
    }
    else {
#if CALCPOTENTIAL
        fi->calculator = HOST;
#endif /* CALCPOTENTIAL */
	vtc_get_force_direct(fi, nb);
    }
#else /* tree */
    if (grape_flag) {
#if NOFORCE
	fi->calculator = NOCALCULATOR;
#elif MDGRAPE2
	fi->calculator = GRAPE_FORCEONLY;
#else
	fi->calculator = GRAPE;
#endif /* NOFORCE */
	vtc_get_force_tree(fi, nb);
#if CALCPOTENTIAL && MDGRAPE2
        fi->calculator = GRAPE_POTENTIALONLY;
        vtc_get_force_tree(fi, nb);
	fi->calculator = GRAPE_FORCEONLY;
#endif /* CALCPOTENTIAL && MDGRAPE2 */
    }
    else {
#if CALCPOTENTIAL
        fi->calculator = HOST;
#endif /* CALCPOTENTIAL */
	vtc_get_force_tree(fi, nb);
    }
#endif
    vtc_print_cputime("initial vtc_get_force end at");
    fprintf(stderr, "ninteraction: %e list_len_avg: %6.5f nwalk: %d\n",
	    fi->ninteraction, (double)fi->ninteraction/nb->n, fi->nwalk);
    K = get_kinetic_energy(nb);
#if CALCPOTENTIAL
    W = get_potential_energy(nb);
    E = E0 = W+K;
    PR(E0, 20.17f); PR(W, 20.17f);
#endif
    PRL(K, f);
    plot_nbody(t, nb);

    /* calculate force at T=0 and quit */
    if (snapout_flag && dtsnapout == 0.0) {
	static int nout = 0;
	char fn[255];
	snapout_acc_flag = 1;
	sprintf(fn, snapoutfile, nout);
	PRL(fn, s);
	if (ionemo_flag) {
	    write_binary(fn, t, nb);
	}
	else if (usepob_flag) {
	    write_pob(fn, t, nb);
	}
	else {
	    write_ascii(fn, t, nb);
	}
	vtc_print_cputime("exit at");
#if USE_GM_API
	fprintf(stderr, "will m2_gm_finalize...\n");
	m2_gm_finalize();
	fprintf(stderr, "done m2_gm_finalize.\n");
#endif /* USE_GM_API */
    }
    for (i = 0; i < nstep; i++) {
 	if (i%outlogstep == outlogstep - 1 && cputime_flag) {
	    vtc_turnon_cputime();
	}
	else {
	    vtc_turnoff_cputime();
	}

	fprintf(stderr, "step %d\n", i);
        push_velocity(0.5*dt, nb);
        push_position(dt, nb);
	t = tstart+(i+1)*dt;
	vtc_init_cputime();
#if DIRECT /* direct sum */
	vtc_get_force_direct(fi, nb);
#else /* tree */
	vtc_get_force_tree(fi, nb);
#endif
	vtc_print_cputime("vtc_get_force end at");
        push_velocity(0.5*dt, nb);
	vtc_print_cputime("integration end at");

	plot_nbody(t, nb);
 	if (i%outlogstep == outlogstep - 1) {
	    fprintf(stderr, "ninteraction: %e list_len_avg: %6.5f nwalk: %d\n",
		    fi->ninteraction, fi->ninteraction/nb->n, fi->nwalk);
	    K = get_kinetic_energy(nb);
#if CALCPOTENTIAL
#if MDGRAPE2
	    if (grape_flag) {
		fi->calculator = GRAPE_POTENTIALONLY;
#if DIRECT /* direct sum */
		vtc_get_force_direct(fi, nb);
#else /* tree */
		vtc_get_force_tree(fi, nb);
#endif /* direct/tree */
		fi->calculator = GRAPE_FORCEONLY;
	    }
#endif /* MDGRAPE2 */
	    W = get_potential_energy(nb);
	    E = W+K;
	    Q = K/(K-E);
	    fprintf(stderr, "\nT= %f K= %20.17f Q= %20.17f E= %20.17f Eerr= %20.17f Eabserr= %20.17f\n",
		    t, K, Q, E, (E0-E)/E0, E0-E);
#else /* CALCPOTENTIAL */
	    fprintf(stderr, "\nT= %f K= %20.17f\n", t, K);
#endif /* CALCPOTENTIAL */
	    fprintf(stderr, "step: %d\n", i);
	    get_cmterms(nb, cm, cmv);
	    fprintf(stderr, "CM  %15.13e %15.13e %15.13e\n",
		    cm[0], cm[1], cm[2]);
	    fprintf(stderr, "CMV %15.13e %15.13e %15.13e\n",
		    cmv[0], cmv[1], cmv[2]);
 	}
	if (i%outsnapstep == outsnapstep - 1 && snapout_flag) {
	    static int nout = 0;
	    char fn[255];
	    char cmd[255];

	    sprintf(fn, snapoutfile, nout);
	    PRL(fn, s);
	    if (ionemo_flag) {
		write_binary(fn, t, nb);
	    }
	    else if (usepob_flag) {
		write_pob(fn, t, nb);
	    }
	    else {
		write_ascii(fn, t, nb);
	    }

	    if (command_exec_flag) {
		sprintf(cmd, "%s %s %03d", command_name, fn, nout);
		fprintf(stderr, "execute %s\n", cmd);
		system(cmd);
	    }
	    nout++;
	    PR(t, f); PRL(fn, s);
	}
	if (i%outimagestep == outimagestep - 1 && imageout_flag) {
	    static int nout = 0;
	    char fn[255];
	    char cmd[255];
	    char msg[255];
	    double center[2];

	    sprintf(fn, snapoutfile, nout);
	    strcat(fn, ".gif");
	    PRL(fn, s);

	    sprintf(msg, "t: %5.3f", t);
	    center[0] = 0.0;
	    center[1] = 0.0;
	    // vtc_plotstar(fn, nb, msg, image_scale, center, 1e10, NULL, NULL);
	    // vtc_plotstar(nb->x, nb->m, nb->n, t, image_scale, fn);
	    nout++;
	    PR(t, f); PRL(fn, s);
	}
	vtc_print_cputime("exit at");
    } /* i loop */
}