SyFi  0.3
Bubble.cpp
Go to the documentation of this file.
00001 // Copyright (C) 2006-2009 Kent-Andre Mardal and Simula Research Laboratory
00002 //
00003 // This file is part of SyFi.
00004 //
00005 // SyFi is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // SyFi is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with SyFi. If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #include "Bubble.h"
00019 
00020 #include "tools.h"
00021 
00022 using std::cout;
00023 using std::endl;
00024 using std::string;
00025 
00026 namespace SyFi
00027 {
00028 
00029         Bubble::Bubble(): StandardFE()
00030         {
00031                 description = "Bubble";
00032         }
00033 
00034         Bubble::Bubble(Polygon& p, unsigned int order): StandardFE(p, order)
00035         {
00036                 compute_basis_functions();
00037         }
00038 
00039         void Bubble:: compute_basis_functions()
00040         {
00041 
00042                 // remove previously computed basis functions and dofs
00043                 Ns.clear();
00044                 dofs.clear();
00045 
00046                 if ( p == NULL )
00047                 {
00048                         throw(std::logic_error("You need to set a polygon before the basisfunctions can be computed"));
00049                 }
00050 
00051                 if ( p->str().find("ReferenceLine") != string::npos )
00052                 {
00053                         Ns.insert(Ns.end(), x*(1-x));
00054                         description = "Bubble_1D";
00055                 }
00056                 else if ( p->str().find("Triangle") != string::npos )
00057                 {
00058 
00059                         GiNaC::ex b = barycenter_triangle(p->vertex(0), p->vertex(1), p->vertex(2));
00060                         GiNaC::ex N = GiNaC::numeric(1);
00061                         for (unsigned int d=0; d< b.nops(); d++)
00062                         {
00063                                 N = N*b.op(d).rhs();
00064                         }
00065                         Ns.insert(Ns.end(), N);
00066 
00067                         description = "Bubble_2D";
00068 
00069                 }
00070                 else if ( p->str().find("Tetrahedron") != string::npos )
00071                 {
00072                         GiNaC::ex b = barycenter_tetrahedron(p->vertex(0), p->vertex(1),
00073                                 p->vertex(2), p->vertex(3));
00074                         GiNaC::ex N = GiNaC::numeric(1);
00075                         for (unsigned int d=0; d< b.nops(); d++)
00076                         {
00077                                 N = N*b.op(d).rhs();
00078                         }
00079                         Ns.insert(Ns.end(), N);
00080 
00081                         description = "Bubble_3D";
00082                 }
00083 
00084                 // create and insert dof
00085                 GiNaC::lst midpoint = GiNaC::lst();
00086                 for (unsigned int d=0; d< p->vertex(1).nops(); d++)
00087                 {
00088                         midpoint.append(GiNaC::numeric(0));
00089                 }
00090                 for (unsigned int i=1; i<= p->no_vertices(); i++)
00091                 {
00092                         for (unsigned int d=0; d< p->vertex(i-1).nops(); d++)
00093                         {
00094                                 midpoint.let_op(d)  += p->vertex(i-1).op(d);
00095                         }
00096                 }
00097 
00098                 for (unsigned int d=0; d< p->vertex(1).nops(); d++)
00099                 {
00100                         midpoint.let_op(d)  = midpoint.op(d)/p->no_vertices();
00101                 }
00102 
00103                 dofs.insert(dofs.end(), midpoint);
00104         }
00105 
00106 }                                                                // namespace SyFi
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator