Skip to content

Commit

Permalink
Merge pull request #112 from rchristie/derivative_bugfix
Browse files Browse the repository at this point in the history
Fix boundary derivative smoothing
  • Loading branch information
rchristie authored Dec 9, 2020
2 parents a7310c9 + e8a2ec9 commit 618e7cd
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/scaffoldmaker/utils/derivativemoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ def smooth(self, updateDirections=False, maxIterations=10, arcLengthTolerance=1.
if edgeCount == 1:
# boundary smoothing over single edge
nodeIdentifier, nodeValueLabel, nodeVersion = derivativeKey
fieldcache.setNode(self._nodes.findNodeByIdentifier(nodeIdentifier))
edge, expressionIndex, totalScaleFactor = derivativeEdges[0]
# re-evaluate arc length so parameters are up-to-date for other end
arcLength = edge.evaluateArcLength(self._nodes, self._field, fieldcache)
fieldcache.setNode(self._nodes.findNodeByIdentifier(nodeIdentifier)) # since changed by evaluateArcLength
otherExpressionIndex = 3 if (expressionIndex == 1) else 1
otherd = edge.getParameter(otherExpressionIndex)
if updateDirections:
Expand All @@ -376,12 +376,11 @@ def smooth(self, updateDirections=False, maxIterations=10, arcLengthTolerance=1.
x = [ d/totalScaleFactor for d in x ]
else:
result, x = self._field.getNodeParameters(fieldcache, -1, nodeValueLabel, nodeVersion, componentsCount)
othermag = magnitude(otherd)
mag = (2.0*arcLength - othermag)/totalScaleFactor
if (mag <= 0.0):
print('Node', nodeIdentifier, 'label', nodeValueLabel, 'version', nodeVersion, 'has negative mag', mag)
x = setMagnitude(x, mag)
fieldcache.setNode(self._nodes.findNodeByIdentifier(nodeIdentifier)) # need to set again as changed node in edge.evaluateArcLength
othermag = magnitude(otherd)
mag = (2.0*arcLength - othermag)/math.fabs(totalScaleFactor)
if (mag <= 0.0):
print('Derivative smoothing: Node', nodeIdentifier, 'label', nodeValueLabel, 'version', nodeVersion, 'has negative magnitude', mag)
x = setMagnitude(x, mag)
result = self._field.setNodeParameters(fieldcache, -1, nodeValueLabel, nodeVersion, x)
# record modified nodes while ChangeManager is in effect
if self._editNodesetGroup:
Expand Down

0 comments on commit 618e7cd

Please sign in to comment.