6 class ReferenceSimplex
:
7 def __init__(self
, nsd
):
11 coords
= symbols('xyz')[:nsd
]
14 for d
in range(0,nsd
):
15 coords
.append(Symbol("x_%d" % d
))
18 def integrate(self
,f
):
27 for d
in range(0,nsd
):
30 intf
= integrate(intf
, (p
, 0, limit
))
33 def bernstein_space(order
, nsd
):
35 raise RuntimeError("Bernstein only implemented in 1D, 2D, and 3D")
42 for o1
in range(0,order
+1):
43 for o2
in range(0,order
+1):
45 aij
= Symbol("a_%d_%d" % (o1
,o2
))
46 sum += aij
*binomial(order
,o1
)*pow(b1
, o1
)*pow(b2
,
48 basis
.append(binomial(order
,o1
)*pow(b1
,
54 b1
, b2
, b3
= x
, y
, 1-x
-y
55 for o1
in range(0,order
+1):
56 for o2
in range(0,order
+1):
57 for o3
in range(0,order
+1):
58 if o1
+ o2
+ o3
== order
:
59 aij
= Symbol("a_%d_%d_%d" % (o1
,o2
,o3
))
60 fac
= factorial(order
)/ (factorial(o1
)*factorial(o2
)*factorial(o3
))
61 sum += aij
*fac
*pow(b1
, o1
)*pow(b2
, o2
)*pow(b3
,
63 basis
.append(fac
*pow(b1
, o1
)*pow(b2
,
68 b1
, b2
, b3
, b4
= x
, y
, z
, 1-x
-y
-z
69 for o1
in range(0,order
+1):
70 for o2
in range(0,order
+1):
71 for o3
in range(0,order
+1):
72 for o4
in range(0,order
+1):
73 if o1
+ o2
+ o3
+ o4
== order
:
74 aij
= Symbol("a_%d_%d_%d_%d" %
76 fac
= factorial(order
)/ (factorial(o1
)*factorial(o2
)*factorial(o3
)*factorial(o4
))
77 sum += aij
*fac
*pow(b1
, o1
)*pow(b2
, o2
)*pow(b3
, o3
)*pow(b4
, o4
)
78 basis
.append(fac
*pow(b1
, o1
)*pow(b2
,
79 o2
)*pow(b3
, o3
)*pow(b4
, o4
))
83 return sum, coeff
, basis
85 def create_point_set(order
, nsd
):
90 for i
in range(0, order
+1):
96 for i
in range(0, order
+1):
98 for j
in range(0, order
+1):
104 for i
in range(0, order
+1):
106 for j
in range(0, order
+1):
108 for k
in range(0, order
+1):
117 def create_matrix(equations
, coeffs
):
118 A
= zeronm(len(equations
), len(equations
))
120 for j
in range(0, len(coeffs
)):
122 for i
in range(0, len(equations
)):
131 def __init__(self
,nsd
, order
):
139 def compute_basis(self
):
143 pol
, coeffs
, basis
= bernstein_space(order
, nsd
)
144 points
= create_point_set(order
, nsd
)
148 ex
= pol
.subs(x
, p
[0])
150 ex
= ex
.subs(y
, p
[1])
152 ex
= ex
.subs(z
, p
[2])
153 equations
.append(ex
)
155 A
= create_matrix(equations
, coeffs
)
158 b
= eye(len(equations
))
162 for i
in range(0,len(equations
)):
164 for j
in range(0,len(coeffs
)):
165 Ni
= Ni
.subs(coeffs
[j
], xx
[j
,i
])