From e8a2ec99493514ae6f5fca5c9d8d3ef87c653288 Mon Sep 17 00:00:00 2001 From: Richard Christie Date: Wed, 9 Dec 2020 16:02:04 +1300 Subject: [PATCH] Fix boundary derivative smoothing Was taking derivative vector from wrong node. Make result consistent when updating/not updating directions. --- src/scaffoldmaker/utils/derivativemoothing.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/scaffoldmaker/utils/derivativemoothing.py b/src/scaffoldmaker/utils/derivativemoothing.py index ea8e3dee..4c365dda 100644 --- a/src/scaffoldmaker/utils/derivativemoothing.py +++ b/src/scaffoldmaker/utils/derivativemoothing.py @@ -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: @@ -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: