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

Separate variable interpolation from cubic sampling #25

Merged
merged 2 commits into from
Oct 17, 2018
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
53 changes: 27 additions & 26 deletions scaffoldmaker/meshtypes/meshtype_3d_heartatria1.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def generateBaseMesh(cls, region, options):
dd1 = [ -d for d in laBaseOuterd2[n1MidFreeWall]]
# get point on venous peak
# GRC fudge factor
px, pd1, _ = sampleCubicHermiteCurves([ ax, dx ], [ ad1, dd1 ], [], 2, lengthFractionStart = 0.4)
px, pd1 = sampleCubicHermiteCurves([ ax, dx ], [ ad1, dd1 ], elementsCountOut = 2, lengthFractionStart = 0.4, arcLengthDerivatives = True)[0:2]
nx = [ ax, [ px[1][0], px[1][1], aOuterHeight ] ]
nd1 = smoothCubicHermiteDerivativesLine(nx, [ ad1, [ pd1[1][0], pd1[1][1], 0.0 ] ], fixStartDerivative = True, fixEndDirection = True)
ex = nx[1]
Expand All @@ -363,26 +363,26 @@ def generateBaseMesh(cls, region, options):
bx = interpolateCubicHermite(ax, ad1, ex, ed1, xi)
bd1 = interpolateCubicHermiteDerivative(ax, ad1, ex, ed1, xi)
# cx = limit of venous atrium on ridge
cx, cd1, _, _ = getCubicHermiteCurvesPointAtArcDistance([ ax, bx, ex, dx ], [ ad1, bd1, ed1, dd1 ], ridgeVenousDistance)
cx, cd1, ce, cxi= getCubicHermiteCurvesPointAtArcDistance([ ax, bx, ex, dx ], [ ad1, bd1, ed1, dd1 ], ridgeVenousDistance)
if elementsCountRidgeVenous == 1:
#rx, rd1, _ = sampleCubicHermiteCurves([ ax, bx, cx ], [ ad1, bd1, cd1 ], [],
# elementsCountRidgeVenous)
rx = [ [ ax[0], ax[1], ax[2] ], [ cx[0], cx[1], cx[2] ] ]
rd1 = [ [ ad1[0], ad1[1], ad1[2] ], [ cd1[0], cd1[1], cd1[2] ] ]
else:
rx, rd1, _ = sampleCubicHermiteCurves([ ax, bx, cx ], [ ad1, bd1, cd1 ], [],
elementsCountRidgeVenous,
lengthFractionStart = 0.5, addLengthStart = 0.5*iaGrooveDerivative)
rx, rd1 = sampleCubicHermiteCurves([ ax, bx, cx ], [ ad1, bd1, cd1 ], elementsCountRidgeVenous,
lengthFractionStart = 0.5, addLengthStart = 0.5*iaGrooveDerivative,
arcLengthDerivatives = True)[0:2]

# get points on outside arch of "venous" left atrium, anterior and posterior
for na in range(elementsCountRidgeVenous + 1):
np = elementsCountAroundAtrialFreeWall - na
# sample arch from double cubic through anterior, ridge and posterior points
lx, ld2, ( ld1, ) = sampleCubicHermiteCurves(
lx, ld2, le, lxi = sampleCubicHermiteCurves(
[ laBaseOuterx[na], rx[na], laBaseOuterx[np] ],
[ laBaseOuterd2[na], [ -rd1[na][1], rd1[na][0], 0.0 ], [ -d for d in laBaseOuterd2[np]] ],
[ [ laBaseOuterd1[na], rd1[na], [ -d for d in laBaseOuterd1[np]] ] ],
2*elementsCountUpAtria, elementLengthStartEndRatio = aElementSizeRatioAnteriorPosterior)
2*elementsCountUpAtria, elementLengthStartEndRatio = aElementSizeRatioAnteriorPosterior,
arcLengthDerivatives = True)[0:4]
ld1 = interpolateSampleLinear([ laBaseOuterd1[na], rd1[na], [ -d for d in laBaseOuterd1[np]] ], le, lxi)

