From febbd05e590f1758f285d1e4449bfff66913d46f Mon Sep 17 00:00:00 2001 From: kanschat Date: Thu, 17 Jun 2010 15:51:46 +0000 Subject: [PATCH] further cleaning in MeshWorker git-svn-id: https://svn.dealii.org/trunk@21222 0785d39b-7218-0410-832d-ea1e28bc413d --- .../deal.II/include/numerics/mesh_worker.h | 425 ++++++++++++++++- .../include/numerics/mesh_worker_info.h | 444 +----------------- .../mesh_worker_vector_selector.templates.h | 4 +- .../deal.II/source/numerics/mesh_worker.cc | 29 +- deal.II/examples/step-12/step-12.cc | 1 + deal.II/examples/step-39/step-39.cc | 3 + 6 files changed, 451 insertions(+), 455 deletions(-) diff --git a/deal.II/deal.II/include/numerics/mesh_worker.h b/deal.II/deal.II/include/numerics/mesh_worker.h index aca24c21bc..97b53e3308 100644 --- a/deal.II/deal.II/include/numerics/mesh_worker.h +++ b/deal.II/deal.II/include/numerics/mesh_worker.h @@ -16,16 +16,13 @@ #include #include #include -#include -#include -#include +#include +#include #include -#include -#include - DEAL_II_NAMESPACE_OPEN +class BlockIndices; template class DoFHandler; template class MGDoFHandler; @@ -174,8 +171,422 @@ template class MGDoFHandler; */ namespace MeshWorker { -} +/** + * The class providing the scrapbook to fill with local integration + * results. These can be values, local contributions to forms or cell + * and face matrices. + * + * The local matrices initialized by reinit() of the info object and + * then assembled into the global system by Assembler classes. + * + * @ingroup MeshWorker + * @author Guido Kanschat, 2009 + */ + template + class LocalResults + { + private: + /** + * Initialize a single local + * matrix block. A helper + * function for initialize() + */ + void initialize_local(MatrixBlock >& M, + const unsigned int row, + const unsigned int col); + + public: + void initialize_numbers(const unsigned int n); + void initialize_vectors(const unsigned int n); + /** + * Allocate @p n local + * matrices. Additionally, + * set their block row and + * column coordinates to + * zero. The matrices + * themselves are resized by + * reinit(). + * + * The template parameter @p + * MatrixPtr should point to + * a MatrixBlock + * instantiation in order to + * provide row and column info. + */ + void initialize_matrices(unsigned int n, bool both); + + /** + * Allocate a local matrix + * for each of the global + * ones in @p + * matrices. Additionally, + * set their block row and + * column coordinates. The + * matrices themselves are + * resized by reinit(). + * + * The template parameter @p + * MatrixPtr should point to + * a MatrixBlock + * instantiation in order to + * provide row and column info. + */ + template + void initialize_matrices(const MatrixBlockVector& matrices, + bool both); + + /** + * Initialize quadrature values + * to nv values in + * np quadrature points. + */ + void initialize_quadrature(unsigned int np, unsigned int nv); + + /** + * Reinitialize matrices for + * new cell. Resizes the + * matrices for hp and sets + * them to zero. + */ + void reinit(const BlockIndices& local_sizes); + + /** + * The number of scalar values. + */ + unsigned int n_values () const; + + /** + * The number of vectors. + */ + unsigned int n_vectors () const; + + /** + * The number of matrices. + */ + unsigned int n_matrices () const; + + /** + * The number of quadrature + * points in #quadrature_values. + */ + unsigned int n_quadrature_points() const; + + /** + * The number of values in each + * quadrature point in + * #quadrature_values. + */ + unsigned int n_quadrature_values() const; + + /** + * Access scalar value at index + * @p i. + */ + number& value(unsigned int i); + + /** + * Read scalar value at index + * @p i. + */ + number value(unsigned int i) const; + + /** + * Access vector at index @p i. + */ + BlockVector& vector(unsigned int i); + + /** + * Read vector at index @p i. + */ + const BlockVector& vector(unsigned int i) const; + + /** + * Access matrix at index @p + * i. For results on internal + * faces, a true value for @p + * external refers to the flux + * between cells, while false + * refers to entries coupling + * inside the cell. + */ + MatrixBlock >& matrix(unsigned int i, bool external = false); + + /** + * Read matrix at index @p + * i. For results on internal + * faces, a true value for @p + * external refers to the flux + * between cells, while false + * refers to entries coupling + * inside the cell. + */ + const MatrixBlock >& matrix(unsigned int i, bool external = false) const; + + /** + * Access the ith value + * at quadrature point k + */ + number& quadrature_value(unsigned int k, unsigned int i); + + /** + * Read the ith value + * at quadrature point k + */ + number quadrature_value(unsigned int k, unsigned int i) const; + + private: + /** + * The local numbers, + * computed on a cell or on a + * face. + */ + std::vector J; + + /** + * The local vectors. This + * field is public, so that + * local integrators can + * write to it. + */ + std::vector > R; + + /** + * The local matrices + * coupling degrees of + * freedom in the cell + * itself or within the + * first cell on a face. + */ + std::vector > > M1; + + /** + * The local matrices + * coupling test functions on + * the cell with trial + * functions on the other + * cell. + * + * Only used on interior + * faces. + */ + std::vector > > M2; + /** + * Values in quadrature points. + */ + std::vector > quadrature_values; + }; + +//----------------------------------------------------------------------// + + template + inline void + LocalResults::initialize_numbers(unsigned int n) + { + J.resize(n); + } + + + template + inline void + LocalResults::initialize_vectors(const unsigned int n) + { + R.resize(n); + } + + + template + template + inline void + LocalResults::initialize_matrices( + const MatrixBlockVector& matrices, + bool both) + { + M1.resize(matrices.size()); + if (both) + M2.resize(matrices.size()); + for (unsigned int i=0;i + inline void + LocalResults::initialize_matrices(const unsigned int n, + const bool both) + { + M1.resize(n); + if (both) + M2.resize(n); + for (unsigned int i=0;i + inline void + LocalResults::initialize_quadrature(unsigned int np, unsigned int nv) + { + quadrature_values.resize(np, std::vector(nv)); + } + + + template + inline + unsigned int + LocalResults::n_values() const + { + return J.size(); + } + + + template + inline + unsigned int + LocalResults::n_vectors() const + { + return R.size(); + } + + + template + inline + unsigned int + LocalResults::n_matrices() const + { + return M1.size(); + } + + + template + inline + unsigned int + LocalResults::n_quadrature_points() const + { + return quadrature_values.size(); + } + + + template + inline + unsigned int + LocalResults::n_quadrature_values() const + { + Assert(quadrature_values.size() != 0, ExcNotInitialized()); + return quadrature_values[0].size(); + } + + + template + inline + number& + LocalResults::value(unsigned int i) + { + AssertIndexRange(i,J.size()); + return J[i]; + } + + + template + inline + BlockVector& + LocalResults::vector(unsigned int i) + { + AssertIndexRange(i,R.size()); + return R[i]; + } + + + template + inline + MatrixBlock >& + LocalResults::matrix(unsigned int i, bool external) + { + if (external) + { + AssertIndexRange(i,M2.size()); + return M2[i]; + } + AssertIndexRange(i,M1.size()); + return M1[i]; + } + + + template + inline + number& + LocalResults::quadrature_value(unsigned int k, unsigned int i) + { + AssertIndexRange(k,quadrature_values.size()); + AssertIndexRange(i,quadrature_values[0].size()); + return quadrature_values[k][i]; + } + + + template + inline + number + LocalResults::value(unsigned int i) const + { + AssertIndexRange(i,J.size()); + return J[i]; + } + + + template + inline + const BlockVector& + LocalResults::vector(unsigned int i) const + { + AssertIndexRange(i,R.size()); + return R[i]; + } + + + template + inline + const MatrixBlock >& + LocalResults::matrix(unsigned int i, bool external) const + { + if (external) + { + AssertIndexRange(i,M2.size()); + return M2[i]; + } + AssertIndexRange(i,M1.size()); + return M1[i]; + } + + + template + inline + number + LocalResults::quadrature_value(unsigned int k, unsigned int i) const + { + AssertIndexRange(k,quadrature_values.size()); + AssertIndexRange(i,quadrature_values[0].size()); + return quadrature_values[k][i]; + } +} DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/deal.II/include/numerics/mesh_worker_info.h b/deal.II/deal.II/include/numerics/mesh_worker_info.h index cfa71204d6..e14ec200ac 100644 --- a/deal.II/deal.II/include/numerics/mesh_worker_info.h +++ b/deal.II/deal.II/include/numerics/mesh_worker_info.h @@ -14,10 +14,10 @@ #define __deal2__mesh_worker_info_h #include -#include #include #include #include +#include #include DEAL_II_NAMESPACE_OPEN @@ -25,215 +25,6 @@ DEAL_II_NAMESPACE_OPEN namespace MeshWorker { template class DoFInfoBox; - -/** - * The class providing the scrapbook to fill with local integration - * results. These can be values, local contributions to forms or cell - * and face matrices. - * - * The local matrices initialized by reinit() of the info object and - * then assembled into the global system by Assembler classes. - * - * @ingroup MeshWorker - * @author Guido Kanschat, 2009 - */ - template - class LocalResults - { - private: - /** - * Initialize a single local - * matrix block. A helper - * function for initialize() - */ - void initialize_local(MatrixBlock >& M, - const unsigned int row, - const unsigned int col); - - public: - void initialize_numbers(const unsigned int n); - void initialize_vectors(const unsigned int n); - /** - * Allocate @p n local - * matrices. Additionally, - * set their block row and - * column coordinates to - * zero. The matrices - * themselves are resized by - * reinit(). - * - * The template parameter @p - * MatrixPtr should point to - * a MatrixBlock - * instantiation in order to - * provide row and column info. - */ - void initialize_matrices(unsigned int n, bool both); - - /** - * Allocate a local matrix - * for each of the global - * ones in @p - * matrices. Additionally, - * set their block row and - * column coordinates. The - * matrices themselves are - * resized by reinit(). - * - * The template parameter @p - * MatrixPtr should point to - * a MatrixBlock - * instantiation in order to - * provide row and column info. - */ - template - void initialize_matrices(const MatrixBlockVector& matrices, - bool both); - - /** - * Initialize quadrature values - * to nv values in - * np quadrature points. - */ - void initialize_quadrature(unsigned int np, unsigned int nv); - - /** - * Reinitialize matrices for - * new cell. Resizes the - * matrices for hp and sets - * them to zero. - */ - void reinit(const BlockIndices& local_sizes); - - /** - * The number of scalar values. - */ - unsigned int n_values () const; - - /** - * The number of vectors. - */ - unsigned int n_vectors () const; - - /** - * The number of matrices. - */ - unsigned int n_matrices () const; - - /** - * The number of quadrature - * points in #quadrature_values. - */ - unsigned int n_quadrature_points() const; - - /** - * The number of values in each - * quadrature point in - * #quadrature_values. - */ - unsigned int n_quadrature_values() const; - - /** - * Access scalar value at index - * @p i. - */ - number& value(unsigned int i); - - /** - * Read scalar value at index - * @p i. - */ - number value(unsigned int i) const; - - /** - * Access vector at index @p i. - */ - BlockVector& vector(unsigned int i); - - /** - * Read vector at index @p i. - */ - const BlockVector& vector(unsigned int i) const; - - /** - * Access matrix at index @p - * i. For results on internal - * faces, a true value for @p - * external refers to the flux - * between cells, while false - * refers to entries coupling - * inside the cell. - */ - MatrixBlock >& matrix(unsigned int i, bool external = false); - - /** - * Read matrix at index @p - * i. For results on internal - * faces, a true value for @p - * external refers to the flux - * between cells, while false - * refers to entries coupling - * inside the cell. - */ - const MatrixBlock >& matrix(unsigned int i, bool external = false) const; - - /** - * Access the ith value - * at quadrature point k - */ - number& quadrature_value(unsigned int k, unsigned int i); - - /** - * Read the ith value - * at quadrature point k - */ - number quadrature_value(unsigned int k, unsigned int i) const; - - private: - /** - * The local numbers, - * computed on a cell or on a - * face. - */ - std::vector J; - - /** - * The local vectors. This - * field is public, so that - * local integrators can - * write to it. - */ - std::vector > R; - - /** - * The local matrices - * coupling degrees of - * freedom in the cell - * itself or within the - * first cell on a face. - */ - std::vector > > M1; - - /** - * The local matrices - * coupling test functions on - * the cell with trial - * functions on the other - * cell. - * - * Only used on interior - * faces. - */ - std::vector > > M2; - - /** - * Values in quadrature points. - */ - std::vector > quadrature_values; - }; - - template class DoFInfoBox; - /** * A class containing information on geometry and degrees of freedom * of a mesh object. @@ -1001,237 +792,6 @@ namespace MeshWorker }; -//----------------------------------------------------------------------// - - template - inline void - LocalResults::initialize_numbers(unsigned int n) - { - J.resize(n); - } - - - template - inline void - LocalResults::initialize_vectors(const unsigned int n) - { - R.resize(n); - } - - - template - template - inline void - LocalResults::initialize_matrices( - const MatrixBlockVector& matrices, - bool both) - { - M1.resize(matrices.size()); - if (both) - M2.resize(matrices.size()); - for (unsigned int i=0;i - inline void - LocalResults::initialize_matrices(const unsigned int n, - const bool both) - { - M1.resize(n); - if (both) - M2.resize(n); - for (unsigned int i=0;i - inline void - LocalResults::initialize_quadrature(unsigned int np, unsigned int nv) - { - quadrature_values.resize(np, std::vector(nv)); - } - - - template - inline void - LocalResults::reinit(const BlockIndices& bi) - { - for (unsigned int i=0;i - inline - unsigned int - LocalResults::n_values() const - { - return J.size(); - } - - - template - inline - unsigned int - LocalResults::n_vectors() const - { - return R.size(); - } - - - template - inline - unsigned int - LocalResults::n_matrices() const - { - return M1.size(); - } - - - template - inline - unsigned int - LocalResults::n_quadrature_points() const - { - return quadrature_values.size(); - } - - - template - inline - unsigned int - LocalResults::n_quadrature_values() const - { - Assert(quadrature_values.size() != 0, ExcNotInitialized()); - return quadrature_values[0].size(); - } - - - template - inline - number& - LocalResults::value(unsigned int i) - { - AssertIndexRange(i,J.size()); - return J[i]; - } - - - template - inline - BlockVector& - LocalResults::vector(unsigned int i) - { - AssertIndexRange(i,R.size()); - return R[i]; - } - - - template - inline - MatrixBlock >& - LocalResults::matrix(unsigned int i, bool external) - { - if (external) - { - AssertIndexRange(i,M2.size()); - return M2[i]; - } - AssertIndexRange(i,M1.size()); - return M1[i]; - } - - - template - inline - number& - LocalResults::quadrature_value(unsigned int k, unsigned int i) - { - AssertIndexRange(k,quadrature_values.size()); - AssertIndexRange(i,quadrature_values[0].size()); - return quadrature_values[k][i]; - } - - - template - inline - number - LocalResults::value(unsigned int i) const - { - AssertIndexRange(i,J.size()); - return J[i]; - } - - - template - inline - const BlockVector& - LocalResults::vector(unsigned int i) const - { - AssertIndexRange(i,R.size()); - return R[i]; - } - - - template - inline - const MatrixBlock >& - LocalResults::matrix(unsigned int i, bool external) const - { - if (external) - { - AssertIndexRange(i,M2.size()); - return M2[i]; - } - AssertIndexRange(i,M1.size()); - return M1[i]; - } - - - template - inline - number - LocalResults::quadrature_value(unsigned int k, unsigned int i) const - { - AssertIndexRange(k,quadrature_values.size()); - AssertIndexRange(i,quadrature_values[0].size()); - return quadrature_values[k][i]; - } - - //----------------------------------------------------------------------// template @@ -1481,7 +1041,7 @@ namespace MeshWorker p->initialize(data); cell_data = p; cell.initialize_data(p); - + p = boost::shared_ptr >(new VectorData (boundary_selector)); p->initialize(data); boundary_data = p; diff --git a/deal.II/deal.II/include/numerics/mesh_worker_vector_selector.templates.h b/deal.II/deal.II/include/numerics/mesh_worker_vector_selector.templates.h index 5b8c3f826f..053f5f4369 100644 --- a/deal.II/deal.II/include/numerics/mesh_worker_vector_selector.templates.h +++ b/deal.II/deal.II/include/numerics/mesh_worker_vector_selector.templates.h @@ -128,14 +128,14 @@ namespace MeshWorker for (unsigned int i=0;in_gradients();++i) { - const VECTOR& src = *data(this->value_index(i)); + const VECTOR& src = *data(this->gradient_index(i)); VectorSlice > > > dst(gradients[i], component, n_comp); fe.get_function_gradients(src, make_slice(index, start, size), dst, true); } for (unsigned int i=0;in_hessians();++i) { - const VECTOR& src = *data(this->value_index(i)); + const VECTOR& src = *data(this->hessian_index(i)); VectorSlice > > > dst(hessians[i], component, n_comp); fe.get_function_hessians(src, make_slice(index, start, size), dst, true); } diff --git a/deal.II/deal.II/source/numerics/mesh_worker.cc b/deal.II/deal.II/source/numerics/mesh_worker.cc index 803c7e5a83..662cffde0f 100644 --- a/deal.II/deal.II/source/numerics/mesh_worker.cc +++ b/deal.II/deal.II/source/numerics/mesh_worker.cc @@ -10,12 +10,33 @@ // //--------------------------------------------------------------------------- -#include -#include -#include #include -#include +#include DEAL_II_NAMESPACE_OPEN +using namespace MeshWorker; + +template +void +LocalResults::reinit(const BlockIndices& bi) +{ + for (unsigned int i=0;i; +template class LocalResults; + DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/examples/step-12/step-12.cc b/deal.II/examples/step-12/step-12.cc index bd07fd93a6..01a3c1a8ec 100644 --- a/deal.II/examples/step-12/step-12.cc +++ b/deal.II/examples/step-12/step-12.cc @@ -62,6 +62,7 @@ // for using the MeshWorker framework: #include #include +#include #include // Like in all programs, we finish diff --git a/deal.II/examples/step-39/step-39.cc b/deal.II/examples/step-39/step-39.cc index 2028ed8672..30e77699b7 100644 --- a/deal.II/examples/step-39/step-39.cc +++ b/deal.II/examples/step-39/step-39.cc @@ -38,6 +38,8 @@ // The include files for using the // MeshWorker framework #include +#include +#include #include // Support for multigrid methods @@ -850,6 +852,7 @@ Step39::estimate() // solution we just computed. NamedData* > solution_data; solution_data.add(&solution, "solution"); + // Then, we tell the Meshworker::VectorSelector // for cells, that we need the // second derivatives of this -- 2.39.5