Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle d1 scaling when using inward and update unit test for bladder #237

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/scaffoldmaker/utils/tubemesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def extrudeSurfaceCoordinates(xSurf, d1Surf, d2Surf, d3Surf,
:param d1Surf: Derivatives on surface around tube
:param d2Surf: Derivatives on surface along tube
:param d3Surf: Derivatives on surface through wall
:param wallThicknessList: Wall thickness for each element along tube
:param wallThicknessList: Wall thickness for each node along tube
:param relativeThicknessList: Relative wall thickness for each element through wall
:param elementsCountAround: Number of elements around tube
:param elementsCountAlong: Number of elements along tube
Expand Down Expand Up @@ -292,8 +292,10 @@ def extrudeSurfaceCoordinates(xSurf, d1Surf, d2Surf, d3Surf,
# Calculate curvature along elements around
prevIdx = n - 1 if (n1 != 0) else (n2 + 1)*elementsCountAround - 1
nextIdx = n + 1 if (n1 < elementsCountAround - 1) else n2*elementsCountAround
kappam = interp.getCubicHermiteCurvatureSimple(xSurf[prevIdx], d1Surf[prevIdx], xSurf[n], d1Surf[n], 1.0)
kappap = interp.getCubicHermiteCurvatureSimple(xSurf[n], d1Surf[n], xSurf[nextIdx], d1Surf[nextIdx], 0.0)
kappam = interp.getCubicHermiteCurvature(xSurf[prevIdx], d1Surf[prevIdx], xSurf[n], d1Surf[n],
vector.normalise(d3Surf[n]), 1.0)
kappap = interp.getCubicHermiteCurvature(xSurf[n], d1Surf[n], xSurf[nextIdx], d1Surf[nextIdx],
vector.normalise(d3Surf[n]), 0.0)
if not transitElementList[n1] and not transitElementList[(n1-1)%elementsCountAround]:
curvatureAround = 0.5*(kappam + kappap)
elif transitElementList[n1]:
Expand Down Expand Up @@ -336,20 +338,15 @@ def extrudeSurfaceCoordinates(xSurf, d1Surf, d2Surf, d3Surf,
xList.append(x)

# dx_ds1
factor = 1.0 + wallThickness * xi3 * curvatureAroundSurf[n]
factor = 1.0 - wallOutwardDisplacement * (xi3 if outward else (1.0 - xi3)) * curvatureAroundSurf[n]
d1 = [factor*c for c in d1Surf[n]]
d1List.append(d1)

# dx_ds2
curvature = curvatureAlong[n]
distance = vector.magnitude([x[i] - xSurf[n][i] for i in range(3)])
if outward:
factor = 1.0 - curvature * distance
else:
factor = 1.0 + curvature * distance
d2 = [factor*c for c in d2Surf[n]]
factor = 1.0 - wallOutwardDisplacement * (xi3 if outward else (1.0 - xi3)) * curvatureAlong[n]
d2 = [factor * c for c in d2Surf[n]]
d2List.append(d2)
curvatureList.append(curvature)
curvatureList.append(curvatureAlong[n])

# dx_ds3
d3 = [c * wallThickness * (relativeThicknessList[n3] if relativeThicknessList else 1.0/elementsCountThroughWall) for c in norm]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bladder.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def test_bladder1(self):
fieldcache = fieldmodule.createFieldcache()
result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(surfaceArea, 3.6740101958977296, delta=1.0E-8)
self.assertAlmostEqual(surfaceArea, 3.6692194413389085, delta=1.0E-8)
result, volume = volumeField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(volume, 0.02543636759208289, delta=1.0E-8)
self.assertAlmostEqual(volume, 0.025324264242304235, delta=1.0E-8)
# result, flatSurfaceArea = flatSurfaceAreaField.evaluateReal(fieldcache, 1)
# self.assertEqual(result, RESULT_OK)
# self.assertAlmostEqual(flatSurfaceArea, 32905.65612644931, delta=1.0E-3)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bladderurethra.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def test_bladderurethra1(self):
fieldcache = fieldmodule.createFieldcache()
result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(surfaceArea, 4564.851396969593, delta=1.0E-6)
self.assertAlmostEqual(surfaceArea, 4564.518506192725, delta=1.0E-6)
result, volume = volumeField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(volume, 2221.1973927759996, delta=1.0E-6)
self.assertAlmostEqual(volume, 2218.8526070746825, delta=1.0E-6)
result, flatSurfaceArea = flatSurfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(flatSurfaceArea, 4087.7670057497376, delta=1.0E-3)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cecum.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_cecum1(self):
self.assertTrue(coordinates.isValid())
minimums, maximums = evaluateFieldNodesetRange(coordinates, nodes)
assertAlmostEqualList(self, minimums, [-49.01658984455258, -46.89686037622053, -2.343256155753525], 1.0E-6)
assertAlmostEqualList(self, maximums, [42.18085849205387, 54.902119877312636, 180.0], 1.0E-6)
assertAlmostEqualList(self, maximums, [42.18085849205387, 54.90211871346987, 180.0], 1.0E-6)

with ChangeManager(fieldmodule):
one = fieldmodule.createFieldConstant(1.0)
Expand All @@ -82,10 +82,10 @@ def test_cecum1(self):
fieldcache = fieldmodule.createFieldcache()
result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(surfaceArea, 65960.86557108756, delta=1.0E-6)
self.assertAlmostEqual(surfaceArea, 65905.04907630144, delta=1.0E-6)
result, volume = volumeField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(volume, 127907.08806524028, delta=1.0E-6)
self.assertAlmostEqual(volume, 127866.92887366761, delta=1.0E-6)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions tests/test_colon.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ def test_colon1(self):
fieldcache = fieldmodule.createFieldcache()
result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(surfaceArea, 174848.22676409548, delta=1.0E-6)
self.assertAlmostEqual(surfaceArea, 174749.05868939584, delta=1.0E-6)
result, volume = volumeField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(volume, 313689.5754456567, delta=1.0E-6)
self.assertAlmostEqual(volume, 314670.65237072564, delta=1.0E-6)

def test_mousecolon1(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_colonsegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def test_humancolonsegment1(self):
fieldcache = fieldmodule.createFieldcache()
result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(surfaceArea, 21035.8818469729, delta=1.0E-6)
self.assertAlmostEqual(surfaceArea, 21032.6788157990, delta=1.0E-6)
result, volume = volumeField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(volume, 39781.704358310606, delta=1.0E-6)
self.assertAlmostEqual(volume, 39836.60239335828, delta=1.0E-6)

def test_mousecolonsegment1(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_esophagus.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def test_esophagus1(self):
fieldcache = fieldmodule.createFieldcache()
result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(surfaceArea, 13994.064785386161, delta=1.0E-6)
self.assertAlmostEqual(surfaceArea, 13952.301236699395, delta=1.0E-6)
result, volume = volumeField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(volume, 35763.04473815047, delta=1.0E-6)
self.assertAlmostEqual(volume, 35523.4403218177, delta=1.0E-6)

# check some annotationGroups:
expectedSizes3d = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_smallintestine.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def test_smallintestine1(self):
fieldcache = fieldmodule.createFieldcache()
result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(surfaceArea, 143.8506801217898, delta=1.0E-6)
self.assertAlmostEqual(surfaceArea, 143.8501823770281, delta=1.0E-6)
result, volume = volumeField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(volume, 13.608918623618687, delta=1.0E-6)
self.assertAlmostEqual(volume, 13.608455265457282, delta=1.0E-6)
result, flatSurfaceArea = flatSurfaceAreaField.evaluateReal(fieldcache, 1)
self.assertEqual(result, RESULT_OK)
self.assertAlmostEqual(flatSurfaceArea, 144.42091907104523, delta=1.0E-3)
Expand Down