Guest User

Untitled

a guest
Jun 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. Imports MathNet.Numerics.LinearAlgebra.Double
  2.  
  3. Public Class NDSpline2
  4.  
  5. Private BasisCache(,,)() As DenseMatrix
  6.  
  7. Public Structure SplineInterpResult
  8. Public z() As Double
  9. Public dzdx(,) As Double
  10. End Structure
  11.  
  12. ....a bunch of private variables declared as dynamic arrays at class level,
  13. then a "New" subroutine that appropriately dimensions all these arrays.
  14. Perhaps most relevant is the call within the New subroutine to the below
  15. routine which populates a cache matrices which hopefully will make the
  16. interpolate function down below run more quickly. The concept in all this is
  17. that interpolate is called lots of times and needs to be as fast as possible.
  18.  
  19. Private Sub BasisCacher()
  20.  
  21. ReDim BasisCache(2, _Dimensions - 1, 1)
  22. For k = 0 To 2
  23. For d = 0 To _Dimensions - 1
  24. ReDim BasisCache(k, d, 0)(_NumberOfKnots(d))
  25. ReDim BasisCache(k, d, 1)(_NumberOfKnots(d))
  26. For LIminus3 = 0 To _NumberOfKnots(d)
  27. BasisCache(k, d, 0)(LIminus3) = New DenseMatrix(k + 1, k + 2)
  28. BasisCache(k, d, 1)(LIminus3) = New DenseMatrix(k + 1, k + 2)
  29. For j = 0 To k
  30. Index1Holder = LIminus3 + 4 + j
  31. Index2Holder = LIminus3 + 3 + j - k
  32. BasisCache(k, d, 0)(LIminus3)(j, j) =
  33. _KnotVector(d) (Index1Holder) /
  34. (_KnotVector(d)(Index1Holder) -
  35. _KnotVector(d)(Index2Holder))
  36. BasisCache(k, d, 0)(LIminus3)(j, j + 1) =
  37. -_KnotVector(d)(Index2Holder) /
  38. (_KnotVector(d)(Index1Holder) -
  39. _KnotVector(d)(Index2Holder))
  40. BasisCache(k, d, 1)(LIminus3)(j, j) = -1 /
  41. (_KnotVector(d)(Index1Holder) -
  42. _KnotVector(d)(Index2Holder))
  43. BasisCache(k, d, 1)(LIminus3)(j, j + 1) = 1 /
  44. (_KnotVector(d)(Index1Holder) -
  45. _KnotVector(d)(Index2Holder))
  46. Next j
  47. Next LIminus3
  48. Next d
  49. Next k
  50.  
  51. End Sub
  52.  
  53. Function Interpolate_NonUniformNonRecurringKnots(x() As Double) As
  54. SplineInterpResult
  55.  
  56. 'Build Basis Functions with cached values
  57. For d = 0 To _Dimensions - 1
  58. LowerIndex(d) = Array.BinarySearch(_KnotVectorStorage(d), x(d))
  59. If LowerIndex(d) < 0 Then LowerIndex(d) = -LowerIndex(d) - 2
  60. For k = 0 To 2 'degree=k+1
  61. BasisHolder(k) = BasisCache(k, d, 0)
  62. (LowerIndex(d)).Add(BasisCache(k, d, 1)
  63. (LowerIndex(d)).Multiply(x(d)))
  64. Next k
  65. BasisHolderAllDims(d) = (BasisHolder(0) * BasisHolder(1) *
  66. BasisHolder(2)).Row(0)
  67. Next d
  68.  
  69. ....stuff that I haven't built yet which will calculate z and dzdx.
  70. The lines above about BasisHolder(k) and BasisHolderAllDims(d) are
  71. exemplary of where the exception occurs.
  72.  
  73. Return MySplineResult
  74.  
  75. End Function
Add Comment
Please, Sign In to add comment