SyFi  0.3
SyFi Namespace Reference

Classes

class  ArnoldFalkWintherWeakSymSigma
class  ArnoldFalkWintherWeakSymU
class  ArnoldFalkWintherWeakSymP
class  BrezziDouglasMarini
class  Bubble
class  CrouzeixRaviart
class  VectorCrouzeixRaviart
class  DiscontinuousLagrange
class  VectorDiscontinuousLagrange
class  Dof
class  FE
class  StandardFE
class  SymbolMapBuilderVisitor
class  SymbolCounterVisitor
class  ExStatsVisitor
class  ExStats
class  Hermite
class  Lagrange
class  VectorLagrange
class  TensorLagrange
class  MixedFE
class  Nedelec
class  Nedelec2Hdiv
class  OrderedPtvSet
struct  OrderedPtvSet_is_less
class  OrderedPtvSet_i
struct  OrderedPtvSet_i_is_less
class  P0
class  VectorP0
class  TensorP0
class  Polygon
class  Line
class  ReferenceLine
class  Triangle
class  ReferenceTriangle
class  Rectangle
class  ReferenceRectangle
class  Tetrahedron
class  ReferenceTetrahedron
class  Box
class  ReferenceBox
class  Simplex
class  RaviartThomas
class  Robust
class  SpaceTimeDomain
class  SpaceTimeElement

Typedefs

typedef std::pair
< GiNaC::symbol, GiNaC::ex > 
symexpair
typedef std::list< std::pair
< GiNaC::symbol, GiNaC::ex > > 
symexlist
typedef std::list< GiNaC::ex > exlist
typedef std::set< GiNaC::ex,
GiNaC::ex_is_less > 
exset
typedef std::map< GiNaC::ex,
int, GiNaC::ex_is_less > 
ex_int_map
typedef std::pair< unsigned
int, unsigned int > 
pair_ii
typedef std::vector< std::pair
< unsigned int, unsigned int > > 
vector_ii

Enumerations

enum  Repr_format { SUBS_PERFORMED = 1, SUBS_NOT_PERFORMED = 2 }

Functions

GiNaC::ex div (GiNaC::ex v)
GiNaC::ex div (GiNaC::ex v, GiNaC::ex G)
GiNaC::ex div (GiNaC::lst &v)
GiNaC::ex div (GiNaC::lst &v, GiNaC::ex G)
GiNaC::ex div (GiNaC::exvector &v)
GiNaC::ex grad (GiNaC::ex f)
GiNaC::ex grad (GiNaC::ex f, GiNaC::ex G)
void usage (FE &fe)
void usage (FE &v_fe, FE &p_fe)
void compute_Poisson_element_matrix (FE &fe, Dof &dof, std::map< std::pair< unsigned int, unsigned int >, GiNaC::ex > &A)
void compute_Stokes_element_matrix (FE &v_fe, FE &p_fe, Dof &dof, std::map< std::pair< unsigned int, unsigned int >, GiNaC::ex > &A)
void compute_mixed_Poisson_element_matrix (FE &v_fe, FE &p_fe, Dof &dof, std::map< std::pair< unsigned int, unsigned int >, GiNaC::ex > &A)
GiNaC::lst cross (GiNaC::lst &v1, GiNaC::lst &v2)
GiNaC::ex inner (GiNaC::ex a, GiNaC::ex b, bool transposed)
GiNaC::ex inner (GiNaC::lst v1, GiNaC::lst v2)
GiNaC::ex inner (GiNaC::exvector &v1, GiNaC::exvector &v2)
GiNaC::lst matvec (GiNaC::matrix &M, GiNaC::lst &x)
GiNaC::ex matvec (GiNaC::ex A, GiNaC::ex x)
GiNaC::lst ex2equations (GiNaC::ex rel)
GiNaC::lst collapse (GiNaC::lst l)
GiNaC::matrix equations2matrix (const GiNaC::ex &eqns, const GiNaC::ex &symbols)
void matrix_from_equations (const GiNaC::ex &eqns, const GiNaC::ex &symbols, GiNaC::matrix &A, GiNaC::matrix &b)
GiNaC::ex lst_to_matrix2 (const GiNaC::lst &l)
GiNaC::lst matrix_to_lst2 (const GiNaC::ex &m)
GiNaC::lst lst_equals (GiNaC::ex a, GiNaC::ex b)
int find (GiNaC::ex e, GiNaC::lst list)
void visitor_subst_pow (GiNaC::ex e, GiNaC::exmap &map, ex_int_map &intmap, string a)
void check_visitor (GiNaC::ex e, GiNaC::lst &exlist)
GiNaC::ex homogenous_pol (unsigned int order, unsigned int nsd, const string a)
GiNaC::lst homogenous_polv (unsigned int no_fields, unsigned int order, unsigned int nsd, const string a)
GiNaC::ex pol (unsigned int order, unsigned int nsd, const string a)
GiNaC::lst polv (unsigned int no_fields, unsigned int order, unsigned int nsd, const string a)
GiNaC::ex polb (unsigned int order, unsigned int nsd, const string a)
GiNaC::lst coeffs (GiNaC::lst pols)
GiNaC::lst coeffs (GiNaC::ex pol)
GiNaC::exvector coeff (GiNaC::ex pol)
GiNaC::exmap pol2basisandcoeff (GiNaC::ex e, GiNaC::ex s)
GiNaC::exmap pol2basisandcoeff (GiNaC::ex e)
GiNaC::ex legendre1D (const GiNaC::symbol x, unsigned int n)
GiNaC::ex legendre (unsigned int order, unsigned int nsd, const string s)
GiNaC::lst legendrev (unsigned int no_fields, unsigned int order, unsigned int nsd, const string a)
bool compare (const ex &e, const string &s)
void EQUAL_OR_DIE (const ex &e, const string &s)
exhashmap< int > count_symbols (const ex &e)
ex extract_symbols (const ex &e)
void collect_symbols (const GiNaC::ex &e, exset &v)
GiNaC::exvector collect_symbols (const GiNaC::ex &e)
bool compare_archives (const string &first, const string &second, std::ostream &os)
ExStats count_ops (const ex &e)
ex replace_powers (const ex &ein, const list< symbol > &symbols, list< symexpair > &sel, const string &tmpsymbolprefix)
bool compare (const GiNaC::ex &e, const std::string &s)
void EQUAL_OR_DIE (const GiNaC::ex &e, const std::string &s)
bool compare_archives (const std::string &first, const std::string &second, std::ostream &os=std::cout)
void visitor_subst_pow (GiNaC::ex e, GiNaC::exmap &map, ex_int_map &intmap, std::string a)
GiNaC::ex pol (unsigned int order, unsigned int nsd, const std::string a)
GiNaC::lst polv (unsigned int no_fields, unsigned int order, unsigned int nsd, const std::string a)
GiNaC::ex polb (unsigned int order, unsigned int nsd, const std::string a)
GiNaC::ex homogenous_pol (unsigned int order, unsigned int nsd, const std::string a)
GiNaC::lst homogenous_polv (unsigned int no_fields, unsigned int order, unsigned int nsd, const std::string a)
GiNaC::ex legendre (unsigned int order, unsigned int nsd, const std::string a)
GiNaC::lst legendrev (unsigned int no_fields, unsigned int order, unsigned int nsd, const std::string a)
GiNaC::exhashmap< int > count_symbols (const GiNaC::ex &e)
GiNaC::ex extract_symbols (const GiNaC::ex &e)
ExStats count_ops (const GiNaC::ex &e)
GiNaC::ex replace_powers (const GiNaC::ex &e, const std::list< GiNaC::symbol > &symbols, std::list< symexpair > &sel, const std::string &tmpsymbolprefix="p_")
GiNaC::ex lagrange (unsigned int order, Polygon &p, const std::string &a)
GiNaC::lst lagrangev (unsigned int no_fields, unsigned int order, Polygon &p, const std::string &a)
std::ostream & operator<< (std::ostream &os, const OrderedPtvSet &p)
std::ostream & operator<< (std::ostream &os, const OrderedPtvSet_i &p)
lst bezier_ordinates (Tetrahedron &tetrahedra, unsigned int d)
lst interior_coordinates (Tetrahedron &tetrahedra, unsigned int d)
lst bezier_ordinates (Triangle &triangle, unsigned int d)
lst interior_coordinates (Triangle &triangle, unsigned int d)
lst bezier_ordinates (Line &line, unsigned int d)
lst interior_coordinates (Line &line, unsigned int d)
ex barycenter_line (ex p0, ex p1)
ex barycenter_triangle (ex p0, ex p1, ex p2)
ex barycenter_tetrahedron (ex p0, ex p1, ex p2, ex p3)
ex barycenter (Simplex &simplex)
ex bernstein (unsigned int order, Polygon &p, const string &a)
lst bernsteinv (unsigned int no_fields, unsigned int order, Polygon &p, const string &a)
lst normal (Tetrahedron &tetrahedron, unsigned int i)
lst normal (Triangle &triangle, unsigned int i)
lst tangent (Triangle &triangle, unsigned int i)
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::ex bernstein (unsigned int order, Polygon &p, const std::string &a)
GiNaC::lst bernsteinv (unsigned int no_fields, unsigned int order, Polygon &p, const std::string &a)
void sort_vector (vector< Ptv > &a)
void set_tolerance (double tolerance)
double mul (const Ptv &a, const Ptv &b)
double norm (const Ptv &a)
void normalize (Ptv &a)
void add (const Ptv &a, const Ptv &b, Ptv &c)
void sub (const Ptv &a, const Ptv &b, Ptv &c)
void cross (const Ptv &a, const Ptv &b, Ptv &c)
bool is_equal (Ptv &a, Ptv &b)
bool line_contains (Ptv &e0, Ptv &e1, Ptv &p)
bool is_inside_triangle (Ptv &e0, Ptv &e1, Ptv &e2, Ptv &p)
bool contains2D (Ptv &e0, Ptv &e1, Ptv &p)
bool contains3D (Ptv &e0, Ptv &e1, Ptv &e2, Ptv &p)
GiNaC::symbol x ("(x is not initialized since initSyFi has never been called)")
GiNaC::symbol y ("(y is not initialized since initSyFi has never been called)")
GiNaC::symbol z ("(z is not initialized since initSyFi has never been called)")
GiNaC::symbol t ("(t is not initialized since initSyFi has never been called)")
GiNaC::symbol infinity ("(infinity is not initialized since initSyFi has never been called)")
GiNaC::symbol DUMMY ("(DUMMY is not initialized since initSyFi has never been called)")
void initSyFi (unsigned int nsd_)
bool symbol_exists (const string &name)
const symbol & get_symbol (const string &name)
const symbol & isymb (const string &a, int b)
const symbol & isymb (const string &a, int b, int c)
GiNaC::ex get_symbolic_vector (int m, const std::string &basename)
GiNaC::ex get_symbolic_matrix (int m, int n, const std::string &basename)
bool symbol_exists (const std::string &name)
const GiNaC::symbol & get_symbol (const std::string &name)
const GiNaC::symbol & isymb (const std::string &a, int b)
const GiNaC::symbol & isymb (const std::string &a, int b, int c)
int dirac (unsigned int i, unsigned int j)
string int2string (int i)
string istr (const string &a, int b)
string istr (const string &a, int b, int c)
string lst2string (GiNaC::lst &l)
string exvector2string (GiNaC::exvector &v)
void print (GiNaC::lst &l)
void print (GiNaC::exvector &v)
void print (std::map< std::pair< unsigned int, unsigned int >, GiNaC::ex > &A)
void print (ex_int_map map)
void print (GiNaC::exmap map)
std::string istr (const std::string &a, int b)
std::string istr (const std::string &a, int b, int c)

Variables

unsigned int nsd = 2
GiNaC::lst p
map< string, symbol > symbol_collection
GiNaC::symbol x
GiNaC::symbol y
GiNaC::symbol z
GiNaC::symbol t
GiNaC::symbol infinity
GiNaC::symbol DUMMY
const int version_major = SYFILIB_MAJOR_VERSION
const int version_minor = SYFILIB_MINOR_VERSION
const char * version_micro = SYFILIB_MICRO_VERSION

Typedef Documentation

typedef std::map<GiNaC::ex, int, GiNaC::ex_is_less> SyFi::ex_int_map

Definition at line 40 of file containers.h.

typedef std::list<GiNaC::ex> SyFi::exlist

Definition at line 37 of file containers.h.

typedef std::set<GiNaC::ex, GiNaC::ex_is_less> SyFi::exset

Definition at line 38 of file containers.h.

typedef std::pair<unsigned int, unsigned int> SyFi::pair_ii

Definition at line 32 of file Dof.h.

typedef std::list< std::pair<GiNaC::symbol, GiNaC::ex> > SyFi::symexlist

Definition at line 34 of file containers.h.

typedef std::pair<GiNaC::symbol, GiNaC::ex> SyFi::symexpair

Definition at line 33 of file containers.h.

typedef std::vector< std::pair<unsigned int, unsigned int> > SyFi::vector_ii

Definition at line 33 of file Dof.h.


Enumeration Type Documentation

Enumerator:
SUBS_PERFORMED 
SUBS_NOT_PERFORMED 

Definition at line 27 of file Polygon.h.


Function Documentation

void SyFi::add ( const Ptv a,
const Ptv b,
Ptv c 
)

Definition at line 76 of file Ptv_tools.cpp.

References Ptv::redim(), and Ptv::size().

        {
                if ( a.size() != b.size() )
                {
                        throw(std::logic_error("Exception from add(const Ptv&, const Ptv&, Ptv&):  The dimentions of a and b must be the same."));
                }

                c.redim(a.size());
                for (unsigned int i=0; i< c.size(); i++)
                {
                        c[i] = a[i] + b[i];
                }
        }
GiNaC::ex SyFi::barycenter ( Simplex &  simplex)

Definition at line 1768 of file Polygon.cpp.

References get_symbolic_vector(), SyFi::Polygon::no_vertices(), nsd, and SyFi::Polygon::vertex().

Referenced by main().

        {
                if (nsd != simplex.no_vertices()-1)
                {
                        throw std::runtime_error("Could not compute the barycentric coordinates. Not implemented yet for simplices with no_vertices != nsd +1.");
                }

                // put symbols in lst
                ex b = get_symbolic_vector(simplex.no_vertices(), "b");
                lst symbols;
                for (unsigned int i=0; i<b.nops(); i++)
                {
                        symbols.append(b.op(i));
                }

                // put equations in lst
                lst eqs;
                for (unsigned int i=0; i<nsd; i++)
                {
                        ex sum = 0;
                        for (unsigned int k=0; k< simplex.no_vertices(); k++)
                        {
                                sum += b.op(k)*simplex.vertex(k).op(i);
                        }
                        ex eqi = p[i] == sum;
                        eqs.append(eqi);
                }

                // last eq, sum = 1
                ex sum = 0;
                for (unsigned int i=0; i<symbols.nops(); i++)
                {
                        sum += symbols.op(i);
                }
                ex last_eq = 1 == sum;
                eqs.append(last_eq);

                // solve equations
                ex sol = lsolve(eqs, symbols);
                return sol;
        }
GiNaC::ex SyFi::barycenter_line ( GiNaC::ex  p0,
GiNaC::ex  p1 
)
ex SyFi::barycenter_line ( ex  p0,
ex  p1 
)

Definition at line 1623 of file Polygon.cpp.

References x.

