Skip to content

Commit 5e5cd8b

Browse files
committed
added levelset parser
* some cleanup. * testing. Signed-off-by: Lakshman Anumolu <acrlakshman@yahoo.co.in>
1 parent 8a07ea1 commit 5e5cd8b

File tree

16 files changed

+512
-58
lines changed

16 files changed

+512
-58
lines changed
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/input-fields.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131

3232
#pragma once
3333

34-
#include "general.h"
35-
#include "grid.h"
36-
#include "time.h"
37-
#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"
3839

3940
namespace GALS
4041
{
@@ -59,6 +60,7 @@ class InputFields
5960
GALS::INPUT_FIELDS::Grid *m_grid;
6061
GALS::INPUT_FIELDS::Time *m_time;
6162
GALS::INPUT_FIELDS::Velocity *m_velocity;
63+
GALS::INPUT_FIELDS::Levelset *m_levelset;
6264
};
6365

6466
} // 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-parser/levelset.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 Levelset
43+
*
44+
* Class to parse input fields for grid.
45+
*/
46+
class Levelset
47+
{
48+
public:
49+
/*! Default constructor
50+
*/
51+
Levelset();
52+
53+
/*! Destructor
54+
*/
55+
~Levelset();
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/grid.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,6 @@ class Grid
238238
*/
239239
void generate(T x_min, T x_max, T y_min, T y_max, T z_min, T z_max);
240240

241-
/*! Write grid data to a file.
242-
*
243-
* \param file_name writes grid file with the prescribed name.
244-
* \param dir_name writes grid in the prescribed directory.
245-
* \param show_padding writes grid with or without padding cells.
246-
*/
247-
void writeToFile(std::string file_name = "grid.dat", std::string dir_name = ".", bool show_padding = false);
248-
249241
private:
250242
int m_dimension, m_nx, m_ny, m_nz, m_pad;
251243
size_t m_total_cells;

src/cpu/analytical-fields/levelset.cc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 "gals/analytical-fields/levelset.h"
33+
#include "gals/utilities/utilities.h"
34+
35+
template <typename T_GRID, typename T>
36+
GALS::ANALYTICAL_FIELDS::Levelset<T_GRID, T>::Levelset(const T_GRID& grid, const GALS::INPUT_FIELDS::Levelset& inputs)
37+
: m_grid(grid), m_inputs(inputs)
38+
{
39+
}
40+
41+
template <typename T_GRID, typename T>
42+
GALS::ANALYTICAL_FIELDS::Levelset<T_GRID, T>::~Levelset()
43+
{
44+
}
45+
46+
template <typename T_GRID, typename T>
47+
void GALS::ANALYTICAL_FIELDS::Levelset<T_GRID, T>::compute(
48+
const GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>>& positions, GALS::CPU::Levelset<T_GRID, T>& levelset)
49+
{
50+
const GALS::CPU::Vec3<int> num_cells = positions.numCells();
51+
const auto& levelset_name = m_inputs.name;
52+
53+
switch (levelset_name_map[levelset_name]) {
54+
case LevelsetFieldNames::CIRCLE: {
55+
auto& phi = levelset.phi();
56+
57+
GALS::CPU::Vec3<T> distance_vec;
58+
59+
for (int i = 0; i < num_cells[0]; ++i)
60+
for (int j = 0; j < num_cells[1]; ++j)
61+
for (int k = 0; k < num_cells[2]; ++k) {
62+
distance_vec = positions(i, j, k) - m_inputs.center;
63+
phi(i, j, k) = distance_vec.mag() - m_inputs.radius;
64+
}
65+
66+
break;
67+
}
68+
69+
default:
70+
break;
71+
}
72+
}
73+
74+
template class GALS::ANALYTICAL_FIELDS::Levelset<GALS::CPU::Grid<double, 1>, double>;
75+
template class GALS::ANALYTICAL_FIELDS::Levelset<GALS::CPU::Grid<double, 2>, double>;
76+
template class GALS::ANALYTICAL_FIELDS::Levelset<GALS::CPU::Grid<double, 3>, double>;

src/cpu/file-utils.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@ void GALS::UTILITIES::FileUtils::write(const std::string file_name, const T& fie
9494

9595
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 1>, double>));
9696
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 1>, GALS::CPU::Vec3<double>>));
97+
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 2>, double>));
9798
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 2>, GALS::CPU::Vec3<double>>));
9899
_INSTANTIATE_WRITE_(P(GALS::CPU::Array<GALS::CPU::Grid<double, 3>, GALS::CPU::Vec3<double>>));

0 commit comments

Comments
 (0)