From f223dabbdcb32242940299c5f727ffe3d64fddd7 Mon Sep 17 00:00:00 2001 From: hartmann Date: Tue, 11 Feb 2003 14:55:13 +0000 Subject: [PATCH] Move MGLevelObject from mg_base.h to separate file. For the history of the MGLevelObject class please refer to the history of the mg_base.h file. git-svn-id: https://svn.dealii.org/trunk@7077 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/multigrid/mg_level_object.h | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 deal.II/deal.II/include/multigrid/mg_level_object.h diff --git a/deal.II/deal.II/include/multigrid/mg_level_object.h b/deal.II/deal.II/include/multigrid/mg_level_object.h new file mode 100644 index 0000000000..62f082d533 --- /dev/null +++ b/deal.II/deal.II/include/multigrid/mg_level_object.h @@ -0,0 +1,173 @@ +//-------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//-------------------------------------------------------------------- +#ifndef __deal2__mg_level_object_h +#define __deal2__mg_level_object_h + + +/** + * An array with an object for each level. The purpose of this class + * is mostly to allow access by level number, even if the lower levels + * are not used and therefore have no object at all; this is done by + * simply shifting the given index by the minimum level we have + * stored. + * + * In most cases, the objects which are stored on each levels, are + * either matrices or vectors. + * + * @author Wolfgang Bangerth, Guido Kanschat, 1999 + */ +template +class MGLevelObject : public Subscriptor +{ + public: + /** + * Constructor allowing to + * initialize the number of + * levels. By default, the object + * is created empty. + */ + MGLevelObject (const unsigned int minlevel = 0, + const unsigned int maxlevel = 0); + + /** + * Access object on level @p{level}. + */ + Object & operator[] (const unsigned int level); + + /** + * Access object on level + * @p{level}. Constant version. + */ + const Object & operator[] (const unsigned int level) const; + + /** + * Delete all previous contents + * of this object and reset its + * size according to the values + * of @p{new_minlevel} and + * @p{new_maxlevel}. + */ + void resize (const unsigned int new_minlevel, + const unsigned int new_maxlevel); + + /** + * Call @p{clear} on all objects + * stored by this object. This + * function is only implemented + * for some @p{Object} classes, + * most notably for vectors and + * matrices. Note that if + * @p{Object==Vector}, @p{clear} + * will set all entries to zero, + * while if + * @p{Object==vector}, + * @p{clear} deletes the elements + * of the vectors. This class + * might therefore not be useful + * for STL vectors. + */ + void clear(); + + ////// + unsigned int get_minlevel () const; + unsigned int get_maxlevel () const; + + private: + /** + * Level of first component. + */ + unsigned int minlevel; + + /** + * Array of the objects to be held. + */ + std::vector objects; +}; + + +/* ------------------------------------------------------------------- */ + + +template +MGLevelObject::MGLevelObject(const unsigned int min, + const unsigned int max) + : + minlevel(0) +{ + resize (min, max); +} + + +template +Object & +MGLevelObject::operator[] (const unsigned int i) +{ + Assert((i>=minlevel) && (i +const Object & +MGLevelObject::operator[] (const unsigned int i) const +{ + Assert((i>=minlevel) && (i +void +MGLevelObject::resize (const unsigned int new_minlevel, + const unsigned int new_maxlevel) +{ + Assert (new_minlevel <= new_maxlevel, ExcInternalError()); + objects.clear (); + + minlevel = new_minlevel; + objects.resize (new_maxlevel - new_minlevel + 1); +} + + +template +void +MGLevelObject::clear () +{ + typename std::vector::iterator v; + for (v = objects.begin(); v != objects.end(); ++v) + v->clear(); +} + + +template +unsigned int +MGLevelObject::get_minlevel () const +{ + return minlevel; +} + + +template +unsigned int +MGLevelObject::get_maxlevel () const +{ + return minlevel + objects.size() - 1; +} + + +/*----------------------- mg_level_object.h -----------------------*/ + +#endif +/*----------------------- mg_level_object.h -----------------------*/ -- 2.39.5