Referenced by bernstein().

        {
                ex sol;

                // 1D
                if (!GiNaC::is_a<lst>(p0))
                {
                        GiNaC::symbol b0("b0"), b1("b1");
                        ex eq1 = x == b0*p0 + b1*p1;
                        ex eq2 = 1 == b0 + b1;
                        sol = lsolve(lst(eq1, eq2), lst(b0, b1));
                }
                else if (p0.nops() == 1 && p1.nops() == 1)
                {
                        GiNaC::symbol b0("b0"), b1("b1");
                        ex eq1 = x == b0*p0.op(0) + b1*p1.op(0);
                        ex eq2 = 1 == b0 + b1;
                        sol = lsolve(lst(eq1, eq2), lst(b0, b1));
                        if ( sol == 0 )
                        {
                                ex eq1 = y == b0*p0.op(1) + b1*p1.op(1);
                                sol = lsolve(lst(eq1, eq2), lst(b0, b1));
                        }
                        if ( sol == 0 )
                        {
                                ex eq1 = z == b0*p0.op(2) + b1*p1.op(2);
                                sol = lsolve(lst(eq1, eq2), lst(b0, b1));
                        }
                }
                //2D
                else if ( p0.nops() == 2 && p1.nops() == 2 )
                {
                        GiNaC::symbol b0("b0"), b1("b1");
                        ex eq1 = x == b0*p0.op(0) + b1*p1.op(0);
                        ex eq3 = 1 == b0 + b1;
                        sol = lsolve(lst(eq1, eq3), lst(b0, b1));
                        if (sol.nops() == 0)
                        {
                                ex eq2 = y == b0*p0.op(1) + b1*p1.op(1);
                                sol = lsolve(lst(eq2, eq3), lst(b0, b1));
                        }
                }
                //3D
                else if ( p0.nops() == 3 && p1.nops() == 3 )
                {
                        GiNaC::symbol b0("b0"), b1("b1");
                        ex eq1 = x == b0*p0.op(0) + b1*p1.op(0);
                        ex eq4 = 1 == b0 + b1;
                        sol = lsolve(lst(eq1, eq4), lst(b0, b1));
                        if (sol.nops() == 0)
                        {
                                ex eq2 = y == b0*p0.op(1) + b1*p1.op(1);
                                sol = lsolve(lst(eq2, eq4), lst(b0, b1));
                        }
                        if (sol.nops() == 0)
                        {
                                ex eq3 = z == b0*p0.op(2) + b1*p1.op(2);
                                sol = lsolve(lst(eq3, eq4), lst(b0, b1));
                        }
                }
                else
                {
                        throw std::runtime_error("Could not compute the barycentric coordinates. Check the coordinates.");
                }

                return sol;
        }
GiNaC::ex SyFi::barycenter_tetrahedron ( GiNaC::ex  p0,
GiNaC::ex  p1,
GiNaC::ex  p2,
GiNaC::ex  p3 
)
ex SyFi::barycenter_tetrahedron ( ex  p0,
ex  p1,
ex  p2,
ex  p3 
)

Definition at line 1752 of file Polygon.cpp.

References x.

Referenced by barycenter_triangle(), bernstein(), and SyFi::Bubble::compute_basis_functions().

        {
                GiNaC::symbol b0("b0"), b1("b1"), b2("b2"), b3("b3");

                // 3D
                ex eq1 = x == b0*p0.op(0) + b1*p1.op(0) + b2*p2.op(0) + b3*p3.op(0);
                ex eq2 = y == b0*p0.op(1) + b1*p1.op(1) + b2*p2.op(1) + b3*p3.op(1);
                ex eq3 = z == b0*p0.op(2) + b1*p1.op(2) + b2*p2.op(2) + b3*p3.op(2);
                ex eq4 = 1 == b0 + b1 + b2 +b3;

                ex sol = lsolve(lst(eq1, eq2, eq3, eq4), lst(b0, b1, b2, b3));

                return sol;

        }
GiNaC::ex SyFi::barycenter_triangle ( GiNaC::ex  p0,
GiNaC::ex  p1,
GiNaC::ex  p2 
)
ex SyFi::barycenter_triangle ( ex  p0,
ex  p1,
ex  p2 
)

Definition at line 1691 of file Polygon.cpp.

References barycenter_tetrahedron(), cross(), and x.

Referenced by bernstein(), and SyFi::Bubble::compute_basis_functions().

        {
                ex sol;

                // 2D
                if ( p0.nops() == 2 && p1.nops() == 2 && p2.nops() == 2)
                {
                        GiNaC::symbol b0("b0"), b1("b1"), b2("b2");
                        ex eq1 = x == b0*p0.op(0) + b1*p1.op(0) + b2*p2.op(0);
                        ex eq2 = y == b0*p0.op(1) + b1*p1.op(1) + b2*p2.op(1);
                        ex eq3 = 1 == b0 + b1 + b2;

                        sol = lsolve(lst(eq1, eq2, eq3), lst(b0, b1, b2));
                }
                // 3D
                else if ( p0.nops() == 3 && p1.nops() == 3 && p2.nops() == 3)
                {
                        lst n1(p1.op(0) - p0.op(0),  p1.op(1) - p0.op(1), p1.op(2) - p0.op(2));
                        lst n2 = lst(p2.op(0) - p0.op(0),  p2.op(1) - p0.op(1), p2.op(2) - p0.op(2));
                        lst n = cross(n1,n2);

                        lst midpoint = lst((p0.op(0) + p1.op(0) + p2.op(0))/3,
                                (p0.op(1) + p1.op(1) + p2.op(1))/3,
                                (p0.op(2) + p1.op(2) + p2.op(2))/3);

                        ex p3 = lst(midpoint.op(0) + n.op(0),
                                midpoint.op(1) + n.op(1),
                                midpoint.op(2) + n.op(2));

                        ex s = barycenter_tetrahedron(p0, p1, p2, p3);
                        lst solution;
                        for (unsigned int i=0; i<s.nops(); i++)
                        {
                                ex d = s.op(i).subs(x == p3.op(0)).subs(y == p3.op(1)).subs(z == p3.op(2));
                                d = d.rhs();
                                if ( GiNaC::is_a<GiNaC::numeric>(d))
                                {
                                                                 // FIXME: bad test, should use the toleranse variable set by CLN or something
                                        if ( GiNaC::abs(GiNaC::ex_to<GiNaC::numeric>(d)) < 10e-8)
                                        {
                                                solution.append(s.op(i));
                                        }
                                }
                                else
                                {
                                        if ( d.is_zero() )
                                        {
                                                solution.append(s.op(i));
                                        }
                                }
                        }
                        sol = solution;
                }
                else
                {
                        throw std::runtime_error("Could not compute the barycentric coordinates. Check the coordinates.");
                }

                return sol;
        }
GiNaC::ex SyFi::bernstein ( unsigned int  order,
Polygon &  p,
const std::string &  a 
)
ex SyFi::bernstein ( unsigned int  order,
Polygon &  p,
const string &  a 
)

Definition at line 1810 of file Polygon.cpp.

References barycenter_line(), barycenter_tetrahedron(), barycenter_triangle(), get_symbolic_matrix(), matrix_to_lst2(), SyFi::Polygon::str(), and SyFi::Polygon::vertex().

Referenced by bernsteinv(), SyFi::Lagrange::compute_basis_functions(), SyFi::CrouzeixRaviart::compute_basis_functions(), SyFi::Nedelec::compute_basis_functions(), SyFi::Nedelec2Hdiv::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), SyFi::RaviartThomas::compute_basis_functions(), SyFi::Robust::compute_basis_functions_old(), and main().

        {

                if ( order < 0 )
                {
                        throw(std::logic_error("Can not create polynomials of order less than 0!"));
                }

                ex ret;                                  // ex to return
                int dof;                                 // degrees of freedom
                ex A;                                    // ex holding the coefficients a_0 .. a_dof
                lst basis;

                if ( p.str().find("Line") != string::npos )
                {
                        ex bary = barycenter_line(p.vertex(0), p.vertex(1));
                        ex b0= bary.op(0).rhs();
                        ex b1= bary.op(1).rhs();
                        dof = order+1;
                        A = get_symbolic_matrix(1,dof, a);
                        int o=0;
                        for (GiNaC::const_iterator i = A.begin(); i != A.end(); ++i)
                        {
                                ex scale = GiNaC::binomial(order,o);
                                ret += (*i)*scale*pow(b0,o)*pow(b1,order-o);
                                basis.append(scale*pow(b0,o)*pow(b1,order-o));
                                o++;
                        }
                }
                else if ( p.str().find("Triangle") != string::npos )
                {

                        dof = (order+1)*(order+2)/2;
                        A = get_symbolic_matrix(1, dof , a);

                        ex bary = barycenter_triangle(p.vertex(0), p.vertex(1), p.vertex(2));
                        ex b0= bary.op(0).rhs();
                        ex b1= bary.op(1).rhs();
                        ex b2= bary.op(2).rhs();

                        size_t i=0;
                        for (unsigned int o1 = 0; o1 <= order; o1++)
                        {
                                for (unsigned int o2 = 0; o2 <= order; o2++)
                                {
                                        for (unsigned int o3 = 0; o3 <= order; o3++)
                                        {
                                                if ( o1 + o2 + o3 == order )
                                                {
                                                        ex scale = (GiNaC::factorial(order)/(GiNaC::factorial(o1)*GiNaC::factorial(o2)*GiNaC::factorial(o3)));
                                                        ret += A.op(i)*scale*pow(b0,o1)*pow(b1,o2)*pow(b2,o3);

                                                        basis.append(scale*pow(b0,o1)*pow(b1,o2)*pow(b2,o3));
                                                        i++;
                                                }
                                        }
                                }
                        }
                }

                else if ( p.str().find("Tetrahedron") != string::npos )
                {

                        dof = 0;
                        for (unsigned int j=0; j<= order; j++)
                        {
                                dof += (j+1)*(j+2)/2;
                        }
                        A = get_symbolic_matrix(1, dof , a);

                        ex bary = barycenter_tetrahedron(p.vertex(0), p.vertex(1), p.vertex(2), p.vertex(3));
                        ex b0= bary.op(0).rhs();
                        ex b1= bary.op(1).rhs();
                        ex b2= bary.op(2).rhs();
                        ex b3= bary.op(3).rhs();

                        size_t i=0;
                        for (unsigned int o1 = 0; o1 <= order; o1++)
                        {
                                for (unsigned int o2 = 0; o2 <= order; o2++)
                                {
                                        for (unsigned int o3 = 0; o3 <= order; o3++)
                                        {
                                                for (unsigned int o4 = 0; o4 <= order; o4++)
                                                {
                                                        if ( o1 + o2 + o3 + o4 == order )
                                                        {
                                                                ex scale = (GiNaC::factorial(order)/(GiNaC::factorial(o1)*GiNaC::factorial(o2)*GiNaC::factorial(o3)*GiNaC::factorial(o4)));
                                                                ret += A.op(i)*scale*pow(b0,o1)*pow(b1,o2)*pow(b2,o3)*pow(b3,o4);
                                                                basis.append(scale*pow(b0,o1)*pow(b1,o2)*pow(b2,o3)*pow(b3,o4));
                                                                i++;
                                                        }
                                                }
                                        }
                                }
                        }
                }

                else if (p.str() == "Simplex" || p.str() == "ReferenceSimplex")
                {

                        throw std::runtime_error("Not implemented yet.");
                        //      ex bary = barycenter(p);
                }
                return lst(ret,matrix_to_lst2(A),basis);
        }
GiNaC::lst SyFi::bernsteinv ( unsigned int  no_fields,
unsigned int  order,
Polygon &  p,
const std::string &  a 
)
lst SyFi::bernsteinv ( unsigned int  no_fields,
unsigned int  order,
Polygon &  p,
const string &  a 
)

Definition at line 1917 of file Polygon.cpp.

References bernstein(), pol(), and SyFi::Polygon::str().

Referenced by SyFi::Nedelec::compute_basis_functions(), SyFi::Nedelec2Hdiv::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), SyFi::RaviartThomas::compute_basis_functions(), SyFi::BrezziDouglasMarini::compute_basis_functions(), and SyFi::Robust::compute_basis_functions_old().

        {

                if ( order < 0 )
                {
                        throw(std::logic_error("Can not create polynomials of order less than 0!"));
                }

                lst ret1;                                // contains the polynom
                lst ret2;                                // contains the coefficients
                lst ret3;                                // constains the basis functions
                lst basis_tmp;
                for (unsigned int i=0; i< no_fields; i++)
                {
                        lst basis;
                        std::ostringstream s;
                        s <<a<<""<<i<<"_";
                        ex pol = bernstein(order, p, s.str());
                        ret1.append(pol.op(0));
                        ret2.append(pol.op(1));
                        basis_tmp = ex_to<lst>(pol.op(2));
                        for (lst::const_iterator basis_iterator = basis_tmp.begin();
                                basis_iterator != basis_tmp.end(); ++basis_iterator)
                        {
                                lst tmp_lst;
                                for (unsigned int d=1; d<=no_fields; d++) tmp_lst.append(0);
                                tmp_lst.let_op(i) = (*basis_iterator);
                                ret3.append(tmp_lst);
                        }
                }
                return lst(ret1,ret2,ret3);

        }
GiNaC::lst SyFi::bezier_ordinates ( Tetrahedron &  tetrahedra,
unsigned int  d 
)

Definition at line 1392 of file Polygon.cpp.

References lst_to_matrix2(), matrix_to_lst2(), and SyFi::Polygon::vertex().

Referenced by SyFi::Lagrange::compute_basis_functions(), and main().

        {

                //FIXME: ugly conversion to matrix

                lst ret;
                ex V1 = tetrahedra.vertex(0);
                ex V2 = tetrahedra.vertex(1);
                ex V3 = tetrahedra.vertex(2);
                ex V4 = tetrahedra.vertex(3);

                lst V1l = ex_to<lst>(V1);
                lst V2l = ex_to<lst>(V2);
                lst V3l = ex_to<lst>(V3);
                lst V4l = ex_to<lst>(V4);

                ex V1m  = lst_to_matrix2(V1l);
                ex V2m  = lst_to_matrix2(V2l);
                ex V3m  = lst_to_matrix2(V3l);
                ex V4m  = lst_to_matrix2(V4l);

                int l;
                for (unsigned int i=0; i<= d; i++)
                {
                        for (unsigned int j=0; j<= d; j++)
                        {
                                for (unsigned int k=0; k<= d; k++)
                                {
                                        if ( d - i - j -k  >= 0 )
                                        {
                                                l= d - i - j -k;
                                                ex sum = (l*V1m + k*V2m + j*V3m + i*V4m)/d;
                                                ret.append(matrix_to_lst2(sum.evalm()));
                                        }
                                }
                        }
                }
                // FIXME how should these be sorted ?????
                //  ret = ret.sort();
                return ret;
        }
GiNaC::lst SyFi::bezier_ordinates ( Triangle &  triangle,
unsigned int  d 
)

Definition at line 1477 of file Polygon.cpp.

References lst_to_matrix2(), matrix_to_lst2(), and SyFi::Polygon::vertex().

        {

                //FIXME: ugly conversion to matrix

                lst ret;
                ex V1 = triangle.vertex(0);
                ex V2 = triangle.vertex(1);
                ex V3 = triangle.vertex(2);

                lst V1l = ex_to<lst>(V1);
                lst V2l = ex_to<lst>(V2);
                lst V3l = ex_to<lst>(V3);

                ex V1m  = lst_to_matrix2(V1l);
                ex V2m  = lst_to_matrix2(V2l);
                ex V3m  = lst_to_matrix2(V3l);

                int k;
                for (unsigned int i=0; i <= d; i++)
                {
                        for (unsigned int j=0; j <= d; j++)
                        {
                                if ( int(d) - int(i) - int(j) >= 0  )
                                {
                                        k = d - i - j;
                                        ex sum = (k*V1m + j*V2m + i*V3m)/d;
                                        ret.append(matrix_to_lst2(sum.evalm()));
                                }
                        }
                }
                // FIXME how should these be sorted ?????
                // ret = ret.sort();
                return ret;
        }
GiNaC::lst SyFi::bezier_ordinates ( Line &  line,
unsigned int  d 
)

Definition at line 1551 of file Polygon.cpp.

References lst_to_matrix2(), matrix_to_lst2(), and SyFi::Polygon::vertex().

        {

                lst ret;
                ex V1 = line.vertex(0);
                ex V2 = line.vertex(1);

                if (!GiNaC::is_a<lst>(V1))
                {
                        int k;
                        for (unsigned int i=0; i <= d; i++)
                        {
                                k = d - i;
                                ex sum = (k*V1 + i*V2)/d;
                                ret.append(sum);
                        }
                }
                else
                {

                        //FIXME: ugly conversion to matrix

                        lst V1l = ex_to<lst>(V1);
                        lst V2l = ex_to<lst>(V2);

                        ex V1m  = lst_to_matrix2(V1l);
                        ex V2m  = lst_to_matrix2(V2l);

                        int k;
                        for (unsigned int i=0; i <= d; i++)
                        {
                                k = d - i;
                                ex sum = (k*V1m + i*V2m)/d;
                                ret.append(matrix_to_lst2(sum.evalm()));
                        }
                        // FIXME how should these be sorted ?????
                        // ret = ret.sort();
                }
                return ret;
        }
