LifeV
GraphElement.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory UNiversity
7 
8  This file is part of the LifeV library
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, see <http://www.gnu.org/licenses/>
22 
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /*!
29  * @file
30  @brief This file contains the definition of the GraphElement class.
31 
32  @date 06/2011
33  @author Radu Popescu <radu.popescu@epfl.ch>
34  */
35 
36 #ifndef GRAPH_ELEMENT_HPP
37 #define GRAPH_ELEMENT_HPP
38 
39 #ifdef _OPENMP
40 #include <omp.h>
41 #endif
42 
43 #include <lifev/core/LifeV.hpp>
44 #include <lifev/core/util/OpenMPParameters.hpp>
45 
46 #include <lifev/core/fem/QuadratureRule.hpp>
47 #include <lifev/eta/fem/ETCurrentFE.hpp>
48 #include <lifev/eta/fem/MeshGeometricMap.hpp>
49 
50 #include <lifev/eta/expression/ExpressionToEvaluation.hpp>
51 
52 #include <lifev/eta/array/ETMatrixElemental.hpp>
53 
54 #include <boost/shared_ptr.hpp>
55 
56 
57 
58 namespace LifeV
59 {
60 
61 namespace ExpressionAssembly
62 {
63 
64 
65 //! The class to actually perform the loop over the elements to precompute a graph
66 /*!
67  @author Radu Popescu <radu.popescu@epfl.ch>
68 
69  This class is used to store the data required for building the graph of a
70  matrix
71  */
72 template < typename MeshType,
73  typename TestSpaceType,
74  typename SolutionSpaceType,
75  typename ExpressionType >
77 {
78 public:
79 
80  //! @name Public Types
81  //@{
82 
83  //! Type of the Evaluation
84  typedef typename ExpressionToEvaluation < ExpressionType,
85  TestSpaceType::field_dim,
86  SolutionSpaceType::field_dim,
88 
89  //@}
90 
91 
92  //! @name Constructors, destructor
93  //@{
94 
95  //! Full data constructor
96  GraphElement (const std::shared_ptr<MeshType>& mesh,
97  const QuadratureRule& quadrature,
98  const std::shared_ptr<TestSpaceType>& testSpace,
99  const std::shared_ptr<SolutionSpaceType>& solutionSpace,
100  const ExpressionType& expression,
101  const OpenMPParameters& ompParams,
102  const UInt offsetUp = 0,
103  const UInt offsetLeft = 0);
104 
105  //! Copy constructor
106  GraphElement (const GraphElement < MeshType,
107  TestSpaceType,
108  SolutionSpaceType,
109  ExpressionType > & integrator);
110 
111  //! Destructor
112  ~GraphElement();
113 
114  //@}
115 
116 
117  //! @name Operators
118  //@{
119 
120  //! Operator wrapping the addTo method (for shared_ptr)
121  template <typename GraphType>
122  inline void operator>> (std::shared_ptr<GraphType> graph)
123  {
124  addTo (graph);
125  }
126 
127  //@}
128 
129 
130  //! @name Methods
131  //@{
132 
133  //! Ouput method
134  void check (std::ostream& out = std::cout);
135 
136  //! Method that builds the graph
137  /*!
138  The loop over the elements is located right
139  in this method.
140  */
141  template <typename GraphType>
142  void addTo (GraphType& graph);
143 
144  //! Method that performs the assembly
145  /*!
146  The loop over the elements is located right
147  in this method.
148 
149  Specialized for the case where the matrix is passed as a shared_ptr
150  */
151  template <typename GraphType>
152  inline void addTo (std::shared_ptr<GraphType> graph)
153  {
154  ASSERT (graph != 0, " Cannot assemble with an empty graph");
155  addTo (*graph);
156  }
157 
158  //@}
159 
160 private:
161 
162  //! @name Private Methods
163  //@{
164 
165  //! No empty constructor
166  GraphElement();
167 
168  //@}
169 
170  // Pointer on the mesh
172 
173  // Quadrature to be used
175 
176  // Shared pointer on the Spaces
179 
180  // For multi-threading
181  OpenMPParameters M_ompParams;
182 
183  // Offsets
186 };
187 
188 
189 // ===================================================
190 // IMPLEMENTATION
191 // ===================================================
192 
193 // ===================================================
194 // Constructors & Destructor
195 // ===================================================
196 
197 template < typename MeshType, typename TestSpaceType, typename SolutionSpaceType, typename ExpressionType>
198 GraphElement<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType>::
199 GraphElement (const std::shared_ptr<MeshType>& mesh,
200  const QuadratureRule& quadrature,
201  const std::shared_ptr<TestSpaceType>& testSpace,
202  const std::shared_ptr<SolutionSpaceType>& solutionSpace,
203  const ExpressionType& /*expression*/,
204  const OpenMPParameters& ompParams,
205  const UInt offsetUp,
206  const UInt offsetLeft)
207  : M_mesh (mesh),
211  M_ompParams (ompParams),
212  M_offsetUp (offsetUp),
213  M_offsetLeft (offsetLeft)
214 {
215 }
216 
217 template < typename MeshType, typename TestSpaceType, typename SolutionSpaceType, typename ExpressionType>
218 GraphElement<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType>::
219 GraphElement (const GraphElement<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType>& integrator)
224  M_ompParams (integrator.M_ompParams),
225  M_offsetUp (integrator.M_offsetUp),
226  M_offsetLeft (integrator.M_offsetLeft)
227 {
228 }
229 
230 template < typename MeshType, typename TestSpaceType, typename SolutionSpaceType, typename ExpressionType>
231 GraphElement<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType>::
233 {
234 }
235 
236 // ===================================================
237 // Methods
238 // ===================================================
239 
240 template < typename MeshType, typename TestSpaceType, typename SolutionSpaceType, typename ExpressionType>
241 void
242 GraphElement<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType>::
243 check (std::ostream& out)
244 {
245 }
246 
247 
248 template < typename MeshType, typename TestSpaceType, typename SolutionSpaceType, typename ExpressionType>
249 template <typename GraphType>
250 void
251 GraphElement<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType>::
252 addTo (GraphType& graph)
253 {
254  UInt nbElements (M_mesh->numElements() );
255  UInt nbTestDof (M_testSpace->refFE().nbDof() );
256  UInt nbSolutionDof (M_solutionSpace->refFE().nbDof() );
257 
258  // OpenMP setup and pragmas around the loop
259  M_ompParams.apply();
260 
261  #pragma omp parallel
262  {
263  ETMatrixElemental elementalMatrix (TestSpaceType::field_dim * M_testSpace->refFE().nbDof(),
264  SolutionSpaceType::field_dim * M_solutionSpace->refFE().nbDof() );
265 
266  #pragma omp for schedule(runtime)
267  for (UInt iElement = 0; iElement < nbElements; ++iElement)
268  {
269  // Zeros out the matrix
270  elementalMatrix.zero();
271 
272  // Loop on the blocks
273  for (UInt iblock (0); iblock < TestSpaceType::field_dim; ++iblock)
274  {
275  for (UInt jblock (0); jblock < SolutionSpaceType::field_dim; ++jblock)
276  {
277 
278  // Set the row global indices in the local matrix
279  for (UInt i (0); i < nbTestDof; ++i)
280  {
281  elementalMatrix.setRowIndex
282  (i + iblock * nbTestDof,
283  M_testSpace->dof().localToGlobalMap (iElement, i) + iblock * M_testSpace->dof().numTotalDof() + M_offsetUp);
284  }
285 
286  // Set the column global indices in the local matrix
287  for (UInt j (0); j < nbSolutionDof; ++j)
288  {
289  elementalMatrix.setColumnIndex
290  (j + jblock * nbSolutionDof,
291  M_solutionSpace->dof().localToGlobalMap (iElement, j) + jblock * M_solutionSpace->dof().numTotalDof() + M_offsetLeft);
292  }
293  }
294  }
295  const std::vector<Int>& rowIdx = elementalMatrix.rowIndices();
296  const std::vector<Int>& colIdx = elementalMatrix.columnIndices();
297  #pragma omp critical
298  {
299  graph.InsertGlobalIndices (rowIdx.size(), &rowIdx[0],
300  colIdx.size(), &colIdx[0]);
301  }
302  }
303  }
304  M_ompParams.restorePreviousNumThreads();
305 }
306 
307 
308 } // Namespace ExpressionAssembly
309 
310 } // Namespace LifeV
311 
312 #endif
GraphElement(const GraphElement< MeshType, TestSpaceType, SolutionSpaceType, ExpressionType > &integrator)
Copy constructor.
ExpressionToEvaluation< ExpressionType, TestSpaceType::field_dim, SolutionSpaceType::field_dim, 3 >::evaluation_Type evaluation_Type
Type of the Evaluation.
void operator>>(std::shared_ptr< GraphType > graph)
Operator wrapping the addTo method (for shared_ptr)
void addTo(std::shared_ptr< GraphType > graph)
Method that performs the assembly.
std::shared_ptr< MeshType > M_mesh
std::shared_ptr< TestSpaceType > M_testSpace
GraphElement()
No empty constructor.
The class to actually perform the loop over the elements to precompute a graph.
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
GraphElement(const std::shared_ptr< MeshType > &mesh, const QuadratureRule &quadrature, const std::shared_ptr< TestSpaceType > &testSpace, const std::shared_ptr< SolutionSpaceType > &solutionSpace, const ExpressionType &expression, const OpenMPParameters &ompParams, const UInt offsetUp=0, const UInt offsetLeft=0)
Full data constructor.
void addTo(GraphType &graph)
Method that builds the graph.
std::shared_ptr< SolutionSpaceType > M_solutionSpace
QuadratureRule - The basis class for storing and accessing quadrature rules.
void check(std::ostream &out=std::cout)
Ouput method.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191