Beispiel #1
0
LOCAL void g_fprint_raw_state(
	FILE		*file,
	Locstate	state,
	int		dim)
{
	int		i;
	static	char	mname[3][3] = { "mx", "my", "mz"};

	(void) fprintf(file,"state %p\n",state);
	//(void) fprintf(file,"\t%-7s = %"FFMT" %-7s = %"FFMT"\n\t","density",
	//	            Dens(state),"energy",Energy(state));
	(void) fprintf(file,"\t%-7s = %22.16g %-7s = %22.16g\n\t","density",
		            Dens(state),"energy",Energy(state));
	for (i = 0; i < dim; i++)
	    (void) fprintf(file,"%-7s = %"FFMT" ",mname[i],Mom(state)[i]);
	(void) fprintf(file,"\n");
	(void) fprintf(file,"\ttype = %u, failed = %u\n",
	                    state_type(state),material_failure(state));
	if (debugging("prt_params"))
	    fprint_Gas_param(file,Params(state));
	else
	    (void) fprintf(file,"Gas_param = %llu\n",
		                gas_param_number(Params(state)));
	if (debugging("local_gamma"))
	{
	    (void) fprintf(file,"Local gamma set: %s\n",
			   Local_gamma_set(state) ? "YES" : "NO");
	    if (Local_gamma_set(state))
		(void) fprintf(file,"Local gamma = %"FFMT"\n",
			       Local_gamma(state));
	}
}		/*end g_fprint_raw_state*/
Beispiel #2
0
nemo_main()
{
  stream instr;
  real   tsnap, x, y, v, d;
  int    i, nbody, bits, iy, ny, nout;
  Body *btab = NULL, *bp;
  Grid g;
  real yrange[MAXY], sumd[MAXY], sumvd[MAXY], sumxd[MAXY];
  bool Qmass = getbparam("mass");
  
  instr = stropen(getparam("in"), "r");           /* open input file */
  ny = nemoinpr(getparam("y"),yrange,MAXY);
  if (ny<2) error("yrange syntax error or not enuf slices");
#if 0  
  inia_grid(&g, ny, yrange);
#else
  inil_grid(&g, ny-1, yrange[0], yrange[ny-1]);
#endif

  get_history(instr);			    /* accumulate data history */
  for(;;) {				 	 /* loop for all times */
    get_history(instr);                         /* for paranoidici */
    if (!get_tag_ok(instr, SnapShotTag))          /* check if done */
      break;
    get_snap(instr, &btab, &nbody, &tsnap, &bits);      /* get one */
    if ((bits & PhaseSpaceBit) == 0)
      continue;     /* if no positions -  skip */
    
    for (i=0; i<ny; i++)
      sumd[i] = sumxd[i] = sumvd[i] = 0.0;

    for (bp = btab; bp < btab+nbody; bp++) {    /* loop all bodies */
      y = Pos(bp)[1];
      iy = index_grid(&g, y);
      if (iy < 0) continue;
      d = Qmass ? Mass(bp) : Dens(bp);
      x = Pos(bp)[0];
      v = Vel(bp)[1];
      sumd[iy]  += d;
      sumvd[iy] += v*d;
      sumxd[iy] += x*d;
    }
    break; /* for now just first snapshot */
  }
  nout = 0;
  for (i=0; i<ny-1; i++) {
    if (sumd[i] > 0.0) {
      nout++;
      printf("%g %g %g %g\n",value_grid(&g, (real)i+0.5), 
	     sumxd[i]/sumd[i], sumvd[i]/sumd[i], sumd[i]);
    }
  }
  if (nout==0)
    warning("No densities found in slices %s",getparam("y"));
} /* nemo_main() */
Beispiel #3
0
LOCAL	Locstate	load_tmpst(
	float    rho,
	float    e,
	Locstate state)
{
	static  Locstate tmpst = NULL;
	if (tmpst == NULL)
	    g_alloc_state(&tmpst,Params(state)->sizest);
	Set_params(tmpst,state);
	Dens(tmpst) = rho;
	Energy(tmpst) = e;
	set_type_of_state(tmpst,EGAS_STATE);
	return tmpst;
}		/*load_tmpst*/
Beispiel #4
0
LOCAL void g_fprint_raw_Estate(
	FILE		*file,
	Locstate	state,
	int		dim)
{
	int		i;
	static	char	vname[3][3] = { "vx", "vy", "vz"};

	(void) fprintf(file,"\tdensity = %"FFMT" energy = %"FFMT" ",
		            Dens(state),Energy(state));
	for (i = 0; i < dim; i++)
	    (void) fprintf(file,"%-8s = %"FFMT" ",vname[i],Vel(state)[i]);
	if (debugging("prt_params"))
	    fprint_Gas_param(file,Params(state));
	else
	    (void) fprintf(file,"Gas_param = %llu\n",
		                gas_param_number(Params(state)));

}		/*end g_fprint_raw_Estate*/
Beispiel #5
0
EXPORT	void	get_state_rt_kh_perturbed(
	float		*coords,
	Locstate	s,
	COMP_TYPE	*ct,
	HYPER_SURF	*hs,
	INTERFACE	*intfc,
	INIT_DATA	*init,
	int             stype)
{
	int		prob_type = ct->type;

	debug_print("init_states","Entered get_state_rt_kh_perturbed()\n");
	if ((prob_type != RT_PERTURBED) && (prob_type != KH_PERTURBED))
	{
	    screen("ERROR in get_state_rt_kh_perturbed(), "
	           "inconsistent comp_type->type\n");
	    clean_up(ERROR);
	}

	if (prob_type == RT_PERTURBED)
	{
	    POINTER		extra = ct->extra;
	    ct->extra = (POINTER) Rt_perturbed(ct)->rt_kh;
	    get_state_rt_kh(coords,s,ct,hs,intfc,init,TGAS_STATE);
	    ct->extra = extra;
	    rt_add_to_state(coords,s,ct,init);
	}
	else if (prob_type == KH_PERTURBED)
	    kh_add_to_state(coords, s, ct);

	if (Dens(s) < 0)
	{
	    int	dim = ct->params->dim;

	    screen("\nERROR in get_state_rt_kh_perturbed(), ");
	    print_general_vector("At point ",coords,dim,"");
	    screen(", the density of the state is less than 0.\n");
	    clean_up(ERROR);
	}
	set_state(s,stype,s);
}		/*end get_state_rt_kh_perturbed*/
Beispiel #6
0
EXPORT	 void g_print_internal_energy(
	const char	*mesg,
	float		**ucon,
	Vec_Muscl	*vmuscl,
	int		start,
	int		end)
{
	int		i, j, dim = vmuscl->dim;
	float		int_e, ke;
	float		E, m[MAXD], rho;
	Locstate	*state = vmuscl->vst->state + vmuscl->offset;
	static Locstate st = NULL;

	if (st == NULL)
	{
	    g_alloc_state(&st,vmuscl->sizest);
	}

	(void) printf("%s\n",mesg);
	(void) printf("%-4s %-14s %-14s\n","n","Int_energy","Pressure");
	for (j = start; j < end; ++j)
	{
	    Dens(st) = rho = ucon[0][j];
	    Energy(st) = E = ucon[1][j];
	    ke = 0.0;
	    for (i = 0; i < dim; ++i)
	    {
	    	Mom(st)[i] = m[i] = ucon[2+i][j];
	    	ke += 0.5*sqr(m[i])/rho;
	    }
	    Set_params(st,state[j]);
	    set_type_of_state(st,GAS_STATE);
	    reset_gamma(st);
	    int_e = (E - ke)/rho;
	    (void) printf("%-4d %-14g %-14g",j,int_e,pressure(st));
	    if (int_e < 0.0)
	    	(void) printf("\tNEGATIVE INTERNAL ENERGY\n");
	    else
	    	(void) printf("\n");
	}
}		/*end g_print_internal_energy*/
Beispiel #7
0
/*ARGSUSED*/
LOCAL	void	get_state_rt_kh(
	float		*coords,
	Locstate	state,
	COMP_TYPE	*ct,
	HYPER_SURF	*hs,
	INTERFACE	*intfc,
	INIT_DATA	*init,
	int	        stype)
{
	int		    dim = ct->params->dim;
	STRATIFICATION_TYPE s_type = Rt_kh(ct)->stratification_type;
	float		    *ref_c = Rt_kh(ct)->ref_coords;
	Locstate	    ref_st = Rt_kh(ct)->ref_state;
	float		    z, z_r, g_z;
	const float	    *grav;

	debug_print("init_states","Entered get_state_rt_kh()\n");
	z = coords[dim-1]; 
	z_r = ref_c[dim-1];
	grav = gravity(coords,initial_time(init));
	g_z = grav[dim-1];
	get_state_in_stratified_region(s_type,state,z-z_r,g_z,ref_st);
	if (Dens(state) < 0)
	{
	    screen("ERROR in get_state_rt_kh().\n");
	    fprint_general_vector(stderr,"At point ",coords,dim,"");
	    print_general_vector("At point ",coords,dim,"");
	    screen(", the density of the state is less than 0.\n");
	    clean_up(ERROR);
	}
	if (Press(state) < 0.0)
	{
	    (void) printf("WARNING in get_state_rt_kh().\n");
	    print_general_vector("At point ",coords,dim,"");
	    (void) printf(", the pressure of the state is less than 0.\n");
	}
	set_state(state,stype,state);
}		/*end get_state_rt_kh*/
Beispiel #8
0
LOCAL	void	rt_add_to_state(
	float		*coords,
	Locstate	state, /* assumed to be TGAS_STATE */
	COMP_TYPE	*ct,
	INIT_DATA	*init)
{
#if defined(float)
	static const float ACC = 1.0e-14;		/*TOLERANCE*/
#else /* defined(float) */
	static const float ACC = 1.0e-7;		/*TOLERANCE*/
#endif /* defined(float) */

	int		i, j, k0, k1, dim, layer_label, num_modes, nstep;
	float		rho, csq, rho_prime, a_z, b_z, k_dot_r, sig, phase;
	float		tmp, ub, lb, z0, z1, a0, a1, b0, b1, z, h_z, g_z;
	const float	*grav;
	_RT_PERTURBED	*rtp = Rt_perturbed(ct);
	NORMAL_MODE	*n_m;

	dim = ct->params->dim;
	layer_label = rtp->layer_label;
	nstep = rtp->lin_pert_intvl;
	num_modes = rtp->num_modes;

	if (num_modes <= 0)	return;

	z0 = lb = get_surf_height(coords, rtp->lower_surf);
	z1 = ub = get_surf_height(coords, rtp->upper_surf);
	h_z = (ub-lb)/nstep;
	z = coords[dim-1];
	grav = gravity(coords,initial_time(init));
	g_z = grav[dim-1];

	/* find out which interval z belongs */
	if (ub < lb)
	{
	    screen("\nERROR in rt_add_to_state(), ");
	    screen("Interfaces are already tangled.\n");
	    (void) printf("ub = %g, lb = %g\n",ub,lb);
	    print_interface(current_interface());
	    clean_up(ERROR);
	}
	if (z >= ub)
	    k0 = k1 = nstep;
	else if (z <= lb)
	    k0 = k1 = 0;
	else
	{
	    k0 = 0,		k1 = nstep;
	    for (;;)
	    {
	    	tmp = (z0+z1)/2.0;
	    	if (z >= tmp)
	    	    k0 = (k0+k1)/2, 	z0 = tmp;
	    	else
	    	    k1 = (k0+k1)/2, 	z1 = tmp;
	    	if (k1-k0 == 1)	break;
	    }
	}

	z0 = lb+k0*h_z;	
	z1 = lb+k1*h_z;	
	rho = Dens(state);
	csq = sound_speed_squared(state);
	rho_prime = get_rho_prime(state,ct,g_z);
	/* sum over all the normal modes */
	for (i = 0; i < num_modes; ++i)
	{
	    n_m = rtp->normal_mode[i];
	    if (k0 == k1)
	    {
	    	a_z = n_m->a[layer_label][k1];
	    	b_z = n_m->b[layer_label][k1];
	    }
	    else
	    {
	    	a0 = n_m->a[layer_label][k0];
	    	a1 = n_m->a[layer_label][k1];
	    	a_z = ((a1-a0)*z+(a0*z1-a1*z0))/h_z;
	    	b0 = n_m->b[layer_label][k0];
	    	b1 = n_m->b[layer_label][k1];
	    	b_z = ((b1-b0)*z+(b0*z1-b1*z0))/h_z;
	    }
	    if ((fabs(a_z) < ACC) && (fabs(b_z) < ACC))	continue;

	    sig = n_m->sigma_r;
	    phase = n_m->phase;
	    k_dot_r = 0.0;
	    for (j = 0; j <= dim-2; ++j)
	    	k_dot_r += n_m->wv_num[j]*coords[j];
	    phase += k_dot_r;
	    Dens(state) += ((g_z*rho/csq-rho_prime)*a_z+b_z/csq)/sig*sin(phase);
	    Press(state) += b_z/sig*sin(phase);
	    Vel(state)[dim-1] += a_z*sin(phase);
	    set_type_of_state(state,TGAS_STATE);
	    phase += 3.0*PI/2;
	    for (j = 0; j <= dim-2; ++j)
	        Vel(state)[j] += sin(phase)*n_m->wv_num[j]*b_z/(rho*sig*sig);
            reset_gamma(state);
	}
}		/*end rt_add_to_state*/
Beispiel #9
0
EXPORT	void fprint_gas_data(
	FILE		*file,
	Locstate	state)
{
	(void) fprintf(file,"State information for the ");
	if (state == NULL)
	{
	    (void) fprintf(file,"NULL state 0x%p\n\n",(POINTER)state);
	    return;
	}
	if (is_obstacle_state(state)) 
	{
	    (void) fprintf(file,"OBSTACLE state 0x%p\n\n",(POINTER)state);
	    return;
	}
	(void) fprintf(file,"state 0x%p\n",(POINTER)state);
	(void) fprintf(file,"\tState Data ");
	if (is_binary_output() == YES)
	{
	    uint64_t prms;
	    float    *x;
	    int      stype = state_type(state);
	    int      failed = material_failure(state);

	    (void) fprintf(file,"\f%c",(char)Params(state)->sizest);
	    x = &Dens(state);
	    (void) fwrite((const void *)x,FLOAT,2+SMAXD,file);
	    prms = gas_param_number(Params(state));
	    (void) fwrite((const void *)&prms,sizeof(uint64_t),1,file);
	    (void) fwrite((const void *)&stype,sizeof(int),1,file);
	    (void) fwrite((const void *)&failed,sizeof(int),1,file);
#if defined(COMBUSTION_CODE)
	    switch (Composition_type(state))
	    {
	    case ZND:
	    case PTFLAME:
	        (void) fwrite((const void *)pdens(state),FLOAT,1,file);
		break;
	    case TWO_CONSTITUENT_REACTIVE:
	        (void) fwrite((const void *)pdens(state),FLOAT,2,file);
		break;
	    case PURE_NON_REACTIVE:
	    default:
	        break;
	    }
#endif /* defined(COMBUSTION_CODE) */
            if(g_composition_type() == MULTI_COMP_NON_REACTIVE)
            {
                if(Params(state) != NULL &&
                   Params(state)->n_comps != 1)
                {
                    int i;
                    for(i = 0; i < Params(state)->n_comps; i++)
                        (void) fwrite((const void *)&(pdens(state)[i]),FLOAT,1,file);
                }
            }
	    (void) fprintf(file,"\n");
	    return;
	}
	(void) fprintf(file,"\n");
	switch (state_type(state))
	{
	case GAS_STATE:
	    g_fprint_state(file,state);
	    break;

	case EGAS_STATE:
	    g_fprint_Estate(file,state);
	    break;

	case TGAS_STATE:
	    g_fprint_Tstate(file,state);
	    break;

	case FGAS_STATE:
	    g_fprint_Fstate(file,state);
	    break;

	case VGAS_STATE:
	    verbose_fprint_state(file,"",state);
	    break;

	default:
	    screen("ERROR in fprint_gas_data(), "
	           "unknown state type %d\n",state_type(state));
	    clean_up(ERROR);
	}
}		/*end fprint_gas_data*/
Beispiel #10
0
EXPORT	bool output_spectral_in_time(
	char		*basename,
	Wave		*wave,
	Front		*front)
{
	COMPONENT	comp;
	Locstate	state;
	float		*coords;
	float		*L = wave->rect_grid->L;
	float		*U = wave->rect_grid->U;
	float		*h = wave->rect_grid->h;
	float		kk,kx,ky,dk,Ek,Vk;
	int		icoords[MAXD];
	int		dim = wave->rect_grid->dim;
	int		status;
	char		eng_name[100],vor_name[100];
	static	FILE	*eng_file,*vor_file;
	static  int	first = YES;
	int		i, ix, iy;
	int		xmax, ymax, kmax, mx, my, dummy;
	COMPLEX		**mesh_eng,**mesh_vor;
	Locstate	lstate,rstate,bstate,tstate;

	debug_print("fft","Entered output_spectral_in_time()\n");

	if (first)
	{
	    first = NO;
	    (void) sprintf(eng_name,"%s.energy-time.dat",basename);
	    (void) sprintf(vor_name,"%s.vorticity-time.dat",basename);
	    eng_file    = fopen(eng_name,"w");
	    vor_file = fopen(vor_name,"w");
	    fprintf(eng_file,"VARIABLES=k,E(k)\n",xmax,ymax);
	    fprintf(vor_file,"VARIABLES=k,V(k)\n",xmax,ymax);
	}


 	xmax = wave->rect_grid->gmax[0];
 	ymax = wave->rect_grid->gmax[1];
	if (!Powerof2(xmax,&mx,&dummy) || !Powerof2(ymax,&my,&dummy))
	{
	    screen("output_spectral_in_time() cannot analyze "
				"mesh not power of 2\n");
	    screen("xmax = %d  ymax = %d\n",xmax,ymax);
	    return FUNCTION_FAILED;
	}
	bi_array(&mesh_eng,xmax,ymax,sizeof(COMPLEX));
	bi_array(&mesh_vor,xmax,ymax,sizeof(COMPLEX));
	for (iy = 0; iy < ymax; ++iy)
	{
	    for (ix = 0; ix < xmax; ++ix)
	    {
	    	icoords[0] = ix; icoords[1] = iy;
	    	coords = Rect_coords(icoords,wave);
	    	comp = Rect_comp(icoords,wave);
	    	state = Rect_state(icoords,wave);

		if (ix != 0) icoords[0] = ix - 1;
		else icoords[0] = ix;
	    	lstate = Rect_state(icoords,wave);
		if (ix != xmax-1) icoords[0] = ix + 1;
		else icoords[0] = ix;
	    	rstate = Rect_state(icoords,wave);

		icoords[0] = ix;
		if (iy != 0) icoords[1] = iy - 1;
		else icoords[1] = iy;
	    	bstate = Rect_state(icoords,wave);
		if (iy != ymax-1) icoords[1] = iy + 1;
		else icoords[1] = iy;
	    	tstate = Rect_state(icoords,wave);

		mesh_eng[ix][iy].real = kinetic_energy(state);
		mesh_eng[ix][iy].imag = 0.0;
		mesh_vor[ix][iy].real = (Mom(rstate)[1]/Dens(rstate) 
			    	- Mom(lstate)[1]/Dens(lstate))/h[0]
				- (Mom(tstate)[0]/Dens(tstate)
				- Mom(bstate)[0]/Dens(bstate))/h[1];
		mesh_vor[ix][iy].imag = 0.0;
	    }
	}
	fft2d(mesh_eng,xmax,ymax,1);
	fft2d(mesh_vor,xmax,ymax,1);

	kmax = xmax/2;
        dk = 2.0*PI/(U[0] - L[0]);
	fprintf(eng_file,"ZONE\n",kk,Ek);
	fprintf(vor_file,"ZONE\n",kk,Vk);
	for (i = 0; i < kmax; ++i)
	{
	    Ek = 0.0;
	    Vk = 0.0;
	    kk = 2.0*i*PI/(U[0] - L[0]);
	    for (iy = 0; iy < ymax/2; ++iy)
	    {
	    	for (ix = 0; ix < xmax/2; ++ix)
		{
		    kx = 2.0*ix*PI/(U[0] - L[0]);
		    ky = 2.0*iy*PI/(U[1] - L[1]);
		    if (sqrt(sqr(kx)+sqr(ky)) >= kk-0.5*dk &&
		        sqrt(sqr(kx)+sqr(ky)) < kk+0.5*dk)
		    {
		    	Ek += 2.0*sqrt(sqr(mesh_eng[ix][iy].real) +
				       sqr(mesh_eng[ix][iy].imag));
		    	Vk += 2.0*sqrt(sqr(mesh_vor[ix][iy].real) +
				       sqr(mesh_vor[ix][iy].imag));
		    }
		}
	    }
	    fprintf(eng_file,"%lf\t%lf\n",kk,Ek);
	    fprintf(vor_file,"%lf\t%lf\n",kk,Vk);
	}
	fflush(eng_file);
	fflush(vor_file);

	free_these(2,mesh_eng,mesh_vor);

	debug_print("fft","Left output_spectral_in_time()\n");
	return FUNCTION_SUCCEEDED;
}		/*end output_spectral_in_time*/
Beispiel #11
0
EXPORT	bool output_spectral_analysis(
	char		*basename,
	Wave		*wave,
	Front		*front)
{
	COMPONENT	comp;
	Locstate	state;
	float		*coords;
	float		*L = wave->rect_grid->L;
	float		*U = wave->rect_grid->U;
	float		*h = wave->rect_grid->h;
	int		icoords[MAXD];
	int		dim = wave->rect_grid->dim;
	int		status;
	int		step = front->step;
	char		energy_name[100],vorticity_name[100],
			enstrophy_name[100],dens_name[100],pres_name[100];
	FILE		*energy_file,*vorticity_file,
			*enstrophy_file,*dens_file,*pres_file;

	debug_print("fft","Entered fft_energy_spectral()\n");

	(void) sprintf(energy_name,"%s.energy%s.dat",basename,
                         right_flush(step,TSTEP_FIELD_WIDTH));
	(void) sprintf(vorticity_name,"%s.vorticity%s.dat",basename,
                         right_flush(step,TSTEP_FIELD_WIDTH));
	(void) sprintf(enstrophy_name,"%s.enstrophy%s.dat",basename,
                         right_flush(step,TSTEP_FIELD_WIDTH));
	(void) sprintf(dens_name,"%s.density%s.dat",basename,
                         right_flush(step,TSTEP_FIELD_WIDTH));
	(void) sprintf(pres_name,"%s.pressure%s.dat",basename,
                         right_flush(step,TSTEP_FIELD_WIDTH));
	energy_file    = fopen(energy_name,"w");
	vorticity_file = fopen(vorticity_name,"w");
	enstrophy_file = fopen(enstrophy_name,"w");
	dens_file = fopen(dens_name,"w");
	pres_file = fopen(pres_name,"w");

	if (wave->sizest == 0)
	{
	    debug_print("fft","Left fft_energy_spectral()\n");
	    return FUNCTION_FAILED;
	}

	switch (dim)
	{
#if defined(ONED)
	case 1:
	{
	    int		ix;
	    int		xmax;
	    COMPLEX	*mesh_energy;

	    xmax = wave->rect_grid->gmax[0];
	    uni_array(&mesh_energy,xmax,sizeof(COMPLEX));
	    for (ix = 0; ix < xmax; ++ix)
	    {
	    	icoords[0] = ix;
	    	coords = Rect_coords(icoords,wave);
	    	comp = Rect_comp(icoords,wave);
	    	state = Rect_state(icoords,wave);
		mesh_energy[ix].real = Energy(state);
		mesh_energy[ix].imag = 0.0;
	    }
	    break;
	}
#endif /* defined(ONED) */
#if defined(TWOD)
	case 2:
	{
	    int		ix, iy;
	    int		xmax, ymax, mx, my, dummy;
	    COMPLEX	**mesh_energy,**mesh_vorticity,**mesh_enstrophy;
	    Locstate	lstate,rstate,bstate,tstate;
	    float	kk,kx,ky,dk;

	    xmax = wave->rect_grid->gmax[0];
	    ymax = wave->rect_grid->gmax[1];
	    if (!Powerof2(xmax,&mx,&dummy) || !Powerof2(ymax,&my,&dummy))
	    {
		screen("fft_energy_spectral() cannot analyze "
				"mesh not power of 2\n");
		screen("xmax = %d  ymax = %d\n",xmax,ymax);
		return FUNCTION_FAILED;
	    }
	    bi_array(&mesh_energy,xmax,ymax,sizeof(COMPLEX));
	    bi_array(&mesh_vorticity,xmax,ymax,sizeof(COMPLEX));
	    fprintf(energy_file,"zone  i=%d, j=%d\n",xmax,ymax);
	    fprintf(vorticity_file,"zone  i=%d, j=%d\n",xmax,ymax);
	    fprintf(dens_file,"zone  i=%d, j=%d\n",xmax,ymax);
	    fprintf(pres_file,"zone  i=%d, j=%d\n",xmax,ymax);
	    fprintf(enstrophy_file,"zone  i=%d, j=%d\n",xmax,ymax);
	    for (iy = 0; iy < ymax; ++iy)
	    {
	    	for (ix = 0; ix < xmax; ++ix)
	    	{
	    	    icoords[0] = ix; icoords[1] = iy;
	    	    coords = Rect_coords(icoords,wave);
	    	    comp = Rect_comp(icoords,wave);
	    	    state = Rect_state(icoords,wave);
		    mesh_energy[ix][iy].real = kinetic_energy(state);
		    mesh_energy[ix][iy].imag = 0.0;

		    if (ix != 0) icoords[0] = ix - 1;
		    else icoords[0] = ix;
	    	    lstate = Rect_state(icoords,wave);
		    if (ix != xmax-1) icoords[0] = ix + 1;
		    else icoords[0] = ix;
	    	    rstate = Rect_state(icoords,wave);

		    icoords[0] = ix;
		    if (iy != 0) icoords[1] = iy - 1;
		    else icoords[1] = iy;
	    	    bstate = Rect_state(icoords,wave);
		    if (iy != ymax-1) icoords[1] = iy + 1;
		    else icoords[1] = iy;
	    	    tstate = Rect_state(icoords,wave);
		    mesh_vorticity[ix][iy].real = (Mom(rstate)[1]/Dens(rstate) 
			    		- Mom(lstate)[1]/Dens(lstate))/h[0]
					- (Mom(tstate)[0]/Dens(tstate)
					- Mom(bstate)[0]/Dens(bstate))/h[1];
		    mesh_vorticity[ix][iy].imag = 0.0;
		    fprintf(energy_file,"%lf\n",kinetic_energy(state));
		    fprintf(vorticity_file,"%lf\n",mesh_vorticity[ix][iy].real);
		    fprintf(enstrophy_file,"%lf\n",
		    		sqr(mesh_vorticity[ix][iy].real));
		    fprintf(dens_file,"%lf\n",Dens(state));
		    fprintf(pres_file,"%lf\n",pressure(state));
	    	}
	    }
	    fft_output2d(basename,"energy",step,wave->rect_grid,
	    				mesh_energy);
	    fft_output2d(basename,"vorticity",step,wave->rect_grid,
	    				mesh_vorticity);
	    free_these(2,mesh_energy,mesh_vorticity);
	    break;
	}
#endif /* defined(TWOD) */
#if defined(THREED)
	case 3:
	{
	    int		ix, iy, iz;
	    int		xmax, ymax, zmax;
	    COMPLEX	***mesh_energy;

	    xmax = wave->rect_grid->gmax[0];
	    ymax = wave->rect_grid->gmax[1];
	    zmax = wave->rect_grid->gmax[2];
	    tri_array(&mesh_energy,xmax,ymax,zmax,sizeof(COMPLEX));
	    for (iz = 0; iz < zmax; ++iz)
	    {
	    	icoords[2] = iz;
	    	for (iy = 0; iy < ymax; ++iy)
	    	{
	    	    icoords[1] = iy;
	    	    for (ix = 0; ix < xmax; ++ix)
	    	    {
	    	    	icoords[0] = ix;
	    	    	coords = Rect_coords(icoords,wave);
	    	    	comp = Rect_comp(icoords,wave);
	    	    	state = Rect_state(icoords,wave);
			mesh_energy[ix][iy][iz].real = Energy(state);
		    	mesh_energy[ix][iy][iz].imag = 0.0;
	    	    }
	    	}
	    }
	    break;
	}
#endif /* defined(THREED) */
	}
	fclose(energy_file);
	fclose(vorticity_file);
	fclose(enstrophy_file);
	fclose(dens_file);
	fclose(pres_file);

	debug_print("fft","Left fft_energy_spectral()\n");
	return FUNCTION_SUCCEEDED;
}		/*end fft_energy_spectral*/
Beispiel #12
0
EXPORT void g_verbose_fprint_state(
	FILE	   *file,
	const char *name,
	Locstate   state)
{
	bool		bin_out;
	int		i, dim;
	float		p, c, S, v[SMAXD], speed;
	static	char	vname[3][3] = { "vx", "vy", "vz"};
	static	char	mname[3][3] = { "mx", "my", "mz"};

	if (name == NULL)
	    name = "";
	(void) fprintf(file,"\n%s:\n",name);
	(void) fprintf(file,"address %p\n",state);
	if (state == NULL || is_obstacle_state(state))
	{
	    (void) fprintf(file,"(OBSTACLE STATE)\n\n");
	    return;
	}
	dim = Params(state)->dim;

	p = pressure(state);
	c = sound_speed(state);
	S = entropy(state);

	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n",
		       "density",Dens(state),
		       "specific internal energy",
		       specific_internal_energy(state));
	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","pressure",p,
		       "sound speed",c);
	(void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","temperature",
		       temperature(state),"specific entropy",S);

	speed = 0.0;
	for (i = 0; i < dim; i++)
	{
	    v[i] = vel(i,state);	speed += sqr(v[i]);
	    (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n",
			   mname[i],mom(i,state),vname[i],v[i]);
	}
	speed = sqrt(speed);

	(void) fprintf(file,"%-24s = %-"FFMT"","total energy",energy(state));
	if (c > 0. && Dens(state) > 0.)
	   (void) fprintf(file," %-24s = %-"FFMT"\n","Mach number",speed / c);
	else
	   (void) fprintf(file,"\n");