void SyFi::check_visitor ( GiNaC::ex  e,
GiNaC::lst &  exlist 
)

Definition at line 461 of file ginac_tools.cpp.

References find().

{
        if (find(e, exlist) >= 0) return;

        //  cout <<"ex e "<<e<<endl;
        if (GiNaC::is_a<GiNaC::numeric>(e))
        {
        }
        else if (GiNaC::is_a<GiNaC::add>(e) )
        {
                //    cout <<"e "<<e <<endl;
                //    cout <<"e.nops() "<<e.nops() <<endl;
                if (e.nops() > 4 && e.nops() < 10 ) exlist.append(e);
                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        //       cout <<"add e "<<e2<<endl;
                        //       exlist.append(e2);
                        check_visitor(e2,exlist);
                }
        }
        else if (GiNaC::is_a<GiNaC::mul>(e))
        {
                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        //       cout <<"mul e "<<e2<<endl;
                        exlist.append(e2);
                        check_visitor(e2,exlist);
                }
        }
        else if (GiNaC::is_a<GiNaC::lst>(e))
        {
                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        //       cout <<"GiNaC::lst e "<<e2<<endl;
                        //       exlist.append(e2);
                        check_visitor(e2,exlist);
                }
        }
        else if (GiNaC::is_exactly_a<GiNaC::power>(e))
        {
                exlist.append(e);
                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        //       cout <<"power e "<<e2<<endl;
                        check_visitor(e2,exlist);
                }
        }
        else if (GiNaC::is_a<GiNaC::function>(e))
        {
                exlist.append(e);
                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        //       cout <<"function e "<<e2<<endl;
                        check_visitor(e2,exlist);
                }
        }

        else
        {
                //       exlist.append(e);
                //    cout <<"atom e "<<e<<endl;
        }

        exlist.sort();
        exlist.unique();
}
GiNaC::exvector SyFi::coeff ( GiNaC::ex  pol)

Definition at line 855 of file ginac_tools.cpp.

References test_syfi::debug::c, x, y, and z.

Referenced by SyFi::Nedelec2Hdiv::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), and SyFi::Robust::compute_basis_functions_old().

{
        using SyFi::x;
        using SyFi::y;
        using SyFi::z;

        GiNaC::exvector cc;
        GiNaC::ex c, b;
        for (int i=pol.ldegree(x); i<=pol.degree(x); ++i)
        {
                for (int j=pol.ldegree(y); j<=pol.degree(y); ++j)
                {
                        for (int k=pol.ldegree(z); k<=pol.degree(z); ++k)
                        {
                                c = pol.coeff(x,i).coeff(y, j).coeff(z,k);
                                if ( c != 0 ) cc.insert(cc.begin(),c);
                        }
                }
        }
        return cc;
}
GiNaC::lst SyFi::coeffs ( GiNaC::lst  pols)

Definition at line 819 of file ginac_tools.cpp.

References collapse().

{
        GiNaC::lst cc;
        GiNaC::lst tmp;
        for (unsigned int i=0; i<= pols.nops()-1; i++)
        {
                tmp = coeffs(pols.op(i));
                cc = collapse(GiNaC::lst(cc, tmp));
        }
        return cc;
}
GiNaC::lst SyFi::coeffs ( GiNaC::ex  pol)

Definition at line 832 of file ginac_tools.cpp.

References test_syfi::debug::c, x, y, and z.

{
        using SyFi::x;
        using SyFi::y;
        using SyFi::z;

        GiNaC::lst cc;
        GiNaC::ex c, b;
        for (int i=pol.ldegree(x); i<=pol.degree(x); ++i)
        {
                for (int j=pol.ldegree(y); j<=pol.degree(y); ++j)
                {
                        for (int k=pol.ldegree(z); k<=pol.degree(z); ++k)
                        {
                                c = pol.coeff(x,i).coeff(y, j).coeff(z,k);
                                if ( c != 0 ) cc.append(c);
                        }
                }
        }
        return cc;
}
GiNaC::lst SyFi::collapse ( GiNaC::lst  l)

Definition at line 214 of file ginac_tools.cpp.

Referenced by coeffs(), SyFi::Nedelec::compute_basis_functions(), SyFi::Nedelec2Hdiv::compute_basis_functions(), SyFi::RaviartThomas::compute_basis_functions(), SyFi::BrezziDouglasMarini::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), and SyFi::Robust::compute_basis_functions_old().

        {
                GiNaC::lst lc;
                GiNaC::lst::const_iterator iter1, iter2;

                for (iter1 = l.begin(); iter1 != l.end(); ++iter1)
                {
                        if (GiNaC::is_a<GiNaC::lst>(*iter1))
                        {
                                for (iter2 = GiNaC::ex_to<GiNaC::lst>(*iter1).begin(); iter2 != GiNaC::ex_to<GiNaC::lst>(*iter1).end(); ++iter2)
                                {
                                        lc.append(*iter2);
                                }
                        }
                        else
                        {
                                lc.append(*iter1);
                        }
                }
                lc.sort();
                lc.unique();
                return lc;
        }
void SyFi::collect_symbols ( const GiNaC::ex &  e,
exset &  v 
)

Definition at line 1234 of file ginac_tools.cpp.

References test_syfi::debug::v.

Referenced by collect_symbols().

{
        if (GiNaC::is_a<GiNaC::symbol>(e))
        {
                v.insert(e);
        }
        else
        {
                for (size_t i=0; i<e.nops(); i++)
                {
                        collect_symbols(e.op(i), v);
                }
        }
}
GiNaC::exvector SyFi::collect_symbols ( const GiNaC::ex &  e)

Definition at line 1250 of file ginac_tools.cpp.

References collect_symbols(), and test_syfi::debug::v.

{
        exset s;
        collect_symbols(e, s);
        GiNaC::exvector v(s.size());
        for(exset::iterator i=s.begin(); i!= s.end(); i++)
        {
                v.push_back(*i);
        }
        return v;
}
bool SyFi::compare ( const GiNaC::ex &  e,
const std::string &  s 
)
bool SyFi::compare ( const ex &  e,
const string &  s 
)

Definition at line 1087 of file ginac_tools.cpp.

Referenced by EQUAL_OR_DIE().

{
        ostringstream ss;
        ss << e;
        return ss.str() == s;
}
bool SyFi::compare_archives ( const std::string &  first,
const std::string &  second,
std::ostream &  os = std::cout 
)
bool SyFi::compare_archives ( const string &  first,
const string &  second,
std::ostream &  os 
)

Definition at line 1263 of file ginac_tools.cpp.

References extract_symbols().

Referenced by check_CrouzeixRaviart(), and main().

{
        bool ret = true;

        // read both archives
        archive a1, a2;
        ifstream if1(first.c_str()), if2(second.c_str());
        if1 >> a1;
        if2 >> a2;

        // compare size
        int n = a1.num_expressions();
        int n2 = a2.num_expressions();
        if(n != n2)
        {
                os << "Archives " << first << " and " << second
                        << " has a different number of expressions, " << n << " and " << n2 << "." << endl;
                os << "Comparing common expressions." << endl;
                ret = false;
        }

        // iterate over all expressions in first archive
        ex e1,e2;
        for(int i=0; i<n; i++)
        {
                lst syms;
                string exname;

                e1 = a1.unarchive_ex(syms, exname, i);

                syms = ex_to<lst>(extract_symbols(e1));
                //        os << "Comparing " << exname << " with symbols " << syms << endl;

                // is this in the second archive?
                try
                {
                        e2 = a2.unarchive_ex(syms, exname.c_str());

                        // got it, now compare
                        bool isequal = is_zero(e1-e2);
                        if(!isequal)
                        {
                                if(ret)
                                {
                                        os << "Archives " << first << " and " << second
                                                << " are not equal, details follow:" << endl;
                                }
                                os << "Expression with name " << exname << " is not equal:" << endl;
                                os << "First:  " << endl << e1 << endl;
                                os << "Second: " << endl << e2 << endl;
                                ret = false;
                        }
                }
                catch(...)
                {
                        os << "Expression " << exname << " is missing from " << second << "." << endl;
                        ret = false;
                }
        }

        return ret;
}
void SyFi::compute_mixed_Poisson_element_matrix ( FE &  v_fe,
FE &  p_fe,
Dof &  dof,
std::map< std::pair< unsigned int, unsigned int >, GiNaC::ex > &  A 
)

Definition at line 150 of file ElementComputations.cpp.

References div(), SyFi::FE::dof(), SyFi::FE::get_polygon(), SyFi::Dof::glob_dof(), inner(), SyFi::Dof::insert_dof(), SyFi::Polygon::integrate(), SyFi::FE::N(), and SyFi::FE::nbf().

Referenced by main().

        {
                std::pair<unsigned int,unsigned int> index;
                std::pair<unsigned int,unsigned int> index2;

                // FIXME: need to check that p_fe
                // contains the same domain
                Polygon& domain = v_fe.get_polygon();

                // Insert the local degrees of freedom into the global Dof
                for (unsigned int i=0; i< v_fe.nbf(); i++)
                {
                        dof.insert_dof(1,i,v_fe.dof(i));
                }
                for (unsigned int i=0; i< p_fe.nbf(); i++)
                {
                        dof.insert_dof(1,v_fe.nbf()+i+1,p_fe.dof(i));
                }

                // The term (u,v)
                for (unsigned int i=0; i< v_fe.nbf(); i++)
                {
                                                                 // fetch the global dof related to i and v
                        index.first = dof.glob_dof(v_fe.dof(i));
                        for (unsigned int j=0; j< v_fe.nbf(); j++)
                        {
                                                                 // fetch the global dof related to j and p
                                index.second = dof.glob_dof(v_fe.dof(j));
                                                                 // compute the integrand
                                GiNaC::ex mass = inner(v_fe.N(i),v_fe.N(j));
                                                                 // compute the integral
                                GiNaC::ex Aij = domain.integrate(mass);
                                A[index] += Aij; // add to global matrix
                        }
                }

                // The term -(div u, q)
                for (unsigned int i=0; i< p_fe.nbf(); i++)
                {
                                                                 // fetch the global dof for p_i
                        index.first = dof.glob_dof(p_fe.dof(i));
                        for (unsigned int j=0; j< v_fe.nbf(); j++)
                        {
                                                                 // fetch the global dof for v_j
                                index.second=dof.glob_dof(v_fe.dof(j));
                                                                 // compute the integrand
                                GiNaC::ex divV= -p_fe.N(i)*div(v_fe.N(j));
                                                                 // compute the integral
                                GiNaC::ex Aij = domain.integrate(divV);
                                A[index] += Aij; // add to global matrix

                                // Do not need to compute the term (grad(p),v), since the system is
                                // symmetric we simply set Aji = Aij
                                index2.first = index.second;
                                index2.second = index.first;
                                A[index2] += Aij;
                        }
                }
        }
void SyFi::compute_Poisson_element_matrix ( FE &  fe,
Dof &  dof,
std::map< std::pair< unsigned int, unsigned int >, GiNaC::ex > &  A 
)

Definition at line 52 of file ElementComputations.cpp.

References SyFi::FE::dof(), SyFi::FE::get_polygon(), SyFi::Dof::glob_dof(), grad(), inner(), SyFi::Dof::insert_dof(), SyFi::Polygon::integrate(), SyFi::FE::N(), and SyFi::FE::nbf().

        {
                std::pair<unsigned int,unsigned int> index;

                // Insert the local degrees of freedom into the global Dof
                for (unsigned int i=0; i< fe.nbf(); i++)
                {
                        dof.insert_dof(1,i,fe.dof(i));
                }

                Polygon& domain = fe.get_polygon();

                // The term (grad u, grad v)
                for (unsigned int i=0; i< fe.nbf(); i++)
                {
                                                                 // fetch the global dof for Ni
                        index.first = dof.glob_dof(fe.dof(i));
                        for (unsigned int j=0; j< fe.nbf(); j++)
                        {
                                                                 // fetch the global dof for Nj
                                index.second = dof.glob_dof(fe.dof(j));
                                                                 // compute the integrand
                                GiNaC::ex nabla = inner(grad(fe.N(i)),
                                        grad(fe.N(j)));
                                                                 // compute the integral
                                GiNaC::ex Aij = domain.integrate(nabla);
                                A[index] += Aij; // add to global matrix
                        }
                }
        }
void SyFi::compute_Stokes_element_matrix ( FE &  v_fe,
FE &  p_fe,
Dof &  dof,
std::map< std::pair< unsigned int, unsigned int >, GiNaC::ex > &  A 
)

Definition at line 86 of file ElementComputations.cpp.

References div(), SyFi::FE::dof(), SyFi::FE::get_polygon(), SyFi::Dof::glob_dof(), grad(), inner(), SyFi::Dof::insert_dof(), SyFi::Polygon::integrate(), SyFi::FE::N(), and SyFi::FE::nbf().

Referenced by main().

        {
                std::pair<unsigned int,unsigned int> index;
                std::pair<unsigned int,unsigned int> index2;

                // FIXME: need to check that p_fe
                // contains the same domain
                Polygon& domain = v_fe.get_polygon();

                // Insert the local degrees of freedom into the global Dof
                for (unsigned int i=0; i< v_fe.nbf(); i++)
                {
                        dof.insert_dof(1,i,v_fe.dof(i));
                }
                for (unsigned int i=0; i< p_fe.nbf(); i++)
                {
                        dof.insert_dof(1,v_fe.nbf()+i,p_fe.dof(i));
                }

                // The term (grad u, grad v)
                for (unsigned int i=0; i< v_fe.nbf(); i++)
                {
                                                                 // fetch the global dof for v_i
                        index.first = dof.glob_dof(v_fe.dof(i));
                        for (unsigned int j=0; j< v_fe.nbf(); j++)
                        {
                                                                 // fetch the global dof for v_j
                                index.second = dof.glob_dof(v_fe.dof(j));
                                GiNaC::ex nabla = inner(grad(v_fe.N(i)),
                                        grad(v_fe.N(j)));// compute the integrand
                                                                 // compute the integral
                                GiNaC::ex Aij = domain.integrate(nabla);
                                A[index] += Aij; // add to global matrix
                        }
                }

                // The term -(div u, q)
                for (unsigned int i=0; i< p_fe.nbf(); i++)
                {
                                                                 // fetch the global dof for p_i
                        index.first = dof.glob_dof(p_fe.dof(i));
                        for (unsigned int j=0; j< v_fe.nbf(); j++)
                        {
                                                                 // fetch the global dof for v_j
                                index.second=dof.glob_dof(v_fe.dof(j));
                                                                 // compute the integrand
                                GiNaC::ex divV= -p_fe.N(i)*div(v_fe.N(j));
                                                                 // compute the integral
                                GiNaC::ex Aij = domain.integrate(divV);
                                A[index] += Aij; // add to global matrix

                                // Do not need to compute the term (grad(p),v), since the system is
                                // symmetric. We simply set Aji = Aij
                                index2.first = index.second;
                                index2.second = index.first;
                                A[index2] += Aij;
                        }
                }
        }
bool SyFi::contains2D ( Ptv e0,
Ptv e1,
Ptv p 
)

Definition at line 201 of file Ptv_tools.cpp.

References line_contains(), and Ptv::size().

        {

                if ( e0.size() != e1.size() || e0.size() != p.size()  )
                {
                        throw(std::logic_error("Exception from contains2D(Ptv&, Ptv&, Ptv&): The dimentions of a and b must be the same."));
                }

                bool b = line_contains(e0, e1, p);

                return b;
        }
bool SyFi::contains3D ( Ptv e0,
Ptv e1,
Ptv e2,
Ptv p 
)

Definition at line 214 of file Ptv_tools.cpp.

