dune-localfunctions
2.1.1
|
00001 #ifndef BASISPRINT 00002 #define BASISPRINT 00003 #include <dune/localfunctions/utility/multiindex.hh> 00004 #include <dune/localfunctions/utility/polynomialbasis.hh> 00005 namespace Dune { 00006 /********************************************** 00007 * Methods for printing a PolynomialBasis. 00008 * Is achieved by using the MultiIndex class as 00009 * Field type and printing the results. 00010 * The basis and higher order derivatives can be 00011 * printed. This could be the basis for printing 00012 * routings providing C++ or matlab methods 00013 * for computing the basisfunctions for given 00014 * orders or reference elements. 00015 **********************************************/ 00016 // default argument does not work for gcc 4.1.2 00017 // template <int deriv,class BasisFactory,class PrintField=typename BasisFactory::StorageField> 00018 template <int deriv,class BasisFactory,class PrintField> 00019 void basisPrint(std::ostream &out, 00020 typename BasisFactory::Object &basis) 00021 { 00022 typedef typename BasisFactory::Object Basis; 00023 const int dimension = Basis::dimension; 00024 00025 typedef MultiIndex< dimension, PrintField > Field; 00026 typedef typename BasisFactory::template EvaluationBasisFactory<dimension,Field>::Type 00027 MIBasisFactory; 00028 typedef typename MIBasisFactory::Object MIBasis; 00029 typedef typename Basis::CoefficientMatrix CMatrix; 00030 typedef PolynomialBasis<StandardEvaluator<MIBasis>, CMatrix > PrintBasis; 00031 00032 MIBasis *miBasis = MIBasisFactory::create(basis.basis().topologyId(),basis.basis().order()); 00033 PrintBasis printBasis(*miBasis,basis.matrix(),basis.size()); 00034 00035 unsigned int size = printBasis.size(); 00036 00037 out << "% Number of base functions: " << size << std::endl; 00038 out << "% Derivative order: " << deriv << std::endl; 00039 00040 /* 00041 std::vector< FieldVector< 00042 LFETensor<Field,dimension,deriv>,PrintBasis::dimRange> > 00043 y( size ); 00044 */ 00045 std::vector< FieldVector< 00046 FieldVector<Field,LFETensor<Field,dimension,deriv>::size>, 00047 PrintBasis::dimRange> > y( size ); 00048 00049 FieldVector< Field, dimension > x; 00050 for( int i = 0; i < dimension; ++i ) 00051 x[ i ].set( i, 1 ); 00052 printBasis.template evaluateSingle<deriv>( x, y ); 00053 for (unsigned int i=0;i<size;++i) 00054 { 00055 out << "func_" << i << ":" << std::endl; 00056 out << "( "; 00057 for (unsigned int r=0;r<PrintBasis::dimRange;++r) 00058 out << y[i][r] << (r<PrintBasis::dimRange-1?" , ":" )"); 00059 out << std::endl; 00060 } 00061 MIBasisFactory::release(miBasis); 00062 } 00063 // template <int deriv,class BasisFactory,class PrintField=typename BasisFactory::StorageField> 00064 template <int deriv,class BasisFactory,class PrintField> 00065 void basisPrint(std::ostream &out, 00066 typename BasisFactory::Key &key) 00067 { 00068 typename BasisFactory::Object *basis = BasisFactory::create(key); 00069 basisPrint<deriv,BasisFactory,PrintField>(out,*basis); 00070 BasisFactory::release(basis); 00071 } 00072 } 00073 00074 00075 #endif // BASISPRINT