From 3b6a67447bd60e2bc409faf25ae8bae371d13a78 Mon Sep 17 00:00:00 2001 From: wolf Date: Tue, 3 Sep 2002 15:24:52 +0000 Subject: [PATCH] Have the new Table class which supercedes the vector2d class. Use it. git-svn-id: https://svn.dealii.org/trunk@6346 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/data_out_base.h | 4 +- deal.II/base/include/base/table.h | 1763 +++++++++++++++++++++ deal.II/base/include/base/vector2d.h | 949 ----------- 3 files changed, 1765 insertions(+), 951 deletions(-) create mode 100644 deal.II/base/include/base/table.h delete mode 100644 deal.II/base/include/base/vector2d.h diff --git a/deal.II/base/include/base/data_out_base.h b/deal.II/base/include/base/data_out_base.h index 583149f510..0f6b50a1b5 100644 --- a/deal.II/base/include/base/data_out_base.h +++ b/deal.II/base/include/base/data_out_base.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include @@ -486,7 +486,7 @@ class DataOutBase * should yield the same value for all * patches provided. */ - vector2d data; + Table<2,float> data; /** * Default constructor. Sets diff --git a/deal.II/base/include/base/table.h b/deal.II/base/include/base/table.h new file mode 100644 index 0000000000..be0f1f4e39 --- /dev/null +++ b/deal.II/base/include/base/table.h @@ -0,0 +1,1763 @@ +//----------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2000, 2001, 2002 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__table_h +#define __deal2__table_h + +#include +#include + +#include +#include + + +// forward declaration +template +class TableBase; + + +/** + * Base class for an array of indices of fixed size used for the + * @ref{TableBase} class. Actually, this class serves a dual purpose, + * as it not only stores indices into said class, but also the sizes + * of the table in its various coordinates. + * + * @author Wolfgang Bangerth, 2002 + */ +template +class TableIndicesBase +{ + public: + /** + * Access the value of the + * @p{i}th index. + */ + unsigned int operator[] (const unsigned int i) const; + + protected: + /** + * Store the indices in an array. + */ + unsigned indices[N]; +}; + + +/** + * Array of indices of fixed size used for the @ref{TableBase} + * class. + * + * This is the general template, and has no implementation. There are + * a number of specializations that are actually implemented (one for + * each used value of @p{N}), which only differ in the way they + * implement their constructors (they take @p{N} arguments, something + * that cannot be represented by a general template). Actual storage + * of and access to data is done by the @ref{TableIndicesBase} base + * class of a specializations. + * + * @author Wolfgang Bangerth, 2002 + */ +template +class TableIndices +{}; + + + +/** + * Array of indices of fixed size used for the @ref{TableBase} + * class. + * + * This is the specialization for a one-dimensional table, i.e. a + * vector. This class only differs in the non-default constructors + * from the other specializations. Actual storage of and access to + * data is done by the @ref{TableIndicesBase} base class of a + * specializations. + * + * @author Wolfgang Bangerth, 2002 + */ +template <> +class TableIndices<1> : public TableIndicesBase<1> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1); +}; + + + +/** + * Array of indices of fixed size used for the @ref{TableBase} + * class. + * + * This is the specialization for a two-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the @ref{TableIndicesBase} base class of a specializations. + * + * @author Wolfgang Bangerth, 2002 + */ +template <> +class TableIndices<2> : public TableIndicesBase<2> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2); +}; + + + +/** + * Array of indices of fixed size used for the @ref{TableBase} + * class. + * + * This is the specialization for a three-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the @ref{TableIndicesBase} base class of a specializations. + * + * @author Wolfgang Bangerth, 2002 + */ +template <> +class TableIndices<3> : public TableIndicesBase<3> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3); +}; + + +/** + * Have a namespace in which we declare some classes that are used to + * access the elements of tables using the @p{operator[]}. These are + * quite technical, since they have to do their work recursively (due + * to the fact that the number of indices is not known, we have to + * return an iterator into the next lower dimension object if we + * access one object, until we are on the lowest level and can + * actually return a reference to the stored data type itself). This + * is so technical that you will not usually want to look at these + * classes at all, except possibly for educational reasons. None of + * the classes herein has a interface that you should use explicitly + * in your programs (except, of course, through access to the elements + * of tables with @p{operator[]}, which generates temporary objects of + * the types of this namespace). + * + * @author Wolfgang Bangerth, 2002 + */ +namespace TableBaseAccessors +{ +/** + * Have a class which declares some nested typedefs, depending on its + * template parameters. The general template declares nothing, but + * there are more useful specializations regaring the last parameter + * indicating constness of the table for which accessor objects are to + * be generated in this namespace. + */ + template + class Types + {}; + +/** + * Have a class which declares some nested typedefs, depending on its + * template parameters. Specialization for accessors to constant + * objects. + */ + template struct Types + { + typedef const T value_type; + typedef const TableBase TableType; + }; + +/** + * Have a class which declares some nested typedefs, depending on its + * template parameters. Specialization for accessors to non-constant + * objects. + */ + template struct Types + { + typedef T value_type; + typedef TableBase TableType; + }; + + +/** + * Class that acts as accessor to subobjects of tables of type + * @p{Table}. The template parameter @p{C} may be either true or + * false, and indicates whether the objects worked on are constant or + * not (i.e. write access is only allowed if the value is false). + * + * Since with @p{N} indices, the effect of applying @p{operator[]} is + * getting access to something we @p{N-1} indices, we have to + * implement these accessor classes recursively, with stopping when we + * have only one index left. For the latter case, a specialization of + * this class is declared below, where calling @p{operator[]} gives + * you access to the objects actually stored by the table. In the + * value given to the index operator needs to be checked whether it is + * inside its bounds, for which we need to know which index of the + * table we are actually accessing presently. This is done through the + * template parameter @p{P}: it indicates, how many remaining indices + * there are. For a vector, @p{P} may only be one (and then the + * specialization below is used). For a table this value may be two, + * and when using @p{operator[]}, an object with @p{P=1} emerges. + * + * The value of @p{P} is also used to determine the stride: this + * object stores a pointer indicating the beginning of the range of + * objects that it may access. When we apply @p{operator[]} on this + * object, the resulting new accessor may only access a subset of + * these elements, and to know which subset we need to know the + * dimensions of the table and the present index, which is indicated + * by @p{P}. + * + * As stated for the entire namespace, you will not usually have to do + * with these classes directly, and should not try to use their + * interface directly as it may change without notice. + * + * @author Wolfgang Bangerth, 2002 + */ + template + class Accessor + { + public: + /** + * Import two typedefs from the + * switch class above. + */ + typedef typename Types::value_type * pointer; + typedef typename Types::TableType TableType; + + /** + * Constructor. Take a pointer + * to the table object to know + * about the sizes of the + * various dimensions, and a + * pointer to the subset of + * data we may access. + */ + Accessor (const TableType &table, + const pointer data); + + /** + * Index operator. Performs a + * range check. + */ + Accessor operator [] (const unsigned int i) const; + + /** + * Exception for range + * check. Do not use global + * exception since this way we + * can output which index is + * the wrong one. + */ + DeclException3 (ExcIndexRange, int, int, int, + << "The " << N-P+1 << "th index has a value of " + << arg1 << " but needs to be in the range [" + << arg2 << "," << arg3 << "["); + private: + /** + * Store the data given to the + * constructor. There are no + * non-const member functions + * of this class, so there is + * no reason not to make these + * elements constant. + */ + const TableType &table; + const pointer data; + }; + + + +/** + * Accessor class for tables. This is the specialization for the last + * index, which actually allows access to the elements of the table, + * rather than recursively returning access objects for further + * subsets. + * + * @author Wolfgang Bangerth, 2002 + */ + template + class Accessor + { + public: + /** + * Typedef constant and + * non-constant iterator + * types to the elements of + * this row, as well as all + * the other types usually + * required for the standard + * library algorithms. + */ + typedef typename Types::value_type value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + /** + * Import a typedef from the + * switch class above. + */ + typedef typename Types::TableType TableType; + + /** + * Constructor. Take a pointer + * to the table object to know + * about the sizes of the + * various dimensions, and a + * pointer to the subset of + * data we may access (which in + * this particular case is only + * one row). + */ + Accessor (const TableType &table, + const pointer data); + + /** + * Index operator. Performs a + * range check. + */ + reference operator [] (const unsigned int) const; + + /** + * Return the length of one row, + * i.e. the number of elements + * corresponding to the last + * index of the table object. + */ + unsigned int size () const; + + /** + * Return an iterator to the + * first element of this + * row. + */ + iterator begin () const; + + /** + * Return an interator to the + * element past the end of + * this row. + */ + iterator end () const; + + /** + * Exception for range + * check. Do not use global + * exception since this way we + * can output which index is + * the wrong one. + */ + DeclException3 (ExcIndexRange, int, int, int, + << "The " << N << "th index has a value of " + << arg1 << " but needs to be in the range [" + << arg2 << "," << arg3 << "["); + private: + /** + * Store the data given to the + * constructor. There are no + * non-const member functions + * of this class, so there is + * no reason not to make these + * elements constant. + */ + const TableType &table; + const pointer data; + }; +}; + + + + + + +/** + * General class holding an array of objects of templated type in + * multiple dimensions. If the template parameter indicating the + * number of dimensions is one, then this is more or less a vector, if + * it is two then it is a matrix, and so on. + * + * Previously, this data type was emulated in this library by + * constructs like @p{std::vector>}, or even higher + * nested constructs. However, this has the disadvantage that it is + * hard to initialize, and most importantly that it is very + * inefficient if all rows have the same size (which is the usual + * case), since then the memory for each row is allocated + * independently, both wasting time and memory. This can be made more + * efficient by allocating only one chunk of memory for the entire + * object. + * + * Therefore, this data type was invented. Its implementation is + * rather straightforward, with two exceptions. The first thing to + * think about is how to pass the size in each of the coordinate + * directions to the object; this is done using the @ref{TableIndices} + * class. Second, how to access the individual elements. The basic + * problem here is that we would like to make the number of arguments + * to be passed to the constructor as well as the access functions + * dependent on the template parameter @p{N} indicating the number of + * dimensions. Of course, this is not possible. + * + * The way out of the first problem (and partly the second one as + * well) is to have derived class for each value of @p{N} that have a + * constructor with the right number of arguments, one for each + * dimension. These then transform their arguments into the data type + * this class wants to see, both for construction as well as access + * through the @p{operator()} function. + * + * The second problem is that we would like to allow access through a + * sequence of @p{operator[]} calls. This mostly because, as said, + * this class is a replacement for previous use of nested + * @p{std::vector} objects, where we had to use the @p{operator[]} + * access function recursively until we were at the innermost + * object. Emulating this behavior without losing the ability to do + * index checks, and in particular without losing performance is + * possible but nontrivial, and done in the @ref{TableBaseAccessors} + * namespace. + * + * + * @sect3{Comparison with the Tensor class} + * + * In some way, this class is similar to the @ref{Tensor} class, in + * that it templatizes on the number of dimensions. However, there are + * two major differences. The first is that the @ref{Tensor} class + * stores only numeric values (as @p{double}s), while the @p{Table} + * class stores arbitrary objects. The second is that the @ref{Tensor} + * class has fixed dimensions, also give as a template argument, while + * this class can handle arbitrary dimensions, which may also be + * different between different indices. + * + * This has two consequences. First, since the size is not known at + * compile time, it has to do explicit memory allocating. Second, the + * layout of individual elements is not known at compile time, so + * access is slower than for the @ref{Tensor} class where the number + * of elements are their location is known at compile time and the + * compiler can optimize with this knowledge (for example when + * unrolling loops). On the other hand, this class is of course more + * flexible, for example when you want a two-dimensional table with + * the number of rows equal to the number of degrees of freedom on a + * cell, and the number of columns equal to the number of quadrature + * points. Both numbers may only be known at run-time, so a flexible + * table is needed here. Furthermore, you may want to store, say, the + * gradients of shape functions, so the data type is not a single + * scalar value, but a tensor itself. + * + * @author Wolfgang Bangerth, 2002. + */ +template +class TableBase : public Subscriptor +{ + public: + /** + * Default constructor. Set all + * dimensions to zero. + */ + TableBase (); + + /** + * Constructor. Initialize the + * array with the given + * dimensions in each index + * component. + */ + TableBase (const TableIndices &sizes); + + /** + * Copy constructor. Performs a + * deep copy. + */ + TableBase (const TableBase &src); + + /** + * Copy constructor. Performs a + * deep copy from a table object + * storing some other data type. + */ + template + TableBase (const TableBase &src); + + /** + * Destructor. Free allocated memory. + */ + ~TableBase (); + + /** + * Assignment operator. + * Copy all elements of @p{src} + * into the matrix. The size is + * adjusted if needed. + * + * We can't use the other, templatized + * version since if we don't declare + * this one, the compiler will happily + * generate a predefined copy + * operator which is not what we want. + */ + TableBase& operator = (const TableBase& src); + + /** + * Copy operator. + * Copy all elements of @p{src} + * into the array. The size is + * adjusted if needed. + * + * This function requires that the + * type @p{T2} is convertible to + * @p{T}. + */ + template + TableBase& operator = (const TableBase &src); + + /** + * Set all entries to their + * default value (i.e. copy them + * over with default constructed + * objects). + */ + void clear (); + + /** + * Set the dimensions of this + * object to the sizes given in + * the argument, and newly + * allocate the required + * memory. Forget the previous + * content of the array. + */ + void reinit (const TableIndices &new_size); + + /** + * Return the sizes of this + * object in each direction. + */ + const TableIndices & size () const; + + /** + * Return the number of elements + * stored in this object, which + * is the product of the + * extensions in each dimension. + */ + unsigned int n_elements () const; + + /** + * Return whether the object is + * empty, i.e. one of the + * directions is zero. This is + * equivalent to + * @p{n_elements()==0}. + */ + bool empty () const; + + /** + * Fill array with an array of + * elements. The input array must + * be arranged in usual C style, + * i.e. with the last index + * running fastest. For + * two-dimensional tables, this + * means line by line. No range + * checking is performed, i.e., + * it is assumed that the input + * array @p{entries} contains + * @p{n_rows()*n_cols()} + * elements, and that the layout + * refers to the desired shape of + * this table. + * + * Note also that the type of the + * objects of the input array, + * @p{T2}, must be convertible to + * the type of the objects of + * this array. + */ + template + void fill (const T2 *entries); + + /** + * Return a read-write reference + * to the indicated element. + */ + T & operator() (const TableIndices &indices); + + /** + * Return the value of the + * indicated element as a + * read-only reference. + * + * We return the requested value + * as a constant reference rather + * than by value since this + * object may hold data types + * that may be large, and we + * don't know here whether + * copying is expensive or not. + */ + const T & operator() (const TableIndices &indices) const; + + /** + * Determine an estimate for the + * memory consumption (in bytes) + * of this object. + */ + unsigned int memory_consumption () const; + + protected: + /** + * Return the position of the + * indicated element within the + * array of elements stored one + * after the other. This function + * does no index checking. + */ + unsigned int position (const TableIndices &indices) const; + + /** + * Return a read-write reference + * to the indicated element. + * + * This function does no bounds + * checking and is only to be + * used internally and in + * functions already checked. + */ + T & el (const TableIndices &indices); + + /** + * Return the value of the + * indicated element as a + * read-only reference. + * + * This function does no bounds + * checking and is only to be + * used internally and in + * functions already checked. + * + * We return the requested value + * as a constant reference rather + * than by value since this + * object may hold data types + * that may be large, and we + * don't know here whether + * copying is expensive or not. + */ + const T & el (const TableIndices &indices) const; + + /** + * Direct read-only access to + * data field. Used by + * @ref{FullMatrix} (there even + * with a cast from const), + * otherwise, keep away! + */ + const T* data () const; + + protected: + /** + * Component-array. + */ + T* val; + + /** + * Size of array. This may be + * larger than the number of + * actually used elements, since + * we don't shrink the array upon + * calls to @p{reinit} unless the + * new size is zero. + */ + unsigned int val_size; + + /** + * Size in each direction of the + * table. + */ + TableIndices table_size; +}; + + +/** + * A class representing a table with arbitrary but fixed number of + * indices. This general template implements some additional functions + * over those provided bythe @ref{TableBase} class, such as indexing + * functions taking the correct number of arguments, etc. + * + * Rather than this general template, these functions are implemented + * in partial specializations of this class, with fixed numbers of + * dimensions. See there, and in the documentation of the base class + * for more information. + * + * @author Wolfgang Bangerth, 2002 + */ +template +class Table : public TableBase +{}; + + +/** + * A class representing a one-dimensional table, i.e. a vector-like + * class. Since the C++ library has a vector class, there is probably + * not much need for this particular class, but since it is so simple + * to implement on top of the template base class, we provide it + * anyway. + * + * For the rationale of this class, and a description of the + * interface, see the base class. + * + * @author Wolfgang Bangerth, 2002 + */ +template +class Table<1,T> : public TableBase<1,T> +{ + public: + /** + * Default constructor. Set all + * dimensions to zero. + */ + Table (); + + /** + * Constructor. Pass down the + * given dimension to the base + * class. + */ + Table (const unsigned int size); + + /** + * Access operator. Since this is + * a one-dimensional object, this + * simply accesses the requested + * data element. Returns a + * read-only reference. + */ + const T & + operator [] (const unsigned int i) const; + + /** + * Access operator. Since this is + * a one-dimensional object, this + * simply accesses the requested + * data element. Returns a + * read-write reference. + */ + T & + operator [] (const unsigned int i); + + /** + * Access operator. Since this is + * a one-dimensional object, this + * simply accesses the requested + * data element. Returns a + * read-only reference. + */ + const T & + operator () (const unsigned int i) const; + + /** + * Access operator. Since this is + * a one-dimensional object, this + * simply accesses the requested + * data element. Returns a + * read-write reference. + */ + T & + operator () (const unsigned int i); +}; + + + +/** + * A class representing a two-dimensional table, i.e. a matrix of + * objects (not necessarily only numbers). + * + * For the rationale of this class, and a description of the + * interface, see the base class. Since this serves as the base class + * of the full matrix classes in this library, and to keep a minimal + * compatibility with a predecessor class (@p{vector2d}), some + * additional functions are provided. + * + * @author Wolfgang Bangerth, 2002 + */ +template +class Table<2,T> : public TableBase<2,T> +{ + public: + /** + * Default constructor. Set all + * dimensions to zero. + */ + Table (); + + /** + * Constructor. Pass down the + * given dimensions to the base + * class. + */ + Table (const unsigned int size1, + const unsigned int size2); + + /** + * Reinitialize the object. This + * function is mostly here for + * compatibility with the earlier + * @p{vector2d} class. Passes + * down to the base class by + * converting the arguments to + * the data type requested by the + * base class. + */ + void reinit (const unsigned int size1, + const unsigned int size2); + + /** + * Access operator. Generate an + * object that accesses the + * requested row of this + * two-dimensional table. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + TableBaseAccessors::Accessor<2,T,true,1> + operator [] (const unsigned int i) const; + + /** + * Access operator. Generate an + * object that accesses the + * requested row of this + * two-dimensional table. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + TableBaseAccessors::Accessor<2,T,false,1> + operator [] (const unsigned int i); + + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + const T & operator () (const unsigned int i, + const unsigned int j) const; + + + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + T & operator () (const unsigned int i, + const unsigned int j); + + + /** + * Number of rows. This function + * really makes only sense since + * we have a two-dimensional + * object here. + */ + unsigned int n_rows () const; + + /** + * Number of columns. This function + * really makes only sense since + * we have a two-dimensional + * object here. + */ + unsigned int n_cols () const; + + protected: + /** + * Return a read-write reference + * to the element @p{(i,j)}. + * + * This function does no bounds + * checking and is only to be + * used internally and in + * functions already checked. + * + * These functions are mainly + * here for compatibility with a + * former implementation of these + * table classes for 2d arrays, + * then called @p{vector2d}. + */ + T & el (const unsigned int i, + const unsigned int j); + + /** + * Return the value of the + * element @p{(i,j)} as a + * read-only reference. + * + * This function does no bounds + * checking and is only to be + * used internally and in + * functions already checked. + * + * We return the requested value + * as a constant reference rather + * than by value since this + * object may hold data types + * that may be large, and we + * don't know here whether + * copying is expensive or not. + * + * These functions are mainly + * here for compatibility with a + * former implementation of these + * table classes for 2d arrays, + * then called @p{vector2d}. + */ + const T & el (const unsigned int i, + const unsigned int j) const; +}; + + + +/** + * A class representing a three-dimensional table of objects (not + * necessarily only numbers). + * + * For the rationale of this class, and a description of the + * interface, see the base class. + * + * @author Wolfgang Bangerth, 2002 + */ +template +class Table<3,T> : public TableBase<3,T> +{ + public: + /** + * Default constructor. Set all + * dimensions to zero. + */ + Table (); + + /** + * Constructor. Pass down the + * given dimensions to the base + * class. + */ + Table (const unsigned int size1, + const unsigned int size2, + const unsigned int size3); + + /** + * Access operator. Generate an + * object that accesses the + * requested two-dimensional + * subobject of this + * three-dimensional table. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + TableBaseAccessors::Accessor<3,T,true,2> + operator [] (const unsigned int i) const; + + /** + * Access operator. Generate an + * object that accesses the + * requested two-dimensional + * subobject of this + * three-dimensional table. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + TableBaseAccessors::Accessor<3,T,false,2> + operator [] (const unsigned int i); + + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * only allows read access. + */ + const T & operator () (const unsigned int i, + const unsigned int j, + const unsigned int k) const; + + + /** + * Direct access to one element + * of the table by specifying all + * indices at the same time. Range + * checks are performed. + * + * This version of the function + * allows read-write access. + */ + T & operator () (const unsigned int i, + const unsigned int j, + const unsigned int k); +}; + + + + +/* --------------------- Template and inline functions ---------------- */ + + +template +inline +unsigned int +TableIndicesBase::operator [] (const unsigned int i) const +{ + return indices[i]; +}; + + + +inline +TableIndices<1>::TableIndices () +{ + this->indices[0] = 0; +}; + + + +inline +TableIndices<1>::TableIndices (const unsigned int index1) +{ + this->indices[0] = index1; +}; + + + +inline +TableIndices<2>::TableIndices () +{ + this->indices[0] = this->indices[1] = 0; +}; + + + +inline +TableIndices<2>::TableIndices (const unsigned int index1, + const unsigned int index2) +{ + this->indices[0] = index1; + this->indices[1] = index2; +}; + + + +inline +TableIndices<3>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] = 0; +}; + + + +inline +TableIndices<3>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; +}; + + + +template +TableBase::TableBase () + : + val (0), + val_size (0) +{}; + + + +template +TableBase::TableBase (const TableIndices &sizes) + : + val (0), + val_size (0) +{ + reinit (sizes); +}; + + + +template +TableBase::TableBase (const TableBase &src) + : + Subscriptor (), + val (0), + val_size (0) +{ + reinit (src.table_size); + fill (src.data()); +}; + + + +template +template +TableBase::TableBase (const TableBase &src) + : + val (0), + val_size (0) +{ + reinit (src.table_size); + fill (src.data()); +}; + + + +namespace TableBaseAccessors +{ + template + inline + Accessor::Accessor (const TableType &table, + const pointer data) + : + table (table), + data (data) + {}; + + + + template + inline + Accessor + Accessor::operator [] (const unsigned int i) const + { + Assert (i < table.size()[N-P], + ExcIndexRange (i, 0, table.size()[N-P])); + + // access i-th + // subobject. optimize on the + // case i==0 + if (i==0) + return Accessor (table, data); + else + { + // note: P>1, otherwise the + // specialization would have + // been taken! + unsigned int subobject_size = table.size()[N-1]; + for (int p=P-1; p>1; --p) + subobject_size *= table.size()[N-p]; + const pointer new_data = data + i*subobject_size; + return Accessor (table, new_data); + }; + }; + + + + template + inline + Accessor::Accessor (const TableType &table, + const pointer data) + : + table (table), + data (data) + {}; + + + + template + inline + typename Accessor::reference + Accessor::operator [] (const unsigned int i) const + { + Assert (i < table.size()[N-1], + ExcIndexRange (i, 0, table.size()[N-1])); + return data[i]; + }; + + + + template + inline + unsigned int + Accessor::size () const + { + return table.size()[N-1]; + }; + + + + template + inline + typename Accessor::iterator + Accessor::begin () const + { + return data; + }; + + + + template + inline + typename Accessor::iterator + Accessor::end () const + { + return data+table.size()[N-1]; + }; +}; + + + +template +inline +TableBase::~TableBase () +{ + if (val != 0) + delete[] val; +}; + + + +template +TableBase& +TableBase::operator = (const TableBase& m) +{ + reinit (m.size()); + if (!empty()) + std::copy (&m.val[0], &m.val[n_elements()], &val[0]); + + return *this; +} + + + +template +template +TableBase& +TableBase::operator = (const TableBase& m) +{ + reinit (m.size()); + if (!empty()) + std::copy (&m.val[0], &m.val[n_elements()], &val[0]); + + return *this; +} + + + +template +inline +void +TableBase::clear () +{ + if (val != 0) + std::fill_n (val, n_elements(), T()); +}; + + + +template +void +TableBase::reinit (const TableIndices &new_sizes) +{ + table_size = new_sizes; + + const unsigned int new_size = n_elements(); + + // if zero size was given: free all + // memory + if (new_size == 0) + { + if (val != 0) + delete[] val; + + val = 0; + val_size = 0; + + // set all sizes to zero, even + // if one was previously + // nonzero. This simplifies + // some assertions. + table_size = TableIndices(); + + return; + }; + + // if new size is nonzero: + // if necessary allocate + // additional memory + if (val_size +const TableIndices & +TableBase::size () const +{ + return table_size; +}; + + + +template +unsigned int +TableBase::n_elements () const +{ + unsigned s = 1; + for (unsigned int n=0; n +bool +TableBase::empty () const +{ + return (n_elements() == 0); +}; + + + +template +template +inline +void +TableBase::fill (const T2* entries) +{ + if (val_size != 0) + std::copy (entries, entries+n_elements(), val); +} + + + +template +unsigned int +TableBase::memory_consumption () const +{ + return sizeof(*this) + val_size*sizeof(T); +} + + +template +inline +unsigned int +TableBase::position (const TableIndices &indices) const +{ + // specialize this for the + // different numbers of dimensions, + // to make the job somewhat easier + // for the compiler. have the + // general formula nevertheless: + switch (N) + { + case 1: + return indices[0]; + case 2: + return indices[0]*table_size[1] + indices[1]; + case 3: + return ((indices[0]*table_size[1] + indices[1])*table_size[2] + + indices[2]); + default: + { + unsigned int s = indices[0]; + for (unsigned int n=1; n +inline const T & +TableBase::operator() (const TableIndices &indices) const +{ + for (unsigned int n=0; n +inline T & +TableBase::operator() (const TableIndices &indices) +{ + for (unsigned int n=0; n +inline const T & +TableBase::el (const TableIndices &indices) const +{ + return val[position(indices)]; +}; + + + +template +inline T & +TableBase::el (const TableIndices &indices) +{ + return val[position(indices)]; +}; + + + +template +inline +const T * +TableBase::data () const +{ + return val; +} + + + + +template +Table<1,T>::Table () +{}; + + + +template +Table<1,T>::Table (const unsigned int size) + : + TableBase<1,T> (TableIndices<1> (size)) +{}; + + + +template +const T & +Table<1,T>::operator [] (const unsigned int i) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + return this->val[i]; +}; + + + +template +T & +Table<1,T>::operator [] (const unsigned int i) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + return this->val[i]; +}; + + + +template +inline +const T & +Table<1,T>::operator () (const unsigned int i) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + return this->val[i]; +}; + + + +template +inline +T & +Table<1,T>::operator () (const unsigned int i) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + return this->val[i]; +}; + + + + +template +Table<2,T>::Table () +{}; + + + +template +Table<2,T>::Table (const unsigned int size1, + const unsigned int size2) + : + TableBase<2,T> (TableIndices<2> (size1, size2)) +{}; + + + +template +void +Table<2,T>::reinit (const unsigned int size1, + const unsigned int size2) +{ + this->TableBase<2,T>::reinit (TableIndices<2> (size1, size2)); +}; + + + +template +inline +TableBaseAccessors::Accessor<2,T,true,1> +Table<2,T>::operator [] (const unsigned int i) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + return TableBaseAccessors::Accessor<2,T,true,1>(*this, + this->val+i*n_cols()); +}; + + + +template +inline +TableBaseAccessors::Accessor<2,T,false,1> +Table<2,T>::operator [] (const unsigned int i) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + return TableBaseAccessors::Accessor<2,T,false,1>(*this, + this->val+i*n_cols()); +}; + + + +template +inline +const T & +Table<2,T>::operator () (const unsigned int i, + const unsigned int j) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + return this->val[i*this->table_size[1]+j]; +}; + + + +template +inline +T & +Table<2,T>::operator () (const unsigned int i, + const unsigned int j) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + return this->val[i*this->table_size[1]+j]; +}; + + + +template +inline +const T & +Table<2,T>::el (const unsigned int i, + const unsigned int j) const +{ + return this->val[i*this->table_size[0]+j]; +}; + + + +template +inline +T & +Table<2,T>::el (const unsigned int i, + const unsigned int j) +{ + return this->val[i*this->table_size[0]+j]; +}; + + + +template +inline +unsigned int +Table<2,T>::n_rows () const +{ + return this->table_size[0]; +}; + + + +template +inline +unsigned int +Table<2,T>::n_cols () const +{ + return this->table_size[1]; +}; + + + + + +template +Table<3,T>::Table () +{}; + + + +template +Table<3,T>::Table (const unsigned int size1, + const unsigned int size2, + const unsigned int size3) + : + TableBase<3,T> (TableIndices<3> (size1, size2, size3)) +{}; + + + +template +inline +TableBaseAccessors::Accessor<3,T,true,2> +Table<3,T>::operator [] (const unsigned int i) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + const unsigned int subobject_size = this->table_size[1] * + this->table_size[2]; + return (TableBaseAccessors::Accessor<3,T,true,2> + (*this, + this->val+i*subobject_size)); +}; + + + +template +inline +TableBaseAccessors::Accessor<3,T,false,2> +Table<3,T>::operator [] (const unsigned int i) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + const unsigned int subobject_size = this->table_size[1] * + this->table_size[2]; + return (TableBaseAccessors::Accessor<3,T,false,2> + (*this, + this->val+i*subobject_size)); +}; + + + +template +inline +const T & +Table<3,T>::operator () (const unsigned int i, + const unsigned int j, + const unsigned int k) const +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + Assert (k < this->table_size[2], + ExcIndexRange (k, 0, this->table_size[2])); + return this->val[(i*this->table_size[1]+j)*this->table_size[2] + k]; +}; + + + +template +inline +T & +Table<3,T>::operator () (const unsigned int i, + const unsigned int j, + const unsigned int k) +{ + Assert (i < this->table_size[0], + ExcIndexRange (i, 0, this->table_size[0])); + Assert (j < this->table_size[1], + ExcIndexRange (j, 0, this->table_size[1])); + Assert (k < this->table_size[2], + ExcIndexRange (k, 0, this->table_size[2])); + return this->val[(i*this->table_size[1]+j)*this->table_size[2] + k]; +}; + + +#endif diff --git a/deal.II/base/include/base/vector2d.h b/deal.II/base/include/base/vector2d.h deleted file mode 100644 index 2f7fe7f7dc..0000000000 --- a/deal.II/base/include/base/vector2d.h +++ /dev/null @@ -1,949 +0,0 @@ -//----------------------------------------------------------------------- -// $Id$ -// Version: $Name$ -// -// Copyright (C) 2000, 2001, 2002 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__vector2d_h -#define __deal2__vector2d_h - -#include -#include - -#include - -template class vector2d; -template class FullMatrix; - - -/** - * Two-dimensional array of arbitrary data. - * - * This is an implementation of a two-dimensional array with access by - * pairs of coordinates. Access is either by @p{x(i,j)} to keep with - * matrix notation, or @p{x[i][j]} in accordance to C-style arrays. - * - * The name is chosen to be @p{vector2d} to be conformant with the - * standard C++ classes. This, although array would have been - * preferrable, since a vector should be element of a vector space. - * - * @author Guido Kanschat, 2001. Parts by Wolfgang Bangerth and others. - */ -template -class vector2d : public Subscriptor -{ - public: - /** - * Object representing one row of - * a @ref{vector2d} object. It - * allows to access the elements - * through the - * @p{operator[]}. Since objects - * of this type are also - * generated through the - * @p{vector2d::operator[]}, this - * allows accessing the elements - * of @p{vector2d} objects just - * as those of two-dimensional - * C-style arrays. - * - * This class is used for - * constant @p{vector2d} - * objects. It only allows - * read-only access to the - * elements. - */ - class ConstRowAccessor - { - public: - /** - * Typedef iterator and other - * types to the elements of - * this row. Since this class - * represents rows of - * constant objects, - * @p{iterator} and - * @p{const_iterator} have - * the same type. - */ - typedef const T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type* iterator; - typedef const value_type* const_iterator; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - - /** - * Constructor. - */ - ConstRowAccessor (const vector2d &parent, - const unsigned int row); - - /** - * Access operator. - */ - const_reference operator [] (const unsigned int column) const; - - /** - * Return an iterator to the - * first element of this row. - */ - const_iterator begin () const; - - /** - * Return an interator to the - * element past the end of - * this row. - */ - const_iterator end () const; - - /** - * Return the number of - * elements between @p{begin} - * and @p{end}, i.e. the - * number of columns of the - * matrix. - */ - unsigned int size () const; - - protected: - /** - * Pointer to the parent - * object. Used only to check - * access indices for - * validity. - */ - const vector2d &parent; - - /** - * Pointer to the start of - * the row pointed to by this - * object. - */ - const T * const row_start; - }; - - - /** - * Object representing one row of - * a @ref{vector2d} object. It - * allows to access the elements - * through the - * @p{operator[]}. Since objects - * of this type are also - * generated through the - * @p{vector2d::operator[]}, this - * allows accessing the elements - * of @p{vector2d} objects just - * as those of two-dimensional - * C-style arrays. - * - * This class is used for - * non-constant @p{vector2d} - * objects. It allows read and - * write access to the elements. - */ - class NonConstRowAccessor - { - public: - /** - * Typedef constant and - * non-constant iterator - * types to the elements of - * this row, as well as all - * the other types usually - * required for the standard - * library algorithms. - */ - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type* iterator; - typedef const value_type* const_iterator; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - - - /** - * Constructor. - */ - NonConstRowAccessor (vector2d &parent, - const unsigned int row); - - - /** - * Access operator. - */ - reference operator [] (const unsigned int column) const; - - /** - * Return an iterator to the - * first element of this - * row. Constant version. - */ - const_iterator begin () const; - - /** - * Return an iterator to the - * first element of this - * row. Non-constant version. - */ - iterator begin (); - - /** - * Return an interator to the - * element past the end of - * this row. Constant version. - */ - const_iterator end () const; - - /** - * Return an interator to the - * element past the end of - * this row. Non-constant - * version. - */ - iterator end (); - - /** - * Return the number of - * elements between @p{begin} - * and @p{end}, i.e. the - * number of columns of the - * matrix. - */ - unsigned int size () const; - - private: - /** - * Pointer to the parent - * object. Used only to check - * access indices for - * validity. - */ - const vector2d &parent; - - /** - * Pointer to the start of - * the row pointed to by this - * object. - */ - T * const row_start; - }; - - /** - * Default - * constructor. Initialize this - * as an empty array, i.e. all - * dimensions are zero. - */ - vector2d (); - - /** - * Constructor for a @p{rows} by - * @p{cols} array. - */ - vector2d (const unsigned int rows, - const unsigned int cols); - - - /** - * Constructor just as the one - * above, but use the give - * pointer to initialize the - * elements of this table. For - * the requirements on the format - * of the initializers, see the - * @p{fill} function of this - * class. - */ - vector2d (const unsigned int rows, - const unsigned int cols, - const T *initializers); - - /** - * Copy-constructor for deep copy. - */ - vector2d (const vector2d&); - - /** - * Assignment operator. - * Copy all elements of @p{src} - * into the matrix. The size is - * adjusted if needed. - * - * We can't use the other, templatized - * version since if we don't declare - * this one, the compiler will happily - * generate a predefined copy - * operator which is not what we want. - */ - vector2d& operator = (const vector2d& src); - - /** - * Copy operator. - * Copy all elements of @p{src} - * into the array. The size is - * adjusted if needed. - * - * This function requires that the - * type @p{T2} is convertible to - * @p{T}. - */ - template - vector2d& operator = (const vector2d &src); - - /** - * Destructor. Free allocated memory. - */ - ~vector2d (); - - /** - * Set dimension to $m\times n$ - * and allocate memory if - * necessary. Forget the previous - * content of the array. - */ - void reinit (const unsigned int m, - const unsigned int n); - - /** - * Set dimension to $n\times n$ - * and allocate memory if - * necessary. Forget the previous - * content of the array. - */ - void reinit (const unsigned int n); - - /** - * Set the dimensions to the same - * as another array. The other - * array will not be copied, - * though. The entries of this - * array will be zero. - */ - template - void reinit (const vector2d &shape); - - /** - * Number of rows. - */ - unsigned int n_rows () const; - - /** - * Number of columns. - */ - unsigned int n_cols () const; - - /** - * Return the value of the - * element at position @p{(i,j)} - * as a constant reference. - * - * We return the requested value - * as a constant reference rather - * than by value since this - * object may hold data types - * that may be large, and we - * don't know here whether - * copying is expensive or not. - */ - const T & operator() (const unsigned int i, - const unsigned int j) const; - - /** - * Return a read-write reference to - * the element at position @p{(i,j)}. - */ - T & operator() (const unsigned int i, - const unsigned int j); - - /** - * Return an object representing - * a certain row of this - * array. This object in turn has - * an @p{operator[]}, so that the - * elements of this array can be - * accessed through @p{x[i][j]} - * as well as through @p{x(i,j)}. - * - * This function is for constant - * objects. The returned row - * representing object only - * allows read access to the - * elements of the row pointed - * to. - */ - ConstRowAccessor operator [] (const unsigned int row) const; - - /** - * Return an object representing - * a certain row of this - * array. This object in turn has - * an @p{operator[]}, so that the - * elements of this array can be - * accessed through @p{x[i][j]} - * as well as through @p{x(i,j)}. - * - * This function is for - * non-constant objects. The - * returned row representing - * object allows read and write - * access to the elements of the - * row pointed to. - */ - NonConstRowAccessor operator [] (const unsigned int row); - - - /** - * Set all entries to their - * default value (zero). - */ - void clear (); - - /** - * Fill array with an array of - * elements. The array is - * arranged line by line. No - * range checking is performed, - * i.e., it is assumed that the - * input array @p{entries} - * contains @p{n_rows()*n_cols()} - * elements, and that the layout - * refers to the desired shape of - * this table. - */ - template - void fill (const T2 *entries); - - /** - * Determine an estimate for the - * memory consumption (in bytes) - * of this object. - */ - unsigned int memory_consumption () const; - - protected: - /** - * Return a read-write reference - * to the element @p{(i,j)}. - * - * This function does no bounds - * checking and is only to be - * used internally and in - * functions already checked. - */ - T & el (const unsigned int i, const unsigned int j); - - /** - * Return the value of the - * element @p{(i,j)} as a - * read-only reference. - * - * This function does no bounds - * checking and is only to be - * used internally and in - * functions already checked. - * - * We return the requested value - * as a constant reference rather - * than by value since this - * object may hold data types - * that may be large, and we - * don't know here whether - * copying is expensive or not. - */ - const T & el (const unsigned int i, const unsigned int j) const; - - /** - * Direct read-only access to - * data field. Used by - * @ref{FullMatrix} (there even - * with a cast from const), - * otherwise, keep away! - */ - const T* data () const; - - private: - /** - * Component-array. - */ - T* val; - - /** - * Size of array. This may be - * larger than the number of - * actually used elements, since - * we don't shrink the array upon - * calls to @p{reinit} unless the - * new size is zero. - */ - unsigned int val_size; - - /** - * Number of Rows - */ - unsigned int num_rows; - - /** - * Number of Columns - */ - unsigned int num_cols; - - /** - * Friend declaration needed for - * inter-type copy operator. - */ - template friend class vector2d; - - /** - * This is unfortunately needed. - */ - template friend class FullMatrix; - - /** - * Make the following classes - * friends; this is not strictly - * necessary according to a - * defect report to the C++ - * standard, but older compilers - * still require this behavior. - */ - friend class ConstRowAccessor; - friend class NonConstRowAccessor; -}; - - -/* --------------------- Template and inline functions ---------------- */ - -template -inline -vector2d::ConstRowAccessor:: -ConstRowAccessor (const vector2d &parent, - const unsigned int row) - : - parent (parent), - row_start(&parent.val[row*parent.n_cols()]) -{ - Assert (row < parent.n_rows(), ExcInternalError()); -}; - - -template -inline -typename vector2d::ConstRowAccessor::const_reference -vector2d::ConstRowAccessor:: -operator [] (const unsigned int column) const -{ - Assert (column < parent.n_cols(), ExcInternalError()); - return *(row_start+column); -}; - - - -template -inline -typename vector2d::ConstRowAccessor::const_iterator -vector2d::ConstRowAccessor::begin () const -{ - return row_start; -}; - - - -template -inline -typename vector2d::ConstRowAccessor::const_iterator -vector2d::ConstRowAccessor::end () const -{ - return row_start+parent.n_cols(); -}; - - - -template -inline -unsigned int -vector2d::ConstRowAccessor::size () const -{ - return parent.n_cols(); -}; - - - -template -inline -vector2d::NonConstRowAccessor:: -NonConstRowAccessor (vector2d &parent, - const unsigned int row) - : - parent (parent), - row_start(&parent.val[row*parent.n_cols()]) -{ - Assert (row < parent.n_rows(), ExcInternalError()); -}; - - - -template -inline -typename vector2d::NonConstRowAccessor::reference -vector2d::NonConstRowAccessor:: -operator [] (const unsigned int column) const -{ - Assert (column < parent.n_cols(), ExcInternalError()); - return *(row_start+column); -}; - - - -template -inline -typename vector2d::NonConstRowAccessor::iterator -vector2d::NonConstRowAccessor::begin () -{ - return row_start; -}; - - - -template -inline -typename vector2d::NonConstRowAccessor::const_iterator -vector2d::NonConstRowAccessor::end () const -{ - return row_start+parent.n_cols(); -}; - - - -template -inline -typename vector2d::NonConstRowAccessor::iterator -vector2d::NonConstRowAccessor::end () -{ - return row_start+parent.n_cols(); -}; - - - -template -inline -unsigned int -vector2d::NonConstRowAccessor::size () const -{ - return parent.n_cols(); -}; - - - -template -inline -vector2d::~vector2d () -{ - if (val != 0) - delete[] val; -}; - - - -template -inline -void -vector2d::clear () -{ - if (val != 0) - std::fill_n (val, num_rows*num_cols, T()); -}; - - - -template -template -inline -void -vector2d::fill (const T2* entries) -{ - if (val_size != 0) - std::copy (entries, entries+(num_rows*num_cols), val); -} - - - -template -void -vector2d::reinit (const unsigned int mm, - const unsigned int nn) -{ - num_cols = nn; - num_rows = mm; - - // if zero size was given: free all - // memory - if ((num_cols==0) || (num_rows == 0)) - { - if (val != 0) - delete[] val; - - val = 0; - val_size = 0; - - // set both sizes to zero, even - // if one was previously - // nonzero. This simplifies - // some Assertions. - num_cols = num_rows = 0; - - return; - }; - - // if new size is nonzero: - // if necessary: allocate - // additional memory - if (val_size -void -vector2d::reinit (const unsigned int n) -{ - reinit (n, n); -}; - - - -template -template -void -vector2d::reinit (const vector2d &B) -{ - reinit (B.n_rows(), B.n_cols()); -}; - - - -template -vector2d::vector2d () - : - val (0), - val_size (0), - num_rows (0), - num_cols (0) -{ - reinit (0,0); -}; - - - -template -vector2d::vector2d (const unsigned int m, - const unsigned int n) - : - val (0), - val_size (0), - num_rows (0), - num_cols (0) -{ - reinit (m,n); -}; - - - -template -vector2d::vector2d (const vector2d &m) - : - Subscriptor (), - val (0), - val_size (0), - num_rows (0), - num_cols (0) -{ - reinit (m.num_rows, m.num_cols); - if (num_cols*num_rows != 0) - std::copy (&m.val[0], &m.val[num_rows*num_cols], &val[0]); -}; - - -template -vector2d::vector2d (const unsigned int m, - const unsigned int n, - const T *entries) - : - val (0), - val_size (0), - num_rows (0), - num_cols (0) -{ - reinit (m,n); - - if (num_cols*num_rows != 0) - std::copy (entries, entries+num_rows*num_cols, val); -}; - - - -template -vector2d& -vector2d::operator = (const vector2d& m) -{ - reinit (m); - if (num_cols*num_rows != 0) - std::copy (&m.val[0], &m.val[num_rows*num_cols], - &val[0]); - - return *this; -} - - - -template -template -vector2d& -vector2d::operator = (const vector2d& m) -{ - reinit(m); - if (num_cols*num_rows != 0) - copy (&m.val[0], &m.val[num_rows*num_cols], - &val[0]); - - return *this; -} - - - -template -inline -unsigned int -vector2d::n_rows () const -{ - return num_rows; - -} - - - -template -inline -unsigned int -vector2d::n_cols () const -{ - return num_cols; - -} - - - -template -inline T & -vector2d::el (const unsigned int i, const unsigned int j) -{ - return val[i*n_cols()+j]; -}; - - - -template -inline const T & -vector2d::el (const unsigned int i, const unsigned int j) const -{ - return val[i*n_cols()+j]; -}; - - - -template -inline const T & -vector2d::operator() (const unsigned int i, const unsigned int j) const -{ - Assert (i -inline -T & -vector2d::operator() (const unsigned int i, const unsigned int j) -{ - Assert (i -inline -typename vector2d::ConstRowAccessor -vector2d::operator [] (const unsigned int row) const -{ - // Note: check for validity of row - // number is done in the - // constructor of the created - // object - return ConstRowAccessor(*this, row); -}; - - - -template -inline -typename vector2d::NonConstRowAccessor -vector2d::operator [] (const unsigned int row) -{ - // Note: check for validity of row - // number is done in the - // constructor of the created - // object - return NonConstRowAccessor(*this, row); -}; - - - - - -template -inline -const T * -vector2d::data () const -{ - return val; -} - - - -template -inline -unsigned int -vector2d::memory_consumption () const -{ - return sizeof (*this) + val_size * sizeof (T); -} - -#endif -- 2.39.5