References is_equal(), is_inside_triangle(), and line_contains().

        {

                // check if p is either e0, e1, or e2
                if ( is_equal(e0, p) )  return true;
                else if ( is_equal(e1, p) )  return true;
                else if ( is_equal(e2, p) )  return true;

                // check if p is on the lines connecting e0, e1, and e2
                if ( line_contains(e0, e1, p) ) return true;
                else if ( line_contains(e1, e2, p) ) return true;
                else if ( line_contains(e2, e1, p) ) return true;

                // check if p is inside the triangle with verticies e0, e1, and e2
                if ( is_inside_triangle(e0, e1, e2, p) ) return true;

                return false;

        }
ExStats SyFi::count_ops ( const GiNaC::ex &  e)
ExStats SyFi::count_ops ( const ex &  e)

Definition at line 1378 of file ginac_tools.cpp.

References SyFi::ExStatsVisitor::es, and test_syfi::debug::v.

Referenced by main(), and print().

{
        //cout << "count_ops " << e << endl;
        //cout << "is an add: " << GiNaC::is<GiNaC::add>(e) << endl;
        //cout << "is a  mul: " << GiNaC::is<GiNaC::mul>(e) << endl;
        ExStatsVisitor v;
        e.traverse(v);
        return v.es;
}
GiNaC::exhashmap<int> SyFi::count_symbols ( const GiNaC::ex &  e)
exhashmap<int> SyFi::count_symbols ( const ex &  e)

Definition at line 1167 of file ginac_tools.cpp.

References SyFi::SymbolCounterVisitor::symbolcount, and test_syfi::debug::v.

Referenced by print().

{
        SymbolCounterVisitor v;
        e.traverse(v);
        return v.symbolcount;
}
GiNaC::lst SyFi::cross ( GiNaC::lst &  v1,
GiNaC::lst &  v2 
)

Definition at line 34 of file ginac_tools.cpp.

Referenced by barycenter_triangle(), SyFi::Nedelec::compute_basis_functions(), line_contains(), and normal().

        {
                GiNaC::lst ret;
                if ( v1.nops() != v2.nops() )
                {
                        cout <<"incompatible vectors "<<endl;
                        cout <<"v1.nops() "<<v1.nops();
                        cout <<"  v2.nops() "<<v2.nops()<<endl; ;
                        return GiNaC::lst();
                }
                ret.append(  v1.op(1)*v2.op(2) - v1.op(2)*v2.op(1));
                ret.append(- v1.op(0)*v2.op(2) + v1.op(2)*v2.op(0));
                ret.append(  v1.op(0)*v2.op(1) - v1.op(1)*v2.op(0));
                return ret;
        }
void SyFi::cross ( const Ptv a,
const Ptv b,
Ptv c 
)

Definition at line 104 of file Ptv_tools.cpp.

References Ptv::redim(), and Ptv::size().

        {
                if ( a.size() != b.size() )
                {
                        throw(std::logic_error("Exception from cross (const Ptv&, const Ptv&, Ptv&): The dimentions of a and b must be the same."));
                }

                if ( a.size() == 2 )
                {
                        c.redim(1);
                        c[0] = a[0]*b[1] - a[1]*b[0];
                }

                else if ( a.size() == 3 )
                {
                        c.redim(3);
                        c[0] =   a[1]*b[2] - b[1]*a[2];
                        c[1] = - a[0]*b[2] + b[0]*a[2];
                        c[2] =   a[0]*b[1] - b[0]*a[1];
                }

                else
                {
                        throw(std::logic_error("The cross product can only be computed in 2D and 3D."));
                }

        }
int SyFi::dirac ( unsigned int  i,
unsigned int  j 
)

Definition at line 34 of file utilities.cpp.

Referenced by SyFi::CrouzeixRaviart::compute_basis_functions(), and main().

        {
                if (i==j) return 1;
                else return 0;
        }
GiNaC::ex SyFi::div ( GiNaC::ex  v)

Definition at line 45 of file diff_tools.cpp.

References test_syfi::debug::c, nsd, test_syfi::debug::v, x, y, and z.

Referenced by SyFi::Robust::compute_basis_functions(), SyFi::Robust::compute_basis_functions_old(), compute_mixed_Poisson_element_matrix(), compute_Stokes_element_matrix(), div(), and main().

        {
                using SyFi::nsd;
                using SyFi::x;
                using SyFi::y;
                using SyFi::z;

                GiNaC::ex ret;
                if (GiNaC::is_a<GiNaC::matrix>(v))
                {
                        GiNaC::matrix m = GiNaC::ex_to<GiNaC::matrix>(v);
                        if ( m.cols() == 1 && m.rows() == nsd )
                        {
                                if (nsd == 1)
                                {
                                        ret = diff(m,x);
                                }
                                else if (nsd == 2)
                                {
                                        ret = diff(m.op(0),x) + diff(m.op(1),y) ;
                                }
                                else if (nsd == 3)
                                {
                                        ret = diff(m.op(0),x) + diff(m.op(1),y) + diff(m.op(2),z) ;
                                }
                                else
                                {
                                        throw std::runtime_error("Invalid nsd");
                                }

                        }
                        else
                        {
                                GiNaC::matrix retm = GiNaC::matrix(m.cols(),1);
                                if ( nsd != m.rows() )
                                {
                                        throw(std::invalid_argument("The number of rows must equal nsd."));
                                }
                                GiNaC::symbol xr;
                                GiNaC::ex tmp;
                                for (unsigned int c=0; c<m.cols(); c++)
                                {
                                        for (unsigned int r=0; r<m.rows(); r++)
                                        {
                                                if (r+1 == 1) xr = x;
                                                if (r+1 == 2) xr = y;
                                                if (r+1 == 3) xr = z;
                                                retm(c,0) += diff(m(c,r), xr);
                                        }
                                }
                                ret = retm;
                        }
                        return ret;

                }
                else if (GiNaC::is_a<GiNaC::lst>(v))
                {
                        GiNaC::lst l = GiNaC::ex_to<GiNaC::lst>(v);
                        return div(l);
                }
                throw std::invalid_argument("v must be a matrix or lst.");
        }
GiNaC::ex SyFi::div ( GiNaC::ex  v,
GiNaC::ex  G 
)

Definition at line 108 of file diff_tools.cpp.

References div(), nsd, test_syfi::debug::v, x, y, and z.

        {
                using SyFi::nsd;
                using SyFi::x;
                using SyFi::y;
                using SyFi::z;

                GiNaC::ex ret;
                if (GiNaC::is_a<GiNaC::matrix>(v) && GiNaC::is_a<GiNaC::matrix>(G))
                {
                        GiNaC::matrix m = GiNaC::ex_to<GiNaC::matrix>(v);
                        GiNaC::matrix GG = GiNaC::ex_to<GiNaC::matrix>(G);
                        if ( m.cols() == 1 && m.rows() == nsd && GG.rows() == nsd && GG.cols() == nsd )
                        {
                                if ( nsd == 1 || nsd == 2 || nsd == 3)
                                {
                                        ret = GiNaC::numeric(0);
                                        GiNaC::symbol xj;
                                        for (unsigned int i=0; i< nsd; i++)
                                        {
                                                for (unsigned int j=0; j< nsd; j++)
                                                {
                                                        if (j == 0) xj = x;
                                                        if (j == 1) xj = y;
                                                        if (j == 2) xj = z;
                                                        ret += m.op(i).diff(xj)*GG(i,j);
                                                }
                                        }
                                }
                                else
                                {
                                        throw std::runtime_error("Invalid nsd");
                                }
                        }
                        else
                        {
                                throw std::invalid_argument("This functions needs v and G on the form: v.cols()=1, v.rows()=G.rows()=G.cols()=nsd.");
                        }
                }
                else if (GiNaC::is_a<GiNaC::lst>(v))
                {
                        GiNaC::lst l = GiNaC::ex_to<GiNaC::lst>(v);
                        return div(l,G);
                }
                else
                {
                        throw std::invalid_argument("v must be a matrix or lst.");
                }
                return ret;
        }
GiNaC::ex SyFi::div ( GiNaC::lst &  v)

Definition at line 159 of file diff_tools.cpp.

References nsd, x, y, and z.

        {
                using SyFi::x;
                using SyFi::y;
                using SyFi::z;

                using SyFi::nsd;
                nsd = v.nops();
                GiNaC::ex ret;
                if (nsd == 1)
                {
                        ret = v.op(0).diff(x);
                }
                else if (nsd == 2)
                {
                        ret = v.op(0).diff(x) + v.op(1).diff(y);
                }
                else if (nsd == 3)
                {
                        ret = v.op(0).diff(x) + v.op(1).diff(y) + v.op(2).diff(z);
                }
                return ret;
        }
GiNaC::ex SyFi::div ( GiNaC::lst &  v,
GiNaC::ex  G 
)

Definition at line 183 of file diff_tools.cpp.

References nsd, x, y, and z.

        {
                using SyFi::x;
                using SyFi::y;
                using SyFi::z;

                using SyFi::nsd;
                nsd = v.nops();
                GiNaC::ex ret;
                if (GiNaC::is_a<GiNaC::matrix>(G))
                {
                        GiNaC::matrix GG = GiNaC::ex_to<GiNaC::matrix>(G);
                        if ( nsd != GG.cols() || nsd != GG.rows())
                        {
                                throw(std::invalid_argument("The number of rows and cols in G must equal the size of v."));
                        }
                        if (nsd == 1 || nsd == 2 || nsd == 3 )
                        {
                                GiNaC::symbol xj;
                                ret = GiNaC::numeric(0);
                                for (unsigned int i=0; i< nsd; i++)
                                {
                                        for (unsigned int j=0; j< nsd; j++)
                                        {
                                                if (i == 0) xj = x;
                                                if (i == 1) xj = y;
                                                if (i == 2) xj = z;
                                                ret += v.op(i).diff(xj)*GG(i,j);
                                        }
                                }
                        }
                        else
                        {
                                throw std::runtime_error("Invalid nsd");
                        }
                }
                else
                {
                        throw std::invalid_argument("v must be a matrix.");
                }
                return ret;
        }
GiNaC::ex SyFi::div ( GiNaC::exvector &  v)

Definition at line 226 of file diff_tools.cpp.

References nsd, x, y, and z.

        {
                using SyFi::nsd;
                using SyFi::x;
                using SyFi::y;
                using SyFi::z;

                GiNaC::ex ret;
                if (nsd == 2)
                {
                        ret = v[0].diff(x) + v[1].diff(y);
                }
                else if (nsd == 3)
                {
                        ret = v[0].diff(x) + v[1].diff(y) + v[2].diff(z);
                }
                return ret;
        }
GiNaC::symbol SyFi::DUMMY ( "(DUMMY is not initialized since initSyFi has never been called)"  )
void SyFi::EQUAL_OR_DIE ( const GiNaC::ex &  e,
const std::string &  s 
)
void SyFi::EQUAL_OR_DIE ( const ex &  e,
const string &  s 
)

Definition at line 1095 of file ginac_tools.cpp.

References compare().

Referenced by main().

{
        if (!compare(e, s))
        {
                ostringstream os;
                os << "ERROR: expression e: " <<e<<" is not equal to "<<s<<endl;
                throw runtime_error(os.str());
        }
}
GiNaC::matrix SyFi::equations2matrix ( const GiNaC::ex &  eqns,
const GiNaC::ex &  symbols 
)

Definition at line 238 of file ginac_tools.cpp.

References test_syfi::debug::c.

        {

                GiNaC::matrix sys(eqns.nops(),symbols.nops());
                GiNaC::matrix rhs(eqns.nops(),1);
                GiNaC::matrix vars(symbols.nops(),1);

                for (size_t r=0; r<eqns.nops(); r++)
                {
                                                                 // lhs-rhs==0
                        const GiNaC::ex eq = eqns.op(r).op(0)-eqns.op(r).op(1);
                        GiNaC::ex linpart = eq;
                        for (size_t c=0; c<symbols.nops(); c++)
                        {
                                const GiNaC::ex co = eq.coeff(GiNaC::ex_to<GiNaC::symbol>(symbols.op(c)),1);
                                linpart -= co*symbols.op(c);
                                sys(r,c) = co;
                        }
                        linpart = linpart.expand();
                        rhs(r,0) = -linpart;
                }
                return sys;
        }
GiNaC::lst SyFi::ex2equations ( GiNaC::ex  rel)

Definition at line 187 of file ginac_tools.cpp.

References x, y, and z.

        {
                GiNaC::ex lhs = rel.lhs();
                GiNaC::ex rhs = rel.rhs();

                GiNaC::ex l;
                GiNaC::ex r;

                GiNaC::lst eqs;

                for (int i=lhs.ldegree(x); i<=lhs.degree(x); ++i)
                {
                        for (int j=lhs.ldegree(y); j<=lhs.degree(y); ++j)
                        {
                                for (int k=lhs.ldegree(z); k<=lhs.degree(z); ++k)
                                {
                                        l = lhs.coeff(x,i).coeff(y, j).coeff(z,k);
                                        r = rhs.coeff(x,i).coeff(y, j).coeff(z,k);
                                        //      if (! (l == 0 && r == 0 ) )  eqs.append(l == r); OLD VERSION
                                        if ( (l != 0 && (r == 0 || r == 1) ) )  eqs.append(l == r);
                                }
                        }
                }
                eqs.sort();
                return eqs;
        }
GiNaC::ex SyFi::extract_symbols ( const GiNaC::ex &  e)
ex SyFi::extract_symbols ( const ex &  e)

Definition at line 1215 of file ginac_tools.cpp.

References SyFi::SymbolCounterVisitor::symbolcount, and test_syfi::debug::v.

Referenced by compare_archives().

{
        // Implemented directly to avoid copying map:
        SymbolCounterVisitor v;
        e.traverse(v);
        exhashmap<int> & sc = v.symbolcount;

        lst l;
        for(exhashmap<int>::iterator it=sc.begin(); it!=sc.end(); it++)
        {
                l.append(it->first);
                std::cout << (it->first) << std::endl;
        }
        ex ret = l;
        return ret;
}
string SyFi::exvector2string ( GiNaC::exvector &  v)

Definition at line 77 of file utilities.cpp.

        {
                ostringstream s;
                s <<"[";
                for (unsigned int i=0; i< v.size()-1; i++)
                {
                        s <<v[i]<<",";
                }
                s<<v[v.size()-1]<< "]";
                return s.str();
        }
int SyFi::find ( GiNaC::ex  e,
GiNaC::lst  list 
)

Definition at line 390 of file ginac_tools.cpp.

Referenced by check_visitor().

{
        for (unsigned int i=0; i< list.nops(); i++)
        {
                if ( e == list.op(i) ) return i;
        }
        return -1;
}
const GiNaC::symbol& SyFi::get_symbol ( const std::string &  name)
const symbol& SyFi::get_symbol ( const string &  name)

Definition at line 123 of file syfi/symbol_factory.cpp.

References symbol_collection.

Referenced by initSyFi(), isymb(), main(), pickExpression(), and replace_powers().

        {
                map<string, symbol>::iterator i = symbol_collection.find(name);
                if( i != symbol_collection.end() )
                {
                        return i->second;
                }
                return symbol_collection.insert(make_pair(name, symbol(name))).first->second;
        }
GiNaC::ex SyFi::get_symbolic_matrix ( int  m,
int  n,
const std::string &  basename 
)

Definition at line 154 of file syfi/symbol_factory.cpp.

References isymb().

Referenced by bernstein(), homogenous_pol(), lagrange(), lagrangev(), legendre(), main(), pol(), and polb().

        {
                GiNaC::matrix A(m,n);
                for(int i=0; i<m; i++)
                {
                        for(int j=0; j<n; j++)
                        {
                                A.set(i, j, isymb(basename, i,j));
                        }
                }
                GiNaC::ex e = A;
                return e;
        }
GiNaC::ex SyFi::get_symbolic_vector ( int  m,
const std::string &  basename 
)

Definition at line 143 of file syfi/symbol_factory.cpp.

References isymb().

Referenced by barycenter(), initSyFi(), main(), and SyFi::Simplex::repr().

        {
                GiNaC::matrix A(m,1);
                for(int i=0; i<m; i++)
                {
                        A.set(i, 0, isymb(basename, i));
                }
                GiNaC::ex e = A;
                return e;
        }
