From: kanschat Date: Fri, 14 Sep 2012 08:37:12 +0000 (+0000) Subject: add a simplified interface for MeshWorker::loop() X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b47cc3f37398dec2772c3ec1a9071033169edad9;p=dealii-svn.git add a simplified interface for MeshWorker::loop() git-svn-id: https://svn.dealii.org/trunk@26371 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/meshworker/local_integrator.h b/deal.II/include/deal.II/meshworker/local_integrator.h new file mode 100644 index 0000000000..4777ff70df --- /dev/null +++ b/deal.II/include/deal.II/meshworker/local_integrator.h @@ -0,0 +1,111 @@ +//--------------------------------------------------------------------------- +// $Id: loop.h 26042 2012-08-20 19:22:01Z bangerth $ +// +// Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 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__mesh_worker_local_integrator_h +#define __deal2__mesh_worker_local_integrator_h + +#include +#include + +DEAL_II_NAMESPACE_OPEN + +namespace MeshWorker +{ + template class DoFInfo; + template class IntegrationInfo; + +/** + * A local integrator object, which can be used to simplify the call + * of loop(). Instead of providing the three local integration + * functions separately, we bundle them as virtual functions in this + * class. + * + * Additionally, since we cannot have a virtual null function, we + * provide flags, which allow us to indicate, whether we want to + * integrate on boundary and interior faces. Thes flags are true by + * default, but can be modified by applications to speed up the loop. + * + * @ingroup MeshWorker + * @author Guido Kanschat + * @date 2012 + */ + template + class LocalIntegrator : public Subscriptor + { + public: + /** + * The constructor setting + * default values. + */ + LocalIntegrator(); + + /** + * The empty virtual destructor. + */ + ~LocalIntegrator(); + + /** + * Virtual function for + * integrating on cells. + */ + virtual void cell(DoFInfo& dinfo, + IntegrationInfo& info) const = 0; + /** + * Virtual function for + * integrating on boundary faces. + */ + virtual void boundary(DoFInfo& dinfo, + IntegrationInfo& info) const = 0; + /** + * Virtual function for + * integrating on interior faces. + */ + virtual void face(DoFInfo& dinfo1, + DoFInfo& dinfo2, + IntegrationInfo& info1, + IntegrationInfo& info2) const = 0; + + /** + * The flag indicating whether + * the cell integrator cell() + * is to be used in the + * loop. Defaults to + * true. + */ + bool use_cell; + + /** + * The flag indicating whether + * the boundary integrator + * boundary() is to be + * used in the loop. Defaults + * to true. + */ + bool use_boundary; + + /** + * The flag indicating whether + * the interior face integrator + * face() is to be used in the + * loop. Defaults to + * true. + */ + bool use_face; + + }; +} + + + +DEAL_II_NAMESPACE_CLOSE + +#endif diff --git a/deal.II/include/deal.II/meshworker/local_results.h b/deal.II/include/deal.II/meshworker/local_results.h index cb27256847..829f68840c 100644 --- a/deal.II/include/deal.II/meshworker/local_results.h +++ b/deal.II/include/deal.II/meshworker/local_results.h @@ -31,7 +31,10 @@ template class MGDoFHandler; * an ubiquitous part of each finite element program. * * The workhorse of this namespace is the loop() function, which implements a - * completely generic loop over all mesh cells. + * completely generic loop over all mesh cells. Since the calls to + * loop() are error-prone due to its generality, for many applications + * it is advisable to derive a class from MeshWorker::LocalIntegrator + * and use the less general integration_loop() instead. * * The loop() depends on certain objects handed to it as * arguments. These objects are of two types, info objects like diff --git a/deal.II/include/deal.II/meshworker/loop.h b/deal.II/include/deal.II/meshworker/loop.h index 1c1f648287..c3d2d3224c 100644 --- a/deal.II/include/deal.II/meshworker/loop.h +++ b/deal.II/include/deal.II/meshworker/loop.h @@ -18,9 +18,11 @@ #include #include #include +#include #include #include + #define DEAL_II_MESHWORKER_PARALLEL 1 DEAL_II_NAMESPACE_OPEN @@ -282,6 +284,9 @@ namespace MeshWorker } /** + * @deprecated The simplification in this loop is + * insignificant. Therefore, it is recommended to use loop() instead. + * * Simplified interface for loop() if specialized for integration. * * @ingroup MeshWorker @@ -310,6 +315,49 @@ namespace MeshWorker assembler, cells_first); } + + +/** + * Simplified interface for loop() if specialized for integration, + * using the virtual functions in LocalIntegrator. + * + * @ingroup MeshWorker + * @author Guido Kanschat, 2009 + */ + template + void integration_loop(ITERATOR begin, + typename identity::type end, + DoFInfo& dof_info, + IntegrationInfoBox& box, + const LocalIntegrator& integrator, + ASSEMBLER &assembler, + bool cells_first = true) + { + std_cxx1x::function&, IntegrationInfo&)> cell_worker; + std_cxx1x::function&, IntegrationInfo&)> boundary_worker; + std_cxx1x::function&, DoFInfo&, + IntegrationInfo&, + IntegrationInfo&)> face_worker; + if (integrator.use_cell) + cell_worker = std_cxx1x::bind(&LocalIntegrator::cell, &integrator, std_cxx1x::_1, std_cxx1x::_2); + if (integrator.use_boundary) + boundary_worker = std_cxx1x::bind(&LocalIntegrator::boundary, &integrator, std_cxx1x::_1, std_cxx1x::_2); + if (integrator.use_face) + face_worker = std_cxx1x::bind(&LocalIntegrator::face, &integrator, std_cxx1x::_1, std_cxx1x::_2, std_cxx1x::_3, std_cxx1x::_4); + + loop + (begin, end, + dof_info, + box, + cell_worker, + boundary_worker, + face_worker, + assembler, + cells_first); + } + + + } DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/source/numerics/mesh_worker.cc b/deal.II/source/numerics/mesh_worker.cc index 1ba1bbd28d..bd92f34bbf 100644 --- a/deal.II/source/numerics/mesh_worker.cc +++ b/deal.II/source/numerics/mesh_worker.cc @@ -11,6 +11,7 @@ //--------------------------------------------------------------------------- #include +#include #include DEAL_II_NAMESPACE_OPEN @@ -51,6 +52,30 @@ namespace MeshWorker template class LocalResults; template class LocalResults; + + template + LocalIntegrator::LocalIntegrator () + : + use_cell(true), use_boundary(true), use_face(true) + {} + + + template + LocalIntegrator::~LocalIntegrator () + {} + + template class LocalIntegrator<1,1,float>; + template class LocalIntegrator<1,1,double>; + template class LocalIntegrator<1,2,float>; + template class LocalIntegrator<1,2,double>; + template class LocalIntegrator<1,3,float>; + template class LocalIntegrator<1,3,double>; + template class LocalIntegrator<2,2,float>; + template class LocalIntegrator<2,2,double>; + template class LocalIntegrator<2,3,float>; + template class LocalIntegrator<2,3,double>; + template class LocalIntegrator<3,3,float>; + template class LocalIntegrator<3,3,double>; }