#if defined(TWOD)
	if (dim == 2)
	    (void) fprintf(file,"%-24s = %-"FFMT"\n","velocity angle",
			   degrees(angle(v[0],v[1])));
#endif /* defined(TWOD) */


	fprint_state_type(file,"State type = ",state_type(state));
	(void) fprintf(file,"Params state = %llu\n",
		       gas_param_number(Params(state)));

	bin_out = is_binary_output();
	set_binary_output(NO);
	if (debugging("prt_params"))
	    fprint_Gas_param(file,Params(state));
	else
	    (void) fprintf(file,"Gas_param = %llu\n",
		                gas_param_number(Params(state)));
	set_binary_output(bin_out);

	//if(p< -2000 || p>10000)
	//{
	//    printf("#huge pressure\n");
	//    clean_up(0);
	//}
#if !defined(COMBUSTION_CODE)
	(void) fprintf(file,"\n");
#else /* !defined(COMBUSTION_CODE) */
	if (Composition_type(state) == PURE_NON_REACTIVE)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-12s   %-24s = %-"FFMT"\n","burned",
		       Burned(state) ? "BURNED" : "UNBURNED",
		       "q",Params(state)->q);
	(void) fprintf(file,"%-24s = %-"FFMT"\n","t_crit",
		       Params(state)->critical_temperature);

	if (Composition_type(state) == PTFLAME)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-"FFMT"\n","product density",Prod(state));
	(void) fprintf(file,"%-24s = %-"FFMT"\n",
		       "reaction progress",React(state));

	if (Composition_type(state) == ZND)
	{
	    (void) fprintf(file,"\n");
	    return;
	}

	(void) fprintf(file,"%-24s = %-"FFMT"\n","rho1",Dens1(state));