GiNaC::ex SyFi::grad ( GiNaC::ex  f)

Definition at line 245 of file diff_tools.cpp.

References run_tests::f, nsd, x, y, and z.

Referenced by compute_nlconvdiff_element_matrix(), compute_Poisson_element_matrix(), compute_poisson_element_matrix(), compute_Poisson_element_matrix(), compute_Stokes_element_matrix(), example_of_use(), main(), and usage().

        {
                using SyFi::nsd;
                using SyFi::x;
                using SyFi::y;
                using SyFi::z;

                if (GiNaC::is_a<GiNaC::matrix>(f))
                {
                        GiNaC::matrix m = GiNaC::ex_to<GiNaC::matrix>(f);
                        GiNaC::matrix ret_m(nsd,m.rows());
                        for (unsigned int r=0; r< m.rows(); r++)
                        {
                                if (nsd == 1)
                                {
                                        //         ret_m(0,r) = diff(m.op(r),x);
                                        return diff(f, x);
                                }
                                else if ( nsd == 2)
                                {
                                        ret_m(0,r) = diff(m.op(r),x);
                                        ret_m(1,r) = diff(m.op(r),y);
                                }
                                else if ( nsd == 3)
                                {
                                        ret_m(0,r) = diff(m.op(r),x);
                                        ret_m(1,r) = diff(m.op(r),y);
                                        ret_m(2,r) = diff(m.op(r),z);
                                }
                        }
                        return ret_m;
                }
                else
                {

                        if (nsd == 1)
                        {
                                //      return GiNaC::matrix(nsd,1,GiNaC::lst(diff(f,x)));
                                return diff(f,x);
                        }
                        else if ( nsd == 2)
                        {
                                return GiNaC::matrix(nsd,1,GiNaC::lst(diff(f,x), diff(f,y)));
                        }
                        else if ( nsd == 3)
                        {
                                return GiNaC::matrix(nsd,1,GiNaC::lst(diff(f,x), diff(f,y), diff(f,z)));
                        }
                        else
                        {
                                throw(std::invalid_argument("nsd must be either 1, 2, or 3."));
                                return GiNaC::matrix();
                        }
                }
        }
GiNaC::ex SyFi::grad ( GiNaC::ex  f,
GiNaC::ex  G 
)

Definition at line 301 of file diff_tools.cpp.

References test_syfi::debug::c, run_tests::f, nsd, x, y, and z.

        {
                using SyFi::nsd;
                using SyFi::x;
                using SyFi::y;
                using SyFi::z;

                GiNaC::symbol xr;
                if ( GiNaC::is_a<GiNaC::matrix>(G))
                {
                        GiNaC::matrix GG = GiNaC::ex_to<GiNaC::matrix>(G);

                        if (! (GG.rows() == nsd && GG.cols() == nsd ))
                        {
                                throw(std::invalid_argument("The number of cols/rows in G must equal nsd."));
                        }

                        if (GiNaC::is_a<GiNaC::matrix>(f) )
                        {
                                GiNaC::matrix m = GiNaC::ex_to<GiNaC::matrix>(f);
                                GiNaC::matrix ret_m(nsd,m.rows());
                                for (unsigned int k=0; k< m.rows(); k++)
                                {
                                        for (unsigned int c=0; c<nsd; c++)
                                        {
                                                for (unsigned int r=0; r<nsd; r++)
                                                {
                                                        if (r == 0) xr = x;
                                                        if (r == 1) xr = y;
                                                        if (r == 2) xr = z;
                                                        ret_m(c,k) += diff(f,xr)*GG(r,c);
                                                }
                                        }
                                }

                                return ret_m;
                        }
                        else
                        {
                                GiNaC::matrix ret_m(nsd,1);
                                for (unsigned int c=0; c<nsd; c++)
                                {
                                        for (unsigned int r=0; r<nsd; r++)
                                        {
                                                if (r == 0) xr = x;
                                                if (r == 1) xr = y;
                                                if (r == 2) xr = z;
                                                ret_m(c,0) += diff(f,xr)*GG(r,c);
                                        }
                                }
                                return ret_m;
                        }
                }
                else
                {
                        throw(std::invalid_argument("G must be a matrix."));
                }
        }
GiNaC::ex SyFi::homogenous_pol ( unsigned int  order,
unsigned int  nsd,
const std::string  a 
)
GiNaC::ex SyFi::homogenous_pol ( unsigned int  order,
unsigned int  nsd,
const string  a 
)

Definition at line 534 of file ginac_tools.cpp.

References get_symbolic_matrix(), istr(), matrix_to_lst2(), x, y, and z.

Referenced by homogenous_polv(), and main().

{
        using SyFi::x;
        using SyFi::y;
        using SyFi::z;

        if ( nsd == 1)
        {
                GiNaC::symbol a0(istr(a,0));
                return GiNaC::lst(a0*pow(x,order), a0, pow(x,order));
        }
        else if ( nsd == 2 )
        {
                GiNaC::ex variables = get_symbolic_matrix(1,order+1, a);
                GiNaC::lst basis;
                GiNaC::ex ret;
                for (unsigned int i=0; i<= order; i++)
                {
                        basis.append(pow(x,i)*pow(y,order-i));
                        ret += variables.op(i)*basis.op(i);
                }
                return GiNaC::lst(ret, matrix_to_lst2(variables), basis);
        }
        else if ( nsd == 3 )
        {
                GiNaC::lst basis;
                for (unsigned int i=0; i<= order; i++)
                {
                        for (unsigned int j=0; j<= order; j++)
                        {
                                for (unsigned int k=0; k<= order; k++)
                                {
                                        if ( i + j + k == order )
                                        {
                                                basis.append(pow(x,i)*pow(y,j)*pow(z,k));
                                        }
                                }
                        }
                }
                GiNaC::ex variables = get_symbolic_matrix(1,basis.nops(), a);
                GiNaC::ex ret;
                for (unsigned int i=0; i<basis.nops(); i++)
                {
                        ret += variables.op(i)*basis.op(i);
                }
                return GiNaC::lst(ret, matrix_to_lst2(variables), basis);
        }
        throw std::runtime_error("Homogenous polynomials only implemented in 1D, 2D and 3D");
}
GiNaC::lst SyFi::homogenous_polv ( unsigned int  no_fields,
unsigned int  order,
unsigned int  nsd,
const std::string  a 
)
GiNaC::lst SyFi::homogenous_polv ( unsigned int  no_fields,
unsigned int  order,
unsigned int  nsd,
const string  a 
)

Definition at line 585 of file ginac_tools.cpp.

References homogenous_pol().

Referenced by SyFi::Nedelec::compute_basis_functions(), and SyFi::Nedelec2Hdiv::compute_basis_functions().

{
        GiNaC::lst ret1;                         // contains the polynom
        GiNaC::lst ret2;                         // contains the coefficients
        GiNaC::lst ret3;                         // constains the basis functions
        GiNaC::lst basis_tmp;
        for (unsigned int i=0; i< no_fields; i++)
        {
                GiNaC::lst basis;
                std::ostringstream s;
                s <<a<<""<<i<<"_";
                GiNaC::ex polspace = homogenous_pol(order, nsd, s.str());
                ret1.append(polspace.op(0));
                ret2.append(polspace.op(1));
                basis_tmp = GiNaC::ex_to<GiNaC::lst>(polspace.op(2));
                for (GiNaC::lst::const_iterator basis_iterator = basis_tmp.begin();
                        basis_iterator != basis_tmp.end(); ++basis_iterator)
                {
                        GiNaC::lst tmp_lst;
                        for (unsigned int d=1; d<=no_fields; d++) tmp_lst.append(0);
                        tmp_lst.let_op(i) = (*basis_iterator);
                        ret3.append(tmp_lst);
                }
        }
        return GiNaC::lst(ret1,ret2,ret3);
}
GiNaC::symbol SyFi::infinity ( "(infinity is not initialized since initSyFi has never been called)"  )
void SyFi::initSyFi ( unsigned int  nsd_)

Definition at line 46 of file syfi/symbol_factory.cpp.

References DUMMY, get_symbol(), get_symbolic_vector(), infinity, nsd, p, t, x, y, and z.

Referenced by check_CrouzeixRaviart(), check_RaviartThomas(), and main().

        {
                // initSyFi uses the global coordinates x      for nsd == 1
                // initSyFi uses the global coordinates x,y    for nsd == 2
                // initSyFi uses the global coordinates x,y,z  for nsd == 3
                // when nsd > 3 the coordinates can be found in the p, which is of type lst

                // FIXME: this whole thing is just a mess, but it's a nontrivial job to fix it all over syfi...

                SyFi::nsd      = nsd_;
                SyFi::t        = get_symbol("t");

                SyFi::infinity = get_symbol("infinity");
                SyFi::DUMMY    = get_symbol("DUMMY");

                SyFi::x        = get_symbol("(SyFi::x is not initialized)");
                SyFi::y        = get_symbol("(SyFi::y is not initialized)");
                SyFi::z        = get_symbol("(SyFi::z is not initialized)");

                /*
                std::cout << "SyFi::p before remove_all:" << std::endl;
                std::cout << SyFi::p << std::endl;
                */

                SyFi::p.remove_all();

                /*
                std::cout << "SyFi::p after remove_all:" << std::endl;
                std::cout << SyFi::p << std::endl;
                */

                if ( nsd  > 3 )
                {
                        SyFi::x = get_symbol("(SyFi::x is an invalid symbol when nsd>3)");
                        SyFi::y = get_symbol("(SyFi::y is an invalid symbol when nsd>3)");
                        SyFi::z = get_symbol("(SyFi::z is an invalid symbol when nsd>3)");

                        ex tmp = get_symbolic_vector(nsd, "x");
                        for (unsigned int i=0; i<tmp.nops(); i++)
                        {
                                p.append(tmp.op(i));
                        }
                }
                else
                {
                        if ( nsd  > 0 )
                        {
                                SyFi::x = get_symbol("x");
                                SyFi::p.append(SyFi::x);
                        }
                        if ( nsd  > 1 )
                        {
                                SyFi::y = get_symbol("y");
                                SyFi::p.append(SyFi::y);
                        }
                        if ( nsd  > 2 )
                        {
                                SyFi::z = get_symbol("z");
                                SyFi::p.append(SyFi::z);
                        }
                }

                /*
                std::cout << "SyFi::p at end of initSyFi:" << std::endl;
                std::cout << SyFi::p << std::endl;
                */
        }
GiNaC::ex SyFi::inner ( GiNaC::ex  a,
GiNaC::ex  b,
bool  transposed 
)

Definition at line 50 of file ginac_tools.cpp.

Referenced by SyFi::Nedelec::compute_basis_functions(), SyFi::Nedelec2Hdiv::compute_basis_functions(), SyFi::BrezziDouglasMarini::compute_basis_functions(), SyFi::RaviartThomas::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), SyFi::Robust::compute_basis_functions_old(), compute_mixed_Poisson_element_matrix(), compute_nlconvdiff_element_matrix(), compute_poisson_element_matrix(), compute_Poisson_element_matrix(), compute_Poisson_element_matrix(), compute_Stokes_element_matrix(), inner(), and main().

        {
                if (GiNaC::is_a<GiNaC::matrix>(a) && GiNaC::is_a<GiNaC::matrix>(b))
                {
                        GiNaC::matrix ma = GiNaC::ex_to<GiNaC::matrix>(a);
                        GiNaC::matrix mb = GiNaC::ex_to<GiNaC::matrix>(b);
                        if ( !transposed )
                        {
                                if (ma.cols() != mb.cols() || ma.rows() != mb.rows() )
                                {
                                        cout <<"Incompatible matrices "<<endl;
                                        cout <<"a.cols() "<<ma.cols()<<endl;
                                        cout <<"a.rows() "<<ma.rows()<<endl;
                                        cout <<"b.cols() "<<mb.cols()<<endl;
                                        cout <<"b.rows() "<<mb.rows()<<endl;
                                        cout <<"a="<<a<<endl;
                                        cout <<"b="<<b<<endl;
                                        throw std::runtime_error("Incompatible matrices.");
                                }

                                GiNaC::ex ret;
                                for (unsigned int i=0; i<ma.rows(); i++)
                                {
                                        for (unsigned int j=0; j<ma.cols(); j++)
                                        {
                                                ret += ma(i,j)*mb(i,j);
                                        }
                                }
                                return ret;
                        }
                        else
                        {
                                if (ma.cols() != mb.rows() || ma.rows() != mb.cols() )
                                {
                                        cout <<"Incompatible matrices "<<endl;
                                        cout <<"a.cols() "<<ma.cols()<<endl;
                                        cout <<"a.rows() "<<ma.rows()<<endl;
                                        cout <<"b.cols() "<<mb.cols()<<endl;
                                        cout <<"b.rows() "<<mb.rows()<<endl;
                                        cout <<"a="<<a<<endl;
                                        cout <<"b="<<b<<endl;
                                        throw std::runtime_error("Incompatible matrices.");
                                }

                                GiNaC::ex ret;
                                for (unsigned int i=0; i<ma.rows(); i++)
                                {
                                        for (unsigned int j=0; j<ma.cols(); j++)
                                        {
                                                ret += ma(i,j)*mb(j,i);
                                        }
                                }
                                return ret;
                        }
                }
                else if (GiNaC::is_a<GiNaC::lst>(a)
                        && GiNaC::is_a<GiNaC::lst>(b))
                {
                        return inner(GiNaC::ex_to<GiNaC::lst>(a), GiNaC::ex_to<GiNaC::lst>(b));
                }
                else
                {
                        return a*b;
                }
        }
GiNaC::ex SyFi::inner ( GiNaC::lst  v1,
GiNaC::lst  v2 
)

Definition at line 116 of file ginac_tools.cpp.

References inner().

        {
                GiNaC::ex ret;

                if ( v1.nops() != v2.nops() )
                {
                        cout <<"incompatible vectors "<<endl;
                        cout <<"v1.nops() "<<v1.nops();
                        cout <<"  v2.nops() "<<v2.nops()<<endl; ;
                        return 0;
                }
                for (unsigned i = 0; i <= v1.nops()-1 ; ++i)
                {
                        if ( GiNaC::is_a<GiNaC::lst>(v1.op(i)) &&
                                GiNaC::is_a<GiNaC::lst>(v2.op(i)) )
                        {
                                ret += inner(GiNaC::ex_to<GiNaC::lst>(v1.op(i)),
                                        GiNaC::ex_to<GiNaC::lst>(v2.op(i)));
                        }
                        else
                        {
                                ret += v1.op(i)*v2.op(i);
                        }
                }
                return ret;
        }
GiNaC::ex SyFi::inner ( GiNaC::exvector &  v1,
GiNaC::exvector &  v2 
)

Definition at line 143 of file ginac_tools.cpp.

        {
                GiNaC::ex ret;
                for (unsigned int i=0; i< v1.size(); i++)
                {
                        ret += v1[i]*v2[i];
                }
                return ret;
        }
std::string SyFi::int2string ( int  i)

Definition at line 40 of file utilities.cpp.

Referenced by replace_powers().

        {
                ostringstream os;
                os << i;
                return os.str();
        }
GiNaC::lst SyFi::interior_coordinates ( Tetrahedron &  tetrahedra,
unsigned int  d 
)

Definition at line 1434 of file Polygon.cpp.

References lst_to_matrix2(), matrix_to_lst2(), and SyFi::Polygon::vertex().

