Skip to content

Commit a0ce7ef

Browse files
committed
compute mixed derivatives
* refer #59 Signed-off-by: Lakshman Anumolu <[email protected]>
1 parent 63f4b72 commit a0ce7ef

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ENDIF()
3131

3232
MARK_AS_ADVANCED(BUILD_COVERAGE)
3333

34-
SET(CMAKE_CXX_STANDARD 14)
34+
SET(CMAKE_CXX_STANDARD 17)
3535
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
3636

3737
IF (BUILD_TESTS)

include/gals/cpu/levelset.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ class Levelset
8484
*/
8585
~Levelset();
8686

87+
/*! Compute mixed derivatives.
88+
*
89+
* Mixed derivatives of the levelset is computed using second order gradient approximation on
90+
* the levelset gradient.
91+
*
92+
* \param psi gradient of levelset.
93+
* \param phi_mixed_derivatives mixed derivatives of the levelset.
94+
*
95+
* \return Void.
96+
*/
97+
void computeMixedDerivatives(const Array<T_GRID, Vec3<T>>& psi,
98+
Array<T_GRID, VecN<T, T_GRID::num_mixed_derivatives>>& phi_mixed_derivatives);
99+
87100
/*! Return grid.
88101
*
89102
* \return grid.

src/cpu/levelset.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
///////////////////////////////////////////////////////////////////////////////
3131

3232
#include "gals/cpu/levelset.h"
33+
#include "gals/cpu/gradient.h"
3334

3435
#include <iostream>
3536

@@ -52,6 +53,32 @@ GALS::CPU::Levelset<T_GRID, T>::~Levelset()
5253
{
5354
}
5455

56+
template <typename T_GRID, typename T>
57+
void GALS::CPU::Levelset<T_GRID, T>::computeMixedDerivatives(
58+
const Array<T_GRID, Vec3<T>>& psi, Array<T_GRID, VecN<T, T_GRID::num_mixed_derivatives>>& phi_mixed_derivatives)
59+
{
60+
// For now gradient computation is hardcoded here.
61+
const Vec3<int> num_cells = psi.numCells();
62+
const T_GRID& grid = psi.grid();
63+
const Vec3<typename T_GRID::value_type> dx = grid.dX();
64+
const auto& axis_vectors = GALS::CPU::Grid<typename T_GRID::value_type, T_GRID::dim>::axis_vectors;
65+
66+
if constexpr (T_GRID::dim == 1) {
67+
for (int i = 0; i < num_cells[0]; ++i)
68+
for (int j = 0; j < num_cells[1]; ++j)
69+
for (int k = 0; k < num_cells[2]; ++k) {
70+
for (int axis = 0; axis < T_GRID::dim; ++axis) {
71+
typename T_GRID::value_type one_by_dx = static_cast<typename T_GRID::value_type>(1.) / dx[axis];
72+
73+
// grad_alpha(i, j, k)[axis] =
74+
//(alpha(i + axis_vectors(axis, 0), j + axis_vectors(axis, 1), k + axis_vectors(axis, 2)) -
75+
// alpha(i - axis_vectors(axis, 0), j - axis_vectors(axis, 1), k - axis_vectors(axis, 2))) *
76+
// one_by_dx * static_cast<T>(0.5);
77+
}
78+
}
79+
}
80+
}
81+
5582
template <typename T_GRID, typename T>
5683
void GALS::CPU::Levelset<T_GRID, T>::print()
5784
{

0 commit comments

Comments
 (0)