DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_STKMeshEntityLocalMap.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_STKMeshEntityLocalMap.hpp"
42 #include "DTK_DBC.hpp"
43 #include "DTK_IntrepidCellLocalMap.hpp"
45 #include "DTK_STKMeshHelpers.hpp"
46 
47 #include <Intrepid_FieldContainer.hpp>
48 
49 #include <stk_mesh/base/MetaData.hpp>
50 #include <stk_mesh/base/Part.hpp>
51 #include <stk_mesh/base/Selector.hpp>
52 #include <stk_topology/topology.hpp>
53 
54 namespace DataTransferKit
55 {
56 //---------------------------------------------------------------------------//
57 // Constructor.
59  const Teuchos::RCP<stk::mesh::BulkData> &bulk_data )
60  : d_bulk_data( bulk_data )
61  , d_inclusion_tol( 1.0e-6 )
62 { /* ... */
63 }
64 
65 //---------------------------------------------------------------------------//
66 // Set parameters for mapping.
67 void STKMeshEntityLocalMap::setParameters(
68  const Teuchos::ParameterList &parameters )
69 {
70  if ( parameters.isParameter( "Point Inclusion Tolerance" ) )
71  {
72  d_inclusion_tol = parameters.get<double>( "Point Inclusion Tolerance" );
73  }
74 }
75 
76 //---------------------------------------------------------------------------//
77 // Return the entity measure with respect to the parameteric dimension (volume
78 // for a 3D entity, area for 2D, and length for 1D).
79 double STKMeshEntityLocalMap::measure( const Entity &entity ) const
80 {
81  // Get the STK entity and its topology.
82  const stk::mesh::Entity &stk_entity =
84  stk::mesh::EntityRank rank = d_bulk_data->entity_rank( stk_entity );
85  shards::CellTopology entity_topo =
86  STKMeshHelpers::getShardsTopology( stk_entity, *d_bulk_data );
87 
88  // Get the STK entity coordinates.
89  Intrepid::FieldContainer<double> entity_coords =
91  Teuchos::Array<stk::mesh::Entity>( 1, stk_entity ), *d_bulk_data );
92 
93  // Compute the measure of the element.
94  if ( rank == stk::topology::ELEM_RANK )
95  {
96  return IntrepidCellLocalMap::measure( entity_topo, entity_coords );
97  }
98 
99  // Compute the measure of the face.
100  else if ( rank == stk::topology::FACE_RANK )
101  {
102  bool not_implemented = true;
103  DTK_INSIST( !not_implemented );
104  return -1.0;
105  }
106 
107  // Check for unsupported ranks.
108  else
109  {
110  bool bad_rank = true;
111  DTK_INSIST( !bad_rank );
112  return -1.0;
113  }
114  return -1.0;
115 }
116 
117 //---------------------------------------------------------------------------//
118 // Return the centroid of the entity.
120  const Entity &entity, const Teuchos::ArrayView<double> &centroid ) const
121 {
122  // Get the STK entity.
123  const stk::mesh::Entity &stk_entity =
125  stk::mesh::EntityRank rank = d_bulk_data->entity_rank( stk_entity );
126 
127  // Extract the centroid of the element.
128  if ( rank == stk::topology::ELEM_RANK )
129  {
130  shards::CellTopology entity_topo =
131  STKMeshHelpers::getShardsTopology( stk_entity, *d_bulk_data );
132  Intrepid::FieldContainer<double> entity_coords =
134  Teuchos::Array<stk::mesh::Entity>( 1, stk_entity ),
135  *d_bulk_data );
136  IntrepidCellLocalMap::centroid( entity_topo, entity_coords, centroid );
137  }
138 
139  // Extract the centroid of the face.
140  else if ( rank == stk::topology::FACE_RANK )
141  {
142  bool not_implemented = true;
143  DTK_INSIST( !not_implemented );
144  }
145 
146  // The centroid of a node is the node coordinates.
147  else if ( rank == stk::topology::NODE_RANK )
148  {
149  Intrepid::FieldContainer<double> entity_coords =
151  Teuchos::Array<stk::mesh::Entity>( 1, stk_entity ),
152  *d_bulk_data );
153  centroid.assign( entity_coords.getData()() );
154  }
155 
156  // Check for unsupported ranks.
157  else
158  {
159  bool bad_rank = true;
160  DTK_INSIST( !bad_rank );
161  }
162 }
163 
164 //---------------------------------------------------------------------------//
165 // Perform a safeguard check for mapping a point to the reference space
166 // of an entity using the given tolerance.
168  const Entity &entity,
169  const Teuchos::ArrayView<const double> &physical_point ) const
170 {
171  // Get the STK entity.
172  const stk::mesh::Entity &stk_entity =
174  stk::mesh::EntityRank rank = d_bulk_data->entity_rank( stk_entity );
175 
176  // If we have an element, use the default implementation.
177  if ( rank == stk::topology::ELEM_RANK )
178  {
180  physical_point );
181  }
182 
183  // If we have a face, perform the projection safeguard.
184  else if ( rank == stk::topology::FACE_RANK )
185  {
186  bool not_implemented = true;
187  DTK_INSIST( !not_implemented );
188  return false;
189  }
190 
191  // Check for unsupported ranks.
192  else
193  {
194  bool bad_rank = true;
195  DTK_INSIST( !bad_rank );
196  return false;
197  }
198 
199  // Return true to indicate successful mapping. Catching Intrepid errors
200  // and returning false is a possibility here.
201  return true;
202 }
203 
204 //---------------------------------------------------------------------------//
205 // Map a point to the reference space of an entity. Return the parameterized
206 // point.
208  const Entity &entity,
209  const Teuchos::ArrayView<const double> &physical_point,
210  const Teuchos::ArrayView<double> &reference_point ) const
211 {
212  // Get the STK entity.
213  const stk::mesh::Entity &stk_entity =
215  stk::mesh::EntityRank rank = d_bulk_data->entity_rank( stk_entity );
216 
217  // Use the cell to perform the element mapping.
218  if ( rank == stk::topology::ELEM_RANK )
219  {
220  shards::CellTopology entity_topo =
221  STKMeshHelpers::getShardsTopology( stk_entity, *d_bulk_data );
222  Intrepid::FieldContainer<double> entity_coords =
224  Teuchos::Array<stk::mesh::Entity>( 1, stk_entity ),
225  *d_bulk_data );
226  IntrepidCellLocalMap::mapToReferenceFrame(
227  entity_topo, entity_coords, physical_point, reference_point );
228  }
229 
230  // Use the side cell to perform the face mapping.
231  else if ( rank == stk::topology::FACE_RANK )
232  {
233  bool not_implemented = true;
234  DTK_INSIST( !not_implemented );
235  return false;
236  }
237 
238  // Check for unsupported ranks.
239  else
240  {
241  bool bad_rank = true;
242  DTK_INSIST( !bad_rank );
243  }
244 
245  // Return true to indicate successful mapping. Catching Intrepid errors
246  // and returning false is a possibility here.
247  return true;
248 }
249 
250 //---------------------------------------------------------------------------//
251 // Determine if a reference point is in the parameterized space of an entity.
253  const Entity &entity,
254  const Teuchos::ArrayView<const double> &reference_point ) const
255 {
256  // Get the STK entity and its topology.
257  const stk::mesh::Entity &stk_entity =
259  stk::mesh::EntityRank rank = d_bulk_data->entity_rank( stk_entity );
260  shards::CellTopology entity_topo =
261  STKMeshHelpers::getShardsTopology( stk_entity, *d_bulk_data );
262 
263  // Check point inclusion in the element.
264  if ( rank == stk::topology::ELEM_RANK )
265  {
266  return IntrepidCellLocalMap::checkPointInclusion(
267  entity_topo, reference_point, d_inclusion_tol );
268  }
269 
270  // Check point inclusion in the face.
271  else if ( rank == stk::topology::FACE_RANK )
272  {
273  bool not_implemented = true;
274  DTK_INSIST( !not_implemented );
275  return false;
276  }
277 
278  // Check for unsupported ranks.
279  else
280  {
281  bool bad_rank = true;
282  DTK_INSIST( !bad_rank );
283  return false;
284  }
285 
286  return false;
287 }
288 
289 //---------------------------------------------------------------------------//
290 // Map a reference point to the physical space of an entity.
292  const Entity &entity,
293  const Teuchos::ArrayView<const double> &reference_point,
294  const Teuchos::ArrayView<double> &physical_point ) const
295 {
296  // Get the STK entity.
297  const stk::mesh::Entity &stk_entity =
299  stk::mesh::EntityRank rank = d_bulk_data->entity_rank( stk_entity );
300 
301  // Map from the element.
302  if ( rank == stk::topology::ELEM_RANK )
303  {
304  shards::CellTopology entity_topo =
305  STKMeshHelpers::getShardsTopology( stk_entity, *d_bulk_data );
306  Intrepid::FieldContainer<double> entity_coords =
308  Teuchos::Array<stk::mesh::Entity>( 1, stk_entity ),
309  *d_bulk_data );
310  IntrepidCellLocalMap::mapToPhysicalFrame(
311  entity_topo, entity_coords, reference_point, physical_point );
312  }
313 
314  // Map from the face.
315  else if ( rank == stk::topology::FACE_RANK )
316  {
317  bool not_implemented = true;
318  DTK_INSIST( !not_implemented );
319  }
320 
321  // Check for unsupported ranks.
322  else
323  {
324  bool bad_rank = true;
325  DTK_INSIST( !bad_rank );
326  }
327 }
328 
329 //---------------------------------------------------------------------------//
330 // Compute the normal on a face (3D) or edge (2D) at a given reference point.
332  const Entity &entity, const Entity &parent_entity,
333  const Teuchos::ArrayView<const double> &reference_point,
334  const Teuchos::ArrayView<double> &normal ) const
335 {
336  // Get the STK entity.
337  const stk::mesh::Entity &stk_entity =
339  stk::mesh::EntityRank rank = d_bulk_data->entity_rank( stk_entity );
340 
341  // We can only compute normals for faces.
342  if ( rank == stk::topology::FACE_RANK )
343  {
344  bool not_implemented = true;
345  DTK_INSIST( !not_implemented );
346  }
347 
348  // Check for unsupported ranks.
349  else
350  {
351  bool bad_rank = true;
352  DTK_INSIST( !bad_rank );
353  }
354 }
355 
356 //---------------------------------------------------------------------------//
357 
358 } // end namespace DataTransferKit
359 
360 //---------------------------------------------------------------------------//
361 // end DTK_STKMeshEntityLocalMap.cpp
362 //---------------------------------------------------------------------------//
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...
Geometric entity interface definition.
Definition: DTK_Entity.hpp:61
static const stk::mesh::Entity & extractEntity(const Entity dtk_entity)
Given a DTK entity, extract the STK entity.
virtual bool isSafeToMapToReferenceFrame(const Entity &entity, const Teuchos::ArrayView< const double > &physical_point) const
(Safeguard the reverse map) Perform a safeguard check for mapping a point to the reference space of a...
Assertions and Design-by-Contract for error handling.
void mapToPhysicalFrame(const Entity &entity, const Teuchos::ArrayView< const double > &reference_point, const Teuchos::ArrayView< double > &physical_point) const override
(Forward Map) Map a reference point to the physical space of an entity.
bool checkPointInclusion(const Entity &entity, const Teuchos::ArrayView< const double > &reference_point) const override
Determine if a reference point is in the parameterized space of an entity.
bool isSafeToMapToReferenceFrame(const Entity &entity, const Teuchos::ArrayView< const double > &physical_point) const override
(Safeguard the reverse map) Perform a safeguard check for mapping a point to the reference space of a...
static shards::CellTopology getShardsTopology(const stk::mesh::Entity stk_entity, const stk::mesh::BulkData &bulk_data)
Given a STK entity, return its shards topology.
double measure(const Entity &entity) const override
Return the entity measure with respect to the parameteric dimension (volume for a 3D entity...
void centroid(const Entity &entity, const Teuchos::ArrayView< double > &centroid) const override
Return the centroid of the entity.
void normalAtReferencePoint(const Entity &entity, const Entity &parent_entity, const Teuchos::ArrayView< const double > &reference_point, const Teuchos::ArrayView< double > &normal) const override
Compute the normal on a face (3D) or edge (2D) at a given reference point. A default implementation i...
STKMeshEntityLocalMap(const Teuchos::RCP< stk::mesh::BulkData > &bulk_data)
Constructor.
DTK_BasicEntitySet.cpp.
bool mapToReferenceFrame(const Entity &entity, const Teuchos::ArrayView< const double > &physical_point, const Teuchos::ArrayView< double > &reference_point) const override
(Reverse Map) Map a point to the reference space of an entity. Return the parameterized point...
A stateless class of projection primitive operations.