#endif /* !defined(COMBUSTION_CODE) */
	(void) fprintf(file,"%-24s = %-24s %-24s = %-"FFMT"\n\n","gamma_set",
		      Local_gamma_set(state)?"YES" : "NO","local_gamma",
		      Local_gamma(state));
        if(g_composition_type() == MULTI_COMP_NON_REACTIVE)
        {
            if(Params(state) != NULL &&
               Params(state)->n_comps != 1)
            {
                for(i = 0; i < Params(state)->n_comps; i++)
                    (void) fprintf(file,"partial density[%2d] = %"FFMT"\n",
                       i,pdens(state)[i]);
                (void) fprintf(file,"\n");
                 /* TMP the following print is for the debuging display purpose */
                for(i = 0; i < Params(state)->n_comps; i++)
                    (void) fprintf(file,"[%d]Mass fraction = %-"FFMT"\n",
                             i, pdens(state)[i]/Dens(state));
                (void) fprintf(file,"\n");
            }
        }
}		/*end g_verbose_fprint_state*/
Beispiel #13
0
/*ARGSUSED*/
EXPORT	void	get_state_ambient(
	float		*coords,
	Locstate	s,
	COMP_TYPE	*ct,
	HYPER_SURF	*hs,
	INTERFACE	*intfc,
	INIT_DATA	*init,
	int		stype)
{
	Locstate	ct_state = Ambient(ct);
        int             save_stype = stype;

        debug_print("init_states","Entered get_state_ambient()\n");
	if ( ct->type != AMBIENT )
	{
	    screen("\nERROR in get_state_ambient(), "
		   "inconsistent comp_type->type\n");
	    clean_up(ERROR);
	}

	if ( ct_state != NULL )
        {
            if(g_composition_type() == MULTI_COMP_NON_REACTIVE)
                stype = TGAS_STATE;

            set_state(s,stype,ct_state);
	    //if(coords[0] > -0.15 && coords[2] > 3.9)
		//Vel(s)[0] = 0.0;
		
	    get_constant_state_init(s, 2, coords, 0.0);

	    /* scramjet nozzle boundary layer */
/*	    double r1, r2=0.099;
            if(coords[2] > 4.0-1.0 && coords[2] < 4.0-1.0+0.095)
            	r1 = r2;
            if(coords[2] >= 4.0-1.0+0.095 && coords[2] < 4.0-1.0+0.095+0.317)
            	r1 = r2+0.556-sqrt(sqr(0.556)-sqr(coords[2]-(4.0-1.0+0.095)));
            if(coords[2] >= 4.0-1.0+0.095+0.317 && coords[2] < 4.0-1.0+0.095+0.317+0.061)
            	r1 = r2+0.556-sqrt(sqr(0.556)-sqr(0.317))+(coords[2]-(4.0-1.0+0.095+0.317))*tan(3.14159*67.5/180);
            if(coords[2] >= 4.0-1.0+0.095+0.317+0.061 && coords[2] <= 4.0)
            	r1 = r2+0.556-sqrt(sqr(0.556)-sqr(0.317))+0.061*tan(3.14159*67.5/180);

	    if(coords[2] > 3.0 && coords[2] < 4.0)
	    {
            	double f = get_blasius_vel_coefficient_nozzle(coords,r1);
            	Vel(s)[2]*=f;
	    }
*/
//	    if(coords[2] <= 3.9)
//	    {
  //          	double f = get_blasius_vel_coefficient(coords,3.9);
    //        	Vel(s)[0]*=f;
//	    }
	    
	    //TMP for the shift 
	    //get_state_shift(coords, s);
        }
	else
	{
	    screen("ERROR in get_state_ambient(), NULL state encountered\n");
	    clean_up(ERROR);
	}

        /* This is for the oned sod-tube test problem */
        /* init partial density */
        if(g_composition_type() == MULTI_COMP_NON_REACTIVE)
        {
            if(debugging("sod_tube"))
            {
                Gas_param *params = Params(s);
                int    num_comps, i;
                float   *rho;
                if((num_comps = params->n_comps) != 1)
                {
                    rho = pdens(s);
                    if(coords[0] >= 0.0 && coords[0] <= 0.5)
                        rho[0] = 0.8*Dens(s);
                    else if(coords[0] > 0.5 && coords[0] <= 0.7)
                        rho[0] = 0.3*Dens(s);
                    else
                        rho[0] = 0.1*Dens(s);
                    rho[1] = 0.19*sqr(sin(20*3.1415927*coords[0]))*Dens(s);
                    rho[2] = Dens(s) - rho[1] - rho[0];
                    if(rho[0] < 0.0 || rho[1] < 0.0 || rho[2] < 0.0)
                    {
                        printf("ERROR: get_state_ambient, partial den < 0.0\n");
                        clean_up(ERROR);
                    }
                }
            }
            else if(debugging("blast_wave"))
            {
                Gas_param *params = Params(s);
                int    num_comps, i;
                float   *rho;
                if((num_comps = params->n_comps) != 1)
                {
                    rho = pdens(s);
                    rho[0] = 0.5*sqr(coords[0])*Dens(s);
                    rho[1] = 0.5*sqr(sin(20*coords[0]))*Dens(s);
                    rho[2] = Dens(s) - rho[1] - rho[0];
                    if(rho[0] < 0.0 || rho[1] < 0.0 || rho[2] < 0.0)
                    {
                        printf("ERROR: get_state_ambient, partial den < 0.0\n");
                        clean_up(ERROR);
                    }
                }
            }
            set_state(s,save_stype,s);
            // verbose_print_state("get_state_ambient", s);
        }
}		/*end get_state_ambient*/
Beispiel #14
0
LOCAL	void		add_ext_deposition(
	Locstate	state,
	COMPONENT	comp,
	float		*coords,
	int		dim)
{
	float	dep, tcrds[MAXD+1];
	int	i, d;

	if (is_obstacle_state(state)) return;

	//TMP vel pertb
	if(NO)
	{
	    if(coords[2] < 0.8 && coords[2] > -0.8 && comp == deparam[0].comp)
	    {
		set_state(state,TGAS_STATE,state);
		Vel(state)[0] = 0.25*rand()/((float)RAND_MAX + 1);
		Vel(state)[1] = 0.25*rand()/((float)RAND_MAX + 1);
		Vel(state)[2] = 0.25*rand()/((float)RAND_MAX + 1);
		set_state(state,GAS_STATE,state);
	    }
	}

	// set tcrds
	tcrds[0] = 0;
	for (d = 0; d < dim; d++)  tcrds[d+1] = coords[d];
	
	//TMP for cylindy depo
	//tcrds[3] = 0;

	for (i = 0; i < dep_number; i++)
	{
	    if (comp != -1 && comp != deparam[i].comp) continue; // comp = -1 for all components
	    
	    // check if within deposition boundary
	    if ( tcrds[0] < deparam[i].bd[0][0] || tcrds[0] > deparam[i].bd[0][1] )
		continue; // check time
	    if (deparam[i].region == DEP_RECT)
	    {
		for (d = 1; d < dim+1; d++)
		    if ( tcrds[d] < deparam[i].bd[d][0] || tcrds[d] > deparam[i].bd[d][1] )
			    break;
		if (d < dim+1)  continue;
	    }
	    else // DEP_ELLIP
	    {
		float	sum = 0;
		for (d = 1; d < dim+1; d++)
		    sum += sqr((tcrds[d]-deparam[i].bd[d][0])/deparam[i].bd[d][1]);
		//if (sum > 1) continue;
	    }

	    dep = deparam[i].amp;
	    
	    for (d = 0; d < dim+1; d++)
	    {
		if (deparam[i].prof[d] == GAUSSIAN)
		{   // param[d][0] = decay length
		    if (deparam[i].flag[d][0] == false) // Gaussian
			dep /= exp(sqr((tcrds[d]-deparam[i].orig[d])/deparam[i].param[d][0]));
		    else // exponential
			dep /= exp((tcrds[d]-deparam[i].orig[d])/deparam[i].param[d][0]);
		}
		else if (deparam[i].prof[d] == POWER)
		{   // param[d][0] = decay exponent
		    dep /= pow(fabs(tcrds[d]-deparam[i].orig[d]),deparam[i].param[d][0]);
		}
		else if (deparam[i].prof[d] == SINUSOIDAL)
		{   // param[d][0] = wavelength, params[d][1] = phase
		    dep *= sin(2*PI*( (tcrds[d] - deparam[i].orig[d])
			/ deparam[i].param[d][0] + deparam[i].param[d][1]/360 ));
		}
	    }

	    dep += deparam[i].base;
	    switch(deparam[i].type)
	    {
		case EXT_ENERGY: // total energy density
		    Energy(state) = dep;
		    break;
		case EXT_PRESSURE:
		    set_state(state,TGAS_STATE,state);
		    //dep = interp_from_data(coords)*13000.0/0.009351;
		    //dep = interp_from_data(coords)*17500.0/0.03976;
		    //dep = interp_from_data(coords);
		    dep = interp_from_data(coords)*15000.0/0.01544;

		    Press(state) += dep;
		    
		    set_state(state,GAS_STATE,state);
		    break;
		case EXT_TEMPER: // keep density fixed
		    set_state(state,FGAS_STATE,state);
		    Temperature(state) = dep;
		    set_state(state,GAS_STATE,state);
		    break;
		case EXT_VX:
		    set_state(state,TGAS_STATE,state);
		    Vel(state)[0] = dep;
		    set_state(state,GAS_STATE,state);
		    break;
		case EXT_VY:
		    set_state(state,TGAS_STATE,state);
		    Vel(state)[1] = dep;
		    set_state(state,GAS_STATE,state);
		    break;
		case EXT_VZ:
		    set_state(state,TGAS_STATE,state);
		    Vel(state)[2] = dep;
		    set_state(state,GAS_STATE,state);
		    break;
		case EXT_DENSITY:
		    Dens(state) = dep;
		    break;
	    }
	    if (debugging("deposition"))
	    {
		printf("{%c}dep[",dep_name[deparam[i].type]);
		for (d = 0;d < dim-1;d++)  printf("%g,",coords[d]);
		printf("%g]=%g, ",coords[dim-1],dep);
	    }
	}
}	/* end add_ext_deposition() */
Beispiel #15
0
void nemo_main()
{
    stream instr, outstr;
    real   mscale, pscale, xscale, tsnap, escale, dscale;
    vector rscale, vscale, ascale;
    string times;
    int i, nbody, bits, nrscale, nvscale, nascale, kscale;
    Body *btab = NULL, *bp;
    bool Qmass, Qphase, Qacc, Qpot, Qkey, Qaux, Qeps, Qdens;

    nrscale = nemoinpr(getparam("rscale"),rscale,NDIM);     /* RSCALE */
    if (nrscale==1) 
    	for (i=1; i<NDIM; i++)
    	   rscale[i] = rscale[0];
    else if (nrscale!=NDIM)
    	error("keyword rscale needs either 1 or %d numbers", NDIM);
    			

    nvscale = nemoinpr(getparam("vscale"),vscale,NDIM);     /* VSCALE */
    if (nvscale==1)
    	for (i=1; i<NDIM; i++)
    	   vscale[i] = vscale[0];
    else if (nvscale!=NDIM)
    	error("keyword vscale needs either 1 or %d numbers", NDIM);    

    nascale = nemoinpr(getparam("ascale"),ascale,NDIM);     /* ASCALE */
    if (nascale==1)
    	for (i=1; i<NDIM; i++)
    	   ascale[i] = ascale[0];
    else if (nascale!=NDIM)
    	error("keyword ascale needs either 1 or %d numbers", NDIM);    

    mscale = getdparam("mscale");
    pscale = getdparam("pscale");
    xscale = getdparam("xscale");
    dscale = getdparam("dscale");
    escale = getdparam("escale");
    kscale = getiparam("kscale");
    times = getparam("times");

    instr = stropen(getparam("in"), "r");   /* open files */
    outstr = stropen(getparam("out"), "w");

    get_history(instr);
    put_history(outstr);		
    for (;;) {
    	get_history(instr);		/* skip over stuff we can forget */
        if (!get_tag_ok(instr, SnapShotTag))
		break;			/* done with work in loop */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) {
	    continue;       /* just skip it's probably a diagnostics */
        }

        if ((bits & TimeBit) == 0)
	    tsnap = 0.0;
        else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ))
            continue;
        dprintf (1,"Scaling snapshot at time= %f bits=0x%x\n",tsnap,bits);

        Qmass  = MassBit & bits        && !uscalar(mscale);
        Qphase = PhaseSpaceBit & bits  &&(!uvector(rscale) || !uvector(vscale));
        Qacc   = AccelerationBit & bits&& !uvector(ascale);
        Qpot   = PotentialBit & bits   && !uscalar(pscale);
        Qaux   = AuxBit & bits         && !uscalar(xscale);
        Qkey   = KeyBit & bits         && (kscale!=1);
        Qdens  = DensBit & bits        && !uscalar(dscale);
        Qeps   = EpsBit & bits         && !uscalar(escale);

        dprintf(1,"Scaling: ");
        if (Qmass)  dprintf(1," mass");
        if (Qphase) dprintf(1," phase");
        if (Qacc)   dprintf(1," acc");
        if (Qpot)   dprintf(1," pot");
        if (Qaux)   dprintf(1," aux");
        if (Qkey)   dprintf(1," key");
        if (Qdens)  dprintf(1," dens");
        if (Qeps)   dprintf(1," eps");
        dprintf(1,"\n");

        if (Qmass || Qphase || Qacc || Qpot || Qaux || Qkey || Qdens || Qeps) {
            for (bp = btab; bp < btab+nbody; bp++) {
                if(Qmass) Mass(bp) *= mscale;
                if(Qphase) {
                    SMULVV(Pos(bp),rscale);
                    SMULVV(Vel(bp),vscale);
	        }
                if(Qpot) Phi(bp) *= pscale;
                if(Qacc) {
                    SMULVV(Acc(bp),ascale);
                }
                if(Qaux) Aux(bp) *= xscale;
                if(Qkey) Key(bp) *= kscale;
		if(Qdens) Dens(bp) *= dscale;
		if(Qeps) Eps(bp) *= escale;
            }
        } else {
            warning("No scaling applied to snapshot");
	}

        put_snap(outstr, &btab, &nbody, &tsnap, &bits);
    }
}