Ejemplo n.º 1
0
void DATA::Print(const double t, const int step, const char* outputname){
	int i;
	char filename[200];
	FILE *outfile;
	sprintf(filename,"vtkoutput_%s",right_flush(step,7));
	//sprintf(filename,"%s_%s",filename,outputname);
	//if (PN * PM * PL != 1)
	//	sprintf(filename,"%s-nd%s",filename,right_flush(id,4));
	sprintf(filename,"%s.vtk",filename);
	outfile = fopen(filename,"w");
	fprintf(outfile,"# vtk DataFile Version 3.0\n");
	fprintf(outfile,"The actual time is %.8f\n",t);
	fprintf(outfile,"ASCII\n");
	fprintf(outfile,"DATASET POLYDATA\n");
	fprintf(outfile,"POINTS %d double\n",m_num_of_par);
	for (i = 0; i < m_num_of_par; i++)
		fprintf(outfile,"%.16g %.16g %.16g\n",m_xp[i],m_yp[i],m_zp[i]);
	fprintf(outfile,"POINT_DATA %d\n",m_num_of_par);
	fprintf(outfile,"VECTORS Velocity double\n");
	for (i = 0; i < m_num_of_par; i++)
		fprintf(outfile,"%.16g %.16g %.16g\n",m_up[i],m_vp[i],m_wp[i]);
//	fprintf(outfile,"SCALARS Type integer\n");
//	fprintf(outfile,"LOOKUP_TABLE default\n");
//	for (i = 0; i < m_num_of_par; i++)
//		fprintf(outfile,"%d\n",m_Boundary_Flag[i]);
	fclose(outfile);
}
Ejemplo n.º 2
0
LOCAL   char *set_ppfname(
        char       *ppfname,
        const char *fname,
        size_t     *ppfname_len)
{
        size_t len;

        if (pp_numnodes() > 1 )
        {
            const char   *nd;

            nd = right_flush(pp_mynode(),4);
            if (fname == NULL)
                fname = "";
            len = strlen(fname)+1+strlen(nd)+1;
            if (*ppfname_len < len)
            {
                *ppfname_len = len;
                if (ppfname != NULL)
                    free(ppfname);
                uni_array(&ppfname,*ppfname_len,CHAR);
            }
            (void) sprintf(ppfname,"%s.%s",fname,nd);
        }
        else
        {
            if (fname == NULL)
                fname = "";
            len = strlen(fname)+1;
            if (*ppfname_len < len)
            {
                *ppfname_len = len;
                if (ppfname != NULL)
                    free(ppfname);
                uni_array(&ppfname,*ppfname_len,CHAR);
            }
            (void) strcpy(ppfname,fname);
        }
        return ppfname;
}               /*end set_ppfname*/
Ejemplo n.º 3
0
LOCAL	void fft_output2d(
	const char *basename,
	const char *var_name,
	int step,
	RECT_GRID *grid,
	COMPLEX **cc)
{
	int i, ix, iy;
	int kmax, xmax, ymax;
	float kx, ky, kk, dk, var_k;
	float *h, *L, *U;
	char fft_name[120], mfft_name[120];
	FILE *fft_file, *mfft_file;

	xmax = grid->gmax[0];
	ymax = grid->gmax[1];
	h = grid->h;
	L = grid->L;
        U = grid->U;

	(void) sprintf(fft_name,"%s.%s.fft%s.dat",basename,var_name,
                         right_flush(step,TSTEP_FIELD_WIDTH));
	(void) sprintf(mfft_name,"%s.%s.mfft%s.dat",basename,var_name,
                         right_flush(step,TSTEP_FIELD_WIDTH));
	fft_file  = fopen(fft_name,"w");
	mfft_file = fopen(mfft_name,"w");

	fft2d(cc,xmax,ymax,1);

	for (iy = 0; iy < ymax/2; ++iy)
	{
	    for (ix = 0; ix < xmax/2; ++ix)
	    {
	    	var_k = 2.0*sqrt(sqr(cc[ix][iy].real) + sqr(cc[ix][iy].imag));
		fprintf(fft_file,"%f\n",var_k);
	    }
	}
	kmax = xmax/2;
        dk = 2.0*PI/(U[0] - L[0]);
        fprintf(mfft_file,"VARIABLES=k,'%s(k)'\n",var_name);
	for (i = 0; i < kmax; ++i)
	{
	    var_k = 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)
		    {
		    	var_k += 2.0*sqrt(sqr(cc[ix][iy].real) +
				          sqr(cc[ix][iy].imag));
		    }
		}
	    }
	    fprintf(mfft_file,"%lf\t%lf\n",kk,var_k);
	}

	fclose(fft_file);
	fclose(mfft_file);
}	/* end fft_output */
Ejemplo n.º 4
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*/
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
	static Front front;
	static RECT_GRID comp_grid;
	static F_BASIC_DATA f_basic;
	static LEVEL_FUNC_PACK level_func_pack;
	static VELO_FUNC_PACK velo_func_pack;
	TNORV_PARAMS norm_params; /* velocity function parameters */
	TMC_PARAMS mc_params;
	Locstate  sl;

	f_basic.dim = 2;
	FrontInitStandardIO(argc,argv,&f_basic);

	/* Initialize basic computational data */

	f_basic.L[0] = 0.0;	f_basic.L[1] = 0.0;
	f_basic.U[0] = 1.0;	f_basic.U[1] = 1.0;
	f_basic.gmax[0] = 100;	f_basic.gmax[1] = 100;
	f_basic.boundary[0][0] = f_basic.boundary[0][1] = PERIODIC_BOUNDARY;
	f_basic.boundary[1][0] = f_basic.boundary[1][1] = PERIODIC_BOUNDARY;
	f_basic.size_of_intfc_state = 0;

        in_name                 = f_basic.in_name;
        restart_state_name      = f_basic.restart_state_name;
        out_name                = f_basic.out_name;
        restart_name            = f_basic.restart_name;
        RestartRun              = f_basic.RestartRun;
        RestartStep             = f_basic.RestartStep;

        sprintf(restart_name,"%s.ts%s",restart_name,right_flush(RestartStep,7));
