* @brief Create a simulation object containing all the initial parameters and * condition of the simulation * * @details * For the ux, uy, and boundary images, we use RGB values for to define the * specific quantites for each grid cell/pixel * * /// R & B for ux & uy * * For ux and uy, Red means positive value while Blue means negative value. The * speed value for both ux and uy is compu
| 123 | * |
| 124 | */ |
| 125 | Simulation create_simulation(uint32_t grid_width, uint32_t grid_height, |
| 126 | float density, float velocity, float reynolds, |
| 127 | const char* ux_image_filename, |
| 128 | const char* uy_image_filename, |
| 129 | const char* boundaries_filename) { |
| 130 | Simulation sim; |
| 131 | |
| 132 | sim.grid_width = grid_width; |
| 133 | sim.grid_height = grid_height; |
| 134 | sim.velocity = velocity; |
| 135 | sim.density = density; |
| 136 | sim.reynolds = reynolds; |
| 137 | |
| 138 | try { |
| 139 | sim.ux = af::loadImage(ux_image_filename, true); |
| 140 | } catch (const af::exception& e) { |
| 141 | std::cerr << e.what() << std::endl; |
| 142 | sim.ux = af::constant(0, grid_width, grid_height, 3); |
| 143 | } |
| 144 | |
| 145 | auto ux_dim = sim.ux.dims(); |
| 146 | if (ux_dim[0] != grid_width || ux_dim[1] != grid_height) { |
| 147 | std::cerr |
| 148 | << "Fluid flow ux image has dimensions different to the simulation" |
| 149 | << std::endl; |
| 150 | throw std::runtime_error{ |
| 151 | "Fluid flow ux image has dimensions different to the simulation"}; |
| 152 | } |
| 153 | |
| 154 | try { |
| 155 | sim.uy = af::loadImage(uy_image_filename, true); |
| 156 | } catch (const af::exception& e) { |
| 157 | std::cerr << e.what() << std::endl; |
| 158 | sim.uy = af::constant(0, grid_width, grid_height, 3); |
| 159 | } |
| 160 | |
| 161 | auto uy_dim = sim.uy.dims(); |
| 162 | if (uy_dim[0] != grid_width || uy_dim[1] != grid_height) { |
| 163 | std::cerr |
| 164 | << "Fluid flow uy image has dimensions different to the simulation" |
| 165 | << std::endl; |
| 166 | throw std::runtime_error{ |
| 167 | "Fluid flow uy image has dimensions different to the simulation"}; |
| 168 | } |
| 169 | |
| 170 | try { |
| 171 | sim.set_boundaries = af::loadImage(boundaries_filename, false); |
| 172 | } catch (const af::exception& e) { |
| 173 | std::cerr << e.what() << std::endl; |
| 174 | sim.set_boundaries = af::constant(0, grid_width, grid_height); |
| 175 | } |
| 176 | |
| 177 | auto b_dim = sim.set_boundaries.dims(); |
| 178 | if (b_dim[0] != grid_width || b_dim[1] != grid_height) { |
| 179 | std::cerr |
| 180 | << "Fluid boundary image has dimensions different to the simulation" |
| 181 | << std::endl; |
| 182 | throw std::runtime_error{ |
no test coverage detected