Referenced by SyFi::BrezziDouglasMarini::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), and SyFi::RaviartThomas::compute_basis_functions().

        {

                //FIXME: ugly conversion to matrix
                d = d+4;

                lst ret;
                ex V1 = tetrahedra.vertex(0);
                ex V2 = tetrahedra.vertex(1);
                ex V3 = tetrahedra.vertex(2);
                ex V4 = tetrahedra.vertex(3);

                lst V1l = ex_to<lst>(V1);
                lst V2l = ex_to<lst>(V2);
                lst V3l = ex_to<lst>(V3);
                lst V4l = ex_to<lst>(V4);

                ex V1m  = lst_to_matrix2(V1l);
                ex V2m  = lst_to_matrix2(V2l);
                ex V3m  = lst_to_matrix2(V3l);
                ex V4m  = lst_to_matrix2(V4l);

                int l;
                for (unsigned int i=1; i< d; i++)
                {
                        for (unsigned int j=1; j< d; j++)
                        {
                                for (unsigned int k=1; k< d; k++)
                                {
                                        if ( int(d) - int(i) - int(j) - int(k)  >= 1 )
                                        {
                                                l= int(d) - int(i) - int(j) - int(k);
                                                ex sum = (l*V1m + k*V2m + j*V3m + i*V4m)/d;
                                                ret.append(matrix_to_lst2(sum.evalm()));
                                        }
                                }
                        }
                }
                // FIXME how should these be sorted ?????
                //  ret = ret.sort();
                return ret;
        }
GiNaC::lst SyFi::interior_coordinates ( Triangle &  triangle,
unsigned int  d 
)

Definition at line 1513 of file Polygon.cpp.

References lst_to_matrix2(), matrix_to_lst2(), and SyFi::Polygon::vertex().

        {

                //FIXME: ugly conversion to matrix
                //
                d=d+3;

                lst ret;
                ex V1 = triangle.vertex(0);
                ex V2 = triangle.vertex(1);
                ex V3 = triangle.vertex(2);

                lst V1l = ex_to<lst>(V1);
                lst V2l = ex_to<lst>(V2);
                lst V3l = ex_to<lst>(V3);

                ex V1m  = lst_to_matrix2(V1l);
                ex V2m  = lst_to_matrix2(V2l);
                ex V3m  = lst_to_matrix2(V3l);

                int k;
                for (unsigned int i=1; i < d; i++)
                {
                        for (unsigned int j=1; j < d; j++)
                        {
                                if ( int(d) - int(i) - int(j) >= 1  )
                                {
                                        k = d - i - j;
                                        ex sum = (k*V1m + j*V2m + i*V3m)/d;
                                        ret.append(matrix_to_lst2(sum.evalm()));
                                }
                        }
                }
                // FIXME how should these be sorted ?????
                // ret = ret.sort();
                return ret;
        }
GiNaC::lst SyFi::interior_coordinates ( Line &  line,
unsigned int  d 
)

Definition at line 1592 of file Polygon.cpp.

References lst_to_matrix2(), matrix_to_lst2(), and SyFi::Polygon::vertex().

        {

                //FIXME: ugly conversion to matrix
                d = d+2;

                lst ret;
                ex V1 = line.vertex(0);
                ex V2 = line.vertex(1);

                lst V1l = ex_to<lst>(V1);
                lst V2l = ex_to<lst>(V2);

                ex V1m  = lst_to_matrix2(V1l);
                ex V2m  = lst_to_matrix2(V2l);

                int k;
                for (unsigned int i=1; i < d; i++)
                {
                        k = d - i;
                        ex sum = (k*V1m + i*V2m)/d;
                        ret.append(matrix_to_lst2(sum.evalm()));
                }
                // FIXME how should these be sorted ?????
                // ret = ret.sort();
                return ret;
        }
bool SyFi::is_equal ( Ptv a,
Ptv b 
)

Definition at line 132 of file Ptv_tools.cpp.

References Ptv::size(), and Ptv::tol.

Referenced by contains3D(), and line_contains().

        {
                if (a.size() != b.size()) return false;

                for (unsigned int i=0; i < a.size(); i++ )
                {
                        if ( fabs( a[i] - b[i]) > Ptv::tol )
                        {
                                return false;
                        }
                }

                return true;
        }
bool SyFi::is_inside_triangle ( Ptv e0,
Ptv e1,
Ptv e2,
Ptv p 
)

Definition at line 174 of file Ptv_tools.cpp.

References mul(), normalize(), sub(), and Ptv::tol.

Referenced by contains3D().

        {

                Ptv n0;
                sub(e0, p, n0);
                normalize(n0);

                Ptv n1;
                sub(e1, p, n1);
                normalize(n1);

                Ptv n2;
                sub(e2, p, n2);
                normalize(n2);

                double c0 = acos(mul(n0,n1));
                double c1 = acos(mul(n1,n2));
                double c2 = acos(mul(n2,n1));

                if ( fabs(c0 + c1 + c2 - 2*3.1415926535897931) < Ptv::tol) return true;

                return false;
        }
std::string SyFi::istr ( const std::string &  a,
int  b 
)
std::string SyFi::istr ( const std::string &  a,
int  b,
int  c 
)
string SyFi::istr ( const string &  a,
int  b,
int  c 
)

Definition at line 54 of file utilities.cpp.

References test_syfi::debug::c.

        {
                ostringstream s;
                s << a << b << "_" <<c;
                return s.str();
        }
const GiNaC::symbol& SyFi::isymb ( const std::string &  a,
int  b 
)
const GiNaC::symbol& SyFi::isymb ( const std::string &  a,
int  b,
int  c 
)
const symbol& SyFi::isymb ( const string &  a,
int  b 
)

Definition at line 133 of file syfi/symbol_factory.cpp.

References get_symbol(), and istr().

Referenced by get_symbolic_matrix(), get_symbolic_vector(), and main().

        {
                return get_symbol(istr(a,b));
        }
const symbol& SyFi::isymb ( const string &  a,
int  b,
int  c 
)

Definition at line 138 of file syfi/symbol_factory.cpp.

References get_symbol(), and istr().

        {
                return get_symbol(istr(a,b,c));
        }
GiNaC::ex SyFi::lagrange ( unsigned int  order,
Polygon &  p,
const std::string &  a 
)

Definition at line 528 of file Lagrange.cpp.

References get_symbolic_matrix(), matrix_to_lst2(), SyFi::StandardFE::N(), and SyFi::StandardFE::nbf().

        {
                if ( order < 1 )
                {
                        throw(std::logic_error("Can not create polynomials of order less than 1!"));
                }

                GiNaC::ex A;
                GiNaC::ex ret;
                GiNaC::lst basis;

                Lagrange fe(p,order);
                A = get_symbolic_matrix(1, fe.nbf(), a);

                for (unsigned int i=0; i<fe.nbf(); i++)
                {
                        ret += A.op(i)*fe.N(i);
                        basis.append(fe.N(i));
                }
                return GiNaC::lst(ret,matrix_to_lst2(A),basis);
        }
GiNaC::lst SyFi::lagrangev ( unsigned int  no_fields,
unsigned int  order,
Polygon &  p,
const std::string &  a 
)

Definition at line 550 of file Lagrange.cpp.

References get_symbolic_matrix(), matrix_to_lst2(), SyFi::StandardFE::N(), and SyFi::StandardFE::nbf().

        {
                if ( order < 1 )
                {
                        throw(std::logic_error("Can not create polynomials of order less than 1!"));
                }

                GiNaC::ex A;
                GiNaC::ex ret;
                GiNaC::lst basis;

                VectorLagrange fe(p,order);
                A = get_symbolic_matrix(1, fe.nbf(), a);

                for (unsigned int i=0; i<fe.nbf(); i++)
                {
                        ret += A.op(i)*fe.N(i);
                        basis.append(fe.N(i));
                }
                return GiNaC::lst(ret,matrix_to_lst2(A),basis);
        }
GiNaC::ex SyFi::legendre ( unsigned int  order,
unsigned int  nsd,
const std::string  a 
)
GiNaC::ex SyFi::legendre ( unsigned int  order,
unsigned int  nsd,
const string  s 
)

Definition at line 942 of file ginac_tools.cpp.

References run_tests::f, get_symbolic_matrix(), legendre1D(), matrix_to_lst2(), x, y, and z.

Referenced by SyFi::Hermite::compute_basis_functions(), legendrev(), and main().

{
        using SyFi::x;
        using SyFi::y;
        using SyFi::z;

        // The Legendre polynomials to be used in FiniteElement
        GiNaC::ex leg;
        GiNaC::ex A;
        GiNaC::lst basis;
        int dof;

        GiNaC::ex b;

        // 1D
        if(nsd == 1)
        {
                dof = order+1;
                A = get_symbolic_matrix(1,dof,s);
                int o=0;
                for(GiNaC::const_iterator i = A.begin(); i!=A.end(); ++i)
                {
                        b= legendre1D(x,o);
                        leg+= (*i)*b;
                        basis.append(b);
                        o++;
                }
        }
        // 2D
        /*
        else if(nsd == 2){  // NB: Only for tensor products on TRIANGLES (not boxes)
                / * 2D: structure of coefficients (a_i)
                 * [ a_0           a_1 P_1(x)           a_3 P_2(x)        a_6 P_3(x)
                 * [ a_2 P_1(y)    a_4 P_1(x)*P_1(y)    a_7 P_2(x)*P_1(y)
                 * [ a_5 P_2(y)    a_8 P_1(x)*P_2(y)
        * [ a_9 P_3(y)
        * /
        dof = (order+1)*(order+2)/2;
        A = get_symbolic_matrix(1,dof,s);
        size_t i=0;
        for (int o = 0; o <= order; o++) {
        for (int d = 0; d <= o; d++) {
        b = legendre1D(y,d)*legendre1D(x,o-d);
        leg += A.op(i)*b;
        basis.append(b);
        i++;

        }
        }
        }
        */
        else if(nsd == 2)                        // NB: Only for tensor products on rectangles
        {
                dof = (order+1)*(order+1);
                A = get_symbolic_matrix(1,dof,s);
                size_t i=0;
                for (unsigned int o = 0; o <= order; o++)
                {
                        for (unsigned int d = 0; d <= order; d++)
                        {
                                b = legendre1D(y,d)*legendre1D(x,o);
                                leg += A.op(i)*b;
                                basis.append(b);
                                i++;

                        }
                }
        }

        /* tetrahedron
        else if(nsd==3){
                dof = 0;
                for (int j=0; j<= order; j++) {
                        dof += (j+1)*(j+2)/2;
                }
        A = get_symbolic_matrix(1, dof , s);

        size_t i=0;
        for (int o = 0; o <= order; o++) {
        for (int d = 0; d <= o; d++) {
        for (int f = 0; f <= o; f++) {
        if ( o-d-f >= 0) {
        b = legendre1D(y,f)*legendre1D(z,d)*legendre1D(x,o-d-f);
        leg += A.op(i)*b;
        basis.append(b);
        i++;
        }
        }
        }
        }
        }
        */

        else if(nsd==3)
        {
                dof = (order+1)*(order+1)*(order+1);
                A = get_symbolic_matrix(1, dof , s);

                size_t i=0;
                for (unsigned int o = 0; o <= order; o++)
                {
                        for (unsigned int d = 0; d <= order; d++)
                        {
                                for (unsigned int f = 0; f <= order; f++)
                                {
                                        b = legendre1D(y,f)*legendre1D(z,d)*legendre1D(x,o);
                                        leg += A.op(i)*b;
                                        basis.append(b);
                                        i++;
                                }
                        }
                }
        }
        return GiNaC::lst(leg,matrix_to_lst2(A), basis);
}
GiNaC::ex SyFi::legendre1D ( const GiNaC::symbol  x,
unsigned int  n 
)

Definition at line 928 of file ginac_tools.cpp.

References x.

Referenced by legendre().

{
        GiNaC::ex P;
        // Rodrigue's formula for Legendre polynomial of 1D
        // The interval [-1, 1]
        P=1/(pow(2,n)*GiNaC::factorial(n))*GiNaC::diff(GiNaC::pow((x*x-1),n),x,n);
        // -----------------
        // The interval [0,1]
        //  GiNaC::ex xx = 2*x - 1;
        // P=1/(pow(2,2*n)*GiNaC::factorial(n))*GiNaC::diff(GiNaC::pow((xx*xx-1),n),x,n);
        return P;
}
GiNaC::lst SyFi::legendrev ( unsigned int  no_fields,
unsigned int  order,
unsigned int  nsd,
const std::string  a 
)
GiNaC::lst SyFi::legendrev ( unsigned int  no_fields,
unsigned int  order,
unsigned int  nsd,
const string  a 
)

Definition at line 1059 of file ginac_tools.cpp.

References legendre().

{
        GiNaC::lst ret1;                         // contains the polynom
        GiNaC::lst ret2;                         // contains the coefficients
        GiNaC::lst ret3;                         // constains the basis functions
        GiNaC::lst basis_tmp;
        for (unsigned int i=1; i<= no_fields; i++)
        {
                GiNaC::lst basis;
                std::ostringstream s;
                s <<a<<""<<i<<"_";
                GiNaC::ex polspace = legendre(order, nsd, s.str());
                ret1.append(polspace.op(0));
                ret2.append(polspace.op(1));
                basis_tmp = GiNaC::ex_to<GiNaC::lst>(polspace.op(2));
                for (GiNaC::lst::const_iterator basis_iterator = basis_tmp.begin();
                        basis_iterator != basis_tmp.end(); ++basis_iterator)
                {
                        GiNaC::lst tmp_lst;
                        for (unsigned int d=1; d<=no_fields; d++) tmp_lst.append(0);
                        tmp_lst.let_op(i-1) = (*basis_iterator);
                        ret3.append(tmp_lst);
                }
        }
        return GiNaC::lst(ret1,ret2,ret3);
}
bool SyFi::line_contains ( Ptv e0,
Ptv e1,
Ptv p 
)

Definition at line 147 of file Ptv_tools.cpp.

References test_syfi::debug::c, cross(), is_equal(), Ptv::less(), norm(), sub(), and Ptv::tol.

Referenced by contains2D(), and contains3D().

        {

                if ( is_equal(e0, p) || is_equal(e1, p) ) return true;

                // vec0 = e1-e0
                Ptv vec0;
                sub(e1,e0, vec0);
                // vec1 = e1-p
                Ptv vec1;
                sub(e1, p, vec1);

                // check if the vec0 and vec1 are parallel
                Ptv c;
                cross(vec0, vec1, c);
                if (norm(c) > Ptv::tol)
                {
                        return false;
                }

                // check whether the edge (e0,e1) contains p .
                if ( e0.less(p) && e1.less(p) ) return false;
                if ( p.less(e0) && p.less(e1) ) return false;

                return true;
        }
std::string SyFi::lst2string ( GiNaC::lst &  l)

Definition at line 61 of file utilities.cpp.

Referenced by main().

        {

                ostringstream s;
                GiNaC::lst::const_iterator i = l.begin();
                s <<"("<<*i;
                ++i;

                for (; i != l.end() ; ++i)
                {
                        s<< ","<< *i;
                }
                s <<");"<<endl;
                return s.str();
        }
GiNaC::lst SyFi::lst_equals ( GiNaC::ex  a,
GiNaC::ex  b 
)

Definition at line 365 of file ginac_tools.cpp.

        {
                GiNaC::lst ret;
                if ( (GiNaC::is_a<GiNaC::lst>(a)) && (GiNaC::is_a<GiNaC::lst>(b)) /*&& (a.nops() == b.nops())*/ ) {
                for (unsigned int i=0; i<= a.nops()-1; i++)
                {
                        ret.append(b.op(i) == a.op(i));
                }
        }
        else if ( !(GiNaC::is_a<GiNaC::lst>(a)) && !(GiNaC::is_a<GiNaC::lst>(b)))
        {
                ret.append(b == a);
        }
        else if ( !(GiNaC::is_a<GiNaC::lst>(a)) && (GiNaC::is_a<GiNaC::lst>(b)))
        {
                ret.append(b.op(0) == a);
        }
        else
        {
                throw(std::invalid_argument("Make sure that the lists a and b are comparable."));
        }
        return ret;
}
GiNaC::ex SyFi::lst_to_matrix2 ( const GiNaC::lst &  l)

Definition at line 287 of file ginac_tools.cpp.