#if defined(__MPI__)
        sprintf(restart_name,"%s-nd%s",restart_name,right_flush(pp_mynode(),4));
#endif /* defined(__MPI__) */

	FrontStartUp(&front,&f_basic);

	if (!RestartRun)
	{
	    /* Initialize interface through level function */

	    mc_params.num_cir = 3;
            vector(&mc_params.rad,mc_params.num_cir,FLOAT);
            matrix(&mc_params.cen,mc_params.num_cir,2,FLOAT);
	    mc_params.cen[0][0] = 0.3;
	    mc_params.cen[0][1] = 0.3;
	    mc_params.cen[1][0] = 0.7;
	    mc_params.cen[1][1] = 0.3;
	    mc_params.cen[2][0] = 0.5;
	    mc_params.cen[2][1] = 0.7;
	    mc_params.rad[0] = 0.1;
	    mc_params.rad[1] = 0.1;
	    mc_params.rad[2] = 0.1;

	    level_func_pack.neg_component = 1;
	    level_func_pack.pos_component = 2;
	    level_func_pack.func_params = (POINTER)&mc_params;
	    level_func_pack.func = multi_circle_func;

	    FrontInitIntfc(&front,&level_func_pack);
	}

	/* Initialize velocity field function */

	norm_params.dim = 2;
	norm_params.coeff = 0.1;

	velo_func_pack.func_params = (POINTER)&norm_params;
	velo_func_pack.func = norm_vel_func;
	velo_func_pack.point_propagate = first_order_point_propagate;

	FrontInitVelo(&front,&velo_func_pack);

        /* For geometry-dependent velocity, use first
        * order point propagation function, higher order
        * propagation requires surface propagate, currently
        * in writing, not yet in use. The following override
        * the assigned fourth_order_point_propagate.
        */

        front._point_propagate = first_order_point_propagate;

	/* Propagate the front */

	test_propagate(&front);

	clean_up(0);
	return 0;
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
	static Front front;
	static RECT_GRID comp_grid;
	static F_BASIC_DATA f_basic;
	static LEVEL_FUNC_PACK level_func_pack;
	static VELO_FUNC_PACK velo_func_pack;
        DOUBLE_VORTEX_PARAMS dv_params; /* velocity function parameters */

	f_basic.dim = 2;
	FrontInitStandardIO(argc,argv,&f_basic);

	/* Initialize basic computational data */

	f_basic.L[0] = 0.0;	f_basic.L[1] = 0.0;
	f_basic.U[0] = 1.0;	f_basic.U[1] = 1.0;
	f_basic.gmax[0] = 200;	f_basic.gmax[1] = 200;
	f_basic.boundary[0][0] = f_basic.boundary[0][1] = DIRICHLET_BOUNDARY;
	f_basic.boundary[1][0] = f_basic.boundary[1][1] = DIRICHLET_BOUNDARY;
	f_basic.size_of_intfc_state = 0;

        in_name                 = f_basic.in_name;
        restart_state_name      = f_basic.restart_state_name;
        out_name                = f_basic.out_name;
        restart_name            = f_basic.restart_name;
        RestartRun              = f_basic.RestartRun;
        RestartStep             = f_basic.RestartStep;

        sprintf(restart_name,"%s.ts%s",restart_name,right_flush(RestartStep,7));
