#include <tools.h>
Go to the source code of this file.
Classes | |
class | Polygon |
class | Line |
class | ReferenceLine |
class | Triangle |
class | ReferenceTriangle |
class | Tetrahedron |
class | ReferenceTetrahedron |
Enumerations | |
enum | Repr_format { SUBS_PERFORMED = 1, SUBS_NOT_PERFORMED = 2 } |
Functions | |
GiNaC::ex | barycenter_line (GiNaC::ex p0, GiNaC::ex p1) |
GiNaC::ex | barycenter_triangle (GiNaC::ex p0, GiNaC::ex p1, GiNaC::ex p2) |
GiNaC::ex | barycenter_tetrahedron (GiNaC::ex p0, GiNaC::ex p1, GiNaC::ex p2, GiNaC::ex p3) |
GiNaC::lst | bezier_ordinates (Triangle &triangle, int d) |
GiNaC::lst | bezier_ordinates (Tetrahedron &tetrahedra, int d) |
GiNaC::ex | bernstein (int order, Polygon &p, const string a) |
GiNaC::lst | bernsteinv (int order, Polygon &p, const string a) |
GiNaC::lst | normal (Triangle &, int i) |
GiNaC::lst | normal (Tetrahedron &, int i) |
|
Definition at line 15 of file Polygon.h. 00015 { 00016 SUBS_PERFORMED = 1, 00017 SUBS_NOT_PERFORMED = 2 00018 };
|
|
Definition at line 665 of file Polygon.cpp. References DUMMY, x, y, and z. Referenced by bernstein(). 00665 { 00666 GiNaC::ex sol = DUMMY; 00667 00668 // 1D 00669 if ( p0.nops() == 1 && p1.nops() == 1 ) { 00670 GiNaC::symbol b0("b0"), b1("b1"); 00671 GiNaC::ex eq1 = x == b0*p0.op(0) + b1*p1.op(0); 00672 GiNaC::ex eq2 = 1 == b0 + b1; 00673 sol = lsolve(GiNaC::lst(eq1, eq2), GiNaC::lst(b0, b1)); 00674 } 00675 //2D 00676 else if ( p0.nops() == 2 && p1.nops() == 2 ) { 00677 GiNaC::symbol b0("b0"), b1("b1"); 00678 GiNaC::ex eq1 = x == b0*p0.op(0) + b1*p1.op(0); 00679 GiNaC::ex eq3 = 1 == b0 + b1; 00680 sol = lsolve(GiNaC::lst(eq1, eq3), GiNaC::lst(b0, b1)); 00681 if (sol.nops() == 0) { 00682 GiNaC::ex eq2 = y == b0*p0.op(1) + b1*p1.op(1); 00683 sol = lsolve(GiNaC::lst(eq2, eq3), GiNaC::lst(b0, b1)); 00684 } 00685 } 00686 //3D 00687 else if ( p0.nops() == 3 && p1.nops() == 3 ) { 00688 GiNaC::symbol b0("b0"), b1("b1"); 00689 GiNaC::ex eq1 = x == b0*p0.op(0) + b1*p1.op(0); 00690 GiNaC::ex eq4 = 1 == b0 + b1; 00691 sol = lsolve(GiNaC::lst(eq1, eq4), GiNaC::lst(b0, b1)); 00692 if (sol.nops() == 0) { 00693 GiNaC::ex eq2 = y == b0*p0.op(1) + b1*p1.op(1); 00694 sol = lsolve(GiNaC::lst(eq2, eq4), GiNaC::lst(b0, b1)); 00695 } 00696 if (sol.nops() == 0) { 00697 GiNaC::ex eq3 = z == b0*p0.op(2) + b1*p1.op(2); 00698 sol = lsolve(GiNaC::lst(eq3, eq4), GiNaC::lst(b0, b1)); 00699 } 00700 } 00701 else { 00702 cout <<"Could not compute the barycentric coordinates."<<endl; 00703 cout <<"Check the coordinates."<<endl; 00704 } 00705 return sol; 00706 }
|
|
Definition at line 745 of file Polygon.cpp. Referenced by bernstein(). 00745 { 00746 GiNaC::symbol b0("b0"), b1("b1"), b2("b2"), b3("b3"); 00747 00748 // 3D 00749 GiNaC::ex eq1 = x == b0*p0.op(0) + b1*p1.op(0) + b2*p2.op(0) + b3*p3.op(0); 00750 GiNaC::ex eq2 = y == b0*p0.op(1) + b1*p1.op(1) + b2*p2.op(1) + b3*p3.op(1); 00751 GiNaC::ex eq3 = z == b0*p0.op(2) + b1*p1.op(2) + b2*p2.op(2) + b3*p3.op(2); 00752 GiNaC::ex eq4 = 1 == b0 + b1 + b2 +b3; 00753 00754 GiNaC::ex sol = lsolve(GiNaC::lst(eq1, eq2, eq3, eq4), GiNaC::lst(b0, b1, b2, b3)); 00755 00756 return sol; 00757 00758 }
|
|
Definition at line 710 of file Polygon.cpp. References DUMMY, x, y, and z. Referenced by bernstein(). 00710 { 00711 GiNaC::ex sol; 00712 sol = DUMMY; 00713 00714 // 2D 00715 if ( p0.nops() == 2 && p1.nops() == 2 && p2.nops() == 2) { 00716 GiNaC::symbol b0("b0"), b1("b1"), b2("b2"); 00717 GiNaC::ex eq1 = x == b0*p0.op(0) + b1*p1.op(0) + b2*p2.op(0); 00718 GiNaC::ex eq2 = y == b0*p0.op(1) + b1*p1.op(1) + b2*p2.op(1); 00719 GiNaC::ex eq3 = 1 == b0 + b1 + b2; 00720 00721 sol = lsolve(GiNaC::lst(eq1, eq2, eq3), GiNaC::lst(b0, b1, b2)); 00722 } 00723 // 3D 00724 else if ( p0.nops() == 3 && p1.nops() == 3 && p2.nops() == 3) { 00725 GiNaC::symbol b0("b0"), b1("b1"), b2("b2"); 00726 GiNaC::ex eq1 = x == b0*p0.op(0) + b1*p1.op(0) + b2*p2.op(0); 00727 GiNaC::ex eq2 = y == b0*p0.op(1) + b1*p1.op(1) + b2*p2.op(1); 00728 GiNaC::ex eq3 = z == b0*p0.op(2) + b1*p1.op(2) + b2*p2.op(2); 00729 GiNaC::ex eq4 = 1 == b0 + b1 + b2; 00730 00731 sol = lsolve(GiNaC::lst(eq1, eq2, eq4), GiNaC::lst(b0, b1, b2)); 00732 if ( sol.nops() == 0 ) { 00733 sol = lsolve(GiNaC::lst(eq1, eq3, eq4), GiNaC::lst(b0, b1, b2)); 00734 } 00735 if ( sol.nops() == 0 ) { 00736 sol = lsolve(GiNaC::lst(eq2, eq3, eq4), GiNaC::lst(b0, b1, b2)); 00737 } 00738 } 00739 00740 00741 00742 return sol; 00743 }
|
|
Definition at line 760 of file Polygon.cpp. References barycenter_line(), barycenter_tetrahedron(), barycenter_triangle(), matrix_to_lst2(), Polygon::str(), and Polygon::vertex(). Referenced by bernsteinv(), CrouzeixRaviart::compute_basis_functions(), RaviartThomas::compute_basis_functions(), and main(). 00760 { 00761 GiNaC::ex ret; // GiNaC::ex to return 00762 int dof; // degrees of freedom 00763 GiNaC::ex A; // GiNaC::ex holding the coefficients a_0 .. a_dof 00764 GiNaC::lst basis; 00765 00766 if ( p.str() == "Line" || p.str() == "ReferenceLine" ) { 00767 GiNaC::ex bary = barycenter_line(p.vertex(0), p.vertex(1)); 00768 GiNaC::ex b0= bary.op(0).rhs(); 00769 GiNaC::ex b1= bary.op(1).rhs(); 00770 dof = order+1; 00771 A = GiNaC::symbolic_matrix(1,dof, a); 00772 int o=0; 00773 for (GiNaC::const_iterator i = A.begin(); i != A.end(); ++i) { 00774 ret += (*i)*GiNaC::binomial(order,o)*pow(b0,o)*pow(b1,order-o); 00775 basis.append(pow(b0,o)*pow(b1,order-o)); 00776 o++; 00777 } 00778 } 00779 else if ( p.str() == "Triangle" || p.str() == "ReferenceTriangle" ) { 00780 00781 dof = (order+1)*(order+2)/2; 00782 A = GiNaC::symbolic_matrix(1, dof , a); 00783 00784 GiNaC::ex bary = barycenter_triangle(p.vertex(0), p.vertex(1), p.vertex(2)); 00785 GiNaC::ex b0= bary.op(0).rhs(); 00786 GiNaC::ex b1= bary.op(1).rhs(); 00787 GiNaC::ex b2= bary.op(2).rhs(); 00788 00789 size_t i=0; 00790 for (int o1 = 0; o1 <= order; o1++) { 00791 for (int o2 = 0; o2 <= order; o2++) { 00792 for (int o3 = 0; o3 <= order; o3++) { 00793 if ( o1 + o2 + o3 == order ) { 00794 ret += A.op(i)*(GiNaC::factorial(order)/(GiNaC::factorial(o1)*GiNaC::factorial(o2)*GiNaC::factorial(o3))) 00795 *pow(b0,o1)*pow(b1,o2)*pow(b2,o3); 00796 00797 basis.append(pow(b0,o1)*pow(b1,o2)*pow(b2,o3)); 00798 i++; 00799 } 00800 } 00801 } 00802 } 00803 } 00804 else if (p.str() == "Tetrahedron" || p.str() == "ReferenceTetrahedron") { 00805 00806 00807 dof = 0; 00808 for (int j=0; j<= order; j++) { 00809 dof += (j+1)*(j+2)/2; 00810 } 00811 A = GiNaC::symbolic_matrix(1, dof , a); 00812 00813 00814 GiNaC::ex bary = barycenter_tetrahedron(p.vertex(0), p.vertex(1), p.vertex(2), p.vertex(3)); 00815 GiNaC::ex b0= bary.op(0).rhs(); 00816 GiNaC::ex b1= bary.op(1).rhs(); 00817 GiNaC::ex b2= bary.op(2).rhs(); 00818 GiNaC::ex b3= bary.op(3).rhs(); 00819 00820 00821 size_t i=0; 00822 for (int o1 = 0; o1 <= order; o1++) { 00823 for (int o2 = 0; o2 <= order; o2++) { 00824 for (int o3 = 0; o3 <= order; o3++) { 00825 for (int o4 = 0; o4 <= order; o4++) { 00826 if ( o1 + o2 + o3 + o4 == order ) { 00827 ret += A.op(i)*(GiNaC::factorial(order)/(GiNaC::factorial(o1)*GiNaC::factorial(o2)*GiNaC::factorial(o3)*GiNaC::factorial(o4))) 00828 *pow(b0,o1)*pow(b1,o2)*pow(b2,o3)*pow(b3,o4); 00829 basis.append(pow(b0,o1)*pow(b1,o2)*pow(b2,o3)*pow(b3,o4)); 00830 i++; 00831 } 00832 } 00833 } 00834 } 00835 } 00836 } 00837 return GiNaC::lst(ret,matrix_to_lst2(A),basis); 00838 }
|
|
Definition at line 840 of file Polygon.cpp. References bernstein(), nsd, pol(), and Polygon::str(). Referenced by RaviartThomas::compute_basis_functions(). 00840 { 00841 GiNaC::lst ret1; // contains the polynom 00842 GiNaC::lst ret2; // contains the coefficients 00843 GiNaC::lst ret3; // constains the basis functions 00844 GiNaC::lst basis_tmp; 00845 for (int i=1; i<= nsd; i++) { 00846 GiNaC::lst basis; 00847 std::ostringstream s; 00848 s <<a<<""<<i<<"_"; 00849 GiNaC::ex pol = bernstein(order, p, s.str()); 00850 ret1.append(pol.op(0)); 00851 ret2.append(pol.op(1)); 00852 basis_tmp = GiNaC::ex_to<GiNaC::lst>(pol.op(2)); 00853 for (GiNaC::lst::const_iterator basis_iterator = basis_tmp.begin(); 00854 basis_iterator != basis_tmp.end(); ++basis_iterator) { 00855 GiNaC::lst tmp_lst; 00856 for (int d=1; d<=nsd; d++) tmp_lst.append(0); 00857 tmp_lst.let_op(i-1) = (*basis_iterator); 00858 ret3.append(tmp_lst); 00859 } 00860 } 00861 return GiNaC::lst(ret1,ret2,ret3); 00862 00863 }
|
|
Definition at line 592 of file Polygon.cpp. References lst_to_matrix2(), matrix_to_lst2(), and Tetrahedron::vertex(). 00592 { 00593 00594 //FIXME: ugly conversion to matrix 00595 00596 GiNaC::lst ret; 00597 GiNaC::ex V1 = tetrahedra.vertex(0); 00598 GiNaC::ex V2 = tetrahedra.vertex(1); 00599 GiNaC::ex V3 = tetrahedra.vertex(2); 00600 GiNaC::ex V4 = tetrahedra.vertex(3); 00601 00602 GiNaC::lst V1l = GiNaC::ex_to<GiNaC::lst>(V1); 00603 GiNaC::lst V2l = GiNaC::ex_to<GiNaC::lst>(V2); 00604 GiNaC::lst V3l = GiNaC::ex_to<GiNaC::lst>(V3); 00605 GiNaC::lst V4l = GiNaC::ex_to<GiNaC::lst>(V4); 00606 00607 00608 GiNaC::ex V1m = lst_to_matrix2(V1l); 00609 GiNaC::ex V2m = lst_to_matrix2(V2l); 00610 GiNaC::ex V3m = lst_to_matrix2(V3l); 00611 GiNaC::ex V4m = lst_to_matrix2(V4l); 00612 00613 int l; 00614 for (int i=0; i<= d; i++) { 00615 for (int j=0; j<= d; j++) { 00616 for (int k=0; k<= d; k++) { 00617 if ( d - i - j -k >= 0 ) { 00618 l= d - i - j -k; 00619 GiNaC::ex sum = (i*V1m + j*V2m + k*V3m + l*V4m)/d; 00620 ret.append(matrix_to_lst2(sum.evalm())); 00621 } 00622 } 00623 } 00624 } 00625 // FIXME how should these be sorted ????? 00626 // ret = ret.sort(); 00627 return ret; 00628 }
|
|
Definition at line 632 of file Polygon.cpp. References lst_to_matrix2(), matrix_to_lst2(), and Triangle::vertex(). 00632 { 00633 00634 //FIXME: ugly conversion to matrix 00635 00636 GiNaC::lst ret; 00637 GiNaC::ex V1 = triangle.vertex(0); 00638 GiNaC::ex V2 = triangle.vertex(1); 00639 GiNaC::ex V3 = triangle.vertex(2); 00640 00641 GiNaC::lst V1l = GiNaC::ex_to<GiNaC::lst>(V1); 00642 GiNaC::lst V2l = GiNaC::ex_to<GiNaC::lst>(V2); 00643 GiNaC::lst V3l = GiNaC::ex_to<GiNaC::lst>(V3); 00644 00645 GiNaC::ex V1m = lst_to_matrix2(V1l); 00646 GiNaC::ex V2m = lst_to_matrix2(V2l); 00647 GiNaC::ex V3m = lst_to_matrix2(V3l); 00648 00649 int k; 00650 for (int i=0; i<= d; i++) { 00651 for (int j=0; j<= d-i; j++) { 00652 k= d - i - j; 00653 GiNaC::ex sum = (i*V1m + j*V2m + k*V3m)/d; 00654 ret.append(matrix_to_lst2(sum.evalm())); 00655 } 00656 } 00657 // FIXME how should these be sorted ????? 00658 // ret = ret.sort(); 00659 return ret; 00660 }
|
|
Definition at line 865 of file Polygon.cpp. References cross(), Triangle::line(), Line::repr(), and Tetrahedron::triangle(). 00865 { 00866 Triangle triangle = tetrahedron.triangle(i); 00867 00868 GiNaC::symbol t("t"); 00869 GiNaC::ex line1_repr = triangle.line(1).repr(t); 00870 GiNaC::ex n11 = line1_repr.op(0).rhs().coeff(t,1); 00871 GiNaC::ex n12 = line1_repr.op(1).rhs().coeff(t,1); 00872 GiNaC::ex n13 = line1_repr.op(2).rhs().coeff(t,1); 00873 00874 GiNaC::ex line2_repr = triangle.line(2).repr(t); 00875 GiNaC::ex n21 = line2_repr.op(0).rhs().coeff(t,1); 00876 GiNaC::ex n22 = line2_repr.op(1).rhs().coeff(t,1); 00877 GiNaC::ex n23 = line2_repr.op(2).rhs().coeff(t,1); 00878 00879 GiNaC::lst n1 = GiNaC::lst(n11,n12,n13); 00880 GiNaC::lst n2 = GiNaC::lst(n21,n22,n23); 00881 GiNaC::lst n3 = cross(n1,n2); 00882 00883 return n3; 00884 }
|
|
Definition at line 887 of file Polygon.cpp. References Triangle::line(), normal(), and Line::repr(). 00887 { 00888 Line line = triangle.line(i); 00889 //FIXME: 5 lines to compute the normal vector, these should 00890 // be put somewhere else. 00891 GiNaC::symbol t("t"); 00892 GiNaC::ex line_repr = line.repr(t); 00893 GiNaC::ex n1 = line_repr.op(0).rhs().coeff(t,1); 00894 GiNaC::ex n2 = line_repr.op(1).rhs().coeff(t,1); 00895 GiNaC::lst normal = GiNaC::lst(n2,-n1); 00896 return normal; 00897 }
|