Skip to content
Snippets Groups Projects
Commit 5e92d724 authored by Oliver Sander's avatar Oliver Sander
Browse files

Prototyp eines Frameworks zur Berechnung von Normen von diskreten Funktionen.

Es gibt eine Basisklasse Norm<class DiscFuncType> mit einer rein virtuellen
Methode compute.  Konkrete Normen leiten von dieser Klasse ab und reimplementieren
compute.  Als Beispiel habe ich mal die L_2-Norm eingebaut.
Verwendet wird das ganze zum Beispiel in meinem LinearSolver.

Wie gesagt ein Prototyp.  Wer Kritik oder Anregungen hat möge sie äußern!

[[Imported from SVN: r590]]
parent 38636ec6
No related branches found
No related tags found
No related merge requests found
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef __DUNE_L2NORM_HH__
#define __DUNE_L2NORM_HH__
#include <dune/fem/norms/norm.hh>
#include <dune/fem/fastquad.hh>
namespace Dune {
//! Class calculating the \f$ L_2 \f$ norm of a discrete function
template <class DiscreteFunctionType>
class L2Norm : public Norm<DiscreteFunctionType>
{
typedef typename DiscreteFunctionType::FunctionSpaceType FunctionSpaceType;
public:
double compute (const DiscreteFunctionType &discFunc)
{
/** \todo Automatically choose the correct quadrature order */
const int polOrd = 2;
const typename DiscreteFunctionType::FunctionSpace
& functionSpace_= discFunc.getFunctionSpace();
typedef typename FunctionSpaceType::GridType GridType;
typedef typename GridType::template Traits<0>::LevelIterator LevelIterator;
typedef typename DiscreteFunctionType::LocalFunctionType LocalFuncType;
GridType & grid = functionSpace_.getGrid();
const int level = grid.maxlevel();
typename FunctionSpaceType::Range phi (0.0);
double sum = 0.0;
LocalFuncType lf = (const_cast<DiscreteFunctionType*>(&discFunc))->newLocalFunction();
LevelIterator endit = grid.template lend<0> ( level );
LevelIterator it = grid.template lbegin<0> ( level );
FastQuad < typename FunctionSpaceType::RangeField,
typename FunctionSpaceType::Domain , polOrd > quad ( *it );
for(; it != endit ; ++it) {
double det = (*it).geometry().integration_element(quad.point(0));
(const_cast<DiscreteFunctionType*>(&discFunc))->localFunction(*it,lf);
for(int qP = 0; qP < quad.nop(); qP++) {
lf.evaluate((*it),quad,qP,phi);
sum += det * quad.weight(qP) * SQR(phi(0));
}
}
return sqrt(sum);
}
};
} // namespace Dune
#endif
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef __DUNE_NORM_HH__
#define __DUNE_NORM_HH__
namespace Dune {
//! Abstract base for classes computing norms of discrete functions
template <class DiscFuncType>
class Norm {
public:
//! Compute the norm
virtual double compute(const DiscFuncType& f) = 0;
};
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment