Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MPAssembly/BoxElemFixture.hpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos: Manycore Performance-Portable Multidimensional Arrays
6 // Copyright (2012) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_EXAMPLE_BOXELEMFIXTURE_HPP
45 #define KOKKOS_EXAMPLE_BOXELEMFIXTURE_HPP
46 
47 #include <stdio.h>
48 #include <utility>
49 
50 #include <Kokkos_Core.hpp>
51 
52 #include <HexElement.hpp>
53 #include <BoxElemPart.hpp>
54 
55 //----------------------------------------------------------------------------
56 
57 namespace Kokkos {
58 namespace Example {
59 
63 struct MapGridUnitCube {
64 
65  const double m_a ;
66  const double m_b ;
67  const double m_c ;
68  const size_t m_max_x ;
69  const size_t m_max_y ;
70  const size_t m_max_z ;
71 
72  MapGridUnitCube( const size_t grid_max_x ,
73  const size_t grid_max_y ,
74  const size_t grid_max_z ,
75  const double bubble_x ,
76  const double bubble_y ,
77  const double bubble_z )
78  : m_a( bubble_x )
79  , m_b( bubble_y )
80  , m_c( bubble_z )
81  , m_max_x( grid_max_x )
82  , m_max_y( grid_max_y )
83  , m_max_z( grid_max_z )
84  {}
85 
86  template< typename Scalar >
87  KOKKOS_INLINE_FUNCTION
88  void operator()( int grid_x ,
89  int grid_y ,
90  int grid_z ,
91  Scalar & coord_x ,
92  Scalar & coord_y ,
93  Scalar & coord_z ) const
94  {
95  // Map to a unit cube [0,1]^3
96 
97  const double x = double(grid_x) / double(m_max_x);
98  const double y = double(grid_y) / double(m_max_y);
99  const double z = double(grid_z) / double(m_max_z);
100 
101  coord_x = x + x * x * ( x - 1 ) * ( x - 1 ) * m_a ;
102  coord_y = y + y * y * ( y - 1 ) * ( y - 1 ) * m_b ;
103  coord_z = z + z * z * ( z - 1 ) * ( z - 1 ) * m_c ;
104  }
105 };
106 
107 } // namespace Example
108 } // namespace Kokkos
109 
110 //----------------------------------------------------------------------------
111 
112 namespace Kokkos {
113 namespace Example {
114 
121 template< class Device ,
122  BoxElemPart::ElemOrder Order ,
123  class CoordinateMap = MapGridUnitCube >
124 class BoxElemFixture {
125 public:
126 
127  typedef Device execution_space ;
128 
129  enum { SpaceDim = 3 };
130  enum { ElemNode = Order == BoxElemPart::ElemLinear ? 8 :
131  Order == BoxElemPart::ElemQuadratic ? 27 : 0 };
132 
133 private:
134 
136 
138  CoordinateMap m_coord_map ;
139 
140  Kokkos::View< double *[SpaceDim] , Device > m_node_coord ;
141  Kokkos::View< size_t *[SpaceDim] , Device > m_node_grid ;
142  Kokkos::View< size_t *[ElemNode] , Device > m_elem_node ;
143  Kokkos::View< size_t *[2] , Device > m_recv_node ;
144  Kokkos::View< size_t *[2] , Device > m_send_node ;
145  Kokkos::View< size_t * , Device > m_send_node_id ;
146 
147  unsigned char m_elem_node_local[ ElemNode ][4] ;
148 
149 public:
150 
151  typedef Kokkos::View< const size_t * [ElemNode], Device > elem_node_type ;
152  typedef Kokkos::View< const double * [SpaceDim], Device > node_coord_type ;
153  typedef Kokkos::View< const size_t * [SpaceDim], Device > node_grid_type ;
154  typedef Kokkos::View< const size_t * [2] , Device > comm_list_type ;
155  typedef Kokkos::View< const size_t * , Device > send_nodeid_type ;
156 
157  inline bool ok() const { return m_box_part.ok(); }
158 
159  KOKKOS_INLINE_FUNCTION
160  size_t node_count() const { return m_node_grid.extent(0); }
161 
162  KOKKOS_INLINE_FUNCTION
163  size_t node_count_owned() const { return m_box_part.owns_node_count(); }
164 
165  KOKKOS_INLINE_FUNCTION
166  size_t node_count_global() const { return m_box_part.global_node_count(); }
167 
168  KOKKOS_INLINE_FUNCTION
169  size_t elem_count() const { return m_elem_node.extent(0); }
170 
171  KOKKOS_INLINE_FUNCTION
172  size_t elem_count_global() const { return m_box_part.global_elem_count(); }
173 
174  KOKKOS_INLINE_FUNCTION
175  size_t elem_node_local( size_t inode , int k ) const
176  { return m_elem_node_local[inode][k] ; }
177 
178  KOKKOS_INLINE_FUNCTION
179  size_t node_grid( size_t inode , int iaxis ) const
180  { return m_node_grid(inode,iaxis); }
181 
182  KOKKOS_INLINE_FUNCTION
183  size_t node_global_index( size_t local ) const
184  {
185  const size_t nodeGrid[SpaceDim] =
186  { m_node_grid(local,0) , m_node_grid(local,1) , m_node_grid(local,2) };
187  return m_box_part.global_node_id( nodeGrid );
188  }
189 
190  KOKKOS_INLINE_FUNCTION
191  double node_coord( size_t inode , int iaxis ) const
192  { return m_node_coord(inode,iaxis); }
193 
194  KOKKOS_INLINE_FUNCTION
195  size_t node_grid_max( int iaxis ) const
196  { return m_box_part.global_coord_max(iaxis); }
197 
198  KOKKOS_INLINE_FUNCTION
199  size_t elem_node( size_t ielem , size_t inode ) const
200  { return m_elem_node(ielem,inode); }
201 
202  elem_node_type elem_node() const { return m_elem_node ; }
204  node_grid_type node_grid() const { return m_node_grid ; }
205  comm_list_type recv_node() const { return m_recv_node ; }
206  comm_list_type send_node() const { return m_send_node ; }
208 
209  KOKKOS_INLINE_FUNCTION
211  : m_box_part( rhs.m_box_part )
212  , m_coord_map( rhs.m_coord_map )
213  , m_node_coord( rhs.m_node_coord )
214  , m_node_grid( rhs.m_node_grid )
215  , m_elem_node( rhs.m_elem_node )
216  , m_recv_node( rhs.m_recv_node )
217  , m_send_node( rhs.m_send_node )
219  {
220  for ( int i = 0 ; i < ElemNode ; ++i ) {
221  m_elem_node_local[i][0] = rhs.m_elem_node_local[i][0] ;
222  m_elem_node_local[i][1] = rhs.m_elem_node_local[i][1] ;
223  m_elem_node_local[i][2] = rhs.m_elem_node_local[i][2] ;
224  m_elem_node_local[i][3] = 0 ;
225  }
226  }
227 
229  {
230  m_box_part = rhs.m_box_part ;
231  m_coord_map = rhs.m_coord_map ;
232  m_node_coord = rhs.m_node_coord ;
233  m_node_grid = rhs.m_node_grid ;
234  m_elem_node = rhs.m_elem_node ;
235  m_recv_node = rhs.m_recv_node ;
236  m_send_node = rhs.m_send_node ;
237  m_send_node_id = rhs.m_send_node_id ;
238 
239  for ( int i = 0 ; i < ElemNode ; ++i ) {
240  m_elem_node_local[i][0] = rhs.m_elem_node_local[i][0] ;
241  m_elem_node_local[i][1] = rhs.m_elem_node_local[i][1] ;
242  m_elem_node_local[i][2] = rhs.m_elem_node_local[i][2] ;
243  m_elem_node_local[i][3] = 0 ;
244  }
245  return *this ;
246  }
247 
249  const size_t global_size ,
250  const size_t global_rank ,
251  const size_t elem_nx ,
252  const size_t elem_ny ,
253  const size_t elem_nz ,
254  const double bubble_x = 1.1 ,
255  const double bubble_y = 1.2 ,
256  const double bubble_z = 1.3 )
257  : m_box_part( Order , decompose , global_size , global_rank , elem_nx , elem_ny , elem_nz )
258  , m_coord_map( m_box_part.global_coord_max(0) ,
259  m_box_part.global_coord_max(1) ,
260  m_box_part.global_coord_max(2) ,
261  bubble_x ,
262  bubble_y ,
263  bubble_z )
264  , m_node_coord( "fixture_node_coord" , m_box_part.uses_node_count() )
265  , m_node_grid( "fixture_node_grid" , m_box_part.uses_node_count() )
266  , m_elem_node( "fixture_elem_node" , m_box_part.uses_elem_count() )
267  , m_recv_node( "fixture_recv_node" , m_box_part.recv_node_msg_count() )
268  , m_send_node( "fixture_send_node" , m_box_part.send_node_msg_count() )
269  , m_send_node_id( "fixture_send_node_id" , m_box_part.send_node_id_count() )
270  {
271  {
272  const hex_data elem_data ;
273 
274  for ( int i = 0 ; i < ElemNode ; ++i ) {
275  m_elem_node_local[i][0] = elem_data.eval_map[i][0] ;
276  m_elem_node_local[i][1] = elem_data.eval_map[i][1] ;
277  m_elem_node_local[i][2] = elem_data.eval_map[i][2] ;
278  m_elem_node_local[i][3] = 0 ;
279  }
280  }
281 
282  const size_t nwork =
283  std::max( m_recv_node.extent(0) ,
284  std::max( m_send_node.extent(0) ,
285  std::max( m_send_node_id.extent(0) ,
286  std::max( m_node_grid.extent(0) ,
287  m_elem_node.extent(0) * m_elem_node.extent(1) ))));
288 
289  Kokkos::parallel_for( nwork , *this );
290  }
291 
292 
293  // Initialization:
294 
295  KOKKOS_INLINE_FUNCTION
296  void operator()( size_t i ) const
297  {
298  if ( i < m_elem_node.extent(0) * m_elem_node.extent(1) ) {
299 
300  const size_t ielem = i / ElemNode ;
301  const size_t inode = i % ElemNode ;
302 
303  size_t elem_grid[SpaceDim] ;
304  size_t nodeGrid[SpaceDim] ;
305 
306  m_box_part.uses_elem_coord( ielem , elem_grid );
307 
308  enum { elem_node_scale = Order == BoxElemPart::ElemLinear ? 1 :
309  Order == BoxElemPart::ElemQuadratic ? 2 : 0 };
310 
311  nodeGrid[0] = elem_node_scale * elem_grid[0] + m_elem_node_local[inode][0] ;
312  nodeGrid[1] = elem_node_scale * elem_grid[1] + m_elem_node_local[inode][1] ;
313  nodeGrid[2] = elem_node_scale * elem_grid[2] + m_elem_node_local[inode][2] ;
314 
315  m_elem_node(ielem,inode) = m_box_part.local_node_id( nodeGrid );
316  }
317 
318  if ( i < m_node_grid.extent(0) ) {
319  size_t nodeGrid[SpaceDim] ;
320  m_box_part.local_node_coord( i , nodeGrid );
321  m_node_grid(i,0) = nodeGrid[0] ;
322  m_node_grid(i,1) = nodeGrid[1] ;
323  m_node_grid(i,2) = nodeGrid[2] ;
324 
325  m_coord_map( nodeGrid[0] ,
326  nodeGrid[1] ,
327  nodeGrid[2] ,
328  m_node_coord(i,0) ,
329  m_node_coord(i,1) ,
330  m_node_coord(i,2) );
331  }
332 
333  if ( i < m_recv_node.extent(0) ) {
336  }
337 
338  if ( i < m_send_node.extent(0) ) {
341  }
342 
343  if ( i < m_send_node_id.extent(0) ) {
345  }
346  }
347 };
348 
349 } // namespace Example
350 } // namespace Kokkos
351 
352 //----------------------------------------------------------------------------
353 
354 #endif /* #ifndef KOKKOS_EXAMPLE_BOXELEMFIXTURE_HPP */
Kokkos::View< size_t *[SpaceDim], Device > m_node_grid
KOKKOS_INLINE_FUNCTION void uses_elem_coord(size_t lid, unsigned c[]) const
Kokkos::View< const unsigned *[2], Device > comm_list_type
Kokkos::View< size_t *[ElemNode], Device > m_elem_node
KOKKOS_INLINE_FUNCTION size_t elem_node_local(size_t inode, int k) const
Kokkos::View< const size_t *[SpaceDim], Device > node_grid_type
KOKKOS_INLINE_FUNCTION unsigned send_node_count(unsigned msg) const
KOKKOS_INLINE_FUNCTION size_t elem_node(size_t ielem, size_t inode) const
Kokkos::View< const size_t *[2], Device > comm_list_type
KOKKOS_INLINE_FUNCTION unsigned local_node_id(const unsigned c[]) const
KOKKOS_INLINE_FUNCTION void operator()(int grid_x, int grid_y, int grid_z, Scalar &coord_x, Scalar &coord_y, Scalar &coord_z) const
KOKKOS_INLINE_FUNCTION size_t global_node_id(const unsigned c[]) const
KOKKOS_INLINE_FUNCTION size_t global_elem_count() const
Kokkos::View< size_t *[2], Device > m_recv_node
Kokkos::View< const double *[SpaceDim], Device > node_coord_type
BoxElemFixture & operator=(const BoxElemFixture &rhs)
Kokkos::View< const unsigned *[ElemNode], Device > elem_node_type
KOKKOS_INLINE_FUNCTION double node_coord(size_t inode, int iaxis) const
Kokkos::View< unsigned *[2], Device > m_recv_node
Kokkos::View< const unsigned *[SpaceDim], Device > node_grid_type
KOKKOS_INLINE_FUNCTION unsigned send_node_id(unsigned item) const
KOKKOS_INLINE_FUNCTION size_t elem_count_global() const
Kokkos::View< unsigned *[2], Device > m_send_node
KOKKOS_INLINE_FUNCTION size_t node_grid(size_t inode, int iaxis) const
KOKKOS_INLINE_FUNCTION size_t node_grid_max(int iaxis) const
KOKKOS_INLINE_FUNCTION void local_node_coord(size_t lid, unsigned coord[]) const
Kokkos::View< const size_t *[ElemNode], Device > elem_node_type
Kokkos::View< const unsigned *, Device > send_nodeid_type
Kokkos::Example::HexElement_TensorData< ElemNode > hex_data
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
BoxElemFixture(const BoxElemPart::Decompose decompose, const size_t global_size, const size_t global_rank, const size_t elem_nx, const size_t elem_ny, const size_t elem_nz, const double bubble_x=1.1, const double bubble_y=1.2, const double bubble_z=1.3)
KOKKOS_INLINE_FUNCTION size_t owns_node_count() const
Kokkos::View< unsigned *[ElemNode], Device > m_elem_node
KOKKOS_INLINE_FUNCTION size_t node_count_owned() const
KOKKOS_INLINE_FUNCTION void operator()(size_t i) const
KOKKOS_INLINE_FUNCTION size_t node_count() const
Kokkos::View< double *[SpaceDim], Device > m_node_coord
KOKKOS_INLINE_FUNCTION size_t node_count_global() const
KOKKOS_INLINE_FUNCTION size_t node_global_index(size_t local) const
Kokkos::View< size_t *, Device > m_send_node_id
MapGridUnitCube(const size_t grid_max_x, const size_t grid_max_y, const size_t grid_max_z, const double bubble_x, const double bubble_y, const double bubble_z)
KOKKOS_INLINE_FUNCTION unsigned send_node_rank(unsigned msg) const
Kokkos::View< const size_t *, Device > send_nodeid_type
KOKKOS_INLINE_FUNCTION unsigned recv_node_count(unsigned msg) const
KOKKOS_INLINE_FUNCTION unsigned global_coord_max(unsigned axis) const
KOKKOS_INLINE_FUNCTION unsigned recv_node_rank(unsigned msg) const
Partition a box of hexahedral elements among subdomains.
KOKKOS_INLINE_FUNCTION size_t elem_count() const
Kokkos::View< size_t *[2], Device > m_send_node
Kokkos::View< unsigned *[SpaceDim], Device > m_node_grid
KOKKOS_INLINE_FUNCTION size_t global_node_count() const
KOKKOS_INLINE_FUNCTION BoxElemFixture(const BoxElemFixture &rhs)
Generate a distributed unstructured finite element mesh from a partitioned NX*NY*NZ box of elements...
Kokkos::View< unsigned *, Device > m_send_node_id