Skip to content

Commit 6492784

Browse files
committed
LevelsetVelocity is used to compute analytical velocities
* Velocity gradient can be computed analytically for solid body rotation field. Signed-off-by: Lakshman Anumolu <[email protected]>
1 parent 7fdbb82 commit 6492784

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

applications/advection/main.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ int main(int argc, char **argv)
101101

102102
// Construct velocity.
103103
const auto &velocity_inputs = *(input_fields.m_velocity);
104-
GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>> velocity_field(grid);
104+
GALS::CPU::LevelsetVelocity<T_GRID, T> levelset_velocity(grid);
105+
const auto &velocity_field = levelset_velocity.velocity();
105106
GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T> velocity(grid, velocity_inputs);
106-
velocity.compute(positions, velocity_field);
107+
velocity.compute(positions, levelset_velocity);
107108

108109
const auto &time_inputs = *(input_fields.m_time);
109110

include/gals/analytical-fields/velocity.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <string>
3636
#include <vector>
3737

38+
#include "gals/cpu/levelset-velocity.h"
3839
#include "gals/input-fields/velocity.h"
3940
#include "gals/utilities/array.h"
4041
#include "gals/utilities/grid.h"
@@ -84,10 +85,10 @@ class Velocity
8485
/*! Compute velocity field.
8586
*
8687
* \param positions array of positions where velocity needs to be computed.
87-
* \param velocity velocity field which will be updated by this function.
88+
* \param levelset_velocity velocity field which will be updated by this function.
8889
*/
8990
void compute(const GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>>& positions,
90-
GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>>& velocity);
91+
GALS::CPU::LevelsetVelocity<T_GRID, T>& levelset_velocity);
9192

9293
private:
9394
const T_GRID& m_grid;

src/cpu/analytical-fields/velocity.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T>::~Velocity()
4646
template <typename T_GRID, typename T>
4747
void GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T>::compute(
4848
const GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>>& positions,
49-
GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>>& velocity)
49+
GALS::CPU::LevelsetVelocity<T_GRID, T>& levelset_velocity)
5050
{
5151
const GALS::CPU::Vec3<int> num_cells = positions.numCells();
5252
const auto& velocity_name = m_inputs.name;
5353

5454
switch (velocity_name_map[velocity_name]) {
5555
case VelocityFieldNames::CIRCULAR: {
56+
auto& velocity = levelset_velocity.velocity();
57+
5658
if (T_GRID::dim == 1)
5759
GALS_FUNCTION_NOT_IMPLEMENTED(
5860
"GALS::ANALYTICAL_FIELDS::Velocity::compute: CIRCULAR velocity field for 1D grid.");
@@ -71,6 +73,24 @@ void GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T>::compute(
7173
velocity(i, j, k) = velocity_node;
7274
}
7375

76+
// Compute velocity gradient using analytical expressions.
77+
if (!std::strcmp(m_inputs.gradient_scheme, "ANALYTICAL")) {
78+
auto& velocity_gradient = levelset_velocity.velocityGradient();
79+
80+
for (int i = 0; i < num_cells[0]; ++i)
81+
for (int j = 0; j < num_cells[1]; ++j)
82+
for (int k = 0; k < num_cells[2]; ++k) {
83+
for (int cmpt = 0; cmpt < T_GRID::dim; ++cmp) {
84+
for (int derv = 0; derv < T_GRID::dim; ++derv) {
85+
if (cmpt == 0 && derv == 0) velocity_gradient[cmpt][derv] = static_cast<T>(0);
86+
if (cmpt == 0 && derv == 1) velocity_gradient[cmpt][derv] = -coeff;
87+
if (cmpt == 1 && derv == 0) velocity_gradient[cmpt][derv] = coeff;
88+
if (cmpt == 1 && derv == 1) velocity_gradient[cmpt][derv] = static_cast<T>(0);
89+
}
90+
}
91+
}
92+
}
93+
7494
break;
7595
}
7696

tests/analytical-fields-velocity.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ TEST(GALS, ANALYTICAL_FIELDS_VELOCITY_2D)
103103
positions(i, j, k) = grid(i, j, k);
104104
}
105105

106-
GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>> velocity_field(grid);
106+
GALS::CPU::LevelsetVelocity<T_GRID, T> levelset_velocity(grid);
107+
const auto& velocity_field = levelset_velocity.velocity();
108+
107109
GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T> velocity(grid, velocity_inputs);
108-
velocity.compute(positions, velocity_field);
110+
velocity.compute(positions, levelset_velocity);
109111

110112
// TODO (lakshman): Compare these values with results from matlab.
111113
// for (int i = 0; i < num_cells[0]; ++i)

0 commit comments

Comments
 (0)