DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_STKMeshField.hpp
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 #ifndef DTK_STKMESHFIELD_HPP
42 #define DTK_STKMESHFIELD_HPP
43 
44 #include <unordered_map>
45 #include <vector>
46 
47 #include "DTK_Field.hpp"
48 #include "DTK_Types.hpp"
49 
50 #include <Teuchos_ArrayView.hpp>
51 #include <Teuchos_Ptr.hpp>
52 #include <Teuchos_RCP.hpp>
53 
54 #include <stk_mesh/base/BulkData.hpp>
55 #include <stk_mesh/base/Entity.hpp>
56 #include <stk_mesh/base/Selector.hpp>
57 #include <stk_topology/topology.hpp>
58 
59 namespace DataTransferKit
60 {
61 //---------------------------------------------------------------------------//
66 //---------------------------------------------------------------------------//
67 template <class Scalar, class FieldType>
68 class STKMeshField : public Field
69 {
70  public:
74  STKMeshField( const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
75  const Teuchos::Ptr<FieldType> &field, const int field_dim );
76 
80  int dimension() const override;
81 
85  Teuchos::ArrayView<const SupportId> getLocalSupportIds() const override;
86 
91  double readFieldData( const SupportId support_id,
92  const int dimension ) const override;
93 
98  void writeFieldData( const SupportId support_id, const int dimension,
99  const double data ) override;
100 
104  void finalizeAfterWrite() override;
105 
106  private:
107  // The mesh over which the field is defined.
108  Teuchos::RCP<stk::mesh::BulkData> d_bulk_data;
109 
110  // The field containing the vector data.
111  Teuchos::Ptr<FieldType> d_field;
112 
113  // The dimension of the field.
114  int d_field_dim;
115 
116  // The enitities over which the field is defined.
117  std::vector<stk::mesh::Entity> d_field_entities;
118 
119  // The support ids of the entities over which the field is constructed.
120  Teuchos::Array<SupportId> d_support_ids;
121 
122  // Support id to local id map.
123  std::unordered_map<SupportId, int> d_id_map;
124 };
125 
126 //---------------------------------------------------------------------------//
127 
128 } // end namespace DataTransferKit
129 
130 //---------------------------------------------------------------------------//
131 // Template includes.
132 //---------------------------------------------------------------------------//
133 
134 #include "DTK_STKMeshField_impl.hpp"
135 
136 //---------------------------------------------------------------------------//
137 
138 #endif // end DTK_STKMESHFIELD_HPP
139 
140 //---------------------------------------------------------------------------//
141 // end DTK_STKMeshField.hpp
142 //---------------------------------------------------------------------------//
double readFieldData(const SupportId support_id, const int dimension) const override
Given a local support id and a dimension, read data from the application field.
Field data access for STK mesh.
STKMeshField(const Teuchos::RCP< stk::mesh::BulkData > &bulk_data, const Teuchos::Ptr< FieldType > &field, const int field_dim)
Constructor.
unsigned long int SupportId
Support id type.
Definition: DTK_Types.hpp:57
void finalizeAfterWrite() override
Finalize a field after writing into it.
void writeFieldData(const SupportId support_id, const int dimension, const double data) override
Given a local support id, dimension, and field value, write data into the application field...
int dimension() const override
Get the dimension of the field.
Field interface.
Definition: DTK_Field.hpp:72
DTK_BasicEntitySet.cpp.
Teuchos::ArrayView< const SupportId > getLocalSupportIds() const override
Get the locally-owned entity support location ids of the field.