CrouzeixRaviart.cpp

Go to the documentation of this file.
00001 #include <CrouzeixRaviart.h> 
00002 
00003 
00004 CrouzeixRaviart:: CrouzeixRaviart() : StandardFE() {
00005   order = 1; 
00006 }
00007 
00008 
00009 int CrouzeixRaviart:: nbf() {
00010   return Ns.size();  
00011 }
00012 
00013 void CrouzeixRaviart:: compute_basis_functions() {
00014 
00015   // see e.g. Brezzi and Fortin book page 116 for the definition
00016   
00017   if (p->str() == "ReferenceLine") { 
00018     cout <<"Can not define the Raviart-Thomas element on a line"<<endl;  
00019   } else if (p->str() == "ReferenceTriangle" || p->str() == "Triangle"  ) { 
00020     Triangle& triangle = (Triangle&)(*p); 
00021 
00022     // create the polynomial space
00023     GiNaC::ex polynom_space = bernstein(1, triangle, "a"); 
00024     GiNaC::ex polynom = polynom_space.op(0); 
00025     GiNaC::ex variables = polynom_space.op(1); 
00026     GiNaC::ex basis = polynom_space.op(2); 
00027 
00028     // create the dofs
00029     int counter = 0; 
00030     GiNaC::symbol t("t"); 
00031     for (int i=1; i<= 3; i++) {
00032       Line line = triangle.line(i); 
00033       GiNaC::ex dofi = line.integrate(polynom); 
00034       dofs.insert(dofs.end(),dofi); 
00035     }
00036 
00037     // solve the linear system to compute 
00038     // each of the basis functions
00039     for (int i=1; i<= 3; i++) {
00040       GiNaC::lst equations; 
00041       for (int j=1; j<= 3; j++) {
00042         equations.append(dofs[j-1] == dirac(i,j));
00043       }
00044       GiNaC::ex sub = lsolve(equations, variables); 
00045       GiNaC::ex Ni = polynom.subs(sub); 
00046       Ns.insert(Ns.end(),Ni); 
00047     }
00048 
00049   } else if ( p->str() == "ReferenceTetrahedron" ||  p->str() == "Tetrahedron" ) { 
00050     Tetrahedron& tetrahedron = (Tetrahedron&)(*p); 
00051     GiNaC::ex polynom_space = bernstein(1, tetrahedron, "a"); 
00052     GiNaC::ex polynom = polynom_space.op(0); 
00053     GiNaC::ex variables = polynom_space.op(1); 
00054     GiNaC::ex basis = polynom_space.op(2); 
00055 
00056 
00057     GiNaC::ex bernstein_pol; 
00058 
00059     int counter = 0; 
00060     GiNaC::symbol t("t"); 
00061     // dofs related to edges  
00062     for (int i=1; i<= 4; i++) {
00063       Triangle triangle = tetrahedron.triangle(i); 
00064       GiNaC::ex dofi = triangle.integrate(polynom); 
00065       dofs.insert(dofs.end(),dofi); 
00066     }
00067     for (int i=1; i<= 4; i++) {
00068       GiNaC::lst equations; 
00069       for (int j=1; j<= 4; j++) {
00070         equations.append(dofs[j-1] == dirac(i,j));
00071       }
00072       GiNaC::ex sub = lsolve(equations, variables); 
00073       GiNaC::ex Ni = polynom.subs(sub); 
00074       Ns.insert(Ns.end(),Ni); 
00075     }
00076 
00077 
00078 
00079   }
00080 }
00081 
00082 
00083 void CrouzeixRaviart:: set(Polygon& p_) {
00084   StandardFE:: set(p_); 
00085 }
00086 
00087 
00088 void CrouzeixRaviart:: set(int order_) { 
00089   if (order_ != 1) {
00090     cout <<"Only Crouziex-Raviart elements of order 1 is possible"<<endl;  
00091   }
00092 }
00093 
00094 
00095 GiNaC::ex CrouzeixRaviart:: dof(int i) {
00096   return StandardFE::dof(i);  
00097 }
00098 
00099 
00100 GiNaC::ex CrouzeixRaviart::N(int i) {  
00101   return StandardFE::N(i); 
00102 }
00103 
00104 
00105 
00106 // ------------VectorCrouzeixRaviart --- 
00107 
00108 
00109 VectorCrouzeixRaviart:: VectorCrouzeixRaviart() : StandardFE() {
00110   order = 1; 
00111 }
00112 
00113 int VectorCrouzeixRaviart:: nbf() {
00114   return StandardFE::nbf();       
00115 }
00116 
00117 void VectorCrouzeixRaviart:: compute_basis_functions() {
00118   CrouzeixRaviart fe; 
00119   fe.set(*p); 
00120   fe.compute_basis_functions(); 
00121   GiNaC::lst zero_list; 
00122   for (int s=1; s<= size ; s++) {
00123     zero_list.append(0);  
00124   }
00125 
00126   for (int i=1; i<= fe.nbf() ; i++) {
00127     for (int s=1; s<= size ; s++) {
00128       GiNaC::lst Nis = zero_list;    
00129       Nis.let_op(s-1) = fe.N(i); 
00130       GiNaC::ex Nmat = GiNaC::matrix(size,1,Nis); 
00131       Ns.insert(Ns.end(), Nmat);  
00132 
00133       GiNaC::lst dof = GiNaC::lst(fe.dof(i), s) ; 
00134       dofs.insert(dofs.end(), dof);  
00135     }
00136   }
00137 }
00138 
00139 
00140 void VectorCrouzeixRaviart:: set_size(int size_) {
00141   size = size_; 
00142 }
00143 
00144 
00145 void VectorCrouzeixRaviart:: set(Polygon& p_) {
00146   StandardFE::set(p_); 
00147 }
00148 
00149 
00150 
00151 void VectorCrouzeixRaviart:: set(int order_) { 
00152   if (order_ != 1) {
00153     cout <<"Only Crouziex-Raviart elements of order 1 is possible"<<endl;  
00154   }
00155 }
00156 
00157 
00158 
00159 
00160 GiNaC::ex VectorCrouzeixRaviart:: dof(int i) {
00161   return StandardFE::dof(i);  
00162 }
00163 
00164 
00165 GiNaC::ex VectorCrouzeixRaviart::N(int i) {  
00166   return StandardFE::N(i); 
00167 }
00168 
00169 
00170 
00171 
00172 
00173 
00174 

Generated on Mon Jan 9 18:08:08 2006 for SyFi by  doxygen 1.4.4