DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_STKMeshEntityImpl.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 <limits>
42 
43 #include "DTK_DBC.hpp"
44 #include "DTK_STKMeshEntityImpl.hpp"
45 #include "DTK_STKMeshHelpers.hpp"
46 
47 #include <Intrepid_FieldContainer.hpp>
48 
49 #include <stk_mesh/base/CoordinateSystems.hpp>
50 #include <stk_mesh/base/Field.hpp>
51 #include <stk_mesh/base/FieldBase.hpp>
52 #include <stk_mesh/base/MetaData.hpp>
53 
54 namespace DataTransferKit
55 {
56 //---------------------------------------------------------------------------//
57 // Constructor.
59  const stk::mesh::Entity &stk_entity,
60  const Teuchos::Ptr<stk::mesh::BulkData> &bulk_data )
61  : d_extra_data( new STKMeshEntityExtraData( stk_entity ) )
62  , d_bulk_data( bulk_data )
63 { /* ... */
64 }
65 
66 //---------------------------------------------------------------------------//
67 // Get the unique global identifier for the entity.
69 {
70  DTK_REQUIRE( Teuchos::nonnull( d_bulk_data ) );
71  return Teuchos::as<EntityId>(
72  d_bulk_data->identifier( d_extra_data->d_stk_entity ) );
73 }
74 
75 //---------------------------------------------------------------------------//
76 // Get the parallel rank that owns the entity.
78 {
79  DTK_REQUIRE( Teuchos::nonnull( d_bulk_data ) );
80  return d_bulk_data->parallel_owner_rank( d_extra_data->d_stk_entity );
81 }
82 
83 //---------------------------------------------------------------------------//
84 // Get the topological dimension of the entity.
86 {
87  DTK_REQUIRE( Teuchos::nonnull( d_bulk_data ) );
88  stk::mesh::EntityRank rank =
89  d_bulk_data->entity_rank( d_extra_data->d_stk_entity );
91  rank, physicalDimension() );
92 }
93 
94 //---------------------------------------------------------------------------//
95 // Return the physical dimension of the entity.
97 {
98  DTK_REQUIRE( Teuchos::nonnull( d_bulk_data ) );
99  return d_bulk_data->mesh_meta_data().spatial_dimension();
100 }
101 
102 //---------------------------------------------------------------------------//
103 // Return the Cartesian bounding box around an entity.
104 void STKMeshEntityImpl::boundingBox( Teuchos::Tuple<double, 6> &bounds ) const
105 {
106  DTK_REQUIRE( Teuchos::nonnull( d_bulk_data ) );
107 
108  Intrepid::FieldContainer<double> node_coords =
110  Teuchos::Array<stk::mesh::Entity>( 1, d_extra_data->d_stk_entity ),
111  *d_bulk_data );
112  DTK_CHECK( node_coords.rank() == 3 );
113  DTK_CHECK( node_coords.dimension( 0 ) == 1 );
114 
115  double max = std::numeric_limits<double>::max();
116  bounds = Teuchos::tuple( max, max, max, -max, -max, -max );
117  int space_dim = node_coords.dimension( 2 );
118  for ( int n = 0; n < node_coords.dimension( 1 ); ++n )
119  {
120  for ( int d = 0; d < space_dim; ++d )
121  {
122  bounds[d] = std::min( bounds[d], node_coords( 0, n, d ) );
123  bounds[d + 3] = std::max( bounds[d + 3], node_coords( 0, n, d ) );
124  }
125  }
126  for ( int d = space_dim; d < 3; ++d )
127  {
128  bounds[d] = -max;
129  bounds[d + 3] = max;
130  }
131 }
132 
133 //---------------------------------------------------------------------------//
134 // Determine if an entity is in the block with the given id.
135 bool STKMeshEntityImpl::inBlock( const int block_id ) const
136 {
137  DTK_REQUIRE( Teuchos::nonnull( d_bulk_data ) );
138  const stk::mesh::PartVector &all_parts =
139  d_bulk_data->mesh_meta_data().get_parts();
140  stk::mesh::Bucket &entity_bucket =
141  d_bulk_data->bucket( d_extra_data->d_stk_entity );
142  for ( auto part_it = all_parts.begin(); part_it != all_parts.end();
143  ++part_it )
144  {
145  if ( Teuchos::as<int>( ( *part_it )->mesh_meta_data_ordinal() ) ==
146  block_id )
147  {
148  return entity_bucket.member( **part_it );
149  }
150  }
151  return false;
152 }
153 
154 //---------------------------------------------------------------------------//
155 // Determine if an entity is on the boundary with the given id.
156 bool STKMeshEntityImpl::onBoundary( const int boundary_id ) const
157 {
158  return inBlock( boundary_id );
159 }
160 
161 //---------------------------------------------------------------------------//
162 // Get the extra data on the entity.
163 Teuchos::RCP<EntityExtraData> STKMeshEntityImpl::extraData() const
164 {
165  return d_extra_data;
166 }
167 
168 //---------------------------------------------------------------------------//
169 // Provide a verbose description of the object.
171  Teuchos::FancyOStream &out,
172  const Teuchos::EVerbosityLevel /*verb_level*/ ) const
173 {
174  shards::CellTopology topo = STKMeshHelpers::getShardsTopology(
175  d_extra_data->d_stk_entity, *d_bulk_data );
176 
177  Intrepid::FieldContainer<double> node_coords =
179  Teuchos::Array<stk::mesh::Entity>( 1, d_extra_data->d_stk_entity ),
180  *d_bulk_data );
181  int num_node = node_coords.dimension( 1 );
182  int space_dim = node_coords.dimension( 2 );
183 
184  out << std::endl;
185  out << "---" << std::endl;
186  out << "STK Mesh Entity" << std::endl;
187  out << "Id: " << id() << std::endl;
188  out << "Owner rank: " << ownerRank() << std::endl;
189  out << "Topology: " << topo;
190  out << "Node coords: " << std::endl;
191  for ( int n = 0; n < num_node; ++n )
192  {
193  out << " node " << n << ": ";
194  for ( int d = 0; d < space_dim; ++d )
195  {
196  out << node_coords( 0, n, d ) << " ";
197  }
198  out << std::endl;
199  }
200  out << "---" << std::endl;
201 }
202 
203 //---------------------------------------------------------------------------//
204 
205 } // end namespace DataTransferKit
206 
207 //---------------------------------------------------------------------------//
208 // end DTK_STKMeshEntityImpl.cpp
209 //---------------------------------------------------------------------------//
static Intrepid::FieldContainer< double > getEntityNodeCoordinates(const Teuchos::Array< stk::mesh::Entity > &stk_entities, const stk::mesh::BulkData &bulk_data)
Given a STK entity, return the coordinates of its nodes in a field container ordered by canonical nod...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verb_level) const override
Provide a verbose description of the object.
int ownerRank() const override
Get the parallel rank that owns the entity.
static int getTopologicalDimensionFromRank(const stk::mesh::EntityRank stk_rank, const int space_dim)
Given a STK entity rank, get the topological dimension.
bool inBlock(const int block_id) const override
Determine if an entity is in the block with the given id.
bool onBoundary(const int boundary_id) const override
Determine if an entity is on the boundary with the given id.
Assertions and Design-by-Contract for error handling.
STKMeshEntityImpl(const stk::mesh::Entity &stk_entity, const Teuchos::Ptr< stk::mesh::BulkData > &bulk_data)
Constructor.
EntityId id() const override
Get the unique global identifier for the entity.
int topologicalDimension() const override
Return the topological dimension of the entity.
static shards::CellTopology getShardsTopology(const stk::mesh::Entity stk_entity, const stk::mesh::BulkData &bulk_data)
Given a STK entity, return its shards topology.
unsigned long int EntityId
Entity id type.
Definition: DTK_Types.hpp:50
A base class for setting extra data with entities.
Teuchos::RCP< EntityExtraData > extraData() const override
Get the extra data on the entity.
DTK_BasicEntitySet.cpp.
int physicalDimension() const override
Return the physical dimension of the entity.
void boundingBox(Teuchos::Tuple< double, 6 > &bounds) const override
Return the Cartesian bounding box around an entity.