Example #1
0
EXPORT void prompt_for_gravity(
	INIT_DATA	*init,
	INIT_PHYSICS	*ip)
{
	RECT_GRID	*gr = &Comp_grid(init);
	float		*L, *U;
	char		s[Gets_BUF_SIZE];
	float		**m;
	int		c, len;
	static char	dname[3][2] = {"x", "y", "z"};
	float		*g;
	GRAVITY		*grav_data;
	int		i, dim;

	gravity_data(init) = NULL;
	screen("The following choices are available for a gravitational "
	       "acceleration\n"
	       "\tNo gravity (N or default)\n"
	       "\tConstant gravity (C or Y)\n"
	       "\tTime dependent gravity (T)\n"
	       "\tAstrophysical (central force) gravity (A)\n"
	       "\tGeneralized Astrophysical gravity (G)\n"
	       "\tRadial gravity with constant magnitude (R)\n");
	screen("Enter choice: ");
	(void) Gets(s);

	scalar(&grav_data,sizeof(GRAVITY));
	gravity_data(init) = grav_data;

	dim = gr->dim;
	grav_data->dim = dim;
	switch (s[0])
	{
	case 'N':
	case 'n':
	case '\0':
	    grav_data->type = NO_GRAVITY;
	    return;
	case 'C':
	case 'c':
	case 'Y': /*For historical compatibility of input files*/
	case 'y': /*For historical compatibility of input files*/
	    grav_data->type = CONSTANT_GRAVITY;
	    g = grav_data->g;
	    g[0] = g[1] = g[2] = 0.0;
	    for (i = 0; i < dim; ++i)
	    {
	        screen("\tEnter %s component of gravity (dflt = 0): ",dname[i]);
	        (void) Gets(s);
	        if (s[0] != '\0')
	    	    (void) sscan_float(s,g+i);
	    }
	    return;
	case 'T':
	case 't':
	    screen("Gravity data consists of an array of uni_arrays (time, g)\n");
	    screen("This data can be entered directly or input from a file\n");
	    screen("Enter either a filename or the number of data points\n");
	    screen("Enter filename or integer: ");
	    (void) Gets(s);
	    if (s[0] == '\0')
	    {
	        grav_data->type = NO_GRAVITY;
	        return;
	    }
	    grav_data->type = TIME_DEPENDENT_GRAVITY;
	    /*Was an integer input?*/
	    len = (int) strlen(s);
	    for (i = 0; i < len; ++i)
	    {
		c = s[i];
		if (!isdigit(c))
		    break;
	    }
	    if (i == len)
	    {
		(void) sscanf(s,"%d",&grav_data->num_time_points);
		bi_array(&m,grav_data->num_time_points,dim+1,FLOAT);
		grav_data->g_of_t = m;
		screen("Enter %d data points consisting of a monotonically "
		       "increasing time value\n",grav_data->num_time_points);
		screen("\tfollowed by a %d vector of gravity "
		       "values for that time\n",dim);
		read_gravity_data(stdin,dim,m,grav_data->num_time_points);
	    }
	    else
	    {
	        FILE	*file = fopen(s,"r");
		int	nf;
		float	x;
		if (file == NULL)
		{
		    screen("ERROR in prompt_for_gravity(), can't open %s",s);
		    clean_up(ERROR);
		}
		/*count entries in file*/
		for (nf = 0; ((c = getc(file)) != EOF); ++nf)
		{
		    (void)ungetc(c,file);
		    if (fscan_float(file,&x) != 1)
			break;
		}
		if ((nf%(dim+1)) != 0)
		{
		    screen("ERROR in prompt_for_gravity(), invalid file\n");
		    clean_up(ERROR);
		}
		grav_data->num_time_points = nf/(dim+1);
		rewind(file);
		bi_array(&m,grav_data->num_time_points,dim+1,FLOAT);
		grav_data->g_of_t = m;
		read_gravity_data(file,dim,m,grav_data->num_time_points);
	    }
	    /*Check for monotonicity of time values*/
	    for (i = 1; i < grav_data->num_time_points; ++i)
	    {
		if (m[i][0] <= m[i-1][0])
		{
		    screen("ERROR in prompt_for_gravity(), "
			   "invalid time values\n");
		    clean_up(ERROR);
		}
	    }
	    return;
	case 'A':
	case 'a':
	    grav_data->type = ASTROPHYSICAL_GRAVITY;
	    grav_data->G = 0.0;
	    grav_data->M = 0.0;
	    L = gr->GL;
	    U = gr->GU;
	    for (i = 0; i < dim; ++i)
		grav_data->center[i] = 0.5*(L[i]+U[i]);
	    screen("Enter the coordinates of the gravity center (dflt =");
	    for (i = 0; i < dim; ++i)
		screen(" %g",grav_data->center[i]);
	    screen("): ");
	    (void) Gets(s);
	    if (s[0] != '\0')
	    {
		float	*cen = grav_data->center;
#if defined(float)
		static const char *fmt = "%lf %lf %lf";
#else /* defined(float) */
		static const char *fmt = "%f %f %f";
#endif /* defined(float) */
		if (sscanf(s,fmt,cen,cen+1,cen+2) != dim)
		{
		    screen("ERROR in prompt_for_gravity(), "
			   "invalid coordinate for gravity center\n");
		    clean_up(ERROR);
		}
	    }
	    screen("Enter the gravitational constant (dflt = %g): ",
		   grav_data->G);
	    (void) Gets(s);
	    if (s[0] != '\0')
		sscan_float(s,&grav_data->G);
	    screen("Enter the mass of the gravity center (dflt = %g): ",
		   grav_data->M);
	    (void) Gets(s);
	    if (s[0] != '\0')
		sscan_float(s,&grav_data->M);
	    return;
	case 'R':
	case 'r':
	    grav_data->type = RADIAL_GRAVITY;
	    grav_data->G = 0.0;
	    grav_data->M = 0.0;
	    L = gr->GL;
	    U = gr->GU;
	    for (i = 0; i < dim; ++i)
		grav_data->center[i] = 0.5*(L[i]+U[i]);
	    screen("Enter the coordinates of the gravity center (dflt =");
	    for (i = 0; i < dim; ++i)
		screen(" %g",grav_data->center[i]);
	    screen("): ");
	    (void) Gets(s);
	    if (s[0] != '\0')
	    {
		float	*cen = grav_data->center;
#if defined(float)
		static const char *fmt = "%lf %lf %lf";
#else /* defined(float) */
		static const char *fmt = "%f %f %f";
#endif /* defined(float) */
		if (sscanf(s,fmt,cen,cen+1,cen+2) != dim)
		{
		    screen("ERROR in prompt_for_gravity(), "
			   "invalid coordinate for gravity center\n");
		    clean_up(ERROR);
		}
	    }
	    screen("Enter the magnitude of the gravitational acceleration "
		   "(dflt = %g): ",grav_data->G);
	    (void) Gets(s);
	    if (s[0] != '\0')
		sscan_float(s,&grav_data->G);
	    return;
	case 'G':
	case 'g':
	    grav_data->type = GENERALIZED_ASTROPHYSICAL_GRAVITY;
            grav_data->roots = &ip->root;
            grav_data->nroots = 1;
	    grav_data->G = 0.0;
	    grav_data->M = 0.0;
	    grav_data->N = 100;
	    for (i = 0; i < dim; ++i)
		grav_data->center[i] = 0.0;
	    screen("Enter the coordinates of the gravity center (dflt =");
	    for (i = 0; i < dim; ++i)
		screen(" %g",grav_data->center[i]);
	    screen("): ");
	    (void) Gets(s);
	    if (s[0] != '\0')
	    {
		float	*cen = grav_data->center;
#if defined(float)
		static const char *fmt = "%lf %lf %lf";
#else /* defined(float) */
		static const char *fmt = "%f %f %f";
#endif /* defined(float) */
		if (sscanf(s,fmt,cen,cen+1,cen+2) != dim)
		{
		    screen("ERROR in prompt_for_gravity(), "
			   "invalid coordinate for gravity center\n");
		    clean_up(ERROR);
		}
	    }
	    screen("Enter the gravitational constant (dflt = %g): ",
		   grav_data->G);
	    (void) Gets(s);
	    if (s[0] != '\0')
		sscan_float(s,&grav_data->G);

            for(i = 0; i < dim; ++i)
            {
                grav_data->GL[i] = gr->GL[i];
                grav_data->GU[i] = gr->GU[i];
                grav_data->gmax[i] = gr->gmax[i];
            }

	    screen("Enter the number of rings the whole domain"
		   "should be divided into (dflt = %d): ", grav_data->N);
	    (void) Gets(s);
	    if (s[0] != '\0')
	    	(void) sscanf(s,"%d",&grav_data->N);
	    //grav_data->Mp = (float*)malloc(grav_data->N*sizeof(float));
	    return;
	default:
	    screen("ERROR in prompt_for_gravity(), "
		   "invalid choice %s\n",s);
	    clean_up(ERROR);
	}
}		/*end prompt_for_gravity*/
Example #2
0
EXPORT	void init_topological_grid(
	RECT_GRID *top_grid,
	const RECT_GRID *r_grid)
{
	char       *c;
	const char *dimname;
	static const char *blanks = " \t";
	const char *fmt1,*fmt2,*fmt3;
	char	   *message;
	double	   cor_fac;
	int	   len;
	int	   i, dim = r_grid->dim;
	int	   n_ints, n_floats, gmax[3];
	static const char *dimnames[] = {"one", "two", "three"};
	char    s[Gets_BUF_SIZE];

	dimname = dimnames[dim-1];
	copy_rect_grid(top_grid,r_grid);
	(void) adjust_top_grid_for_square(top_grid,r_grid);
	for (i = 0; i < dim; ++i)
		gmax[i] = top_grid->gmax[i];

	fmt1 =
		"The topological grid is a grid used for the construction of "
		"the tracked front topology. "
		"It is constrained to be a square grid. "
		"You specify the grid in one of two ways. "
		"If you enter a single number,  it will be used as a "
		"coarseness factor for the topological grid relative to the "
		"computational grid entered above. "
		"In this case the length of a topological grid block cell "
		"side is the nearest allowable multiple of the shortest side "
		"of the computational grid by the coarseness factor. ";
	fmt2 =
		"Otherwise the code will read the %s integers input for the "
		"number of grid cells in each coordinate direction of the "
		"topological grid. "
		"If your input values do not yield a square grid they will "
		"be corrected to produce a square grid. "
		"This correction will attempt to produce values close to those "
		"input, but if the input values are highly rectangular, "
		"the resulting values may differ considerably from those "
		"entered. ";
	fmt3 =
		"The default for this input option is the nearest "
		"square grid that matches the computational grid. "
		"Generally the topological grid is coarser than the "
		"computational grid. "
		"Larger coarseness factors yield coarser grids,  a value one "
		"gives the nearest square grid to the computational grid.\n";

	len = 500;
	uni_array(&message,len,CHAR);
	(void) sprintf(message,fmt1,dimname);
	screen_print_long_string(message);
	(void) sprintf(message,fmt2,dimname);
	screen_print_long_string(message);
	(void) sprintf(message,fmt3,dimname);
	screen_print_long_string(message);
	free(message);
	message = NULL;
	if (dim == 1)
	{
		screen_print_long_string(
			"\tBe sure to use a decimal point to "
			"indicate a floating point number "
			"if you choose to input a coarseness factor.\n");
	}
	screen("Enter your choice (cor_fac, %s integer%s, or return)\n",
		dimname,(dim > 1) ? "s" : "");
	screen("\t(defaults are");
	for (i = 0; i < dim; ++i) screen(" %d",gmax[i]);
	screen("): ");
	(void) Gets(s);
	if (s[0] != '\0')
	{
	    n_floats = sscan_float(s,&cor_fac);
	    if (dim == 1)
	    {
	        /*
	        *  To distinguish whether the input is a
	        *  coarseness factor search for a "." in s
	        */
	        if (strstr(s,".") == NULL)
	        {
	            n_floats = 0;
	            cor_fac = ERROR_FLOAT;
	        }
	    }
	    for (n_ints = 0, c = strtok(s,blanks); c != NULL;
	                     c = strtok(NULL,blanks), ++n_ints)
	    {
	        (void) sscanf(c,"%d",gmax+n_ints%dim);
	    }
	    if (n_ints == 2*dim)
	    {
	        /* There is a secret undocumemted option here.
	        *  Enter the topological grid sizes twice and the
	        *  code will use these values whether they give a square grid
	        *  or not.  This makes nearest_interface_point()
	        *  invalid,  but you can get what you ask for.
	        */
	        set_rect_grid(top_grid->L,top_grid->U,top_grid->L,top_grid->U,
	                      NOBUF,NOBUF,gmax,dim,&r_grid->Remap,top_grid);
	    }
	    else if ((n_ints == 1) && (n_floats > 0))
	    {
	        int imin;
	        imin = 0;
	        for (i = 1; i < dim; ++i)
	            if (r_grid->h[i] < r_grid->h[imin]) imin = i;

	        top_grid->gmax[imin] = irint(r_grid->gmax[imin]/cor_fac);
	        if (top_grid->gmax[imin] <= 0) top_grid->gmax[imin] = 1;
	        top_grid->h[imin] = (top_grid->U[imin] - top_grid->L[imin]) /
	                    top_grid->gmax[imin];
	        for (i = 0; i < dim; ++i)
	        {
	            double   tmp_gmax;
	            if (i == imin) continue;
	            tmp_gmax = (top_grid->U[i] - top_grid->L[i]) /
	                    top_grid->h[imin];
	            top_grid->gmax[i] = (int)(tmp_gmax);
	        }
	        (void) adjust_top_grid_for_square(top_grid,r_grid);
	        set_rect_grid(top_grid->L,top_grid->U,top_grid->L,top_grid->U,
	            NOBUF,NOBUF,top_grid->gmax,dim,&r_grid->Remap,top_grid);
	    }
	    else if (n_ints == dim)
	    {
	        for (i = 0; i < dim; ++i)
	            top_grid->gmax[i] = gmax[i];
	        (void) adjust_top_grid_for_square(top_grid,r_grid);
	        set_rect_grid(top_grid->L,top_grid->U,top_grid->L,top_grid->U,
	            NOBUF,NOBUF,top_grid->gmax,dim,&r_grid->Remap,top_grid);
	    }
	    else
	    {
	        screen("ERROR in init_topological_grid(), "
	               "invalid input of topogical grid mesh\n");
	        clean_up(ERROR);
	    }
	}
	screen("The topological mesh used is ");
	for (i = 0; i < dim; ++i) screen(" %d",top_grid->gmax[i]);
	screen("\n\n");
}		/*end init_topological_grid*/