dune-localfunctions  2.2.1
basisprint.hh
Go to the documentation of this file.
1 #ifndef BASISPRINT
2 #define BASISPRINT
5 namespace Dune {
6  /**********************************************
7  * Methods for printing a PolynomialBasis.
8  * Is achieved by using the MultiIndex class as
9  * Field type and printing the results.
10  * The basis and higher order derivatives can be
11  * printed. This could be the basis for printing
12  * routings providing C++ or matlab methods
13  * for computing the basisfunctions for given
14  * orders or reference elements.
15  **********************************************/
16  // default argument does not work for gcc 4.1.2
17  // template <int deriv,class BasisFactory,class PrintField=typename BasisFactory::StorageField>
18  template <int deriv,class BasisFactory,class PrintField>
19  void basisPrint(std::ostream &out,
20  typename BasisFactory::Object &basis)
21  {
22  typedef typename BasisFactory::Object Basis;
23  const int dimension = Basis::dimension;
24 
26  typedef typename BasisFactory::template EvaluationBasisFactory<dimension,Field>::Type
27  MIBasisFactory;
28  typedef typename MIBasisFactory::Object MIBasis;
29  typedef typename Basis::CoefficientMatrix CMatrix;
30  typedef PolynomialBasis<StandardEvaluator<MIBasis>, CMatrix > PrintBasis;
31 
32  MIBasis *miBasis = MIBasisFactory::create( Dune::GeometryType( basis.basis().topologyId(),dimension ),basis.basis().order());
33  PrintBasis printBasis(*miBasis,basis.matrix(),basis.size());
34 
35  unsigned int size = printBasis.size();
36 
37  out << "% Number of base functions: " << size << std::endl;
38  out << "% Derivative order: " << deriv << std::endl;
39 
40 /*
41  std::vector< FieldVector<
42  LFETensor<Field,dimension,deriv>,PrintBasis::dimRange> >
43  y( size );
44 */
45  std::vector< FieldVector<
46  FieldVector<Field,LFETensor<Field,dimension,deriv>::size>,
47  PrintBasis::dimRange> > y( size );
48 
49  FieldVector< Field, dimension > x;
50  for( int i = 0; i < dimension; ++i )
51  x[ i ].set( i, 1 );
52  printBasis.template evaluateSingle<deriv>( x, y );
53  for (unsigned int i=0;i<size;++i)
54  {
55  out << "$\\varphi_" << i << "(a,b,c)$&$=$&$" << std::endl;
56  out << "( ";
57  for (unsigned int r=0;r<PrintBasis::dimRange;++r)
58  out << y[i][r] << (r<PrintBasis::dimRange-1?" , $ \\\\ && $":" )$ \\\\");
59  out << std::endl;
60  }
61  MIBasisFactory::release(miBasis);
62  }
63  // template <int deriv,class BasisFactory,class PrintField=typename BasisFactory::StorageField>
64  template <int deriv,class BasisFactory,class PrintField>
65  void basisPrint(std::ostream &out,
66  typename BasisFactory::Key &key)
67  {
68  typename BasisFactory::Object *basis = BasisFactory::create(key);
69  basisPrint<deriv,BasisFactory,PrintField>(out,*basis);
70  BasisFactory::release(basis);
71  }
72 }
73 
74 
75 #endif // BASISPRINT