DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_STKMeshManager.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_STKMESHMANAGER_HPP
42 #define DTK_STKMESHMANAGER_HPP
43 
44 #include <string>
45 #include <unordered_map>
46 
47 #include "DTK_ClientManager.hpp"
48 #include "DTK_DBC.hpp"
49 #include "DTK_Field.hpp"
50 #include "DTK_FieldMultiVector.hpp"
51 #include "DTK_FunctionSpace.hpp"
52 #include "DTK_STKMeshField.hpp"
53 #include "DTK_Types.hpp"
54 
55 #include <Teuchos_Array.hpp>
56 #include <Teuchos_RCP.hpp>
57 
58 #include <stk_mesh/base/BulkData.hpp>
59 #include <stk_mesh/base/Selector.hpp>
60 
61 namespace DataTransferKit
62 {
63 //---------------------------------------------------------------------------//
72 //---------------------------------------------------------------------------//
74 {
75  public:
79  enum BasisType
80  {
81  BASIS_TYPE_GRADIENT
82  };
83 
84  public:
95  STKMeshManager( const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
96  const BasisType basis_type = BASIS_TYPE_GRADIENT );
97 
111  STKMeshManager( const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
112  const Teuchos::Array<std::string> &part_names,
113  const BasisType basis_type = BASIS_TYPE_GRADIENT );
114 
128  STKMeshManager( const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
129  const stk::mesh::PartVector &parts,
130  const BasisType basis_type = BASIS_TYPE_GRADIENT );
131 
145  STKMeshManager( const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
146  const stk::mesh::Selector &selector,
147  const BasisType basis_type = BASIS_TYPE_GRADIENT );
148 
153  template <class FieldType>
154  void registerField( const Teuchos::Ptr<FieldType> &field,
155  const int field_dim );
156 
161  Teuchos::RCP<FunctionSpace> functionSpace() const;
162 
166  template <class FieldType>
167  Teuchos::RCP<FieldMultiVector>
168  createFieldMultiVector( const Teuchos::Ptr<FieldType> &field,
169  const int field_dim );
170 
172 
176  Teuchos::RCP<EntitySet> entitySet() const override;
177 
181  Teuchos::RCP<EntityLocalMap> localMap() const override;
182 
186  Teuchos::RCP<EntityShapeFunction> shapeFunction() const override;
187 
191  Teuchos::RCP<EntityIntegrationRule> integrationRule() const override;
192 
196  PredicateFunction selectFunction() const override;
197 
201  Teuchos::RCP<Field> field( const std::string &field_name ) const override;
203 
204  private:
205  // Create the function space.
206  void createFunctionSpace( const BasisType basis_type,
207  const PredicateFunction &select_function );
208 
209  private:
210  // Bulk data.
211  Teuchos::RCP<stk::mesh::BulkData> d_bulk_data;
212 
213  // The function space over which the mesh and its fields are defined.
214  Teuchos::RCP<FunctionSpace> d_function_space;
215 
216  // Field name to local id indexer.
217  std::unordered_map<std::string, int> d_field_indexer;
218 
219  // Registered fields.
220  Teuchos::Array<Teuchos::RCP<Field>> d_fields;
221 };
222 
223 //---------------------------------------------------------------------------//
224 // Template functions.
225 //---------------------------------------------------------------------------//
226 template <class FieldType>
227 Teuchos::RCP<FieldMultiVector>
228 STKMeshManager::createFieldMultiVector( const Teuchos::Ptr<FieldType> &field,
229  const int field_dim )
230 {
231  DTK_REQUIRE( Teuchos::nonnull( d_bulk_data ) );
232  DTK_REQUIRE( Teuchos::nonnull( d_function_space ) );
233 
234  Teuchos::RCP<Field> stk_field = Teuchos::rcp(
235  new STKMeshField<double, FieldType>( d_bulk_data, field, field_dim ) );
236  return Teuchos::rcp(
237  new FieldMultiVector( stk_field, d_function_space->entitySet() ) );
238 }
239 
240 //---------------------------------------------------------------------------//
241 template <class FieldType>
242 void STKMeshManager::registerField( const Teuchos::Ptr<FieldType> &field,
243  const int field_dim )
244 {
245  DTK_REQUIRE( Teuchos::nonnull( d_bulk_data ) );
246  DTK_REQUIRE( Teuchos::nonnull( d_function_space ) );
247 
248  d_field_indexer.emplace( field->name(), d_fields.size() );
249 
250  d_fields.push_back( Teuchos::rcp( new STKMeshField<double, FieldType>(
251  d_bulk_data, field, field_dim ) ) );
252 }
253 
254 //---------------------------------------------------------------------------//
255 
256 } // end namespace DataTransferKit
257 
258 //---------------------------------------------------------------------------//
259 
260 #endif // end DTK_STKMESHMANAGER_HPP
261 
262 //---------------------------------------------------------------------------//
263 // end DTK_STKMeshManager.hpp
264 //---------------------------------------------------------------------------//
Field data access for STK mesh.
Teuchos::RCP< EntityIntegrationRule > integrationRule() const override
Get the integration rule for entities supporting the function.
Assertions and Design-by-Contract for error handling.
Teuchos::RCP< Field > field(const std::string &field_name) const override
Get the field for the given string key.
PredicateFunction selectFunction() const override
Get the selector function.
STKMeshManager(const Teuchos::RCP< stk::mesh::BulkData > &bulk_data, const BasisType basis_type=BASIS_TYPE_GRADIENT)
Default constructor.
std::function< bool(Entity)> PredicateFunction
Predicate function typedef.
Definition: DTK_Types.hpp:64
Teuchos::RCP< FunctionSpace > functionSpace() const
Get the function space over which the mesh and its fields are defined.
Teuchos::RCP< EntitySet > entitySet() const override
ClientManager interface implementation.
Teuchos::RCP< EntityLocalMap > localMap() const override
Get the local map for entities supporting the function.
High-level manager for STK mesh.
DTK_BasicEntitySet.cpp.
void registerField(const Teuchos::Ptr< FieldType > &field, const int field_dim)
Register a tag with the manager that will be available for solution transfer.
Teuchos::RCP< FieldMultiVector > createFieldMultiVector(const Teuchos::Ptr< FieldType > &field, const int field_dim)
Given a field and dimension, build a vector over that field.
ClientManager interface.
Teuchos::RCP< EntityShapeFunction > shapeFunction() const override
Get the shape function for entities supporting the function.