From 2e1336857894167056814f163293013b6228ae25 Mon Sep 17 00:00:00 2001 From: bangerth Date: Sat, 21 Dec 2013 13:44:29 +0000 Subject: [PATCH] Generalize TableBase::fill. git-svn-id: https://svn.dealii.org/trunk@32081 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 9 ++ deal.II/include/deal.II/base/table.h | 117 ++++++++++++++---- .../include/deal.II/matrix_free/shape_info.h | 2 +- 3 files changed, 101 insertions(+), 27 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 98203a9f9d..273a5504d5 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -82,6 +82,15 @@ inconvenience this causes.

Specific improvements

    +
  1. New: The TableBase::fill function has become more powerful in that + it now doesn't just take pointers to initializing elements but can deal + with arbitrary input iterators. It now also takes a flag that denotes the + order in which table elements are initialized, allowing to switch between + C- and Fortran-style table layouts. +
    + (Wolfgang Bangerth, 2013/12/21) +
  2. +
  3. New: There is now a new class Functions::InterpolatedTensorProductGridData that can be used to (bi-/tri-)linearly interpolate data given on a tensor product mesh of $x$ (and $y$ and $z$) values, for example to evaluate experimentally diff --git a/deal.II/include/deal.II/base/table.h b/deal.II/include/deal.II/base/table.h index 4f884dc414..984446817b 100644 --- a/deal.II/include/deal.II/base/table.h +++ b/deal.II/include/deal.II/base/table.h @@ -583,31 +583,48 @@ public: 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 entries contains - * n_rows()*n_cols() - * elements, and that the layout - * refers to the desired shape of - * this table. The only check we - * do is that the present array - * is non-empty. + * Fill this table (which is assumed to already have the correct + * size) from a source given by dereferencing the given forward + * iterator (which could, for example, be a pointer to the first + * element of an array, or an inserting std::istream_iterator). The + * second argument denotes whether the elements pointed to are + * arranged in a way that corresponds to the last index running + * fastest or slowest. The default is to use C-style indexing + * where the last index runs fastest (as opposed to Fortran-style + * where the first index runs fastest when traversing multidimensional + * arrays. For example, if you try to fill an object of type + * Table<2,T>, then calling this function with the default + * value for the second argument will result in the equivalent of + * doing + * @code + * Table<2,T> t; + * for (unsigned int i=0; i t; + * for (unsigned int j=0; jT2, must be convertible to - * the type of the objects of - * this array. + * @param entries An iterator to a set of elements from which to + * initialize this table. It is assumed that iterator can be + * incremented and dereferenced a sufficient number of times + * to fill this table. + * @param C_style_indexing If true, run over elements of the + * table with the last index changing fastest as we dereference + * subsequent elements of the input range. If false, change + * the first index fastest. */ - template - void fill (const T2 *entries); + template + void fill (ForwardIterator entries, + const bool C_style_indexing = true); /** * Fill all table entries with @@ -2080,16 +2097,64 @@ TableBase::empty () const +namespace internal +{ + namespace Table + { + template + void fill_Fortran_style (ForwardIterator entries, + TableBase<1,T> &table) + { + for (unsigned int i=0; i(i)) = *entries++; + } + + + template + void fill_Fortran_style (ForwardIterator entries, + TableBase<2,T> &table) + { + for (unsigned int j=0; j(i,j)) = *entries++; + } + + + template + void fill_Fortran_style (ForwardIterator entries, + TableBase<3,T> &table) + { + for (unsigned int k=0; k(i,j,k)) = *entries++; + } + + + template + void fill_Fortran_style (ForwardIterator, + TableBase &) + { + Assert (false, ExcNotImplemented()); + } + } +} + + template -template +template inline void -TableBase::fill (const T2 *entries) +TableBase::fill (ForwardIterator entries, + const bool C_style_indexing) { Assert (n_elements() != 0, ExcMessage("Trying to fill an empty matrix.")); - std::copy (entries, entries+n_elements(), values.begin()); + if (C_style_indexing) + std::copy_n (entries, n_elements(), values.begin()); + else + internal::Table::fill_Fortran_style (entries, *this); } diff --git a/deal.II/include/deal.II/matrix_free/shape_info.h b/deal.II/include/deal.II/matrix_free/shape_info.h index e25b8bfb37..8bbae186b8 100644 --- a/deal.II/include/deal.II/matrix_free/shape_info.h +++ b/deal.II/include/deal.II/matrix_free/shape_info.h @@ -112,7 +112,7 @@ namespace internal * 2*dim faces, and the columns the * DoFs on the faces. */ - Table<2,unsigned int> face_indices; + dealii::Table<2,unsigned int> face_indices; /** * Stores one-dimensional values of shape functions evaluated in zero -- 2.39.5