12 from pylab
import hold, show, axis
13 from pylab
import plot
as pyplot
14 from numpy
import array, linspace, linalg, diag, cross
15 from numpy
import cos
as pycos
16 from numpy
import sin
as pysin
17 from numpy
import sqrt
as pysqrt
18 from numpy
import abs
as pyabs
19 from adaptivity
import metric_pnorm, mesh_metric, adapt, mesh_metric2
20 set_log_level(WARNING)
23 mesh = RectangleMesh(0,0,1,1,20,20)
24 mesh =
adapt(interpolate(Constant(((10.,0.),(0.,10.))),TensorFunctionSpace(mesh,
'CG',1)))
28 i = 20; t = linspace(0,2*pi,101)
29 ind = MpH.function_space().dofmap().cell_dofs(i)
30 thecell = mesh.cells()[i]
31 centerxy = mesh.coordinates()[thecell,:].mean(0).repeat(3).reshape([2,3]).T
32 cxy = mesh.coordinates()[thecell,:]-centerxy
33 pyplot(cxy[:,0],cxy[:,1],
'-b')
34 H = MpH.vector().gather(ind).reshape(2,2);
37 [v,w] = linalg.eig(H); v /= pysqrt(3)
38 elxy = array([pycos(t),pysin(t)]).T.dot(w).dot(diag(v)).dot(w.T)
39 hold(
'on'); pyplot(elxy[:,0],elxy[:,1],
'-r'); hold(
'off'); axis(
'equal')
40 print(
'triangle area: %0.6f, ellipse axis product(*3*sqrt(3)/4): %0.6f' % (pyabs(linalg.det(array([cxy[1,:]-cxy[0,:],cxy[2,:]-cxy[0,:]])))/2,v[0]*v[1]*3*sqrt(3)/4))
44 mesh = BoxMesh(0,0,0,1,1,1,20,20,20)
45 mesh =
adapt(interpolate(Constant(((100.,0.,0.),(0.,100.,0.),(0.,0.,100.))),TensorFunctionSpace(mesh,
'CG',1)))
50 thecell = mesh.cells()[i]
51 ind = MpH.function_space().dofmap().cell_dofs(i)
52 coords = mesh.coordinates()[thecell,:]
53 r1 = coords[1,:]-coords[0,:]
54 r2 = coords[2,:]-coords[0,:]
55 r3 = coords[0:3,:].mean(0)-coords[3,:]
56 r12c = cross(r2,r1)/6.
57 det1234 = pyabs((r12c*r3).sum())
59 H = MpH.vector().gather(ind).reshape(3,3)
61 print(
'tetrahedron volume: %0.6f, ellipsoid axis product(*sqrt(2)/12): %0.6f' % (det1234,v.prod()*sqrt(2)/12))
62 print v.prod()*sqrt(2)/12/(det1234)
64 if __name__==
"__main__":