for noa in range(1, elementsCountUpAtria*2):
if noa <= elementsCountUpAtria:
laOuterx[noa][na] = lx[noa]
Expand Down Expand Up @@ -424,9 +424,10 @@ def generateBaseMesh(cls, region, options):
phi3 = xi*(-1.0 + 2.0*xi)
startDerivative = phi1*startDerivative1 + phi2*startDerivative2 + phi3*startDerivative3
endDerivative = vector.magnitude(bd2)
ex, ed2, ( ed1, ) = sampleCubicHermiteCurves([ ax, bx ], [ ad2, bd2 ], [ [ ad1, bd1 ] ], elementsCountUpAtria,
ex, ed2, ee, exi = sampleCubicHermiteCurves([ ax, bx ], [ ad2, bd2 ], elementsCountUpAtria,
addLengthStart = 0.5*startDerivative, lengthFractionStart = 0.5,
addLengthEnd = 0.5*endDerivative, lengthFractionEnd = 0.5)
addLengthEnd = 0.5*endDerivative, lengthFractionEnd = 0.5, arcLengthDerivatives = True)[0:4]
ed1 = interpolateSampleLinear([ ad1, bd1 ], ee, exi)
laOuterd2[0][n1] = ed2[0]
for n2 in range(1, elementsCountUpAtria):
laOuterx [n2][n1] = ex [n2]
Expand Down Expand Up @@ -524,9 +525,10 @@ def generateBaseMesh(cls, region, options):
fd1 = [ ( ud1[c]*math.cos(fradians) + ud2[c]*math.sin(fradians)) for c in range(3) ]
fd2 = [ (-ud1[c]*math.sin(fradians) + ud2[c]*math.cos(fradians)) for c in range(3) ]
fx = [ (ux[c] + fd1[c]) for c in range(3) ]
tx, td1, ( td2, ) = sampleCubicHermiteCurves([ fx, gx ], [ fd1, gd1 ], [ [ fd2, gd2 ] ], 2,
tx, td1, te, txi = sampleCubicHermiteCurves([ fx, gx ], [ fd1, gd1 ], elementsCountOut = 2,
addLengthStart = 0.5*vector.magnitude(fd1), lengthFractionStart = 0.5,
addLengthEnd = 0.5*vector.magnitude(gd1), lengthFractionEnd = 0.5)
addLengthEnd = 0.5*vector.magnitude(gd1), lengthFractionEnd = 0.5, arcLengthDerivatives = True)[0:4]
td2 = interpolateSampleLinear([ fd2, gd2 ], te, txi)
mx = tx [1]
md1 = td1[1]
md2 = td2[1]
Expand Down Expand Up @@ -563,11 +565,9 @@ def generateBaseMesh(cls, region, options):
# get start distance to account for aBaseSlopeRadians
scale2 = -aBaseSlopeHeight/pd2[2]
addLengthEnd = vector.magnitude([ pd2[0]*scale2, pd2[1]*scale2, aBaseSlopeHeight ])
ix, id2, ( id1, ) = sampleCubicHermiteCurves(
[ ax , mx , px ],
[ ad2, md2, pd2 ],
[ [ ad1, md1, pd1 ] ],
2*elementsCountUpAtria, addLengthStart, addLengthEnd, elementLengthStartEndRatio = aElementSizeRatioAnteriorPosterior)
ix, id2, ie, ixi = sampleCubicHermiteCurves([ ax , mx , px ], [ ad2, md2, pd2 ], 2*elementsCountUpAtria,
addLengthStart, addLengthEnd, elementLengthStartEndRatio = aElementSizeRatioAnteriorPosterior, arcLengthDerivatives = True)[0:4]
id1 = interpolateSampleLinear([ ad1, md1, pd1 ], ie, ixi)
for noa in range(elementsCountUpAtria*2 + 1):
nop = elementsCountUpAtria*2 - noa
if noa <= elementsCountUpAtria:
Expand Down Expand Up @@ -1164,7 +1164,7 @@ def generateBaseMesh(cls, region, options):

