Skip to content

Commit 0b1dab8

Browse files
committed
started advection app
* refer #56. Signed-off-by: Lakshman Anumolu <acrlakshman@yahoo.co.in>
1 parent 0f10214 commit 0b1dab8

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ IF (BUILD_TESTS)
5656
ADD_SUBDIRECTORY(tests)
5757
ENDIF()
5858

59+
# Build applications
60+
ADD_SUBDIRECTORY(applications)
61+
5962
FILE(GLOB_RECURSE GALS_CPU_SRC
6063
src/cpu/*.cc
6164
src/cpu/*.h

applications/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FILE(GLOB FILES "*.cpp" "*.cc")
2+
3+
SET(APP_NAME app)
4+
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/advection ADVECTION_SRC)
5+
ADD_EXECUTABLE(${APP_NAME} ${ADVECTION_SRC})
6+
7+
SET_PROPERTY(TARGET ${APP_NAME} PROPERTY CXX_STANDARD 14)
8+
9+
TARGET_INCLUDE_DIRECTORIES(${APP_NAME}
10+
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/advection
11+
${PROJECT_SOURCE_DIR}/src
12+
${PROJECT_SOURCE_DIR}/include
13+
)
14+
15+
TARGET_LINK_LIBRARIES(${APP_NAME}
16+
PUBLIC
17+
gals_cpu
18+
yaml-cpp
19+
spdlog
20+
filesystem
21+
)
22+
23+
SET_TARGET_PROPERTIES(${APP_NAME} PROPERTIES FOLDER "Applications")
24+
25+
ADD_TEST(NAME ${APP_NAME} COMMAND ${APP_NAME})

applications/advection/main.cc

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
}

src/cpu/file-utils.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ void GALS::UTILITIES::FileUtils::write(const std::string file_name, const T& fie
8888
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 1>, double>));
8989
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 1>, GALS::CPU::Vec3<double>>));
9090
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::Vec3<double>>));
91+
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::Vec3<double>>));

0 commit comments

Comments
 (0)