1 from __future__
import print_function
9 sxx,syy,szz,syz,sxz,sxy=symbols(
"sxx,syy,szz,syz,sxz,sxy")
10 S=Matrix([[sxx],[syy],[szz],[syz],[sxz],[sxy]])
12 x,y,z=symbols(
'x,y,z')
14 P=Matrix([[x**2, y**2, z**2, y*z, x*z, x*y]])
17 b = P.transpose()*Matrix([[1]])
20 sphere = {x:1, y:1, z:1,
21 sxx:Rational(1,3),syy:Rational(1, 3),szz:Rational(1, 3),syz:0,sxz:0,sxy:0}
23 if (A*S).evalf(subs=sphere)==b.evalf(subs=sphere):
31 pyname=sys.argv[0].split(
'/')[-1]
34 cxxname=pyname[:-3]+
".cpp"
37 /* Start of code generated by %s. Warning - be careful about modifying
38 any of the generated code directly. Any changes/fixes should be done
39 in the code generation script generation.
44 void fit_ellipsoid(int i, real_t *sm){
45 Eigen::Matrix<double, 6, 6> A = Eigen::Matrix<real_t, 6, 6>::Zero(6,6);
46 Eigen::Matrix<double, 6, 1> b = Eigen::Matrix<real_t, 6, 1>::Zero(6);
48 std::vector<index_t> nodes = _mesh->NNList[i];
51 for(typename std::vector<index_t>::const_iterator it=nodes.begin();it!=nodes.end();++it){
52 const real_t *X0=_mesh->get_coords(*it);
53 real_t x0=X0[0], y0=X0[1], z0=X0[2];
54 assert(std::isfinite(x0));
55 assert(std::isfinite(y0));
56 assert(std::isfinite(z0));
58 for(typename std::vector<index_t>::const_iterator n=_mesh->NNList[*it].begin();n!=_mesh->NNList[*it].end();++n){
62 const real_t *X=_mesh->get_coords(*n);
63 real_t x=X[0]-x0, y=X[1]-y0, z=X[2]-z0;
65 assert(std::isfinite(x));
66 assert(std::isfinite(y));
67 assert(std::isfinite(z));
78 src+=
"A[%d]+="%(i*6+j)+ccode(A[i,j], contract=
False)+
"; "
82 src+=
"b[%d]+="%(i)+ccode(b[i], contract=
False)+
";\n"
88 Eigen::Matrix<double, 6, 1> S = Eigen::Matrix<real_t, 6, 1>::Zero(6);
92 if(_mesh->NNList[i].size()>=6){
93 sm[0] = S[0]; sm[1] = S[5]; sm[2] = S[4];
94 sm[3] = S[1]; sm[4] = S[3];
97 sm[0] = S[0]; sm[1] = 0; sm[2] = 0;
98 sm[3] = S[1]; sm[4] = 0;
105 /* End of code generated by %s. Warning - be careful about
106 modifying any of the generated code directly. Any changes/fixes
107 should be done in the code generation script generation.*/\n"""%pyname
109 cxxfile = open(cxxname,
"w")