Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Search for

# code_gen.cpp File Reference

`#include <SyFi.h>`
`#include <fstream>`

Go to the source code of this file.

## Functions
void | compute_Poisson_element_matrix (FE &fe, Dof &dof, std::map< std::pair< int, int >, GiNaC::ex > &A)
void | code_gen2D (FE &fe)
int | main ()

## Function Documentation

void code_gen2D | ( | FE & | fe | ) |

| Definition at line 33 of file code_gen.cpp. References FE::N(), FE::nbf(), x, and y. Referenced by main().
    00033                        {
    00034   cout <<csrc;
    00035   for (int i=0; i< fe.nbf(); i++) {
    00036     cout <<"double N"<<i<<"(double x, double y){"<<endl;
    00037     cout <<"  return "<<fe.N(i)<<";"<<endl;
    00038     cout <<"}"<<endl;
    00039   }
    00040
    00041   for (int i=0; i< fe.nbf(); i++) {
    00042     cout <<"double dN"<<i<<"dx(double x, double y){"<<endl;
    00043     cout <<"  return "<<diff(fe.N(i),x)<<";"<<endl;
    00044     cout <<"}"<<endl;
    00045   }
    00046
    00047   for (int i=0; i< fe.nbf(); i++) {
    00048     cout <<"double dN"<<i<<"dy(double x, double y){"<<endl;
    00049     cout <<"  return "<<diff(fe.N(i),y)<<";"<<endl;
    00050     cout <<"}"<<endl;
    00051   }
    00052
    00053   cout <<"double N(int i, double x, double y){"<<endl;
    00054   cout <<"  switch(i) {"<<endl;
    00055   for (int i=0; i< fe.nbf(); i++) {
    00056     cout <<"    case "<<i<<" :  return N"<<i<<"(x,y);"<<endl;
    00057   }
    00058   cout <<"  }"<<endl;
    00059   cout <<"}"<<endl;
    00060
    00061   cout <<"double dNdx(int i, double x, double y){"<<endl;
    00062   cout <<"  switch(i) {"<<endl;
    00063   for (int i=0; i< fe.nbf(); i++) {
    00064     cout <<"    case "<<i<<" :  return dN"<<i<<"dx(x,y);"<<endl;
    00065   }
    00066   cout <<"  }"<<endl;
    00067   cout <<"}"<<endl;
    00068
    00069   cout <<"double dNdy(int i, double x, double y){"<<endl;
    00070   cout <<"  switch(i) {"<<endl;
    00071   for (int i=0; i< fe.nbf(); i++) {
    00072     cout <<"    case "<<i<<" :  return dN"<<i<<"dy(x,y);"<<endl;
    00073   }
    00074   cout <<"  }"<<endl;
    00075   cout <<"}"<<endl;
    00076 }

void compute_Poisson_element_matrix | ( | FE & | fe,
|  | Dof & | dof,
|  | std::map< std::pair< int, int >, GiNaC::ex > & | A
| ) |

| Definition at line 7 of file code_gen.cpp. References FE::dof(), FE::getPolygon(), Dof::glob_dof(), grad(), inner(), Dof::insert_dof(), Polygon::integrate(), FE::N(), and FE::nbf().
    00011 {
    00012   std::pair<int,int> index;
    00013
    00014    // Insert the local degrees of freedom into the global Dof
    00015   for (int i=0; i< fe.nbf(); i++) {
    00016     dof.insert_dof(1,i,fe.dof(i));
    00017   }
    00018
    00019   Polygon& domain = fe.getPolygon();
    00020
    00021   // The term (grad u, grad v)
    00022   for (int i=0; i< fe.nbf(); i++) {
    00023     index.first = dof.glob_dof(fe.dof(i));               // fetch the global dof for Ni
    00024     for (int j=0; j< fe.nbf(); j++) {
    00025       index.second = dof.glob_dof(fe.dof(j));            // fetch the global dof for Nj
    00026       GiNaC::ex nabla = inner(grad(fe.N(i)),grad(fe.N(j)));
    00027       GiNaC::ex Aij = domain.integrate(nabla);   // compute the integral
    00028       A[index] += Aij;                           // add to global matrix
    00029     }
    00030   }
    00031 }

int main | ( |  | ) |

| Definition at line 78 of file code_gen.cpp. References code_gen2D(), LagrangeFE::compute_basis_functions(), compute_Poisson_element_matrix(), print(), and LagrangeFE::set().
    00078            {
    00079   int order =1;
    00080   Triangle triangle(lst(0,0), lst(1,0), lst(0,1));
    00081   LagrangeFE fe;
    00082   fe.set(2);
    00083   fe.set(triangle);
    00084   fe.compute_basis_functions();
    00085   code_gen2D(fe);
    00086
    00087
    00088   Dof dof;
    00089   std::map<std::pair<int,int>, ex> A;
    00090   compute_Poisson_element_matrix(fe, dof, A);
    00091   cout <<"C code format on output "<<endl;
    00092   cout <<csrc;
    00093   print(A);
    00094
    00095
    00096
    00097
    00098
    00099 }