| 1 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
// vi: set et ts=4 sw=2 sts=2: |
| 3 |
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 4 |
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception |
| 5 |
#ifndef DUNE_DEFAULTBASISFACTORY_HH |
| 6 |
#define DUNE_DEFAULTBASISFACTORY_HH |
| 7 |
|
| 8 |
#include <fstream> |
| 9 |
#include <dune/common/exceptions.hh> |
| 10 |
|
| 11 |
#include <dune/localfunctions/utility/basismatrix.hh> |
| 12 |
|
| 13 |
namespace Dune |
| 14 |
{ |
| 15 |
struct Identity |
| 16 |
{ |
| 17 |
template <class T> |
| 18 |
static T apply( const T &t ) |
| 19 |
{ |
| 20 |
return t; |
| 21 |
} |
| 22 |
}; |
| 23 |
/************************************************ |
| 24 |
* Class for providing a factory for basis |
| 25 |
* functions over the set of reference elements. |
| 26 |
* Is based on the TopologyFactory but additionally |
| 27 |
* provides rebindes of the field type. |
| 28 |
* The user provides factories for the pre basis and the |
| 29 |
* interpolations. The default construction process of |
| 30 |
* the basis is performed in this class. |
| 31 |
************************************************/ |
| 32 |
template< class PreBFactory, |
| 33 |
class InterpolFactory, |
| 34 |
unsigned int dim, unsigned int dimR, |
| 35 |
class D, class R, |
| 36 |
class SF, class CF, |
| 37 |
class PreBasisKeyExtractor = Identity > |
| 38 |
struct DefaultBasisFactory |
| 39 |
{ |
| 40 |
static const unsigned int dimension = dim; |
| 41 |
static const unsigned int dimRange = dimR; |
| 42 |
typedef D Domain; |
| 43 |
typedef R Range; |
| 44 |
typedef SF StorageField; |
| 45 |
typedef CF ComputeField; |
| 46 |
typedef PreBFactory PreBasisFactory; |
| 47 |
typedef typename PreBasisFactory::Object PreBasis; |
| 48 |
typedef InterpolFactory InterpolationFactory; |
| 49 |
typedef typename InterpolationFactory::Object Interpolation; |
| 50 |
typedef typename PreBasisFactory::template EvaluationBasisFactory<dim,SF>::Type MonomialBasisFactory; |
| 51 |
typedef typename MonomialBasisFactory::Object MonomialBasis; |
| 52 |
typedef StandardEvaluator< MonomialBasis > Evaluator; |
| 53 |
typedef PolynomialBasisWithMatrix< Evaluator, SparseCoeffMatrix< SF, dimRange >, D, R > Basis; |
| 54 |
|
| 55 |
typedef const Basis Object; |
| 56 |
typedef typename InterpolationFactory::Key Key; |
| 57 |
template <unsigned int dd, class FF> |
| 58 |
struct EvaluationBasisFactory |
| 59 |
{ |
| 60 |
typedef typename PreBasisFactory::template EvaluationBasisFactory<dd,FF>::Type |
| 61 |
Type; |
| 62 |
}; |
| 63 |
|
| 64 |
template< GeometryType::Id geometryId > |
| 65 |
static Object *create ( const Key &key ) |
| 66 |
{ |
| 67 |
const typename PreBasisFactory::Key preBasisKey = PreBasisKeyExtractor::apply(key); |
| 68 |
const PreBasis *preBasis = PreBasisFactory::template create<geometryId>( preBasisKey ); |
| 69 |
const Interpolation *interpol = InterpolationFactory::template create<geometryId>( key ); |
| 70 |
BasisMatrix< PreBasis, Interpolation, ComputeField > matrix( *preBasis, *interpol ); |
| 71 |
|
| 72 |
const MonomialBasis *monomialBasis = MonomialBasisFactory::template create< geometryId >( preBasis->order() ); |
| 73 |
|
| 74 |
Basis *basis = new Basis( *monomialBasis ); |
| 75 |
|
| 76 |
basis->fill( matrix ); |
| 77 |
|
| 78 |
InterpolationFactory::release(interpol); |
| 79 |
PreBasisFactory::release(preBasis); |
| 80 |
|
| 81 |
return basis; |
| 82 |
} |
| 83 |
//! release the object returned by the create methods |
| 84 |
static void release( Object *object) |
| 85 |
{ |
| 86 |
const MonomialBasis *monomialBasis = &(object->basis()); |
| 87 |
delete object; |
| 88 |
MonomialBasisFactory::release( monomialBasis ); |
| 89 |
} |
| 90 |
}; |
| 91 |
} |
| 92 |
|
| 93 |
#endif // #ifndef DUNE_DEFAULTBASISFACTORY_HH |