Ejemplo n.º 1
0
TSEND CStair::Missioning(_us (*img)[256], int now){
	switch(now){
	case 0:
		m_send = Up1(img);
		break;
	case 1:
		m_send = Up2(img);
		break;
	case 2:
		m_send = Up3(img);
		break;
	case 3:
		m_send = Step4(img);
		break;
	case 4:
		m_send = Step5(img);
		break;
		/////////////////////////////////// 올라가기전
	case 5:
		m_send = Up1(img);
		break;
	case 6:
		m_send = Up2(img);
		break;
	}
	return m_send;
}
Ejemplo n.º 2
0
bool TTetrahedron::IsInner(const TPoint& P) const {
    TVector N, U1(X1, X2), U2(X1, X3), U3(X1, X4), U4(X2, X3), U5(X2, X4), U6(X2, X1);
    TVector Up1(X1, P), Up2(X2, P);

    N = Cross(U1, U2); //X4 is on opposite side of plain X1,X2,X3 than P
    if (Dot(N, U3) * Dot(N, Up1) < 0) {
        return false;
    }

    N = Cross(U1, U3); //X3 x P
    if (Dot(N, U2) * Dot(N, Up1) < 0) {
        return false;
    }

    N = Cross(U2, U3); //X2 x P
    if (Dot(N, U1) * Dot(N, Up1) < 0) {
        return false;
    }

    N = Cross(U4, U5); //X1 x P
    if (Dot(N, U6) * Dot(N, Up2) < 0) {
        return false;
    }

    return true;
}
int main() {

// Define Variables
	std::string parameter_filename = "solver_parms.txt";
	std::string input_filename = "test4.bkcfd";
	std::string output_filename = "test4_output.txt";
	std::vector<double> parameters;
	std::vector<double> Fiph, Fimh, Giph, Gimh;
	double CFL, dt, delta_x, delta_y, min_delta_x, min_delta_y, min_delta;
	TDstate state_minus, state_plus, slope_minus, slope_plus, limiter_value;
	TDstate state_leftcell, state_rightcell, state_bottomcell, state_topcell;
	std::vector<TDstate> F (2);
	std::vector<TDstate> G (2);

	double thresh = pow(10,-8); // 1E-8 tolerance for riemann solver - velocity
	double gamma = 1.4;
	bool debug = false;
	bool save_timesteps = true;	

// 1 = harmonic mean for slopes, 2 = first order upwind (no limiter) ...
	int limiter_number = 2; 

	std::vector<cell> grid;

	// Read parameters from input file defined by filename string
	parameters = read_parameters(parameter_filename);
	CFL = parameters.at(0);	
	int num_timesteps = parameters.at(1);
	

// Read initial file defined from Matlab with cell edges and connections
// Read the initial condition file from MATLAB with [rho rho*u rho*v e] defined for each cell
	read_grid(input_filename, grid, gamma);
	
	min_delta_x = gridmin(grid, 'x');
	min_delta_y = gridmin(grid, 'y');
	min_delta = std::min(min_delta_x,min_delta_y);
/*
	for(auto input: grid) {
		std::cout << input.cellnumber << '\n';
		std::cout << "cornerlocs_x: " << input.cornerlocs_x[0] << ' ';
		std::cout << input.cornerlocs_x[1] << ' ';
		std::cout << input.cornerlocs_x[2] << ' ';
		std::cout << input.cornerlocs_x[3] << '\n';
		std::cout << "cornerlocs_y: " << input.cornerlocs_y[0] << ' ';
		std::cout << input.cornerlocs_y[1] << ' ';
		std::cout << input.cornerlocs_y[2] << ' ';
		std::cout << input.cornerlocs_y[3] << '\n';
		std::cout << "adjacent_cells: " << input.adjacent_cells[0] << ' ';
		std::cout << input.adjacent_cells[1] << ' ';
		std::cout << input.adjacent_cells[2] << ' ';
		std::cout << input.adjacent_cells[3] << '\n';
		std::cout << "is_edgecell: " << input.is_edgecell << '\n';
		std::cout << "state: " << input.state.rho << ' ';
		std::cout << input.state.rhou << ' ';
		std::cout << input.state.rhov << ' ';
		std::cout << input.state.E << '\n' << '\n';
	} 
*/
	std::vector<TDstate> U;
	for (unsigned int cellnum = 0; cellnum < grid.size(); ++cellnum) {
		U.push_back(grid[cellnum].state);
	}

	double max_wavespeed = 0; 	
	for (unsigned int cellnum = 0; cellnum < grid.size(); ++cellnum) { // For each cell
		if (grid[cellnum].is_edgecell == 0) { // Cell is not a ghost cell/edge cell
         FluxSolver(grid, delta_x, delta_y, state_minus, state_plus, gamma, slope_plus, slope_minus, limiter_number, cellnum, limiter_value, F, G, CFL, max_wavespeed, U, debug);
		}
	}
	dt = CFL*min_delta/max_wavespeed;

// Start calculation in for loop going to final time
	TDstate Uph;
	std::vector<TDstate> Up1 (grid.size());
	for (int timestep = 0; timestep < num_timesteps; timestep++) { // for each timestep
		std::cout << "Timestep " << timestep << " of " << num_timesteps << '\n';
		if (timestep > 0) {
			U = Up1;
		}
		if (debug) {
			outputU(U);
		}

// Go through each cell, calculate fluxes, update to new piecewise linear state
		for (unsigned int cellnum = 0; cellnum < grid.size(); ++cellnum) { // For each cell
			if (grid[cellnum].is_edgecell == 0)  { // Cell is not a ghost cell/edge cell
   	   	FluxSolver(grid, delta_x, delta_y, state_minus, state_plus, gamma, slope_plus, slope_minus, limiter_number, cellnum, limiter_value, F, G, CFL, max_wavespeed, U, debug);
			// Now, use the fluxes calculated above to assign a new state, Uph
				compute_halfway_state(Uph, U[cellnum], F, G, dt, delta_x, delta_y);
		
				if (debug) {				
				std::cout << "Cell number: " << cellnum << '\n';
				std::cout << "bottom/top Limiter - " << limiter_value.rho << " " << limiter_value.rhou << " " << limiter_value.rhov << " "  << limiter_value.E << '\n';
				std::cout << "Current State: " << U[cellnum].rho << " " << U[cellnum].rhou << " " << U[cellnum].rhov << " " << U[cellnum].E << '\n';
//				std::cout << "F, cell number " << cellnum << ": " << '\n';
//				std::cout << F[0].rho << " " << F[0].rhou << " " << F[0].rhov << " " << F[0].E << '\n';
//				std::cout << F[1].rho << " " << F[1].rhou << " " << F[1].rhov << " " << F[1].E << '\n';
	
//				std::cout << "G, cell number: " << cellnum << '\n';
//				std::cout << G[0].rho << " " << G[0].rhou << " " << G[0].rhov << " " << G[0].E << '\n';
//				std::cout << G[1].rho << " " << G[1].rhou << " " << G[1].rhov << " " << G[1].E << '\n';
	
				std::cout << "Cell " << cellnum << " half-state: " <<  Uph.rho << " " << Uph.rhou << " " << Uph.rhov << " " << Uph.E << '\n';
				}

// Solve riemann problem on edge for euler flux
				TDstate state_center_2D = U[cellnum];
				TDstate tempflux;
				ODstate state_leftcell_1D, center_lr, center_bt, state_rightcell_1D, state_bottomcell_1D, state_topcell_1D;
				
				assign_edge_state(state_leftcell, state_rightcell, U, grid, cellnum, 0); // The left and right cell TDstates of the current cell
				assign_edge_state(state_bottomcell, state_topcell, U, grid, cellnum, 1); // The bottom and top cell TDstates of the current cell
				
// All this mess is because the riemann problem is 1D and we store 2D states.
// So we have to make new, temporary 1D states and fixes (all the doubles) to make the RP work.
				center_lr.rho = U[cellnum].rho;
				center_lr.rhou = U[cellnum].rhou;
				double center_lr_parallelvel = U[cellnum].rhov/U[cellnum].rho; 
				center_lr.E = U[cellnum].E;

				center_bt.rho = U[cellnum].rho;
				double center_bt_parallelvel = U[cellnum].rhou/U[cellnum].rho; 
				center_bt.rhou = U[cellnum].rhov;	
				center_bt.E = U[cellnum].E;

				state_leftcell_1D.rho = state_leftcell.rho;
				state_leftcell_1D.rhou = state_leftcell.rhou;
				double leftcell_parallelvel = state_leftcell.rhov/state_leftcell.rho;
				state_leftcell_1D.E = state_leftcell.E;

				state_rightcell_1D.rho = state_rightcell.rho; 
				state_rightcell_1D.rhou = state_rightcell.rhou;
				double rightcell_parallelvel = state_rightcell.rhov/state_rightcell.rho; 
				state_rightcell_1D.E = state_rightcell.E;

				state_bottomcell_1D.rho = state_bottomcell.rho;
				double bottomcell_parallelvel = state_bottomcell.rhou/state_bottomcell.rho;
				state_bottomcell_1D.rhou = state_bottomcell.rhov;
				state_bottomcell_1D.E = state_bottomcell.E;

				state_topcell_1D.rho = state_topcell.rho;
				double topcell_parallelvel = state_topcell.rhou/state_topcell.rho;
				state_topcell_1D.rhou = state_topcell.rhov;
				state_topcell_1D.E = state_topcell.E;


// Need to read in overall velocity magnitude to Exact Riemann Solver so we can get an accurate pressure reading!
// Reconstruct, from the state_[  ] ODstates, the TDstates corresponding assuming that the non-OD direction velocity is constant
// Then compute the flux from these new TDstates (4x), and update solution from t+1/2 to t+1 !!!
				ODstate state_leftedge_1D = Exact_Riemann_Solver(state_leftcell_1D, center_lr, leftcell_parallelvel, center_lr_parallelvel, thresh, gamma, debug);
				ODstate state_rightedge_1D = Exact_Riemann_Solver(center_lr, state_rightcell_1D, center_lr_parallelvel, rightcell_parallelvel, thresh, gamma, debug);
				ODstate state_bottomedge_1D = Exact_Riemann_Solver(state_bottomcell_1D, center_bt, bottomcell_parallelvel, center_bt_parallelvel, thresh, gamma, debug);
				ODstate state_topedge_1D = Exact_Riemann_Solver(center_bt, state_topcell_1D, center_bt_parallelvel, topcell_parallelvel, thresh, gamma, debug);


				TDstate state_leftedge_2D, state_rightedge_2D, state_bottomedge_2D, state_topedge_2D;


				state_leftedge_2D.rho = state_leftedge_1D.rho;
				state_leftedge_2D.rhou = state_leftedge_1D.rhou;
				state_leftedge_2D.rhov = state_center_2D.rhov;
				state_leftedge_2D.E = state_leftedge_1D.E;
				
				state_rightedge_2D.rho = state_rightedge_1D.rho;
				state_rightedge_2D.rhou = state_rightedge_1D.rhou;
				state_rightedge_2D.rhov = state_center_2D.rhov;
				state_rightedge_2D.E = state_rightedge_1D.E;

				state_bottomedge_2D.rho = state_bottomedge_1D.rho;
				state_bottomedge_2D.rhou = state_center_2D.rhou; 
				state_bottomedge_2D.rhov = state_bottomedge_1D.rhou;
				state_bottomedge_2D.E = state_bottomedge_1D.E;

				state_topedge_2D.rho = state_topedge_1D.rho;
				state_topedge_2D.rhou = state_center_2D.rhou; 
				state_topedge_2D.rhov = state_topedge_1D.rhou;
				state_topedge_2D.E = state_topedge_1D.E;

				compute_cell_flux(tempflux, state_leftedge_2D, 0, gamma);
				F[0] = tempflux;
				compute_cell_flux(tempflux, state_rightedge_2D, 0, gamma);
				F[1] = tempflux;
				compute_cell_flux(tempflux, state_bottomedge_2D, 1, gamma);
				G[0] = tempflux;
				compute_cell_flux(tempflux, state_topedge_2D, 1, gamma);
				G[1] = tempflux;
//Use all these fluxes to define updated state on each cell 
				compute_halfway_state(Up1[cellnum], Uph, F, G, dt, delta_x, delta_y); 
	
				if (debug) {
					std::cout << "Cell " << cellnum << " Updated State : " <<  Up1[cellnum].rho << " " << Up1[cellnum].rhou << " " << Up1[cellnum].rhov << " " << Up1[cellnum].E << '\n' << '\n';
				}
			} // end of if (!isedge(grid,cell)) 
		} // end of for(unsigned int cell = 0; cell < grid.size(); ++cell) (first one)

		// Now need to redefine the ghost cells to the correct values
		for(unsigned int cellnum = 0; cellnum < grid.size(); ++cellnum) {
			if (grid[cellnum].is_edgecell == 1) { // It is a ghost cell 
				int special_value = -1;		
				int num_edges = 0;		
				std::vector<int> edge_locations;
				for(int adjacentcell = 0; adjacentcell < 4; ++adjacentcell) {
					if (grid[cellnum].adjacent_cells[adjacentcell] == special_value) {
						edge_locations.push_back(adjacentcell);
						num_edges++;
					}
				}
		//		if (num_edges >= 2) {
	//				continue; // Sorry bro, we don't care about updating you!
//				} else if (num_edges == 1) {
					if (edge_locations[0] < 2) {
						edge_locations[0] = (edge_locations[0] + 2);
					} else {
						edge_locations[0] = (edge_locations[0] - 2);					
					}
				
					Up1[cellnum] = Up1[grid[cellnum].adjacent_cells[edge_locations[0]]];
					if (edge_locations[0] >= 2) {
						edge_locations[0] = (edge_locations[0] - 2);
					}
					assert((edge_locations[0] == 0) || (edge_locations[0] == 1));
					if (edge_locations[0] == 0) { // left-right
						if (Up1[cellnum].rhou == 0) {
							continue;
						} else {
							Up1[cellnum].rhou = -(Up1[cellnum].rhou);
						}
					} else if (edge_locations[0] == 1) { //up-down
						if (Up1[cellnum].rhou == 0) {
							continue;
						} else {
							Up1[cellnum].rhov = -(Up1[cellnum].rhov);
						}
					}
				//}
			} // end of if (isedge(grid,cell)) 
		} // end of for(unsigned int cell = 0; cell < grid.size(); ++cell) (second one)
		if (save_timesteps) {
			write_to_file(grid,Up1,output_filename);
		}
	} // end of for(double t = 0; t <= 2*dt; t++) 
return 0;
}