Пример #1
0
void
plot_line(struct Fis * fis)
{
    int i;
    double dx = 0.01;
    int max = (int) (1.0 / dx);
    double x[1];
    double out[1];
    double y[max], x_i[max];

    gnuplot_ctrl * h1;
    h1 = gnuplot_init();
    gnuplot_setstyle(h1,"lines");
    for (i = 0; i < max; i++) {
        x[0] = (double)i * dx;
//        x[1] = (double)i * dx;
        x_i[i] = x[0];
        evalfis(out,x,fis);
        y[i] = out[0];
    }
    gnuplot_plot_xy(h1, x_i, y, max, "Fuzzy Output");
    gnuplot_plot_xy(h1, x_i, x_i, max, "Expected Output");
    printf("Press any key to close window\n");
    getchar();
    gnuplot_close(h1);
}
Пример #2
0
/**
 * @brief	Open a new session, plot a signal, close the session.
 * @param	title	Plot title
 * @param	style	Plot style
 * @param	label_x	Label for X
 * @param	label_y	Label for Y
 * @param	x		Array of X coordinates
 * @param	y		Array of Y coordinates (can be NULL)
 * @param	n		Number of values in x and y.
 * @return
 *
 *  This function opens a new gnuplot session, plots the provided
 *  signal as an X or XY signal depending on a provided y, waits for
 *  a carriage return on stdin and closes the session.
 *
 * It is Ok to provide an empty title, empty style, or empty labels for
 * X and Y. Defaults are provided in this case.
 */
void gnuplot_plot_once(char* title, char* style, char* label_x, char* label_y,
												float* x, float* y, int n) {
	gnuplot_ctrl* handle;

	if (x==NULL || n<1)
		return;

	if ((handle = gnuplot_init()) == NULL)
		return;

	if (style!=NULL)
		gnuplot_setstyle(handle, style);
	else
		gnuplot_setstyle(handle, (char*)"lines");

	if (label_x!=NULL)
		gnuplot_set_xlabel(handle, label_x);
	else
		gnuplot_set_xlabel(handle, (char*)"X");

	if (label_y!=NULL)
		gnuplot_set_ylabel(handle, label_y);
	else
		gnuplot_set_ylabel(handle, (char*)"Y");

	if (y==NULL)
		gnuplot_plot_x(handle, x, n, title);
	else
		gnuplot_plot_xy(handle, x, y, n, title);

	printf("press ENTER to continue\n");
	while (getchar()!='\n') {}
	gnuplot_close(handle);
	return;
}
Пример #3
0
void
PlotGraph::PlotAugmentingPath(BipartiteGraph& _bg, vector<EID>& _path){

    //get assignment size, assume the sizes of agents and tasks are identical
    size_t as_size = _bg.GetNumAgents();
    double plx[as_size];
    double ply[as_size];
/*
    //gnuplot_resetplot(g);
    gnuplot_cmd(g, (char*)"unset label");
    gnuplot_cmd(g, (char*)"set xrange [-0.25:1.25]");
    gnuplot_cmd(g, (char*)"set yrange [-0.25:%f]", as_size-1+.25);
    gnuplot_cmd(g, (char*)"set xtics 0");
    gnuplot_cmd(g, (char*)"set ytics 0");
    gnuplot_cmd(g, (char*)"set nokey");
*/
    //gnuplot_cmd(g, (char*)"set style line 2 lt 2 lc rgb \"blue\" lw 3");
    // Plot matching
    //cout<<endl<<"Set M: "<<endl;
    //DisplayData(_M);    
    bool alter = true;
    for (unsigned int i = 0; i < _path.size(); i++){
        plx[0] = _path[i].first;
        ply[0] = 0.0;
        plx[1] = _path[i].second;
        ply[1] = 1.0;

        //gnuplot_setstyle(g, (char*)"linespoints lc rgb \"#55DD99\" lw 3");
        if(alter)
          gnuplot_setstyle(g, (char*)"lines lc rgb \"#458B74\" lw 3");
        else
          gnuplot_setstyle(g, (char*)"lines lc rgb \"#7CCD7C\" lw 3");

        alter = !alter;
        gnuplot_plot_xy(g, plx, ply, 2, NULL);
    }

#ifdef SAVE_PLOTS
    stringstream ss;
    ss << setw(3) << setfill('0') << Cnt++;
    string postfix = ss.str();

    string name="save/plot"+postfix+".jpeg";
    gnuplot_cmd(g, (char*)"set terminal jpeg");
    //gnuplot_cmd(g, (char*)"set terminal jpeg small size 320,240");//bad
    gnuplot_cmd(g, (char*)"set output \"%s\"", name.c_str());
    printf("saved jpeg: \"%s\"\n", name.c_str());
#endif

    gnuplot_cmd(g, (char*)"replot");

   sleep(period);
}
Пример #4
0
int plot_doubles(gnuplot_ctrl *h, double *xdata, double *ydata, int len, char *plot_name)
{
	if( h == NULL || ydata == NULL || xdata == NULL|| len <= 0  || plot_name == NULL){
		fprintf(stderr, "plot_data: dodgy arguments\n");
		return -1;
	}

	gnuplot_setstyle(h, "lines");
	gnuplot_resetplot(h);
	gnuplot_plot_xy(h, xdata, ydata, len, plot_name);

	return 0;
}
Пример #5
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Plotter::plot(std::vector<double> x,
                   std::vector<double> y,
                   const std::string& title)
{
	int size = x.size();
	double* xArray = new double[size];
	double* yArray = new double[size];
	std::copy(x.begin(), x.end(), xArray);
	std::copy(y.begin(), y.end(), yArray);

	if (_plotter)
		gnuplot_plot_xy(_plotter, xArray, yArray, size, const_cast<char*>(title.c_str()));

	delete [] xArray;
	delete [] yArray;
}
void BatchBinSet::plotBatchMu(const char* filename,
					const char* xlabel, const char* ylabel) {

	if (_num_batches == 0)
		log_printf(ERROR, "Cannot plot batch mu since the binners"
				" for this BatchBinSet have not yet been generated");

	else if (!_statistics_compute)
		log_printf(ERROR, "Cannot plot batch mu since is has not yet"
				" not yet been computed for this BatchBinSet");

	/* Plot the neutron flux */
		gnuplot_ctrl* handle = gnuplot_init();
		gnuplot_set_xlabel(handle, (char*)xlabel);
		gnuplot_set_ylabel(handle, (char*)ylabel);
		gnuplot_setstyle(handle, (char*)"dots");
		gnuplot_saveplot(handle, (char*)filename);
		gnuplot_plot_xy(handle, getBinner(0)->getBinCenters(),
				_batch_mu, _num_bins, (char*)"Batch Mu");
		gnuplot_close(handle);
}
void gnuplot_plot_once(
	char	*	title,
	char	*	style,
	char	*	label_x,
	char	*	label_y,
	double	*	x,
	double	*	y,
	int			n
)
{
	gnuplot_ctrl	*	handle ;

	if (x==NULL || n<1) return ;

	handle = gnuplot_init();
	if (style!=NULL) {
		gnuplot_setstyle(handle, style);
	} else {
		gnuplot_setstyle(handle, "lines");
	}
	if (label_x!=NULL) {
		gnuplot_set_xlabel(handle, label_x);
	} else {
		gnuplot_set_xlabel(handle, "X");
	}
	if (label_y!=NULL) {
		gnuplot_set_ylabel(handle, label_y);
	} else {
		gnuplot_set_ylabel(handle, "Y");
	}
	if (y==NULL) {
		gnuplot_plot_x(handle, x, n, title);
	} else {
		gnuplot_plot_xy(handle, x, y, n, title);
	}
	printf("press ENTER to continue\n");
	while (getchar()!='\n') {}
	gnuplot_close(handle);
	return ;
}
Пример #8
0
void ParticleListCPUSorted::plot_particles(PlasmaData* pdata)
{
	float* x_vals = (float*)malloc(nptcls*sizeof(realkind));
	float* y_vals = (float*)malloc(nptcls*sizeof(realkind));


	for(int i=0;i<nptcls;i++)
	{
		x_vals[i] = (px[i]+ix[i])*pdata->dxdi + pdata->xmin;
		//x_vals[i] = (py[i]+iy[i])*pdata->dydi + pdata->ymin;
		y_vals[i] = vx[i];
//		printf("particle[%i]: %f %f\n",i,x_vals[i],y_vals[i]);

	}

	gnuplot_resetplot(plot);

	gnuplot_plot_xy(plot,x_vals,y_vals,nptcls,NULL);


	free(x_vals);
	free(y_vals);
}
Пример #9
0
void TwoStream_Initializer::finish(ParticleList* particles,
		HOMoments** moments,HOMoments* moments_old,FieldData** fields,ParallelInfo* myinfo)
{


	// Print out the sum of the x-component of the current
	if(myinfo->myid_mpi == 0)
	{
		if(pdata->plot_flag)
		{
			gnuplot_resetplot(plot);
			gnuplot_cmd(plot,"set xlabel \"time\"");
			gnuplot_cmd(plot,"set ylabel \"Field Energy\"");
			gnuplot_plot_xy(plot,max_t_array,Energy_array,nplot,"PlasmaApp3D");
			gnuplot_cmd(plot,"replot \"E_vec.csv\" title \"Matlab Code\" with points");
			//getchar();
			gnuplot_save_pdf(plot,"TS_field_energy");
		}

	}

	MPI_Barrier(MPI_COMM_WORLD);

}
Пример #10
0
void 
PlotGraph::PlotBipartiteGraph(BipartiteGraph& _bg,
			      vector<VID>& _S, 
			      vector<VID>& _T,
			      vector<VID>& _N,
			      vector<EID>& _EG,
			      vector<EID>& _M, 
			      int target_task){

    //get assignment size, assume the sizes of agents and tasks are identical
    size_t as_size = _bg.GetNumAgents();
    double plx[as_size];
    double ply[as_size];

    //g=gnuplot_init();
    gnuplot_resetplot(g);
    gnuplot_cmd(g, (char*)"unset label");
    gnuplot_cmd(g, (char*)"set xrange [-0.25:%f]", as_size-1+.25);
    gnuplot_cmd(g, (char*)"set yrange [-0.25:1.25]");
    gnuplot_cmd(g, (char*)"set xtics 0");
    gnuplot_cmd(g, (char*)"set ytics 0");
    gnuplot_cmd(g, (char*)"set nokey");

    // Plot matching
    //cout<<endl<<"Set M: "<<endl;
    //DisplayData(_M);    
    for (unsigned int i = 0; i < _M.size(); i++){
        plx[0] = _M[i].first;
        ply[0] = 0.0;
        plx[1] = _M[i].second;
        ply[1] = 1.0;

        gnuplot_setstyle(g, (char*)"lines lc rgb \"red\" lw 3");
        gnuplot_plot_xy(g, plx, ply, 2, NULL);
    }

    // Plot admissible edges (EG)
    //cout<<"EG: "<<endl;
    //DisplayData(_EG);
    for(unsigned int i=0; i<_EG.size(); i++){
        plx[0] = _EG[i].first;
        ply[0] = 0.0;
        plx[1] = _EG[i].second;
        ply[1] = 1.0;

        gnuplot_setstyle(g, (char*)"lines lc rgb \"gray\"");
        gnuplot_plot_xy(g, plx, ply, 2, NULL);
                
        plx[0] = (0.9*plx[0] + 0.1*plx[1]);
        ply[0] = 0.11;
        gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#FFFFFF\" pt 7");
        gnuplot_plot_xy(g, plx, ply, 1, NULL);

        //cout<<"EG "<<i<<": "<<_bg.GetMatrix(_EG[i])->GetWeight()<<endl;
        gnuplot_cmd(g, (char*)"set label \"%d\" at %f-0.04,0.1 front tc rgb \"#4682B4\" font \",8\"", int(_bg.GetMatrix(_EG[i])->GetWeight()), plx[0]);
    }


    // Plot membership of set S
    //cout<<"S: "<<endl;
    //DisplayData(_S);
    for(unsigned int i=0; i<_S.size(); i++){
        plx[0] = _S[i];
        ply[0] = 0.0;
        gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"green\" pt 7");
        gnuplot_plot_xy(g, plx, ply, 1, NULL);
    }

    // Plot membership of the set T
    //cout<<"T: "<<endl;
    //DisplayData(_T);
    for(unsigned int i=0; i<_T.size(); i++){
        plx[0] = _T[i];
        ply[0] = 1.0;
        gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"#00BFFF\" pt 7");
        gnuplot_plot_xy(g, plx, ply, 1, NULL);
    }

        if (target_task != -1) // not yet unioned, but the reversal point for the 
        {                         // alternating path
            plx[0] = target_task;
            ply[0] = 1.0;
            gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"grey\" pt 7");
            gnuplot_plot_xy(g, plx, ply, 1, NULL);
        }


    // Plot nodes
    for(unsigned int i = 0; i < as_size; i++)
    {
        plx[i] = i;
        ply[i] = 0.0;
    }

    gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#102063\" pt 7");
    gnuplot_plot_xy(g, plx, ply, as_size, NULL);

    for(unsigned int i = 0; i < as_size; i++)
    {
        plx[i] = i;
        ply[i] = 1.0;
    }

    gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#102063\" pt 7");
    gnuplot_plot_xy(g, plx, ply, as_size, NULL);

    for (unsigned int i = 0; i < as_size; i++)
    {
        gnuplot_cmd(g, (char*)"set label \"x%d\" at %d-0.025,-0.08 tc rgb \"black\"", i, i);
        gnuplot_cmd(g, (char*)"set label \"y%d\" at %d-0.025,1.08 tc rgb \"black\"", i, i);
	//cout<<"Label "<<i<<": "<<_bg.GetAgent(i)->GetLabel()<<endl;
	//cout<<"Label "<<i<<": "<<_bg.GetTask(i)->GetLabel()<<endl;
        gnuplot_cmd(g, (char*)"set label \"%d\" at %d-0.025,-0.15 tc rgb \"#112244\"", int(_bg.GetAgent(i)->GetLabel()), i);
        gnuplot_cmd(g, (char*)"set label \"%d\" at %d-0.025,1.15 tc rgb \"#112244\"", int(_bg.GetTask(i)->GetLabel()), i);
    }