#if defined(__MPI__)
        sprintf(restart_name,"%s-nd%s",restart_name,right_flush(pp_mynode(),4));
#endif /* defined(__MPI__) */
	

	FrontStartUp(&front,&f_basic);

	if (!RestartRun)
	{
	    /* Initialize interface through level function */

	    level_func_pack.neg_component = 1;
	    level_func_pack.pos_component = 2;
	    level_func_pack.func_params = NULL;
	    level_func_pack.func = NULL;
	    level_func_pack.num_points = 500;
	    level_func_pack.is_closed_curve = YES;

	    matrix(&level_func_pack.point_array,500,2,sizeof(float));
	    int i;
	    for (i = 0; i < 500; ++i)
	    {
	        float phi = i*2.0*PI/500.0;
	        level_func_pack.point_array[i][0] = 0.5 + 0.3*cos(phi);
	        level_func_pack.point_array[i][1] = 0.5 + 0.3*sin(phi);
	    }
	
	    FrontInitIntfc(&front,&level_func_pack);
	}

	/* Initialize velocity field function */

        dv_params.cen1[0] = 0.25;
        dv_params.cen1[1] = 0.50;
        dv_params.cen2[0] = 0.75;
        dv_params.cen2[1] = 0.50;
        dv_params.i1 = -0.5;
        dv_params.i2 =  0.5;

        velo_func_pack.func_params = (POINTER)&dv_params;
        velo_func_pack.func = test_vortex_vel;
        velo_func_pack.point_propagate = fourth_order_point_propagate;

        FrontInitVelo(&front,&velo_func_pack);

        /* Propagate the front */

        test_propagate(&front);

	clean_up(0);
}
Ejemplo n.º 7
0
EXPORT void geomview_amr_fronts_plot2d(
        const char    *dname,
        Front         **frs,
        int           num_patches,
        Wv_on_pc      **redistr_table,
        int           max_n_patch)
{
        FILE              *fp;
        int               i; 
        char              fmt[256];
        static const char *indent = "    ";
        static char       *fname = NULL, *ppfname = NULL;
        static size_t     fname_len = 0, ppfname_len = 0;
        INTERFACE         *intfc = frs[0]->interf; 
        INTERFACE         *tmpintfc;  
        CURVE             **c;
        INTERFACE         *sav_intfc;
        bool              sav_copy; 
        float             **clrmap = NULL; 
        float             ccolor[4] = {0.0, 0.0, 0.0, 1.0};
        int               myid, numnodes;
        const char        *nstep;
        char              outname[256],outdir[256];

        myid = pp_mynode(); numnodes = pp_numnodes();
        sprintf(outdir,"%s/%s",dname,"geomintfc"); 
        ppfname = set_ppfname(ppfname,"intfc",&ppfname_len);
        nstep = right_flush(frs[0]->step,7);
        sprintf(outname,"%s.ts%s",ppfname,nstep);

        if (create_directory(dname,YES) == FUNCTION_FAILED)
        {
            (void) printf("WARNING in geomview_intfc_plot2d(), directory "
                          "%s doesn't exist and can't be created\n",dname);
            return;
        }
        if (create_directory(outdir,YES) == FUNCTION_FAILED)
        {
            (void) printf("WARNING in geomview_intfc_plot2d(), directory "
                         "%s doesn't exist and can't be created\n",outdir);
            return;
        }

        sav_intfc = current_interface();
        sav_copy = copy_intfc_states();
        set_size_of_intfc_state(size_of_state(intfc));
        set_copy_intfc_states(YES);
        tmpintfc = copy_interface(intfc);
  
        /* 
        clip_to_interior_region(tmpintfc,
            frs[0]->rect_grid->lbuf,frs[0]->rect_grid->ubuf); 
        */

        uni_array(&clrmap,6,sizeof(float*));  
        for(i = 0; i < 6; i++)
            uni_array(&clrmap[i],4,sizeof(float)); 

        i = 0;  
        clrmap[i][0] = 0.098; clrmap[i][1] = 0.647;
        clrmap[i][2] = 0.400; clrmap[i][3] = 1.000;
        i++;
        clrmap[i][0] = 0.898; clrmap[i][1] = 0.400;
        clrmap[i][2] = 0.000; clrmap[i][3] = 1.000;
        i++;
        clrmap[i][0] = 0.500; clrmap[i][1] = 1.000;
        clrmap[i][2] = 0.500; clrmap[i][3] = 1.000;
        i++;
        clrmap[i][0] = 1.000; clrmap[i][1] = 0.000;
        clrmap[i][2] = 1.000; clrmap[i][3] = 1.000;
        i++;
        clrmap[i][0] = 0.000; clrmap[i][1] = 0.800;
        clrmap[i][2] = 1.000; clrmap[i][3] = 1.000;
        i++;
        clrmap[i][0] = 0.250; clrmap[i][1] = 0.808;
        clrmap[i][2] = 0.098; clrmap[i][3] = 1.000;
        i++;

        
        fname = get_list_file_name(fname,outdir,outname,&fname_len); 
        if ((fp = fopen(fname,"w")) == NULL)
        {
            (void) printf("WARNING in gview_plot_intfc2d(), "
                           "can't open %s\n",fname);
            delete_interface(tmpintfc);  
            set_current_interface(sav_intfc);
            set_copy_intfc_states(sav_copy);
            return;
        }
        fprintf(fp,"{ LIST \n");
        /* beginning of writting Vect to file */
        for(c = tmpintfc->curves; c and *c;  c++)
            gview_plot_curve2d(fp,*c,ccolor); 

        for(int i = 0; i < num_patches; i++)
        {
           int use_clr;  
           /* 
           gview_plot_box2d(fp, frs[i]->rect_grid->L,
                frs[i]->rect_grid->U,clrmap[i%3]); 
           */ 
           if(NULL != redistr_table)
               use_clr = redistr_table[myid][i].pc_id % 6;
           else
               use_clr = 1;  
           gview_plot_grid2d(fp,frs[i]->rect_grid,clrmap[use_clr]);  
        }  

        /* end of LIST OBJ */
        fprintf(fp,"}\n");
        fclose(fp); 

        set_current_interface(sav_intfc);
        set_copy_intfc_states(sav_copy);
        delete_interface(tmpintfc);  

        for(int i = 0; i < 6; i++)
            free(clrmap[i]); 
        free(clrmap);  
}