# GRC fudgefactors, multiple of inner radius that inlet centre is away from septum
rpvSeptumDistanceFactor = 2.0
mx, md1, _, _ = getCubicHermiteCurvesPointAtArcDistance(rx, rd1, 0.5*aSeptumThickness + rpvSeptumDistanceFactor*rpvInnerRadius + rx[0][0])
mx, md1 = getCubicHermiteCurvesPointAtArcDistance(rx, rd1, 0.5*aSeptumThickness + rpvSeptumDistanceFactor*rpvInnerRadius + rx[0][0])[0:2]
laSeptumModX = aBaseInnerMajorMag*math.cos(aMajorAxisRadians)*math.cos(laSeptumRadians) \
+ aBaseInnerMinorMag*math.sin(aMajorAxisRadians)*math.sin(laSeptumRadians)
laOuterMajorx = [ aBaseOuterMajorMag*math.cos(aMajorAxisRadians), -aBaseOuterMajorMag*math.sin(aMajorAxisRadians), 0.0 ]
Expand Down Expand Up @@ -1199,8 +1199,8 @@ def generateBaseMesh(cls, region, options):
coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1, bd2)
nodeIdentifier += 1

px, pd1, _ = sampleCubicHermiteCurves([ ax, mx, bx ], [ ad2, md2, bd2 ], [], 2,
lengthFractionEnd = rpvPositionUp/(2.0 - rpvPositionUp))
px, pd1 = sampleCubicHermiteCurves([ ax, mx, bx ], [ ad2, md2, bd2 ], 2,
lengthFractionEnd = rpvPositionUp/(2.0 - rpvPositionUp), arcLengthDerivatives = True)[0:2]
rcpvx = px[1]
rcpvd1 = pd1[1]

Expand All @@ -1211,8 +1211,9 @@ def generateBaseMesh(cls, region, options):
coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1, rcpvd1)
nodeIdentifier += 1

ex, _, _ = sampleCubicHermiteCurves([ laOuterx[0][n1MidFreeWall], vx ],
[ laOuterd2[0][n1MidFreeWall], vd2 ], [], 2, lengthFractionStart = lpvPositionUp/(1.0 - lpvPositionUp))
ex = sampleCubicHermiteCurves([ laOuterx[0][n1MidFreeWall], vx ],
[ laOuterd2[0][n1MidFreeWall], vd2 ], elementsCountOut = 2,
lengthFractionStart = lpvPositionUp/(1.0 - lpvPositionUp), arcLengthDerivatives = True)[0]
lcpvx = ex[1]

if False:
Expand Down Expand Up @@ -1472,8 +1473,8 @@ def generateBaseMesh(cls, region, options):
md2 = [ 0.5*(bx[0] - ax[0]), 0.5*(bx[1] - ax[1]), 0.0 ]

gap = 2.0 - svcPositionUp - ivcPositionUp
px, _, _ = sampleCubicHermiteCurves([ ax, mx, bx ], [ ad2, md2, bd2 ], [], 3, \
lengthFractionStart = svcPositionUp/gap, lengthFractionEnd = ivcPositionUp/gap)
px = sampleCubicHermiteCurves([ ax, mx, bx ], [ ad2, md2, bd2 ], elementsCountOut = 3, \
lengthFractionStart = svcPositionUp/gap, lengthFractionEnd = ivcPositionUp/gap, arcLengthDerivatives = True)[0]
svcWallx = px[1]
ivcWallx = px[2]