/*    //image setting
       set terminal png 
              {{no}transparent} {{no}interlace}
              {tiny | small | medium | large | giant}
              {font <face> {<pointsize>}}
              {size <x>,<y>} {{no}crop}
              {{no}enhanced}
              {<color0> <color1> <color2> ...}
*/

#ifdef SAVE_PLOTS
    stringstream ss;
    ss << setw(3) << setfill('0') << Cnt++;
    string postfix = ss.str();

    string name="save/plot"+postfix+".jpeg";
    gnuplot_cmd(g, (char*)"set terminal jpeg");
    //gnuplot_cmd(g, (char*)"set terminal jpeg small size 320,240");//bad
    gnuplot_cmd(g, (char*)"set output \"%s\"", name.c_str());
    printf("saved jpeg: \"%s\"\n", name.c_str());
#endif

    gnuplot_cmd(g, (char*)"replot");

    sleep(period);
    //gnuplot_close(g);
}
Пример #11
0
int main(int argc, const char **argv) {

	Options options(argc, argv);
	Timer timer;

	log_setlevel(options.getVerbosity());

	/* Get the number of neutrons, bins and batches */
	int num_neutrons = options.getNumNeutrons();
	int num_bins = options.getNumBins();
	int num_batches = options.getNumBatches();
    int num_threads = options.getNumThreads();
	int num_gen;
	int num_alive;

	log_printf(NORMAL, "Beginning two region problem with %d neutrons, "
			"%d bins, %d batches, %d threads...", num_neutrons, num_bins,
			num_batches, num_threads);

	/* Create a handle for plotting with gnuplot */
	gnuplot_ctrl* handle;


	/* Create a set of plotting flux bins for each batch */
	BatchBinSet* total_flux = new BatchBinSet();
	BatchBinSet* fuel_flux = new BatchBinSet();
	BatchBinSet* moderator_flux = new BatchBinSet();

	total_flux->createBinners(1E-6, 1E7, num_bins, num_batches,
							LOGARITHMIC, FLUX_ENERGY, (char*)"all");
	fuel_flux->createBinners(1E-6, 1E7, num_bins, num_batches,
							LOGARITHMIC, FLUX_ENERGY, (char*)"all");
	moderator_flux->createBinners(1E-6, 1E7, num_bins, num_batches,
							LOGARITHMIC, FLUX_ENERGY, (char*)"all");


	/* Create bins to compute total fission and absorption rates */
	BatchBinSet* tot_fiss_rate = new BatchBinSet();
	BatchBinSet* tot_abs_rate = new BatchBinSet();

	tot_fiss_rate->createBinners(1E-7, 1E7, 1, num_batches, EQUAL,
									FISSION_RATE_ENERGY, (char*)"all");
	tot_abs_rate->createBinners(1E-7, 1E7, 1, num_batches, EQUAL,
									ABSORPTION_RATE_ENERGY, (char*)"all");
	float nu_bar = 2.455;	/* CASMO edit for average # neutrons per fission */

	/* Create bins to compute two group cell-averaged cross-sections */
	BatchBinSet* capture_2G = new BatchBinSet();
	BatchBinSet* absorb_2G = new BatchBinSet();
	BatchBinSet* fission_2G = new BatchBinSet();
	BatchBinSet* elastic_2G = new BatchBinSet();
	BatchBinSet* total_2G = new BatchBinSet();
	BatchBinSet* two_group_flux = new BatchBinSet();

	float two_group_E_ranges[3] = {0.0, 0.625, 1E7};

	capture_2G->createBinners(two_group_E_ranges, 2, num_batches,
							CAPTURE_RATE_ENERGY, (char*)"all");
	absorb_2G->createBinners(two_group_E_ranges, 2, num_batches,
							ABSORPTION_RATE_ENERGY, (char*)"all");
	fission_2G->createBinners(two_group_E_ranges, 2, num_batches,
							FISSION_RATE_ENERGY, (char*)"all");
	elastic_2G->createBinners(two_group_E_ranges, 2, num_batches,
							ELASTIC_RATE_ENERGY, (char*)"all");
	total_2G->createBinners(two_group_E_ranges, 2, num_batches,
							COLLISION_RATE_ENERGY, (char*)"all");
	two_group_flux->createBinners(two_group_E_ranges, 2, num_batches,
									FLUX_ENERGY, (char*)"all");


	/* Create bins to compute two group isotopic cross-sections */
	BatchBinSet* H1_capture_rate_2G = new BatchBinSet();
	BatchBinSet* H1_elastic_rate_2G = new BatchBinSet();
	BatchBinSet* O16_elastic_rate_2G = new BatchBinSet();
	BatchBinSet* ZR90_elastic_rate_2G = new BatchBinSet();

	BatchBinSet* U235_capture_rate_2G = new BatchBinSet();
	BatchBinSet* U235_elastic_rate_2G = new BatchBinSet();
	BatchBinSet* U235_fission_rate_2G = new BatchBinSet();
	BatchBinSet* U238_capture_rate_2G = new BatchBinSet();
	BatchBinSet* U238_elastic_rate_2G = new BatchBinSet();
	BatchBinSet* U238_fission_rate_2G = new BatchBinSet();

	H1_capture_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										CAPTURE_RATE_ENERGY, (char*)"H1");
	H1_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										ELASTIC_RATE_ENERGY, (char*)"H1");
	O16_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										ELASTIC_RATE_ENERGY, (char*)"O16");
	ZR90_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										ELASTIC_RATE_ENERGY, (char*)"ZR90");

	U235_capture_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										CAPTURE_RATE_ENERGY, (char*)"U235");
	U235_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										ELASTIC_RATE_ENERGY, (char*)"U235");
	U235_fission_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										FISSION_RATE_ENERGY, (char*)"U235");
	U238_capture_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										CAPTURE_RATE_ENERGY, (char*)"U238");
	U238_elastic_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										ELASTIC_RATE_ENERGY, (char*)"U238");
	U238_fission_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
										FISSION_RATE_ENERGY, (char*)"U238");


	/* Create bins to compute moderator to fuel flux ratios */
	int num_ratios = 13;
	BatchBinSet* fuel_flux_ratio = new BatchBinSet();
	BatchBinSet* moderator_flux_ratio = new BatchBinSet();

	float flux_ratio_E_ranges[14] = {0.0, 0.1, 0.5, 1.0, 6.0, 10.0, 25.0,
									50.0, 100.0, 1000.0, 10000.0, 100000.0,
									500000.0, 10000000.0};

	fuel_flux_ratio->createBinners(flux_ratio_E_ranges, num_ratios,
							num_batches, FLUX_ENERGY, (char*)"all");

	moderator_flux_ratio->createBinners(flux_ratio_E_ranges, num_ratios,
							num_batches, FLUX_ENERGY, (char*)"all");


	/* Create bins to compute the diffusion coefficient for three methods */
	BatchBinSet* coll_rate_2G = new BatchBinSet();
	BatchBinSet* transport_rate_2G = new BatchBinSet();
	BatchBinSet* diffusion_rate_2G = new BatchBinSet();

	coll_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
								COLLISION_RATE_ENERGY, (char*)"all");
	transport_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
								TRANSPORT_RATE_ENERGY, (char*)"all");
	diffusion_rate_2G->createBinners(two_group_E_ranges, 2, num_batches,
								DIFFUSION_RATE_ENERGY, (char*)"all");


	/* 2-region pin cell geometric parameters (units in cm) */
	float r_fuel = 0.4096;
	float r_gap = 0.4178;
	float r_cladding = 0.4750;
	float pitch = 1.26;
	float p2 = pitch * pitch;

	/* 2-region homogenized densities (g/cm^3) and enrichment */
	float rho_fuel = 10.2;
	float rho_cladding = 6.549;
	float rho_coolant = 0.9966;
	float enrichment = 0.03035;

	/* Isotope number densities */
	float N_A = 6.023E23;	/* Avogadro's number (at / mol) */
	float N_U238 = rho_fuel*N_A*(1.0 - enrichment) / ((238.0 *
					(1.0 - enrichment)) + (235.0*enrichment) + (16.0*2.0));
	float N_U235 = rho_fuel*N_A*enrichment / ((238.0 *
					(1.0 - enrichment)) + (235.0*enrichment) + (16.0*2.0));
	float N_O16 = rho_fuel*N_A*2.0 / ((238.0 *
					(1.0 - enrichment)) + (235.0*enrichment) + (16.0*2.0));
	float N_ZR90 = rho_cladding*N_A / 90.0;
	float N_H2O = rho_coolant*N_A / 18.0;
	float N_H1 = rho_coolant*N_A*2.0 / 18.0;

	/* 2-region pin cell volumes (cm^3) */
	float v_fuel = M_PI*r_fuel*r_fuel;
	float v_gap = M_PI*(r_gap*r_gap - r_fuel*r_fuel);
	float v_cladding = M_PI*(r_cladding*r_cladding - r_gap*r_gap);
	float v_coolant = p2 - M_PI*r_cladding*r_cladding;
	float v_moderator = v_gap + v_cladding + v_coolant;
	float v_total = v_fuel + v_moderator;

	/* Compute homogenized moderator number densities using volume weighting */
	N_H2O *= (v_coolant / v_moderator);
	N_H1 *= (v_coolant / v_moderator);
	N_ZR90 *= (v_cladding / v_moderator);

	/* Dancoff factor from CASMO-5 */
	float dancoff = 0.277;

	/* Escape cross-section */
	float sigma_e = 1.0 / (2.0*r_fuel);

	/* Carlvik's two-term rational model */
	float A = (1.0 - dancoff) / dancoff;
	float alpha1 = ((5.0*A + 6.0) - sqrt(A*A + 36.0*A + 36.0)) /
														(2.0*(A+1.0));
	float alpha2 = ((5.0*A + 6.0) + sqrt(A*A + 36.0*A + 36.0)) /
														(2.0*(A+1.0));
	float beta = (((4.0*A + 6.0) / (A + 1.0)) - alpha1) / (alpha2 - alpha1);

	/* Print out the geometry parameters */
	log_printf(NORMAL, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "\t\t\t\tGeometry Parameters (cm)");
	log_printf(NORMAL, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "");
	log_printf(NORMAL, "r_fuel = %f", r_fuel);
	log_printf(NORMAL, "r_gap  = %f", r_gap);
	log_printf(NORMAL, "r_cladding = %f", r_cladding);
	log_printf(NORMAL, "pitch = %f", pitch);
	log_printf(NORMAL, "total cell area = %f", p2);
	log_printf(NORMAL, "v_fuel = %f", v_fuel);
	log_printf(NORMAL, "v_gap = %f", v_gap);
	log_printf(NORMAL, "v_cladding = %f", v_cladding);
	log_printf(NORMAL, "v_coolant = %f", v_coolant);
	log_printf(NORMAL, "v_moderator = %f", v_moderator);
	log_printf(NORMAL, "v_total = %f", v_total);
	log_printf(NORMAL, "");

	/* Print to the console the number densities */
	log_printf(NORMAL, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "\t\t\t\tNumber Densities (at/cm^3)");
	log_printf(NORMAL, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "");
	log_printf(NORMAL, "H1:\t%1.5e", N_H1);
	log_printf(NORMAL, "H2O:\t%1.5e", N_H2O);
	log_printf(NORMAL, "ZR90:\t%1.5e", N_ZR90);
	log_printf(NORMAL, "U235:\t%1.5e", N_U235);
	log_printf(NORMAL, "U238:\t%1.5e", N_U238);
	log_printf(NORMAL, "O16:\t%1.5e", N_O16);
	log_printf(NORMAL, "");

	/* Print to the console the collision probability parameters */
	log_printf(NORMAL, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "\t\t\tTwo Region Collision Probability Parameters");
	log_printf(NORMAL, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "");
	log_printf(NORMAL, "dancoff = %f", dancoff);
	log_printf(NORMAL, "sigma_e = %f", sigma_e);
	log_printf(NORMAL, "A = %f", A);
	log_printf(NORMAL, "alpha1 = %f", alpha1);
	log_printf(NORMAL, "alpha2 = %f", alpha2);
	log_printf(NORMAL, "beta = %f", beta);
	log_printf(NORMAL, "");


	/* Create isotopes*/
	char* delim = (char*)"\t";

	Isotope* H1 = new Isotope();
	H1->setA(1);
	H1->setIsotopeType((char*)"H1");
	H1->loadXS((char*)"pendf/h-1_capture.txt", CAPTURE, delim);
	H1->loadXS((char*)"pendf/h-1_elastic.txt", ELASTIC, delim);
	H1->setElasticAngleType(ISOTROPIC_LAB);
	H1->initializeThermalScattering(1E-6, 15, 1000, 15);

	Isotope* O16 = new Isotope();
	O16->setA(16);
	O16->setIsotopeType((char*)"O16");
	O16->loadXS((char*)"pendf/o-16_elastic.txt", ELASTIC, delim);
	O16->setElasticAngleType(ISOTROPIC_LAB);

	Isotope* ZR90 = new Isotope();
	ZR90->setA(90);
	ZR90->setIsotopeType((char*)"ZR90");
	ZR90->loadXS((char*)"pendf/zr-90_elastic.txt", ELASTIC, delim);
	ZR90->setElasticAngleType(ISOTROPIC_LAB);

	Isotope* U235 = new Isotope();
	U235->setA(235);
	U235->setIsotopeType((char*)"U235");
	U235->loadXS((char*)"pendf/u-235_capture.txt", CAPTURE, delim);
	U235->setOneGroupElasticXS(11.4, ISOTROPIC_LAB);
	U235->loadXS((char*)"pendf/u-235_fission.txt", FISSION, delim);

	Isotope* U238 = new Isotope();
	U238->setA(238);
	U238->setIsotopeType((char*)"U238");
	U238->loadXS((char*)"pendf/u-238_capture.txt", CAPTURE, delim);
	U238->setOneGroupElasticXS(11.3, ISOTROPIC_LAB);
	U238->loadXS((char*)"pendf/u-238_fission.txt", FISSION, delim);


	/* Create Materials */
	Material* moderator = new Material[num_threads];
	Material* fuel = new Material[num_threads];


	/* Create Regions for each thread */
	Region1D* pellet = new Region1D[num_threads];
	Region1D* coolant = new Region1D[num_threads];

	/* Create Fissioners for each thread */
	Fissioner* fissioners = new Fissioner[num_threads];

	/* Create Region class objects for each thread */
	for (int i=0; i < num_threads; i++) {

		/* Initialize Materials for each thread with isotope clones */
		moderator[i].setMaterialName((char*)"moderator");
		fuel[i].setMaterialName((char*)"fuel");

		moderator[i].addIsotope(ZR90->clone(), N_ZR90);
		moderator[i].addIsotope(H1->clone(), N_H1);
		moderator[i].addIsotope(O16->clone(), N_H2O);
		moderator[i].rescaleCrossSections(1E-7, 1E7, 50000, LOGARITHMIC);

		fuel[i].addIsotope(U235->clone(), N_U235);
		fuel[i].addIsotope(U238->clone(), N_U238);
		fuel[i].addIsotope(O16->clone(), N_O16);
		fuel[i].rescaleCrossSections(1E-7, 1E7, 50000, LOGARITHMIC);

		/* Set the two region collision probability parameters */
		pellet[i].setRegionName((char*)"pellet");
		pellet[i].setMaterial(&fuel[i]);
		pellet[i].setAsFuel();
		pellet[i].setOtherPinCellRegion(&coolant[i]);
		pellet[i].setVolume(v_fuel);
		pellet[i].setTwoRegionPinCellParams(sigma_e, beta, alpha1, alpha2);

		coolant[i].setRegionName((char*)"coolant");
		coolant[i].setMaterial(&moderator[i]);
		coolant[i].setAsModerator();
		coolant[i].setOtherPinCellRegion(&pellet[i]);
		coolant[i].setVolume(v_moderator);
		coolant[i].setTwoRegionPinCellParams(sigma_e, beta, alpha1, alpha2);

		/* Set the fissioner class for this thread to have 10MeV maximum and
		 * 5000 sample bins */
		fissioners[i].setEMax(10.0);
		fissioners[i].setNumBins(200);
		fissioners[i].buildCDF();
	}


	/* Run the simulation */
	log_printf(NORMAL, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "\t\t\t\tBeginning Simulation...");
	log_printf(NORMAL, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "");

	timer.start();

	omp_set_num_threads(num_threads);
	#pragma omp parallel shared(total_flux, fuel_flux, moderator_flux,\
							fuel_flux_ratio, moderator_flux_ratio,\
							tot_fiss_rate, tot_abs_rate, U235_capture_rate_2G,\
							U235_elastic_rate_2G, U235_fission_rate_2G,\
							U238_capture_rate_2G, U238_elastic_rate_2G,\
							U238_fission_rate_2G, H1_capture_rate_2G,\
							H1_elastic_rate_2G, O16_elastic_rate_2G,\
							ZR90_elastic_rate_2G, fuel, moderator, \
							pellet, coolant, fissioners)
	{
		/* Loop over batches */
		#pragma omp for private(num_gen, num_alive)
		for (int b=0; b < num_batches; b++) {

			int thread_num = omp_get_thread_num();
			log_printf(NORMAL, "Batch: %d\tThread: %d", b, thread_num);

			/* Set the binns for this batch */
			pellet[thread_num].clearBinners();
			pellet[thread_num].addBinner(total_flux->getBinner(b));
			pellet[thread_num].addBinner(fuel_flux->getBinner(b));
			pellet[thread_num].addBinner(fuel_flux_ratio->getBinner(b));
			pellet[thread_num].addBinner(tot_fiss_rate->getBinner(b));
			pellet[thread_num].addBinner(tot_abs_rate->getBinner(b));
			pellet[thread_num].addBinner(U235_capture_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(U235_elastic_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(U235_fission_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(U238_capture_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(U238_elastic_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(U238_fission_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(O16_elastic_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(two_group_flux->getBinner(b));
			pellet[thread_num].addBinner(coll_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(transport_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(diffusion_rate_2G->getBinner(b));
			pellet[thread_num].addBinner(capture_2G->getBinner(b));
			pellet[thread_num].addBinner(fission_2G->getBinner(b));
			pellet[thread_num].addBinner(absorb_2G->getBinner(b));
			pellet[thread_num].addBinner(elastic_2G->getBinner(b));
			pellet[thread_num].addBinner(total_2G->getBinner(b));

			coolant[thread_num].clearBinners();
			coolant[thread_num].addBinner(total_flux->getBinner(b));
			coolant[thread_num].addBinner(moderator_flux->getBinner(b));
			coolant[thread_num].addBinner(moderator_flux_ratio->getBinner(b));
			coolant[thread_num].addBinner(tot_fiss_rate->getBinner(b));
			coolant[thread_num].addBinner(tot_abs_rate->getBinner(b));
			coolant[thread_num].addBinner(H1_capture_rate_2G->getBinner(b));
			coolant[thread_num].addBinner(H1_elastic_rate_2G->getBinner(b));
			coolant[thread_num].addBinner(O16_elastic_rate_2G->getBinner(b));
			coolant[thread_num].addBinner(ZR90_elastic_rate_2G->getBinner(b));
			coolant[thread_num].addBinner(two_group_flux->getBinner(b));
			coolant[thread_num].addBinner(coll_rate_2G->getBinner(b));
			coolant[thread_num].addBinner(transport_rate_2G->getBinner(b));
			coolant[thread_num].addBinner(diffusion_rate_2G->getBinner(b));
			coolant[thread_num].addBinner(capture_2G->getBinner(b));
			coolant[thread_num].addBinner(fission_2G->getBinner(b));
			coolant[thread_num].addBinner(absorb_2G->getBinner(b));
			coolant[thread_num].addBinner(elastic_2G->getBinner(b));
			coolant[thread_num].addBinner(total_2G->getBinner(b));

			/* Initialize all neutrons for this batch and add them to slab 1 */
			for (int n=0; n < num_neutrons; n++) {
				neutron* new_neutron = initializeNewNeutron();
				new_neutron->_x = 0.0;
				new_neutron->_mu = (float(rand()) / RAND_MAX) * 2.0 - 1.0;
				new_neutron->_energy = fissioners[thread_num].emitNeutroneV();
				pellet[thread_num].addNeutron(new_neutron);
			}

			/* Loop over all neutrons until they are all dead */
			num_gen = 1;
			num_alive = num_neutrons;

			while (num_alive > 0) {

				log_printf(DEBUG, "batch = %d, thread = %d, gen = %d, "
						"num_alive = %d", b, thread_num, num_gen, num_alive);

				num_gen++;
				num_alive = 0;

				/* Transfer neutrons between regions based on
				 * two region collision probabilities */
				pellet[thread_num].twoRegionNeutronTransferral();
				coolant[thread_num].twoRegionNeutronTransferral();

				/* Update each region's vector of neutrons with those
				 * neutrons which were just transferred */
				pellet[thread_num].initializeTransferredNeutrons();
				coolant[thread_num].initializeTransferredNeutrons();

				/* Move neutrons within each region */
				pellet[thread_num].moveNeutrons();
				coolant[thread_num].moveNeutrons();

				num_alive = pellet[thread_num].getNumNeutrons() +
							coolant[thread_num].getNumNeutrons();
			}
		}
	}

	log_printf(NORMAL, "");

	/* Stop the timer record the timing split for this simulation */
	timer.stop();
	timer.recordSplit("Pset 4 time (sec)");

	/* Compute batch statistics for total flux and flux in fuel, moderator */
	total_flux->computeScaledBatchStatistics(num_neutrons*v_total);
	fuel_flux->computeScaledBatchStatistics(num_neutrons*v_fuel);
	moderator_flux->computeScaledBatchStatistics(num_neutrons*v_moderator);

	/* Compute batch statistics for total fission and absorption rates */
	tot_fiss_rate->computeScaledBatchStatistics(num_neutrons*v_total);
	tot_abs_rate->computeScaledBatchStatistics(num_neutrons*v_total);

	/* Compute batch statistics for cell-averaged macro cross-sections */
	capture_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	fission_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	absorb_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	elastic_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	total_2G->computeScaledBatchStatistics(num_neutrons*v_total);

	/* Compute batch statistics for one group cross-sections */
	H1_capture_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	H1_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	O16_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	ZR90_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	U235_capture_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	U235_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	U235_fission_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	U238_capture_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	U238_elastic_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	U238_fission_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	two_group_flux->computeScaledBatchStatistics(num_neutrons*v_total);
	coll_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	transport_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);
	diffusion_rate_2G->computeScaledBatchStatistics(num_neutrons*v_total);

	/* Compute k-infinity */
	float fiss_rate_mu = tot_fiss_rate->getBatchMu()[0];
	float fiss_rate_var = tot_fiss_rate->getBatchVariance()[0];
	float abs_rate_mu = tot_abs_rate->getBatchMu()[0];
	float abs_rate_var = tot_abs_rate->getBatchVariance()[0];

	float k_inf = fiss_rate_mu * nu_bar / abs_rate_mu;

	float k_inf_var = (fiss_rate_mu*fiss_rate_mu)*abs_rate_var +
						(abs_rate_mu*abs_rate_mu)*fiss_rate_var +
									fiss_rate_var*abs_rate_var;

	float k_inf_std_dev = sqrt(k_inf_var);

	/* Compute moderator to fuel flux ratios */
	fuel_flux_ratio->computeScaledBatchStatistics(num_neutrons*v_fuel);
	moderator_flux_ratio->computeScaledBatchStatistics(num_neutrons*v_moderator);
	fuel_flux_ratio->computeScaledBatchStatistics(num_neutrons*v_fuel);
	moderator_flux_ratio->computeScaledBatchStatistics(num_neutrons*v_moderator);

	/* Print to the console the total fission rate */
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "\t\t\tTotal Fission Rate (Batch Statistics)");
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(NORMAL, "");
	log_printf(RESULT, "Tot fission rate = %1.8f\t\tVariance = %1.8f",
									tot_fiss_rate->getBatchMu()[0],
									tot_fiss_rate->getBatchVariance()[0]);
	log_printf(RESULT, "Tot absorption rate = %f\t\tVariance = %f",
									tot_abs_rate->getBatchMu()[0],
									tot_abs_rate->getBatchVariance()[0]);
	log_printf(RESULT, "k_inf = %f\t\tvariance = %1.8f \t\t 2 sigma = %1.8f", k_inf,
													k_inf_var, k_inf_std_dev);
	log_printf(RESULT, "");

	/* Print to the console the moderator/fuel flux ratios */
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "\t\t\t\tModerator/Fuel Flux Ratios");
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "");

	float ratio;
	for (int i=1; i < num_ratios+1; i++) {

		ratio = moderator_flux_ratio->getBatchMu()[i-1] /
						fuel_flux_ratio->getBatchMu()[i-1];

		log_printf(RESULT, "[%2.e eV - %2.e eV]:\t%f",
				flux_ratio_E_ranges[i-1], flux_ratio_E_ranges[i], ratio);
	}

	log_printf(RESULT, "");


	/* Print to the console the cell-averaged fast to thermal flux ratio */
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "\t\t\tCell-Averaged Fast-to-Thermal Flux Ratio");
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "");
	double* two_group_flux_mu = two_group_flux->getBatchMu();
	double flux1 = two_group_flux_mu[0];
	double flux2 = two_group_flux_mu[1];
	log_printf(RESULT, "Ratio = %f", flux2 / flux1);
	log_printf(RESULT, "");


	/* Print to the console the two group macroscopic cross-sections */
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "\t\tTwo Group Macroscopic Cross-Sections (cm^-1)");
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "");

	float xs1, xs2;

	log_printf(RESULT, "\t\t\t[%1.1f eV - %1.3f eV]\t[%1.3f eV - %1.1e eV]",
						two_group_flux->getBinner(0)->getBinEdges()[0],
						two_group_flux->getBinner(0)->getBinEdges()[1],
						two_group_flux->getBinner(0)->getBinEdges()[1],
						two_group_flux->getBinner(0)->getBinEdges()[2]);

	/* H1 capture */
	xs1 = H1_capture_rate_2G->getBatchMu()[0] / flux1;
	xs2 = H1_capture_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "H1 Capture: \t\t%f\t\t%f", xs1, xs2);

	/* H1 elastic */
	xs1 = H1_elastic_rate_2G->getBatchMu()[0] / flux1;
	xs2 = H1_elastic_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "H1 Elastic: \t\t%f\t\t%f", xs1, xs2);

	/* O16 elastic */
	xs1 = O16_elastic_rate_2G->getBatchMu()[0] / flux1;
	xs2 = O16_elastic_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "O16 Elastic: \t\t%f\t\t%f", xs1, xs2);

	/* ZR90 elastic */
	xs1 = ZR90_elastic_rate_2G->getBatchMu()[0] / flux1;
	xs2 = ZR90_elastic_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "ZR90 Elastic: \t\t%f\t\t%f", xs1, xs2);

	/* U235 capture */
	xs1 = U235_capture_rate_2G->getBatchMu()[0] / flux1;
	xs2 = U235_capture_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "U235 Capture: \t\t%f\t\t%f", xs1, xs2);

	/* U235 elastic */
	xs1 = U235_elastic_rate_2G->getBatchMu()[0] / flux1;
	xs2 = U235_elastic_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "U235 Elastic: \t\t%f\t\t%f", xs1, xs2);

	/* U235 fission */
	xs1 = U235_fission_rate_2G->getBatchMu()[0] / flux1;
	xs2 = U235_fission_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "U235 Fission: \t\t%f\t\t%f", xs1, xs2);

	/* U238 capture */
	xs1 = U238_capture_rate_2G->getBatchMu()[0] / flux1;
	xs2 = U238_capture_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "U238 Capture: \t\t%f\t\t%f", xs1, xs2);

	/* U238 elastic */
	xs1 = U238_elastic_rate_2G->getBatchMu()[0] / flux1;
	xs2 = U238_elastic_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "U238 Elastic: \t\t%f\t\t%f", xs1, xs2);

	/* U238 fission */
	xs1 = U238_fission_rate_2G->getBatchMu()[0] / flux1;
	xs2 = U238_fission_rate_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "U238 Fission: \t\t%f\t\t%f", xs1, xs2);

	log_printf(RESULT, "");


	/* Print to the console the two group macroscopic cross-sections */
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "\tTwo Group Cell-Averaged Macroscopic "
			"Cross-Sections (cm^-1)");
	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "");

	log_printf(RESULT, "\t\t\t[%1.1f eV - %1.3f eV]\t[%1.3f eV - %1.1e eV]",
						two_group_flux->getBinner(0)->getBinEdges()[0],
						two_group_flux->getBinner(0)->getBinEdges()[1],
						two_group_flux->getBinner(0)->getBinEdges()[1],
						two_group_flux->getBinner(0)->getBinEdges()[2]);

	/* Flux */
	log_printf(RESULT, "Flux: \t\t\t%f\t\t%f", flux1, flux2);

	/* Capture */
	xs1 = capture_2G->getBatchMu()[0] / flux1;
	xs2 = capture_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "Capture: \t\t\t%f\t\t%f", xs1, xs2);

	/* Fission */
	xs1 = fission_2G->getBatchMu()[0] / flux1;
	xs2 = fission_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "Fission: \t\t\t%f\t\t%f", xs1, xs2);

	/* Absorption */
	xs1 = absorb_2G->getBatchMu()[0] / flux1;
	xs2 = absorb_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "Absorb: \t\t\t%f\t\t%f", xs1, xs2);

	/* Elastic */
	xs1 = elastic_2G->getBatchMu()[0] / flux1;
	xs2 = elastic_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "Elastic: \t\t\t%f\t\t%f", xs1, xs2);

	/* Total */
	xs1 = total_2G->getBatchMu()[0] / flux1;
	xs2 = total_2G->getBatchMu()[1] / flux2;
	log_printf(RESULT, "Total: \t\t\t%f\t\t%f", xs1, xs2);
	log_printf(RESULT, "");


	/* Print to the console the two group macroscopic cross-sections */
	log_printf(RESULT, "*******************************************************"
												"*************************");
	log_printf(RESULT, "\t\t\tTwo Group Diffusion Coefficients");
	log_printf(RESULT, "*******************************************************"
												"*************************");
	log_printf(RESULT, "");
	log_printf(RESULT, "\t\t\t[%1.1f eV - %1.3f eV]\t[%1.3f eV - %1.1e eV]",
						two_group_flux->getBinner(0)->getBinEdges()[0],
						two_group_flux->getBinner(0)->getBinEdges()[1],
						two_group_flux->getBinner(0)->getBinEdges()[1],
						two_group_flux->getBinner(0)->getBinEdges()[2]);

	float sigma_t1, sigma_t2;
	float sigma_tr1, sigma_tr2;
	float D1, D2;

	sigma_t1 = coll_rate_2G->getBatchMu()[0] / flux1;
	sigma_t2 = coll_rate_2G->getBatchMu()[1] / flux2;
	D1 = 1.0 / (3.0 * sigma_t1);
	D2 = 1.0 / (3.0 * sigma_t2);

	log_printf(RESULT, "1/(3*sigma_t):\t\t%f\t\t%f", D1, D2);

	sigma_tr1 = transport_rate_2G->getBatchMu()[0] / flux1;
	sigma_tr2  = transport_rate_2G->getBatchMu()[1] / flux2;
	D1 = 1.0 / (3.0 * sigma_tr1);
	D2 = 1.0 / (3.0 * sigma_tr2);

	log_printf(RESULT, "1/(3*sigma_tr):\t\t%f\t\t%f", D1, D2);

	D1 = diffusion_rate_2G->getBatchMu()[0] / flux1;
	D2 = diffusion_rate_2G->getBatchMu()[1] / flux2;

	log_printf(RESULT, "Diff coeff:\t\t%f\t\t%f", D1, D2);

	log_printf(RESULT, "");


	/* Plot the total neutron flux */
	handle = gnuplot_init();
	gnuplot_set_xlabel(handle, (char*)"Energy (eV)");
	gnuplot_set_ylabel(handle, (char*)"flux");
	gnuplot_set_xrange(handle, 0.005, 1E7);
	gnuplot_cmd(handle, (char*)"set logscale xy");
	gnuplot_cmd(handle, (char*)"set title \"Normalized Flux\"");
	gnuplot_setstyle(handle, (char*)"lines");
	gnuplot_plot_xy(handle, total_flux->getBinner(0)->getBinCenters(),
			total_flux->getBatchMu(), num_bins, (char*)"Total Flux");
	gnuplot_plot_xy(handle, fuel_flux->getBinner(0)->getBinCenters(),
			fuel_flux->getBatchMu(), num_bins, (char*)"Fuel Flux");
	gnuplot_saveplot(handle, (char*)"flux");
	gnuplot_plot_xy(handle, moderator_flux->getBinner(0)->getBinCenters(),
			moderator_flux->getBatchMu(), num_bins, (char*)"Moderator Flux");
	gnuplot_close(handle);


	/* Free all allocated memory */
	delete [] pellet;
	delete [] coolant;
	delete [] fissioners;

	delete [] moderator;
	delete [] fuel;

	delete total_flux;
	delete fuel_flux;
	delete moderator_flux;
	delete tot_fiss_rate;
	delete tot_abs_rate;
	delete fuel_flux_ratio;
	delete moderator_flux_ratio;
	delete H1_capture_rate_2G;
	delete H1_elastic_rate_2G;
	delete O16_elastic_rate_2G;
	delete U235_capture_rate_2G;
	delete U235_elastic_rate_2G;
	delete U235_fission_rate_2G;
	delete U238_capture_rate_2G;
	delete U238_elastic_rate_2G;
	delete U238_fission_rate_2G;
	delete ZR90_elastic_rate_2G;
	delete two_group_flux;
	delete coll_rate_2G;
	delete transport_rate_2G;
	delete diffusion_rate_2G;

	delete H1;
	delete O16;
	delete ZR90;
	delete U235;
	delete U238;

	log_printf(RESULT, "*******************************************************"
													"*************************");
	log_printf(RESULT, "\t\t\t\tTiming Results");
	log_printf(RESULT, "*******************************************************"
													"*************************");
	timer.printSplits();
}
Пример #12
0
void draw_graph(int new_member_of_T)
{
    double plx[N];
    double ply[N];
    int count = 0;

    if (!graph) return;

    reinit_graph(g);
    gnuplot_cmd(g, "unset label");
    gnuplot_cmd(g, "set xrange [-0.25:1.25]");
    gnuplot_cmd(g, "set yrange [-0.25:%f]", n-1+.25);
    gnuplot_cmd(g, "set xtics 0");
    gnuplot_cmd(g, "set ytics 0");
    gnuplot_cmd(g, "set nokey");

    // Plot matching
    for (int i = 0; i < n; i++)
    {
        if (xy[i] >= 0)
        {
            plx[0] = 0.0;
            ply[0] = n-i-1;
            plx[1] = 1.0;
            ply[1] = n-xy[i]-1;

            gnuplot_setstyle(g, "lines lc rgb \"#55DD99\" lw 3");
            gnuplot_plot_xy(g, plx, ply, 2, NULL);

        }

    }

    // Plot edges 
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (cost[i][j] == lx[i] + ly[j])
            {
                plx[0] = 0.0;
                ply[0] = n-i-1;
                plx[1] = 1.0;
                ply[1] = n-j-1;

                gnuplot_setstyle(g, "lines lc rgb \"gray\"");
                gnuplot_plot_xy(g, plx, ply, 2, NULL);

                
                plx[0] = 0.11;
                ply[0] = (0.9*ply[0] + 0.1*ply[1]);
                gnuplot_setstyle(g, "points pointsize 2 lc rgb \"#FFFFFF\" pt 7");
                gnuplot_plot_xy(g, plx, ply, 1, NULL);


                gnuplot_cmd(g, "set label \"%d\" at 0.1,%f front tc rgb \"magenta\"", cost[i][j], ply[0]);
            }
        }
    }

    // Plot membership of the S / T sets
    for (int i = 0; i < n; i++)
    {
        if (S[i])
        {
                plx[0] = 0.0;
                ply[0] = n-i-1;
                gnuplot_setstyle(g, "points pointsize 3 lc rgb \"#99AAFF\" pt 7");
                gnuplot_plot_xy(g, plx, ply, 1, NULL);
        }

        if (T[i])
        {
                plx[0] = 1.0;
                ply[0] = n-i-1;
                gnuplot_setstyle(g, "points pointsize 3 lc rgb \"#FF99AA\" pt 7");
                gnuplot_plot_xy(g, plx, ply, 1, NULL);
        }

        if (i == new_member_of_T) // not yet unioned, but the reversal point for the 
        {                         // laternating path
            plx[0] = 1.0;
            ply[0] = n-i-1;
            gnuplot_setstyle(g, "points pointsize 3 lc rgb \"#FF99FF\" pt 7");
            gnuplot_plot_xy(g, plx, ply, 1, NULL);
        }

    }


    // Plot nodes
    count = 0;
    for (int i = 0; i < n; i++)
    {
        plx[count] = 0.0;
        ply[count] = i;
        count++;
    }

    for (int i = 0; i < n; i++)
    {
        plx[count] = 1.0;
        ply[count] = i;
        count++;
    }

    gnuplot_setstyle(g, "points pointsize 2 lc rgb \"#102063\" pt 7");
    gnuplot_plot_xy(g, plx, ply, count, NULL);

    for (int i = 0; i < n; i++)
    {
        gnuplot_cmd(g, "set label \"x%d\" at -0.075,%d tc rgb \"black\"", i, n-i-1);
        gnuplot_cmd(g, "set label \"y%d\" at  1.02,%d tc rgb \"black\"", i, n-i-1);

        gnuplot_cmd(g, "set label \"%d\" at -0.175,%d tc rgb \"#112244\"", lx[i], n-i-1);
        gnuplot_cmd(g, "set label \"%d\" at 1.12,%d tc rgb \"#112244\"", ly[i], n-i-1);
    }

    gnuplot_cmd(g, "replot");

}
Пример #13
0
void draw_bfs_tree(int root, int addx, bool high_light_root)
{
    bool myS[N], myT[N];         //sets S and T in algorithm
    bool leaf[N];
    double edgex[2];
    double edgey[2];
    int i, j;
    int q[N], wr = 0, rd = 0;          //q - queue for bfs, wr,rd - write and read

    int level[N];

    memset(myS, false, sizeof(S));      
    memset(myT, false, sizeof(T));       
    memset(leaf, false, sizeof(leaf));       
    memset(level, -1, sizeof(level));       

    level[root] = 0;
    S[root] = true;

    q[wr++] = root;
    while (rd < wr)                                                 
    {
        i = q[rd++];         

        if ((root == i) && (high_light_root))
            gnuplot_cmd(h, "set label \"x%d\" at %f,%f front tc rgb \"red\"", i, (float)i+addx, (float)-level[i]);
        else
            gnuplot_cmd(h, "set label \"x%d\" at %f,%f front tc rgb \"black\"", i, (float)i+addx, (float)-level[i]);
        

        for (j = 0; j < n; j++)                                     
        {
                if (cost[i][j] == lx[i] + ly[j] &&  !myT[j])
                {
                    // plot edge between i and j
                    edgex[0] = i+addx;
                    edgey[0] = -level[i];
                    edgex[1] = j+addx;
                    edgey[1] = -(level[i]+0.5);

                    gnuplot_setstyle(h, "lines lc rgb \"#FF2222\" lw 2");
                    gnuplot_plot_xy(h, edgex, edgey, 2, NULL);

                    gnuplot_cmd(h, "set label \"y%d\" at %f,%f front tc rgb \"black\"", j, edgex[1], edgey[1]);

                    leaf[j] = (yx[j] == -1);
                    
                    myT[j] = true;

                    if (!leaf[j])
                    {
                        q[wr++] = yx[j];
                        myS[yx[j]] = true;
                        level[yx[j]] = level[i] + 1;

                        edgex[0] = yx[j]+addx;
                        edgey[0] = -level[yx[j]];
                        edgex[1] = j+addx;
                        edgey[1] = -(level[i]+0.5);

                        gnuplot_setstyle(h, "lines lc rgb \"#FFFF22\" lw 2");
                        gnuplot_plot_xy(h, edgex, edgey, 2, NULL);


                    }
                    else
                    {

                    }

                    
                }
        }
    }
    

}
Пример #14
0
int main(int argc,char* argv[])
{

	PlasmaData pdata(argc,argv);
	gnuplot_ctrl* plot;
	gnuplot_ctrl* plot_anim;


	plot = gnuplot_init();
	plot_anim = gnuplot_init();
	gnuplot_setstyle(plot,"lines");
	gnuplot_setstyle(plot_anim,"points");

	gnuplot_cmd(plot_anim,"set term gif animate nooptimize size 1280,1280 xffffffff");
	gnuplot_cmd(plot_anim,"set output \"particles.gif\"");

	gnuplot_cmd(plot_anim,"set xrange [-1:1]");
	gnuplot_cmd(plot_anim,"set yrange [-1:1]");

	float xmin = 0;
	float ymin = 0;
	float zmin = 0;

	float Lx = 5.0;
	float Ly = 5.0;
	float Lz = 5.0;

	int nx = 64;
	int ny = 64;
	int nz = 64;

	int nspecies = 1;

	const float dt = 0.01;

	const float dtau0 = 0.1;

	const int nptcls = 500;
	const int steps = 200;

	int iptcl[nptcls];

	float Ey = 5.0;
	float Bz = 100.0;




	pdata.nx = nx;
	pdata.ny = ny;
	pdata.nz = nz;

	pdata.Lx = Lx;
	pdata.Ly = Ly;
	pdata.Lz = Lz;

	pdata.xmin = xmin;
	pdata.ymin = ymin;
	pdata.zmin = zmin;
	pdata.epsilon_a = 1.0e-4;
	pdata.epsilon_r = 1.0e-10;

	pdata.dt = dt;

	pdata.niter_max = 20;

	pdata.nSubcycle_max = 1000;

	pdata.Bmag_avg = 1.0;
	pdata.ndimensions = 3;

	pdata.setup();

	FieldDataCPU fields;
	ParticleListCPU particles;
	HOMoments* moments;

	int numprocs = omp_get_num_procs();

	moments = (HOMoments*)malloc(numprocs*sizeof(HOMoments));

	for(int i=0;i<numprocs;i++)
	{
		moments[i] = *new HOMoments(&pdata);
	}
	float x_plot[nptcls][steps];
	float y_plot[nptcls][steps];
	float gx_plot[nptcls][steps];
	float gy_plot[nptcls][steps];

	float error_array[nptcls];


	//float x_plot_a[nptcls];
	//float y_plot_a[nptcls];


	fields.allocate(&pdata);
	particles.allocate(nptcls);

	fields.dx = pdata.dxdi;
	fields.dy = pdata.dydi;
	fields.dz = pdata.dzdi;

	particles.ispecies = 0;






	for(int i=0;i<nptcls;i++)
	{
		iptcl[i] = i;

		particles.px[i] = rand()%10000/10000.0;
		particles.py[i] = rand()%10000/10000.0;
		particles.pz[i] = 0.5;

		particles.ix[i] = nx/2;
		particles.iy[i] = ny/2;
		particles.iz[i] = nz/2;

		particles.vx[i] = 0.5*(2*(rand()%10000))/10000.0 + 0.5;
		particles.vy[i] = 0.5*(2*(rand()%10000))/10000.0 + 0.5;
		particles.vz[i] = 0.0* (rand()%50000 / 50000.0f - 0.5);

		error_array[i] = 0;


	}



	// Setup E-field
	for(int i=0;i<nx;i++)
	{
		for(int j=0;j<ny;j++)
		{
			for(int k=0;k<nz;k++)
			{
				float x = i*pdata.dxdi+xmin;
				float y = j*pdata.dydi+ymin;
				float z = k*pdata.dzdi+zmin;

				float Ex = -1.0*x;


				fields.getE(i,j,k,0) = 0;
				fields.getE(i,j,k,1) = Ey;
				fields.getE(i,j,k,2) = 0;

				fields.getB(i,j,k,0) = 0;
				fields.getB(i,j,k,1) = 0;
				fields.getB(i,j,k,2) = Bz;


			//	printf("fields(%i,%i,%i) = %f, %f, %f\n",i,j,k,
				//	fields.getE(i,j,k,0),fields.getE(i,j,k,1),fields.getE(i,j,k,2));
			}
		}
	}

	fields.q2m[0] = 1.0;

	printf("Efield setup complete\n");

	float time;
	double avg_error = 0.0;
	int n_error = 0;

	CPUTimer timer;


	moments->init_plot();

	timer.start();
	for(int i=0;i<steps;i++)
	{
		//time = dtau0*(i);


		//moments.set_vals(0);
		particles.push(&pdata,&fields,moments);
		printf("finished step %i\n",i);


		for(int j=0;j<nptcls;j++)
		{

			float px,py,gx,gy;
			float rl;
			float vx,vy,vxy,vz,vxyz;

			float vgx,vgy;
			float verror;

			px = (particles.px[j] + particles.ix[j])*pdata.dxdi + pdata.xmin;
			py = (particles.py[j] + particles.iy[j])*pdata.dydi + pdata.ymin;

			vx = particles.vx[j];
			vy = particles.vy[j];
			vz = particles.vz[j];
			vxy = sqrt(vx*vx+vy*vy);

			vxyz = sqrt(vxy*vxy + vz*vz);

			rl = vxy/Bz;

			gx = vy*Bz/sqrt(vx*Bz*vx*Bz + vy*Bz*vy*Bz)*rl + px;
			gy = -vx*Bz/sqrt(vx*Bz*vx*Bz + vy*Bz*vy*Bz)*rl + py;

			x_plot[j][i] = px;
			y_plot[j][i] = py;

			gx_plot[j][i] = gx;
			gy_plot[j][i] = gy;

			if(i >= 1)
			{
				vgx = (gx_plot[j][i] - gx_plot[j][0])/(dt*(i));
				vgy = (gy_plot[j][i] - gy_plot[j][0])/(dt*(i));

				verror = fabs(Ey/Bz - vgx)/(Ey/Bz);

				error_array[j] = fmax(error_array[j],verror);

				avg_error += verror;
				n_error ++;

			//	printf("true[%i] v = %e, %e actual v = %e, %e, error = %e\n",
			//			j,Ey/Bz,0.0f,vgx,vgy,verror);
			}

		}




		//if((i+1)%64 == 0)
		//gnuplot_resetplot(plot_anim);
/*
		float diff_avg = 0.0;
		for(int j=0;j<nptcls;j++)
		{

			x_plot[j][i] = (particles.px[j] + particles.ix[j])*pdata.dxdi + pdata.xmin;
			y_plot[j][i] = (particles.py[j] + particles.iy[j])*pdata.dydi + pdata.ymin;

			//printf("particle %i with position %f, %f\n",j,x_plot[j][i],y_plot[j][i]);

		//	x_plot_a[j] = x_plot[j][i];
		//	y_plot_a[j] = y_plot[j][i];

		}
*/

		//avg_error += diff_avg / steps;


		//gnuplot_plot_xy(plot_anim,x_plot_a,y_plot_a,nptcls,NULL);


	}
	timer.stop();
	printf("average error = %e \n",avg_error/((float)n_error));
	printf("Run did %f particles per second\n",nptcls*steps/(timer.diff()*1.0e-3));

	for(int j=0;j<nptcls;j++)
	{
		if(error_array[j] >= 1.0e-2)
			gnuplot_plot_xy(plot,x_plot[j],y_plot[j],steps,NULL);


	}


	//moments->plot(nz/2,0,HOMoments_currentx);


	printf("Press 'Enter' to continue\n");
		getchar();

	moments->close_plot();



	gnuplot_close(plot);

	gnuplot_close(plot_anim);

}
Пример #15
0
void plotData(const parameters * p, fit_results * fr, plot_data * pd)
{
  int i;
  char * str=(char*)calloc(256,sizeof(char));
  plotOpen=1; 
  handle=gnuplot_init();
    
  printf("\nDATA PLOTS\n----------\n");
  
  if(strcmp(p->plotMode,"1d")==0)
    {
      for(i=0;i<p->numVar;i++)
        {
          gnuplot_setstyle(handle,"points"); //set style for grid points
          if(strcmp(p->dataType,"chisq")==0)
            gnuplot_cmd(handle,"set ylabel 'Chisq'");
          else  
            gnuplot_cmd(handle,"set ylabel 'Value'");
          sprintf(str,"set xlabel 'Parameter %i'",i+1);
          gnuplot_cmd(handle,str);
          gnuplot_plot_xy(handle, pd->data[i][i], pd->data[i][p->numVar], pd->plotDataSize[i], "Data");
          if(pd->axisLabelStyle[i][i]==1)
            gnuplot_cmd(handle,"set format x '%%12.2E'");
          if(pd->axisLabelStyle[i][p->numVar]==1)
            gnuplot_cmd(handle,"set format y '%%12.2E'");
          gnuplot_setstyle(handle,"lines");//set style for fit data
          if(p->numVar==1)
            {
              gnuplot_plot_xy(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPlotPts, "Fit");
            }  
          else
            {
              if(i==0)
                gnuplot_plot_xy(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPtsPerVar, "Fit");
              else if(i==1)
                gnuplot_plot_xygrid(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, "Fit");
              else if(i==2)
                gnuplot_plot_xygrid(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, pd->numFitPtsPerVar*pd->numFitPtsPerVar, 0, "Fit");
            }
          //strcpy(str,fr->fitForm[i]);//retrieve fit data functional form
          //gnuplot_plot_equation(handle, str, "Fit (function)");
          //plot confidence intervals
          if(p->plotCI==1)
          	{
          		gnuplot_plot_xy(handle,fr->ciXVal[i],fr->ciUVal[i],CI_DIM,"Upper 1-sigma confidence band");
          		gnuplot_plot_xy(handle,fr->ciXVal[i],fr->ciLVal[i],CI_DIM,"Lower 1-sigma confidence band");
          		/*strcpy(str,fr->ciUForm[0]);
          		gnuplot_plot_equation(handle, str, "Upper 95% confidence band");
          		strcpy(str,fr->ciLForm[0]);
          		gnuplot_plot_equation(handle, str, "Lower 95% confidence band");
          		strcpy(str,fr->piUForm[0]);
          		gnuplot_plot_equation(handle, str, "Upper 95% prediction band");
          		strcpy(str,fr->piLForm[0]);
          		gnuplot_plot_equation(handle, str, "Lower 95% prediction band");*/
          	}
          printf("Showing plot for parameter %i.\n",i+1);
          if(p->numVar==3)
            {
              if(i==0)
                printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",2,pd->fixedParVal[1],3,pd->fixedParVal[2]);
              if(i==1)
                printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",1,pd->fixedParVal[0],3,pd->fixedParVal[2]);
              if(i==2)
                printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",1,pd->fixedParVal[0],2,pd->fixedParVal[1]);
            }
          else if(p->numVar==2)
            {
              if(i==0)
                printf("Parameter %i fixed to %Lf\n",2,pd->fixedParVal[1]);
              if(i==1)
                printf("Parameter %i fixed to %Lf\n",1,pd->fixedParVal[0]);
            }
          printf("%i data points available for plot.\n",pd->plotDataSize[i]);
          if(i<(p->numVar-1))
            plotPrompt(1);
          else
            plotPrompt(0);
          gnuplot_resetplot(handle);
        }
    }
  else if(strcmp(p->plotMode,"2d")==0)
    {
      if(p->numVar==3)
        {
          for(i=0;i<p->numVar;i++)
            {
              gnuplot_setstyle(handle,"points"); //set style for grid points
              if(i==0)
                {
                  gnuplot_plot_xyz(handle, pd->data[i][1], pd->data[i][2], pd->data[i][p->numVar], pd->plotDataSize[i], "Data");
                  if(pd->axisLabelStyle[i][1]==1)
                    gnuplot_cmd(handle,"set format x '%%12.2E'");
                  if(pd->axisLabelStyle[i][2]==1)
                    gnuplot_cmd(handle,"set format y '%%12.2E'");
                  if(pd->axisLabelStyle[i][p->numVar]==1)
                    gnuplot_cmd(handle,"set format z '%%12.2E'");
                  sprintf(str,"set xlabel 'Parameter 2'; set ylabel 'Parameter 3'");
                }
              else if(i==1)
                {
                  gnuplot_plot_xyz(handle, pd->data[i][0], pd->data[i][2], pd->data[i][p->numVar], pd->plotDataSize[i], "Data");
                  if(pd->axisLabelStyle[i][0]==1)
                    gnuplot_cmd(handle,"set format x '%%12.2E'");
                  if(pd->axisLabelStyle[i][2]==1)
                    gnuplot_cmd(handle,"set format y '%%12.2E'");
                  if(pd->axisLabelStyle[i][p->numVar]==1)
                    gnuplot_cmd(handle,"set format z '%%12.2E'");
                  sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 3'");
                }
              else if(i==2)
                {
                  gnuplot_plot_xyz(handle, pd->data[i][0], pd->data[i][1], pd->data[i][p->numVar], pd->plotDataSize[i], "Data");
                  if(pd->axisLabelStyle[i][0]==1)
                    gnuplot_cmd(handle,"set format x '%%12.2E'");
                  if(pd->axisLabelStyle[i][1]==1)
                    gnuplot_cmd(handle,"set format y '%%12.2E'");
                  if(pd->axisLabelStyle[i][p->numVar]==1)
                    gnuplot_cmd(handle,"set format z '%%12.2E'");
                  sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'");
                }
              if(strcmp(p->dataType,"chisq")==0)
                gnuplot_cmd(handle,"set zlabel 'Chisq'");
              else  
                gnuplot_cmd(handle,"set zlabel 'Value'");
              gnuplot_cmd(handle,str);
              gnuplot_setstyle(handle,"lines");
              gnuplot_cmd(handle,"set grid");//set style for fit data
              if(i==0)
                gnuplot_plot_xyzgrid(handle, pd->fit[i][1], pd->fit[i][2], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, "Fit");
              else if(i==1)
                gnuplot_plot_xyzgrid(handle, pd->fit[i][0], pd->fit[i][2], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, 0, pd->numFitPtsPerVar, "Fit");
              else if(i==2)
                gnuplot_plot_xyzgrid(handle, pd->fit[i][0], pd->fit[i][1], pd->fit[i][p->numVar], pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, 0, "Fit");
              //strcpy(str,fr->fitForm[i]);//retrieve fit data functional form
              //gnuplot_plot_equation(handle, str, "Fit (function)");
              printf("Showing surface plot with parameter %i fixed to %Lf\n",i+1,pd->fixedParVal[i]);
              printf("%i data points available for plot.\n",pd->plotDataSize[i]);
              if(i<(p->numVar-1))
                plotPrompt(1);
              else
                plotPrompt(0);
              gnuplot_resetplot(handle);
            }
        }
      else if(p->numVar==2)
        {
          gnuplot_setstyle(handle,"points"); //set style for grid points
          gnuplot_plot_xyz(handle, pd->data[0][0], pd->data[0][1], pd->data[0][p->numVar], pd->plotDataSize[0], "Data");
          if(pd->axisLabelStyle[0][0]==1)
            gnuplot_cmd(handle,"set format x '%%12.2E'");
          if(pd->axisLabelStyle[0][1]==1)
            gnuplot_cmd(handle,"set format y '%%12.2E'");
          if(pd->axisLabelStyle[0][p->numVar]==1)
            gnuplot_cmd(handle,"set format z '%%12.2E'"); 
          if(strcmp(p->dataType,"chisq")==0)
            gnuplot_cmd(handle,"set zlabel 'Chisq'");
          else  
            gnuplot_cmd(handle,"set zlabel 'Value'");
          sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'");
          gnuplot_cmd(handle,str);
          gnuplot_setstyle(handle,"lines");
          gnuplot_cmd(handle,"set grid");//set style for fit data
          //gnuplot_cmd(handle,"set dgrid3d 30,30 qnorm 2");//set style for fit data
          gnuplot_plot_xyzgrid(handle, pd->fit[0][0], pd->fit[0][1], pd->fit[0][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, 0, 0, "Fit");
          //strcpy(str,fr->fitForm[0]);//retrieve fit data functional form
          //gnuplot_plot_equation(handle, str, "Fit (function)");
          printf("Showing surface plot.\n");
          printf("%i data points available for plot.\n",pd->plotDataSize[0]);
          plotPrompt(0);
          gnuplot_resetplot(handle);
        }
    }
  else if(strcmp(p->plotMode,"3d")==0)
    {
      if(p->numVar==3)
        {
          gnuplot_setstyle(handle,"points"); //set style for grid points
          gnuplot_plot_xyza(handle, pd->data[0][0], pd->data[0][1], pd->data[0][2], pd->data[0][p->numVar], pd->plotDataSize[0], "Data");
          if(pd->axisLabelStyle[0][0]==1)
            gnuplot_cmd(handle,"set format x '%%12.2E'");
          if(pd->axisLabelStyle[0][1]==1)
            gnuplot_cmd(handle,"set format y '%%12.2E'");
          if(pd->axisLabelStyle[0][2]==1)
            gnuplot_cmd(handle,"set format z '%%12.2E'");
          sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'; set zlabel 'Parameter 3'");
          gnuplot_cmd(handle,str);
          sprintf(str,"set cbrange [%f:%f]",pd->min_m,pd->max_m); //set the color bar range
          gnuplot_cmd(handle,str);
          if(strcmp(p->fitType,"par3")==0)
            {
              gnuplot_setcolor(handle,"black");
              gnuplot_cmd(handle,"set pointsize 1.5");
              double xVert=(double)fr->fitVert[0];
              double yVert=(double)fr->fitVert[1];
              double zVert=(double)fr->fitVert[2];
              gnuplot_plot_xyz(handle, &xVert, &yVert, &zVert, 1, "Fit Vertex");
            }
          printf("Showing heatmap plot.\n");
          printf("%i data points available for plot.\n",pd->plotDataSize[0]);
          plotPrompt(0);
          gnuplot_resetplot(handle);
        }
    }
  else
    {
      printf("ERROR: The plot mode '%s' defined in the data file '%s' is not supported!\n",p->plotMode,p->filename);
      exit(-1);
    }

}
Пример #16
0
int main(int argc,char* argv[])
{
	PlasmaData pdata(argc,argv);


	FieldDataCPU fields;

	pdata.Lx = 1.0;
	pdata.Ly = 1.0;
	pdata.Lz = 1.0;

	pdata.setup();
	fields.allocate(&pdata);

	int nx = pdata.nx;
	int ny = pdata.ny;
	int nz = pdata.nz;
	int nshape = 100;

	float shape1[nshape];
	float shape2[nshape];
	float shapex[nshape];

	for(int i=0;i<nshape;i++)
	{
		float x = i*4.0/nshape - 2.0;

		shape1[i] = S1_shape(x);
		shape2[i] = S2_shape(x);
		shapex[i] = x;
	}


	gnuplot_ctrl* shape_plot = gnuplot_init();

	gnuplot_plot_xy(shape_plot,shapex,shape1,nshape,"Shape 1");
	gnuplot_plot_xy(shape_plot,shapex,shape2,nshape,"Shape 2");



	// Setup E-field
	for(int i=0;i<pdata.nx;i++)
	{
		for(int j=0;j<pdata.ny;j++)
		{
			for(int k=0;k<pdata.nz;k++)
			{
				float x = i*pdata.dxdi+pdata.xmin;
				float y = j*pdata.dydi+pdata.ymin;
				float z = k*pdata.dzdi+pdata.zmin;


				fields.getE(i,j,k,0) = Ex_function(x,y+0.5*pdata.dydi,z+0.5*pdata.dzdi);
				fields.getE(i,j,k,1) = Ey_function(x+0.5*pdata.dxdi,y,z+0.5*pdata.dzdi);
				fields.getE(i,j,k,2) = Ez_function(x+0.5*pdata.dxdi,y+0.5*pdata.dydi,z);

				fields.getB(i,j,k,0) = Ex_function(x,y,z);
				fields.getB(i,j,k,1) = Ey_function(x,y,z);
				fields.getB(i,j,k,2) = Ez_function(x,y,z);

				//fields.getB(i,j,k,0) = 0.0;
				//fields.getB(i,j,k,1) = 0.0f;
				//fields.getB(i,j,k,2) = 0.0f;

			//	printf("fields(%i,%i,%i) = %f, %f, %f\n",i,j,k,
				//	fields.getE(i,j,k,0),fields.getE(i,j,k,1),fields.getE(i,j,k,2));
			}
		}
	}

	fields.init_plot();

	fields.plot(&pdata,pdata.nz/2,0,0,0);

	getchar();


	double Ex_total = 0;
	double Ey_total = 0;
	double Ez_total = 0;

	double Bx_total = 0;
	double By_total = 0;
	double Bz_total = 0;


	// Setup E-field
	for(int i=0;i<pdata.nx;i++)
	{
		for(int j=0;j<pdata.ny;j++)
		{
			for(int k=0;k<pdata.nz;k++)
			{
				float xfrac = 0.5;
				float yfrac = 0.5;
				float zfrac = 0.5;

				float x = (xfrac + i)*pdata.dxdi+pdata.xmin;
				float y = (yfrac + j)*pdata.dydi+pdata.ymin;
				float z = (zfrac + k)*pdata.dzdi+pdata.zmin;


				float Ex_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,0,FieldData_deriv_f);
				float Ey_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,1,FieldData_deriv_f);
				float Ez_intrp = fields.intrpE(xfrac,yfrac,zfrac,i,j,k,2,FieldData_deriv_f);

				float Ex_real = Ex_function(x,y,z);
				float Ey_real = Ey_function(x,y,z);
				float Ez_real = Ez_function(x,y,z);


				float Ex_err = fabs(Ex_real - Ex_intrp)/fabs(Ex_real);
				float Ey_err = fabs(Ey_real - Ey_intrp)/fabs(Ey_real);
				float Ez_err = fabs(Ez_real - Ez_intrp)/fabs(Ez_real);

				float Bx_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,0,FieldData_deriv_f);
				float By_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,1,FieldData_deriv_f);
				float Bz_intrp = fields.intrpB(xfrac,yfrac,zfrac,i,j,k,2,FieldData_deriv_f);

				float Bx_real = Ex_function(x,y,z);
				float By_real = Ey_function(x,y,z);
				float Bz_real = Ez_function(x,y,z);


				float Bx_err = fabs(Bx_real - Bx_intrp)/fabs(Bx_real);
				float By_err = fabs(By_real - By_intrp)/fabs(By_real);
				float Bz_err = fabs(Bz_real - Bz_intrp)/fabs(Bz_real);

				Ex_total += Ex_err;
				Ey_total += Ey_err;
				Ez_total += Ez_err;

				Bx_total += Bx_err;
				By_total += By_err;
				Bz_total += Bz_err;
				//printf("values: x: %f / %f, y: %f / %f, z: %f / %f \n",Ex_real,Ex_intrp,Ey_intrp,Ey_real,Ez_intrp,Ez_real);
				//printf("Errors: x = %e, y = %e, z = %e\n",Ex_err,Ey_err,Ez_err);

			}
		}
	}



	printf("Errors_avg: x = %e, y = %e, z = %e\n",Ex_total/(nx*ny*nz*1.0),Ey_total/(nx*ny*nz*1.0),Ez_total/(nx*ny*nz*1.0));
	printf("Errors_avg: x = %e, y = %e, z = %e\n",Bx_total/(nx*ny*nz*1.0),By_total/(nx*ny*nz*1.0),Bz_total/(nx*ny*nz*1.0));

	printf("Efield setup complete\n");


}
Пример #17
0
void TwoStream_Initializer::check_step(ParticleList* particles,
		HOMoments** moments,HOMoments* moments_old,FieldData** fields,ParallelInfo* myinfo)
{



	if(myinfo->myid_mpi == 0)
	{
		particles->plot_particles(pdata);


		double pEnergy = ((fields[0] -> evaluate_energy()));
		double kEnergy = moments[0] -> evaluate_energy();

		Energy_array[nplot] = pEnergy;
		kEnergy_array[nplot] = kEnergy;

		TEnergy_array[nplot] = (E0+kE0 - (kEnergy + pEnergy))/(E0+kE0);
		//printf("Energy Error= %e\n",(E0+kE0 - (Energy_array[nplot]+kEnergy_array[nplot]))/(E0+kE0));
		max_t_array[nplot] = (nplot-1)*pdata->dt*2;
		if(nplot == 1)
		{
			max_array[0] = log(Energy_array[0]);
			max_t_array[nmax_array] = pdata->dt;
			nmax_array++;
		}
		else if(nplot > 1)
		{
			if(Energy_array[nplot-1] > fmax(Energy_array[nplot-2],Energy_array[nplot]))
			{
				//max_array[nmax_array] = log(Energy_array[nplot-1]);
				//max_t_array[nmax_array] = (nplot-1);

				//realkind period = (max_t_array[nmax_array]-max_t_array[nmax_array-1])*pdata->dt;
				//realkind vphase = 2.0*pi_const/period* 1.0*pdata->Lx/(2.0*pi_const);
				//printf("Energy fluctuation period = %f\n",period);
				//printf("Phase velocity = %f\n",vphase);
				//printf("Energy decay rate = %f\n",(max_array[nmax_array]-max_array[nmax_array-1])/
				//		(pdata->dt*(max_t_array[nmax_array]-max_t_array[nmax_array-1])));

				nmax_array++;
			}
		}

		realkind charge_cons = moments[0] -> check_charge(moments_old);

		printf("Charge conservation = %e\n",charge_cons);
		charge_cons_array[nplot] = charge_cons;


		if((nplot > 0)&&(nplot%10 == 9))
		{
			if(pdata->plot_flag){
			gnuplot_resetplot(plot);
			gnuplot_resetplot(kenergy_plot);
			gnuplot_resetplot(Tenergy_plot);
			gnuplot_resetplot(charge_cons_plot);
			}
		}

		nplot++;


		if((pdata->plot_flag)&&(nplot%10 == 9))
		{
			gnuplot_plot_xy(plot,max_t_array+1,Energy_array+1,nplot-1,"Field Energy");
			gnuplot_cmd(plot,"replot \"E_vec.csv\" title \"Matlab Code\" with points");
			gnuplot_plot_x(kenergy_plot,kEnergy_array,nplot,"Particle Energy");
			gnuplot_plot_x(Tenergy_plot,TEnergy_array,nplot,"Total Energy");
			gnuplot_plot_x(charge_cons_plot,charge_cons_array,nplot,"Charge Conservation");
		}


	}

}
Пример #18
0
int main(void)
{
 int i,j,k,m,seed,idx,fcluster[S+1+1],bond[N+1][NB+1],cluster_size[S+1+1][B+1];
 double X[S+1+1],temperature[S+1];
 char filename[20];
 gnuplot_ctrl*a;
 gnuplot_ctrl*b;
 
 FILE 	*fp1=fopen("Iris01.dat","r"),//Αρχικό αρχείο δεδομένων-Συμπληρώνεται και στη συνάρτηση output, εάν θέλουμε να κάνουμε διστδιάστατες προβολές
      	*fp2=fopen("data_iris.dat","w"),//Αρχείο που δημιουργείται, με τα παραγόμενα δεδομένα (χ,Τ,cluster size κλπ)
	*fp3=fopen("cluster_iris","w"),//αρχείο με πληροφορίες για τα clusters
	*fp4=fopen("G.dat","w"),//αρχείο με πληροφορίες για τη συνάρτηση G
	*fp5=fopen("nbors_iris.dat","r");//αρχείο γειτόνων, που παρήχθησαν από το πρόγραμμα nbors.c

 /*Parameters(Παράμετροι)*/

 
 T0=EPS;           //Starting Temperature(αρχική θερμοκρασία)
 Tmax=0.09;        //Highest Temperature(τελική θερμοκρασία)
 Tinc=(Tmax-T0)/S; //Temperature Increment(βήμα θερμοκρασίας)
 th=0.5;           //Threshold Value for condition [G(i,j)>th] (κατώφλι για τη συνθήκη [G(i,j)>th])

 /*Read data from file(διάβασμα αρχείου)*/
 /*
 	 =============
 	 =============
                               */
 //Initialise data(Αρχικοποίηση δεδομένων)

 for(i=0;i<=N;i++)for(j=0;j<=DM;j++)data[i][j]=0.0;T=0.0;
 for(i=0;i<=N;i++)for(j=0;j<=NB;j++){dist[i][j]=0.0;nbors[i][j]=0;}
 for(i=0;i<=N;i++)for(j=0;j<=NB;j++){J[i][j]=0.0;G[i][j]=0.0;}
 for(i=0;i<=S+1;i++){X[i]=0.0;fcluster[i]=0;}
 for(i=0;i<=S+1;i++)for(j=0;j<=B;j++)cluster_size[i][j]=0;
 for(i=0;i<=N;i++)for(j=0;j<=NB;j++)bond[i][j]=0;
 for(i=0;i<=N;i++)G_max[i]=0.0;for(i=0;i<=S;i++)temperature[i]=0;
 for(i=0;i<=N;i++)cluster[i]=0;
 for(i=0;i<S+1;i++)a1[i]=0.0;
 //Open file(Άνοιγμα αρχείου)
 
 //File 1---------------------------------------------
 if(fp1==NULL)
 {
  printf("Unable to open file for reading\n");
  exit(1);
 }
 rewind(fp1);//rewinding file(τοποθέτηση δείκτη αρχείου στην αρχή)
 i=1;j=1;
 while(fscanf(fp1,"%lf",&data[i][j])!=EOF)
 {
  j++;
  if(j==DM+1)
  {
   i++;
   j=1;
  }//Read data from file(Ανάγνωση δεδομένων από το αρχείο)
 }
 fclose(fp1);
 //File 1---------------------------------------------

 printf("\nReading Data Complete\n");

 //open file (άνοιγμα αρχείου γειτόνων)
 
 //File 5---------------------------------------------
 if(fp5==NULL)
 {
  printf("\nUnable to open file for reading\n");
  exit(1);
 }
 i=1;j=1;
 while (fscanf(fp5,"%d ",&nbors[i][j])!=EOF)
 {
  j++;
  if(j==NB+1)
   {
    i++;
    j=1;
   }
 }
 fclose(fp5);
 printf("Reading Neighbor List File Complete\n");
 //File 5---------------------------------------------

 
 /*Calculate Interaction Matrix*/
 /*============================*/

 /*-----CALL interaction_matrix function to calculate the interactions between the points (Καλούμε τη συνάρτηση interaction_matrix για τον υπολογισμό των αλληλεπιδράσεων μεταξύ των σημείων )------*/
 interaction_matrix(nbors,J,dist,data);
 /*------				  */

 printf("Calculate Interaction matrix complete\n");

 //Create random numbers(Δημιουργούμε τυχαίους αριθμούς)
 srand48((unsigned int)time(NULL));
 printf("seed =%d\n",(unsigned int) time(NULL));
 seed=1083354197;
 srand48(seed);
 
 /*--------------------------------------------------------*/
 for(k=1;k<=S+1;k++)//Temperature steps (Βήματα θερμοκρασίας)
 {
  /* Clustering Algorithm(Αλγόριθμος Ομαδοποίησης)   */
  
  T=T0+Tinc*(k-1);
  X[k]=SW(q,T,nbors,bond,cluster,J,G);//χ[T] Calculation
  printf("T= %f X[%d] = %f\n",T,k,X[k]);
  temperature[k]=T;
  /*  Final Data Clusters   */
  fcluster[k]=final_cluster(k,q,th,nbors,bond,cluster,cluster_data,G);
  printf("# of clusters[%d]=%d\n",k,fcluster[k]);
  if(plot_pixelmap==1)
  {
   sprintf(filename,"%f",temperature[k]);
   strncat(filename,".ppm",4);
   output(lattice,filename);
  }
 /*   Find Biggest Clusters  */  
  find_ClusterSize(k,cluster,fcluster,cluster_size);
 }
 /*--------------------------------------------------------*/
 /*Write result to file (εγγραφή αποτελεσμάτων σε αρχείο)*/

  //File 2---------------------------------------------
 
 X[2]=0.0309;
 for(i=1;i<=S+1;i++)
 {
  fprintf(fp2,"%f  %f  %d ",T0+Tinc*(i-1),X[i],fcluster[i]);
  for(j=1;j<=B;j++)
  {
   fprintf(fp2,"  %d  ",cluster_size[i][j]);
  }
  fprintf(fp2,"\n");
 }
 fclose(fp2);
 //File 2---------------------------------------------


 //File 3---------------------------------------------
 for(i=1;i<=N;i++)
 {
  for(j=1;j<=S+1;j++)
  {
   fprintf(fp3,"%d  ",cluster_data[i][j]);
  }
  fprintf(fp3,"\n");
 }
 fclose(fp3);
 //File 3---------------------------------------------
 

 //File 4---------------------------------------------
 for(i=1;i<=N;i++)
 {
  for(j=1;j<=NB;j++)
  {
   fprintf(fp4,"%f ",G[i][j]);
  }
  fprintf(fp4,"\n");
 }
 fclose(fp4);
 //File 4---------------------------------------------

 /*Gnuplot Graphics session - Συνεδρία γραφικών Gnuplot*/

 a=gnuplot_init();
 gnuplot_setstyle(a,"lines");
 gnuplot_set_xlabel(a,"Boltzmann constant*temperature");
 gnuplot_set_ylabel(a,"Susceptibility density");
 gnuplot_cmd(a,"set terminal svg");
 gnuplot_cmd(a,"set output \"Susceptibility.svg\"");
 for(k=0;k<=S;k++)
 {//Correction for Gnuplot, nothing important
  temperature[k]=temperature[k+1];
  X[k]=X[k+1];
 }
 gnuplot_plot_xy(a,temperature,X,(S+1),"X");//plotting X for all temperatures. (σχεδιάζουμε την χ για όλες τις θερμοκρασίες.)
 gnuplot_close(a);

 //---------------------------------------------------------//

 b=gnuplot_init();
 gnuplot_setstyle(b,"lines");
 gnuplot_set_xlabel(b,"Boltzmann constant*temperature");
 gnuplot_set_ylabel(b,"Cluster Size");
 gnuplot_cmd(b,"set terminal svg");
 gnuplot_cmd(b,"set output \"Clustersize.svg\"");
 //gnuplot_cmd(b,"set xrange [0:0.08]");//optional. sets the x-axis range.
 for (i=1;i<=B;i++)//For all the biggest clusters(για όλα τα μεγαλύτερα clusters)
 {
  for (j=1;j<=(S+1);j++)//For all temperatures (για όλες τις θερμοκρασίες)
  {
   a1[j]=(double)cluster_size[j][i];//keep current cluster array depending on T, to plot(κρατάμε τον τρέχοντα πίνακα για ένα συγκεκριμένο cluster για όλες τις Τ)
  }
  gnuplot_plot_xy(b,temperature,a1,(S+1),"cluster");//plotting current cluster curve (σχεδιάζουμε την καμπύλη του τρέχοντος cluster)
 }//now we have all cluster curves in a single diagram.(έχουμε όλες τις καμπύλες cluster σε μία γραφική παράσταση)
 gnuplot_close(b);

//---------------------------------------------------------//

return 0;
}
Пример #19
0
void EnergyCons_Initializer::check_step(ParticleList* particles,
		HOMoments** moments,HOMoments* moments_old,FieldData** fields,ParallelInfo* myinfo)
{



	// Print out the sum of the x-component of the current
	if(myinfo->myid_mpi == 0)
	{
		Energy_array[nplot] = ((fields[0] -> evaluate_energy()));
		kEnergy_array[nplot] = particles->evaluate_energy(pdata);

		TEnergy_array[nplot] = kEnergy_array[nplot] + Energy_array[nplot];
		printf("Energy Error= %e\n",(E0+kE0 - (Energy_array[nplot]+kEnergy_array[nplot]))/(E0+kE0));

		if(nplot == 1)
		{
			max_array[0] = log(Energy_array[0]);
			max_t_array[nmax_array] = pdata->dt;
			nmax_array++;
		}
		else if(nplot > 1)
		{
			if(Energy_array[nplot-1] > fmax(Energy_array[nplot-2],Energy_array[nplot]))
			{
				max_array[nmax_array] = log(Energy_array[nplot-1]);
				max_t_array[nmax_array] = (nplot-1);

				float period = (max_t_array[nmax_array]-max_t_array[nmax_array-1])*pdata->dt;
				float vphase = 2.0*pi_const/period* 1.0*pdata->Lx/(2.0*pi_const);
				printf("Energy fluctuation period = %f\n",period);
				printf("Phase velocity = %f\n",vphase);
				printf("Energy decay rate = %f\n",(max_array[nmax_array]-max_array[nmax_array-1])/
						(pdata->dt*(max_t_array[nmax_array]-max_t_array[nmax_array-1])));

				nmax_array++;
			}
		}


		if(nplot > 0)
		{
			gnuplot_resetplot(plot);
			gnuplot_resetplot(kenergy_plot);
			gnuplot_resetplot(Tenergy_plot);
		}

		nplot++;
		gnuplot_plot_x(plot,Energy_array,nplot,"Field Energy");
		gnuplot_plot_x(kenergy_plot,kEnergy_array,nplot,"Particle Energy");
		gnuplot_plot_x(Tenergy_plot,TEnergy_array,nplot,"Total Energy");
		//gnuplot_setstyle(plot,"lines");
		gnuplot_plot_xy(plot,max_t_array,max_array,nmax_array,NULL);
		//gnuplot_setstyle(plot,"points");


	}
















}
Пример #20
0
int main(int argc, char *argv[])
{
    gnuplot_ctrl    *   h1,
                    *   h2,
                    *   h3,
                    *   h4 ;
    double              x[NPOINTS] ;
    double              y[NPOINTS] ;
    int                 i ;

    /*
     * Initialize the gnuplot handle
     */
    printf("*** example of gnuplot control through C ***\n") ;
    h1 = gnuplot_init() ;

    /*
     * Slopes
     */
    gnuplot_setstyle(h1, "lines") ;

    printf("*** plotting slopes\n") ;
    printf("y = x\n") ;
    gnuplot_plot_slope(h1, 1.0, 0.0, "unity slope") ;
    sleep(SLEEP_LGTH) ;

    printf("y = 2*x\n") ;
    gnuplot_plot_slope(h1, 2.0, 0.0, "y=2x") ;
    sleep(SLEEP_LGTH) ;

    printf("y = -x\n") ;
    gnuplot_plot_slope(h1, -1.0, 0.0, "y=-x") ;
    sleep(SLEEP_LGTH) ;


    /*
     * Equations
     */

    gnuplot_resetplot(h1) ;
    printf("\n\n") ;
    printf("*** various equations\n") ;
    printf("y = sin(x)\n") ;
    gnuplot_plot_equation(h1, "sin(x)", "sine") ;
    sleep(SLEEP_LGTH) ;

    printf("y = log(x)\n") ;
    gnuplot_plot_equation(h1, "log(x)", "logarithm") ;
    sleep(SLEEP_LGTH) ;

    printf("y = sin(x)*cos(2*x)\n") ;
    gnuplot_plot_equation(h1, "sin(x)*cos(2*x)", "sine product") ;
    sleep(SLEEP_LGTH) ;


    /*
     * Styles
     */

    gnuplot_resetplot(h1) ;
    printf("\n\n") ;
    printf("*** showing styles\n") ;

    printf("sine in points\n") ;
    gnuplot_setstyle(h1, "points") ;
    gnuplot_plot_equation(h1, "sin(x)", "sine") ;
    sleep(SLEEP_LGTH) ;

    printf("sine in impulses\n") ;
    gnuplot_setstyle(h1, "impulses") ;
    gnuplot_plot_equation(h1, "sin(x)", "sine") ;
    sleep(SLEEP_LGTH) ;

    printf("sine in steps\n") ;
    gnuplot_setstyle(h1, "steps") ;
    gnuplot_plot_equation(h1, "sin(x)", "sine") ;
    sleep(SLEEP_LGTH) ;

    /*
     * User defined 1d and 2d point sets
     */

    gnuplot_resetplot(h1) ;
    gnuplot_setstyle(h1, "impulses") ;
    printf("\n\n") ;
    printf("*** user-defined lists of doubles\n") ;
    for (i=0 ; i<NPOINTS ; i++) {
        x[i] = (double)i*i ;
    }
    gnuplot_plot_x(h1, x, NPOINTS, "user-defined doubles") ;
    sleep(SLEEP_LGTH) ;

	printf("*** user-defined lists of points\n");
    for (i=0 ; i<NPOINTS ; i++) {
        x[i] = (double)i ;
        y[i] = (double)i * (double)i ;
    }
    gnuplot_resetplot(h1) ;
    gnuplot_setstyle(h1, "points") ;
    gnuplot_plot_xy(h1, x, y, NPOINTS, "user-defined points") ;
    sleep(SLEEP_LGTH) ;


    /*
     * Multiple output screens
     */

    printf("\n\n") ;
    printf("*** multiple output windows\n") ;
    gnuplot_resetplot(h1) ;
    gnuplot_setstyle(h1, "lines") ;
    h2 = gnuplot_init() ;
    gnuplot_setstyle(h2, "lines") ;
    h3 = gnuplot_init() ;
    gnuplot_setstyle(h3, "lines") ;
    h4 = gnuplot_init() ;
    gnuplot_setstyle(h4, "lines") ;

    printf("window 1: sin(x)\n") ;
    gnuplot_plot_equation(h1, "sin(x)", "sin(x)") ;
    sleep(SLEEP_LGTH) ;
    printf("window 2: x*sin(x)\n") ;
    gnuplot_plot_equation(h2, "x*sin(x)", "x*sin(x)") ;
    sleep(SLEEP_LGTH) ;
    printf("window 3: log(x)/x\n") ;
    gnuplot_plot_equation(h3, "log(x)/x", "log(x)/x");
    sleep(SLEEP_LGTH) ;
    printf("window 4: sin(x)/x\n") ;
    gnuplot_plot_equation(h4, "sin(x)/x", "sin(x)/x") ;
    sleep(SLEEP_LGTH) ;

    /*
     * close gnuplot handles
     */


    printf("\n\n") ;
    printf("*** end of gnuplot example\n") ;
    gnuplot_close(h1) ;
    gnuplot_close(h2) ;
    gnuplot_close(h3) ;
    gnuplot_close(h4) ;
    return 0 ;
}