Skip to content

Commit 74d2125

Browse files
committed
added more parsers and towards finishing advection
* refer #56. * added parsers to read general and time sections from inputs file. * WIP: advection algorithm. Signed-off-by: Lakshman Anumolu <acrlakshman@yahoo.co.in>
1 parent affd2c1 commit 74d2125

File tree

24 files changed

+532
-20
lines changed

24 files changed

+532
-20
lines changed

applications/advection/main.cc

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ int main(int argc, char **argv)
4444

4545
std::string inputs_file;
4646
if (argc == 1) {
47-
std::cout << "./<executable> <inputs_file>" << std::endl;
47+
std::cout << "<path-to-executable>/<executable> <path-to-inputs_file>" << std::endl;
4848
exit(0);
4949
} else {
5050
inputs_file = std::string(argv[1]);
5151

52-
// TODO (lakshman): Check if the file exists.
52+
GALS::UTILITIES::FileUtils file_utils;
53+
if (!file_utils.fileExists(inputs_file)) {
54+
std::cout << "File: " << inputs_file << " does not exist" << std::endl;
55+
exit(0);
56+
}
5357
}
5458

5559
const int dim = 2;
@@ -62,6 +66,11 @@ int main(int argc, char **argv)
6266

6367
input_parser.parse(inputs_file, &input_fields);
6468

69+
GALS::UTILITIES::FileUtils file_utils;
70+
71+
const auto &general_inputs = *(input_fields.m_general);
72+
file_utils.setRootDirectory(general_inputs.output_directory + "/");
73+
6574
// Construct grid.
6675
const auto &grid_inputs = *(input_fields.m_grid);
6776
T_GRID grid(grid_inputs.nx, grid_inputs.ny, grid_inputs.nz);
@@ -96,9 +105,29 @@ int main(int argc, char **argv)
96105
GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T> velocity(grid, velocity_inputs);
97106
velocity.compute(positions, velocity_field);
98107

108+
const auto &time_inputs = *(input_fields.m_time);
109+
110+
T t_start = time_inputs.start;
111+
T t_end = time_inputs.end;
112+
T dt = time_inputs.dt;
113+
bool is_dt_fixed = std::strcmp(time_inputs.constant_dt.c_str(), "NO");
114+
T sim_time = 0;
115+
116+
if (!is_dt_fixed) {
117+
dt = grid.dX().min() / 2.;
118+
}
119+
120+
// Time loop
121+
bool run_sim = true;
122+
while (run_sim) {
123+
sim_time += dt;
124+
125+
//
126+
127+
if (GALS::is_equal(sim_time, t_end) || sim_time > t_end) run_sim = false;
128+
}
129+
99130
// Write velocity to a file.
100-
GALS::UTILITIES::FileUtils file_utils;
101-
file_utils.setRootDirectory("tmp/advection/");
102131
file_utils.createDirectory(file_utils.getRootDirectory());
103132
file_utils.write(std::string(file_utils.getRootDirectory() + "velocity"), velocity_field);
104133

include/gals/input-fields/general.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
#pragma once
33+
34+
#include <string>
35+
36+
namespace GALS
37+
{
38+
namespace INPUT_FIELDS
39+
{
40+
struct General {
41+
std::string output_directory;
42+
};
43+
44+
} // namespace INPUT_FIELDS
45+
} // namespace GALS

include/gals/input-fields/input-fields.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
#pragma once
3333

34+
#include "general.h"
3435
#include "grid.h"
36+
#include "time.h"
3537
#include "velocity.h"
3638

3739
namespace GALS
@@ -53,7 +55,9 @@ class InputFields
5355
*/
5456
~InputFields();
5557

58+
GALS::INPUT_FIELDS::General *m_general;
5659
GALS::INPUT_FIELDS::Grid *m_grid;
60+
GALS::INPUT_FIELDS::Time *m_time;
5761
GALS::INPUT_FIELDS::Velocity *m_velocity;
5862
};
5963

include/gals/input-fields/time.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
#pragma once
33+
34+
#include <string>
35+
36+
namespace GALS
37+
{
38+
namespace INPUT_FIELDS
39+
{
40+
struct Time {
41+
double start, end, dt;
42+
std::string constant_dt;
43+
};
44+
45+
} // namespace INPUT_FIELDS
46+
} // namespace GALS

include/gals/input-fields/velocity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct Velocity {
4242
std::string name; //! Name of velocity field.
4343
std::vector<double> vector; //! Uniform velocity magnitudes of all components.
4444
std::vector<double> center; //! Center of velocity field for few velocity types.
45+
std::string gradient_scheme; //! Scheme to compute gradient of velocity field.
4546
};
4647

4748
} // namespace INPUT_FIELDS

include/gals/input-parser/general.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
#pragma once
33+
34+
#include "gals/input-fields/input-fields.h"
35+
36+
#include "yaml-cpp/yaml.h"
37+
38+
namespace GALS
39+
{
40+
namespace INPUT_PARSER
41+
{
42+
/*! \class General
43+
*
44+
* Class to parse input fields for grid.
45+
*/
46+
class General
47+
{
48+
public:
49+
/*! Default constructor
50+
*/
51+
General();
52+
53+
/*! Destructor
54+
*/
55+
~General();
56+
57+
/*! Parse input variables for grid section.
58+
*
59+
* \param field YAML node for grid.
60+
* \param p_input_fields pointer to input fields object.
61+
*/
62+
void parse(const YAML::Node &field, GALS::INPUT_FIELDS::InputFields *p_input_fields);
63+
64+
/*! Overloaded operator to parse.
65+
*
66+
* \param field YAML node for grid.
67+
* \param p_input_fields pointer to input fields object.
68+
*/
69+
void operator()(const YAML::Node &field, GALS::INPUT_FIELDS::InputFields *p_input_fields);
70+
};
71+
72+
} // namespace INPUT_PARSER
73+
} // namespace GALS

include/gals/input-parser/grid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ class Grid
6969
void operator()(const YAML::Node &field, GALS::INPUT_FIELDS::InputFields *p_input_fields);
7070
};
7171

72-
} // namespace CPU
72+
} // namespace INPUT_PARSER
7373
} // namespace GALS

include/gals/input-parser/time.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
#pragma once
33+
34+
#include "gals/input-fields/input-fields.h"
35+
36+
#include "yaml-cpp/yaml.h"
37+
38+
namespace GALS
39+
{
40+
namespace INPUT_PARSER
41+
{
42+
/*! \class Time
43+
*
44+
* Class to parse input fields for grid.
45+
*/
46+
class Time
47+
{
48+
public:
49+
/*! Default constructor
50+
*/
51+
Time();
52+
53+
/*! Destructor
54+
*/
55+
~Time();
56+
57+
/*! Parse input variables for grid section.
58+
*
59+
* \param field YAML node for grid.
60+
* \param p_input_fields pointer to input fields object.
61+
*/
62+
void parse(const YAML::Node &field, GALS::INPUT_FIELDS::InputFields *p_input_fields);
63+
64+
/*! Overloaded operator to parse.
65+
*
66+
* \param field YAML node for grid.
67+
* \param p_input_fields pointer to input fields object.
68+
*/
69+
void operator()(const YAML::Node &field, GALS::INPUT_FIELDS::InputFields *p_input_fields);
70+
};
71+
72+
} // namespace INPUT_PARSER
73+
} // namespace GALS

include/gals/utilities/file-utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class FileUtils
6767
*/
6868
const std::string getRootDirectory() const;
6969

70+
/*! Checks if file exists or not.
71+
*
72+
* \param file_name name of file with relative or absolute path.
73+
*
74+
* \return true if exists, false otherwise.
75+
*/
76+
bool fileExists(const std::string file_name) const;
77+
7078
/*! Remove file.
7179
*
7280
* \param file_name name of file with relative or absolute path.

include/gals/utilities/vec3.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ class Vec3
7272
*/
7373
const int size() const;
7474

75+
/*! Returns minimum value from the array.
76+
*
77+
* \return minimum value.
78+
*/
79+
const T min() const;
80+
7581
/*! Overloaded subscript operator that returns a const value.
7682
*
7783
* \param idx zero based index of element.

0 commit comments

Comments
 (0)