Skip to content

Commit

Permalink
added boundaries to grid; cut in the subspace scheme is not diagonal:
Browse files Browse the repository at this point in the history
ooooo
ooooo
oooo
ooo
oo

so the boundaries havn't more points


git-svn-id: https://ipvs.informatik.uni-stuttgart.de/SGpp/repos/trunk@143 4eea3252-f0fb-4393-894d-40516dce545b
  • Loading branch information
Alexander Heinecke committed Feb 13, 2009
1 parent 809f956 commit f8e3c3a
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pysgpp/GridFactory.i
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/*****************************************************************************/

%newobject sg::Grid::createLinearGrid(size_t dim);
%newobject sg::Grid::createLinearBoundaryGrid(size_t dim);
%newobject sg::Grid::createModLinearGrid(size_t dim);
%newobject sg::Grid::createPolyGrid(size_t dim, size_t degree);
%newobject sg::Grid::createModPolyGrid(size_t dim, size_t degree);
Expand All @@ -48,6 +49,7 @@ class Grid
{
public:
static Grid* createLinearGrid(size_t dim);
static Grid* createLinearBoundaryGrid(size_t dim);
static Grid* createModLinearGrid(size_t dim);
static Grid* createPolyGrid(size_t dim, size_t degree);
static Grid* createModPolyGrid(size_t dim, size_t degree);
Expand Down
2 changes: 2 additions & 0 deletions pysgpp/Operations.i
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class GridGenerator
{
public:
virtual void regular(size_t level) = 0;
virtual void regularBoundaries(size_t level) = 0;
virtual void regularFullBoundaries(size_t level) = 0;
virtual void refine(RefinementFunctor* func) = 0;
};

Expand Down
2 changes: 2 additions & 0 deletions pysgpp/pysgpp.i
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace std {
%include "sg++/algorithm/UnidirGradient.hpp"

%include "sg++/basis/linear/linear_base.hpp"
%include "sg++/basis/linearboundary/linearboundaryBase.hpp"
%include "sg++/basis/modlinear/modified_linear_base.hpp"
%include "sg++/basis/modpoly/modified_poly_base.hpp"
%include "sg++/basis/poly/poly_base.hpp"
Expand All @@ -95,6 +96,7 @@ namespace std {
%template(GridStorage) sg::HashGridStorage<sg::GridIndex>;

%template(SLinearBase) sg::linear_base<unsigned int, unsigned int>;
%template(SLinearBoundaryBase) sg::linearboundaryBase<unsigned int, unsigned int>;
%template(SModLinearBase) sg::modified_linear_base<unsigned int, unsigned int>;
%template(SPolyBase) sg::poly_base<unsigned int, unsigned int>;
%template(SModPolyBase) sg::modified_poly_base<unsigned int, unsigned int>;
Expand Down
1 change: 1 addition & 0 deletions sg++/basis/basis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define BASIS_HPP

#include "basis/linear/linear_base.hpp"
#include "basis/linearboundary/linearboundaryBase.hpp"
#include "basis/modlinear/modified_linear_base.hpp"
#include "basis/modpoly/modified_poly_base.hpp"
#include "basis/modwavelet/modified_wavelet_base.hpp"
Expand Down
65 changes: 65 additions & 0 deletions sg++/basis/linearboundary/linearboundaryBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*****************************************************************************/
/* This file is part of sg++, a program package making use of spatially */
/* adaptive sparse grids to solve numerical problems */
/* */
/* Copyright (C) 2009 Alexander Heinecke (Alexander.Heinecke@mytum.de) */
/* */
/* sg++ is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* sg++ is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with sg++; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* or see <http://www.gnu.org/licenses/>. */
/*****************************************************************************/

#ifndef LINEARBOUNDARYBASE_HPP
#define LINEARBOUNDARYBASE_HPP

#include <cmath>

namespace sg
{

/**
* linear base functions with boundaries
* And here we have another implicit dependence on tensor products
*/
template<class LT, class IT>
class linearboundaryBase
{
public:
/**
* Evaluate a base functions.
* Has a dependence on the absolute position of grid point and support.
*/
double eval(LT level, IT index, double p)
{
if (level == 0)
{
if (index == 1)
{

}
if (index == 3)
{

}
}
else
{
return 1.0 - fabs((1<<level) * p - index);
}
}
};

}

#endif /* LINEARBOUNDARYBASE_HPP */
1 change: 1 addition & 0 deletions sg++/grid/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Grid
{
public:
static Grid* createLinearGrid(size_t dim);
static Grid* createLinearBoundaryGrid(size_t dim);
static Grid* createModLinearGrid(size_t dim);
static Grid* createPolyGrid(size_t dim, size_t degree);
static Grid* createModPolyGrid(size_t dim, size_t degree);
Expand Down
2 changes: 2 additions & 0 deletions sg++/grid/generation/GridGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class GridGenerator
virtual ~GridGenerator() {}

virtual void regular(size_t level) = 0;
virtual void regularBoundaries(size_t level) = 0;
virtual void regularFullBoundaries(size_t level) = 0;
virtual void refine(RefinementFunctor* func) = 0;
};

Expand Down
2 changes: 2 additions & 0 deletions sg++/grid/generation/StandardGridGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class StandardGridGenerator : public GridGenerator
virtual ~StandardGridGenerator();

virtual void regular(size_t level);
virtual void regularBoundaries(size_t level);
virtual void regularFullBoundaries(size_t level);
virtual void refine(RefinementFunctor* func);

protected:
Expand Down
92 changes: 87 additions & 5 deletions sg++/grid/generation/hashmap/HashGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class HashGenerator
typedef index_type::level_type level_t;


/*
* Generates a regular sparse grid of level levels
* TODO: level should be of type level_t but swig doesnt want that
*/
/**
* Generates a regular sparse grid of level levels
* TODO: level should be of type level_t but swig doesnt want that
*/
void regular(GridStorage* storage, int level)
{
if(storage->size() > 0)
Expand All @@ -64,7 +64,27 @@ class HashGenerator
this->regular_rec(storage, index, storage->dim() - 1, storage->dim(), level + storage->dim() - 1);
}

/**
* Generates a regular sparse grid of level levels with boundaries
* TODO: level should be of type level_t but swig doesnt want that
*/
void regularWithBoundaries(GridStorage* storage, int level, bool fullBoundaries)
{
if(storage->size() > 0)
{
throw generation_exception("storage not empty");
}

index_type index(storage->dim());

// the boundaries are hyperplanes
for(size_t d = 0; d < storage->dim(); d++)
{
index.push(d, 1, 1);
}

this->boundaries_rec(storage, index, storage->dim() - 1, storage->dim(), level + storage->dim() - 1);
}

protected:
void regular_rec(GridStorage* storage, index_type& index, size_t current_dim, level_t current_level, level_t level)
Expand Down Expand Up @@ -94,7 +114,6 @@ class HashGenerator

index.push(current_dim, source_level + 1, 2*source_index + 1);
this->regular_rec(storage, index, current_dim, current_level + 1, level);

}

index.push(current_dim, source_level, source_index);
Expand All @@ -112,6 +131,69 @@ class HashGenerator
}
}
}

