Skip to content

Commit 54c12bd

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

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
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)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#### Dependencies
1010

1111
* [CMake]
12-
* Compiler that supports C++14
12+
* Compiler that supports C++17
1313

1414
```sh
1515
git clone https://github.com/acrlakshman/gradient-augmented-levelset-cuda --recursive

docs/pages/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Implementation of Gradient Augmented Levelset method in CPU and GPU.
1616
#### Dependencies
1717

1818
* [CMake]
19-
* Compiler that supports C++14
19+
* Compiler that supports C++17
2020

2121
```sh
2222
git clone https://github.com/acrlakshman/gradient-augmented-levelset-cuda --recursive

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: 69 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,74 @@ 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 computations are hardcoded in this function.
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 one_over_dx = grid.oneOverDX();
65+
const auto& axis_vectors = GALS::CPU::Grid<typename T_GRID::value_type, T_GRID::dim>::axis_vectors;
66+
67+
if constexpr (T_GRID::dim == 2) {
68+
int axis_x = 0, axis_y = 1;
69+
70+
// Computing \frac{\partial}{\partial y} \left( \frac{\partial}{\partial x} \right).
71+
for (int i = 0; i < num_cells[0]; ++i)
72+
for (int j = 0; j < num_cells[1]; ++j)
73+
for (int k = 0; k < num_cells[2]; ++k) {
74+
phi_mixed_derivatives(i, j, k)[0] =
75+
(psi(i + axis_vectors(axis_y, 0), j + axis_vectors(axis_y, 1), k + axis_vectors(axis_y, 2))[axis_x] -
76+
psi(i - axis_vectors(axis_y, 0), j - axis_vectors(axis_y, 1), k - axis_vectors(axis_y, 2))[axis_x]) *
77+
one_over_dx[axis_y] * static_cast<T>(0.5);
78+
}
79+
} else if constexpr (T_GRID::dim == 3) {
80+
int axis_x = 0, axis_y = 1, axis_z = 2;
81+
82+
// Computing \frac{\partial}{\partial x} \left( \frac{\partial}{\partial y} \right).
83+
for (int i = 0; i < num_cells[0]; ++i)
84+
for (int j = 0; j < num_cells[1]; ++j)
85+
for (int k = 0; k < num_cells[2]; ++k) {
86+
phi_mixed_derivatives(i, j, k)[0] =
87+
(psi(i + axis_vectors(axis_x, 0), j + axis_vectors(axis_x, 1), k + axis_vectors(axis_x, 2))[axis_y] -
88+
psi(i - axis_vectors(axis_x, 0), j - axis_vectors(axis_x, 1), k - axis_vectors(axis_x, 2))[axis_y]) *
89+
one_over_dx[axis_x] * static_cast<T>(0.5);
90+
}
91+
92+
// Computing \frac{\partial}{\partial y} \left( \frac{\partial}{\partial z} \right).
93+
for (int i = 0; i < num_cells[0]; ++i)
94+
for (int j = 0; j < num_cells[1]; ++j)
95+
for (int k = 0; k < num_cells[2]; ++k) {
96+
phi_mixed_derivatives(i, j, k)[1] =
97+
(psi(i + axis_vectors(axis_y, 0), j + axis_vectors(axis_y, 1), k + axis_vectors(axis_y, 2))[axis_z] -
98+
psi(i - axis_vectors(axis_y, 0), j - axis_vectors(axis_y, 1), k - axis_vectors(axis_y, 2))[axis_z]) *
99+
one_over_dx[axis_y] * static_cast<T>(0.5);
100+
}
101+
102+
// Computing \frac{\partial}{\partial z} \left( \frac{\partial}{\partial x} \right).
103+
for (int i = 0; i < num_cells[0]; ++i)
104+
for (int j = 0; j < num_cells[1]; ++j)
105+
for (int k = 0; k < num_cells[2]; ++k) {
106+
phi_mixed_derivatives(i, j, k)[2] =
107+
(psi(i + axis_vectors(axis_z, 0), j + axis_vectors(axis_z, 1), k + axis_vectors(axis_z, 2))[axis_x] -
108+
psi(i - axis_vectors(axis_z, 0), j - axis_vectors(axis_z, 1), k - axis_vectors(axis_z, 2))[axis_x]) *
109+
one_over_dx[axis_z] * static_cast<T>(0.5);
110+
}
111+
112+
// Computing \frac{\partial}{\partial y} \left( \frac{\partial}{\partial z} \right).
113+
for (int i = 0; i < num_cells[0]; ++i)
114+
for (int j = 0; j < num_cells[1]; ++j)
115+
for (int k = 0; k < num_cells[2]; ++k) {
116+
// phi_mixed_derivatives(i, j, k)[1] =
117+
//(psi(i + axis_vectors(axis_y, 0), j + axis_vectors(axis_y, 1), k + axis_vectors(axis_y, 2))[axis_z] -
118+
// psi(i - axis_vectors(axis_y, 0), j - axis_vectors(axis_y, 1), k - axis_vectors(axis_y, 2))[axis_z]) *
119+
// one_over_dx[axis_y] * static_cast<T>(0.5);
120+
}
121+
}
122+
}
123+
55124
template <typename T_GRID, typename T>
56125
void GALS::CPU::Levelset<T_GRID, T>::print()
57126
{

0 commit comments

Comments
 (0)