Referenced by bezier_ordinates(), and interior_coordinates().

        {
                GiNaC::lst::const_iterator itr, itc;

                // Find number of rows and columns
                size_t rows = l.nops(), cols = 0;
                for (itr = l.begin(); itr != l.end(); ++itr)
                {
                        if (!GiNaC::is_a<GiNaC::lst>(*itr))
                                //              throw (std::invalid_argument("lst_to_matrix: argument must be a list of lists"));
                                cols = 1;
                        if (itr->nops() > cols)
                                cols = itr->nops();
                }
                // Allocate and fill matrix
                GiNaC::matrix &M = *new GiNaC::matrix(rows, cols);
                M.setflag(GiNaC::status_flags::dynallocated);

                unsigned i;
                for (itr = l.begin(), i = 0; itr != l.end(); ++itr, ++i)
                {
                        unsigned j;
                        if (cols == 1)
                        {
                                M(i, 0) = *itr;
                        }
                        else
                        {
                                for (itc = GiNaC::ex_to<GiNaC::lst>(*itr).begin(), j = 0; itc != GiNaC::ex_to<GiNaC::lst>(*itr).end(); ++itc, ++j)
                                        M(i, j) = *itc;
                        }
                }
                return M;
        }
void SyFi::matrix_from_equations ( const GiNaC::ex &  eqns,
const GiNaC::ex &  symbols,
GiNaC::matrix &  A,
GiNaC::matrix &  b 
)

Definition at line 262 of file ginac_tools.cpp.

References test_syfi::debug::c.

Referenced by SyFi::Hermite::compute_basis_functions(), SyFi::Nedelec::compute_basis_functions(), SyFi::Lagrange::compute_basis_functions(), SyFi::Nedelec2Hdiv::compute_basis_functions(), SyFi::RaviartThomas::compute_basis_functions(), SyFi::BrezziDouglasMarini::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), and SyFi::Robust::compute_basis_functions_old().

        {
                // build matrix from equation system
                GiNaC::matrix sys(eqns.nops(),symbols.nops());
                GiNaC::matrix rhs(eqns.nops(),1);
                GiNaC::matrix vars(symbols.nops(),1);

                for (size_t r=0; r<eqns.nops(); r++)
                {
                                                                 // lhs-rhs==0
                        const GiNaC::ex eq = eqns.op(r).op(0)-eqns.op(r).op(1);
                        GiNaC::ex linpart = eq;
                        for (size_t c=0; c<symbols.nops(); c++)
                        {
                                const GiNaC::ex co = eq.coeff(GiNaC::ex_to<GiNaC::symbol>(symbols.op(c)),1);
                                linpart -= co*symbols.op(c);
                                sys(r,c) = co;
                        }
                        linpart = linpart.expand();
                        rhs(r,0) = -linpart;
                }
                A = sys;
                b = rhs;
        }
GiNaC::lst SyFi::matrix_to_lst2 ( const GiNaC::ex &  m)

Definition at line 322 of file ginac_tools.cpp.

Referenced by bernstein(), bezier_ordinates(), homogenous_pol(), interior_coordinates(), lagrange(), lagrangev(), legendre(), pol(), and polb().

        {
                if (GiNaC::is_a<GiNaC::matrix>(m))
                {
                        GiNaC::matrix A = GiNaC::ex_to<GiNaC::matrix>(m);
                        int cols = A.cols();
                        int rows = A.rows();

                        GiNaC::lst ret;
                        if ( cols == 1 )
                        {
                                for (unsigned int i=0; i<=A.rows()-1; i++)
                                {
                                        ret.append(A(i,0));
                                }
                        }
                        else if ( rows == 1 )
                        {
                                for (unsigned int i=0; i<=A.cols()-1; i++)
                                {
                                        ret.append(A(0,i));
                                }
                        }
                        else
                        {
                                for (unsigned int i=0; i<=A.rows()-1; i++)
                                {
                                        GiNaC::lst rl;
                                        for (unsigned int j=0; j<=A.cols()-1; j++)
                                        {
                                                rl.append(A(i,j));
                                        }
                                        ret.append(rl);
                                }
                        }
                        return ret;
                }
                else
                {
                        return GiNaC::lst();
                }
        }
GiNaC::lst SyFi::matvec ( GiNaC::matrix &  M,
GiNaC::lst &  x 
)

Definition at line 153 of file ginac_tools.cpp.

        {
                GiNaC::lst ret;
                int nr = M.rows();
                int nc = M.cols();
                for (int i = 0; i < nr; i++)
                {
                        GiNaC::ex tmp;
                        for (int j = 0; j < nc; j++)
                        {
                                tmp = tmp +  M(i,j)*(x.op(j));
                        }
                        ret.append(tmp);
                }
                return ret;
        }
GiNaC::ex SyFi::matvec ( GiNaC::ex  A,
GiNaC::ex  x 
)

Definition at line 170 of file ginac_tools.cpp.

References x.

        {
                ex sol;

                if (GiNaC::is_a<GiNaC::matrix>(A) && GiNaC::is_a<GiNaC::matrix>(x))
                {
                        GiNaC::matrix AA = GiNaC::ex_to<GiNaC::matrix>(A);
                        GiNaC::matrix xx = GiNaC::ex_to<GiNaC::matrix>(x);
                        sol = AA.mul(xx);
                }
                else
                {
                        throw std::runtime_error("Invalid argument types, need matrices");
                }
                return sol;
        }
double SyFi::mul ( const Ptv a,
const Ptv b 
)

Definition at line 40 of file Ptv_tools.cpp.

References Ptv::size().

Referenced by is_inside_triangle().

        {
                if ( a.size() != b.size() )
                {
                        throw(std::logic_error("Exception from mul(const Ptv&, const Ptv&):  The dimentions of a and b must be the same."));
                }

                double sum = 0;
                for (unsigned int i=0; i< a.size(); i++)
                {
                        sum += (a[i])*(b[i]);
                }
                return sum;
        }
double SyFi::norm ( const Ptv a)

Definition at line 55 of file Ptv_tools.cpp.

References Ptv::size().

Referenced by line_contains(), normal(), normalize(), and tangent().

        {
                double sum = 0.0;
                for (unsigned int i=0; i < a.size(); i++)
                {
                        sum += a[i]*a[i];
                }

                sum = sqrt(sum);
                return sum;
        }
GiNaC::lst SyFi::normal ( Tetrahedron &  tetrahedron,
unsigned int  i 
)

Definition at line 1951 of file Polygon.cpp.

References cross(), norm(), SyFi::Tetrahedron::triangle(), and SyFi::Polygon::vertex().

Referenced by SyFi::Nedelec::compute_basis_functions(), SyFi::Nedelec2Hdiv::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), SyFi::RaviartThomas::compute_basis_functions(), SyFi::BrezziDouglasMarini::compute_basis_functions(), SyFi::Robust::compute_basis_functions_old(), main(), and variants().

        {
                // Normal as defined by Maries note
                Triangle triangle = tetrahedron.triangle(i);
                lst      vertex_i   = ex_to<lst>(tetrahedron.vertex(i));
                lst      vertex_0   = ex_to<lst>(triangle.vertex(0));
                lst      vertex_1   = ex_to<lst>(triangle.vertex(1));
                lst      vertex_2   = ex_to<lst>(triangle.vertex(2));

                lst n1(vertex_1.op(0) - vertex_0.op(0),
                        vertex_1.op(1) - vertex_0.op(1),
                        vertex_1.op(2) - vertex_0.op(2));

                lst n2(vertex_2.op(0) - vertex_0.op(0),
                        vertex_2.op(1) - vertex_0.op(1),
                        vertex_2.op(2) - vertex_0.op(2));

                /*
                lst n3(vertex_0.op(0) - vertex_i.op(0),
                           vertex_0.op(1) - vertex_i.op(1),
                           vertex_0.op(2) - vertex_i.op(2));
                */

                lst n4 = cross(n1,n2);
                /*
                ex nn = inner(n3, n4);
                int sign = 1;
                if ( is_a<numeric>(nn)) {
                  if ( nn > 0 ) {
                        sign = 1;
                } else if ( nn < 0) {
                sign = -1;
                } else {
                sign = 0;
                }
                }
                */

                ex norm = sqrt(pow(n4.op(0),2)
                        + pow(n4.op(1),2)
                        + pow(n4.op(2),2));

                n4.let_op(0) = n4.op(0)/norm;
                n4.let_op(1) = n4.op(1)/norm;
                n4.let_op(2) = n4.op(2)/norm;

                return n4;

        }
GiNaC::lst SyFi::normal ( Triangle &  triangle,
unsigned int  i 
)

Definition at line 2001 of file Polygon.cpp.

References SyFi::Triangle::line(), norm(), and SyFi::Polygon::vertex().

        {
                Line line = triangle.line(i);
                lst      vertex_i   = ex_to<lst>(triangle.vertex(i));
                lst      vertex_0   = ex_to<lst>(line.vertex(0));
                lst      vertex_1   = ex_to<lst>(line.vertex(1));

                /*
                lst n1 = lst (- (vertex_1.op(1) - vertex_0.op(1)),  vertex_1.op(0) - vertex_0.op(0) );
                lst n2 = lst (vertex_0.op(0) - vertex_i.op(0),   vertex_0.op(1) - vertex_i.op(1));

                ex nn = inner(n1, n2);
                int sign = 1;
                / *
                        if ( is_a<numeric>(nn)) {
                          if ( nn > 0 ) {
                                sign = 1;
                          } else if ( nn < 0) {
                                sign = -1;
                } else {
                sign = 0;
                }
                }

                ex norm = sqrt(pow(n1.op(0),2) + pow(n1.op(1),2));
                n1.let_op(0) = sign*n1.op(0)/norm;
                n1.let_op(1) = sign*n1.op(1)/norm;
                */

                // normal vector as Marie has defined them
                lst n1 = lst (  (vertex_1.op(1) - vertex_0.op(1)),
                        -(vertex_1.op(0) - vertex_0.op(0)) );

                ex norm = sqrt(pow(n1.op(0),2) + pow(n1.op(1),2));
                n1.let_op(0) = n1.op(0)/norm;
                n1.let_op(1) = n1.op(1)/norm;

                return n1;
        }
void SyFi::normalize ( Ptv a)

Definition at line 67 of file Ptv_tools.cpp.

References norm(), and Ptv::size().

Referenced by is_inside_triangle().

        {
                double invn = 1.0/norm(a);
                for (unsigned int i=0; i< a.size(); i++)
                {
                        a[i] *= invn;
                }
        }
std::ostream & SyFi::operator<< ( std::ostream &  os,
const OrderedPtvSet &  p 
)

Definition at line 118 of file OrderedPtvSet.cpp.

References SyFi::OrderedPtvSet::size().

        {
                if (p.size() >= 1)
                {
                        os <<"[";
                        for (unsigned int i=0; i< p.size()-1; i++)
                        {
                                os <<p[i]<<",";
                        }
                        os <<p[p.size()-1]<<"]";
                }
                else
                {
                        os <<"OrderedPtvSet not created properly"<<std::endl;
                }
                return os;
        }
std::ostream & SyFi::operator<< ( std::ostream &  os,
const OrderedPtvSet_i &  p 
)

Definition at line 198 of file OrderedPtvSet.cpp.

References SyFi::OrderedPtvSet_i::get_i(), SyFi::OrderedPtvSet_i::get_OrderedPtvSet(), and SyFi::OrderedPtvSet_i::size().

        {
                cout <<p.get_OrderedPtvSet();
                if (p.size() >= 1)
                {
                        os <<",[";
                        for (unsigned int i=0; i< p.size()-1; i++)
                        {
                                os <<p.get_i(i)<<",";
                        }
                        os <<p.get_i(p.size()-1)<<"]";
                }
                else
                {
                        os <<"OrderedPtvSet_i not created properly"<<std::endl;
                }
                return os;
        }
GiNaC::ex SyFi::pol ( unsigned int  order,
unsigned int  nsd,
const std::string  a 
)
GiNaC::ex SyFi::pol ( unsigned int  order,
unsigned int  nsd,
const string  a 
)

Definition at line 613 of file ginac_tools.cpp.

References run_tests::f, get_symbolic_matrix(), matrix_to_lst2(), x, y, and z.

Referenced by bernsteinv(), SyFi::Lagrange::compute_basis_functions(), SyFi::Hermite::compute_basis_functions(), main(), and polv().

{
        using SyFi::x;
        using SyFi::y;
        using SyFi::z;

        GiNaC::ex ret;                           // ex to return
        int dof;                                         // degrees of freedom
        GiNaC::ex A;                             // ex holding the coefficients a_0 .. a_dof
        GiNaC::lst basis;

        if (nsd == 1)
        {
                /* 1D:
                 * P^n = a_0 + a_1*x + .... + a_n*x^n
                 * dof : n+1
                 */
                dof = order+1;
                A = get_symbolic_matrix(1,dof, a);
                int o=0;
                for (GiNaC::const_iterator i = A.begin(); i != A.end(); ++i)
                {
                        ret += (*i)*pow(x,o);
                        basis.append(pow(x,o));
                        o++;
                }
        }
        else if ( nsd == 2)
        {

                /* 2D: structure of coefficients (a_i)
                 * [ a_0      a_1 x     a_3 x^2     a_6 x^3
                 * [ a_2 y    a_4 xy    a_7 x^2y
                 * [ a_5 y^2  a_8 xy^2
                 * [ a_9 y^3
                 */
                dof = (order+1)*(order+2)/2;
                A = get_symbolic_matrix(1, dof , a);

                size_t i=0;
                for (unsigned int o = 0; o <= order; o++)
                {
                        for (unsigned int d = 0; d <= o; d++)
                        {
                                ret += A.op(i)*pow(y,d)*pow(x,o-d);
                                basis.append(pow(y,d)*pow(x,o-d));
                                i++;
                        }
                }
        }
        else if (nsd == 3)
        {

                /* Similar structure as in 2D, but
                 * structured as a tetraheder, i.e.,
                 *   a_o + a_1 x + a_2 y + a_3 z
                 * + a_4 x^2 + a_5 xy +
                 */
                dof = 0;
                for (unsigned int j=0; j<= order; j++)
                {
                        dof += (j+1)*(j+2)/2;
                }
                A = get_symbolic_matrix(1, dof , a);

                size_t i=0;
                for (unsigned int o = 0; o <= order; o++)
                {
                        for (unsigned int d = 0; d <= o; d++)
                        {
                                for (unsigned int f = 0; f <= o; f++)
                                {
                                        if ( int(o)-int(d)-int(f) >= 0)
                                        {
                                                ret += A.op(i)*pow(y,f)*pow(z,d)*pow(x,o-d-f);
                                                basis.append(pow(y,f)*pow(z,d)*pow(x,o-d-f));
                                                i++;
                                        }
                                }
                        }
                }
        }
        return GiNaC::lst(ret,matrix_to_lst2(A), basis);
}
GiNaC::exmap SyFi::pol2basisandcoeff ( GiNaC::ex  e,
GiNaC::ex  s 
)

Definition at line 878 of file ginac_tools.cpp.

References test_syfi::debug::c.

Referenced by SyFi::Nedelec::compute_basis_functions(), SyFi::Nedelec2Hdiv::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), and SyFi::Robust::compute_basis_functions_old().

{
        if (GiNaC::is_a<GiNaC::symbol>(s))
        {
                GiNaC::symbol ss = GiNaC::ex_to<GiNaC::symbol>(s);
                e = expand(e);
                GiNaC::ex c;
                GiNaC::ex b;
                GiNaC::exmap map;
                for (int i=e.ldegree(ss); i<=e.degree(ss); ++i)
                {
                        c = e.coeff(ss,i);
                        b = pow(ss,i);
                        map[b] = c;
                }
                return map;
        }
        else
        {
                throw(std::invalid_argument("The second argument must be a symbol."));
        }
}
GiNaC::exmap SyFi::pol2basisandcoeff ( GiNaC::ex  e)

Definition at line 902 of file ginac_tools.cpp.

References test_syfi::debug::c, x, y, and z.

{
        using SyFi::x;
        using SyFi::y;
        using SyFi::z;

        e = expand(e);
        GiNaC::ex c;
        GiNaC::ex b;
        GiNaC::exmap map;
        for (int i=e.ldegree(x); i<=e.degree(x); ++i)
        {
                for (int j=e.ldegree(y); j<=e.degree(y); ++j)
                {
                        for (int k=e.ldegree(z); k<=e.degree(z); ++k)
                        {
                                c = e.coeff(x,i).coeff(y, j).coeff(z,k);
                                b = pow(x,i)*pow(y,j)*pow(z,k);
                                map[b] = c;
                        }
                }
        }
        return map;
}
GiNaC::ex SyFi::polb ( unsigned int  order,
unsigned int  nsd,
const std::string  a 
)
GiNaC::ex SyFi::polb ( unsigned int  order,
unsigned int  nsd,
const string  a 
)

