BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
concrete_grid_view_imp.hpp
1 // Copyright (C) 2011-2012 by the BEM++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #include "../common/common.hpp"
22 #include "../common/acc.hpp"
23 
24 #include "concrete_grid_view.hpp" // to make IDEs happy
25 
26 namespace Bempp
27 {
28 
29 template <typename DuneGridView>
30 void ConcreteGridView<DuneGridView>::getRawElementDataDoubleImpl(
31  arma::Mat<double>& vertices,
32  arma::Mat<int>& elementCorners,
33  arma::Mat<char>& auxData,
34  std::vector<int>* domainIndices) const
35 {
36  getRawElementDataImpl(vertices, elementCorners, auxData, domainIndices);
37 }
38 
39 template <typename DuneGridView>
40 void ConcreteGridView<DuneGridView>::getRawElementDataFloatImpl(arma::Mat<float>& vertices,
41  arma::Mat<int>& elementCorners,
42  arma::Mat<char>& auxData,
43  std::vector<int>* domainIndices) const
44 {
45  getRawElementDataImpl(vertices, elementCorners, auxData, domainIndices);
46 }
47 
48 template <typename DuneGridView>
49 template <typename CoordinateType>
50 void ConcreteGridView<DuneGridView>::getRawElementDataImpl(
51  arma::Mat<CoordinateType>& vertices,
52  arma::Mat<int>& elementCorners,
53  arma::Mat<char>& auxData,
54  std::vector<int>* domainIndices) const
55 {
56  typedef typename DuneGridView::Grid DuneGrid;
57  typedef typename DuneGridView::IndexSet DuneIndexSet;
58  const int dimGrid = DuneGrid::dimension;
59  const int dimWorld = DuneGrid::dimensionworld;
60  const int codimVertex = dimGrid;
61  const int codimElement = 0;
62  typedef Dune::LeafMultipleCodimMultipleGeomTypeMapper<DuneGrid,
63  Dune::MCMGElementLayout> DuneElementMapper;
64  typedef typename DuneGridView::template Codim<codimVertex>::Iterator
65  DuneVertexIterator;
66  typedef typename DuneGridView::template Codim<codimElement>::Iterator
67  DuneElementIterator;
68  typedef typename DuneGridView::template Codim<codimVertex>::Geometry
69  DuneVertexGeometry;
70  typedef typename DuneGridView::template Codim<codimElement>::Geometry
71  DuneElementGeometry;
72  typedef typename DuneGrid::ctype ctype;
73 
74  const DuneIndexSet& indexSet = m_dune_gv.indexSet();
75 
76  vertices.set_size(dimWorld, indexSet.size(codimVertex));
77  for (DuneVertexIterator it = m_dune_gv.template begin<codimVertex>();
78  it != m_dune_gv.template end<codimVertex>(); ++it)
79  {
80  size_t index = indexSet.index(*it);
81  const DuneVertexGeometry& geom = it->geometry();
82  Dune::FieldVector<ctype, dimWorld> vertex = geom.corner(0);
83  for (int i = 0; i < dimWorld; ++i)
84  vertices(i, index) = vertex[i];
85  }
86 
87  const int MAX_CORNER_COUNT = dimWorld == 2 ? 2 : 4;
88  DuneElementMapper elementMapper(m_dune_gv.grid());
89  const int elementCount = elementMapper.size();
90  elementCorners.set_size(MAX_CORNER_COUNT, elementCount);
91  for (DuneElementIterator it = m_dune_gv.template begin<codimElement>();
92  it != m_dune_gv.template end<codimElement>(); ++it)
93  {
94  size_t index = indexSet.index(*it);
95  const Dune::GenericReferenceElement<ctype, dimGrid>& refElement =
96  Dune::GenericReferenceElements<ctype, dimGrid>::general(it->type());
97  const int cornerCount = refElement.size(codimVertex);
98  assert(cornerCount <= MAX_CORNER_COUNT);
99  for (int i = 0; i < cornerCount; ++i)
100  elementCorners(i, index) = indexSet.subIndex(*it, i, codimVertex);
101  for (int i = cornerCount; i < MAX_CORNER_COUNT; ++i)
102  elementCorners(i, index) = -1;
103  }
104 
105  auxData.set_size(0, elementCorners.n_cols);
106 
107  if (domainIndices) {
108  // Somewhat inelegant: we perform a second iteration over elements,
109  // this time using the BEM++ interface to Dune.
110  domainIndices->resize(elementCount);
111  std::auto_ptr<EntityIterator<0> > it = this->entityIterator<0>();
112  const IndexSet& indexSet = this->indexSet();
113  while (!it->finished()) {
114  const Entity<0>& entity = it->entity();
115  const int index = indexSet.entityIndex(entity);
116  const int domain = entity.domain();
117  acc(*domainIndices, index) = domain;
118  it->next();
119  }
120  }
121 }
122 
123 } // namespace Bempp
Container::reference acc(Container &v, typename Container::size_type i)
Returns i&#39;th element of the container v, optionally checking bounds.
Definition: acc.hpp:38