|
| 1 | +/////////////////////////////////////////////////////////////////////////////// |
| 2 | +// Copyright 2019 Lakshman Anumolu, Raunak Bardia. |
| 3 | +// |
| 4 | +// Redistribution and use in source and binary forms, with or without |
| 5 | +// modification, are permitted provided that the following conditions are |
| 6 | +// met: |
| 7 | +// |
| 8 | +// 1. Redistributions of source code must retain the above copyright notice, |
| 9 | +// this list of conditions and the following disclaimer. |
| 10 | +// |
| 11 | +// 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +// this list of conditions and the following disclaimer in the documentation |
| 13 | +// and/or other materials provided with the distribution. |
| 14 | +// |
| 15 | +// 3. Neither the name of the copyright holder nor the names of its contributors |
| 16 | +// may be used to endorse or promote products derived from this software without |
| 17 | +// specific prior written permission. |
| 18 | +// |
| 19 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | +/////////////////////////////////////////////////////////////////////////////// |
| 31 | + |
| 32 | +#include <iostream> |
| 33 | +#include <string> |
| 34 | + |
| 35 | +#include "gals/analytical-fields/velocity.h" |
| 36 | +#include "gals/input-parser.h" |
| 37 | +#include "gals/utilities/file-utils.h" |
| 38 | +#include "gals/utilities/grid.h" |
| 39 | +#include "gals/utilities/vec3.h" |
| 40 | + |
| 41 | +int main(int argc, char **argv) |
| 42 | +{ |
| 43 | + std::cout << "Inside applications/advection" << std::endl; |
| 44 | + |
| 45 | + std::string inputs_file; |
| 46 | + if (argc == 1) { |
| 47 | + std::cout << "./<executable> <inputs_file>" << std::endl; |
| 48 | + exit(0); |
| 49 | + } else { |
| 50 | + inputs_file = std::string(argv[1]); |
| 51 | + |
| 52 | + // TODO (lakshman): Check if the file exists. |
| 53 | + } |
| 54 | + |
| 55 | + const int dim = 2; |
| 56 | + using T = double; |
| 57 | + using TV = GALS::CPU::Vec3<T>; |
| 58 | + using T_GRID = GALS::CPU::Grid<T, dim>; |
| 59 | + |
| 60 | + GALS::INPUT_FIELDS::InputFields input_fields; |
| 61 | + GALS::INPUT_PARSER::InputParser input_parser; |
| 62 | + |
| 63 | + input_parser.parse(inputs_file, &input_fields); |
| 64 | + |
| 65 | + // Construct grid. |
| 66 | + const auto &grid_inputs = *(input_fields.m_grid); |
| 67 | + T_GRID grid(grid_inputs.nx, grid_inputs.ny, grid_inputs.nz); |
| 68 | + grid.generate(grid_inputs.x_min, grid_inputs.x_max, grid_inputs.y_min, grid_inputs.y_max, grid_inputs.z_min, |
| 69 | + grid_inputs.z_max); |
| 70 | + |
| 71 | + // accessing grid details |
| 72 | + const auto mask = grid.getMask(); |
| 73 | + const int pad = grid.getPadding(); |
| 74 | + const auto num_cells = grid.numCells(); |
| 75 | + |
| 76 | + // defining working+ghost domain extent |
| 77 | + int i_min = -pad * mask[0]; |
| 78 | + int j_min = -pad * mask[1]; |
| 79 | + int k_min = -pad * mask[2]; |
| 80 | + int i_max = num_cells[0] + pad * mask[0]; |
| 81 | + int j_max = num_cells[1] + pad * mask[1]; |
| 82 | + int k_max = num_cells[2] + pad * mask[2]; |
| 83 | + |
| 84 | + // Variable to store grid positions. |
| 85 | + GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>> positions(grid); |
| 86 | + |
| 87 | + for (int i = i_min; i < i_max; ++i) |
| 88 | + for (int j = j_min; j < j_max; ++j) |
| 89 | + for (int k = k_min; k < k_max; ++k) { |
| 90 | + positions(i, j, k) = grid(i, j, k); |
| 91 | + } |
| 92 | + |
| 93 | + // Construct velocity. |
| 94 | + const auto &velocity_inputs = *(input_fields.m_velocity); |
| 95 | + GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>> velocity_field(grid); |
| 96 | + GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T> velocity(grid, velocity_inputs); |
| 97 | + velocity.compute(positions, velocity_field); |
| 98 | + |
| 99 | + // Write velocity to a file. |
| 100 | + GALS::UTILITIES::FileUtils file_utils; |
| 101 | + file_utils.setRootDirectory("tmp/advection/"); |
| 102 | + file_utils.createDirectory(file_utils.getRootDirectory()); |
| 103 | + file_utils.write(std::string(file_utils.getRootDirectory() + "velocity"), velocity_field); |
| 104 | + |
| 105 | + return 0; |
| 106 | +} |
0 commit comments