DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_IntrepidCellLocalMap.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 //---------------------------------------------------------------------------//
40 //---------------------------------------------------------------------------//
41 
42 #include "DTK_IntrepidCellLocalMap.hpp"
43 #include "DTK_DBC.hpp"
44 #include "DTK_IntrepidCell.hpp"
46 
47 #include <Intrepid_FieldContainer.hpp>
48 
49 namespace DataTransferKit
50 {
51 //---------------------------------------------------------------------------//
52 // Return the entity measure with respect to the parameteric dimension (volume
53 // for a 3D entity, area for 2D, and length for 1D).
54 double IntrepidCellLocalMap::measure(
55  const shards::CellTopology &entity_topo,
56  const Intrepid::FieldContainer<double> &entity_coords )
57 {
58  // Get the Intrepid cell corresponding to the entity topology.
59  IntrepidCell entity_cell( entity_topo, 1 );
60 
61  // Update thet state of the cell.
62  IntrepidCell::updateState( entity_cell, entity_coords );
63 
64  // Compute the measure of the cell.
65  Intrepid::FieldContainer<double> measure( 1 );
66  entity_cell.getCellMeasures( measure );
67  return measure( 0 );
68 }
69 
70 //---------------------------------------------------------------------------//
71 // Return the centroid of the entity.
72 void IntrepidCellLocalMap::centroid(
73  const shards::CellTopology &entity_topo,
74  const Intrepid::FieldContainer<double> &entity_coords,
75  const Teuchos::ArrayView<double> &centroid )
76 {
77  // Get the Intrepid cell corresponding to the entity topology.
78  IntrepidCell entity_cell( entity_topo, 1 );
79  entity_cell.setCellNodeCoordinates( entity_coords );
80 
81  // Get the reference center of the cell.
82  Intrepid::FieldContainer<double> ref_center( 1,
83  entity_coords.dimension( 2 ) );
84  ProjectionPrimitives::referenceCellCenter( entity_topo, ref_center );
85 
86  // Map the cell center to the physical frame.
87  Intrepid::FieldContainer<double> phys_center(
88  1, 1, entity_coords.dimension( 2 ) );
89  entity_cell.mapToCellPhysicalFrame( ref_center, phys_center );
90 
91  // Extract the centroid coordinates.
92  centroid.assign( phys_center.getData()() );
93 }
94 
95 //---------------------------------------------------------------------------//
96 // Map a point to the reference space of an entity. Return the parameterized
97 // point.
98 bool IntrepidCellLocalMap::mapToReferenceFrame(
99  const shards::CellTopology &entity_topo,
100  const Intrepid::FieldContainer<double> &entity_coords,
101  const Teuchos::ArrayView<const double> &point,
102  const Teuchos::ArrayView<double> &reference_point )
103 {
104  // Get the Intrepid cell corresponding to the entity topology.
105  IntrepidCell entity_cell( entity_topo, 1 );
106  entity_cell.setCellNodeCoordinates( entity_coords );
107 
108  // Map the point to the reference frame of the cell.
109  Teuchos::Array<int> array_dims( 2 );
110  array_dims[0] = 1;
111  array_dims[1] = entity_coords.dimension( 2 );
112  Intrepid::FieldContainer<double> point_container(
113  array_dims, const_cast<double *>( point.getRawPtr() ) );
114  Intrepid::FieldContainer<double> ref_point_container(
115  array_dims, reference_point.getRawPtr() );
116  entity_cell.mapToCellReferenceFrame( point_container, ref_point_container );
117 
118  // Return true to indicate successful mapping. Catching Intrepid errors
119  // and returning false is a possibility here.
120  return true;
121 }
122 
123 //---------------------------------------------------------------------------//
124 // Determine if a reference point is in the parameterized space of an entity.
125 bool IntrepidCellLocalMap::checkPointInclusion(
126  const shards::CellTopology &entity_topo,
127  const Teuchos::ArrayView<const double> &reference_point,
128  const double tolerance )
129 {
130  // Get the Intrepid cell corresponding to the entity topology.
131  IntrepidCell entity_cell( entity_topo, 1 );
132 
133  // Check point inclusion.
134  Teuchos::Array<int> array_dims( 2 );
135  array_dims[0] = 1;
136  array_dims[1] = reference_point.size();
137  Intrepid::FieldContainer<double> ref_point_container(
138  array_dims, const_cast<double *>( reference_point.getRawPtr() ) );
139  return entity_cell.pointInReferenceCell( ref_point_container, tolerance );
140 }
141 
142 //---------------------------------------------------------------------------//
143 // Map a reference point to the physical space of an entity.
144 void IntrepidCellLocalMap::mapToPhysicalFrame(
145  const shards::CellTopology &entity_topo,
146  const Intrepid::FieldContainer<double> &entity_coords,
147  const Teuchos::ArrayView<const double> &reference_point,
148  const Teuchos::ArrayView<double> &point )
149 {
150  // Get the Intrepid cell corresponding to the entity topology.
151  IntrepidCell entity_cell( entity_topo, 1 );
152  entity_cell.setCellNodeCoordinates( entity_coords );
153 
154  // Map the reference point to the physical frame of the cell.
155  Teuchos::Array<int> ref_array_dims( 2 );
156  ref_array_dims[0] = 1;
157  ref_array_dims[1] = entity_coords.dimension( 2 );
158  Intrepid::FieldContainer<double> ref_point_container(
159  ref_array_dims, const_cast<double *>( reference_point.getRawPtr() ) );
160  Teuchos::Array<int> phys_array_dims( 3 );
161  phys_array_dims[0] = 1;
162  phys_array_dims[1] = 1;
163  phys_array_dims[2] = entity_coords.dimension( 2 );
164  Intrepid::FieldContainer<double> point_container( phys_array_dims,
165  point.getRawPtr() );
166  entity_cell.mapToCellPhysicalFrame( ref_point_container, point_container );
167 }
168 
169 //---------------------------------------------------------------------------//
170 
171 } // end namespace DataTransferKit
172 
173 //---------------------------------------------------------------------------//
174 // end DTK_IntrepidCellLocalMap.cpp
175 //---------------------------------------------------------------------------//
static void updateState(IntrepidCell &Intrepid_cell, const MDArray &cell_node_coords)
Free function for updating the cell state for a new set of physical cells in a single call...
static void referenceCellCenter(const shards::CellTopology &cell_topo, Intrepid::FieldContainer< double > &center)
Get the center of the reference cell of the given topology.
Assertions and Design-by-Contract for error handling.
Manager for Intrepid cell-level operations.
DTK_BasicEntitySet.cpp.
A stateless class of projection primitive operations.