Expand Down
27 changes: 14 additions & 13 deletions scaffoldmaker/meshtypes/meshtype_3d_heartventricles1.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@ def generateBaseMesh(cls, region, options):
# extract septum points, reversing order and derivative
nx = [ layerInnerx [-1] ] + nx [-1:-numberAround:-1] + [ layerInnerx [1 - elementsCountAroundRVFreeWall] ]
nd1 = [ layerInnerd1[-1] ] + [ ([-d for d in nd1[n1] ]) for n1 in range(-1, -numberAround, -1) ] + [ layerInnerd1[1 - elementsCountAroundRVFreeWall] ]
px, pd1, _ = sampleCubicHermiteCurves(nx, nd1, [], elementsCountAroundVSeptum + 2,
px, pd1 = sampleCubicHermiteCurves(nx, nd1, elementsCountAroundVSeptum + 2,
addLengthStart = 0.5*vector.magnitude(nd1[ 0]), lengthFractionStart = 0.5,
addLengthEnd = 0.5*vector.magnitude(nd1[-1]), lengthFractionEnd = 0.5,
arcLengthDerivatives = False)
arcLengthDerivatives = False)[0:2]
for n1 in range(elementsCountAroundVSeptum + 1):
lvx = lvInnerx[n2][-n1]
rvx = px[n1 + 1]
Expand Down Expand Up @@ -487,11 +487,11 @@ def generateBaseMesh(cls, region, options):
bx = rvInnerx[n2][n1]
bd1 = rvInnerd1[n2][n1]
bd2 = [ dFactor*d for d in rvInnerd2[n2][n1] ]
px, pd2, ( pd1, ) = sampleCubicHermiteCurves([ ax, bx ], [ ad2, bd2 ], [ [ ad1, bd1 ] ], elementsCountOut = 2,
px, pd2, pe, pxi = sampleCubicHermiteCurves([ ax, bx ], [ ad2, bd2 ], elementsCountOut = 2,
addLengthStart = 0.5*vector.magnitude(ad2)/dFactor, lengthFractionStart = 0.5,
addLengthEnd = 0.5*vector.magnitude(bd2)/dFactor, lengthFractionEnd = 0.5, arcLengthDerivatives = False)
addLengthEnd = 0.5*vector.magnitude(bd2)/dFactor, lengthFractionEnd = 0.5, arcLengthDerivatives = False)[0:4]
sx .append(px[1])
sd1.append(pd1[1])
sd1.append(interpolateSampleLinear([ ad1, bd1 ], pe[1:2], pxi[1:2])[0])
sd2.append(pd2[1])
n1 = 2*elementsCountAroundRVFreeWall - 1
ax = rvInnerx [n2][n1]
Expand All @@ -501,9 +501,10 @@ def generateBaseMesh(cls, region, options):
bx = rvInnerx [n2][n1]
bd1 = [ -d for d in rvInnerd1[n2][n1] ]
bd2 = rvInnerd2[n2][n1]
px, pd1, ( pd2, ) = sampleCubicHermiteCurves([ ax ] + sx + [ bx ], [ ad2 ] + sd1 + [ bd2 ], [ [ ad1 ] + sd2 + [ bd1 ] ], elementsCountAroundRVFreeWall + 2,
px, pd1, pe, pxi = sampleCubicHermiteCurves([ ax ] + sx + [ bx ], [ ad2 ] + sd1 + [ bd2 ], elementsCountAroundRVFreeWall + 2,
addLengthStart = 0.5*vector.magnitude(ad2)/dFactor, lengthFractionStart = 0.5,
addLengthEnd = 0.5*vector.magnitude(bd2)/dFactor, lengthFractionEnd = 0.5, arcLengthDerivatives = True)
addLengthEnd = 0.5*vector.magnitude(bd2)/dFactor, lengthFractionEnd = 0.5, arcLengthDerivatives = False)[0:4]
pd2 = interpolateSampleLinear([ ad1 ] + sd2 + [ bd1 ], pe, pxi)
n2 = elementsCountUpLVApex - 1
for n1 in range(1, elementsCountAroundRVFreeWall + 2):
rvInnerx [n2].append(px [n1])
Expand Down Expand Up @@ -1023,9 +1024,9 @@ def getSeptumPoints(septumArcRadians, lvRadius, radialDisplacement, elementsCoun
cubicLength = computeCubicHermiteArcLength(x1, d1, x2, d2, False)
elementLengthMid = (2.0*cubicLength - lvRadius*radiansPerElementAroundLVFreeWall)/(elementsCountAroundVSeptum + n3 - 1)
odd = elementsCountAroundVSeptum % 2
sx, sd1, _ = sampleCubicHermiteCurves([ x1, x2 ], [ d1, d2 ], [], elementsCountAroundVSeptum//2 + odd,
sx, sd1 = sampleCubicHermiteCurves([ x1, x2 ], [ d1, d2 ], elementsCountAroundVSeptum//2 + odd,
lengthFractionStart = 0.5 if odd else 1.0,
addLengthEnd = cubicLength - 0.5*elementsCountAroundVSeptum*elementLengthMid)
addLengthEnd = cubicLength - 0.5*elementsCountAroundVSeptum*elementLengthMid, arcLengthDerivatives = True)[0:2]
if odd:
sx = sx[1:]
sd1 = sd1[1:]
Expand Down Expand Up @@ -1223,13 +1224,13 @@ def getRVOuterSize(xiUpWidth, xiUpSide, rvWidth, rvWidthGrowthFactor, rvSideExte
'''
if xiUpWidth < 0.0:
return 0.0, 0.0
_, _, _, xiUpWidthRaw = getCubicHermiteCurvesPointAtArcDistance([ [ 0.0 ], [ 1.0 ] ],
xiUpWidthRaw = getCubicHermiteCurvesPointAtArcDistance([ [ 0.0 ], [ 1.0 ] ],
[ [ 2.0*(1.0 - rvWidthGrowthFactor) ] , [ 2.0*rvWidthGrowthFactor ] ],
xiUpWidth)
xiUpWidth)[3]
xiUpWidthMod = 1.0 - (1.0 - xiUpWidthRaw)*(1.0 - xiUpWidthRaw)
_, _, _, xiUpSideMod = getCubicHermiteCurvesPointAtArcDistance([ [ 0.0 ], [ 1.0 ] ],
xiUpSideMod = getCubicHermiteCurvesPointAtArcDistance([ [ 0.0 ], [ 1.0 ] ],
[ [ 2.0*(1.0 - rvSideExtensionGrowthFactor) ] , [ 2.0*rvSideExtensionGrowthFactor ] ],
max(xiUpSide, 0.0))
max(xiUpSide, 0.0))[3]
widthExtension = interpolateCubicHermite([0.0], [0.0], [rvWidth], [0.0], xiUpWidthMod)[0]
sideExtension = interpolateCubicHermite([0.0], [0.0], [rvSideExtension], [0.0], xiUpSideMod)[0]
return widthExtension, sideExtension
7 changes: 4 additions & 3 deletions scaffoldmaker/utils/eftfactory_tricubichermite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,10 +1310,11 @@ def createAnnulusMesh3d(self,
for c in range(3):
bd2[c] += derivativesMap[ds]*endPointsd[ds][n3][n1][c]

mx, md2, ( md1, thi ) = sampleCubicHermiteCurves([ ax, bx ], [ ad2, bd2 ],
[ [ ad1, bd1 ], [ thicknesses[0][n1], thicknesses[-1][n1] ] ], elementsCountRadial,
mx, md2, me, mxi = sampleCubicHermiteCurves([ ax, bx ], [ ad2, bd2 ], elementsCountRadial,
addLengthStart = 0.5*vector.magnitude(ad2), lengthFractionStart = 0.5,
addLengthEnd = 0.5*vector.magnitude(bd2), lengthFractionEnd = 0.5)
addLengthEnd = 0.5*vector.magnitude(bd2), lengthFractionEnd = 0.5, arcLengthDerivatives = True)[0:4]
md1 = interpolateSampleLinear([ ad1, bd1 ], me, mxi)
thi = interpolateSampleLinear([ thicknesses[0][n1], thicknesses[-1][n1] ], me, mxi)
md2 = smoothCubicHermiteDerivativesLine(mx, md2, fixStartDerivative = True, fixEndDerivative = True)
for n2 in range(1, elementsCountRadial):
px [n3][n2][n1] = mx [n2]
Expand Down
Loading