#include <ginac/ginac.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <stdexcept>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | std |
Typedefs | |
typedef vector< GiNaC::ex > | ex_vector |
typedef map< GiNaC::ex, GiNaC::ex, GiNaC::ex_is_less > | ex_ex_map |
typedef map< GiNaC::ex, int, GiNaC::ex_is_less > | ex_int_map |
typedef map< GiNaC::ex, GiNaC::ex >::iterator | ex_ex_it |
typedef map< GiNaC::ex, int >::iterator | ex_int_it |
typedef vector< GiNaC::exvector > | ex_vector_vector |
Functions | |
GiNaC::ex | inner (GiNaC::ex a, GiNaC::ex b, bool transposed=false) |
GiNaC::ex | inner (GiNaC::exvector &v1, GiNaC::exvector &v2) |
GiNaC::ex | inner (GiNaC::lst v1, GiNaC::lst v2) |
GiNaC::lst | cross (GiNaC::lst &v1, GiNaC::lst &v2) |
GiNaC::ex | pol (int order, int nsd, const string a) |
GiNaC::lst | polv (int order, int nsd, const string a) |
GiNaC::ex | polb (int order, int nsd, const string a) |
GiNaC::lst | matvec (GiNaC::matrix &M, GiNaC::lst &x) |
GiNaC::exvector | coeff (GiNaC::ex pol) |
GiNaC::lst | coeffs (GiNaC::ex pol) |
GiNaC::lst | coeffs (GiNaC::lst pols) |
ex_ex_map | pol2basisandcoeff (GiNaC::ex e) |
GiNaC::ex | div (GiNaC::exvector &v) |
GiNaC::ex | div (GiNaC::lst &v) |
GiNaC::ex | div (GiNaC::ex v) |
GiNaC::ex | grad (GiNaC::ex f) |
void | print (GiNaC::exvector &v) |
void | print (GiNaC::lst &l) |
void | print (ex_ex_map m) |
void | print (ex_int_map m) |
void | print (std::map< std::pair< int, int >, GiNaC::ex > &A) |
int | dirac (int i, int j) |
GiNaC::lst | ex2equations (GiNaC::ex rel) |
GiNaC::lst | collapse (GiNaC::lst l) |
GiNaC::matrix | equations2matrix (const GiNaC::ex &eqns, const GiNaC::ex &symbols) |
GiNaC::lst | lst_equals (GiNaC::ex a, GiNaC::ex b) |
GiNaC::ex | lst_to_matrix2 (const GiNaC::lst &l) |
GiNaC::lst | matrix_to_lst2 (const GiNaC::ex &m) |
int | find (GiNaC::ex e, GiNaC::lst list) |
void | check_visitor (GiNaC::ex e, GiNaC::lst &exlist) |
void | visitor_subst_pow (GiNaC::ex e, ex_ex_map &map, ex_int_map &intmap, string a) |
string | istr (string a, int b) |
bool | compare (GiNaC::ex e, string s) |
void | EQUAL_OR_DIE (GiNaC::ex e, char *s) |
void | matrix_from_equations (const GiNaC::ex &eqns, const GiNaC::ex &symbols, GiNaC::matrix &A, GiNaC::matrix &b) |
Variables | |
GiNaC::symbol | x |
GiNaC::symbol | y |
GiNaC::symbol | z |
int | nsd |
GiNaC::symbol | infinity |
GiNaC::symbol | DUMMY |
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 718 of file tools.cpp. References check_visitor(), and find(). Referenced by check_visitor(). 00718 { 00719 if (find(e, exlist) >= 0) return; 00720 00721 // cout <<"ex e "<<e<<endl; 00722 if (GiNaC::is_a<GiNaC::numeric>(e)) { 00723 } 00724 else if (GiNaC::is_a<GiNaC::add>(e) ) { 00725 // cout <<"e "<<e <<endl; 00726 // cout <<"e.nops() "<<e.nops() <<endl; 00727 if (e.nops() > 4 && e.nops() < 10 ) exlist.append(e); 00728 for (int i=0; i< e.nops(); i++) { 00729 GiNaC::ex e2 = e.op(i); 00730 // cout <<"add e "<<e2<<endl; 00731 // exlist.append(e2); 00732 check_visitor(e2,exlist); 00733 } 00734 } 00735 else if (GiNaC::is_a<GiNaC::mul>(e)) { 00736 for (int i=0; i< e.nops(); i++) { 00737 GiNaC::ex e2 = e.op(i); 00738 // cout <<"mul e "<<e2<<endl; 00739 exlist.append(e2); 00740 check_visitor(e2,exlist); 00741 } 00742 } 00743 else if (GiNaC::is_a<GiNaC::lst>(e)) { 00744 for (int i=0; i< e.nops(); i++) { 00745 GiNaC::ex e2 = e.op(i); 00746 // cout <<"GiNaC::lst e "<<e2<<endl; 00747 // exlist.append(e2); 00748 check_visitor(e2,exlist); 00749 } 00750 } 00751 else if (GiNaC::is_exactly_a<GiNaC::power>(e)) { 00752 exlist.append(e); 00753 for (int i=0; i< e.nops(); i++) { 00754 GiNaC::ex e2 = e.op(i); 00755 // cout <<"power e "<<e2<<endl; 00756 check_visitor(e2,exlist); 00757 } 00758 } 00759 else if (GiNaC::is_a<GiNaC::function>(e)) { 00760 exlist.append(e); 00761 for (int i=0; i< e.nops(); i++) { 00762 GiNaC::ex e2 = e.op(i); 00763 // cout <<"function e "<<e2<<endl; 00764 check_visitor(e2,exlist); 00765 } 00766 } 00767 00768 00769 00770 else { 00771 // exlist.append(e); 00772 // cout <<"atom e "<<e<<endl; 00773 } 00774 00775 exlist.sort(); 00776 exlist.unique(); 00777 }
|
|
Definition at line 408 of file tools.cpp. 00408 { 00409 GiNaC::exvector cc; 00410 GiNaC::ex c, b; 00411 for (int i=pol.ldegree(x); i<=pol.degree(x); ++i) { 00412 for (int j=pol.ldegree(y); j<=pol.degree(y); ++j) { 00413 for (int k=pol.ldegree(z); k<=pol.degree(z); ++k) { 00414 c = pol.coeff(x,i).coeff(y, j).coeff(z,k); 00415 if ( c != 0 ) cc.insert(cc.begin(),c); 00416 } 00417 } 00418 } 00419 return cc; 00420 }
|
|
Definition at line 380 of file tools.cpp. References coeffs(), and collapse(). 00380 { 00381 GiNaC::lst cc; 00382 GiNaC::lst tmp; 00383 for (int i=0; i<= pols.nops()-1; i++) { 00384 tmp = coeffs(pols.op(i)); 00385 cc = collapse(GiNaC::lst(cc, tmp)); 00386 } 00387 return cc; 00388 }
|
|
Definition at line 390 of file tools.cpp. 00390 { 00391 GiNaC::lst cc; 00392 GiNaC::ex c, b; 00393 for (int i=pol.ldegree(x); i<=pol.degree(x); ++i) { 00394 for (int j=pol.ldegree(y); j<=pol.degree(y); ++j) { 00395 for (int k=pol.ldegree(z); k<=pol.degree(z); ++k) { 00396 c = pol.coeff(x,i).coeff(y, j).coeff(z,k); 00397 if ( c != 0 ) cc.append(c); 00398 } 00399 } 00400 } 00401 return cc; 00402 }
|
|
Definition at line 497 of file tools.cpp. Referenced by coeffs(), and RaviartThomas::compute_basis_functions(). 00497 { 00498 GiNaC::lst lc; 00499 GiNaC::lst::const_iterator iter1, iter2; 00500 00501 for (iter1 = l.begin(); iter1 != l.end(); ++iter1) { 00502 if (GiNaC::is_a<GiNaC::lst>(*iter1)) { 00503 for (iter2 = GiNaC::ex_to<GiNaC::lst>(*iter1).begin(); iter2 != GiNaC::ex_to<GiNaC::lst>(*iter1).end(); ++iter2) { 00504 lc.append(*iter2); 00505 } 00506 } else { 00507 lc.append(*iter1); 00508 } 00509 } 00510 lc.sort(); 00511 lc.unique(); 00512 return lc; 00513 }
|
|
Definition at line 794 of file tools.cpp. Referenced by EQUAL_OR_DIE(). 00794 { 00795 std::ostringstream ss; 00796 ss<<e; 00797 string es = ss.str(); 00798 if ( es == s) return true; 00799 else return false; 00800 }
|
|
Definition at line 46 of file tools.cpp. Referenced by normal(). 00046 { 00047 GiNaC::lst ret; 00048 if ( v1.nops() != v2.nops() ) { 00049 cout <<"incompatible vectors "<<endl; 00050 cout <<"v1.nops() "<<v1.nops(); 00051 cout <<" v2.nops() "<<v2.nops()<<endl; ; 00052 return GiNaC::lst(); 00053 } 00054 ret.append( v1.op(1)*v2.op(2) - v1.op(2)*v2.op(1)); 00055 ret.append(- v1.op(0)*v2.op(2) + v1.op(2)*v2.op(0)); 00056 ret.append( v1.op(0)*v2.op(1) - v1.op(1)*v2.op(0)); 00057 return ret; 00058 }
|
|
Definition at line 422 of file tools.cpp. Referenced by CrouzeixRaviart::compute_basis_functions(), LagrangeFE::compute_basis_functions(), and main().
|
|
Definition at line 339 of file tools.cpp. References DUMMY, nsd, x, y, and z. 00339 { 00340 GiNaC::ex ret = DUMMY; 00341 if (GiNaC::is_a<GiNaC::matrix>(v)) { 00342 GiNaC::matrix m = GiNaC::ex_to<GiNaC::matrix>(v); 00343 if (nsd == 1) { 00344 ret = diff(m,x); 00345 } else if (nsd == 2) { 00346 ret = diff(m.op(0),x) + diff(m.op(1),y) ; 00347 } else if (nsd == 3) { 00348 ret = diff(m.op(0),x) + diff(m.op(1),y) + diff(m.op(2),z) ; 00349 } 00350 } 00351 return ret; 00352 }
|
|
Definition at line 354 of file tools.cpp. 00354 { 00355 nsd = v.nops(); 00356 GiNaC::ex ret; 00357 if (nsd == 1) { 00358 ret = v.op(0).diff(x); 00359 } 00360 else if (nsd == 2) { 00361 ret = v.op(0).diff(x) + v.op(1).diff(y); 00362 } 00363 else if (nsd == 3) { 00364 ret = v.op(0).diff(x) + v.op(1).diff(y) + v.op(2).diff(z); 00365 } 00366 return ret; 00367 }
|
|
Definition at line 369 of file tools.cpp. 00369 { 00370 GiNaC::ex ret; 00371 if (nsd == 2) { 00372 ret = v[0].diff(x) + v[1].diff(y); 00373 } 00374 else if (nsd == 3) { 00375 ret = v[0].diff(x) + v[1].diff(y) + v[2].diff(z); 00376 } 00377 return ret; 00378 }
|
|
Definition at line 786 of file tools.cpp. References compare(). Referenced by main(). 00786 { 00787 if (!compare(e, string(s))) { 00788 cout <<"ERROR: expression e: " <<e<<" is not equal to "<<s<<endl; 00789 exit(-1); 00790 } 00791 }
|
|
Definition at line 516 of file tools.cpp. 00516 { 00517 00518 cout <<"no equations "<<eqns.nops()<<endl; 00519 cout <<"no variables "<<symbols.nops()<<endl; 00520 00521 GiNaC::matrix sys(eqns.nops(),symbols.nops()); 00522 GiNaC::matrix rhs(eqns.nops(),1); 00523 GiNaC::matrix vars(symbols.nops(),1); 00524 00525 for (size_t r=0; r<eqns.nops(); r++) { 00526 const GiNaC::ex eq = eqns.op(r).op(0)-eqns.op(r).op(1); // lhs-rhs==0 00527 GiNaC::ex linpart = eq; 00528 for (size_t c=0; c<symbols.nops(); c++) { 00529 const GiNaC::ex co = eq.coeff(GiNaC::ex_to<GiNaC::symbol>(symbols.op(c)),1); 00530 linpart -= co*symbols.op(c); 00531 sys(r,c) = co; 00532 } 00533 linpart = linpart.expand(); 00534 rhs(r,0) = -linpart; 00535 } 00536 cout <<"matrix "<<sys<<endl; 00537 cout <<"rhs "<<rhs<<endl; 00538 cout <<"vars"<<vars<<endl; 00539 return sys; 00540 }
|
|
Definition at line 474 of file tools.cpp. 00474 { 00475 GiNaC::ex lhs = rel.lhs(); 00476 GiNaC::ex rhs = rel.rhs(); 00477 00478 GiNaC::ex l; 00479 GiNaC::ex r; 00480 00481 GiNaC::lst eqs; 00482 00483 for (int i=lhs.ldegree(x); i<=lhs.degree(x); ++i) { 00484 for (int j=lhs.ldegree(y); j<=lhs.degree(y); ++j) { 00485 for (int k=lhs.ldegree(z); k<=lhs.degree(z); ++k) { 00486 l = lhs.coeff(x,i).coeff(y, j).coeff(z,k); 00487 r = rhs.coeff(x,i).coeff(y, j).coeff(z,k); 00488 // if (! (l == 0 && r == 0 ) ) eqs.append(l == r); OLD VERSION 00489 if ( (l != 0 && (r == 0 || r == 1) ) ) eqs.append(l == r); 00490 } 00491 } 00492 } 00493 eqs.sort(); 00494 return eqs; 00495 }
|
|
Definition at line 657 of file tools.cpp. Referenced by check_visitor(). 00657 { 00658 for (int i=0; i< list.nops(); i++) { 00659 if ( e == list.op(i) ) return i; 00660 } 00661 return -1; 00662 }
|
|
Definition at line 542 of file tools.cpp. Referenced by compute_nlconvdiff_element_matrix(), compute_Poisson_element_matrix(), compute_poisson_element_matrix(), compute_Stokes_element_matrix(), main(), poisson(), poisson_reference(), and usage(). 00542 { 00543 if (GiNaC::is_a<GiNaC::matrix>(f)) { 00544 GiNaC::matrix m = GiNaC::ex_to<GiNaC::matrix>(f); 00545 GiNaC::matrix ret_m(nsd,m.rows()); 00546 for (int r=0; r< m.rows(); r++) { 00547 if (nsd == 1) { 00548 ret_m(0,r) = diff(m.op(r),x); 00549 } else if ( nsd == 2) { 00550 ret_m(0,r) = diff(m.op(r),x); 00551 ret_m(1,r) = diff(m.op(r),y); 00552 } else if ( nsd == 3) { 00553 ret_m(0,r) = diff(m.op(r),x); 00554 ret_m(1,r) = diff(m.op(r),y); 00555 ret_m(2,r) = diff(m.op(r),z); 00556 } 00557 } 00558 return ret_m; 00559 } else { 00560 00561 if (nsd == 1) { 00562 return GiNaC::matrix(nsd,1,GiNaC::lst(diff(f,x))); 00563 } else if ( nsd == 2) { 00564 return GiNaC::matrix(nsd,1,GiNaC::lst(diff(f,x), diff(f,y))); 00565 } else if ( nsd == 3) { 00566 return GiNaC::matrix(nsd,1,GiNaC::lst(diff(f,x), diff(f,y), diff(f,z))); 00567 } else { 00568 //FIXME: proper error handling 00569 cout <<"THIS SHOULD NEVER HAPPEN"; 00570 return GiNaC::lst(); 00571 } 00572 } 00573 }
|
|
Definition at line 113 of file tools.cpp. References inner(). 00113 { 00114 GiNaC::ex ret; 00115 if ( v1.nops() != v2.nops() ) { 00116 cout <<"incompatible vectors "<<endl; 00117 cout <<"v1.nops() "<<v1.nops(); 00118 cout <<" v2.nops() "<<v2.nops()<<endl; ; 00119 return 0; 00120 } 00121 int i; 00122 for (i = 0; i <= v1.nops()-1 ; ++i) { 00123 if ( GiNaC::is_a<GiNaC::lst>(v1.op(i)) && 00124 GiNaC::is_a<GiNaC::lst>(v2.op(i)) ) { 00125 ret += inner(GiNaC::ex_to<GiNaC::lst>(v1.op(i)), 00126 GiNaC::ex_to<GiNaC::lst>(v2.op(i))); 00127 } else { 00128 ret += v1.op(i)*v2.op(i); 00129 } 00130 } 00131 return ret; 00132 }
|
|
Definition at line 149 of file tools.cpp. 00149 { 00150 GiNaC::ex ret; 00151 for (int i=0; i< v1.size(); i++) { 00152 ret += v1[i]*v2[i]; 00153 } 00154 return ret; 00155 }
|
|
Definition at line 60 of file tools.cpp. References DUMMY, and inner(). 00060 { 00061 if (GiNaC::is_a<GiNaC::matrix>(a) && GiNaC::is_a<GiNaC::matrix>(b)) { 00062 GiNaC::matrix ma = GiNaC::ex_to<GiNaC::matrix>(a); 00063 GiNaC::matrix mb = GiNaC::ex_to<GiNaC::matrix>(b); 00064 if ( !transposed ) { 00065 if (ma.cols() != mb.cols() || ma.rows() != mb.rows() ) { 00066 cout <<"Incompatible matrices "<<endl; 00067 cout <<"a.cols() "<<ma.cols()<<endl; 00068 cout <<"a.rows() "<<ma.rows()<<endl; 00069 cout <<"b.cols() "<<mb.cols()<<endl; 00070 cout <<"b.rows() "<<mb.rows()<<endl; 00071 cout <<"a="<<a<<endl; 00072 cout <<"b="<<b<<endl; 00073 return DUMMY; 00074 } 00075 00076 GiNaC::ex ret; 00077 for (int i=0; i<ma.rows(); i++) { 00078 for (int j=0; j<ma.cols(); j++) { 00079 ret += ma(i,j)*mb(i,j); 00080 } 00081 } 00082 return ret; 00083 } 00084 else { 00085 if (ma.cols() != mb.rows() || ma.rows() != mb.cols() ) { 00086 cout <<"Incompatible matrices "<<endl; 00087 cout <<"a.cols() "<<ma.cols()<<endl; 00088 cout <<"a.rows() "<<ma.rows()<<endl; 00089 cout <<"b.cols() "<<mb.cols()<<endl; 00090 cout <<"b.rows() "<<mb.rows()<<endl; 00091 cout <<"a="<<a<<endl; 00092 cout <<"b="<<b<<endl; 00093 return DUMMY; 00094 } 00095 00096 GiNaC::ex ret; 00097 for (int i=0; i<ma.rows(); i++) { 00098 for (int j=0; j<ma.cols(); j++) { 00099 ret += ma(i,j)*mb(j,i); 00100 } 00101 } 00102 return ret; 00103 } 00104 } else if (GiNaC::is_a<GiNaC::lst>(a) 00105 && GiNaC::is_a<GiNaC::lst>(b)) { 00106 return inner(GiNaC::ex_to<GiNaC::lst>(a), GiNaC::ex_to<GiNaC::lst>(b)); 00107 } else { 00108 return a*b; 00109 } 00110 }
|
|
Definition at line 780 of file tools.cpp. Referenced by RaviartThomas::compute_basis_functions(), Triangle::line(), Tetrahedron::line(), and Tetrahedron::triangle().
|
|
Definition at line 575 of file tools.cpp. 00575 { 00576 GiNaC::lst ret; 00577 if ( (GiNaC::is_a<GiNaC::lst>(a)) && (GiNaC::is_a<GiNaC::lst>(b)) /*&& (a.nops() == b.nops())*/ ) { 00578 for (int i=0; i<= a.nops()-1; i++) { 00579 ret.append(b.op(i) == a.op(i)); 00580 } 00581 } else if ( !(GiNaC::is_a<GiNaC::lst>(a)) && !(GiNaC::is_a<GiNaC::lst>(b))) { 00582 ret.append(b == a); 00583 } else if ( !(GiNaC::is_a<GiNaC::lst>(a)) && (GiNaC::is_a<GiNaC::lst>(b))) { 00584 ret.append(b.op(0) == a); 00585 } else { 00586 //FIXME: proper error handling 00587 cout <<"THIS SHOULD NEVER HAPPEN"<<endl; 00588 } 00589 return ret; 00590 }
|
|
Definition at line 592 of file tools.cpp. Referenced by bezier_ordinates(). 00593 { 00594 GiNaC::lst::const_iterator itr, itc; 00595 00596 // Find number of rows and columns 00597 size_t rows = l.nops(), cols = 0; 00598 for (itr = l.begin(); itr != l.end(); ++itr) { 00599 if (!GiNaC::is_a<GiNaC::lst>(*itr)) 00600 // throw (std::invalid_argument("lst_to_matrix: argument must be a list of lists")); 00601 cols = 1; 00602 if (itr->nops() > cols) 00603 cols = itr->nops(); 00604 } 00605 // Allocate and fill matrix 00606 GiNaC::matrix &M = *new GiNaC::matrix(rows, cols); 00607 M.setflag(GiNaC::status_flags::dynallocated); 00608 00609 unsigned i; 00610 for (itr = l.begin(), i = 0; itr != l.end(); ++itr, ++i) { 00611 unsigned j; 00612 if (cols == 1) { 00613 M(i, 0) = *itr; 00614 } else { 00615 for (itc = GiNaC::ex_to<GiNaC::lst>(*itr).begin(), j = 0; itc != GiNaC::ex_to<GiNaC::lst>(*itr).end(); ++itc, ++j) 00616 M(i, j) = *itc; 00617 } 00618 } 00619 return M; 00620 }
|
|
Definition at line 802 of file tools.cpp. Referenced by RaviartThomas::compute_basis_functions(). 00802 { 00803 // build matrix from equation system 00804 GiNaC::matrix sys(eqns.nops(),symbols.nops()); 00805 GiNaC::matrix rhs(eqns.nops(),1); 00806 GiNaC::matrix vars(symbols.nops(),1); 00807 00808 for (size_t r=0; r<eqns.nops(); r++) { 00809 const GiNaC::ex eq = eqns.op(r).op(0)-eqns.op(r).op(1); // lhs-rhs==0 00810 GiNaC::ex linpart = eq; 00811 for (size_t c=0; c<symbols.nops(); c++) { 00812 const GiNaC::ex co = eq.coeff(GiNaC::ex_to<GiNaC::symbol>(symbols.op(c)),1); 00813 linpart -= co*symbols.op(c); 00814 sys(r,c) = co; 00815 } 00816 linpart = linpart.expand(); 00817 rhs(r,0) = -linpart; 00818 } 00819 A = sys; 00820 b = rhs; 00821 }
|
|
Definition at line 623 of file tools.cpp. Referenced by bernstein(), bezier_ordinates(), pol(), and polb(). 00623 { 00624 if (GiNaC::is_a<GiNaC::matrix>(m)) { 00625 GiNaC::matrix A = GiNaC::ex_to<GiNaC::matrix>(m); 00626 int cols = A.cols(); 00627 int rows = A.rows(); 00628 00629 00630 GiNaC::lst ret; 00631 if ( cols == 1 ) { 00632 for (int i=0; i<=A.rows()-1; i++) { 00633 ret.append(A(i,0)); 00634 } 00635 } else if ( rows == 1 ) { 00636 for (int i=0; i<=A.cols()-1; i++) { 00637 ret.append(A(0,i)); 00638 } 00639 } else { 00640 for (int i=0; i<=A.rows()-1; i++) { 00641 GiNaC::lst rl; 00642 for (int j=0; j<=A.cols()-1; j++) { 00643 rl.append(A(i,j)); 00644 } 00645 ret.append(rl); 00646 } 00647 } 00648 return ret; 00649 } else { 00650 return GiNaC::lst(); 00651 } 00652 00653 }
|
|
Definition at line 134 of file tools.cpp. 00134 { 00135 GiNaC::lst ret; 00136 int nr = M.rows(); 00137 int nc = M.cols(); 00138 for (int i = 0; i < nr; i++) { 00139 GiNaC::ex tmp; 00140 for (int j = 0; j < nc; j++) { 00141 tmp = tmp + M(i,j)*(x.op(j)); 00142 } 00143 ret.append(tmp); 00144 } 00145 return ret; 00146 }
|
|
Definition at line 160 of file tools.cpp. References matrix_to_lst2(), x, y, and z. Referenced by bernsteinv(), LagrangeFE::compute_basis_functions(), main(), and polv(). 00160 { 00161 GiNaC::ex ret; // ex to return 00162 int dof; // degrees of freedom 00163 GiNaC::ex A; // ex holding the coefficients a_0 .. a_dof 00164 GiNaC::lst basis; 00165 00166 00167 if (nsd == 1) { 00168 /* 1D: 00169 * P^n = a_0 + a_1*x + .... + a_n*x^n 00170 * dof : n+1 00171 */ 00172 dof = order+1; 00173 A = GiNaC::symbolic_matrix(1,dof, a); 00174 int o=0; 00175 for (GiNaC::const_iterator i = A.begin(); i != A.end(); ++i) { 00176 ret += (*i)*pow(x,o); 00177 basis.append(pow(x,o)); 00178 o++; 00179 } 00180 } 00181 else if ( nsd == 2) { 00182 00183 /* 2D: structure of coefficients (a_i) 00184 * [ a_0 a_1 x a_3 x^2 a_6 x^3 00185 * [ a_2 y a_4 xy a_7 x^2y 00186 * [ a_5 y^2 a_8 xy^2 00187 * [ a_9 y^3 00188 */ 00189 dof = (order+1)*(order+2)/2; 00190 A = GiNaC::symbolic_matrix(1, dof , a); 00191 00192 size_t i=0; 00193 for (int o = 0; o <= order; o++) { 00194 for (int d = 0; d <= o; d++) { 00195 ret += A.op(i)*pow(y,d)*pow(x,o-d); 00196 basis.append(pow(y,d)*pow(x,o-d)); 00197 i++; 00198 } 00199 } 00200 } 00201 else if (nsd = 3) { 00202 00203 /* Similar structure as in 2D, but 00204 * structured as a tetraheder, i.e., 00205 * a_o + a_1 x + a_2 y + a_3 z 00206 * + a_4 x^2 + a_5 xy + 00207 */ 00208 dof = 0; 00209 for (int j=0; j<= order; j++) { 00210 dof += (j+1)*(j+2)/2; 00211 } 00212 A = GiNaC::symbolic_matrix(1, dof , a); 00213 00214 00215 size_t i=0; 00216 for (int o = 0; o <= order; o++) { 00217 for (int d = 0; d <= o; d++) { 00218 for (int f = 0; f <= o; f++) { 00219 if ( o-d-f >= 0) { 00220 ret += A.op(i)*pow(y,f)*pow(z,d)*pow(x,o-d-f); 00221 basis.append(pow(y,f)*pow(z,d)*pow(x,o-d-f)); 00222 i++; 00223 } 00224 } 00225 } 00226 } 00227 } 00228 return GiNaC::lst(ret,matrix_to_lst2(A), basis); 00229 }
|
|
Definition at line 427 of file tools.cpp. 00427 { 00428 GiNaC::ex c; 00429 GiNaC::ex b; 00430 ex_ex_map map; 00431 for (int i=e.ldegree(x); i<=e.degree(x); ++i) { 00432 for (int j=e.ldegree(y); j<=e.degree(y); ++j) { 00433 for (int k=e.ldegree(z); k<=e.degree(z); ++k) { 00434 c = e.coeff(x,i).coeff(y, j).coeff(z,k); 00435 b = pow(x,i)*pow(y,j)*pow(z,k); 00436 map[b] = c; 00437 } 00438 } 00439 } 00440 return map; 00441 }
|
|
Definition at line 269 of file tools.cpp. References matrix_to_lst2(), x, y, and z. 00269 { 00270 00271 GiNaC::ex ret; // ex to return 00272 int dof; // degrees of freedom 00273 GiNaC::ex A; // ex holding the coefficients a_0 .. a_dof 00274 GiNaC::lst basis; 00275 00276 if (nsd == 1) { 00277 /* 1D: 00278 * P^n = a_0 + a_1*x + .... + a_n*x^n 00279 * dof : n+1 00280 */ 00281 dof = order+1; 00282 A = GiNaC::symbolic_matrix(1,dof, a); 00283 int o=0; 00284 for (GiNaC::const_iterator i = A.begin(); i != A.end(); ++i) { 00285 ret += (*i)*pow(x,o); 00286 basis.append(pow(x,o)); 00287 o++; 00288 } 00289 } 00290 else if ( nsd == 2) { 00291 00292 /* 2D: structure of coefficients (a_i) 00293 * [ a_0 a_1 x a_3 x^2 a_6 x^3 00294 * [ a_2 y a_4 xy a_7 x^2y 00295 * [ a_5 y^2 a_8 xy^2 00296 * [ a_9 y^3 00297 */ 00298 00299 00300 dof = (order+1)*(order+1); 00301 A = GiNaC::symbolic_matrix(1, dof , a); 00302 00303 00304 size_t i=0; 00305 for (int o = 0; o <= order; o++) { 00306 for (int d = 0; d <= order; d++) { 00307 ret += A.op(i)*pow(y,d)*pow(x,o); 00308 basis.append(pow(y,d)*pow(x,o)); 00309 i++; 00310 } 00311 } 00312 } 00313 else if (nsd = 3) { 00314 00315 /* Similar structure as in 2D, but 00316 * structured as a tetraheder, i.e., 00317 * a_o + a_1 x + a_2 y + a_3 z 00318 * + a_4 x^2 + a_5 xy + 00319 */ 00320 dof = (order+1)*(order+1)*(order+1); 00321 A = GiNaC::symbolic_matrix(1, dof , a); 00322 00323 00324 size_t i=0; 00325 for (int o = 0; o <= order; o++) { 00326 for (int d = 0; d <= order; d++) { 00327 for (int f = 0; f <= order; f++) { 00328 ret += A.op(i)*pow(y,f)*pow(z,d)*pow(x,o); 00329 basis.append(pow(y,f)*pow(z,d)*pow(x,o)); 00330 i++; 00331 } 00332 } 00333 } 00334 } 00335 00336 return GiNaC::lst(ret,matrix_to_lst2(A), basis); 00337 }
|
|
Definition at line 231 of file tools.cpp. References pol(). 00231 { 00232 GiNaC::lst ret1; // contains the polynom 00233 GiNaC::lst ret2; // contains the coefficients 00234 GiNaC::lst ret3; // constains the basis functions 00235 GiNaC::lst basis_tmp; 00236 for (int i=1; i<= nsd; i++) { 00237 GiNaC::lst basis; 00238 std::ostringstream s; 00239 s <<a<<""<<i<<"_"; 00240 GiNaC::ex polspace = pol(order, nsd, s.str()); 00241 ret1.append(polspace.op(0)); 00242 ret2.append(polspace.op(1)); 00243 basis_tmp = GiNaC::ex_to<GiNaC::lst>(polspace.op(2)); 00244 for (GiNaC::lst::const_iterator basis_iterator = basis_tmp.begin(); 00245 basis_iterator != basis_tmp.end(); ++basis_iterator) { 00246 GiNaC::lst tmp_lst; 00247 for (int d=1; d<=nsd; d++) tmp_lst.append(0); 00248 tmp_lst.let_op(i-1) = (*basis_iterator); 00249 ret3.append(tmp_lst); 00250 } 00251 } 00252 return GiNaC::lst(ret1,ret2,ret3); 00253 00254 00255 00256 /* Old Code: 00257 GiNaC::lst ret; 00258 for (int i=1; i<= nsd; i++) { 00259 std::ostringstream s; 00260 s <<a<<"^"<<i<<"_"; 00261 GiNaC::ex p = pol(order, nsd, s.str()); 00262 ret.append(p); 00263 } 00264 return ret; 00265 */ 00266 }
|
|
Definition at line 824 of file tools.cpp. 00824 { 00825 map<std::pair<int,int>,GiNaC::ex>::iterator iter; 00826 for (iter = A.begin(); iter != A.end() ; iter++) { 00827 cout <<"A["<<(*iter).first.first<<","<<(*iter).first.second<<"]="<<(*iter).second<<endl; 00828 } 00829 }
|
|
Definition at line 443 of file tools.cpp. 00443 { 00444 GiNaC::ex b; 00445 int c; 00446 ex_int_it iter; 00447 iter = map.begin(); 00448 cout <<"{" <<b<<":"<<c; 00449 for (iter = map.begin(); iter != map.end(); iter++) { 00450 b = (*iter).first; c = map[b]; 00451 cout <<", "<<b<<":"<<c; 00452 } 00453 cout <<"}"<<endl; 00454 00455 }
|
|
Definition at line 459 of file tools.cpp. 00459 { 00460 GiNaC::ex b; 00461 GiNaC::ex c; 00462 ex_ex_it iter; 00463 iter = map.begin(); 00464 cout <<"{" <<b<<":"<<c; 00465 for (iter = map.begin(); iter != map.end(); iter++) { 00466 b = (*iter).first; c = map[b]; 00467 cout <<", "<<b<<":"<<c; 00468 } 00469 cout <<"}"<<endl; 00470 00471 }
|
|
Definition at line 23 of file tools.cpp. 00023 { 00024 // for (GiNaC::lst::const_iterator i = l.begin(); i != l.end(); ++i) 00025 // cout << *i << endl; 00026 // 00027 GiNaC::lst::const_iterator i = l.begin(); 00028 cout <<"GiNaC::lst("<<*i; 00029 ++i; 00030 00031 for (; i != l.end() ; ++i) { 00032 cout << ","<< *i; 00033 } 00034 cout <<");"<<endl; 00035 }
|
|
Definition at line 37 of file tools.cpp. 00037 { 00038 cout <<"v=["; 00039 for (int i=0; i< v.size()-1; i++) { 00040 cout <<v[i]<<"," <<endl; 00041 } 00042 cout <<v[v.size()-1]<< "]"<<endl; 00043 00044 }
|
|
Definition at line 664 of file tools.cpp. References visitor_subst_pow(). Referenced by visitor_subst_pow(). 00664 { 00665 static int i=0; 00666 if (map.find(e) != map.end()) { 00667 intmap[e] = intmap[e]+1; 00668 return; 00669 } 00670 if (GiNaC::is_exactly_a<GiNaC::power>(e)) { 00671 std::ostringstream s; 00672 s <<a<<i++; 00673 map[e] = GiNaC::symbol(s.str()); 00674 intmap[e] = 0; 00675 for (int i=0; i< e.nops(); i++) { 00676 GiNaC::ex e2 = e.op(i); 00677 // cout <<"power e "<<e2<<endl; 00678 visitor_subst_pow(e2,map,intmap, a); 00679 } 00680 } 00681 else if (GiNaC::is_a<GiNaC::function>(e)) { 00682 std::ostringstream s; 00683 s <<a<<i++; 00684 map[e] = GiNaC::symbol(s.str()); 00685 intmap[e] = 0; 00686 for (int i=0; i< e.nops(); i++) { 00687 GiNaC::ex e2 = e.op(i); 00688 // cout <<"function e "<<e2<<endl; 00689 visitor_subst_pow(e2,map,intmap, a); 00690 } 00691 } 00692 else if (GiNaC::is_a<GiNaC::mul>(e)) { 00693 if (e.nops() > 4 && e.nops() < 10 ) { 00694 std::ostringstream s; 00695 s <<a<<i++; 00696 map[e] = GiNaC::symbol(s.str()); 00697 intmap[e] = 0; 00698 } 00699 00700 for (int i=0; i< e.nops(); i++) { 00701 GiNaC::ex e2 = e.op(i); 00702 visitor_subst_pow(e2,map,intmap, a); 00703 } 00704 } 00705 else if (GiNaC::is_a<GiNaC::add>(e)) { 00706 for (int i=0; i< e.nops(); i++) { 00707 GiNaC::ex e2 = e.op(i); 00708 visitor_subst_pow(e2,map,intmap,a); 00709 } 00710 } 00711 00712 00713 }
|
|
Referenced by barycenter_line(), barycenter_triangle(), Square::boundary_node(), div(), inner(), and Square::triangle(). |
|
|
|
Definition at line 9 of file tools.cpp. Referenced by bernsteinv(), check_RaviartThomas(), div(), grad(), and main(). |
|
|
|