DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_STKMeshManager.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_STKMeshManager.hpp"
42 #include "DTK_STKMeshEntityIntegrationRule.hpp"
43 #include "DTK_STKMeshEntityLocalMap.hpp"
44 #include "DTK_STKMeshEntityPredicates.hpp"
45 #include "DTK_STKMeshEntitySet.hpp"
46 #include "DTK_STKMeshNodalShapeFunction.hpp"
47 
48 namespace DataTransferKit
49 {
50 //---------------------------------------------------------------------------//
53  const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
54  const BasisType basis_type )
55  : d_bulk_data( bulk_data )
56 {
57  createFunctionSpace( basis_type, FunctionSpace::selectAll );
58  DTK_ENSURE( Teuchos::nonnull( d_function_space ) );
59 }
60 
61 //---------------------------------------------------------------------------//
64  const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
65  const Teuchos::Array<std::string> &part_names, const BasisType basis_type )
66  : d_bulk_data( bulk_data )
67 {
68  STKPartNamePredicate pred( part_names, d_bulk_data );
69  createFunctionSpace( basis_type, pred.getFunction() );
70  DTK_ENSURE( Teuchos::nonnull( d_function_space ) );
71 }
72 
73 //---------------------------------------------------------------------------//
76  const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
77  const stk::mesh::PartVector &parts, const BasisType basis_type )
78  : d_bulk_data( bulk_data )
79 {
80  STKPartVectorPredicate pred( parts );
81  createFunctionSpace( basis_type, pred.getFunction() );
82  DTK_ENSURE( Teuchos::nonnull( d_function_space ) );
83 }
84 
85 //---------------------------------------------------------------------------//
88  const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
89  const stk::mesh::Selector &selector, const BasisType basis_type )
90  : d_bulk_data( bulk_data )
91 {
92  STKSelectorPredicate pred( selector );
93  createFunctionSpace( basis_type, pred.getFunction() );
94  DTK_ENSURE( Teuchos::nonnull( d_function_space ) );
95 }
96 
97 //---------------------------------------------------------------------------//
98 // Get the function space over which the mesh and its fields are defined.
99 Teuchos::RCP<FunctionSpace> STKMeshManager::functionSpace() const
100 {
101  return d_function_space;
102 }
103 
104 //---------------------------------------------------------------------------//
105 // Create the function space.
106 void STKMeshManager::createFunctionSpace(
107  const BasisType basis_type, const PredicateFunction &select_function )
108 {
109  Teuchos::RCP<EntitySet> entity_set =
110  Teuchos::rcp( new STKMeshEntitySet( d_bulk_data ) );
111 
112  Teuchos::RCP<EntityLocalMap> local_map =
113  Teuchos::rcp( new STKMeshEntityLocalMap( d_bulk_data ) );
114 
115  Teuchos::RCP<EntityShapeFunction> shape_function;
116  switch ( basis_type )
117  {
118  case BASIS_TYPE_GRADIENT:
119  shape_function =
120  Teuchos::rcp( new STKMeshNodalShapeFunction( d_bulk_data ) );
121  break;
122 
123  default:
124  bool bad_basis_type = true;
125  DTK_INSIST( !bad_basis_type );
126  break;
127  }
128  DTK_CHECK( Teuchos::nonnull( shape_function ) );
129 
130  Teuchos::RCP<EntityIntegrationRule> integration_rule =
131  Teuchos::rcp( new STKMeshEntityIntegrationRule( d_bulk_data ) );
132 
133  d_function_space =
134  Teuchos::rcp( new FunctionSpace( entity_set, local_map, shape_function,
135  integration_rule, select_function ) );
136 
137  DTK_ENSURE( Teuchos::nonnull( d_function_space ) );
138 }
139 
140 //---------------------------------------------------------------------------//
141 Teuchos::RCP<EntitySet> STKMeshManager::entitySet() const
142 {
143  return d_function_space->entitySet();
144 }
145 
146 //---------------------------------------------------------------------------//
147 // Get the local map for entities supporting the function.
148 Teuchos::RCP<EntityLocalMap> STKMeshManager::localMap() const
149 {
150  return d_function_space->localMap();
151 }
152 
153 //---------------------------------------------------------------------------//
154 // Get the shape function for entities supporting the function.
155 Teuchos::RCP<EntityShapeFunction> STKMeshManager::shapeFunction() const
156 {
157  return d_function_space->shapeFunction();
158 }
159 
160 //---------------------------------------------------------------------------//
161 // Get the integration rule for entities supporting the function.
162 Teuchos::RCP<EntityIntegrationRule> STKMeshManager::integrationRule() const
163 {
164  return d_function_space->integrationRule();
165 }
166 
167 //---------------------------------------------------------------------------//
168 // Get the selector function.
170 {
171  return d_function_space->selectFunction();
172 }
173 
174 //---------------------------------------------------------------------------//
175 // Get the field for the given string key.
176 Teuchos::RCP<Field> STKMeshManager::field( const std::string &field_name ) const
177 {
178  DTK_REQUIRE( d_field_indexer.count( field_name ) );
179  int field_id = d_field_indexer.find( field_name )->second;
180  return d_fields[field_id];
181 }
182 
183 //---------------------------------------------------------------------------//
184 
185 } // end namespace DataTransferKit
186 
187 //---------------------------------------------------------------------------//
188 // end DTK_STKMeshManager.cpp
189 //---------------------------------------------------------------------------//
STK mesh forward and reverse local map implementation.
Teuchos::RCP< EntityIntegrationRule > integrationRule() const override
Get the integration rule for entities supporting the function.
Predicates for selecting entities in parts by part name.
Predicates for selecting entities in a selector.
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.
Nodal shape function implementation for STK mesh.
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
Predicates for selecting entities in a part vector.
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.
DTK_BasicEntitySet.cpp.
Teuchos::RCP< EntityShapeFunction > shapeFunction() const override
Get the shape function for entities supporting the function.