Definition at line 738 of file ginac_tools.cpp.

References run_tests::f, get_symbolic_matrix(), matrix_to_lst2(), x, y, and z.

{
        using SyFi::x;
        using SyFi::y;
        using SyFi::z;

        GiNaC::ex ret;                           // ex to return
        int dof;                                         // degrees of freedom
        GiNaC::ex A;                             // ex holding the coefficients a_0 .. a_dof
        GiNaC::lst basis;

        if (nsd == 1)
        {
                /* 1D:
                 * P^n = a_0 + a_1*x + .... + a_n*x^n
                 * dof : n+1
                 */
                dof = order+1;
                A = get_symbolic_matrix(1,dof, a);
                int o=0;
                for (GiNaC::const_iterator i = A.begin(); i != A.end(); ++i)
                {
                        ret += (*i)*pow(x,o);
                        basis.append(pow(x,o));
                        o++;
                }
        }
        else if ( nsd == 2)
        {

                /* 2D: structure of coefficients (a_i)
                 * [ a_0      a_1 x     a_3 x^2     a_6 x^3
                 * [ a_2 y    a_4 xy    a_7 x^2y
                 * [ a_5 y^2  a_8 xy^2
                 * [ a_9 y^3
                 */

                dof = (order+1)*(order+1);
                A = get_symbolic_matrix(1, dof , a);

                size_t i=0;
                for (unsigned int o = 0; o <= order; o++)
                {
                        for (unsigned int d = 0; d <= order; d++)
                        {
                                ret += A.op(i)*pow(y,d)*pow(x,o);
                                basis.append(pow(y,d)*pow(x,o));
                                i++;
                        }
                }
        }
        else if (nsd == 3)
        {

                /* Similar structure as in 2D, but
                 * structured as a tetraheder, i.e.,
                 *   a_o + a_1 x + a_2 y + a_3 z
                 * + a_4 x^2 + a_5 xy +
                 */
                dof = (order+1)*(order+1)*(order+1);
                A = get_symbolic_matrix(1, dof , a);

                size_t i=0;
                for (unsigned int o = 0; o <= order; o++)
                {
                        for (unsigned int d = 0; d <= order; d++)
                        {
                                for (unsigned int f = 0; f <= order; f++)
                                {
                                        ret += A.op(i)*pow(y,f)*pow(z,d)*pow(x,o);
                                        basis.append(pow(y,f)*pow(z,d)*pow(x,o));
                                        i++;
                                }
                        }
                }
        }

        return GiNaC::lst(ret,matrix_to_lst2(A), basis);
}
GiNaC::lst SyFi::polv ( unsigned int  no_fields,
unsigned int  order,
unsigned int  nsd,
const std::string  a 
)
GiNaC::lst SyFi::polv ( unsigned int  no_fields,
unsigned int  order,
unsigned int  nsd,
const string  a 
)

Definition at line 699 of file ginac_tools.cpp.

References pol().

{
        GiNaC::lst ret1;                         // contains the polynom
        GiNaC::lst ret2;                         // contains the coefficients
        GiNaC::lst ret3;                         // constains the basis functions
        GiNaC::lst basis_tmp;
        for (unsigned int i=0; i< no_fields; i++)
        {
                GiNaC::lst basis;
                std::ostringstream s;
                s <<a<<""<<i<<"_";
                GiNaC::ex polspace = pol(order, nsd, s.str());
                ret1.append(polspace.op(0));
                ret2.append(polspace.op(1));
                basis_tmp = GiNaC::ex_to<GiNaC::lst>(polspace.op(2));
                for (GiNaC::lst::const_iterator basis_iterator = basis_tmp.begin();
                        basis_iterator != basis_tmp.end(); ++basis_iterator)
                {
                        GiNaC::lst tmp_lst;
                        for (unsigned int d=1; d<=no_fields; d++) tmp_lst.append(0);
                        tmp_lst.let_op(i) = (*basis_iterator);
                        ret3.append(tmp_lst);
                }
        }
        return GiNaC::lst(ret1,ret2,ret3);

        /* Old Code:
           GiNaC::lst ret;
           for (int i=1; i<= nsd; i++) {
           std::ostringstream s;
           s <<a<<"^"<<i<<"_";
           GiNaC::ex p = pol(order, nsd, s.str());
        ret.append(p);
        }
        return ret;
        */
}
void SyFi::print ( GiNaC::lst &  l)

Definition at line 89 of file utilities.cpp.

        {
                //  for (GiNaC::lst::const_iterator i = l.begin(); i != l.end(); ++i)
                //    cout << *i << endl;
                //
                GiNaC::lst::const_iterator i = l.begin();
                cout <<"GiNaC::lst("<<*i;
                ++i;

                for (; i != l.end() ; ++i)
                {
                        cout << ","<< *i;
                }
                cout <<");"<<endl;
        }
void SyFi::print ( GiNaC::exvector &  v)

Definition at line 105 of file utilities.cpp.

        {
                cout <<"v=[";
                for (unsigned int i=0; i< v.size()-1; i++)
                {
                        cout <<v[i]<<"," <<endl;
                }
                cout <<v[v.size()-1]<< "]"<<endl;
        }
void SyFi::print ( std::map< std::pair< unsigned int, unsigned int >, GiNaC::ex > &  A)

Definition at line 115 of file utilities.cpp.

        {
                map<std::pair<unsigned int,unsigned int>,GiNaC::ex>::iterator iter;
                for (iter = A.begin(); iter != A.end() ; iter++)
                {
                        cout <<"A["<<(*iter).first.first<<","<<(*iter).first.second<<"]="<<(*iter).second<<endl;
                }
        }
void SyFi::print ( ex_int_map  map)

Definition at line 124 of file utilities.cpp.

References test_syfi::debug::c.

        {
                GiNaC::ex b;
                int c=0;
                ex_int_map::iterator iter;
                iter = map.begin();
                cout <<"{";
                for (iter = map.begin(); iter != map.end(); iter++)
                {
                        b = (*iter).first; c = map[b];
                        cout <<", "<<b<<":"<<c;
                }
                cout <<"}"<<endl;
        }
void SyFi::print ( GiNaC::exmap  map)

Definition at line 139 of file utilities.cpp.

References test_syfi::debug::c.

        {
                GiNaC::ex b;
                GiNaC::ex c;
                GiNaC::exmap::iterator iter;
                cout <<"{" <<b<<":"<<c;
                for (iter = map.begin(); iter != map.end(); iter++)
                {
                        b = (*iter).first; c = map[b];
                        cout <<", "<<b<<":"<<c;
                }
                cout <<"}"<<endl;
        }
GiNaC::ex SyFi::replace_powers ( const GiNaC::ex &  e,
const std::list< GiNaC::symbol > &  symbols,
std::list< symexpair > &  sel,
const std::string &  tmpsymbolprefix = "p_" 
)
ex SyFi::replace_powers ( const ex &  ein,
const list< symbol > &  symbols,
list< symexpair > &  sel,
const string &  tmpsymbolprefix 
)

Definition at line 1394 of file ginac_tools.cpp.

References get_symbol(), and int2string().

Referenced by variants().

{
        ex e = ein;
        // build power expressions
        list<symbol>::const_iterator it = symbols.begin();
        for(; it != symbols.end(); it++)
        {
                int deg      = e.degree(*it);
                if(deg > 0)
                {
                        symbol sym   = ex_to<symbol>(*it);
                        string sname = tmpsymbolprefix + sym.get_name();

                        // make list of new symbols
                        vector<symbol> symbols(deg);
                        symbols[0] = sym;
                        for(int i=1; i<deg; i++)
                        {
                                symbols[i] = get_symbol( sname + int2string(i+1) );
                                sel.push_back(make_pair(symbols[i], symbols[i-1]*sym));
                        }

                        // with highest order first, subs in e
                        ex prod = sym;
                        for(int i=deg-1; i>=1; i--)
                        {
                                e = e.subs(power(sym,i+1) == symbols[i], subs_options::algebraic);
                        }
                }
        }
        return e;
}
void SyFi::set_tolerance ( double  tolerance)

Definition at line 35 of file Ptv_tools.cpp.

References Ptv::tol.

        {
                Ptv::tol = tolerance;
        }
void SyFi::sort_vector ( vector< Ptv > &  a)

Definition at line 30 of file Ptv_tools.cpp.

        {
                sort(a.begin(), a.end(), Ptv_is_less());
        }
void SyFi::sub ( const Ptv a,
const Ptv b,
Ptv c 
)

Definition at line 90 of file Ptv_tools.cpp.

References Ptv::redim(), and Ptv::size().

Referenced by SyFi::CrouzeixRaviart::compute_basis_functions(), SyFi::Line::integrate(), SyFi::Triangle::integrate(), SyFi::Rectangle::integrate(), SyFi::Tetrahedron::integrate(), SyFi::Box::integrate(), is_inside_triangle(), and line_contains().

        {
                if ( a.size() != b.size() )
                {
                        throw(std::logic_error("Exception from add(const Ptv&, const Ptv&, Ptv&):  The dimentions of a and b must be the same."));
                }

                c.redim(a.size());
                for (unsigned int i=0; i< c.size(); i++)
                {
                        c[i] = a[i] - b[i];
                }
        }
bool SyFi::symbol_exists ( const std::string &  name)
bool SyFi::symbol_exists ( const string &  name)

Definition at line 118 of file syfi/symbol_factory.cpp.

References symbol_collection.

Referenced by main().

        {
                return symbol_collection.find(name) != symbol_collection.end();
        }
GiNaC::symbol SyFi::t ( "(t is not initialized since initSyFi has never been called)"  )
GiNaC::lst SyFi::tangent ( Triangle &  triangle,
unsigned int  i 
)

Definition at line 2041 of file Polygon.cpp.

References SyFi::Triangle::line(), norm(), and SyFi::Polygon::vertex().

Referenced by SyFi::Nedelec::compute_basis_functions(), SyFi::Robust::compute_basis_functions(), and SyFi::Robust::compute_basis_functions_old().

        {
                /*
                Line line = triangle.line(i);
                //FIXME: 5 lines to compute the tangent vector, these should
                // be put somewhere else.
                GiNaC::symbol t("t");
                ex line_repr = line.repr(t);
                ex t1 = line_repr.op(0).rhs().coeff(t,1);
                ex t2 = line_repr.op(1).rhs().coeff(t,1);
                ex norm = sqrt(pow(t1,2) + pow(t2,2));
                lst tangent = lst(t1/norm,t2/norm);
                return tangent;
                */
                /*
                ex t1, t2;
                if ( i == 0 ) {
                  t1 = triangle.vertex(2).op(0) - triangle.vertex(1).op(0);
                  t2 = triangle.vertex(2).op(1) - triangle.vertex(1).op(1);
                } else if ( i == 1 ) {
                t1 = triangle.vertex(0).op(0) - triangle.vertex(2).op(0);
                t2 = triangle.vertex(0).op(1) - triangle.vertex(2).op(1);
                } else if ( i == 2 ) {
                t1 = triangle.vertex(1).op(0) - triangle.vertex(0).op(0);
                t2 = triangle.vertex(1).op(1) - triangle.vertex(0).op(1);
                } else {
                throw(std::out_of_range("The side index is out of range!"));
                }
                */
                Line line = triangle.line(i);
                ex t1 = line.vertex(1).op(0) - line.vertex(0).op(0);
                ex t2 = line.vertex(1).op(1) - line.vertex(0).op(1);

                ex norm = sqrt(pow(t1,2) + pow(t2,2));
                lst tangent = lst(t1/norm,t2/norm);
                return tangent;

        }
void SyFi::usage ( FE &  fe)

Definition at line 27 of file ElementComputations.cpp.

References SyFi::FE::dof(), grad(), SyFi::FE::N(), and SyFi::FE::nbf().

Referenced by check_CrouzeixRaviart(), check_RaviartThomas(), and main().

        {
                for (unsigned int i=0; i< fe.nbf(); i++)
                {
                        cout <<"fe.N("<<i<<")         =   "<<fe.N(i)<<endl;
                        cout <<"grad(fe.N("<<i<<"))   =   "<<grad(fe.N(i))<<endl;
                        cout <<"fe.dof("<<i<<")       =   "<<fe.dof(i)<<endl;
                }
        }
void SyFi::usage ( FE &  v_fe,
FE &  p_fe 
)

Definition at line 37 of file ElementComputations.cpp.

References SyFi::FE::dof(), grad(), SyFi::FE::N(), and SyFi::FE::nbf().

        {
                for (unsigned int i=0; i< v_fe.nbf(); i++)
                {
                        cout <<"v_fe.N("<<i<<")         =   "<<v_fe.N(i)<<endl;
                        cout <<"grad(v_fe.N("<<i<<"))   =   "<<grad(v_fe.N(i))<<endl;
                        cout <<"v_fe.dof("<<i<<")       =   "<<v_fe.dof(i)<<endl;
                }
                for (unsigned int i=0; i< p_fe.nbf(); i++)
                {
                        cout <<"p_fe.N("<<i<<")=   "<<p_fe.N(i)<<endl;
                        cout <<"p_fe.dof("<<i<<")= "<<p_fe.dof(i)<<endl;
                }
        }
void SyFi::visitor_subst_pow ( GiNaC::ex  e,
GiNaC::exmap &  map,
ex_int_map &  intmap,
std::string  a 
)
void SyFi::visitor_subst_pow ( GiNaC::ex  e,
GiNaC::exmap &  map,
ex_int_map &  intmap,
string  a 
)

Definition at line 400 of file ginac_tools.cpp.

{
        static int i=0;
        if (map.find(e) != map.end())
        {
                intmap[e] = intmap[e]+1;
                return;
        }
        if (GiNaC::is_exactly_a<GiNaC::power>(e))
        {
                std::ostringstream s;
                s <<a<<i++;
                map[e] = GiNaC::symbol(s.str());
                intmap[e] = 0;
                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        //       cout <<"power e "<<e2<<endl;
                        visitor_subst_pow(e2,map,intmap, a);
                }
        }
        else if (GiNaC::is_a<GiNaC::function>(e))
        {
                std::ostringstream s;
                s <<a<<i++;
                map[e] = GiNaC::symbol(s.str());
                intmap[e] = 0;
                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        //       cout <<"function e "<<e2<<endl;
                        visitor_subst_pow(e2,map,intmap, a);
                }
        }
        else if (GiNaC::is_a<GiNaC::mul>(e))
        {
                if (e.nops() > 4 && e.nops() < 10 )
                {
                        std::ostringstream s;
                        s <<a<<i++;
                        map[e] = GiNaC::symbol(s.str());
                        intmap[e] = 0;
                }

                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        visitor_subst_pow(e2,map,intmap, a);
                }
        }
        else if (GiNaC::is_a<GiNaC::add>(e))
        {
                for (unsigned int i=0; i< e.nops(); i++)
                {
                        GiNaC::ex e2 = e.op(i);
                        visitor_subst_pow(e2,map,intmap,a);
                }
        }
}
GiNaC::symbol SyFi::x ( "(x is not initialized since initSyFi has never been called)"  )
GiNaC::symbol SyFi::y ( "(y is not initialized since initSyFi has never been called)"  )
GiNaC::symbol SyFi::z ( "(z is not initialized since initSyFi has never been called)"  )

Variable Documentation

GiNaC::symbol SyFi::DUMMY

Referenced by initSyFi().

GiNaC::symbol SyFi::infinity

Referenced by initSyFi().

map<string, symbol> SyFi::symbol_collection

Definition at line 116 of file syfi/symbol_factory.cpp.

Referenced by get_symbol(), and symbol_exists().

const int SyFi::version_major = SYFILIB_MAJOR_VERSION

Definition at line 30 of file utilities.cpp.

const char * SyFi::version_micro = SYFILIB_MICRO_VERSION

Definition at line 32 of file utilities.cpp.

const int SyFi::version_minor = SYFILIB_MINOR_VERSION

Definition at line 31 of file utilities.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator