41 T operator()(
const hrleVectorType<hrleIndexType, D> &indices,
int material) {
42 auto &grid = levelSet->getGrid();
43 double gridDelta = grid.getGridDelta();
45 hrleVectorType<T, 3> coordinate(0., 0., 0.);
46 for (
unsigned i = 0; i <
D; ++i) {
47 coordinate[i] = indices[i] * gridDelta;
51 neighborIterator.goToIndicesSequential(indices);
59 for (
int i = 0; i <
D; i++) {
60 const T deltaPos = gridDelta;
61 const T deltaNeg = -gridDelta;
63 const T phi0 = neighborIterator.getCenter().getValue();
64 const T phiPos = neighborIterator.getNeighbor(i).getValue();
65 const T phiNeg = neighborIterator.getNeighbor(i +
D).getValue();
67 T diffPos = (phiPos - phi0) / deltaPos;
68 T diffNeg = (phiNeg - phi0) / deltaNeg;
71 const T deltaPosPos = 2 * gridDelta;
72 const T deltaNegNeg = -2 * gridDelta;
75 neighborIterator.getNeighbor((
D * order) + i).getValue();
77 neighborIterator.getNeighbor((
D * order) +
D + i).getValue();
80 (((deltaNeg * phiPos - deltaPos * phiNeg) / (deltaPos - deltaNeg) +
82 (deltaPos * deltaNeg);
83 const T diffNegNeg = (((deltaNeg * phiNegNeg - deltaNegNeg * phiNeg) /
84 (deltaNegNeg - deltaNeg) +
86 (deltaNegNeg * deltaNeg);
87 const T diffPosPos = (((deltaPos * phiPosPos - deltaPosPos * phiPos) /
88 (deltaPosPos - deltaPos) +
90 (deltaPosPos * deltaPos);
92 if (std::signbit(diff00) == std::signbit(diffPosPos)) {
93 if (std::abs(diffPosPos * deltaPos) < std::abs(diff00 * deltaNeg)) {
94 diffPos -= deltaPos * diffPosPos;
96 diffPos += deltaNeg * diff00;
100 if (std::signbit(diff00) == std::signbit(diffNegNeg)) {
101 if (std::abs(diffNegNeg * deltaNeg) < std::abs(diff00 * deltaPos)) {
102 diffNeg -= deltaNeg * diffNegNeg;
104 diffNeg += deltaPos * diff00;
109 gradPos[i] = diffNeg;
110 gradNeg[i] = diffPos;
113 pow2(std::max(diffNeg,
T(0))) + pow2(std::min(diffPos,
T(0)));
115 pow2(std::min(diffNeg,
T(0))) + pow2(std::max(diffPos,
T(0)));
122 Vec3D<T> normalVector = {};
123 if (calculateNormalVectors) {
125 for (
int i = 0; i <
D; i++) {
126 T pos = neighborIterator.getNeighbor(i).getValue() -
127 neighborIterator.getCenter().getValue();
128 T neg = neighborIterator.getCenter().getValue() -
129 neighborIterator.getNeighbor(i +
D).getValue();
130 normalVector[i] = (pos + neg) * 0.5;
131 denominator += normalVector[i] * normalVector[i];
133 denominator = std::sqrt(denominator);
134 for (
unsigned i = 0; i <
D; ++i) {
135 normalVector[i] /= denominator;
140 Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
142 double scalarVelocity = velocities->getScalarVelocity(
143 coordArray, material, normalVector,
144 neighborIterator.getCenter().getPointId());
145 Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
146 coordArray, material, normalVector,
147 neighborIterator.getCenter().getPointId());
149 if (scalarVelocity > 0) {
150 vel_grad += std::sqrt(gradPosTotal) * scalarVelocity;
152 vel_grad += std::sqrt(gradNegTotal) * scalarVelocity;
155 for (
int w = 0; w <
D; w++) {
156 if (vectorVelocity[w] > 0.) {
157 vel_grad += vectorVelocity[w] * gradPos[w];
159 vel_grad += vectorVelocity[w] * gradNeg[w];