61 T operator()(
const hrleVectorType<hrleIndexType, D> &indices,
int material) {
63 auto &grid = levelSet->getGrid();
64 double gridDelta = grid.getGridDelta();
66 hrleVectorType<T, 3> coordinate(0., 0., 0.);
67 for (
unsigned i = 0; i <
D; ++i) {
68 coordinate[i] = indices[i] * gridDelta;
72 neighborIterator.goToIndicesSequential(indices);
75 Vec3D<T> coordArray = {coordinate[0], coordinate[1], coordinate[2]};
83 Vec3D<T> normalVector = {};
86 for (
int i = 0; i <
D; i++) {
87 hrleVectorType<hrleIndexType, D> posUnit(0);
88 hrleVectorType<hrleIndexType, D> negUnit(0);
92 const T deltaPos = gridDelta;
93 const T deltaNeg = -gridDelta;
95 const T phi0 = neighborIterator.getCenter().getValue();
96 const T phiPos = neighborIterator.getNeighbor(posUnit).getValue();
97 const T phiNeg = neighborIterator.getNeighbor(negUnit).getValue();
99 T diffPos = (phiPos - phi0) / deltaPos;
100 T diffNeg = (phiNeg - phi0) / deltaNeg;
106 const T deltaPosPos = 2 * gridDelta;
107 const T deltaNegNeg = -2 * gridDelta;
110 (((deltaNeg * phiPos - deltaPos * phiNeg) / (deltaPos - deltaNeg) +
112 (deltaPos * deltaNeg);
113 const T phiPosPos = neighborIterator.getNeighbor(posUnit).getValue();
114 const T phiNegNeg = neighborIterator.getNeighbor(negUnit).getValue();
116 const T diffNegNeg = (((deltaNeg * phiNegNeg - deltaNegNeg * phiNeg) /
117 (deltaNegNeg - deltaNeg) +
119 (deltaNegNeg * deltaNeg);
120 const T diffPosPos = (((deltaPos * phiPosPos - deltaPosPos * phiPos) /
121 (deltaPosPos - deltaPos) +
123 (deltaPosPos * deltaPos);
125 if (std::signbit(diff00) == std::signbit(diffPosPos)) {
126 if (std::abs(diffPosPos * deltaPos) < std::abs(diff00 * deltaNeg)) {
127 diffPos -= deltaPos * diffPosPos;
129 diffPos += deltaNeg * diff00;
133 if (std::signbit(diff00) == std::signbit(diffNegNeg)) {
134 if (std::abs(diffNegNeg * deltaNeg) < std::abs(diff00 * deltaPos)) {
135 diffNeg -= deltaNeg * diffNegNeg;
137 diffNeg += deltaPos * diff00;
142 gradPos[i] = diffNeg;
143 gradNeg[i] = diffPos;
145 normalVector[i] = (diffNeg + diffPos) * 0.5;
146 normalModulus += normalVector[i] * normalVector[i];
148 grad += pow2((diffNeg + diffPos) * 0.5);
152 normalModulus = std::sqrt(normalModulus);
153 for (
unsigned i = 0; i <
D; ++i) {
154 normalVector[i] /= normalModulus;
158 double scalarVelocity = velocities->getScalarVelocity(
159 coordArray, material, normalVector,
160 neighborIterator.getCenter().getPointId());
161 Vec3D<T> vectorVelocity = velocities->getVectorVelocity(
162 coordArray, material, normalVector,
163 neighborIterator.getCenter().getPointId());
167 if (scalarVelocity != 0.) {
168 totalGrad = scalarVelocity * std::sqrt(grad);
171 for (
int w = 0; w <
D; w++) {
172 if (vectorVelocity[w] > 0.) {
173 totalGrad += vectorVelocity[w] * gradPos[w];
175 totalGrad += vectorVelocity[w] * gradNeg[w];
183 const hrleIndexType minIndex = -1;
184 const hrleIndexType maxIndex = 1;
185 const unsigned numNeighbors = std::pow((maxIndex - minIndex) - 1,
D);
187 hrleVectorType<hrleIndexType, D> neighborIndex(minIndex);
188 for (
unsigned i = 0; i < numNeighbors; ++i) {
190 for (
unsigned dir = 0; dir <
D; ++dir) {
191 coords[dir] = coordinate[dir] + neighborIndex[dir] * gridDelta;
193 Vec3D<T> normal = {};
194 double normalModulus = 0.;
195 auto center = neighborIterator.getNeighbor(neighborIndex).getValue();
196 for (
unsigned dir = 0; dir <
D; ++dir) {
197 hrleVectorType<hrleIndexType, D> unity(0);
200 neighborIterator.getNeighbor(neighborIndex - unity).getValue();
202 neighborIterator.getNeighbor(neighborIndex + unity).getValue();
203 normal[dir] = calculateNormalComponent(neg, center, pos, gridDelta);
204 normalModulus += normal[dir] * normal[dir];
206 normalModulus = std::sqrt(normalModulus);
208 T scaVel = velocities->getScalarVelocity(
209 coords, material, normal,
210 neighborIterator.getCenter().getPointId());
211 auto vecVel = velocities->getVectorVelocity(
212 coords, material, normal,
213 neighborIterator.getCenter().getPointId());
215 for (
unsigned dir = 0; dir <
D; ++dir) {
217 normal[i] /= normalModulus;
218 T tempAlpha = std::abs((scaVel + vecVel[i]) * normal[i]);
219 alpha[dir] = std::max(alpha[dir], tempAlpha);
223 incrementIndices(neighborIndex, minIndex, maxIndex);
229 for (
unsigned i = 0; i <
D; ++i) {
230 dissipation += alphaFactor * alpha[i] * (gradNeg[i] - gradPos[i]) * 0.5;
235 return totalGrad - ((totalGrad != 0.) ? dissipation : 0);