DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_EntityCenteredField.cpp
1 //---------------------------------------------------------------------------//
2 /*
3  Copyright (c) 2012, Stuart R. Slattery
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are
8  met:
9 
10  *: Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12 
13  *: Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in the
15  documentation and/or other materials provided with the distribution.
16 
17  *: Neither the name of the University of Wisconsin - Madison nor the
18  names of its contributors may be used to endorse or promote products
19  derived from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 //---------------------------------------------------------------------------//
39 //---------------------------------------------------------------------------//
40 
41 #include "DTK_EntityCenteredField.hpp"
42 #include "DTK_DBC.hpp"
43 
44 namespace DataTransferKit
45 {
46 //---------------------------------------------------------------------------//
47 // Entity constructor.
49  const Teuchos::ArrayView<Entity> &entities, const int field_dim,
50  const Teuchos::ArrayRCP<double> &dof_data, const DataLayout layout )
51  : d_field_dim( field_dim )
52  , d_data( dof_data )
53  , d_layout( layout )
54 {
55  d_lda = entities.size();
56  DTK_CHECK( dof_data.size() == d_lda * d_field_dim );
57 
58  d_support_ids.resize( d_lda );
59  for ( int n = 0; n < d_lda; ++n )
60  {
61  d_support_ids[n] = entities[n].id();
62  d_id_map.emplace( d_support_ids[n], n );
63  }
64 }
65 
66 //---------------------------------------------------------------------------//
67 // Entity id constructor.
69  const Teuchos::ArrayView<const EntityId> &entity_ids, const int field_dim,
70  const Teuchos::ArrayRCP<double> &dof_data, const DataLayout layout )
71  : d_field_dim( field_dim )
72  , d_data( dof_data )
73  , d_layout( layout )
74 {
75  d_lda = entity_ids.size();
76  DTK_CHECK( dof_data.size() == d_lda * d_field_dim );
77 
78  d_support_ids.resize( d_lda );
79  for ( int n = 0; n < d_lda; ++n )
80  {
81  d_support_ids[n] = entity_ids[n];
82  d_id_map.emplace( d_support_ids[n], n );
83  }
84 }
85 
86 //---------------------------------------------------------------------------//
87 // Get the dimension of the field.
88 int EntityCenteredField::dimension() const { return d_field_dim; }
89 
90 //---------------------------------------------------------------------------//
91 // Get the locally-owned entity DOF ids of the field.
92 Teuchos::ArrayView<const SupportId>
94 {
95  return d_support_ids();
96 }
97 
98 //---------------------------------------------------------------------------//
99 // Given a local dof id and a dimension, read data from the application
100 // field.
102  const int dimension ) const
103 {
104  DTK_REQUIRE( d_id_map.count( support_id ) );
105  int local_id = d_id_map.find( support_id )->second;
106  return ( BLOCKED == d_layout ) ? d_data[dimension * d_lda + local_id]
107  : d_data[local_id * d_field_dim + dimension];
108 }
109 
110 //---------------------------------------------------------------------------//
111 // Given a local dof id, dimension, and field value, write data into the
112 // application field.
114  const int dimension,
115  const double data )
116 {
117  int local_id = d_id_map.find( support_id )->second;
118  switch ( d_layout )
119  {
120  case BLOCKED:
121  d_data[dimension * d_lda + local_id] = data;
122  break;
123  case INTERLEAVED:
124  d_data[local_id * d_field_dim + dimension] = data;
125  break;
126  }
127 }
128 
129 //---------------------------------------------------------------------------//
130 
131 } // end namespace DataTransferKit
132 
133 //---------------------------------------------------------------------------//
134 // end DTK_EntityCenteredField.hpp
135 //---------------------------------------------------------------------------//
DataLayout
Blocked/Interleaved data layout enum.
void writeFieldData(const SupportId support_id, const int dimension, const double data)
Given a local dof id, dimension, and field value, write data into the application field...
Teuchos::ArrayView< const SupportId > getLocalSupportIds() const
Get the locally-owned support location ids of the field.
unsigned long int SupportId
Support id type.
Definition: DTK_Types.hpp:57
Assertions and Design-by-Contract for error handling.
int dimension() const
Get the dimension of the field.
double readFieldData(const SupportId support_id, const int dimension) const
Given a local dof id and a dimension, read data from the application field.
EntityCenteredField(const Teuchos::ArrayView< Entity > &entities, const int field_dim, const Teuchos::ArrayRCP< double > &dof_data, const DataLayout layout)
Entity constructor.
DTK_BasicEntitySet.cpp.