void FluxSolver(const std::vector<cell>& grid, double& delta_x, double& delta_y, TDstate& state_minus, TDstate& state_plus, double gamma, TDstate& slope_plus, TDstate& slope_minus, int limiter_number, int cellnum, TDstate& limiter_value, std::vector<TDstate>& F, std::vector<TDstate>& G, double CFL, double& max_wavespeed, std::vector<TDstate>& U, bool debug) { delta_x = (vectormax(grid[cellnum].cornerlocs_x) - vectormin(grid[cellnum].cornerlocs_x)); delta_y = (vectormax(grid[cellnum].cornerlocs_y) - vectormin(grid[cellnum].cornerlocs_y)); // Calculate the limited flux of each conserved quantity for initial t -> t+1/2 update for (int direction = 0; direction < 2; ++direction) { // For the left/right direction and up/down direction // Assign the bottom/left and the top/right states for each cell assign_edge_state(state_minus, state_plus, U, grid, cellnum, direction); // Calculate the flux of each conserved variable, in each direction, on each face, of that cell. // Flux needs to be calculated by first finding the limiter (direction-dependent), then using that limiter to calculate the directional flux, then using the two directional fluxes to update from u_t to u_t+1/2 compute_slope(slope_minus, slope_plus, direction, state_minus, state_plus, delta_x, delta_y, U[cellnum]); if ((direction == 1) && (debug)) { std::cout << "Slope Minus: " << slope_minus.rho << " " << slope_minus.rhou << " " << slope_minus.rhov << " " << slope_minus.E << '\n'; std::cout << "Slope Plus: " << slope_plus.rho << " " << slope_plus.rhou << " " << slope_plus.rhov << " " << slope_plus.E << '\n'; } compute_limiter(limiter_value, slope_minus, slope_plus, limiter_number); if (direction == 0) { // Compute F, x-fluxes compute_limited_flux(F, limiter_value, U[cellnum], slope_plus, slope_minus, direction, gamma, CFL); // std::cout << "rho limiter x: " << limiter_value.rho << '\n'; } else { // Compute G, y-fluxes // std::cout << "rho limiter y: " << limiter_value.rho << '\n'; compute_limited_flux(G, limiter_value, U[cellnum], slope_plus, slope_minus, direction, gamma, CFL); } } // end of for (int direction = 0; direction < 2; ++direction) max_wavespeed_calculator_riemann(max_wavespeed, U[cellnum], gamma); }
void find_wall_angle() { int scan_row = 480/2; // Start with an initial estimate of the wall angle: int centerW = mRawDepth.width / 2; int pix_left = mRawDepth.row(scan_row)[col-3]; int pix_right = mRawDepth.row(scan_row)[col+3]; double slope = compute_slope( pix_left, pix_right, 3 ); double intercept = mRawDepth.row(scan_row)[centerW]; // y= slope*(column-centerW) + intercept our origin is at centerW of image // Now grab all vertical lines which fit in this slope,intercept : for (int col=0; col<640; col++) { double expected_intensity = slope*(column - centerW) + intercept; int low = expected_intensity - tolerance; int high = expected_intensity + tolerance; if ((mRawDepth.row(scan_row)[col] >= low) && (mRawDepth.row(scan_row)[col] <= high)) included_columns.push_back(col); } // And get a better estimate of the wall angle (all included columns) double wall_angle; double wall_position; revise_wall_angle_estimate( wall_angle, wall_position ); printf("Revised Wall Angle = %6.2f\n", wall_angle ); printf("Revised Wall Position = %6.2f\n", wall_position ); }
int main (void) { double coord_x1 = 0.0, coord_x2 = 0.0, coord_y1 = 0.0, coord_y2 = 0.0, slope = 0.0, midpoint_X = 0.0, midpoint_Y = 0.0, y_intercept = 0.0; coord_x1 = get_number('X', 1); coord_y1 = get_number('Y', 1); coord_x2 = get_number('X', 2); coord_y2 = get_number('Y', 2); slope = compute_slope(coord_x1, coord_y1, coord_x2, coord_y2); midpoint_X = compute_midpoint(coord_x1, coord_x2); midpoint_Y = compute_midpoint(coord_y1, coord_y2); slope = compute_bisector_slope(slope); y_intercept = compute_y_intercept(slope, midpoint_X, midpoint_Y); display_results(coord_x1, coord_y1, coord_x2, coord_y2, slope, y_intercept); return 0; }
void gather_wall_slope_intercept_data(cv::Mat& mRawDepth) { intercepts.clear(); slopes.clear(); // Scan a row in center of image. // get the slope 3 pixels above and 3 pixels below. for (int col=0; col<640; col++) { int pix = mDepth.row(scan_row)[col]; int pix_above = mDepth.row(scan_row-3)[col]; int pix_below = mDepth.row(scan_row+3)[col]; double slope = compute_slope( pix_above, pix_below, 3 ); slopes.push_back( slope ); intercepts.push_back( pix ); } }
int main(int argc, char* argv[]){ int sockfd; /*printf("\nSERVER: starting the server\n");*/ /* Create a socket */ /*printf("SERVER: creating socket\n");*/ if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1){ /*perror("SERVER: socket() failed");*/ printf("1 SERVER ERROR\n"); exit(EXIT_FAILURE); } int opt = 1; /* Make it so we can reuse the address and don't get the annoying "address already in use" error message */ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0){ printf("2 SERVER ERROR\n"); exit(EXIT_FAILURE); } /* Configure connection settings */ struct sockaddr_in addr; char ipaddr[] = "127.0.0.1"; addr.sin_family = AF_INET; addr.sin_port = htons(7890); /*printf("SERVER: configuring the server to listen on %s:%d\n",ipaddr,ntohs(addr.sin_port));*/ if (inet_pton(AF_INET, ipaddr, &addr.sin_addr.s_addr) < 1){ /*perror("inet_pton() failed");*/ if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("3 SERVER ERROR\n"); exit(EXIT_FAILURE); } /* Bind the socket to an address */ /*printf("SERVER: binding the server to %s:%d\n",ipaddr,ntohs(addr.sin_port));*/ if (bind(sockfd,(struct sockaddr*)&addr,sizeof(addr)) == -1){ /*perror("SERVER: bind() failed");*/ if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("4 SERVER ERROR\n"); exit(EXIT_FAILURE); } /* Listen for incoming connections */ /*printf("SERVER: listening for an incoming connection\n");*/ if (listen(sockfd,SOMAXCONN) == -1){ /*perror("SERVER: listen() failed");*/ if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("5 SERVER ERROR\n"); exit(EXIT_FAILURE); } int clisock; struct sockaddr_in cliaddr; socklen_t clilength = sizeof(cliaddr); /* Handle incoming connections */ while(1){ /*printf("SERVER: waiting for a connection from a client\n");*/ if ((clisock = accept(sockfd,(struct sockaddr*)&cliaddr,&clilength)) == -1){ /*perror("SERVER: accept() failed");*/ if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("6 SERVER ERROR\n"); exit(EXIT_FAILURE); } /* Get information about the connecting client */ char addrbuf[INET_ADDRSTRLEN]; /*printf("SERVER: getting connection information about the client\n");*/ if (inet_ntop(AF_INET,&((&cliaddr)->sin_addr),addrbuf,INET_ADDRSTRLEN) == NULL){ /*perror("SERVER: inet_ntop() failed");*/ if (close(clisock) == -1){ /*perror("SERVER: close(client socket) failed");*/ } if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("7 SERVER ERROR\n"); exit(EXIT_FAILURE); } /*printf("SERVER: accepted a connection from the client %s:%d\n",addrbuf,ntohs(cliaddr.sin_port));*/ /* Read coordinate data x1 y1 x2 y2 from the client */ char buffer[BUFFER_SIZE]; bzero(buffer,BUFFER_SIZE); /*printf("SERVER: reading data from the client\n");*/ if (read(clisock,buffer,BUFFER_SIZE) == -1){ //STONESOUP:INTERACTION_POINT /*perror("SERVER: read failed()");*/ if (close(clisock) == -1){ /*perror("SERVER: close(client socket) failed");*/ } if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("8 SERVER ERROR\n"); exit(EXIT_FAILURE); } /* printf("SERVER: read %s from client\n",buffer); printf("SERVER: parsing the data from the client\n"); */ enum INPUT input; point p1,p2; char out[BUFFER_SIZE]; bzero(out,BUFFER_SIZE); if (get_input(buffer,out) == 0){ printf("9 SERVER ERROR\n"); exit(EXIT_FAILURE); } if ((input = parse_input(out,&p1,&p2)) != INPUT_POINTS){ if (close(clisock) == -1){ /*perror("SERVER: close(client socket) failed");*/ } if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } if (input == INPUT_ERROR){ printf("10 SERVER ERROR\n"); exit(EXIT_FAILURE); }else{ /*printf("SERVER: closing the server\n");*/ exit(EXIT_SUCCESS); } } /*printf("SERVER: found points (%d,%d) and (%d,%d)\n",p1.x,p1.y,p2.x,p2.y);*/ /* Compute the slope of the line formed by the two given points */ /*printf("SERVER: computing the slope for (%d,%d) and (%d,%d))\n",p1.x,p1.y,p2.x,p2.y);*/ float m; enum SLOPE slope = compute_slope(p1,p2,&m); bzero(buffer,BUFFER_SIZE); if ( slope == DEFINED_SLOPE ){ /* If the slope is defined, we can use the equation y = mx + b */ /* Compute the y-intercept of the line formed by the two points given the slope and point on the line */ /*printf("SERVER: computing the y-intercept using a slope of %f and the point (%d,%d)\n",m,p1.x,p1.y);*/ float b = compute_y_intercept(m,p1); /* Prepare the data y = mx + b that will be sent to the client */ /*printf("SERVER: creating the equation of the line to send back to the client\n");*/ if (snprintf(buffer,BUFFER_SIZE,"y = (%f)x + %f",m,b) < 0){ /*perror("SERVER: snprintf() failed\n");*/ if (close(clisock) == -1){ /*perror("SERVER: close(client socket) failed");*/ } if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("11 SERVER ERROR\n"); exit(EXIT_FAILURE); } }else{ /* If the slope is undefined, x = p1.x or p2.x (they will be the same in this case */ /*printf("SERVER: slope is undefined so creating the equation of the line (x = x1) to send back to the client\n");*/ if (snprintf(buffer,BUFFER_SIZE,"x = %lu",p1.x) < 0){ /*perror("SERVER: snprintf() failed\n");*/ if (close(clisock) == -1){ /*perror("SERVER: close(client socket) failed");*/ } if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("12 SERVER ERROR\n"); exit(EXIT_FAILURE); } } /* Send the data y = mx + b or x = n to the client */ /*printf("SERVER: writing %s to the client\n",buffer);*/ if (write(clisock,buffer,BUFFER_SIZE) == -1){ /*perror("SERVER: write() failed");*/ if (close(clisock) == -1){ /*perror("SERVER: close(client socket) failed");*/ } if (close(sockfd) == -1){ /*perror("SERVER: close(server socket) failed");*/ } printf("13 SERVER ERROR\n"); exit(EXIT_FAILURE); } /* Closing the socket used to communicate with the client */ /*printf("SERVER: closing the client socket\n");*/ if (close(clisock) == -1){ /*perror("SERVER: close(client socket) failed");*/ if (close(sockfd) !=0){ /*perror("SERVER: close() failed");*/ } printf("14 SERVER ERROR\n"); exit(EXIT_FAILURE); } } return 0; }
int main() { // Define Variables std::string parameter_filename = "solver_parms.txt"; std::string input_filename = "5x5square2.bkcfd"; std::vector<double> parameters; std::vector<double> Fiph, Fimh, Giph, Gimh; double CFL, tmax, delta_x, delta_y, min_delta_x, min_delta_y, min_delta; TDstate state_minus, state_plus, slope_minus, slope_plus, limiter_value; std::vector<TDstate> F (2); std::vector<TDstate> G (2); // double thresh = 0.00001; // 1E-5 tolerance for riemann solver - velocity double gamma = 1.4; // 1 = harmonic mean for slopes, 2 = ... int limiter_number = 1; std::vector<cell> grid; // Read parameters from input file defined by filename string parameters = read_parameters(parameter_filename); // CFL = parameters.at(0); // tmax = 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); std::vector<TDstate> Uph (grid.size()); min_delta_x = gridmin(grid, 'x'); min_delta_y = gridmin(grid, 'y'); min_delta = std::min(min_delta_x,min_delta_y); /* std::cout << "printing now..." << '\n'; for(auto input: grid) { std::cout << input.cellnumber << '\n'; std::cout << 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 << 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 << 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 << input.state.rho << ' '; std::cout << input.state.rhou << ' '; std::cout << input.state.rhov << ' '; std::cout << input.state.E << '\n' << '\n'; } */ // Start calculation in for loop going to final time // for (double t = 0, t <= tmax; t++) double max_wavespeed = 0; // 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 (!isedge(grid,cellnum)) { delta_x = (vectormax(grid[cellnum].cornerlocs_x) - vectormin(grid[cellnum].cornerlocs_x)); delta_y = (vectormax(grid[cellnum].cornerlocs_y) - vectormin(grid[cellnum].cornerlocs_y)); // Calculate the limited flux of each conserved quantity for initial t -> t+1/2 update for (int direction = 0; direction < 2; ++direction) { // For the left/right direction and up/down direction // Assign the bottom/left and the top/right states for each cell assign_edge_state(state_minus, state_plus, grid, cellnum, direction); // Calculate the flux of each conserved variable, in each direction, on each face, of that cell. // Flux needs to be calculated by first finding the limiter (direction-dependent), then using that limiter to calculate the directional flux, then using the two directional fluxes to update from u_t to u_t+1/2 compute_slope(slope_minus, slope_plus, grid, cellnum, direction, state_minus, state_plus, delta_x, delta_y); compute_limiter(limiter_value, slope_minus, slope_plus, limiter_number); if (direction == 0) { // Compute F, x-fluxes compute_limited_flux(F, limiter_value, min_delta, CFL, grid[cellnum].state, slope_plus, direction, gamma); // std::cout << "rho limiter x: " << limiter_value.rho << '\n'; } else { // Compute G, y-fluxes // std::cout << "rho limiter y: " << limiter_value.rho << '\n'; compute_limited_flux(G, limiter_value, min_delta, CFL, grid[cellnum].state, slope_plus, direction, gamma); } } // end of for (int direction = 0; direction < 2; ++direction) // std::cout << "F flux: " << F[0].rho << " " << F[1].rho << ", G flux: " << G[0].rho << " " << G[1].rho << '\n'; fluxmax(max_wavespeed, F, G, grid[cellnum].state); } // end of if (!isedge(grid,cell)) // Compute the max // Now, use the fluxes calculated above to assign a new state, Uph compute_halfway_state(Uph, F, G, CFL); // ----------------------------- // Need to check values of flux to see if they are giving accurate results! // // Go through each edge, calculate flux, save // for (int edge = 1, edge <= numedges, ++edge) // // Solve riemann problem on edge for euler flux ODstate left; ODstate right; left.rho = 1.0; //rho left.rhou = 300; //rho*u or rho*v left.E = 100000/0.4 - pow(left.rhou,2)/(left.rho*2); //E right.rho = 1; right.rhou = 0; right.E = 100000/0.4 - pow(right.rhou,2)/(right.rho*2); /* ODstate test_state = Exact_Riemann_Solver(left, right, thresh, gamma); std::cout << '\n' << "State on x=0 is:" << '\n'; std::cout << test_state.rho << '\n'; std::cout << test_state.rhou << '\n'; std::cout << test_state.E << '\n'; std::cout << test_state.pressure << '\n'; */ //Use all these fluxes to define updated state on each cell //Option to save at each timestep } // end of for(unsigned int cell = 0; cell < grid.size(); ++cell) return 0; }