Skip to content

Commit 7fdbb82

Browse files
authored
Merge pull request #57 from acrlakshman/issue_56
added more parsers and towards finishing advection
2 parents affd2c1 + 5e5cd8b commit 7fdbb82

File tree

35 files changed

+1090
-74
lines changed

35 files changed

+1090
-74
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

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 <map>
35+
#include <string>
36+
#include <vector>
37+
38+
#include "gals/cpu/levelset.h"
39+
#include "gals/input-fields/levelset.h"
40+
#include "gals/utilities/array.h"
41+
#include "gals/utilities/grid.h"
42+
#include "gals/utilities/vec_n.h"
43+
44+
namespace GALS
45+
{
46+
namespace ANALYTICAL_FIELDS
47+
{
48+
/*! enums for levelset fields.
49+
*/
50+
enum class LevelsetFieldNames { NOT_DEFINED, CIRCLE };
51+
52+
/*! enum maps for levelset fields.
53+
*/
54+
static std::map<std::string, LevelsetFieldNames> levelset_name_map{{"CIRCLE", LevelsetFieldNames::CIRCLE}};
55+
56+
/*! \class Levelset
57+
*
58+
* Class to create analytical levelset fields.
59+
*/
60+
template <typename T_GRID, typename T = double>
61+
class Levelset
62+
{
63+
public:
64+
/*! Constructor with grid.
65+
*
66+
* \param grid grid.
67+
* \param inputs levelset input fields of type GALS::INPUT_FIELDS::Levelset
68+
*/
69+
Levelset(const T_GRID& grid, const GALS::INPUT_FIELDS::Levelset& inputs);
70+
71+
/*! Remove default constructor.
72+
*/
73+
Levelset() = delete;
74+
75+
/*! Destructor
76+
*/
77+
~Levelset();
78+
79+
/*! Return grid.
80+
*
81+
* \return grid.
82+
*/
83+
const T_GRID& grid() const { return m_grid; }
84+
85+
/*! Compute levelset field.
86+
*
87+
* \param positions array of positions where levelset needs to be computed.
88+
* \param levelset levelset field which will be updated by this function.
89+
*/
90+
void compute(const GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>>& positions, GALS::CPU::Levelset<T_GRID, T>& levelset);
91+
92+
private:
93+
const T_GRID& m_grid;
94+
const GALS::INPUT_FIELDS::Levelset& m_inputs;
95+
};
96+
97+
} // namespace ANALYTICAL_FIELDS
98+
} // namespace GALS

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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131

3232
#pragma once
3333

34-
#include "grid.h"
35-
#include "velocity.h"
34+
#include "gals/input-fields/general.h"
35+
#include "gals/input-fields/grid.h"
36+
#include "gals/input-fields/levelset.h"
37+
#include "gals/input-fields/time.h"
38+
#include "gals/input-fields/velocity.h"
3639

3740
namespace GALS
3841
{
@@ -53,8 +56,11 @@ class InputFields
5356
*/
5457
~InputFields();
5558

59+
GALS::INPUT_FIELDS::General *m_general;
5660
GALS::INPUT_FIELDS::Grid *m_grid;
61+
GALS::INPUT_FIELDS::Time *m_time;
5762
GALS::INPUT_FIELDS::Velocity *m_velocity;
63+
GALS::INPUT_FIELDS::Levelset *m_levelset;
5864
};
5965

6066
} // namespace INPUT_FIELDS

include/gals/input-fields/levelset.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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/utilities/vec3.h"
35+
36+
#include <string>
37+
38+
namespace GALS
39+
{
40+
namespace INPUT_FIELDS
41+
{
42+
struct Levelset {
43+
std::string name; //! Name of levelset field.
44+
GALS::CPU::Vec3<double> center; //! Center of levelset field for few levelset types.
45+
double radius; //! Radius of levelset field for few object types.
46+
std::string gradient_scheme; //! Scheme to compute gradient of levelset field.
47+
};
48+
49+
} // namespace INPUT_FIELDS
50+
} // namespace GALS

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

0 commit comments

Comments
 (0)