42 T operator()(
const hrleVectorType<hrleIndexType, D> &indices,
int material) {
44 auto &grid = levelSet->getGrid();
45 double gridDelta = grid.getGridDelta();
47 hrleVectorType<T, 3> coordinate(0., 0., 0.);
48 for (
unsigned i = 0; i <
D; ++i) {
49 coordinate[i] = indices[i] * gridDelta;
53 neighborIterator.goToIndicesSequential(indices);
61 Vec3D<T> normalVector = {};
63 const bool calcNormals = calculateNormalVectors;
65 for (
int i = 0; i <
D; i++) {
67 const T deltaPos = gridDelta;
68 const T deltaNeg = -gridDelta;
70 const T phi0 = neighborIterator.getCenter().getValue();
71 const T phiPos = neighborIterator.getNeighbor(i).getValue();
72 const T phiNeg = neighborIterator.getNeighbor(i +
D).getValue();
74 T diffPos = (phiPos - phi0) / deltaPos;
75 T diffNeg = (phiNeg - phi0) / deltaNeg;
78 const T deltaPosPos = 2 * gridDelta;
79 const T deltaNegNeg = -2 * gridDelta;
82 (((deltaNeg * phiPos - deltaPos * phiNeg) / (deltaPos - deltaNeg) +
84 (deltaPos * deltaNeg);
86 neighborIterator.getNeighbor((
D * order) + i).getValue();
88 neighborIterator.getNeighbor((
D * order) +
D + i).getValue();
90 const T diffNegNeg = (((deltaNeg * phiNegNeg - deltaNegNeg * phiNeg) /
91 (deltaNegNeg - deltaNeg) +
93 (deltaNegNeg * deltaNeg);
94 const T diffPosPos = (((deltaPos * phiPosPos - deltaPosPos * phiPos) /
95 (deltaPosPos - deltaPos) +
97 (deltaPosPos * deltaPos);
99 if (std::signbit(diff00) == std::signbit(diffPosPos)) {
100 if (std::abs(diffPosPos * deltaPos) < std::abs(diff00 * deltaNeg)) {
101 diffPos -= deltaPos * diffPosPos;
103 diffPos += deltaNeg * diff00;
107 if (std::signbit(diff00) == std::signbit(diffNegNeg)) {
108 if (std::abs(diffNegNeg * deltaNeg) < std::abs(diff00 * deltaPos)) {
109 diffNeg -= deltaNeg * diffNegNeg;
111 diffNeg += deltaPos * diff00;
116 gradPos[i] = diffNeg;
117 gradNeg[i] = diffPos;
120 normalVector[i] = (diffNeg + diffPos) * 0.5;
121 normalModulus += normalVector[i] * normalVector[i];
124 grad += pow2((diffNeg + diffPos) * 0.5);
125 dissipation += (diffPos - diffNeg) * 0.5;
129 normalModulus = std::sqrt(normalModulus);
130 for (
unsigned i = 0; i <
D; ++i) {
131 normalVector[i] /= normalModulus;
136 Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
138 double scalarVelocity = velocities->getScalarVelocity(
139 coordArray, material, normalVector,
140 neighborIterator.getCenter().getPointId());
141 Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
142 coordArray, material, normalVector,
143 neighborIterator.getCenter().getPointId());
146 if (scalarVelocity != 0.) {
147 totalGrad = scalarVelocity * std::sqrt(grad);
150 for (
int w = 0; w <
D; w++) {
151 if (vectorVelocity[w] > 0.) {
152 totalGrad += vectorVelocity[w] * gradPos[w];
154 totalGrad += vectorVelocity[w] * gradNeg[w];
158 return totalGrad - ((totalGrad != 0.) ? alpha * dissipation : 0);