void boundaries_rec(GridStorage* storage, index_type& index, size_t current_dim, level_t current_level, level_t level)
{
if(current_dim == 0)
{
boundaries_rec_1d(storage, index, current_level, level);
}
else
{
index_t source_index;
level_t source_level;

index.get(current_dim, source_level, source_index);

if(current_level <= level)
{
// d-1 recursion
this->boundaries_rec(storage, index, current_dim - 1, current_level, level);
}

if(current_level < level)
{
if (source_level == 1)
{
index.push(current_dim, 0, 0);
this->boundaries_rec(storage, index, current_dim-1, current_level, level);

index.push(current_dim, 0, 1);
this->boundaries_rec(storage, index, current_dim-1, current_level, level);
}

index.push(current_dim, source_level + 1, 2*source_index - 1);
this->boundaries_rec(storage, index, current_dim, current_level + 1, level);

index.push(current_dim, source_level + 1, 2*source_index + 1);
this->boundaries_rec(storage, index, current_dim, current_level + 1, level);
}

index.push(current_dim, source_level, source_index);
}
}

void boundaries_rec_1d(GridStorage* storage, index_type& index, level_t current_level, level_t level)
{
for(level_t l = 0; l <= level-current_level + 1; l++)
{
if (l == 0)
{
index.push(0, 0, 0);
storage->insert(index);
index.push(0, 0, 1);
storage->insert(index);
}
else
{
for(index_t i = 1; i <= 1<<(l-1); i++)
{
index.push(0, l, 2*i-1);
storage->insert(index);
}
}
}
}
};

}
Expand Down
59 changes: 59 additions & 0 deletions sg++/grid/type/LinearBoundaryGrid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*****************************************************************************/
/* This file is part of sg++, a program package making use of spatially */
/* adaptive sparse grids to solve numerical problems */
/* */
/* Copyright (C) 2008 Jörg Blank (blankj@in.tum.de) */
/* Copyright (C) 2009 Alexander Heinecke (Alexander.Heinecke@mytum.de) */
/* */
/* sg++ is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* sg++ is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with sg++; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* or see <http://www.gnu.org/licenses/>. */
/*****************************************************************************/

#ifndef LINEARBOUNDARYGRID_HPP
#define LINEARBOUNDARYGRID_HPP

#include "grid/Grid.hpp"

#include <iostream>

namespace sg
{

/**
* grid with linear base functions with boundaries
*/
class LinearBoundaryGrid : public Grid
{
protected:
LinearBoundaryGrid(std::istream& istr);

public:
LinearBoundaryGrid(size_t dim);
virtual ~LinearBoundaryGrid();

virtual const char* getType();

virtual OperationB* createOperationB();
virtual GridGenerator* createGridGenerator();
virtual OperationMatrix* createOperationLaplace();
virtual OperationEval* createOperationEval();
virtual OperationHierarchisation* createOperationHierarchisation();

static Grid* unserialize(std::istream& istr);
};

}

#endif /* LINEARBOUNDARYGRID_HPP */
1 change: 1 addition & 0 deletions sg++/sgpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace sg
{

typedef linearboundaryBase<unsigned int, unsigned int> SLinearBoundaryBase;
typedef linear_base<unsigned int, unsigned int> SLinearBase;
typedef modified_linear_base<unsigned int, unsigned int> SModLinearBase;
typedef poly_base<unsigned int, unsigned int> SPolyBase;
Expand Down
6 changes: 6 additions & 0 deletions src/GridFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "grid/Grid.hpp"
#include "grid/type/LinearGrid.hpp"
#include "grid/type/LinearBoundaryGrid.hpp"
#include "grid/type/ModLinearGrid.hpp"
#include "grid/type/ModPolyGrid.hpp"
#include "grid/type/PolyGrid.hpp"
Expand All @@ -36,6 +37,11 @@ Grid* Grid::createLinearGrid(size_t dim)
return new LinearGrid(dim);
}

Grid* Grid::createLinearBoundaryGrid(size_t dim)
{
return new LinearBoundaryGrid(dim);
}

Grid* Grid::createModLinearGrid(size_t dim)
{
return new ModLinearGrid(dim);
Expand Down
Loading

0 comments on commit f8e3c3a

Please sign in to comment.