41 T operator()(
const hrleVectorType<hrleIndexType, D> &indices,
int material) {
43 auto &grid = levelSet->getGrid();
44 double gridDelta = grid.getGridDelta();
46 hrleVectorType<T, 3> coordinate(0., 0., 0.);
47 for (
unsigned i = 0; i <
D; ++i) {
48 coordinate[i] = indices[i] * gridDelta;
52 neighborIterator.goToIndicesSequential(indices);
55 Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
63 Vec3D<T> normalVector = {};
66 for (
int i = 0; i <
D; i++) {
68 const T deltaPos = gridDelta;
69 const T deltaNeg = -gridDelta;
71 const T phi0 = neighborIterator.getCenter().getValue();
72 const T phiPos = neighborIterator.getNeighbor(i).getValue();
73 const T phiNeg = neighborIterator.getNeighbor(i +
D).getValue();
75 T diffPos = (phiPos - phi0) / deltaPos;
76 T diffNeg = (phiNeg - phi0) / deltaNeg;
79 const T deltaPosPos = 2 * gridDelta;
80 const T deltaNegNeg = -2 * gridDelta;
83 (((deltaNeg * phiPos - deltaPos * phiNeg) / (deltaPos - deltaNeg) +
85 (deltaPos * deltaNeg);
87 neighborIterator.getNeighbor((
D * order) + i).getValue();
89 neighborIterator.getNeighbor((
D * order) +
D + i).getValue();
91 const T diffNegNeg = (((deltaNeg * phiNegNeg - deltaNegNeg * phiNeg) /
92 (deltaNegNeg - deltaNeg) +
94 (deltaNegNeg * deltaNeg);
95 const T diffPosPos = (((deltaPos * phiPosPos - deltaPosPos * phiPos) /
96 (deltaPosPos - deltaPos) +
98 (deltaPosPos * deltaPos);
100 if (std::signbit(diff00) == std::signbit(diffPosPos)) {
101 if (std::abs(diffPosPos * deltaPos) < std::abs(diff00 * deltaNeg)) {
102 diffPos -= deltaPos * diffPosPos;
104 diffPos += deltaNeg * diff00;
108 if (std::signbit(diff00) == std::signbit(diffNegNeg)) {
109 if (std::abs(diffNegNeg * deltaNeg) < std::abs(diff00 * deltaPos)) {
110 diffNeg -= deltaNeg * diffNegNeg;
112 diffNeg += deltaPos * diff00;
117 gradPos[i] = diffNeg;
118 gradNeg[i] = diffPos;
120 normalVector[i] = (diffNeg + diffPos) * 0.5;
121 normalModulus += normalVector[i] * normalVector[i];
123 grad += pow2((diffNeg + diffPos) * 0.5);
127 normalModulus = std::sqrt(normalModulus);
128 for (
unsigned i = 0; i <
D; ++i) {
129 normalVector[i] /= normalModulus;
133 double scalarVelocity = velocities->getScalarVelocity(
134 coordArray, material, normalVector,
135 neighborIterator.getCenter().getPointId());
136 Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
137 coordArray, material, normalVector,
138 neighborIterator.getCenter().getPointId());
142 if (scalarVelocity != 0.) {
143 totalGrad = scalarVelocity * std::sqrt(grad);
146 for (
int w = 0; w <
D; w++) {
147 if (vectorVelocity[w] > 0.) {
148 totalGrad += vectorVelocity[w] * gradPos[w];
150 totalGrad += vectorVelocity[w] * gradNeg[w];
156 for (
unsigned i = 0; i <
D; ++i) {
158 std::abs((scalarVelocity + vectorVelocity[i]) * normalVector[i]);
159 dissipation += alphaFactor * alpha * (gradNeg[i] - gradPos[i]) * 0.5;
162 return totalGrad - ((totalGrad != 0.) ? dissipation : 0);